# getopt **Repository Path**: franck_li/getopt ## Basic Information - **Project Name**: getopt - **Description**: windows下命令行解析工具,同linux下getopt - **Primary Language**: C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1 - **Created**: 2020-08-04 - **Last Updated**: 2021-05-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # getopt #### 介绍 命令行解析工具 #### 软件架构 软件架构说明 #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 std::unordered_set ignoreArgList; std::string timestamp; std::string sign; int opt; int val; int option_index = 0; static char option_string[] = "-:t:s:"; //':' or use opterr=0 to close error print static option long_options[] = { {"timestamp", required_argument, &val, 1}, {"sign", required_argument, &val, 2}, {NULL, 0, NULL, 0}, }; while((opt = getopt_long_only(argc, argv, option_string, long_options, &option_index)) != -1) { // printf("opterr = %d\t\t", opterr); // printf("opt = %c\t\t", opt); // printf("optarg = %s\t\t",optarg); // printf("optind = %d\t\t",optind); // printf("argv[optind] =%s\t\t", argv[optind]); // printf("option_index = %d\n",option_index); switch(opt) { case 0: //printf("long option value:%d\n", val); switch (val) { case 1: timestamp = optarg; ignoreArgList.insert(optind - 2); ignoreArgList.insert(optind - 1); break; case 2: sign = optarg; ignoreArgList.insert(optind - 2); ignoreArgList.insert(optind - 1); break; } break; //handle short option, because t/s short option will cover the timestamp and sign long option case 't': case 's': //printf("short option(-%c):%s\n", opt,optarg); break; case '?': break; } } optind = 0; //restore the optind for next getopt caller printf("timestamp:%s, sign:%s\n", timestamp.c_str(), sign.c_str()); #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 码云特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. 码云官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解码云上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是码云最有价值开源项目,是码云综合评定出的优秀开源项目 5. 码云官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. 码云封面人物是一档用来展示码云会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)