void AnyOption::addOption ( char opt, int type ) { if ( ! POSIX() ) { printVerbose("Ignoring the option character \""); printVerbose(opt); printVerbose("\" ( POSIX options are turned off )"); printVerbose(); return; } if ( optchar_counter >= max_char_options ) { if ( doubleCharStorage() == false ) { addOptionError(opt); return; } } optionchars[optchar_counter] = opt; optchartype[optchar_counter] = type; optcharindex[optchar_counter] = g_value_counter; optchar_counter ++; }
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(); } } }