windows版本的getopt
来源:互联网 发布:图片修改软件 编辑:程序博客网 时间:2024/05/19 17:05
参考:http://www.oschina.net/code/explore/axis2c-src-1.6.0/util/src/platforms/windows/getopt_windows.c
源码:
static char *optarg = NULL; //用于存储每次得到的参数
源码:
static char *optarg = NULL; //用于存储每次得到的参数
static int optind = 1;
int win_getopt(int __argc, char *const *__argv, const char *__shortopts)
{
int opterr = 1;
int optopt = 0;
static char *pos = "";
char *olstindex = NULL;
if (!*pos)
{
if (optind >= __argc || *(pos = __argv[optind]) != '-')
{
pos = "";
return -1;
}
if (pos[1] && *++pos == '-')
{
++optind;
pos = "";
return -1;
}
}
optopt = (int) *pos++;
olstindex = strchr((char *)__shortopts, optopt);
if (!olstindex)
{
if (optopt == (int) '-')
return -1;
if (!*pos)
++optind;
}
++olstindex;
if (*pos)
optarg = pos;
else if (__argc <= ++optind)
{
pos = "";
}
else
optarg = __argv[optind];
pos = "";
++optind;
return optopt;
}
测试命令: xxx.exe -c config.txt -d 0
int main(int argc, char *argv[])
{
char options[] = "Cc:d:v";
char cfg[1024];
int front = 0;
int ret = 0;
int debug = 0;
//读取配置文件
while( (ret = win_getopt(argc, argv, options)) >= 0){
if(ret == 'c'){
sprintf(cfg, optarg);
}else if(ret == 'd'){
debug = atoi(optarg);
front = 1;
}else if(ret == 'C'){
}else if(ret == 'v'){
return(0);
}else if(ret == '?'){
if(ret == 'd'){
debug = atoi(optarg);
front = 1;
}
}
}
}
测试命令: xxx.exe -c config.txt -d 0
- windows版本的getopt
- Windows下的getopt
- Windows下的getopt(支持Unicode)
- getopt、getopt_long的可重入版本----linux交互式应用程序
- getopt library in windows
- windows遇到getopt
- getopt.cygwin.c,来自cygwin的getopt
- getopt()的初始化问题
- getopt的实现
- getopt函数的功能
- getopt函数的使用
- getopt函数的使用
- getopt的用法
- getopt 函数的用法
- getopt的用法
- getopt的使用
- getopt函数的使用
- getopt函数的使用
- 关于MYSQL 远程登录的授权方法 命令
- [实用工具] 方便好用的完整的ASCII码对照表,包含16进制和8进制对照。
- json = json || {}含义
- 关于GridView的思考
- FatMouse and Cheese_hdu_1078(记忆化搜索).java
- windows版本的getopt
- 用php获取本周,上周,本月,上月,本季度日期的代码
- Watch 窗口
- C# 文件/文件夹专栏
- Android二维码功能实现,在程序内嵌入ZXing项目
- 软件工程剖析
- uva 196
- Eclipse 非常有用命令
- Windows核心编程之 2 字符和字符串