static rc_t get_int32_options( Args * args, const char * name, int32_t * value, bool * used ) { const char * s; rc_t rc = get_str_option( args, name, &s ); if ( rc == 0 && s != NULL ) { char *endp; *value = strtoi32( s, &endp, 0 ); if ( *endp != '\0' ) { rc = RC( rcExe, rcArgv, rcProcessing, rcParam, rcInvalid ); (void)PLOGERR( klogErr, ( klogErr, rc, "error converting string to integer option '$(t)'", "t=%s", name ) ); } else { *used = true; } } return rc; }
int options_parse(int argc, char *argv[], options_t *options) { int result = PQ_SUCCESS; int c, option_index; char *options_string = "hVvi:o:bp:zrmtn:"; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"print-every", required_argument, 0, 'p'}, {"file-in", required_argument, 0, 'i'}, {"file-out", required_argument, 0, 'o'}, {"binary-out", no_argument, 0, 'b'}, {"resolution-only", no_argument, 0, 'z'}, {"header-only", no_argument, 0, 'r'}, {"mode-only", no_argument, 0, 'm'}, {"to-t2", no_argument, 0, 't'}, {"number", required_argument, 0, 'n'}, {0, 0, 0, 0}}; while ( (c = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1 ) { switch (c) { case 'h': usage(); description(); result = PQ_USAGE; break; case 'v': verbose = 1; break; case 'V': version(); result = PQ_VERSION; break; case 'p': options->print_every = strtoi32(optarg, NULL, 10); break; case 'i': options->filename_in = strdup(optarg); break; case 'o': options->filename_out = strdup(optarg); break; case 'b': options->binary_out = 1; break; case 'z': options->print_resolution = 1; break; case 'r': options->print_header = 1; break; case 'm': options->print_mode = 1; break; case 't': options->to_t2 = 1; break; case 'n': options->number = strtoi64(optarg, NULL, 10); break; case '?': default: usage(); description(); result = PQ_ERROR_OPTIONS; } } return(result); }