]> Creatis software - creaImageIO.git/blob - appli/gimmick/gimmick_ggo.c
*** empty log message ***
[creaImageIO.git] / appli / gimmick / gimmick_ggo.c
1 /*
2   File autogenerated by gengetopt version 2.22
3   generated with the following command:
4   gengetopt --file-name=/home/guigues/coding/CreaTools/creaImageIO/appli/gimmick/gimmick_ggo -u --conf-parser 
5
6   The developers of gengetopt consider the fixed text that goes in all
7   gengetopt output files to be in the public domain:
8   we make no copyright claims on it.
9 */
10
11 /* If we use autoconf.  */
12 #ifdef HAVE_CONFIG_H
13 #include "config.h"
14 #endif
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "getopt.h"
21
22 #include "/home/guigues/coding/CreaTools/creaImageIO/appli/gimmick/gimmick_ggo.h"
23
24 const char *gengetopt_args_info_purpose = "";
25
26 const char *gengetopt_args_info_usage = "Usage: gimmick COMMAND [OPTIONS]";
27
28 const char *gengetopt_args_info_description = "";
29
30 const char *gengetopt_args_info_help[] = {
31   "  -h, --help              Print help and exit",
32   "  -V, --version           Print version and exit",
33   "\nCOMMANDS:",
34   "  -p, --print             Prints the local database tree  (default=off)",
35   "  -f, --file=<file name>  Adds the file to local database",
36   "  -d, --dir=<path>        Adds the directory to local database",
37   "  -r, --recurse           Recurse into sub-directories  (default=off)",
38   "\nOPTIONS:",
39   "  -v, --verbose=INT       Verbosity level  (default=`1')",
40     0
41 };
42
43 typedef enum {ARG_NO
44   , ARG_FLAG
45   , ARG_STRING
46   , ARG_INT
47 } cmdline_parser_arg_type;
48
49 static
50 void clear_given (struct gengetopt_args_info *args_info);
51 static
52 void clear_args (struct gengetopt_args_info *args_info);
53
54 static int
55 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
56                         struct cmdline_parser_params *params, const char *additional_error);
57
58 static int
59 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
60 struct line_list
61 {
62   char * string_arg;
63   struct line_list * next;
64 };
65
66 static struct line_list *cmd_line_list = 0;
67 static struct line_list *cmd_line_list_tmp = 0;
68
69 static void
70 free_cmd_list(void)
71 {
72   /* free the list of a previous call */
73   if (cmd_line_list)
74     {
75       while (cmd_line_list) {
76         cmd_line_list_tmp = cmd_line_list;
77         cmd_line_list = cmd_line_list->next;
78         free (cmd_line_list_tmp->string_arg);
79         free (cmd_line_list_tmp);
80       }
81     }
82 }
83
84
85 static char *
86 gengetopt_strdup (const char *s);
87
88 static
89 void clear_given (struct gengetopt_args_info *args_info)
90 {
91   args_info->help_given = 0 ;
92   args_info->version_given = 0 ;
93   args_info->print_given = 0 ;
94   args_info->file_given = 0 ;
95   args_info->dir_given = 0 ;
96   args_info->recurse_given = 0 ;
97   args_info->verbose_given = 0 ;
98 }
99
100 static
101 void clear_args (struct gengetopt_args_info *args_info)
102 {
103   args_info->print_flag = 0;
104   args_info->file_arg = NULL;
105   args_info->file_orig = NULL;
106   args_info->dir_arg = NULL;
107   args_info->dir_orig = NULL;
108   args_info->recurse_flag = 0;
109   args_info->verbose_arg = 1;
110   args_info->verbose_orig = NULL;
111   
112 }
113
114 static
115 void init_args_info(struct gengetopt_args_info *args_info)
116 {
117
118
119   args_info->help_help = gengetopt_args_info_help[0] ;
120   args_info->version_help = gengetopt_args_info_help[1] ;
121   args_info->print_help = gengetopt_args_info_help[3] ;
122   args_info->file_help = gengetopt_args_info_help[4] ;
123   args_info->dir_help = gengetopt_args_info_help[5] ;
124   args_info->recurse_help = gengetopt_args_info_help[6] ;
125   args_info->verbose_help = gengetopt_args_info_help[8] ;
126   
127 }
128
129 void
130 cmdline_parser_print_version (void)
131 {
132   printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
133 }
134
135 static void print_help_common(void) {
136   cmdline_parser_print_version ();
137
138   if (strlen(gengetopt_args_info_purpose) > 0)
139     printf("\n%s\n", gengetopt_args_info_purpose);
140
141   if (strlen(gengetopt_args_info_usage) > 0)
142     printf("\n%s\n", gengetopt_args_info_usage);
143
144   printf("\n");
145
146   if (strlen(gengetopt_args_info_description) > 0)
147     printf("%s\n", gengetopt_args_info_description);
148 }
149
150 void
151 cmdline_parser_print_help (void)
152 {
153   int i = 0;
154   print_help_common();
155   while (gengetopt_args_info_help[i])
156     printf("%s\n", gengetopt_args_info_help[i++]);
157 }
158
159 void
160 cmdline_parser_init (struct gengetopt_args_info *args_info)
161 {
162   clear_given (args_info);
163   clear_args (args_info);
164   init_args_info (args_info);
165
166   args_info->inputs = NULL;
167   args_info->inputs_num = 0;
168 }
169
170 void
171 cmdline_parser_params_init(struct cmdline_parser_params *params)
172 {
173   if (params)
174     { 
175       params->override = 0;
176       params->initialize = 1;
177       params->check_required = 1;
178       params->check_ambiguity = 0;
179       params->print_errors = 1;
180     }
181 }
182
183 struct cmdline_parser_params *
184 cmdline_parser_params_create(void)
185 {
186   struct cmdline_parser_params *params = 
187     (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
188   cmdline_parser_params_init(params);  
189   return params;
190 }
191
192 static void
193 free_string_field (char **s)
194 {
195   if (*s)
196     {
197       free (*s);
198       *s = 0;
199     }
200 }
201
202
203 static void
204 cmdline_parser_release (struct gengetopt_args_info *args_info)
205 {
206   unsigned int i;
207   free_string_field (&(args_info->file_arg));
208   free_string_field (&(args_info->file_orig));
209   free_string_field (&(args_info->dir_arg));
210   free_string_field (&(args_info->dir_orig));
211   free_string_field (&(args_info->verbose_orig));
212   
213   
214   for (i = 0; i < args_info->inputs_num; ++i)
215     free (args_info->inputs [i]);
216
217   if (args_info->inputs_num)
218     free (args_info->inputs);
219
220   clear_given (args_info);
221 }
222
223
224 static void
225 write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
226 {
227   if (arg) {
228     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
229   } else {
230     fprintf(outfile, "%s\n", opt);
231   }
232 }
233
234
235 int
236 cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
237 {
238   int i = 0;
239
240   if (!outfile)
241     {
242       fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
243       return EXIT_FAILURE;
244     }
245
246   if (args_info->help_given)
247     write_into_file(outfile, "help", 0, 0 );
248   if (args_info->version_given)
249     write_into_file(outfile, "version", 0, 0 );
250   if (args_info->print_given)
251     write_into_file(outfile, "print", 0, 0 );
252   if (args_info->file_given)
253     write_into_file(outfile, "file", args_info->file_orig, 0);
254   if (args_info->dir_given)
255     write_into_file(outfile, "dir", args_info->dir_orig, 0);
256   if (args_info->recurse_given)
257     write_into_file(outfile, "recurse", 0, 0 );
258   if (args_info->verbose_given)
259     write_into_file(outfile, "verbose", args_info->verbose_orig, 0);
260   
261
262   i = EXIT_SUCCESS;
263   return i;
264 }
265
266 int
267 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
268 {
269   FILE *outfile;
270   int i = 0;
271
272   outfile = fopen(filename, "w");
273
274   if (!outfile)
275     {
276       fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
277       return EXIT_FAILURE;
278     }
279
280   i = cmdline_parser_dump(outfile, args_info);
281   fclose (outfile);
282
283   return i;
284 }
285
286 void
287 cmdline_parser_free (struct gengetopt_args_info *args_info)
288 {
289   cmdline_parser_release (args_info);
290 }
291
292 /** @brief replacement of strdup, which is not standard */
293 char *
294 gengetopt_strdup (const char *s)
295 {
296   char *result = NULL;
297   if (!s)
298     return result;
299
300   result = (char*)malloc(strlen(s) + 1);
301   if (result == (char*)0)
302     return (char*)0;
303   strcpy(result, s);
304   return result;
305 }
306
307 int
308 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
309 {
310   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
311 }
312
313 int
314 cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info,
315                    struct cmdline_parser_params *params)
316 {
317   int result;
318   result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
319
320   if (result == EXIT_FAILURE)
321     {
322       cmdline_parser_free (args_info);
323       exit (EXIT_FAILURE);
324     }
325   
326   return result;
327 }
328
329 int
330 cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
331 {
332   int result;
333   struct cmdline_parser_params params;
334   
335   params.override = override;
336   params.initialize = initialize;
337   params.check_required = check_required;
338   params.check_ambiguity = 0;
339   params.print_errors = 1;
340
341   result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
342
343   if (result == EXIT_FAILURE)
344     {
345       cmdline_parser_free (args_info);
346       exit (EXIT_FAILURE);
347     }
348   
349   return result;
350 }
351
352 int
353 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
354 {
355   int result = EXIT_SUCCESS;
356
357   if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
358     result = EXIT_FAILURE;
359
360   if (result == EXIT_FAILURE)
361     {
362       cmdline_parser_free (args_info);
363       exit (EXIT_FAILURE);
364     }
365   
366   return result;
367 }
368
369 int
370 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
371 {
372   int error = 0;
373
374   /* checks for required options */
375   
376   /* checks for dependences among options */
377   if (args_info->recurse_given && ! args_info->dir_given)
378     {
379       fprintf (stderr, "%s: '--recurse' ('-r') option depends on option 'dir'%s\n", prog_name, (additional_error ? additional_error : ""));
380       error = 1;
381     }
382
383   return error;
384 }
385
386
387 static char *package_name = 0;
388
389 /**
390  * @brief updates an option
391  * @param field the generic pointer to the field to update
392  * @param orig_field the pointer to the orig field
393  * @param field_given the pointer to the number of occurrence of this option
394  * @param prev_given the pointer to the number of occurrence already seen
395  * @param value the argument for this option (if null no arg was specified)
396  * @param possible_values the possible values for this option (if specified)
397  * @param default_value the default value (in case the option only accepts fixed values)
398  * @param arg_type the type of this option
399  * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
400  * @param override @see cmdline_parser_params.override
401  * @param no_free whether to free a possible previous value
402  * @param multiple_option whether this is a multiple option
403  * @param long_opt the corresponding long option
404  * @param short_opt the corresponding short option (or '-' if none)
405  * @param additional_error possible further error specification
406  */
407 static
408 int update_arg(void *field, char **orig_field,
409                unsigned int *field_given, unsigned int *prev_given, 
410                char *value, char *possible_values[], const char *default_value,
411                cmdline_parser_arg_type arg_type,
412                int check_ambiguity, int override,
413                int no_free, int multiple_option,
414                const char *long_opt, char short_opt,
415                const char *additional_error)
416 {
417   char *stop_char = 0;
418   const char *val = value;
419   int found;
420   char **string_field;
421
422   stop_char = 0;
423   found = 0;
424
425   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
426     {
427       if (short_opt != '-')
428         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
429                package_name, long_opt, short_opt,
430                (additional_error ? additional_error : ""));
431       else
432         fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
433                package_name, long_opt,
434                (additional_error ? additional_error : ""));
435       return 1; /* failure */
436     }
437
438     
439   if (field_given && *field_given && ! override)
440     return 0;
441   if (prev_given)
442     (*prev_given)++;
443   if (field_given)
444     (*field_given)++;
445   if (possible_values)
446     val = possible_values[found];
447
448   switch(arg_type) {
449   case ARG_FLAG:
450     *((int *)field) = !*((int *)field);
451     break;
452   case ARG_INT:
453     if (val) *((int *)field) = strtol (val, &stop_char, 0);
454     break;
455   case ARG_STRING:
456     if (val) {
457       string_field = (char **)field;
458       if (!no_free && *string_field)
459         free (*string_field); /* free previous string */
460       *string_field = gengetopt_strdup (val);
461     }
462     break;
463   default:
464     break;
465   };
466
467   /* check numeric conversion */
468   switch(arg_type) {
469   case ARG_INT:
470     if (val && !(stop_char && *stop_char == '\0')) {
471       fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
472       return 1; /* failure */
473     }
474     break;
475   default:
476     ;
477   };
478
479   /* store the original value */
480   switch(arg_type) {
481   case ARG_NO:
482   case ARG_FLAG:
483     break;
484   default:
485     if (value && orig_field) {
486       if (no_free) {
487         *orig_field = value;
488       } else {
489         if (*orig_field)
490           free (*orig_field); /* free previous string */
491         *orig_field = gengetopt_strdup (value);
492       }
493     }
494   };
495
496   return 0; /* OK */
497 }
498
499
500 int
501 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
502                         struct cmdline_parser_params *params, const char *additional_error)
503 {
504   int c;        /* Character of the parsed option.  */
505
506   int error = 0;
507   struct gengetopt_args_info local_args_info;
508   
509   int override;
510   int initialize;
511   int check_required;
512   int check_ambiguity;
513   
514   package_name = argv[0];
515   
516   override = params->override;
517   initialize = params->initialize;
518   check_required = params->check_required;
519   check_ambiguity = params->check_ambiguity;
520
521   if (initialize)
522     cmdline_parser_init (args_info);
523
524   cmdline_parser_init (&local_args_info);
525
526   optarg = 0;
527   optind = 0;
528   opterr = params->print_errors;
529   optopt = '?';
530
531   while (1)
532     {
533       int option_index = 0;
534
535       static struct option long_options[] = {
536         { "help",       0, NULL, 'h' },
537         { "version",    0, NULL, 'V' },
538         { "print",      0, NULL, 'p' },
539         { "file",       1, NULL, 'f' },
540         { "dir",        1, NULL, 'd' },
541         { "recurse",    0, NULL, 'r' },
542         { "verbose",    1, NULL, 'v' },
543         { NULL, 0, NULL, 0 }
544       };
545
546       c = getopt_long (argc, argv, "hVpf:d:rv:", long_options, &option_index);
547
548       if (c == -1) break;       /* Exit from `while (1)' loop.  */
549
550       switch (c)
551         {
552         case 'h':       /* Print help and exit.  */
553           cmdline_parser_print_help ();
554           cmdline_parser_free (&local_args_info);
555           exit (EXIT_SUCCESS);
556
557         case 'V':       /* Print version and exit.  */
558           cmdline_parser_print_version ();
559           cmdline_parser_free (&local_args_info);
560           exit (EXIT_SUCCESS);
561
562         case 'p':       /* Prints the local database tree.  */
563         
564         
565           if (update_arg((void *)&(args_info->print_flag), 0, &(args_info->print_given),
566               &(local_args_info.print_given), optarg, 0, 0, ARG_FLAG,
567               check_ambiguity, override, 1, 0, "print", 'p',
568               additional_error))
569             goto failure;
570         
571           break;
572         case 'f':       /* Adds the file to local database.  */
573         
574         
575           if (update_arg( (void *)&(args_info->file_arg), 
576                &(args_info->file_orig), &(args_info->file_given),
577               &(local_args_info.file_given), optarg, 0, 0, ARG_STRING,
578               check_ambiguity, override, 0, 0,
579               "file", 'f',
580               additional_error))
581             goto failure;
582         
583           break;
584         case 'd':       /* Adds the directory to local database.  */
585         
586         
587           if (update_arg( (void *)&(args_info->dir_arg), 
588                &(args_info->dir_orig), &(args_info->dir_given),
589               &(local_args_info.dir_given), optarg, 0, 0, ARG_STRING,
590               check_ambiguity, override, 0, 0,
591               "dir", 'd',
592               additional_error))
593             goto failure;
594         
595           break;
596         case 'r':       /* Recurse into sub-directories.  */
597         
598         
599           if (update_arg((void *)&(args_info->recurse_flag), 0, &(args_info->recurse_given),
600               &(local_args_info.recurse_given), optarg, 0, 0, ARG_FLAG,
601               check_ambiguity, override, 1, 0, "recurse", 'r',
602               additional_error))
603             goto failure;
604         
605           break;
606         case 'v':       /* Verbosity level.  */
607         
608         
609           if (update_arg( (void *)&(args_info->verbose_arg), 
610                &(args_info->verbose_orig), &(args_info->verbose_given),
611               &(local_args_info.verbose_given), optarg, 0, "1", ARG_INT,
612               check_ambiguity, override, 0, 0,
613               "verbose", 'v',
614               additional_error))
615             goto failure;
616         
617           break;
618
619         case 0: /* Long option with no short option */
620         case '?':       /* Invalid option.  */
621           /* `getopt_long' already printed an error message.  */
622           goto failure;
623
624         default:        /* bug: option not considered.  */
625           fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
626           abort ();
627         } /* switch */
628     } /* while */
629
630
631
632   if (check_required)
633     {
634       error += cmdline_parser_required2 (args_info, argv[0], additional_error);
635     }
636
637   cmdline_parser_release (&local_args_info);
638
639   if ( error )
640     return (EXIT_FAILURE);
641
642   if (optind < argc)
643     {
644       int i = 0 ;
645       int found_prog_name = 0;
646       /* whether program name, i.e., argv[0], is in the remaining args
647          (this may happen with some implementations of getopt,
648           but surely not with the one included by gengetopt) */
649
650       i = optind;
651       while (i < argc)
652         if (argv[i++] == argv[0]) {
653           found_prog_name = 1;
654           break;
655         }
656       i = 0;
657
658       args_info->inputs_num = argc - optind - found_prog_name;
659       args_info->inputs =
660         (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
661       while (optind < argc)
662         if (argv[optind++] != argv[0])
663           args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
664     }
665
666   return 0;
667
668 failure:
669   
670   cmdline_parser_release (&local_args_info);
671   return (EXIT_FAILURE);
672 }
673
674 #ifndef CONFIG_FILE_LINE_SIZE
675 #define CONFIG_FILE_LINE_SIZE 2048
676 #endif
677 #define ADDITIONAL_ERROR " in configuration file "
678
679 #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
680 /* 3 is for "--" and "=" */
681
682 static int
683 _cmdline_parser_configfile (char * const filename, int *my_argc)
684 {
685   FILE* file;
686   char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
687   char linebuf[CONFIG_FILE_LINE_SIZE];
688   int line_num = 0;
689   int result = 0, equal;
690   char *fopt, *farg;
691   char *str_index;
692   size_t len, next_token;
693   char delimiter;
694
695   if ((file = fopen(filename, "r")) == NULL)
696     {
697       fprintf (stderr, "%s: Error opening configuration file '%s'\n",
698                CMDLINE_PARSER_PACKAGE, filename);
699       return EXIT_FAILURE;
700     }
701
702   while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
703     {
704       ++line_num;
705       my_argv[0] = '\0';
706       len = strlen(linebuf);
707       if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
708         {
709           fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
710                    CMDLINE_PARSER_PACKAGE, filename, line_num);
711           result = EXIT_FAILURE;
712           break;
713         }
714
715       /* find first non-whitespace character in the line */
716       next_token = strspn (linebuf, " \t\r\n");
717       str_index  = linebuf + next_token;
718
719       if ( str_index[0] == '\0' || str_index[0] == '#')
720         continue; /* empty line or comment line is skipped */
721
722       fopt = str_index;
723
724       /* truncate fopt at the end of the first non-valid character */
725       next_token = strcspn (fopt, " \t\r\n=");
726
727       if (fopt[next_token] == '\0') /* the line is over */
728         {
729           farg  = NULL;
730           equal = 0;
731           goto noarg;
732         }
733
734       /* remember if equal sign is present */
735       equal = (fopt[next_token] == '=');
736       fopt[next_token++] = '\0';
737
738       /* advance pointers to the next token after the end of fopt */
739       next_token += strspn (fopt + next_token, " \t\r\n");
740
741       /* check for the presence of equal sign, and if so, skip it */
742       if ( !equal )
743         if ((equal = (fopt[next_token] == '=')))
744           {
745             next_token++;
746             next_token += strspn (fopt + next_token, " \t\r\n");
747           }
748       str_index  += next_token;
749
750       /* find argument */
751       farg = str_index;
752       if ( farg[0] == '\"' || farg[0] == '\'' )
753         { /* quoted argument */
754           str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
755           if (! str_index)
756             {
757               fprintf
758                 (stderr,
759                  "%s:%s:%d: unterminated string in configuration file\n",
760                  CMDLINE_PARSER_PACKAGE, filename, line_num);
761               result = EXIT_FAILURE;
762               break;
763             }
764         }
765       else
766         { /* read up the remaining part up to a delimiter */
767           next_token = strcspn (farg, " \t\r\n#\'\"");
768           str_index += next_token;
769         }
770
771       /* truncate farg at the delimiter and store it for further check */
772       delimiter = *str_index, *str_index++ = '\0';
773
774       /* everything but comment is illegal at the end of line */
775       if (delimiter != '\0' && delimiter != '#')
776         {
777           str_index += strspn(str_index, " \t\r\n");
778           if (*str_index != '\0' && *str_index != '#')
779             {
780               fprintf
781                 (stderr,
782                  "%s:%s:%d: malformed string in configuration file\n",
783                  CMDLINE_PARSER_PACKAGE, filename, line_num);
784               result = EXIT_FAILURE;
785               break;
786             }
787         }
788
789     noarg:
790       if (!strcmp(fopt,"include")) {
791         if (farg && *farg) {
792           result = _cmdline_parser_configfile(farg, my_argc);
793         } else {
794           fprintf(stderr, "%s:%s:%d: include requires a filename argument.\n",
795                   CMDLINE_PARSER_PACKAGE, filename, line_num);
796         }
797         continue;
798       }
799       len = strlen(fopt);
800       strcat (my_argv, len > 1 ? "--" : "-");
801       strcat (my_argv, fopt);
802       if (len > 1 && ((farg && *farg) || equal))
803         strcat (my_argv, "=");
804       if (farg && *farg)
805         strcat (my_argv, farg);
806       ++(*my_argc);
807
808       cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
809       cmd_line_list_tmp->next = cmd_line_list;
810       cmd_line_list = cmd_line_list_tmp;
811       cmd_line_list->string_arg = gengetopt_strdup(my_argv);
812     } /* while */
813
814   if (file)
815     fclose(file);
816   return result;
817 }
818
819 int
820 cmdline_parser_configfile (char * const filename,
821                            struct gengetopt_args_info *args_info,
822                            int override, int initialize, int check_required)
823 {
824   struct cmdline_parser_params params;
825
826   params.override = override;
827   params.initialize = initialize;
828   params.check_required = check_required;
829   params.check_ambiguity = 0;
830   params.print_errors = 1;
831   
832   return cmdline_parser_config_file (filename, args_info, &params);
833 }
834
835 int
836 cmdline_parser_config_file (char * const filename,
837                            struct gengetopt_args_info *args_info,
838                            struct cmdline_parser_params *params)
839 {
840   int i, result;
841   int my_argc = 1;
842   char **my_argv_arg;
843   char *additional_error;
844
845   /* store the program name */
846   cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
847   cmd_line_list_tmp->next = cmd_line_list;
848   cmd_line_list = cmd_line_list_tmp;
849   cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_PACKAGE);
850
851   result = _cmdline_parser_configfile(filename, &my_argc);
852
853   if (result != EXIT_FAILURE) {
854     my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
855     cmd_line_list_tmp = cmd_line_list;
856
857     for (i = my_argc - 1; i >= 0; --i) {
858       my_argv_arg[i] = cmd_line_list_tmp->string_arg;
859       cmd_line_list_tmp = cmd_line_list_tmp->next;
860     }
861
862     my_argv_arg[my_argc] = 0;
863
864     additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
865     strcpy (additional_error, ADDITIONAL_ERROR);
866     strcat (additional_error, filename);
867     result =
868       cmdline_parser_internal (my_argc, my_argv_arg, args_info,
869                               params,
870                               additional_error);
871
872     free (additional_error);
873     free (my_argv_arg);
874   }
875
876   free_cmd_list();
877   if (result == EXIT_FAILURE)
878     {
879       cmdline_parser_free (args_info);
880       exit (EXIT_FAILURE);
881     }
882   
883   return result;
884 }