]> Creatis software - clitk.git/blob - utilities/gengetopt/cmdline.c
Sync gengetopt cmake files with rtk
[clitk.git] / utilities / gengetopt / cmdline.c
1 /*
2   File autogenerated by gengetopt version 2.22.4
3   generated with the following command:
4   ../src/gengetopt --input=../../src/cmdline.ggo --output-dir=../../src --no-handle-version --no-handle-help --no-handle-error --string-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 #ifndef FIX_UNUSED
21 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22 #endif
23
24 #include <getopt.h>
25
26 #include "cmdline.h"
27
28 const char *gengetopt_args_info_purpose = "This program generates a C function that uses getopt_long function\nto parse the command line options, validate them and fill a struct.";
29
30 const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]...";
31
32 const char *gengetopt_args_info_description = "";
33
34 const char *gengetopt_args_info_detailed_help[] = {
35   "  -h, --help                    Print help and exit",
36   "      --detailed-help           Print help, including all details and hidden \n                                  options, and exit",
37   "  -V, --version                 Print version and exit",
38   "\nMain options:",
39   "",
40   "  -i, --input=filename          input file (default std input)",
41   "  -f, --func-name=name          name of generated function  \n                                  (default=`cmdline_parser')",
42   "  -a, --arg-struct-name=name    name of generated args info struct  \n                                  (default=`gengetopt_args_info')",
43   "  -F, --file-name=name          name of generated file  (default=`cmdline')",
44   "      --output-dir=path         output directory",
45   "  \n  if this option is not specified, the files are generated in the current \n  directory.\n",
46   "      --header-output-dir=path  header output directory",
47   "      --src-output-dir=path     source output directory",
48   "  -c, --c-extension=ext         extension of c file  (default=`c')",
49   "  -H, --header-extension=ext    extension of header file  (default=`h')",
50   "  -l, --long-help               long usage line in help",
51   "  \n  The usage line will print all the options, e.g.,\n\n  sample1 -iINT|--int-opt=INT [-h|--help]\n",
52   "      --default-optional        by default, an option is considered optional if \n                                  not specified otherwise",
53   "  -u, --unamed-opts[=STRING]    accept options without names (e.g., file names) \n                                   (default=`FILES')",
54   "\nThe parser generated is thought to be used to parse the command line arguments. \nHowever, you can also generate parsers for configuration files, or strings that \ncontain the arguments to parse, by using the following two options.\n",
55   "  -C, --conf-parser             generate a config file parser",
56   "  -S, --string-parser           generate a string parser (the string contains \n                                  the command line)",
57   "",
58   "\nAdditional options:",
59   "  -G, --include-getopt          adds the code for getopt_long in the generated \n                                  C file",
60   "  -n, --no-handle-help          do not handle --help|-h automatically",
61   "  \n  If --no-handle-help is specified, the command line option --help|-h will not \n  be handled automatically, so the programmer will be able to print some other \n  information; then the function for printing the standard help output can be \n  used; this function is called <parser-name>_print_help.\n\n  Notice that, although the programmer can handle --help|-h manually, the \n  parser will return after finding such option: the other command line options, \n  if any, will be ignored.  In case you want to have full control on --help|-h, \n  you should use --ho-help.\n",
62   "      --no-help                 do not add --help|-h automatically",
63   "  \n  With this option you can disable the automatic addition of options --help|-h. \n  The programmer will then be able to add this option in the input file and \n  handle it as he sees fit.  Notice that --no-help will also disable the \n  automatic options --detailed-help and --full-help.\n\n  The programmer can still define options with short character h as he wants, \n  but he cannot define options help, unless he specifies --no-help (otherwise \n  an error will be printed).\n",
64   "  -N, --no-handle-version       do not handle --version|-V automatically",
65   "      --no-version              do not add --version|-V automatically",
66   "  \n  See above the details about --no-handle-help and --no-help, respectively.\n",
67   "  -e, --no-handle-error         do not exit on errors",
68   "  \n  With this option, if the generated parser encounters an error (e.g., an \n  unknown option) it does not make the main program exit; instead, the parser \n  function returns a value different 0, and the main program can print a help \n  message.\n",
69   "      --show-required[=STRING]  in the output of help will specify which \n                                  options are mandatory, by using the optional \n                                  passed string  (default=`(mandatory)')",
70   "  -g, --gen-version             put gengetopt version in the generated file  \n                                  (default=on)",
71   "      --set-package=STRING      set the package name (override package defined \n                                  in the .ggo file)",
72   "      --set-version=STRING      set the version number (override version \n                                  defined in the .ggo file)",
73   "      --show-help               show the output of --help instead of generating \n                                  code",
74   "      --show-full-help          show the output of --full-help (i.e., including \n                                  hidden options) instead of generating code",
75   "      --show-detailed-help      show the output of --detailed-help (i.e., \n                                  including details and hidden options) instead \n                                  of generating code",
76   "      --show-version            show the output of --version instead of \n                                  generating code",
77   "\nPlease refer to the info manual for further explanations.",
78     0
79 };
80
81 static void
82 init_help_array(void)
83 {
84   gengetopt_args_info_help[0] = gengetopt_args_info_detailed_help[0];
85   gengetopt_args_info_help[1] = gengetopt_args_info_detailed_help[1];
86   gengetopt_args_info_help[2] = gengetopt_args_info_detailed_help[2];
87   gengetopt_args_info_help[3] = gengetopt_args_info_detailed_help[3];
88   gengetopt_args_info_help[4] = gengetopt_args_info_detailed_help[4];
89   gengetopt_args_info_help[5] = gengetopt_args_info_detailed_help[5];
90   gengetopt_args_info_help[6] = gengetopt_args_info_detailed_help[6];
91   gengetopt_args_info_help[7] = gengetopt_args_info_detailed_help[7];
92   gengetopt_args_info_help[8] = gengetopt_args_info_detailed_help[8];
93   gengetopt_args_info_help[9] = gengetopt_args_info_detailed_help[9];
94   gengetopt_args_info_help[10] = gengetopt_args_info_detailed_help[11];
95   gengetopt_args_info_help[11] = gengetopt_args_info_detailed_help[12];
96   gengetopt_args_info_help[12] = gengetopt_args_info_detailed_help[13];
97   gengetopt_args_info_help[13] = gengetopt_args_info_detailed_help[14];
98   gengetopt_args_info_help[14] = gengetopt_args_info_detailed_help[15];
99   gengetopt_args_info_help[15] = gengetopt_args_info_detailed_help[17];
100   gengetopt_args_info_help[16] = gengetopt_args_info_detailed_help[18];
101   gengetopt_args_info_help[17] = gengetopt_args_info_detailed_help[19];
102   gengetopt_args_info_help[18] = gengetopt_args_info_detailed_help[20];
103   gengetopt_args_info_help[19] = gengetopt_args_info_detailed_help[21];
104   gengetopt_args_info_help[20] = gengetopt_args_info_detailed_help[22];
105   gengetopt_args_info_help[21] = gengetopt_args_info_detailed_help[23];
106   gengetopt_args_info_help[22] = gengetopt_args_info_detailed_help[24];
107   gengetopt_args_info_help[23] = gengetopt_args_info_detailed_help[25];
108   gengetopt_args_info_help[24] = gengetopt_args_info_detailed_help[27];
109   gengetopt_args_info_help[25] = gengetopt_args_info_detailed_help[29];
110   gengetopt_args_info_help[26] = gengetopt_args_info_detailed_help[30];
111   gengetopt_args_info_help[27] = gengetopt_args_info_detailed_help[32];
112   gengetopt_args_info_help[28] = gengetopt_args_info_detailed_help[34];
113   gengetopt_args_info_help[29] = gengetopt_args_info_detailed_help[35];
114   gengetopt_args_info_help[30] = gengetopt_args_info_detailed_help[36];
115   gengetopt_args_info_help[31] = gengetopt_args_info_detailed_help[37];
116   gengetopt_args_info_help[32] = gengetopt_args_info_detailed_help[38];
117   gengetopt_args_info_help[33] = gengetopt_args_info_detailed_help[39];
118   gengetopt_args_info_help[34] = gengetopt_args_info_detailed_help[40];
119   gengetopt_args_info_help[35] = gengetopt_args_info_detailed_help[41];
120   gengetopt_args_info_help[36] = gengetopt_args_info_detailed_help[42];
121   gengetopt_args_info_help[37] = 0; 
122   
123 }
124
125 const char *gengetopt_args_info_help[38];
126
127 typedef enum {ARG_NO
128   , ARG_FLAG
129   , ARG_STRING
130 } cmdline_parser_arg_type;
131
132 static
133 void clear_given (struct gengetopt_args_info *args_info);
134 static
135 void clear_args (struct gengetopt_args_info *args_info);
136
137 static int
138 cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
139                         struct cmdline_parser_params *params, const char *additional_error);
140
141 struct line_list
142 {
143   char * string_arg;
144   struct line_list * next;
145 };
146
147 static struct line_list *cmd_line_list = 0;
148 static struct line_list *cmd_line_list_tmp = 0;
149
150 static void
151 free_cmd_list(void)
152 {
153   /* free the list of a previous call */
154   if (cmd_line_list)
155     {
156       while (cmd_line_list) {
157         cmd_line_list_tmp = cmd_line_list;
158         cmd_line_list = cmd_line_list->next;
159         free (cmd_line_list_tmp->string_arg);
160         free (cmd_line_list_tmp);
161       }
162     }
163 }
164
165
166 static char *
167 gengetopt_strdup (const char *s);
168
169 static
170 void clear_given (struct gengetopt_args_info *args_info)
171 {
172   args_info->help_given = 0 ;
173   args_info->detailed_help_given = 0 ;
174   args_info->version_given = 0 ;
175   args_info->input_given = 0 ;
176   args_info->func_name_given = 0 ;
177   args_info->arg_struct_name_given = 0 ;
178   args_info->file_name_given = 0 ;
179   args_info->output_dir_given = 0 ;
180   args_info->header_output_dir_given = 0 ;
181   args_info->src_output_dir_given = 0 ;
182   args_info->c_extension_given = 0 ;
183   args_info->header_extension_given = 0 ;
184   args_info->long_help_given = 0 ;
185   args_info->default_optional_given = 0 ;
186   args_info->unamed_opts_given = 0 ;
187   args_info->conf_parser_given = 0 ;
188   args_info->string_parser_given = 0 ;
189   args_info->include_getopt_given = 0 ;
190   args_info->no_handle_help_given = 0 ;
191   args_info->no_help_given = 0 ;
192   args_info->no_handle_version_given = 0 ;
193   args_info->no_version_given = 0 ;
194   args_info->no_handle_error_given = 0 ;
195   args_info->show_required_given = 0 ;
196   args_info->gen_version_given = 0 ;
197   args_info->set_package_given = 0 ;
198   args_info->set_version_given = 0 ;
199   args_info->show_help_given = 0 ;
200   args_info->show_full_help_given = 0 ;
201   args_info->show_detailed_help_given = 0 ;
202   args_info->show_version_given = 0 ;
203 }
204
205 static
206 void clear_args (struct gengetopt_args_info *args_info)
207 {
208   FIX_UNUSED (args_info);
209   args_info->input_arg = NULL;
210   args_info->input_orig = NULL;
211   args_info->func_name_arg = gengetopt_strdup ("cmdline_parser");
212   args_info->func_name_orig = NULL;
213   args_info->arg_struct_name_arg = gengetopt_strdup ("gengetopt_args_info");
214   args_info->arg_struct_name_orig = NULL;
215   args_info->file_name_arg = gengetopt_strdup ("cmdline");
216   args_info->file_name_orig = NULL;
217   args_info->output_dir_arg = NULL;
218   args_info->output_dir_orig = NULL;
219   args_info->header_output_dir_arg = NULL;
220   args_info->header_output_dir_orig = NULL;
221   args_info->src_output_dir_arg = NULL;
222   args_info->src_output_dir_orig = NULL;
223   args_info->c_extension_arg = gengetopt_strdup ("c");
224   args_info->c_extension_orig = NULL;
225   args_info->header_extension_arg = gengetopt_strdup ("h");
226   args_info->header_extension_orig = NULL;
227   args_info->unamed_opts_arg = gengetopt_strdup ("FILES");
228   args_info->unamed_opts_orig = NULL;
229   args_info->show_required_arg = gengetopt_strdup ("(mandatory)");
230   args_info->show_required_orig = NULL;
231   args_info->gen_version_flag = 1;
232   args_info->set_package_arg = NULL;
233   args_info->set_package_orig = NULL;
234   args_info->set_version_arg = NULL;
235   args_info->set_version_orig = NULL;
236   
237 }
238
239 static
240 void init_args_info(struct gengetopt_args_info *args_info)
241 {
242
243   init_help_array(); 
244   args_info->help_help = gengetopt_args_info_detailed_help[0] ;
245   args_info->detailed_help_help = gengetopt_args_info_detailed_help[1] ;
246   args_info->version_help = gengetopt_args_info_detailed_help[2] ;
247   args_info->input_help = gengetopt_args_info_detailed_help[5] ;
248   args_info->func_name_help = gengetopt_args_info_detailed_help[6] ;
249   args_info->arg_struct_name_help = gengetopt_args_info_detailed_help[7] ;
250   args_info->file_name_help = gengetopt_args_info_detailed_help[8] ;
251   args_info->output_dir_help = gengetopt_args_info_detailed_help[9] ;
252   args_info->header_output_dir_help = gengetopt_args_info_detailed_help[11] ;
253   args_info->src_output_dir_help = gengetopt_args_info_detailed_help[12] ;
254   args_info->c_extension_help = gengetopt_args_info_detailed_help[13] ;
255   args_info->header_extension_help = gengetopt_args_info_detailed_help[14] ;
256   args_info->long_help_help = gengetopt_args_info_detailed_help[15] ;
257   args_info->default_optional_help = gengetopt_args_info_detailed_help[17] ;
258   args_info->unamed_opts_help = gengetopt_args_info_detailed_help[18] ;
259   args_info->conf_parser_help = gengetopt_args_info_detailed_help[20] ;
260   args_info->string_parser_help = gengetopt_args_info_detailed_help[21] ;
261   args_info->include_getopt_help = gengetopt_args_info_detailed_help[24] ;
262   args_info->no_handle_help_help = gengetopt_args_info_detailed_help[25] ;
263   args_info->no_help_help = gengetopt_args_info_detailed_help[27] ;
264   args_info->no_handle_version_help = gengetopt_args_info_detailed_help[29] ;
265   args_info->no_version_help = gengetopt_args_info_detailed_help[30] ;
266   args_info->no_handle_error_help = gengetopt_args_info_detailed_help[32] ;
267   args_info->show_required_help = gengetopt_args_info_detailed_help[34] ;
268   args_info->gen_version_help = gengetopt_args_info_detailed_help[35] ;
269   args_info->set_package_help = gengetopt_args_info_detailed_help[36] ;
270   args_info->set_version_help = gengetopt_args_info_detailed_help[37] ;
271   args_info->show_help_help = gengetopt_args_info_detailed_help[38] ;
272   args_info->show_full_help_help = gengetopt_args_info_detailed_help[39] ;
273   args_info->show_detailed_help_help = gengetopt_args_info_detailed_help[40] ;
274   args_info->show_version_help = gengetopt_args_info_detailed_help[41] ;
275   
276 }
277
278 void
279 cmdline_parser_print_version (void)
280 {
281   printf ("%s %s\n",
282      (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
283      CMDLINE_PARSER_VERSION);
284 }
285
286 static void print_help_common(void) {
287   cmdline_parser_print_version ();
288
289   if (strlen(gengetopt_args_info_purpose) > 0)
290     printf("\n%s\n", gengetopt_args_info_purpose);
291
292   if (strlen(gengetopt_args_info_usage) > 0)
293     printf("\n%s\n", gengetopt_args_info_usage);
294
295   printf("\n");
296
297   if (strlen(gengetopt_args_info_description) > 0)
298     printf("%s\n\n", gengetopt_args_info_description);
299 }
300
301 void
302 cmdline_parser_print_help (void)
303 {
304   int i = 0;
305   print_help_common();
306   while (gengetopt_args_info_help[i])
307     printf("%s\n", gengetopt_args_info_help[i++]);
308 }
309
310 void
311 cmdline_parser_print_detailed_help (void)
312 {
313   int i = 0;
314   print_help_common();
315   while (gengetopt_args_info_detailed_help[i])
316     printf("%s\n", gengetopt_args_info_detailed_help[i++]);
317 }
318
319 void
320 cmdline_parser_init (struct gengetopt_args_info *args_info)
321 {
322   clear_given (args_info);
323   clear_args (args_info);
324   init_args_info (args_info);
325 }
326
327 void
328 cmdline_parser_params_init(struct cmdline_parser_params *params)
329 {
330   if (params)
331     { 
332       params->override = 0;
333       params->initialize = 1;
334       params->check_required = 1;
335       params->check_ambiguity = 0;
336       params->print_errors = 1;
337     }
338 }
339
340 struct cmdline_parser_params *
341 cmdline_parser_params_create(void)
342 {
343   struct cmdline_parser_params *params = 
344     (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
345   cmdline_parser_params_init(params);  
346   return params;
347 }
348
349 static void
350 free_string_field (char **s)
351 {
352   if (*s)
353     {
354       free (*s);
355       *s = 0;
356     }
357 }
358
359
360 static void
361 cmdline_parser_release (struct gengetopt_args_info *args_info)
362 {
363
364   free_string_field (&(args_info->input_arg));
365   free_string_field (&(args_info->input_orig));
366   free_string_field (&(args_info->func_name_arg));
367   free_string_field (&(args_info->func_name_orig));
368   free_string_field (&(args_info->arg_struct_name_arg));
369   free_string_field (&(args_info->arg_struct_name_orig));
370   free_string_field (&(args_info->file_name_arg));
371   free_string_field (&(args_info->file_name_orig));
372   free_string_field (&(args_info->output_dir_arg));
373   free_string_field (&(args_info->output_dir_orig));
374   free_string_field (&(args_info->header_output_dir_arg));
375   free_string_field (&(args_info->header_output_dir_orig));
376   free_string_field (&(args_info->src_output_dir_arg));
377   free_string_field (&(args_info->src_output_dir_orig));
378   free_string_field (&(args_info->c_extension_arg));
379   free_string_field (&(args_info->c_extension_orig));
380   free_string_field (&(args_info->header_extension_arg));
381   free_string_field (&(args_info->header_extension_orig));
382   free_string_field (&(args_info->unamed_opts_arg));
383   free_string_field (&(args_info->unamed_opts_orig));
384   free_string_field (&(args_info->show_required_arg));
385   free_string_field (&(args_info->show_required_orig));
386   free_string_field (&(args_info->set_package_arg));
387   free_string_field (&(args_info->set_package_orig));
388   free_string_field (&(args_info->set_version_arg));
389   free_string_field (&(args_info->set_version_orig));
390   
391   
392
393   clear_given (args_info);
394 }
395
396
397 static void
398 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
399 {
400   FIX_UNUSED (values);
401   if (arg) {
402     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
403   } else {
404     fprintf(outfile, "%s\n", opt);
405   }
406 }
407
408
409 int
410 cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
411 {
412   int i = 0;
413
414   if (!outfile)
415     {
416       fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
417       return EXIT_FAILURE;
418     }
419
420   if (args_info->help_given)
421     write_into_file(outfile, "help", 0, 0 );
422   if (args_info->detailed_help_given)
423     write_into_file(outfile, "detailed-help", 0, 0 );
424   if (args_info->version_given)
425     write_into_file(outfile, "version", 0, 0 );
426   if (args_info->input_given)
427     write_into_file(outfile, "input", args_info->input_orig, 0);
428   if (args_info->func_name_given)
429     write_into_file(outfile, "func-name", args_info->func_name_orig, 0);
430   if (args_info->arg_struct_name_given)
431     write_into_file(outfile, "arg-struct-name", args_info->arg_struct_name_orig, 0);
432   if (args_info->file_name_given)
433     write_into_file(outfile, "file-name", args_info->file_name_orig, 0);
434   if (args_info->output_dir_given)
435     write_into_file(outfile, "output-dir", args_info->output_dir_orig, 0);
436   if (args_info->header_output_dir_given)
437     write_into_file(outfile, "header-output-dir", args_info->header_output_dir_orig, 0);
438   if (args_info->src_output_dir_given)
439     write_into_file(outfile, "src-output-dir", args_info->src_output_dir_orig, 0);
440   if (args_info->c_extension_given)
441     write_into_file(outfile, "c-extension", args_info->c_extension_orig, 0);
442   if (args_info->header_extension_given)
443     write_into_file(outfile, "header-extension", args_info->header_extension_orig, 0);
444   if (args_info->long_help_given)
445     write_into_file(outfile, "long-help", 0, 0 );
446   if (args_info->default_optional_given)
447     write_into_file(outfile, "default-optional", 0, 0 );
448   if (args_info->unamed_opts_given)
449     write_into_file(outfile, "unamed-opts", args_info->unamed_opts_orig, 0);
450   if (args_info->conf_parser_given)
451     write_into_file(outfile, "conf-parser", 0, 0 );
452   if (args_info->string_parser_given)
453     write_into_file(outfile, "string-parser", 0, 0 );
454   if (args_info->include_getopt_given)
455     write_into_file(outfile, "include-getopt", 0, 0 );
456   if (args_info->no_handle_help_given)
457     write_into_file(outfile, "no-handle-help", 0, 0 );
458   if (args_info->no_help_given)
459     write_into_file(outfile, "no-help", 0, 0 );
460   if (args_info->no_handle_version_given)
461     write_into_file(outfile, "no-handle-version", 0, 0 );
462   if (args_info->no_version_given)
463     write_into_file(outfile, "no-version", 0, 0 );
464   if (args_info->no_handle_error_given)
465     write_into_file(outfile, "no-handle-error", 0, 0 );
466   if (args_info->show_required_given)
467     write_into_file(outfile, "show-required", args_info->show_required_orig, 0);
468   if (args_info->gen_version_given)
469     write_into_file(outfile, "gen-version", 0, 0 );
470   if (args_info->set_package_given)
471     write_into_file(outfile, "set-package", args_info->set_package_orig, 0);
472   if (args_info->set_version_given)
473     write_into_file(outfile, "set-version", args_info->set_version_orig, 0);
474   if (args_info->show_help_given)
475     write_into_file(outfile, "show-help", 0, 0 );
476   if (args_info->show_full_help_given)
477     write_into_file(outfile, "show-full-help", 0, 0 );
478   if (args_info->show_detailed_help_given)
479     write_into_file(outfile, "show-detailed-help", 0, 0 );
480   if (args_info->show_version_given)
481     write_into_file(outfile, "show-version", 0, 0 );
482   
483
484   i = EXIT_SUCCESS;
485   return i;
486 }
487
488 int
489 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
490 {
491   FILE *outfile;
492   int i = 0;
493
494   outfile = fopen(filename, "w");
495
496   if (!outfile)
497     {
498       fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
499       return EXIT_FAILURE;
500     }
501
502   i = cmdline_parser_dump(outfile, args_info);
503   fclose (outfile);
504
505   return i;
506 }
507
508 void
509 cmdline_parser_free (struct gengetopt_args_info *args_info)
510 {
511   cmdline_parser_release (args_info);
512 }
513
514 /** @brief replacement of strdup, which is not standard */
515 char *
516 gengetopt_strdup (const char *s)
517 {
518   char *result = 0;
519   if (!s)
520     return result;
521
522   result = (char*)malloc(strlen(s) + 1);
523   if (result == (char*)0)
524     return (char*)0;
525   strcpy(result, s);
526   return result;
527 }
528
529 int
530 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
531 {
532   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
533 }
534
535 int
536 cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
537                    struct cmdline_parser_params *params)
538 {
539   int result;
540   result = cmdline_parser_internal (argc, argv, args_info, params, 0);
541
542   return result;
543 }
544
545 int
546 cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
547 {
548   int result;
549   struct cmdline_parser_params params;
550   
551   params.override = override;
552   params.initialize = initialize;
553   params.check_required = check_required;
554   params.check_ambiguity = 0;
555   params.print_errors = 1;
556
557   result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
558
559   return result;
560 }
561
562 int
563 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
564 {
565   FIX_UNUSED (args_info);
566   FIX_UNUSED (prog_name);
567   return EXIT_SUCCESS;
568 }
569
570
571 static char *package_name = 0;
572
573 /**
574  * @brief updates an option
575  * @param field the generic pointer to the field to update
576  * @param orig_field the pointer to the orig field
577  * @param field_given the pointer to the number of occurrence of this option
578  * @param prev_given the pointer to the number of occurrence already seen
579  * @param value the argument for this option (if null no arg was specified)
580  * @param possible_values the possible values for this option (if specified)
581  * @param default_value the default value (in case the option only accepts fixed values)
582  * @param arg_type the type of this option
583  * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
584  * @param override @see cmdline_parser_params.override
585  * @param no_free whether to free a possible previous value
586  * @param multiple_option whether this is a multiple option
587  * @param long_opt the corresponding long option
588  * @param short_opt the corresponding short option (or '-' if none)
589  * @param additional_error possible further error specification
590  */
591 static
592 int update_arg(void *field, char **orig_field,
593                unsigned int *field_given, unsigned int *prev_given, 
594                char *value, const char *possible_values[],
595                const char *default_value,
596                cmdline_parser_arg_type arg_type,
597                int check_ambiguity, int override,
598                int no_free, int multiple_option,
599                const char *long_opt, char short_opt,
600                const char *additional_error)
601 {
602   char *stop_char = 0;
603   const char *val = value;
604   int found;
605   char **string_field;
606   FIX_UNUSED (field);
607
608   stop_char = 0;
609   found = 0;
610
611   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
612     {
613       if (short_opt != '-')
614         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
615                package_name, long_opt, short_opt,
616                (additional_error ? additional_error : ""));
617       else
618         fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
619                package_name, long_opt,
620                (additional_error ? additional_error : ""));
621       return 1; /* failure */
622     }
623
624   FIX_UNUSED (default_value);
625     
626   if (field_given && *field_given && ! override)
627     return 0;
628   if (prev_given)
629     (*prev_given)++;
630   if (field_given)
631     (*field_given)++;
632   if (possible_values)
633     val = possible_values[found];
634
635   switch(arg_type) {
636   case ARG_FLAG:
637     *((int *)field) = !*((int *)field);
638     break;
639   case ARG_STRING:
640     if (val) {
641       string_field = (char **)field;
642       if (!no_free && *string_field)
643         free (*string_field); /* free previous string */
644       *string_field = gengetopt_strdup (val);
645     }
646     break;
647   default:
648     break;
649   };
650
651
652   /* store the original value */
653   switch(arg_type) {
654   case ARG_NO:
655   case ARG_FLAG:
656     break;
657   default:
658     if (value && orig_field) {
659       if (no_free) {
660         *orig_field = value;
661       } else {
662         if (*orig_field)
663           free (*orig_field); /* free previous string */
664         *orig_field = gengetopt_strdup (value);
665       }
666     }
667   };
668
669   return 0; /* OK */
670 }
671
672
673 int
674 cmdline_parser_internal (
675   int argc, char **argv, struct gengetopt_args_info *args_info,
676                         struct cmdline_parser_params *params, const char *additional_error)
677 {
678   int c;        /* Character of the parsed option.  */
679
680   int error = 0;
681   struct gengetopt_args_info local_args_info;
682   
683   int override;
684   int initialize;
685   int check_required;
686   int check_ambiguity;
687   
688   package_name = argv[0];
689   
690   override = params->override;
691   initialize = params->initialize;
692   check_required = params->check_required;
693   check_ambiguity = params->check_ambiguity;
694
695   if (initialize)
696     cmdline_parser_init (args_info);
697
698   cmdline_parser_init (&local_args_info);
699
700   optarg = 0;
701   optind = 0;
702   opterr = params->print_errors;
703   optopt = '?';
704
705   while (1)
706     {
707       int option_index = 0;
708
709       static struct option long_options[] = {
710         { "help",       0, NULL, 'h' },
711         { "detailed-help",      0, NULL, 0 },
712         { "version",    0, NULL, 'V' },
713         { "input",      1, NULL, 'i' },
714         { "func-name",  1, NULL, 'f' },
715         { "arg-struct-name",    1, NULL, 'a' },
716         { "file-name",  1, NULL, 'F' },
717         { "output-dir", 1, NULL, 0 },
718         { "header-output-dir",  1, NULL, 0 },
719         { "src-output-dir",     1, NULL, 0 },
720         { "c-extension",        1, NULL, 'c' },
721         { "header-extension",   1, NULL, 'H' },
722         { "long-help",  0, NULL, 'l' },
723         { "default-optional",   0, NULL, 0 },
724         { "unamed-opts",        2, NULL, 'u' },
725         { "conf-parser",        0, NULL, 'C' },
726         { "string-parser",      0, NULL, 'S' },
727         { "include-getopt",     0, NULL, 'G' },
728         { "no-handle-help",     0, NULL, 'n' },
729         { "no-help",    0, NULL, 0 },
730         { "no-handle-version",  0, NULL, 'N' },
731         { "no-version", 0, NULL, 0 },
732         { "no-handle-error",    0, NULL, 'e' },
733         { "show-required",      2, NULL, 0 },
734         { "gen-version",        0, NULL, 'g' },
735         { "set-package",        1, NULL, 0 },
736         { "set-version",        1, NULL, 0 },
737         { "show-help",  0, NULL, 0 },
738         { "show-full-help",     0, NULL, 0 },
739         { "show-detailed-help", 0, NULL, 0 },
740         { "show-version",       0, NULL, 0 },
741         { 0,  0, 0, 0 }
742       };
743
744       c = getopt_long (argc, argv, "hVi:f:a:F:c:H:lu::CSGnNeg", long_options, &option_index);
745
746       if (c == -1) break;       /* Exit from `while (1)' loop.  */
747
748       switch (c)
749         {
750         case 'h':       /* Print help and exit.  */
751         
752         
753           if (update_arg( 0 , 
754                0 , &(args_info->help_given),
755               &(local_args_info.help_given), optarg, 0, 0, ARG_NO,
756               check_ambiguity, override, 0, 0,
757               "help", 'h',
758               additional_error))
759             goto failure;
760           cmdline_parser_free (&local_args_info);
761           return 0;
762         
763           break;
764         case 'V':       /* Print version and exit.  */
765         
766         
767           if (update_arg( 0 , 
768                0 , &(args_info->version_given),
769               &(local_args_info.version_given), optarg, 0, 0, ARG_NO,
770               check_ambiguity, override, 0, 0,
771               "version", 'V',
772               additional_error))
773             goto failure;
774           cmdline_parser_free (&local_args_info);
775           return 0;
776         
777           break;
778         case 'i':       /* input file (default std input).  */
779         
780         
781           if (update_arg( (void *)&(args_info->input_arg), 
782                &(args_info->input_orig), &(args_info->input_given),
783               &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
784               check_ambiguity, override, 0, 0,
785               "input", 'i',
786               additional_error))
787             goto failure;
788         
789           break;
790         case 'f':       /* name of generated function.  */
791         
792         
793           if (update_arg( (void *)&(args_info->func_name_arg), 
794                &(args_info->func_name_orig), &(args_info->func_name_given),
795               &(local_args_info.func_name_given), optarg, 0, "cmdline_parser", ARG_STRING,
796               check_ambiguity, override, 0, 0,
797               "func-name", 'f',
798               additional_error))
799             goto failure;
800         
801           break;
802         case 'a':       /* name of generated args info struct.  */
803         
804         
805           if (update_arg( (void *)&(args_info->arg_struct_name_arg), 
806                &(args_info->arg_struct_name_orig), &(args_info->arg_struct_name_given),
807               &(local_args_info.arg_struct_name_given), optarg, 0, "gengetopt_args_info", ARG_STRING,
808               check_ambiguity, override, 0, 0,
809               "arg-struct-name", 'a',
810               additional_error))
811             goto failure;
812         
813           break;
814         case 'F':       /* name of generated file.  */
815         
816         
817           if (update_arg( (void *)&(args_info->file_name_arg), 
818                &(args_info->file_name_orig), &(args_info->file_name_given),
819               &(local_args_info.file_name_given), optarg, 0, "cmdline", ARG_STRING,
820               check_ambiguity, override, 0, 0,
821               "file-name", 'F',
822               additional_error))
823             goto failure;
824         
825           break;
826         case 'c':       /* extension of c file.  */
827         
828         
829           if (update_arg( (void *)&(args_info->c_extension_arg), 
830                &(args_info->c_extension_orig), &(args_info->c_extension_given),
831               &(local_args_info.c_extension_given), optarg, 0, "c", ARG_STRING,
832               check_ambiguity, override, 0, 0,
833               "c-extension", 'c',
834               additional_error))
835             goto failure;
836         
837           break;
838         case 'H':       /* extension of header file.  */
839         
840         
841           if (update_arg( (void *)&(args_info->header_extension_arg), 
842                &(args_info->header_extension_orig), &(args_info->header_extension_given),
843               &(local_args_info.header_extension_given), optarg, 0, "h", ARG_STRING,
844               check_ambiguity, override, 0, 0,
845               "header-extension", 'H',
846               additional_error))
847             goto failure;
848         
849           break;
850         case 'l':       /* long usage line in help.  */
851         
852         
853           if (update_arg( 0 , 
854                0 , &(args_info->long_help_given),
855               &(local_args_info.long_help_given), optarg, 0, 0, ARG_NO,
856               check_ambiguity, override, 0, 0,
857               "long-help", 'l',
858               additional_error))
859             goto failure;
860         
861           break;
862         case 'u':       /* accept options without names (e.g., file names).  */
863         
864         
865           if (update_arg( (void *)&(args_info->unamed_opts_arg), 
866                &(args_info->unamed_opts_orig), &(args_info->unamed_opts_given),
867               &(local_args_info.unamed_opts_given), optarg, 0, "FILES", ARG_STRING,
868               check_ambiguity, override, 0, 0,
869               "unamed-opts", 'u',
870               additional_error))
871             goto failure;
872         
873           break;
874         case 'C':       /* generate a config file parser.  */
875         
876         
877           if (update_arg( 0 , 
878                0 , &(args_info->conf_parser_given),
879               &(local_args_info.conf_parser_given), optarg, 0, 0, ARG_NO,
880               check_ambiguity, override, 0, 0,
881               "conf-parser", 'C',
882               additional_error))
883             goto failure;
884         
885           break;
886         case 'S':       /* generate a string parser (the string contains the command line).  */
887         
888         
889           if (update_arg( 0 , 
890                0 , &(args_info->string_parser_given),
891               &(local_args_info.string_parser_given), optarg, 0, 0, ARG_NO,
892               check_ambiguity, override, 0, 0,
893               "string-parser", 'S',
894               additional_error))
895             goto failure;
896         
897           break;
898         case 'G':       /* adds the code for getopt_long in the generated C file.  */
899         
900         
901           if (update_arg( 0 , 
902                0 , &(args_info->include_getopt_given),
903               &(local_args_info.include_getopt_given), optarg, 0, 0, ARG_NO,
904               check_ambiguity, override, 0, 0,
905               "include-getopt", 'G',
906               additional_error))
907             goto failure;
908         
909           break;
910         case 'n':       /* do not handle --help|-h automatically.  */
911         
912         
913           if (update_arg( 0 , 
914                0 , &(args_info->no_handle_help_given),
915               &(local_args_info.no_handle_help_given), optarg, 0, 0, ARG_NO,
916               check_ambiguity, override, 0, 0,
917               "no-handle-help", 'n',
918               additional_error))
919             goto failure;
920         
921           break;
922         case 'N':       /* do not handle --version|-V automatically.  */
923         
924         
925           if (update_arg( 0 , 
926                0 , &(args_info->no_handle_version_given),
927               &(local_args_info.no_handle_version_given), optarg, 0, 0, ARG_NO,
928               check_ambiguity, override, 0, 0,
929               "no-handle-version", 'N',
930               additional_error))
931             goto failure;
932         
933           break;
934         case 'e':       /* do not exit on errors.  */
935         
936         
937           if (update_arg( 0 , 
938                0 , &(args_info->no_handle_error_given),
939               &(local_args_info.no_handle_error_given), optarg, 0, 0, ARG_NO,
940               check_ambiguity, override, 0, 0,
941               "no-handle-error", 'e',
942               additional_error))
943             goto failure;
944         
945           break;
946         case 'g':       /* put gengetopt version in the generated file.  */
947         
948         
949           if (update_arg((void *)&(args_info->gen_version_flag), 0, &(args_info->gen_version_given),
950               &(local_args_info.gen_version_given), optarg, 0, 0, ARG_FLAG,
951               check_ambiguity, override, 1, 0, "gen-version", 'g',
952               additional_error))
953             goto failure;
954         
955           break;
956
957         case 0: /* Long option with no short option */
958           /* Print help, including all details and hidden options, and exit.  */
959           if (strcmp (long_options[option_index].name, "detailed-help") == 0)
960           {
961           
962           
963             if (update_arg( 0 , 
964                  0 , &(args_info->detailed_help_given),
965                 &(local_args_info.detailed_help_given), optarg, 0, 0, ARG_NO,
966                 check_ambiguity, override, 0, 0,
967                 "detailed-help", '-',
968                 additional_error))
969               goto failure;
970             cmdline_parser_free (&local_args_info);
971             return 0;
972           
973           }
974           /* output directory.  */
975           else if (strcmp (long_options[option_index].name, "output-dir") == 0)
976           {
977           
978           
979             if (update_arg( (void *)&(args_info->output_dir_arg), 
980                  &(args_info->output_dir_orig), &(args_info->output_dir_given),
981                 &(local_args_info.output_dir_given), optarg, 0, 0, ARG_STRING,
982                 check_ambiguity, override, 0, 0,
983                 "output-dir", '-',
984                 additional_error))
985               goto failure;
986           
987           }
988           /* header output directory.  */
989           else if (strcmp (long_options[option_index].name, "header-output-dir") == 0)
990           {
991           
992           
993             if (update_arg( (void *)&(args_info->header_output_dir_arg), 
994                  &(args_info->header_output_dir_orig), &(args_info->header_output_dir_given),
995                 &(local_args_info.header_output_dir_given), optarg, 0, 0, ARG_STRING,
996                 check_ambiguity, override, 0, 0,
997                 "header-output-dir", '-',
998                 additional_error))
999               goto failure;
1000           
1001           }
1002           /* source output directory.  */
1003           else if (strcmp (long_options[option_index].name, "src-output-dir") == 0)
1004           {
1005           
1006           
1007             if (update_arg( (void *)&(args_info->src_output_dir_arg), 
1008                  &(args_info->src_output_dir_orig), &(args_info->src_output_dir_given),
1009                 &(local_args_info.src_output_dir_given), optarg, 0, 0, ARG_STRING,
1010                 check_ambiguity, override, 0, 0,
1011                 "src-output-dir", '-',
1012                 additional_error))
1013               goto failure;
1014           
1015           }
1016           /* by default, an option is considered optional if not specified otherwise.  */
1017           else if (strcmp (long_options[option_index].name, "default-optional") == 0)
1018           {
1019           
1020           
1021             if (update_arg( 0 , 
1022                  0 , &(args_info->default_optional_given),
1023                 &(local_args_info.default_optional_given), optarg, 0, 0, ARG_NO,
1024                 check_ambiguity, override, 0, 0,
1025                 "default-optional", '-',
1026                 additional_error))
1027               goto failure;
1028           
1029           }
1030           /* do not add --help|-h automatically.  */
1031           else if (strcmp (long_options[option_index].name, "no-help") == 0)
1032           {
1033           
1034           
1035             if (update_arg( 0 , 
1036                  0 , &(args_info->no_help_given),
1037                 &(local_args_info.no_help_given), optarg, 0, 0, ARG_NO,
1038                 check_ambiguity, override, 0, 0,
1039                 "no-help", '-',
1040                 additional_error))
1041               goto failure;
1042           
1043           }
1044           /* do not add --version|-V automatically.  */
1045           else if (strcmp (long_options[option_index].name, "no-version") == 0)
1046           {
1047           
1048           
1049             if (update_arg( 0 , 
1050                  0 , &(args_info->no_version_given),
1051                 &(local_args_info.no_version_given), optarg, 0, 0, ARG_NO,
1052                 check_ambiguity, override, 0, 0,
1053                 "no-version", '-',
1054                 additional_error))
1055               goto failure;
1056           
1057           }
1058           /* in the output of help will specify which options are mandatory, by using the optional passed string.  */
1059           else if (strcmp (long_options[option_index].name, "show-required") == 0)
1060           {
1061           
1062           
1063             if (update_arg( (void *)&(args_info->show_required_arg), 
1064                  &(args_info->show_required_orig), &(args_info->show_required_given),
1065                 &(local_args_info.show_required_given), optarg, 0, "(mandatory)", ARG_STRING,
1066                 check_ambiguity, override, 0, 0,
1067                 "show-required", '-',
1068                 additional_error))
1069               goto failure;
1070           
1071           }
1072           /* set the package name (override package defined in the .ggo file).  */
1073           else if (strcmp (long_options[option_index].name, "set-package") == 0)
1074           {
1075           
1076           
1077             if (update_arg( (void *)&(args_info->set_package_arg), 
1078                  &(args_info->set_package_orig), &(args_info->set_package_given),
1079                 &(local_args_info.set_package_given), optarg, 0, 0, ARG_STRING,
1080                 check_ambiguity, override, 0, 0,
1081                 "set-package", '-',
1082                 additional_error))
1083               goto failure;
1084           
1085           }
1086           /* set the version number (override version defined in the .ggo file).  */
1087           else if (strcmp (long_options[option_index].name, "set-version") == 0)
1088           {
1089           
1090           
1091             if (update_arg( (void *)&(args_info->set_version_arg), 
1092                  &(args_info->set_version_orig), &(args_info->set_version_given),
1093                 &(local_args_info.set_version_given), optarg, 0, 0, ARG_STRING,
1094                 check_ambiguity, override, 0, 0,
1095                 "set-version", '-',
1096                 additional_error))
1097               goto failure;
1098           
1099           }
1100           /* show the output of --help instead of generating code.  */
1101           else if (strcmp (long_options[option_index].name, "show-help") == 0)
1102           {
1103           
1104           
1105             if (update_arg( 0 , 
1106                  0 , &(args_info->show_help_given),
1107                 &(local_args_info.show_help_given), optarg, 0, 0, ARG_NO,
1108                 check_ambiguity, override, 0, 0,
1109                 "show-help", '-',
1110                 additional_error))
1111               goto failure;
1112           
1113           }
1114           /* show the output of --full-help (i.e., including hidden options) instead of generating code.  */
1115           else if (strcmp (long_options[option_index].name, "show-full-help") == 0)
1116           {
1117           
1118           
1119             if (update_arg( 0 , 
1120                  0 , &(args_info->show_full_help_given),
1121                 &(local_args_info.show_full_help_given), optarg, 0, 0, ARG_NO,
1122                 check_ambiguity, override, 0, 0,
1123                 "show-full-help", '-',
1124                 additional_error))
1125               goto failure;
1126           
1127           }
1128           /* show the output of --detailed-help (i.e., including details and hidden options) instead of generating code.  */
1129           else if (strcmp (long_options[option_index].name, "show-detailed-help") == 0)
1130           {
1131           
1132           
1133             if (update_arg( 0 , 
1134                  0 , &(args_info->show_detailed_help_given),
1135                 &(local_args_info.show_detailed_help_given), optarg, 0, 0, ARG_NO,
1136                 check_ambiguity, override, 0, 0,
1137                 "show-detailed-help", '-',
1138                 additional_error))
1139               goto failure;
1140           
1141           }
1142           /* show the output of --version instead of generating code.  */
1143           else if (strcmp (long_options[option_index].name, "show-version") == 0)
1144           {
1145           
1146           
1147             if (update_arg( 0 , 
1148                  0 , &(args_info->show_version_given),
1149                 &(local_args_info.show_version_given), optarg, 0, 0, ARG_NO,
1150                 check_ambiguity, override, 0, 0,
1151                 "show-version", '-',
1152                 additional_error))
1153               goto failure;
1154           
1155           }
1156           
1157           break;
1158         case '?':       /* Invalid option.  */
1159           /* `getopt_long' already printed an error message.  */
1160           goto failure;
1161
1162         default:        /* bug: option not considered.  */
1163           fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
1164           abort ();
1165         } /* switch */
1166     } /* while */
1167
1168
1169
1170
1171   cmdline_parser_release (&local_args_info);
1172
1173   if ( error )
1174     return (EXIT_FAILURE);
1175
1176   return 0;
1177
1178 failure:
1179   
1180   cmdline_parser_release (&local_args_info);
1181   return (EXIT_FAILURE);
1182 }
1183
1184 static unsigned int
1185 cmdline_parser_create_argv(const char *cmdline_, char ***argv_ptr, const char *prog_name)
1186 {
1187   char *cmdline, *p;
1188   size_t n = 0, j;
1189   int i;
1190
1191   if (prog_name) {
1192     cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1193     cmd_line_list_tmp->next = cmd_line_list;
1194     cmd_line_list = cmd_line_list_tmp;
1195     cmd_line_list->string_arg = gengetopt_strdup (prog_name);
1196
1197     ++n;
1198   }
1199
1200   cmdline = gengetopt_strdup(cmdline_);
1201   p = cmdline;
1202
1203   while (p && strlen(p))
1204     {
1205       j = strcspn(p, " \t");
1206       ++n;
1207       if (j && j < strlen(p))
1208         {
1209           p[j] = '\0';
1210
1211           cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1212           cmd_line_list_tmp->next = cmd_line_list;
1213           cmd_line_list = cmd_line_list_tmp;
1214           cmd_line_list->string_arg = gengetopt_strdup (p);
1215
1216           p += (j+1);
1217           p += strspn(p, " \t");
1218         }
1219       else
1220         {
1221           cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1222           cmd_line_list_tmp->next = cmd_line_list;
1223           cmd_line_list = cmd_line_list_tmp;
1224           cmd_line_list->string_arg = gengetopt_strdup (p);
1225
1226           break;
1227         }
1228     }
1229
1230   *argv_ptr = (char **) malloc((n + 1) * sizeof(char *));
1231   cmd_line_list_tmp = cmd_line_list;
1232   for (i = (n-1); i >= 0; --i)
1233     {
1234       (*argv_ptr)[i] = cmd_line_list_tmp->string_arg;
1235       cmd_line_list_tmp = cmd_line_list_tmp->next;
1236     }
1237
1238   (*argv_ptr)[n] = 0;
1239
1240   free(cmdline);
1241   return n;
1242 }
1243
1244 int
1245 cmdline_parser_string(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name)
1246 {
1247   return cmdline_parser_string2(cmdline, args_info, prog_name, 0, 1, 1);
1248 }
1249
1250 int
1251 cmdline_parser_string2(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name,
1252     int override, int initialize, int check_required)
1253 {
1254   struct cmdline_parser_params params;
1255
1256   params.override = override;
1257   params.initialize = initialize;
1258   params.check_required = check_required;
1259   params.check_ambiguity = 0;
1260   params.print_errors = 1;
1261
1262   return cmdline_parser_string_ext(cmdline, args_info, prog_name, &params);
1263 }
1264
1265 int
1266 cmdline_parser_string_ext(const char *cmdline, struct gengetopt_args_info *args_info, const char *prog_name,
1267     struct cmdline_parser_params *params)
1268 {
1269   char **argv_ptr = 0;
1270   int result;
1271   unsigned int argc;
1272   
1273   argc = cmdline_parser_create_argv(cmdline, &argv_ptr, prog_name);
1274   
1275   result =
1276     cmdline_parser_internal (argc, argv_ptr, args_info, params, 0);
1277   
1278   if (argv_ptr)
1279     {
1280       free (argv_ptr);
1281     }
1282
1283   free_cmd_list();
1284   
1285   return result;
1286 }
1287