21 #define FIX_UNUSED(X) (void) (X)
28 const char *
gengetopt_args_info_purpose =
"ofxdump prints to stdout, in human readable form, everything the library \nunderstands about a particular file or response, and sends errors to\nstderr. To know exactly what the library understands about of a particular\nofx response file, just call ofxdump on that file.";
32 const char *gengetopt_args_info_versiontext =
"";
37 " -h, --help Print help and exit",
38 " -V, --version Print version and exit",
39 " -f, --import-format=STRING Force the file format of the file(s) specified\n (default=`AUTODETECT')",
40 " --list-import-formats List available import file formats\n 'import-format' command",
41 " --msg_parser Output file parsing messages (default=off)",
42 " --msg_debug Output messages meant for debugging\n (default=off)",
43 " --msg_warning Output warning messages about abnormal conditions\n and unknown constructs (default=on)",
44 " --msg_error Output error messages (default=on)",
45 " --msg_info Output informational messages about the progress\n of the library (default=on)",
46 " --msg_status Output status messages (default=on)",
53 } cmdline_parser_arg_type;
66 gengetopt_strdup (
const char *s);
86 FIX_UNUSED (args_info);
123 if (strlen(gengetopt_args_info_versiontext) > 0)
124 printf(
"\n%s\n", gengetopt_args_info_versiontext);
127 static void print_help_common(
void) {
154 clear_given (args_info);
155 clear_args (args_info);
156 init_args_info (args_info);
185 free_string_field (
char **s)
204 free (args_info->
inputs [i]);
209 clear_given (args_info);
214 write_into_file(FILE *outfile,
const char *opt,
const char *arg,
const char *values[])
218 fprintf(outfile,
"%s=\"%s\"\n", opt, arg);
220 fprintf(outfile,
"%s\n", opt);
237 write_into_file(outfile,
"help", 0, 0 );
239 write_into_file(outfile,
"version", 0, 0 );
243 write_into_file(outfile,
"list-import-formats", 0, 0 );
245 write_into_file(outfile,
"msg_parser", 0, 0 );
247 write_into_file(outfile,
"msg_debug", 0, 0 );
249 write_into_file(outfile,
"msg_warning", 0, 0 );
251 write_into_file(outfile,
"msg_error", 0, 0 );
253 write_into_file(outfile,
"msg_info", 0, 0 );
255 write_into_file(outfile,
"msg_status", 0, 0 );
268 outfile = fopen(filename,
"w");
285 cmdline_parser_release (args_info);
290 gengetopt_strdup (
const char *s)
296 result = (
char*)malloc(strlen(s) + 1);
297 if (result == (
char*)0)
314 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
316 if (result == EXIT_FAILURE)
337 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
339 if (result == EXIT_FAILURE)
351 FIX_UNUSED (args_info);
352 FIX_UNUSED (prog_name);
357 static char *package_name = 0;
378 int update_arg(
void *field,
char **orig_field,
379 unsigned int *field_given,
unsigned int *prev_given,
380 char *value,
const char *possible_values[],
381 const char *default_value,
382 cmdline_parser_arg_type arg_type,
384 int no_free,
int multiple_option,
385 const char *long_opt,
char short_opt,
386 const char *additional_error)
389 const char *val = value;
397 if (!multiple_option && prev_given && (*prev_given || (
check_ambiguity && *field_given)))
399 if (short_opt !=
'-')
400 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
401 package_name, long_opt, short_opt,
402 (additional_error ? additional_error :
""));
404 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
405 package_name, long_opt,
406 (additional_error ? additional_error :
""));
410 FIX_UNUSED (default_value);
412 if (field_given && *field_given && !
override)
419 val = possible_values[found];
423 *((
int *)field) = !*((
int *)field);
427 string_field = (
char **)field;
428 if (!no_free && *string_field)
429 free (*string_field);
430 *string_field = gengetopt_strdup (val);
444 if (value && orig_field) {
450 *orig_field = gengetopt_strdup (value);
460 cmdline_parser_internal (
466 int error_occurred = 0;
474 package_name = argv[0];
493 int option_index = 0;
495 static struct option long_options[] = {
496 {
"help", 0, NULL,
'h' },
497 {
"version", 0, NULL,
'V' },
498 {
"import-format", 1, NULL,
'f' },
499 {
"list-import-formats", 0, NULL, 0 },
500 {
"msg_parser", 0, NULL, 0 },
501 {
"msg_debug", 0, NULL, 0 },
502 {
"msg_warning", 0, NULL, 0 },
503 {
"msg_error", 0, NULL, 0 },
504 {
"msg_info", 0, NULL, 0 },
505 {
"msg_status", 0, NULL, 0 },
509 c = getopt_long (argc, argv,
"hVf:", long_options, &option_index);
530 &(local_args_info.import_format_given), optarg, 0,
"AUTODETECT", ARG_STRING,
531 check_ambiguity,
override, 0, 0,
532 "import-format",
'f',
540 if (strcmp (long_options[option_index].name,
"list-import-formats") == 0)
546 &(local_args_info.list_import_formats_given), optarg, 0, 0, ARG_NO,
547 check_ambiguity,
override, 0, 0,
548 "list-import-formats",
'-',
554 else if (strcmp (long_options[option_index].name,
"msg_parser") == 0)
559 &(local_args_info.msg_parser_given), optarg, 0, 0, ARG_FLAG,
560 check_ambiguity,
override, 1, 0,
"msg_parser",
'-',
566 else if (strcmp (long_options[option_index].name,
"msg_debug") == 0)
571 &(local_args_info.msg_debug_given), optarg, 0, 0, ARG_FLAG,
572 check_ambiguity,
override, 1, 0,
"msg_debug",
'-',
578 else if (strcmp (long_options[option_index].name,
"msg_warning") == 0)
583 &(local_args_info.msg_warning_given), optarg, 0, 0, ARG_FLAG,
584 check_ambiguity,
override, 1, 0,
"msg_warning",
'-',
590 else if (strcmp (long_options[option_index].name,
"msg_error") == 0)
595 &(local_args_info.msg_error_given), optarg, 0, 0, ARG_FLAG,
596 check_ambiguity,
override, 1, 0,
"msg_error",
'-',
602 else if (strcmp (long_options[option_index].name,
"msg_info") == 0)
607 &(local_args_info.msg_info_given), optarg, 0, 0, ARG_FLAG,
608 check_ambiguity,
override, 1, 0,
"msg_info",
'-',
614 else if (strcmp (long_options[option_index].name,
"msg_status") == 0)
619 &(local_args_info.msg_status_given), optarg, 0, 0, ARG_FLAG,
620 check_ambiguity,
override, 1, 0,
"msg_status",
'-',
632 fprintf (stderr,
"%s: option unknown: %c%s\n",
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
640 cmdline_parser_release (&local_args_info);
642 if ( error_occurred )
643 return (EXIT_FAILURE);
648 int found_prog_name = 0;
655 if (argv[i++] == argv[0]) {
661 args_info->
inputs_num = argc - optind - found_prog_name;
663 (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
664 while (optind < argc)
665 if (argv[optind++] != argv[0])
666 args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
673 cmdline_parser_release (&local_args_info);
674 return (EXIT_FAILURE);