LibOFX: cmdline.c Source File

Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

# ofxdump/cmdline.c

    00001 /*
    00002   File autogenerated by gengetopt version 2.13
    00003   generated with the following command:
    00004   gengetopt --unamed-opts
    00005
    00006   The developers of gengetopt consider the fixed text that goes in all
    00007   gengetopt output files to be in the public domain:
    00008   we make no copyright claims on it.
    00009 */
    00010
    00011 /* If we use autoconf.  */
    00012 #ifdef HAVE_CONFIG_H
    00013 #include "config.h"
    00014 #endif
    00015
    00016 #include <stdio.h>
    00017 #include <stdlib.h>
    00018 #include <string.h>
    00019
    00020 #include "getopt.h"
    00021
    00022 #include "cmdline.h"
    00023
    00024 static
    00025 void clear_given (struct gengetopt_args_info *args_info);
    00026 static
    00027 void clear_args (struct gengetopt_args_info *args_info);
    00028
    00029 static int
    00030 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
    00031
    00032
    00033 static char *
    00034 gengetopt_strdup (const char *s);
    00035
    00036 static
    00037 void clear_given (struct gengetopt_args_info *args_info)
    00038 {
    00039   args_info->help_given = 0 ;
    00040   args_info->version_given = 0 ;
    00041   args_info->import_format_given = 0 ;
    00042   args_info->list_import_formats_given = 0 ;
    00043   args_info->msg_parser_given = 0 ;
    00044   args_info->msg_debug_given = 0 ;
    00045   args_info->msg_warning_given = 0 ;
    00046   args_info->msg_error_given = 0 ;
    00047   args_info->msg_info_given = 0 ;
    00048   args_info->msg_status_given = 0 ;
    00049 }
    00050
    00051 static
    00052 void clear_args (struct gengetopt_args_info *args_info)
    00053 {
    00054   args_info->import_format_arg = gengetopt_strdup ("AUTODETECT");
    00055   args_info->msg_parser_flag = 0;
    00056   args_info->msg_debug_flag = 0;
    00057   args_info->msg_warning_flag = 1;
    00058   args_info->msg_error_flag = 1;
    00059   args_info->msg_info_flag = 1;
    00060   args_info->msg_status_flag = 1;
    00061 }
    00062
    00063 void
    00064 cmdline_parser_print_version (void)
    00065 {
    00066   printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
    00067 }
    00068
    00069 void
    00070 cmdline_parser_print_help (void)
    00071 {
    00072   cmdline_parser_print_version ();
    00073   printf("\n%s\n", "ofxdump prints to stdout, in human readable form, everything the library \n understands about a particular file or response, and sends errors to \n stderr.  To know exactly what the library understands about of a particular\n ofx response file, just call ofxdump on that file.");
    00074   printf("\nUsage: %s [OPTIONS]... [FILES]...\n\n", CMDLINE_PARSER_PACKAGE);
    00075   printf("%s\n","  -h, --help                  Print help and exit");
    00076   printf("%s\n","  -V, --version               Print version and exit");
    00077   printf("%s\n","  -f, --import-format=STRING  Force the file format of the file(s) specified  \n                                (default=`AUTODETECT')");
    00078   printf("%s\n","      --list-import-formats   List available import file formats \n                                'import-format' command");
    00079   printf("%s\n","      --msg_parser            Output file parsing messages  (default=off)");
    00080   printf("%s\n","      --msg_debug             Output messages meant for debuging  (default=off)");
    00081   printf("%s\n","      --msg_warning           Output warning messages about abnormal conditions \n                                and unknown constructs  (default=on)");
    00082   printf("%s\n","      --msg_error             Output error messages  (default=on)");
    00083   printf("%s\n","      --msg_info              Output informational messages about the progress \n                                of the library  (default=on)");
    00084   printf("%s\n","      --msg_status            Output status messages  (default=on)");
    00085
    00086 }
    00087
    00088 void
    00089 cmdline_parser_init (struct gengetopt_args_info *args_info)
    00090 {
    00091   clear_given (args_info);
    00092   clear_args (args_info);
    00093
    00094   args_info->inputs = NULL;
    00095   args_info->inputs_num = 0;
    00096 }
    00097
    00098 void
    00099 cmdline_parser_free (struct gengetopt_args_info *args_info)
    00100 {
    00101
    00102   unsigned int i;
    00103   if (args_info->import_format_arg)
    00104     {
    00105       free (args_info->import_format_arg); /* free previous argument */
    00106       args_info->import_format_arg = 0;
    00107     }
    00108
    00109   for (i = 0; i < args_info->inputs_num; ++i)
    00110     free (args_info->inputs [i]);
    00111
    00112   if (args_info->inputs_num)
    00113     free (args_info->inputs);
    00114
    00115   clear_given (args_info);
    00116 }
    00117
    00118 /* gengetopt_strdup() */
    00119 /* strdup.c replacement of strdup, which is not standard */
    00120 char *
    00121 gengetopt_strdup (const char *s)
    00122 {
    00123   char *result = NULL;
    00124   if (!s)
    00125     return result;
    00126
    00127   result = (char*)malloc(strlen(s) + 1);
    00128   if (result == (char*)0)
    00129     return (char*)0;
    00130   strcpy(result, s);
    00131   return result;
    00132 }
    00133
    00134 int
    00135 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
    00136 {
    00137   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
    00138 }
    00139
    00140 int
    00141 cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
    00142 {
    00143   int result;
    00144
    00145   result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
    00146
    00147   if (result == EXIT_FAILURE)
    00148     {
    00149       cmdline_parser_free (args_info);
    00150       exit (EXIT_FAILURE);
    00151     }
    00152
    00153   return result;
    00154 }
    00155
    00156 int
    00157 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
    00158 {
    00159   return EXIT_SUCCESS;
    00160 }
    00161
    00162 int
    00163 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
    00164 {
    00165   int c;        /* Character of the parsed option.  */
    00166
    00167   int error = 0;
    00168   struct gengetopt_args_info local_args_info;
    00169
    00170   if (initialize)
    00171     cmdline_parser_init (args_info);
    00172
    00173   cmdline_parser_init (&local_args_info);
    00174
    00175   optarg = 0;
    00176   optind = 1;
    00177   opterr = 1;
    00178   optopt = '?';
    00179
    00180   while (1)
    00181     {
    00182       int option_index = 0;
    00183       char *stop_char;
    00184
    00185       static struct option long_options[] = {
    00186         { "help",       0, NULL, 'h' },
    00187         { "version",    0, NULL, 'V' },
    00188         { "import-format",      1, NULL, 'f' },
    00189         { "list-import-formats",        0, NULL, 0 },
    00190         { "msg_parser", 0, NULL, 0 },
    00191         { "msg_debug",  0, NULL, 0 },
    00192         { "msg_warning",        0, NULL, 0 },
    00193         { "msg_error",  0, NULL, 0 },
    00194         { "msg_info",   0, NULL, 0 },
    00195         { "msg_status", 0, NULL, 0 },
    00196         { NULL, 0, NULL, 0 }
    00197       };
    00198
    00199       stop_char = 0;
    00200       c = getopt_long (argc, argv, "hVf:", long_options, &option_index);
    00201
    00202       if (c == -1) break;       /* Exit from `while (1)' loop.  */
    00203
    00204       switch (c)
    00205         {
    00206         case 'h':       /* Print help and exit.  */
    00207           cmdline_parser_print_help ();
    00208           exit (EXIT_SUCCESS);
    00209
    00210         case 'V':       /* Print version and exit.  */
    00211           cmdline_parser_print_version ();
    00212           exit (EXIT_SUCCESS);
    00213
    00214         case 'f':       /* Force the file format of the file(s) specified.  */
    00215           if (local_args_info.import_format_given)
    00216             {
    00217               fprintf (stderr, "%s: `--import-format' (`-f') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
    00218               goto failure;
    00219             }
    00220           if (args_info->import_format_given && ! override)
    00221             continue;
    00222           local_args_info.import_format_given = 1;
    00223           args_info->import_format_given = 1;
    00224           if (args_info->import_format_arg)
    00225             free (args_info->import_format_arg); /* free previous string */
    00226           args_info->import_format_arg = gengetopt_strdup (optarg);
    00227           break;
    00228
    00229
    00230         case 0: /* Long option with no short option */
    00231           /* List available import file formats 'import-format' command.  */
    00232           if (strcmp (long_options[option_index].name, "list-import-formats") == 0)
    00233           {
    00234             if (local_args_info.list_import_formats_given)
    00235               {
    00236                 fprintf (stderr, "%s: `--list-import-formats' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
    00237                 goto failure;
    00238               }
    00239             if (args_info->list_import_formats_given && ! override)
    00240               continue;
    00241             local_args_info.list_import_formats_given = 1;
    00242             args_info->list_import_formats_given = 1;
    00243             break;
    00244           }
    00245           /* Output file parsing messages.  */
    00246           else if (strcmp (long_options[option_index].name, "msg_parser") == 0)
    00247           {
    00248             if (local_args_info.msg_parser_given)
    00249               {
    00250                 fprintf (stderr, "%s: `--msg_parser' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
    00251                 goto failure;
    00252               }
    00253             if (args_info->msg_parser_given && ! override)
    00254               continue;
    00255             local_args_info.msg_parser_given = 1;
    00256             args_info->msg_parser_given = 1;
    00257             args_info->msg_parser_flag = !(args_info->msg_parser_flag);
    00258           }
    00259           /* Output messages meant for debuging.  */
    00260           else if (strcmp (long_options[option_index].name, "msg_debug") == 0)
    00261           {
    00262             if (local_args_info.msg_debug_given)
    00263               {
    00264                 fprintf (stderr, "%s: `--msg_debug' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
    00265                 goto failure;
    00266               }
    00267             if (args_info->msg_debug_given && ! override)
    00268               continue;
    00269             local_args_info.msg_debug_given = 1;
    00270             args_info->msg_debug_given = 1;
    00271             args_info->msg_debug_flag = !(args_info->msg_debug_flag);
    00272           }
    00273           /* Output warning messages about abnormal conditions and unknown constructs.  */
    00274           else if (strcmp (long_options[option_index].name, "msg_warning") == 0)
    00275           {
    00276             if (local_args_info.msg_warning_given)
    00277               {
    00278                 fprintf (stderr, "%s: `--msg_warning' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
    00279                 goto failure;
    00280               }
    00281             if (args_info->msg_warning_given && ! override)
    00282               continue;
    00283             local_args_info.msg_warning_given = 1;
    00284             args_info->msg_warning_given = 1;
    00285             args_info->msg_warning_flag = !(args_info->msg_warning_flag);
    00286           }
    00287           /* Output error messages.  */
    00288           else if (strcmp (long_options[option_index].name, "msg_error") == 0)
    00289           {
    00290             if (local_args_info.msg_error_given)
    00291               {
    00292                 fprintf (stderr, "%s: `--msg_error' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
    00293                 goto failure;
    00294               }
    00295             if (args_info->msg_error_given && ! override)
    00296               continue;
    00297             local_args_info.msg_error_given = 1;
    00298             args_info->msg_error_given = 1;
    00299             args_info->msg_error_flag = !(args_info->msg_error_flag);
    00300           }
    00301           /* Output informational messages about the progress of the library.  */
    00302           else if (strcmp (long_options[option_index].name, "msg_info") == 0)
    00303           {
    00304             if (local_args_info.msg_info_given)
    00305               {
    00306                 fprintf (stderr, "%s: `--msg_info' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
    00307                 goto failure;
    00308               }
    00309             if (args_info->msg_info_given && ! override)
    00310               continue;
    00311             local_args_info.msg_info_given = 1;
    00312             args_info->msg_info_given = 1;
    00313             args_info->msg_info_flag = !(args_info->msg_info_flag);
    00314           }
    00315           /* Output status messages.  */
    00316           else if (strcmp (long_options[option_index].name, "msg_status") == 0)
    00317           {
    00318             if (local_args_info.msg_status_given)
    00319               {
    00320                 fprintf (stderr, "%s: `--msg_status' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
    00321                 goto failure;
    00322               }
    00323             if (args_info->msg_status_given && ! override)
    00324               continue;
    00325             local_args_info.msg_status_given = 1;
    00326             args_info->msg_status_given = 1;
    00327             args_info->msg_status_flag = !(args_info->msg_status_flag);
    00328           }
    00329
    00330           break;
    00331         case '?':       /* Invalid option.  */
    00332           /* `getopt_long' already printed an error message.  */
    00333           goto failure;
    00334
    00335         default:        /* bug: option not considered.  */
    00336           fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
    00337           abort ();
    00338         } /* switch */
    00339     } /* while */
    00340
    00341
    00342
    00343
    00344   cmdline_parser_free (&local_args_info);
    00345
    00346   if ( error )
    00347     return (EXIT_FAILURE);
    00348
    00349   if (optind < argc)
    00350     {
    00351       int i = 0 ;
    00352
    00353       args_info->inputs_num = argc - optind ;
    00354       args_info->inputs =
    00355         (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
    00356       while (optind < argc)
    00357         args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
    00358     }
    00359
    00360   return 0;
    00361
    00362 failure:
    00363
    00364   cmdline_parser_free (&local_args_info);
    00365   return (EXIT_FAILURE);
    00366 }