コード例 #1
0
ファイル: anyoption.cpp プロジェクト: scadding/MyUniverse
void
AnyOption::processCommandArgs()
{
    if(!(valueStoreOK() && CommandSet())) {
        return;
    }

    if(max_legal_args == 0) {
        max_legal_args = argc;
    }
    new_argv = (int*) malloc((max_legal_args+1) * sizeof(int));
    for(int i = 1 ; i < argc ; i++) { /* ignore first argv */
        if(argv[i][0] == long_opt_prefix[0] &&
           argv[i][1] == long_opt_prefix[1]) {  /* long GNU option */
            int match_at = parseGNU(argv[i]+2);   /* skip -- */
            if(match_at >= 0 && i < argc-1) { /* found match */
                setValue(options[match_at], argv[++i]);
            }
        } else if(argv[i][0] ==  opt_prefix_char) {   /* POSIX char */
            if(POSIX()) {
                char ch =  parsePOSIX(argv[i]+1);  /* skip - */
                if(ch != '0' && i < argc-1) { /* matching char */
                    setValue(ch,  argv[++i]);
                }
            } else { /* treat it as GNU option with a - */
                int match_at = parseGNU(argv[i]+1);   /* skip - */
                if(match_at >= 0 && i < argc-1) { /* found match */
                    setValue(options[match_at], argv[++i]);
                }
            }
        } else { /* not option but an argument keep index */
            if(new_argc < max_legal_args) {
                new_argv[ new_argc ] = i ;
                new_argc++;
            } else { /* ignore extra arguments */
                printVerbose("Ignoring extra argument: ");
                printVerbose(argv[i]);
                printVerbose();
                printAutoUsage();
            }
            printVerbose("Unknown command argument option : ");
            printVerbose(argv[i]);
            printVerbose();
            printAutoUsage();
        }
    }
}
コード例 #2
0
ファイル: program_options_lite.cpp プロジェクト: Kosyl/HEVC
    list<const char*>
    scanArgv(Options& opts, unsigned argc, const char* argv[])
    {
      /* a list for anything that didn't get handled as an option */
      list<const char*> non_option_arguments;

      for(unsigned i = 1; i < argc; i++)
      {
        if (argv[i][0] != '-')
        {
          non_option_arguments.push_back(argv[i]);
          continue;
        }

        if (argv[i][1] == 0)
        {
          /* a lone single dash is an argument (usually signifying stdin) */
          non_option_arguments.push_back(argv[i]);
          continue;
        }

        if (argv[i][1] != '-')
        {
          /* handle short (single dash) options */
#if 0
          i += parsePOSIX(opts, argc - i, &argv[i]);
#else
          i += parseSHORT(opts, argc - i, &argv[i]);
#endif
          continue;
        }

        if (argv[i][2] == 0)
        {
          /* a lone double dash ends option processing */
          while (++i < argc)
            non_option_arguments.push_back(argv[i]);
          break;
        }

        /* handle long (double dash) options */
        i += parseGNU(opts, argc - i, &argv[i]);
      }

      return non_option_arguments;
    }