void parse_options() { // Parse command line options, and update the environment to match the // specified options. argp->usage( "Usage: jgdoc [OPTIONS] FILE...\n" "Generates documentation from comments found in Jogo source files.\n\n" " -o, --output DIR Write output to DIR.\n" " -i, --include DIR Add the directory DIR to the search path.\n" " -h, --help Print this help message.\n" " -f, --format FORMAT Set output format to FORMAT.\n" " -v, --verbose Print extra information.\n" " --version Print the compiler version number.\n"); for (ArgToken tok = argp->next(); tok; tok = argp->next()) { // Convert abbreviated flags into the longer descriptive form (e.g., // convert -p to --path) if (ArgToken::SHORT == tok.type()) { parse_short_option(tok.value()); } else if (ArgToken::LONG == tok.type()) { parse_option(tok.value()); } else { env->input(tok.value()); } } std::string gen = env->generator(); if (gen != "Markdown") { argp->error("Invalid output format (options: Markdown"); } }
char ap_init( Arg_parser * ap, const int argc, const char * const argv[], const ap_Option options[], const char in_order ) { const char ** non_options = 0; // skipped non-options int non_options_size = 0; // number of skipped non-options int argind = 1; // index in argv int i; ap->data = 0; ap->error = 0; ap->data_size = 0; ap->error_size = 0; if( argc < 2 || !argv || !options ) { return 0; } while( argind < argc ) { const unsigned char ch1 = argv[argind][0]; const unsigned char ch2 = ( ch1 ? argv[argind][1] : 0 ); if( ch1 == '-' && ch2 ) // we found an option { const char * const opt = argv[argind]; const char * const arg = (argind + 1 < argc) ? argv[argind+1] : 0; if( ch2 == '-' ) { if( !argv[argind][2] ) { ++argind; break; } // we found "--" else if( !parse_long_option( ap, opt, arg, options, &argind ) ) return 0; } else if( !parse_short_option( ap, opt, arg, options, &argind ) ) return 0; if( ap->error ) break; } else { if( !in_order ) { if( !ap_resize_buffer( (void *)&non_options, ( non_options_size + 1 ) * sizeof( *non_options ) ) ) return 0; non_options[non_options_size++] = argv[argind++]; } else if( !push_back_record( ap, 0, argv[argind++] ) ) return 0; } } if( ap->error ) free_data( ap ); else { for( i = 0; i < non_options_size; ++i ) if( !push_back_record( ap, 0, non_options[i] ) ) return 0; while( argind < argc ) if( !push_back_record( ap, 0, argv[argind++] ) ) return 0; } if( non_options ) free( non_options ); return 1; }
Arg_parser( const int argc, const char * const argv[], const Option options[], const bool in_order = false ) { if( argc < 2 || !argv || !options ) return; std::vector< std::string > non_options; // skipped non-options int argind = 1; // index in argv while( argind < argc ) { const unsigned char ch1 = argv[argind][0]; const unsigned char ch2 = ( ch1 ? argv[argind][1] : 0 ); if( ch1 == '-' && ch2 ) // we found an option { const char * const opt = argv[argind]; const char * const arg = (argind + 1 < argc) ? argv[argind+1] : 0; if( ch2 == '-' ) { if( !argv[argind][2] ) { ++argind; // we found "--" break; } else if( !parse_long_option( opt, arg, options, argind ) ) break; } else if( !parse_short_option( opt, arg, options, argind ) ) break; } else { if( !in_order ) non_options.push_back( argv[argind++] ); else { data.push_back( Record() ); data.back().argument = argv[argind++]; } } } if( error_.size() ) data.clear(); else { for( unsigned i = 0; i < non_options.size(); ++i ) { data.push_back( Record() ); data.back().argument.swap( non_options[i] ); } while( argind < argc ) { data.push_back( Record() ); data.back().argument = argv[argind++]; } } }
// Parses command-line arguments into the global 'options' // struct. Returns false if the arguments are invalid. bool parse_options(int argc, char** argv) { options.always_scroll = false; options.blank = DEFAULT_BLANK; options.length = DEFAULT_LEN; options.reverse = false; options.tick = DEFAULT_TICK; int i = 1; while (i < argc) { char* arg = argv[i]; if (strlen(arg) < 2) return false; if (arg[0] == '-') { if (arg[1] == '-') { if (!parse_long_option(arg)) { printf("Invalid argument: '%s'\n", arg); return false; } i += 1; } else { size_t len = strlen(arg); char* next = (i < argc-1) ? argv[i+1] : NULL; uint8_t res; for (size_t c=1; c<len; c++) { res = parse_short_option(arg[c], next); if (res == 0 || (c < len-1 && res > 1)) { printf("Invalid argument or value for '-%c'\n", arg[c]); return false; } } i += res; } } else { printf("Invalid argument: '%s'\n", arg); return false; } } return true; }
Arg_parser::Arg_parser( const char * const opt, const char * const arg, const Option options[] ) throw() { if( !opt || !opt[0] || !options ) return; if( opt[0] == '-' && opt[1] ) // we found an option { int argind = 1; // dummy if( opt[1] == '-' ) { if( opt[2] ) parse_long_option( opt, arg, options, argind ); } else parse_short_option( opt, arg, options, argind ); if( _error.size() ) data.clear(); } else { data.push_back( Record() ); data.back().argument = opt; } }
void parse_options() { // Parse command line options, and update the environment to match the // specified options. argp->usage( "Usage: jogo [OPTIONS] FILE...\n\n" "Compiles Jogo source files into a library or executable.\n\n" " -a, --assembly Compile, but do not assemble or link.\n" " -c, --compile Compile and assemble, but do not link.\n" " -e, --execute Execute program as a script.\n" " -d, --debug Emit debug information.\n" " -l, --library LIB Compile and link with native library LIB.\n" " -i, --include DIR Add the directory DIR to the search path.\n" " -o, --output FILE Write compiler output to FILE.\n" " -m, --make Compile input files and out-of-date dependencies.\n" " -h, --help Print this help message.\n" " -v, --verbose Print extra information during compilation.\n" " -g, --generator GEN Use code generator GEN.\n" " --build-dir DIR Output directory for object files.\n" " --dump-ir Output the intermediate representation.\n" " --dump-ast Output the abstract syntax tree.\n" " --dump-liveness Output liveness info when printing the IR.\n" " --dump-regalloc Dump register allocations.\n" " --dump-reggraph Dump register interference graphs.\n" " --version Print the compiler version number.\n"); for (ArgToken tok = argp->next(); tok; tok = argp->next()) { // Convert abbreviated flags into the longer descriptive form (e.g., // convert -p to --path) if (ArgToken::SHORT == tok.type()) { parse_short_option(tok.value()); } else if (ArgToken::LONG == tok.type()) { parse_option(tok.value()); } else { env->input(tok.value()); } } std::string gen = env->generator(); if (gen != "Intel64" && gen != "C" && gen != "Nasm64") { argp->error("Invalid code generator (options: Intel64, NAsm64, C)"); } if (!env->inputs()) { argp->error("No input files."); } }
void parse_options() { // Parse command line options, and update the environment to match the // specified options. argp->usage( "Usage: jgmake [OPTIONS] PACKAGE...\n\n" "Builds a Jogo project from the current working directory. Source files should\n" "be under ./src; output files go to ./build, ./lib, ./bin, and ./doc. Options\n" "given to jgmake are recorded. After an option is set, it will remain set the\n" "next time jgmake is run.\n\n" " -l, --library LIB Compile and link with native library LIB.\n" " -i, --include DIR Add the directory DIR to the search path.\n" " -d, --debug Emit debug information.\n" " -o, --optimize Enable compiler optimizations.\n" " -g, --generator GEN Use code generator GEN.\n" " -h, --help Print this help message.\n" " -v, --verbose Print extra information during compilation.\n" " -r, --reset Erase all build options.\n" " -c, --clean Remove all output directories.\n" " --version Print the program version number.\n"); for (ArgToken tok = argp->next(); tok; tok = argp->next()) { // Convert abbreviated flags into the longer descriptive form (e.g., // convert -p to --path) if (ArgToken::SHORT == tok.type()) { parse_short_option(tok.value()); } else if (ArgToken::LONG == tok.type()) { parse_option(tok.value()); } else { env->input(tok.value()); } } std::string gen = env->generator(); if (gen != "Intel64" && gen != "C" && gen != "Nasm64") { argp->error("Invalid code generator (options: Intel64, Nasm64, C)"); } }