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

cmdline.c

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

Generated on Fri Oct 8 20:34:47 2004 for LibOFX by doxygen 1.3.7