//--------------------------------------------------------------------- // Splits a command line into argc/argv lists, using the VC7 parsing rules. // // This functions interface mimics the CommandLineToArgvW api. // // If function fails, returns NULL. // // If function suceeds, call delete [] on return pointer when done. // //--------------------------------------------------------------------- LPWSTR *SegmentCommandLine(LPCWSTR lpCmdLine, DWORD *pNumArgs) { STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; STATIC_CONTRACT_FAULT; *pNumArgs = 0; int nch = (int)wcslen(lpCmdLine); // Calculate the worstcase storage requirement. (One pointer for // each argument, plus storage for the arguments themselves.) int cbAlloc = (nch+1)*sizeof(LPWSTR) + sizeof(WCHAR)*(nch + 1); LPWSTR pAlloc = new (nothrow) WCHAR[cbAlloc / sizeof(WCHAR)]; if (!pAlloc) return NULL; LPWSTR *argv = (LPWSTR*) pAlloc;// We store the argv pointers in the first halt LPWSTRpdst = (LPWSTR)( ((BYTE*)pAlloc) + sizeof(LPWSTR)*(nch+1) ); // A running pointer to second half to store arguments LPCWSTR psrc = lpCmdLine; WCHAR c; BOOL inquote; BOOL copychar; int numslash; // First, parse the program name (argv[0]). Argv[0] is parsed under // special rules. Anything up to the first whitespace outside a quoted // subtring is accepted. Backslashes are treated as normal characters. argv[ (*pNumArgs)++ ] = pdst; inquote = FALSE; do { if (*psrc == L'"' ) { inquote = !inquote; c = *psrc++; continue; } *pdst++ = *psrc; c = *psrc++; } while ( (c != L'\0' && (inquote || (c != L' ' && c != L'\t'))) ); if ( c == L'\0' ) { psrc--; } else { *(pdst-1) = L'\0'; } inquote = FALSE; /* loop on each argument */ for(;;) { if ( *psrc ) { while (*psrc == L' ' || *psrc == L'\t') { ++psrc; } } if (*psrc == L'\0') break; /* end of args */ /* scan an argument */ argv[ (*pNumArgs)++ ] = pdst; /* loop through scanning one argument */ for (;;) { copychar = 1; /* Rules: 2N backslashes + " ==> N backslashes and begin/end quote 2N+1 backslashes + " ==> N backslashes + literal " N backslashes ==> N backslashes */ numslash = 0; while (*psrc == L'\\') { /* count number of backslashes for use below */ ++psrc; ++numslash; } if (*psrc == L'"') { /* if 2N backslashes before, start/end quote, otherwise copy literally */ if (numslash % 2 == 0) { if (inquote) { if (psrc[1] == L'"') { psrc++; /* Double quote inside quoted string */ } else { /* skip first quote char and copy second */ copychar = 0; } } else { copychar = 0; /* don't copy quote */ } inquote = !inquote; } numslash /= 2; /* divide numslash by two */ } /* copy slashes */ while (numslash--) { *pdst++ = L'\\'; } /* if at end of arg, break loop */ if (*psrc == L'\0' || (!inquote && (*psrc == L' ' || *psrc == L'\t'))) break; /* copy character into argument */ if (copychar) { *pdst++ = *psrc; } ++psrc; } /* null-terminate the argument */ *pdst++ = L'\0'; /* terminate string */ } /* We put one last argument in -- a null ptr */ argv[ (*pNumArgs) ] = NULL; _ASSERTE((BYTE*)pdst return argv; } |
相关推荐
1、我们在Main()函数中,调用Test()函数,我们管Main()函数称之为调用者, 管Test()函数称之为被调用者。 如果被调用者想要得到调用者的值: 1)、传递参数。 2)、使用静态字段来模拟全局变量。 如果调用者想要得到被...
protected : 保护成员,该类内部和继承类中可以访问。 public : 公共成员,完全公开,没有访问限制。 internal: 在同一命名空间内可以访问。 2 .列举ASP.NET 页面之间传递值的几种方式。 答. 1.使用QueryString,...
protected : 保护成员,该类内部和继承类中可以访问。 public : 公共成员,完全公开,没有访问限制。 internal: 在同一命名空间内可以访问。 2 .列举ASP.NET 页面之间传递值的几种方式。 答. (1).使用...
6.9 传统的与现代的函数参数声明 第7章 结构、联合、枚举和用户定义的类型 7.1 结构 7.2 结构数组 7.3 向函数传递结构 7.4 结构指针 7.5 结构中的数组和结构 7.6 位域 7.7 联合 7.8 枚举 7.9 用sizeof来保证可移植...
7.2 main 函数 7.3 进程终止 7.3.1 exit和_exit函数 7.3.2 atexit函数 7.4 命令行参数 7.5 环境表 7.6 C程序的存储空间布局 7.7 共享库 7.8 存储器分配 7.9 环境变量 7.10 setjmp 和longjmp函数 7.10.1 自动, 寄存器...
30.简要谈一下您对微软.NET 构架下remoting和webservice两项技术的理解以及实际中的应用。 答:WS主要是可利用HTTP,穿透防火墙。而Remoting可以利用TCP/IP,二进制传送提高效率。 31.公司要求开发一个继承System....
2-此时,根据依赖规则,由于command.h的文件戳改了,要重新生成main.o和main.d文件。 3-先调用gcc -c main.c -o main.o生成main.o, 再调用gcc -MM main.c > main.d重新生成main.d。 此时main.d的依赖文件里增加了...
在 C 或 C 中与委托最接近的是函数指针,但函数指针只能引用静态函数,而委托可以同时引用静态方法和实例方法。在后一种情况中,委托不仅存储对方法入口点的引用,还存储对调用其方法的对象的引用。与 C 函数指针...
本书系编程语言先驱者Ivor Horton的经典之作,是学习C++编程最畅销的图书品种之一,不仅涵盖了Visual C++ .NET编程知识,还全面介绍了标准C++语言和.NET C++/CLI。本书延续了Ivor Horton讲解编程语言的独特方法,...
3. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。 答:public class MainClass { public static void Main() { Console.WriteLine(Foo(30)); } public static ...
10.3 构造函数和析构函数 .119 10.4 小 结 .122 第十一章 方 法 .124 11.1 方法的声明.124 11.2 方法中的参数.125 11.3 静态和非静态的方法.129 11.4 方法的重载.130 11.5 操作符重载.134 11.6 小 ...
ExtAspNet是一组专业的Asp.net控件库,拥有原生的AJAX支持和丰富的UI效果, 目标是创建没有ViewState,没有JavaScript,没有CSS,没有UpdatePanel,没有WebServices的Web应用程序。 支持的浏览器: IE 7.0+, Firefox...
-在2009-03-03 v1.3.0曾经提到这个兼容问题,并有这样的规则,如果Asp.net的按钮AJAX提交,必须设置UseSubmitBehavior="false" --也就是说生成的input的type不能是"submit",而这个限制在有些情况下是不可原谅的...
封装是把过程和数据包围起来,对数据的访问只能通过已定义的界面。面向对象计算始于这个基本概念,即现实世界可以被描绘成一系列完全自治、封装的对象,这些对象通过一个受保护的接口访问其他对象。 4. 多态性: 多...