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.";
30 const char *gengetopt_args_info_usage =
"Usage: " CMDLINE_PARSER_PACKAGE
" [OPTIONS]... [FILES]...";
32 const char *gengetopt_args_info_versiontext =
"";
34 const char *gengetopt_args_info_description =
"";
36 const char *gengetopt_args_info_help[] = {
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 debuging (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);
103 args_info->
help_help = gengetopt_args_info_help[0] ;
117 cmdline_parser_print_version (
void)
120 (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
121 CMDLINE_PARSER_VERSION);
123 if (strlen(gengetopt_args_info_versiontext) > 0)
124 printf(
"\n%s\n", gengetopt_args_info_versiontext);
127 static void print_help_common(
void) {
128 cmdline_parser_print_version ();
130 if (strlen(gengetopt_args_info_purpose) > 0)
131 printf(
"\n%s\n", gengetopt_args_info_purpose);
133 if (strlen(gengetopt_args_info_usage) > 0)
134 printf(
"\n%s\n", gengetopt_args_info_usage);
138 if (strlen(gengetopt_args_info_description) > 0)
139 printf(
"%s\n\n", gengetopt_args_info_description);
143 cmdline_parser_print_help (
void)
147 while (gengetopt_args_info_help[i])
148 printf(
"%s\n", gengetopt_args_info_help[i++]);
154 clear_given (args_info);
155 clear_args (args_info);
156 init_args_info (args_info);
176 cmdline_parser_params_create(
void)
180 cmdline_parser_params_init(params);
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);
232 fprintf (stderr,
"%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
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");
272 fprintf (stderr,
"%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
276 i = cmdline_parser_dump(outfile, args_info);
285 cmdline_parser_release (args_info);
290 gengetopt_strdup (
const char *s)
296 result = (
char*)malloc(strlen(s) + 1);
297 if (result == (
char*)0)
306 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
314 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
316 if (result == EXIT_FAILURE)
318 cmdline_parser_free (args_info);
337 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
339 if (result == EXIT_FAILURE)
341 cmdline_parser_free (args_info);
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];
482 cmdline_parser_init (args_info);
484 cmdline_parser_init (&local_args_info);
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);
516 cmdline_parser_print_help ();
517 cmdline_parser_free (&local_args_info);
521 cmdline_parser_print_version ();
522 cmdline_parser_free (&local_args_info);
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);
int override
whether to override possibly already present options (default 0)
int msg_info_flag
Output informational messages about the progress of the library (default=on).
int initialize
whether to initialize the option structure gengetopt_args_info (default 1)
const char * msg_status_help
Output status messages help description.
int msg_warning_flag
Output warning messages about abnormal conditions and unknown constructs (default=on).
char * import_format_arg
Force the file format of the file(s) specified (default='AUTODETECT').
unsigned int msg_warning_given
Whether msg_warning was given.
Where the command line options are stored.
unsigned int msg_error_given
Whether msg_error was given.
unsigned int help_given
Whether help was given.
unsigned int msg_debug_given
Whether msg_debug was given.
unsigned int msg_status_given
Whether msg_status was given.
unsigned int msg_parser_given
Whether msg_parser was given.
int msg_debug_flag
Output messages meant for debuging (default=off).
unsigned int list_import_formats_given
Whether list-import-formats was given.
const char * msg_parser_help
Output file parsing messages help description.
The additional parameters to pass to parser functions.
const char * list_import_formats_help
List available import file formats 'import-format' command help description.
unsigned int import_format_given
Whether import-format was given.
const char * version_help
Print version and exit help description.
char * import_format_orig
Force the file format of the file(s) specified original value given at command line.
const char * msg_error_help
Output error messages help description.
const char * import_format_help
Force the file format of the file(s) specified help description.
const char * help_help
Print help and exit help description.
int msg_error_flag
Output error messages (default=on).
const char * msg_debug_help
Output messages meant for debuging help description.
unsigned inputs_num
unamed options number
int msg_status_flag
Output status messages (default=on).
int msg_parser_flag
Output file parsing messages (default=off).
int print_errors
whether getopt_long should print an error message for a bad option (default 1)
int check_ambiguity
whether to check for options already specified in the option structure gengetopt_args_info (default 0...
int check_required
whether to check that all required options were provided (default 1)
const char * msg_info_help
Output informational messages about the progress of the library help description. ...
unsigned int msg_info_given
Whether msg_info was given.
char ** inputs
unamed options (options without names)
const char * msg_warning_help
Output warning messages about abnormal conditions and unknown constructs help description.
unsigned int version_given
Whether version was given.