~ubuntu-branches/ubuntu/hardy/gengetopt/hardy

« back to all changes in this revision

Viewing changes to src/cmdline.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-01-29 14:55:40 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080129145540-bkah1bl330gpelmh
Tags: 2.22-1ubuntu1
* Merge with Debian; remaining changes:
  - Fix build failures with g++-4.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  File autogenerated by gengetopt version 2.21
 
2
  File autogenerated by gengetopt version 2.22
3
3
  generated with the following command:
4
4
  ../src/gengetopt --input=cmdline.ggo --no-handle-version --no-handle-help --no-handle-error --string-parser
5
5
 
27
27
 
28
28
const char *gengetopt_args_info_description = "";
29
29
 
30
 
const char *gengetopt_args_info_help[] = {
 
30
const char *gengetopt_args_info_detailed_help[] = {
31
31
  "  -h, --help                    Print help and exit",
 
32
  "      --detailed-help           Print help, including all details and hidden \n                                  options, and exit",
32
33
  "  -V, --version                 Print version and exit",
33
34
  "\nMain options:",
34
35
  "",
37
38
  "  -a, --arg-struct-name=name    name of generated args info struct  \n                                  (default=`gengetopt_args_info')",
38
39
  "  -F, --file-name=name          name of generated file  (default=`cmdline')",
39
40
  "      --output-dir=path         output directory",
 
41
  "  \n  if this option is not specified, the files are generated in the current \n  directory.\n",
40
42
  "  -c, --c-extension=ext         extension of c file  (default=`c')",
41
43
  "  -H, --header-extension=ext    extension of header file  (default=`h')",
42
44
  "  -l, --long-help               long usage line in help",
 
45
  "  \n  The usage line will print all the options, e.g.,\n\n  sample1 -iINT|--int-opt=INT [-h|--help]\n",
43
46
  "      --default-optional        by default, an option is considered optional if \n                                  not specified otherwise",
44
47
  "  -u, --unamed-opts[=STRING]    accept options without names (e.g., file names) \n                                   (default=`FILES')",
45
48
  "\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",
49
52
  "",
50
53
  "  -G, --include-getopt          adds the code for getopt_long in the generated \n                                  C file",
51
54
  "  -n, --no-handle-help          do not handle --help|-h automatically",
 
55
  "  \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",
 
56
  "      --no-help                 do not add --help|-h automatically",
 
57
  "  \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",
52
58
  "  -N, --no-handle-version       do not handle --version|-V automatically",
 
59
  "      --no-version              do not add --version|-V automatically",
 
60
  "  \n  See above the details about --no-handle-help and --no-help, respectively.\n",
53
61
  "  -e, --no-handle-error         do not exit on errors",
 
62
  "  \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",
54
63
  "      --show-required[=STRING]  in the output of help will specify which \n                                  options are mandatory, by using the optional \n                                  passed string  (default=`(mandatory)')",
55
64
  "  -g, --gen-version             put gengetopt version in the generated file  \n                                  (default=on)",
56
65
  "      --set-package=STRING      set the package name (override package defined \n                                  in the .ggo file)",
57
66
  "      --set-version=STRING      set the version number (override version \n                                  defined in the .ggo file)",
58
67
  "      --show-help               show the output of --help instead of generating \n                                  code",
59
 
  "      --show-full-help          show the output of --help (including hidden \n                                  options) instead of generating code",
 
68
  "      --show-full-help          show the output of --full-help (i.e., including \n                                  hidden options) instead of generating code",
 
69
  "      --show-detailed-help      show the output of --detailed-help (i.e., \n                                  including details and hidden options) instead \n                                  of generating code",
60
70
  "      --show-version            show the output of --version instead of \n                                  generating code",
61
71
  "\nPlease refer to the info manual for further explanations.",
62
72
    0
63
73
};
64
74
 
 
75
static void
 
76
init_help_array(void)
 
77
{
 
78
  gengetopt_args_info_help[0] = gengetopt_args_info_detailed_help[0];
 
79
  gengetopt_args_info_help[1] = gengetopt_args_info_detailed_help[1];
 
80
  gengetopt_args_info_help[2] = gengetopt_args_info_detailed_help[2];
 
81
  gengetopt_args_info_help[3] = gengetopt_args_info_detailed_help[3];
 
82
  gengetopt_args_info_help[4] = gengetopt_args_info_detailed_help[4];
 
83
  gengetopt_args_info_help[5] = gengetopt_args_info_detailed_help[5];
 
84
  gengetopt_args_info_help[6] = gengetopt_args_info_detailed_help[6];
 
85
  gengetopt_args_info_help[7] = gengetopt_args_info_detailed_help[7];
 
86
  gengetopt_args_info_help[8] = gengetopt_args_info_detailed_help[8];
 
87
  gengetopt_args_info_help[9] = gengetopt_args_info_detailed_help[9];
 
88
  gengetopt_args_info_help[10] = gengetopt_args_info_detailed_help[11];
 
89
  gengetopt_args_info_help[11] = gengetopt_args_info_detailed_help[12];
 
90
  gengetopt_args_info_help[12] = gengetopt_args_info_detailed_help[13];
 
91
  gengetopt_args_info_help[13] = gengetopt_args_info_detailed_help[15];
 
92
  gengetopt_args_info_help[14] = gengetopt_args_info_detailed_help[16];
 
93
  gengetopt_args_info_help[15] = gengetopt_args_info_detailed_help[17];
 
94
  gengetopt_args_info_help[16] = gengetopt_args_info_detailed_help[18];
 
95
  gengetopt_args_info_help[17] = gengetopt_args_info_detailed_help[19];
 
96
  gengetopt_args_info_help[18] = gengetopt_args_info_detailed_help[20];
 
97
  gengetopt_args_info_help[19] = gengetopt_args_info_detailed_help[21];
 
98
  gengetopt_args_info_help[20] = gengetopt_args_info_detailed_help[22];
 
99
  gengetopt_args_info_help[21] = gengetopt_args_info_detailed_help[23];
 
100
  gengetopt_args_info_help[22] = gengetopt_args_info_detailed_help[25];
 
101
  gengetopt_args_info_help[23] = gengetopt_args_info_detailed_help[27];
 
102
  gengetopt_args_info_help[24] = gengetopt_args_info_detailed_help[28];
 
103
  gengetopt_args_info_help[25] = gengetopt_args_info_detailed_help[30];
 
104
  gengetopt_args_info_help[26] = gengetopt_args_info_detailed_help[32];
 
105
  gengetopt_args_info_help[27] = gengetopt_args_info_detailed_help[33];
 
106
  gengetopt_args_info_help[28] = gengetopt_args_info_detailed_help[34];
 
107
  gengetopt_args_info_help[29] = gengetopt_args_info_detailed_help[35];
 
108
  gengetopt_args_info_help[30] = gengetopt_args_info_detailed_help[36];
 
109
  gengetopt_args_info_help[31] = gengetopt_args_info_detailed_help[37];
 
110
  gengetopt_args_info_help[32] = gengetopt_args_info_detailed_help[38];
 
111
  gengetopt_args_info_help[33] = gengetopt_args_info_detailed_help[39];
 
112
  gengetopt_args_info_help[34] = gengetopt_args_info_detailed_help[40];
 
113
  gengetopt_args_info_help[35] = 0; 
 
114
  
 
115
}
 
116
 
 
117
const char *gengetopt_args_info_help[36];
 
118
 
 
119
typedef enum {ARG_NO
 
120
  , ARG_FLAG
 
121
  , ARG_STRING
 
122
} cmdline_parser_arg_type;
 
123
 
65
124
static
66
125
void clear_given (struct gengetopt_args_info *args_info);
67
126
static
103
162
void clear_given (struct gengetopt_args_info *args_info)
104
163
{
105
164
  args_info->help_given = 0 ;
 
165
  args_info->detailed_help_given = 0 ;
106
166
  args_info->version_given = 0 ;
107
167
  args_info->input_given = 0 ;
108
168
  args_info->func_name_given = 0 ;
118
178
  args_info->string_parser_given = 0 ;
119
179
  args_info->include_getopt_given = 0 ;
120
180
  args_info->no_handle_help_given = 0 ;
 
181
  args_info->no_help_given = 0 ;
121
182
  args_info->no_handle_version_given = 0 ;
 
183
  args_info->no_version_given = 0 ;
122
184
  args_info->no_handle_error_given = 0 ;
123
185
  args_info->show_required_given = 0 ;
124
186
  args_info->gen_version_given = 0 ;
126
188
  args_info->set_version_given = 0 ;
127
189
  args_info->show_help_given = 0 ;
128
190
  args_info->show_full_help_given = 0 ;
 
191
  args_info->show_detailed_help_given = 0 ;
129
192
  args_info->show_version_given = 0 ;
130
193
}
131
194
 
161
224
static
162
225
void init_args_info(struct gengetopt_args_info *args_info)
163
226
{
164
 
  args_info->help_help = gengetopt_args_info_help[0] ;
165
 
  args_info->version_help = gengetopt_args_info_help[1] ;
166
 
  args_info->input_help = gengetopt_args_info_help[3] ;
167
 
  args_info->func_name_help = gengetopt_args_info_help[4] ;
168
 
  args_info->arg_struct_name_help = gengetopt_args_info_help[5] ;
169
 
  args_info->file_name_help = gengetopt_args_info_help[6] ;
170
 
  args_info->output_dir_help = gengetopt_args_info_help[7] ;
171
 
  args_info->c_extension_help = gengetopt_args_info_help[8] ;
172
 
  args_info->header_extension_help = gengetopt_args_info_help[9] ;
173
 
  args_info->long_help_help = gengetopt_args_info_help[10] ;
174
 
  args_info->default_optional_help = gengetopt_args_info_help[11] ;
175
 
  args_info->unamed_opts_help = gengetopt_args_info_help[12] ;
176
 
  args_info->conf_parser_help = gengetopt_args_info_help[13] ;
177
 
  args_info->string_parser_help = gengetopt_args_info_help[14] ;
178
 
  args_info->include_getopt_help = gengetopt_args_info_help[16] ;
179
 
  args_info->no_handle_help_help = gengetopt_args_info_help[17] ;
180
 
  args_info->no_handle_version_help = gengetopt_args_info_help[18] ;
181
 
  args_info->no_handle_error_help = gengetopt_args_info_help[19] ;
182
 
  args_info->show_required_help = gengetopt_args_info_help[20] ;
183
 
  args_info->gen_version_help = gengetopt_args_info_help[21] ;
184
 
  args_info->set_package_help = gengetopt_args_info_help[22] ;
185
 
  args_info->set_version_help = gengetopt_args_info_help[23] ;
186
 
  args_info->show_help_help = gengetopt_args_info_help[24] ;
187
 
  args_info->show_full_help_help = gengetopt_args_info_help[25] ;
188
 
  args_info->show_version_help = gengetopt_args_info_help[26] ;
 
227
 
 
228
  init_help_array(); 
 
229
  args_info->help_help = gengetopt_args_info_detailed_help[0] ;
 
230
  args_info->detailed_help_help = gengetopt_args_info_detailed_help[1] ;
 
231
  args_info->version_help = gengetopt_args_info_detailed_help[2] ;
 
232
  args_info->input_help = gengetopt_args_info_detailed_help[5] ;
 
233
  args_info->func_name_help = gengetopt_args_info_detailed_help[6] ;
 
234
  args_info->arg_struct_name_help = gengetopt_args_info_detailed_help[7] ;
 
235
  args_info->file_name_help = gengetopt_args_info_detailed_help[8] ;
 
236
  args_info->output_dir_help = gengetopt_args_info_detailed_help[9] ;
 
237
  args_info->c_extension_help = gengetopt_args_info_detailed_help[11] ;
 
238
  args_info->header_extension_help = gengetopt_args_info_detailed_help[12] ;
 
239
  args_info->long_help_help = gengetopt_args_info_detailed_help[13] ;
 
240
  args_info->default_optional_help = gengetopt_args_info_detailed_help[15] ;
 
241
  args_info->unamed_opts_help = gengetopt_args_info_detailed_help[16] ;
 
242
  args_info->conf_parser_help = gengetopt_args_info_detailed_help[18] ;
 
243
  args_info->string_parser_help = gengetopt_args_info_detailed_help[19] ;
 
244
  args_info->include_getopt_help = gengetopt_args_info_detailed_help[22] ;
 
245
  args_info->no_handle_help_help = gengetopt_args_info_detailed_help[23] ;
 
246
  args_info->no_help_help = gengetopt_args_info_detailed_help[25] ;
 
247
  args_info->no_handle_version_help = gengetopt_args_info_detailed_help[27] ;
 
248
  args_info->no_version_help = gengetopt_args_info_detailed_help[28] ;
 
249
  args_info->no_handle_error_help = gengetopt_args_info_detailed_help[30] ;
 
250
  args_info->show_required_help = gengetopt_args_info_detailed_help[32] ;
 
251
  args_info->gen_version_help = gengetopt_args_info_detailed_help[33] ;
 
252
  args_info->set_package_help = gengetopt_args_info_detailed_help[34] ;
 
253
  args_info->set_version_help = gengetopt_args_info_detailed_help[35] ;
 
254
  args_info->show_help_help = gengetopt_args_info_detailed_help[36] ;
 
255
  args_info->show_full_help_help = gengetopt_args_info_detailed_help[37] ;
 
256
  args_info->show_detailed_help_help = gengetopt_args_info_detailed_help[38] ;
 
257
  args_info->show_version_help = gengetopt_args_info_detailed_help[39] ;
189
258
  
190
259
}
191
260
 
195
264
  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
196
265
}
197
266
 
198
 
void
199
 
cmdline_parser_print_help (void)
200
 
{
201
 
  int i = 0;
 
267
static void print_help_common(void) {
202
268
  cmdline_parser_print_version ();
203
269
 
204
270
  if (strlen(gengetopt_args_info_purpose) > 0)
205
271
    printf("\n%s\n", gengetopt_args_info_purpose);
206
272
 
207
 
  printf("\n%s\n\n", gengetopt_args_info_usage);
 
273
  if (strlen(gengetopt_args_info_usage) > 0)
 
274
    printf("\n%s\n", gengetopt_args_info_usage);
 
275
 
 
276
  printf("\n");
208
277
 
209
278
  if (strlen(gengetopt_args_info_description) > 0)
210
279
    printf("%s\n", gengetopt_args_info_description);
 
280
}
211
281
 
 
282
void
 
283
cmdline_parser_print_help (void)
 
284
{
 
285
  int i = 0;
 
286
  print_help_common();
212
287
  while (gengetopt_args_info_help[i])
213
288
    printf("%s\n", gengetopt_args_info_help[i++]);
214
289
}
215
290
 
216
291
void
 
292
cmdline_parser_print_detailed_help (void)
 
293
{
 
294
  int i = 0;
 
295
  print_help_common();
 
296
  while (gengetopt_args_info_detailed_help[i])
 
297
    printf("%s\n", gengetopt_args_info_detailed_help[i++]);
 
298
}
 
299
 
 
300
void
217
301
cmdline_parser_init (struct gengetopt_args_info *args_info)
218
302
{
219
303
  clear_given (args_info);
221
305
  init_args_info (args_info);
222
306
}
223
307
 
224
 
struct cmdline_parser_params *
225
 
cmdline_parser_params_init()
 
308
void
 
309
cmdline_parser_params_init(struct cmdline_parser_params *params)
226
310
{
227
 
  struct cmdline_parser_params *params = 
228
 
    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
229
 
 
230
311
  if (params)
231
312
    { 
232
313
      params->override = 0;
233
 
      params->initialize = 0;
234
 
      params->check_required = 0;
 
314
      params->initialize = 1;
 
315
      params->check_required = 1;
235
316
      params->check_ambiguity = 0;
 
317
      params->print_errors = 1;
236
318
    }
237
 
    
 
319
}
 
320
 
 
321
struct cmdline_parser_params *
 
322
cmdline_parser_params_create(void)
 
323
{
 
324
  struct cmdline_parser_params *params = 
 
325
    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
 
326
  cmdline_parser_params_init(params);  
238
327
  return params;
239
328
}
240
329
 
241
330
static void
 
331
free_string_field (char **s)
 
332
{
 
333
  if (*s)
 
334
    {
 
335
      free (*s);
 
336
      *s = 0;
 
337
    }
 
338
}
 
339
 
 
340
 
 
341
static void
242
342
cmdline_parser_release (struct gengetopt_args_info *args_info)
243
343
{
244
 
  
245
 
  if (args_info->input_arg)
246
 
    {
247
 
      free (args_info->input_arg); /* free previous argument */
248
 
      args_info->input_arg = 0;
249
 
    }
250
 
  if (args_info->input_orig)
251
 
    {
252
 
      free (args_info->input_orig); /* free previous argument */
253
 
      args_info->input_orig = 0;
254
 
    }
255
 
  if (args_info->func_name_arg)
256
 
    {
257
 
      free (args_info->func_name_arg); /* free previous argument */
258
 
      args_info->func_name_arg = 0;
259
 
    }
260
 
  if (args_info->func_name_orig)
261
 
    {
262
 
      free (args_info->func_name_orig); /* free previous argument */
263
 
      args_info->func_name_orig = 0;
264
 
    }
265
 
  if (args_info->arg_struct_name_arg)
266
 
    {
267
 
      free (args_info->arg_struct_name_arg); /* free previous argument */
268
 
      args_info->arg_struct_name_arg = 0;
269
 
    }
270
 
  if (args_info->arg_struct_name_orig)
271
 
    {
272
 
      free (args_info->arg_struct_name_orig); /* free previous argument */
273
 
      args_info->arg_struct_name_orig = 0;
274
 
    }
275
 
  if (args_info->file_name_arg)
276
 
    {
277
 
      free (args_info->file_name_arg); /* free previous argument */
278
 
      args_info->file_name_arg = 0;
279
 
    }
280
 
  if (args_info->file_name_orig)
281
 
    {
282
 
      free (args_info->file_name_orig); /* free previous argument */
283
 
      args_info->file_name_orig = 0;
284
 
    }
285
 
  if (args_info->output_dir_arg)
286
 
    {
287
 
      free (args_info->output_dir_arg); /* free previous argument */
288
 
      args_info->output_dir_arg = 0;
289
 
    }
290
 
  if (args_info->output_dir_orig)
291
 
    {
292
 
      free (args_info->output_dir_orig); /* free previous argument */
293
 
      args_info->output_dir_orig = 0;
294
 
    }
295
 
  if (args_info->c_extension_arg)
296
 
    {
297
 
      free (args_info->c_extension_arg); /* free previous argument */
298
 
      args_info->c_extension_arg = 0;
299
 
    }
300
 
  if (args_info->c_extension_orig)
301
 
    {
302
 
      free (args_info->c_extension_orig); /* free previous argument */
303
 
      args_info->c_extension_orig = 0;
304
 
    }
305
 
  if (args_info->header_extension_arg)
306
 
    {
307
 
      free (args_info->header_extension_arg); /* free previous argument */
308
 
      args_info->header_extension_arg = 0;
309
 
    }
310
 
  if (args_info->header_extension_orig)
311
 
    {
312
 
      free (args_info->header_extension_orig); /* free previous argument */
313
 
      args_info->header_extension_orig = 0;
314
 
    }
315
 
  if (args_info->unamed_opts_arg)
316
 
    {
317
 
      free (args_info->unamed_opts_arg); /* free previous argument */
318
 
      args_info->unamed_opts_arg = 0;
319
 
    }
320
 
  if (args_info->unamed_opts_orig)
321
 
    {
322
 
      free (args_info->unamed_opts_orig); /* free previous argument */
323
 
      args_info->unamed_opts_orig = 0;
324
 
    }
325
 
  if (args_info->show_required_arg)
326
 
    {
327
 
      free (args_info->show_required_arg); /* free previous argument */
328
 
      args_info->show_required_arg = 0;
329
 
    }
330
 
  if (args_info->show_required_orig)
331
 
    {
332
 
      free (args_info->show_required_orig); /* free previous argument */
333
 
      args_info->show_required_orig = 0;
334
 
    }
335
 
  if (args_info->set_package_arg)
336
 
    {
337
 
      free (args_info->set_package_arg); /* free previous argument */
338
 
      args_info->set_package_arg = 0;
339
 
    }
340
 
  if (args_info->set_package_orig)
341
 
    {
342
 
      free (args_info->set_package_orig); /* free previous argument */
343
 
      args_info->set_package_orig = 0;
344
 
    }
345
 
  if (args_info->set_version_arg)
346
 
    {
347
 
      free (args_info->set_version_arg); /* free previous argument */
348
 
      args_info->set_version_arg = 0;
349
 
    }
350
 
  if (args_info->set_version_orig)
351
 
    {
352
 
      free (args_info->set_version_orig); /* free previous argument */
353
 
      args_info->set_version_orig = 0;
354
 
    }
355
 
  
 
344
 
 
345
  free_string_field (&(args_info->input_arg));
 
346
  free_string_field (&(args_info->input_orig));
 
347
  free_string_field (&(args_info->func_name_arg));
 
348
  free_string_field (&(args_info->func_name_orig));
 
349
  free_string_field (&(args_info->arg_struct_name_arg));
 
350
  free_string_field (&(args_info->arg_struct_name_orig));
 
351
  free_string_field (&(args_info->file_name_arg));
 
352
  free_string_field (&(args_info->file_name_orig));
 
353
  free_string_field (&(args_info->output_dir_arg));
 
354
  free_string_field (&(args_info->output_dir_orig));
 
355
  free_string_field (&(args_info->c_extension_arg));
 
356
  free_string_field (&(args_info->c_extension_orig));
 
357
  free_string_field (&(args_info->header_extension_arg));
 
358
  free_string_field (&(args_info->header_extension_orig));
 
359
  free_string_field (&(args_info->unamed_opts_arg));
 
360
  free_string_field (&(args_info->unamed_opts_orig));
 
361
  free_string_field (&(args_info->show_required_arg));
 
362
  free_string_field (&(args_info->show_required_orig));
 
363
  free_string_field (&(args_info->set_package_arg));
 
364
  free_string_field (&(args_info->set_package_orig));
 
365
  free_string_field (&(args_info->set_version_arg));
 
366
  free_string_field (&(args_info->set_version_orig));
 
367
  
 
368
  
 
369
 
356
370
  clear_given (args_info);
357
371
}
358
372
 
 
373
 
 
374
static void
 
375
write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
 
376
{
 
377
  if (arg) {
 
378
    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
 
379
  } else {
 
380
    fprintf(outfile, "%s\n", opt);
 
381
  }
 
382
}
 
383
 
 
384
 
 
385
int
 
386
cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
 
387
{
 
388
  int i = 0;
 
389
 
 
390
  if (!outfile)
 
391
    {
 
392
      fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
 
393
      return EXIT_FAILURE;
 
394
    }
 
395
 
 
396
  if (args_info->help_given)
 
397
    write_into_file(outfile, "help", 0, 0 );
 
398
  if (args_info->detailed_help_given)
 
399
    write_into_file(outfile, "detailed-help", 0, 0 );
 
400
  if (args_info->version_given)
 
401
    write_into_file(outfile, "version", 0, 0 );
 
402
  if (args_info->input_given)
 
403
    write_into_file(outfile, "input", args_info->input_orig, 0);
 
404
  if (args_info->func_name_given)
 
405
    write_into_file(outfile, "func-name", args_info->func_name_orig, 0);
 
406
  if (args_info->arg_struct_name_given)
 
407
    write_into_file(outfile, "arg-struct-name", args_info->arg_struct_name_orig, 0);
 
408
  if (args_info->file_name_given)
 
409
    write_into_file(outfile, "file-name", args_info->file_name_orig, 0);
 
410
  if (args_info->output_dir_given)
 
411
    write_into_file(outfile, "output-dir", args_info->output_dir_orig, 0);
 
412
  if (args_info->c_extension_given)
 
413
    write_into_file(outfile, "c-extension", args_info->c_extension_orig, 0);
 
414
  if (args_info->header_extension_given)
 
415
    write_into_file(outfile, "header-extension", args_info->header_extension_orig, 0);
 
416
  if (args_info->long_help_given)
 
417
    write_into_file(outfile, "long-help", 0, 0 );
 
418
  if (args_info->default_optional_given)
 
419
    write_into_file(outfile, "default-optional", 0, 0 );
 
420
  if (args_info->unamed_opts_given)
 
421
    write_into_file(outfile, "unamed-opts", args_info->unamed_opts_orig, 0);
 
422
  if (args_info->conf_parser_given)
 
423
    write_into_file(outfile, "conf-parser", 0, 0 );
 
424
  if (args_info->string_parser_given)
 
425
    write_into_file(outfile, "string-parser", 0, 0 );
 
426
  if (args_info->include_getopt_given)
 
427
    write_into_file(outfile, "include-getopt", 0, 0 );
 
428
  if (args_info->no_handle_help_given)
 
429
    write_into_file(outfile, "no-handle-help", 0, 0 );
 
430
  if (args_info->no_help_given)
 
431
    write_into_file(outfile, "no-help", 0, 0 );
 
432
  if (args_info->no_handle_version_given)
 
433
    write_into_file(outfile, "no-handle-version", 0, 0 );
 
434
  if (args_info->no_version_given)
 
435
    write_into_file(outfile, "no-version", 0, 0 );
 
436
  if (args_info->no_handle_error_given)
 
437
    write_into_file(outfile, "no-handle-error", 0, 0 );
 
438
  if (args_info->show_required_given)
 
439
    write_into_file(outfile, "show-required", args_info->show_required_orig, 0);
 
440
  if (args_info->gen_version_given)
 
441
    write_into_file(outfile, "gen-version", 0, 0 );
 
442
  if (args_info->set_package_given)
 
443
    write_into_file(outfile, "set-package", args_info->set_package_orig, 0);
 
444
  if (args_info->set_version_given)
 
445
    write_into_file(outfile, "set-version", args_info->set_version_orig, 0);
 
446
  if (args_info->show_help_given)
 
447
    write_into_file(outfile, "show-help", 0, 0 );
 
448
  if (args_info->show_full_help_given)
 
449
    write_into_file(outfile, "show-full-help", 0, 0 );
 
450
  if (args_info->show_detailed_help_given)
 
451
    write_into_file(outfile, "show-detailed-help", 0, 0 );
 
452
  if (args_info->show_version_given)
 
453
    write_into_file(outfile, "show-version", 0, 0 );
 
454
  
 
455
 
 
456
  i = EXIT_SUCCESS;
 
457
  return i;
 
458
}
 
459
 
359
460
int
360
461
cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
361
462
{
370
471
      return EXIT_FAILURE;
371
472
    }
372
473
 
373
 
  if (args_info->help_given) {
374
 
    fprintf(outfile, "%s\n", "help");
375
 
  }
376
 
  if (args_info->version_given) {
377
 
    fprintf(outfile, "%s\n", "version");
378
 
  }
379
 
  if (args_info->input_given) {
380
 
    if (args_info->input_orig) {
381
 
      fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig);
382
 
    } else {
383
 
      fprintf(outfile, "%s\n", "input");
384
 
    }
385
 
  }
386
 
  if (args_info->func_name_given) {
387
 
    if (args_info->func_name_orig) {
388
 
      fprintf(outfile, "%s=\"%s\"\n", "func-name", args_info->func_name_orig);
389
 
    } else {
390
 
      fprintf(outfile, "%s\n", "func-name");
391
 
    }
392
 
  }
393
 
  if (args_info->arg_struct_name_given) {
394
 
    if (args_info->arg_struct_name_orig) {
395
 
      fprintf(outfile, "%s=\"%s\"\n", "arg-struct-name", args_info->arg_struct_name_orig);
396
 
    } else {
397
 
      fprintf(outfile, "%s\n", "arg-struct-name");
398
 
    }
399
 
  }
400
 
  if (args_info->file_name_given) {
401
 
    if (args_info->file_name_orig) {
402
 
      fprintf(outfile, "%s=\"%s\"\n", "file-name", args_info->file_name_orig);
403
 
    } else {
404
 
      fprintf(outfile, "%s\n", "file-name");
405
 
    }
406
 
  }
407
 
  if (args_info->output_dir_given) {
408
 
    if (args_info->output_dir_orig) {
409
 
      fprintf(outfile, "%s=\"%s\"\n", "output-dir", args_info->output_dir_orig);
410
 
    } else {
411
 
      fprintf(outfile, "%s\n", "output-dir");
412
 
    }
413
 
  }
414
 
  if (args_info->c_extension_given) {
415
 
    if (args_info->c_extension_orig) {
416
 
      fprintf(outfile, "%s=\"%s\"\n", "c-extension", args_info->c_extension_orig);
417
 
    } else {
418
 
      fprintf(outfile, "%s\n", "c-extension");
419
 
    }
420
 
  }
421
 
  if (args_info->header_extension_given) {
422
 
    if (args_info->header_extension_orig) {
423
 
      fprintf(outfile, "%s=\"%s\"\n", "header-extension", args_info->header_extension_orig);
424
 
    } else {
425
 
      fprintf(outfile, "%s\n", "header-extension");
426
 
    }
427
 
  }
428
 
  if (args_info->long_help_given) {
429
 
    fprintf(outfile, "%s\n", "long-help");
430
 
  }
431
 
  if (args_info->default_optional_given) {
432
 
    fprintf(outfile, "%s\n", "default-optional");
433
 
  }
434
 
  if (args_info->unamed_opts_given) {
435
 
    if (args_info->unamed_opts_orig) {
436
 
      fprintf(outfile, "%s=\"%s\"\n", "unamed-opts", args_info->unamed_opts_orig);
437
 
    } else {
438
 
      fprintf(outfile, "%s\n", "unamed-opts");
439
 
    }
440
 
  }
441
 
  if (args_info->conf_parser_given) {
442
 
    fprintf(outfile, "%s\n", "conf-parser");
443
 
  }
444
 
  if (args_info->string_parser_given) {
445
 
    fprintf(outfile, "%s\n", "string-parser");
446
 
  }
447
 
  if (args_info->include_getopt_given) {
448
 
    fprintf(outfile, "%s\n", "include-getopt");
449
 
  }
450
 
  if (args_info->no_handle_help_given) {
451
 
    fprintf(outfile, "%s\n", "no-handle-help");
452
 
  }
453
 
  if (args_info->no_handle_version_given) {
454
 
    fprintf(outfile, "%s\n", "no-handle-version");
455
 
  }
456
 
  if (args_info->no_handle_error_given) {
457
 
    fprintf(outfile, "%s\n", "no-handle-error");
458
 
  }
459
 
  if (args_info->show_required_given) {
460
 
    if (args_info->show_required_orig) {
461
 
      fprintf(outfile, "%s=\"%s\"\n", "show-required", args_info->show_required_orig);
462
 
    } else {
463
 
      fprintf(outfile, "%s\n", "show-required");
464
 
    }
465
 
  }
466
 
  if (args_info->gen_version_given) {
467
 
    fprintf(outfile, "%s\n", "gen-version");
468
 
  }
469
 
  if (args_info->set_package_given) {
470
 
    if (args_info->set_package_orig) {
471
 
      fprintf(outfile, "%s=\"%s\"\n", "set-package", args_info->set_package_orig);
472
 
    } else {
473
 
      fprintf(outfile, "%s\n", "set-package");
474
 
    }
475
 
  }
476
 
  if (args_info->set_version_given) {
477
 
    if (args_info->set_version_orig) {
478
 
      fprintf(outfile, "%s=\"%s\"\n", "set-version", args_info->set_version_orig);
479
 
    } else {
480
 
      fprintf(outfile, "%s\n", "set-version");
481
 
    }
482
 
  }
483
 
  if (args_info->show_help_given) {
484
 
    fprintf(outfile, "%s\n", "show-help");
485
 
  }
486
 
  if (args_info->show_full_help_given) {
487
 
    fprintf(outfile, "%s\n", "show-full-help");
488
 
  }
489
 
  if (args_info->show_version_given) {
490
 
    fprintf(outfile, "%s\n", "show-version");
491
 
  }
492
 
  
 
474
  i = cmdline_parser_dump(outfile, args_info);
493
475
  fclose (outfile);
494
476
 
495
 
  i = EXIT_SUCCESS;
496
477
  return i;
497
478
}
498
479
 
502
483
  cmdline_parser_release (args_info);
503
484
}
504
485
 
505
 
 
506
 
/* gengetopt_strdup() */
507
 
/* strdup.c replacement of strdup, which is not standard */
 
486
/** @brief replacement of strdup, which is not standard */
508
487
char *
509
488
gengetopt_strdup (const char *s)
510
489
{
545
524
  params.initialize = initialize;
546
525
  params.check_required = check_required;
547
526
  params.check_ambiguity = 0;
 
527
  params.print_errors = 1;
548
528
 
549
529
  result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
550
530
 
557
537
  return EXIT_SUCCESS;
558
538
}
559
539
 
 
540
 
 
541
static char *package_name = 0;
 
542
 
 
543
/**
 
544
 * @brief updates an option
 
545
 * @param field the generic pointer to the field to update
 
546
 * @param orig_field the pointer to the orig field
 
547
 * @param field_given the pointer to the number of occurrence of this option
 
548
 * @param prev_given the pointer to the number of occurrence already seen
 
549
 * @param value the argument for this option (if null no arg was specified)
 
550
 * @param possible_values the possible values for this option (if specified)
 
551
 * @param default_value the default value (in case the option only accepts fixed values)
 
552
 * @param arg_type the type of this option
 
553
 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
 
554
 * @param override @see cmdline_parser_params.override
 
555
 * @param no_free whether to free a possible previous value
 
556
 * @param multiple_option whether this is a multiple option
 
557
 * @param long_opt the corresponding long option
 
558
 * @param short_opt the corresponding short option (or '-' if none)
 
559
 * @param additional_error possible further error specification
 
560
 */
 
561
static
 
562
int update_arg(void *field, char **orig_field,
 
563
               unsigned int *field_given, unsigned int *prev_given, 
 
564
               char *value, char *possible_values[], const char *default_value,
 
565
               cmdline_parser_arg_type arg_type,
 
566
               short check_ambiguity, short override,
 
567
               short no_free, short multiple_option,
 
568
               const char *long_opt, char short_opt,
 
569
               const char *additional_error)
 
570
{
 
571
  char *stop_char = 0;
 
572
  const char *val = value;
 
573
  int found;
 
574
  char **string_field;
 
575
 
 
576
  stop_char = 0;
 
577
  found = 0;
 
578
 
 
579
  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
 
580
    {
 
581
      if (short_opt != '-')
 
582
        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", 
 
583
               package_name, long_opt, short_opt,
 
584
               (additional_error ? additional_error : ""));
 
585
      else
 
586
        fprintf (stderr, "%s: `--%s' option given more than once%s\n", 
 
587
               package_name, long_opt,
 
588
               (additional_error ? additional_error : ""));
 
589
      return 1; /* failure */
 
590
    }
 
591
 
 
592
    
 
593
  if (field_given && *field_given && ! override)
 
594
    return 0;
 
595
  if (prev_given)
 
596
    (*prev_given)++;
 
597
  if (field_given)
 
598
    (*field_given)++;
 
599
  if (possible_values)
 
600
    val = possible_values[found];
 
601
 
 
602
  switch(arg_type) {
 
603
  case ARG_FLAG:
 
604
    *((int *)field) = !*((int *)field);
 
605
    break;
 
606
  case ARG_STRING:
 
607
    if (val) {
 
608
      string_field = (char **)field;
 
609
      if (!no_free && *string_field)
 
610
        free (*string_field); /* free previous string */
 
611
      *string_field = gengetopt_strdup (val);
 
612
    }
 
613
    break;
 
614
  default:
 
615
    break;
 
616
  };
 
617
 
 
618
 
 
619
  /* store the original value */
 
620
  switch(arg_type) {
 
621
  case ARG_NO:
 
622
  case ARG_FLAG:
 
623
    break;
 
624
  default:
 
625
    if (value && orig_field) {
 
626
      if (no_free) {
 
627
        *orig_field = value;
 
628
      } else {
 
629
        if (*orig_field)
 
630
          free (*orig_field); /* free previous string */
 
631
        *orig_field = gengetopt_strdup (value);
 
632
      }
 
633
    }
 
634
  };
 
635
 
 
636
  return 0; /* OK */
 
637
}
 
638
 
 
639
 
560
640
int
561
641
cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
562
642
                        struct cmdline_parser_params *params, const char *additional_error)
571
651
  int check_required;
572
652
  int check_ambiguity;
573
653
  
 
654
  package_name = argv[0];
 
655
  
574
656
  override = params->override;
575
657
  initialize = params->initialize;
576
658
  check_required = params->check_required;
583
665
 
584
666
  optarg = 0;
585
667
  optind = 0;
586
 
  opterr = 1;
 
668
  opterr = params->print_errors;
587
669
  optopt = '?';
588
670
 
589
671
  while (1)
590
672
    {
591
673
      int option_index = 0;
592
 
      char *stop_char;
593
674
 
594
675
      static struct option long_options[] = {
595
676
        { "help",       0, NULL, 'h' },
 
677
        { "detailed-help",      0, NULL, 0 },
596
678
        { "version",    0, NULL, 'V' },
597
679
        { "input",      1, NULL, 'i' },
598
680
        { "func-name",  1, NULL, 'f' },
608
690
        { "string-parser",      0, NULL, 'S' },
609
691
        { "include-getopt",     0, NULL, 'G' },
610
692
        { "no-handle-help",     0, NULL, 'n' },
 
693
        { "no-help",    0, NULL, 0 },
611
694
        { "no-handle-version",  0, NULL, 'N' },
 
695
        { "no-version", 0, NULL, 0 },
612
696
        { "no-handle-error",    0, NULL, 'e' },
613
697
        { "show-required",      2, NULL, 0 },
614
698
        { "gen-version",        0, NULL, 'g' },
616
700
        { "set-version",        1, NULL, 0 },
617
701
        { "show-help",  0, NULL, 0 },
618
702
        { "show-full-help",     0, NULL, 0 },
 
703
        { "show-detailed-help", 0, NULL, 0 },
619
704
        { "show-version",       0, NULL, 0 },
620
705
        { NULL, 0, NULL, 0 }
621
706
      };
622
707
 
623
 
      stop_char = 0;
624
708
      c = getopt_long (argc, argv, "hVi:f:a:F:c:H:lu::CSGnNeg", long_options, &option_index);
625
709
 
626
710
      if (c == -1) break;       /* Exit from `while (1)' loop.  */
628
712
      switch (c)
629
713
        {
630
714
        case 'h':       /* Print help and exit.  */
631
 
          if (local_args_info.help_given || (check_ambiguity && args_info->help_given))
632
 
            {
633
 
              fprintf (stderr, "%s: `--help' (`-h') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
634
 
              goto failure;
635
 
            }
636
 
          if (args_info->help_given && ! override)
637
 
            continue;
638
 
          local_args_info.help_given = 1;
639
 
          args_info->help_given = 1;
 
715
        
 
716
        
 
717
          if (update_arg( 0 , 
 
718
               0 , &(args_info->help_given),
 
719
              &(local_args_info.help_given), optarg, 0, 0, ARG_NO,
 
720
              check_ambiguity, override, 0, 0,
 
721
              "help", 'h',
 
722
              additional_error))
 
723
            goto failure;
640
724
          cmdline_parser_free (&local_args_info);
641
725
          return 0;
642
 
 
 
726
        
 
727
          break;
643
728
        case 'V':       /* Print version and exit.  */
644
 
          if (local_args_info.version_given || (check_ambiguity && args_info->version_given))
645
 
            {
646
 
              fprintf (stderr, "%s: `--version' (`-V') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
647
 
              goto failure;
648
 
            }
649
 
          if (args_info->version_given && ! override)
650
 
            continue;
651
 
          local_args_info.version_given = 1;
652
 
          args_info->version_given = 1;
 
729
        
 
730
        
 
731
          if (update_arg( 0 , 
 
732
               0 , &(args_info->version_given),
 
733
              &(local_args_info.version_given), optarg, 0, 0, ARG_NO,
 
734
              check_ambiguity, override, 0, 0,
 
735
              "version", 'V',
 
736
              additional_error))
 
737
            goto failure;
653
738
          cmdline_parser_free (&local_args_info);
654
739
          return 0;
655
 
 
 
740
        
 
741
          break;
656
742
        case 'i':       /* input file (default std input).  */
657
 
          if (local_args_info.input_given || (check_ambiguity && args_info->input_given))
658
 
            {
659
 
              fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
660
 
              goto failure;
661
 
            }
662
 
          if (args_info->input_given && ! override)
663
 
            continue;
664
 
          local_args_info.input_given = 1;
665
 
          args_info->input_given = 1;
666
 
          if (args_info->input_arg)
667
 
            free (args_info->input_arg); /* free previous string */
668
 
          args_info->input_arg = gengetopt_strdup (optarg);
669
 
          if (args_info->input_orig)
670
 
            free (args_info->input_orig); /* free previous string */
671
 
          args_info->input_orig = gengetopt_strdup (optarg);
 
743
        
 
744
        
 
745
          if (update_arg( (void *)&(args_info->input_arg), 
 
746
               &(args_info->input_orig), &(args_info->input_given),
 
747
              &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
 
748
              check_ambiguity, override, 0, 0,
 
749
              "input", 'i',
 
750
              additional_error))
 
751
            goto failure;
 
752
        
672
753
          break;
673
 
 
674
754
        case 'f':       /* name of generated function.  */
675
 
          if (local_args_info.func_name_given || (check_ambiguity && args_info->func_name_given))
676
 
            {
677
 
              fprintf (stderr, "%s: `--func-name' (`-f') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
678
 
              goto failure;
679
 
            }
680
 
          if (args_info->func_name_given && ! override)
681
 
            continue;
682
 
          local_args_info.func_name_given = 1;
683
 
          args_info->func_name_given = 1;
684
 
          if (args_info->func_name_arg)
685
 
            free (args_info->func_name_arg); /* free previous string */
686
 
          args_info->func_name_arg = gengetopt_strdup (optarg);
687
 
          if (args_info->func_name_orig)
688
 
            free (args_info->func_name_orig); /* free previous string */
689
 
          args_info->func_name_orig = gengetopt_strdup (optarg);
 
755
        
 
756
        
 
757
          if (update_arg( (void *)&(args_info->func_name_arg), 
 
758
               &(args_info->func_name_orig), &(args_info->func_name_given),
 
759
              &(local_args_info.func_name_given), optarg, 0, "cmdline_parser", ARG_STRING,
 
760
              check_ambiguity, override, 0, 0,
 
761
              "func-name", 'f',
 
762
              additional_error))
 
763
            goto failure;
 
764
        
690
765
          break;
691
 
 
692
766
        case 'a':       /* name of generated args info struct.  */
693
 
          if (local_args_info.arg_struct_name_given || (check_ambiguity && args_info->arg_struct_name_given))
694
 
            {
695
 
              fprintf (stderr, "%s: `--arg-struct-name' (`-a') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
696
 
              goto failure;
697
 
            }
698
 
          if (args_info->arg_struct_name_given && ! override)
699
 
            continue;
700
 
          local_args_info.arg_struct_name_given = 1;
701
 
          args_info->arg_struct_name_given = 1;
702
 
          if (args_info->arg_struct_name_arg)
703
 
            free (args_info->arg_struct_name_arg); /* free previous string */
704
 
          args_info->arg_struct_name_arg = gengetopt_strdup (optarg);
705
 
          if (args_info->arg_struct_name_orig)
706
 
            free (args_info->arg_struct_name_orig); /* free previous string */
707
 
          args_info->arg_struct_name_orig = gengetopt_strdup (optarg);
 
767
        
 
768
        
 
769
          if (update_arg( (void *)&(args_info->arg_struct_name_arg), 
 
770
               &(args_info->arg_struct_name_orig), &(args_info->arg_struct_name_given),
 
771
              &(local_args_info.arg_struct_name_given), optarg, 0, "gengetopt_args_info", ARG_STRING,
 
772
              check_ambiguity, override, 0, 0,
 
773
              "arg-struct-name", 'a',
 
774
              additional_error))
 
775
            goto failure;
 
776
        
708
777
          break;
709
 
 
710
778
        case 'F':       /* name of generated file.  */
711
 
          if (local_args_info.file_name_given || (check_ambiguity && args_info->file_name_given))
712
 
            {
713
 
              fprintf (stderr, "%s: `--file-name' (`-F') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
714
 
              goto failure;
715
 
            }
716
 
          if (args_info->file_name_given && ! override)
717
 
            continue;
718
 
          local_args_info.file_name_given = 1;
719
 
          args_info->file_name_given = 1;
720
 
          if (args_info->file_name_arg)
721
 
            free (args_info->file_name_arg); /* free previous string */
722
 
          args_info->file_name_arg = gengetopt_strdup (optarg);
723
 
          if (args_info->file_name_orig)
724
 
            free (args_info->file_name_orig); /* free previous string */
725
 
          args_info->file_name_orig = gengetopt_strdup (optarg);
 
779
        
 
780
        
 
781
          if (update_arg( (void *)&(args_info->file_name_arg), 
 
782
               &(args_info->file_name_orig), &(args_info->file_name_given),
 
783
              &(local_args_info.file_name_given), optarg, 0, "cmdline", ARG_STRING,
 
784
              check_ambiguity, override, 0, 0,
 
785
              "file-name", 'F',
 
786
              additional_error))
 
787
            goto failure;
 
788
        
726
789
          break;
727
 
 
728
790
        case 'c':       /* extension of c file.  */
729
 
          if (local_args_info.c_extension_given || (check_ambiguity && args_info->c_extension_given))
730
 
            {
731
 
              fprintf (stderr, "%s: `--c-extension' (`-c') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
732
 
              goto failure;
733
 
            }
734
 
          if (args_info->c_extension_given && ! override)
735
 
            continue;
736
 
          local_args_info.c_extension_given = 1;
737
 
          args_info->c_extension_given = 1;
738
 
          if (args_info->c_extension_arg)
739
 
            free (args_info->c_extension_arg); /* free previous string */
740
 
          args_info->c_extension_arg = gengetopt_strdup (optarg);
741
 
          if (args_info->c_extension_orig)
742
 
            free (args_info->c_extension_orig); /* free previous string */
743
 
          args_info->c_extension_orig = gengetopt_strdup (optarg);
 
791
        
 
792
        
 
793
          if (update_arg( (void *)&(args_info->c_extension_arg), 
 
794
               &(args_info->c_extension_orig), &(args_info->c_extension_given),
 
795
              &(local_args_info.c_extension_given), optarg, 0, "c", ARG_STRING,
 
796
              check_ambiguity, override, 0, 0,
 
797
              "c-extension", 'c',
 
798
              additional_error))
 
799
            goto failure;
 
800
        
744
801
          break;
745
 
 
746
802
        case 'H':       /* extension of header file.  */
747
 
          if (local_args_info.header_extension_given || (check_ambiguity && args_info->header_extension_given))
748
 
            {
749
 
              fprintf (stderr, "%s: `--header-extension' (`-H') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
750
 
              goto failure;
751
 
            }
752
 
          if (args_info->header_extension_given && ! override)
753
 
            continue;
754
 
          local_args_info.header_extension_given = 1;
755
 
          args_info->header_extension_given = 1;
756
 
          if (args_info->header_extension_arg)
757
 
            free (args_info->header_extension_arg); /* free previous string */
758
 
          args_info->header_extension_arg = gengetopt_strdup (optarg);
759
 
          if (args_info->header_extension_orig)
760
 
            free (args_info->header_extension_orig); /* free previous string */
761
 
          args_info->header_extension_orig = gengetopt_strdup (optarg);
 
803
        
 
804
        
 
805
          if (update_arg( (void *)&(args_info->header_extension_arg), 
 
806
               &(args_info->header_extension_orig), &(args_info->header_extension_given),
 
807
              &(local_args_info.header_extension_given), optarg, 0, "h", ARG_STRING,
 
808
              check_ambiguity, override, 0, 0,
 
809
              "header-extension", 'H',
 
810
              additional_error))
 
811
            goto failure;
 
812
        
762
813
          break;
763
 
 
764
814
        case 'l':       /* long usage line in help.  */
765
 
          if (local_args_info.long_help_given || (check_ambiguity && args_info->long_help_given))
766
 
            {
767
 
              fprintf (stderr, "%s: `--long-help' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
768
 
              goto failure;
769
 
            }
770
 
          if (args_info->long_help_given && ! override)
771
 
            continue;
772
 
          local_args_info.long_help_given = 1;
773
 
          args_info->long_help_given = 1;
 
815
        
 
816
        
 
817
          if (update_arg( 0 , 
 
818
               0 , &(args_info->long_help_given),
 
819
              &(local_args_info.long_help_given), optarg, 0, 0, ARG_NO,
 
820
              check_ambiguity, override, 0, 0,
 
821
              "long-help", 'l',
 
822
              additional_error))
 
823
            goto failure;
 
824
        
774
825
          break;
775
 
 
776
826
        case 'u':       /* accept options without names (e.g., file names).  */
777
 
          if (local_args_info.unamed_opts_given || (check_ambiguity && args_info->unamed_opts_given))
778
 
            {
779
 
              fprintf (stderr, "%s: `--unamed-opts' (`-u') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
780
 
              goto failure;
781
 
            }
782
 
          if (args_info->unamed_opts_given && ! override)
783
 
            continue;
784
 
          local_args_info.unamed_opts_given = 1;
785
 
          args_info->unamed_opts_given = 1;
786
 
          if (optarg)
787
 
            {
788
 
              if (args_info->unamed_opts_arg)
789
 
                free (args_info->unamed_opts_arg); /* free previous string */
790
 
              args_info->unamed_opts_arg = gengetopt_strdup (optarg);
791
 
              if (args_info->unamed_opts_orig)
792
 
                free (args_info->unamed_opts_orig); /* free previous string */
793
 
              args_info->unamed_opts_orig = gengetopt_strdup (optarg);
794
 
            }
 
827
        
 
828
        
 
829
          if (update_arg( (void *)&(args_info->unamed_opts_arg), 
 
830
               &(args_info->unamed_opts_orig), &(args_info->unamed_opts_given),
 
831
              &(local_args_info.unamed_opts_given), optarg, 0, "FILES", ARG_STRING,
 
832
              check_ambiguity, override, 0, 0,
 
833
              "unamed-opts", 'u',
 
834
              additional_error))
 
835
            goto failure;
 
836
        
795
837
          break;
796
 
 
797
838
        case 'C':       /* generate a config file parser.  */
798
 
          if (local_args_info.conf_parser_given || (check_ambiguity && args_info->conf_parser_given))
799
 
            {
800
 
              fprintf (stderr, "%s: `--conf-parser' (`-C') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
801
 
              goto failure;
802
 
            }
803
 
          if (args_info->conf_parser_given && ! override)
804
 
            continue;
805
 
          local_args_info.conf_parser_given = 1;
806
 
          args_info->conf_parser_given = 1;
 
839
        
 
840
        
 
841
          if (update_arg( 0 , 
 
842
               0 , &(args_info->conf_parser_given),
 
843
              &(local_args_info.conf_parser_given), optarg, 0, 0, ARG_NO,
 
844
              check_ambiguity, override, 0, 0,
 
845
              "conf-parser", 'C',
 
846
              additional_error))
 
847
            goto failure;
 
848
        
807
849
          break;
808
 
 
809
850
        case 'S':       /* generate a string parser (the string contains the command line).  */
810
 
          if (local_args_info.string_parser_given || (check_ambiguity && args_info->string_parser_given))
811
 
            {
812
 
              fprintf (stderr, "%s: `--string-parser' (`-S') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
813
 
              goto failure;
814
 
            }
815
 
          if (args_info->string_parser_given && ! override)
816
 
            continue;
817
 
          local_args_info.string_parser_given = 1;
818
 
          args_info->string_parser_given = 1;
 
851
        
 
852
        
 
853
          if (update_arg( 0 , 
 
854
               0 , &(args_info->string_parser_given),
 
855
              &(local_args_info.string_parser_given), optarg, 0, 0, ARG_NO,
 
856
              check_ambiguity, override, 0, 0,
 
857
              "string-parser", 'S',
 
858
              additional_error))
 
859
            goto failure;
 
860
        
819
861
          break;
820
 
 
821
862
        case 'G':       /* adds the code for getopt_long in the generated C file.  */
822
 
          if (local_args_info.include_getopt_given || (check_ambiguity && args_info->include_getopt_given))
823
 
            {
824
 
              fprintf (stderr, "%s: `--include-getopt' (`-G') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
825
 
              goto failure;
826
 
            }
827
 
          if (args_info->include_getopt_given && ! override)
828
 
            continue;
829
 
          local_args_info.include_getopt_given = 1;
830
 
          args_info->include_getopt_given = 1;
 
863
        
 
864
        
 
865
          if (update_arg( 0 , 
 
866
               0 , &(args_info->include_getopt_given),
 
867
              &(local_args_info.include_getopt_given), optarg, 0, 0, ARG_NO,
 
868
              check_ambiguity, override, 0, 0,
 
869
              "include-getopt", 'G',
 
870
              additional_error))
 
871
            goto failure;
 
872
        
831
873
          break;
832
 
 
833
874
        case 'n':       /* do not handle --help|-h automatically.  */
834
 
          if (local_args_info.no_handle_help_given || (check_ambiguity && args_info->no_handle_help_given))
835
 
            {
836
 
              fprintf (stderr, "%s: `--no-handle-help' (`-n') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
837
 
              goto failure;
838
 
            }
839
 
          if (args_info->no_handle_help_given && ! override)
840
 
            continue;
841
 
          local_args_info.no_handle_help_given = 1;
842
 
          args_info->no_handle_help_given = 1;
 
875
        
 
876
        
 
877
          if (update_arg( 0 , 
 
878
               0 , &(args_info->no_handle_help_given),
 
879
              &(local_args_info.no_handle_help_given), optarg, 0, 0, ARG_NO,
 
880
              check_ambiguity, override, 0, 0,
 
881
              "no-handle-help", 'n',
 
882
              additional_error))
 
883
            goto failure;
 
884
        
843
885
          break;
844
 
 
845
886
        case 'N':       /* do not handle --version|-V automatically.  */
846
 
          if (local_args_info.no_handle_version_given || (check_ambiguity && args_info->no_handle_version_given))
847
 
            {
848
 
              fprintf (stderr, "%s: `--no-handle-version' (`-N') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
849
 
              goto failure;
850
 
            }
851
 
          if (args_info->no_handle_version_given && ! override)
852
 
            continue;
853
 
          local_args_info.no_handle_version_given = 1;
854
 
          args_info->no_handle_version_given = 1;
 
887
        
 
888
        
 
889
          if (update_arg( 0 , 
 
890
               0 , &(args_info->no_handle_version_given),
 
891
              &(local_args_info.no_handle_version_given), optarg, 0, 0, ARG_NO,
 
892
              check_ambiguity, override, 0, 0,
 
893
              "no-handle-version", 'N',
 
894
              additional_error))
 
895
            goto failure;
 
896
        
855
897
          break;
856
 
 
857
898
        case 'e':       /* do not exit on errors.  */
858
 
          if (local_args_info.no_handle_error_given || (check_ambiguity && args_info->no_handle_error_given))
859
 
            {
860
 
              fprintf (stderr, "%s: `--no-handle-error' (`-e') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
861
 
              goto failure;
862
 
            }
863
 
          if (args_info->no_handle_error_given && ! override)
864
 
            continue;
865
 
          local_args_info.no_handle_error_given = 1;
866
 
          args_info->no_handle_error_given = 1;
 
899
        
 
900
        
 
901
          if (update_arg( 0 , 
 
902
               0 , &(args_info->no_handle_error_given),
 
903
              &(local_args_info.no_handle_error_given), optarg, 0, 0, ARG_NO,
 
904
              check_ambiguity, override, 0, 0,
 
905
              "no-handle-error", 'e',
 
906
              additional_error))
 
907
            goto failure;
 
908
        
867
909
          break;
868
 
 
869
910
        case 'g':       /* put gengetopt version in the generated file.  */
870
 
          if (local_args_info.gen_version_given || (check_ambiguity && args_info->gen_version_given))
871
 
            {
872
 
              fprintf (stderr, "%s: `--gen-version' (`-g') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
873
 
              goto failure;
874
 
            }
875
 
          if (args_info->gen_version_given && ! override)
876
 
            continue;
877
 
          local_args_info.gen_version_given = 1;
878
 
          args_info->gen_version_given = 1;
879
 
          args_info->gen_version_flag = !(args_info->gen_version_flag);
 
911
        
 
912
        
 
913
          if (update_arg((void *)&(args_info->gen_version_flag), 0, &(args_info->gen_version_given),
 
914
              &(local_args_info.gen_version_given), optarg, 0, 0, ARG_FLAG,
 
915
              check_ambiguity, override, 1, 0, "gen-version", 'g',
 
916
              additional_error))
 
917
            goto failure;
 
918
        
880
919
          break;
881
920
 
882
 
 
883
921
        case 0: /* Long option with no short option */
 
922
          /* Print help, including all details and hidden options, and exit.  */
 
923
          if (strcmp (long_options[option_index].name, "detailed-help") == 0)
 
924
          {
 
925
          
 
926
          
 
927
            if (update_arg( 0 , 
 
928
                 0 , &(args_info->detailed_help_given),
 
929
                &(local_args_info.detailed_help_given), optarg, 0, 0, ARG_NO,
 
930
                check_ambiguity, override, 0, 0,
 
931
                "detailed-help", '-',
 
932
                additional_error))
 
933
              goto failure;
 
934
            cmdline_parser_free (&local_args_info);
 
935
            return 0;
 
936
          
 
937
          }
884
938
          /* output directory.  */
885
 
          if (strcmp (long_options[option_index].name, "output-dir") == 0)
 
939
          else if (strcmp (long_options[option_index].name, "output-dir") == 0)
886
940
          {
887
 
            if (local_args_info.output_dir_given || (check_ambiguity && args_info->output_dir_given))
888
 
              {
889
 
                fprintf (stderr, "%s: `--output-dir' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
890
 
                goto failure;
891
 
              }
892
 
            if (args_info->output_dir_given && ! override)
893
 
              continue;
894
 
            local_args_info.output_dir_given = 1;
895
 
            args_info->output_dir_given = 1;
896
 
            if (args_info->output_dir_arg)
897
 
              free (args_info->output_dir_arg); /* free previous string */
898
 
            args_info->output_dir_arg = gengetopt_strdup (optarg);
899
 
            if (args_info->output_dir_orig)
900
 
              free (args_info->output_dir_orig); /* free previous string */
901
 
            args_info->output_dir_orig = gengetopt_strdup (optarg);
 
941
          
 
942
          
 
943
            if (update_arg( (void *)&(args_info->output_dir_arg), 
 
944
                 &(args_info->output_dir_orig), &(args_info->output_dir_given),
 
945
                &(local_args_info.output_dir_given), optarg, 0, 0, ARG_STRING,
 
946
                check_ambiguity, override, 0, 0,
 
947
                "output-dir", '-',
 
948
                additional_error))
 
949
              goto failure;
 
950
          
902
951
          }
903
952
          /* by default, an option is considered optional if not specified otherwise.  */
904
953
          else if (strcmp (long_options[option_index].name, "default-optional") == 0)
905
954
          {
906
 
            if (local_args_info.default_optional_given || (check_ambiguity && args_info->default_optional_given))
907
 
              {
908
 
                fprintf (stderr, "%s: `--default-optional' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
909
 
                goto failure;
910
 
              }
911
 
            if (args_info->default_optional_given && ! override)
912
 
              continue;
913
 
            local_args_info.default_optional_given = 1;
914
 
            args_info->default_optional_given = 1;
915
 
            break;
 
955
          
 
956
          
 
957
            if (update_arg( 0 , 
 
958
                 0 , &(args_info->default_optional_given),
 
959
                &(local_args_info.default_optional_given), optarg, 0, 0, ARG_NO,
 
960
                check_ambiguity, override, 0, 0,
 
961
                "default-optional", '-',
 
962
                additional_error))
 
963
              goto failure;
 
964
          
 
965
          }
 
966
          /* do not add --help|-h automatically.  */
 
967
          else if (strcmp (long_options[option_index].name, "no-help") == 0)
 
968
          {
 
969
          
 
970
          
 
971
            if (update_arg( 0 , 
 
972
                 0 , &(args_info->no_help_given),
 
973
                &(local_args_info.no_help_given), optarg, 0, 0, ARG_NO,
 
974
                check_ambiguity, override, 0, 0,
 
975
                "no-help", '-',
 
976
                additional_error))
 
977
              goto failure;
 
978
          
 
979
          }
 
980
          /* do not add --version|-V automatically.  */
 
981
          else if (strcmp (long_options[option_index].name, "no-version") == 0)
 
982
          {
 
983
          
 
984
          
 
985
            if (update_arg( 0 , 
 
986
                 0 , &(args_info->no_version_given),
 
987
                &(local_args_info.no_version_given), optarg, 0, 0, ARG_NO,
 
988
                check_ambiguity, override, 0, 0,
 
989
                "no-version", '-',
 
990
                additional_error))
 
991
              goto failure;
 
992
          
916
993
          }
917
994
          /* in the output of help will specify which options are mandatory, by using the optional passed string.  */
918
995
          else if (strcmp (long_options[option_index].name, "show-required") == 0)
919
996
          {
920
 
            if (local_args_info.show_required_given || (check_ambiguity && args_info->show_required_given))
921
 
              {
922
 
                fprintf (stderr, "%s: `--show-required' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
923
 
                goto failure;
924
 
              }
925
 
            if (args_info->show_required_given && ! override)
926
 
              continue;
927
 
            local_args_info.show_required_given = 1;
928
 
            args_info->show_required_given = 1;
929
 
            if (optarg)
930
 
              {
931
 
                if (args_info->show_required_arg)
932
 
                  free (args_info->show_required_arg); /* free previous string */
933
 
                args_info->show_required_arg = gengetopt_strdup (optarg);
934
 
                if (args_info->show_required_orig)
935
 
                  free (args_info->show_required_orig); /* free previous string */
936
 
                args_info->show_required_orig = gengetopt_strdup (optarg);
937
 
              }
 
997
          
 
998
          
 
999
            if (update_arg( (void *)&(args_info->show_required_arg), 
 
1000
                 &(args_info->show_required_orig), &(args_info->show_required_given),
 
1001
                &(local_args_info.show_required_given), optarg, 0, "(mandatory)", ARG_STRING,
 
1002
                check_ambiguity, override, 0, 0,
 
1003
                "show-required", '-',
 
1004
                additional_error))
 
1005
              goto failure;
 
1006
          
938
1007
          }
939
1008
          /* set the package name (override package defined in the .ggo file).  */
940
1009
          else if (strcmp (long_options[option_index].name, "set-package") == 0)
941
1010
          {
942
 
            if (local_args_info.set_package_given || (check_ambiguity && args_info->set_package_given))
943
 
              {
944
 
                fprintf (stderr, "%s: `--set-package' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
945
 
                goto failure;
946
 
              }
947
 
            if (args_info->set_package_given && ! override)
948
 
              continue;
949
 
            local_args_info.set_package_given = 1;
950
 
            args_info->set_package_given = 1;
951
 
            if (args_info->set_package_arg)
952
 
              free (args_info->set_package_arg); /* free previous string */
953
 
            args_info->set_package_arg = gengetopt_strdup (optarg);
954
 
            if (args_info->set_package_orig)
955
 
              free (args_info->set_package_orig); /* free previous string */
956
 
            args_info->set_package_orig = gengetopt_strdup (optarg);
 
1011
          
 
1012
          
 
1013
            if (update_arg( (void *)&(args_info->set_package_arg), 
 
1014
                 &(args_info->set_package_orig), &(args_info->set_package_given),
 
1015
                &(local_args_info.set_package_given), optarg, 0, 0, ARG_STRING,
 
1016
                check_ambiguity, override, 0, 0,
 
1017
                "set-package", '-',
 
1018
                additional_error))
 
1019
              goto failure;
 
1020
          
957
1021
          }
958
1022
          /* set the version number (override version defined in the .ggo file).  */
959
1023
          else if (strcmp (long_options[option_index].name, "set-version") == 0)
960
1024
          {
961
 
            if (local_args_info.set_version_given || (check_ambiguity && args_info->set_version_given))
962
 
              {
963
 
                fprintf (stderr, "%s: `--set-version' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
964
 
                goto failure;
965
 
              }
966
 
            if (args_info->set_version_given && ! override)
967
 
              continue;
968
 
            local_args_info.set_version_given = 1;
969
 
            args_info->set_version_given = 1;
970
 
            if (args_info->set_version_arg)
971
 
              free (args_info->set_version_arg); /* free previous string */
972
 
            args_info->set_version_arg = gengetopt_strdup (optarg);
973
 
            if (args_info->set_version_orig)
974
 
              free (args_info->set_version_orig); /* free previous string */
975
 
            args_info->set_version_orig = gengetopt_strdup (optarg);
 
1025
          
 
1026
          
 
1027
            if (update_arg( (void *)&(args_info->set_version_arg), 
 
1028
                 &(args_info->set_version_orig), &(args_info->set_version_given),
 
1029
                &(local_args_info.set_version_given), optarg, 0, 0, ARG_STRING,
 
1030
                check_ambiguity, override, 0, 0,
 
1031
                "set-version", '-',
 
1032
                additional_error))
 
1033
              goto failure;
 
1034
          
976
1035
          }
977
1036
          /* show the output of --help instead of generating code.  */
978
1037
          else if (strcmp (long_options[option_index].name, "show-help") == 0)
979
1038
          {
980
 
            if (local_args_info.show_help_given || (check_ambiguity && args_info->show_help_given))
981
 
              {
982
 
                fprintf (stderr, "%s: `--show-help' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
983
 
                goto failure;
984
 
              }
985
 
            if (args_info->show_help_given && ! override)
986
 
              continue;
987
 
            local_args_info.show_help_given = 1;
988
 
            args_info->show_help_given = 1;
989
 
            break;
 
1039
          
 
1040
          
 
1041
            if (update_arg( 0 , 
 
1042
                 0 , &(args_info->show_help_given),
 
1043
                &(local_args_info.show_help_given), optarg, 0, 0, ARG_NO,
 
1044
                check_ambiguity, override, 0, 0,
 
1045
                "show-help", '-',
 
1046
                additional_error))
 
1047
              goto failure;
 
1048
          
990
1049
          }
991
 
          /* show the output of --help (including hidden options) instead of generating code.  */
 
1050
          /* show the output of --full-help (i.e., including hidden options) instead of generating code.  */
992
1051
          else if (strcmp (long_options[option_index].name, "show-full-help") == 0)
993
1052
          {
994
 
            if (local_args_info.show_full_help_given || (check_ambiguity && args_info->show_full_help_given))
995
 
              {
996
 
                fprintf (stderr, "%s: `--show-full-help' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
997
 
                goto failure;
998
 
              }
999
 
            if (args_info->show_full_help_given && ! override)
1000
 
              continue;
1001
 
            local_args_info.show_full_help_given = 1;
1002
 
            args_info->show_full_help_given = 1;
1003
 
            break;
 
1053
          
 
1054
          
 
1055
            if (update_arg( 0 , 
 
1056
                 0 , &(args_info->show_full_help_given),
 
1057
                &(local_args_info.show_full_help_given), optarg, 0, 0, ARG_NO,
 
1058
                check_ambiguity, override, 0, 0,
 
1059
                "show-full-help", '-',
 
1060
                additional_error))
 
1061
              goto failure;
 
1062
          
 
1063
          }
 
1064
          /* show the output of --detailed-help (i.e., including details and hidden options) instead of generating code.  */
 
1065
          else if (strcmp (long_options[option_index].name, "show-detailed-help") == 0)
 
1066
          {
 
1067
          
 
1068
          
 
1069
            if (update_arg( 0 , 
 
1070
                 0 , &(args_info->show_detailed_help_given),
 
1071
                &(local_args_info.show_detailed_help_given), optarg, 0, 0, ARG_NO,
 
1072
                check_ambiguity, override, 0, 0,
 
1073
                "show-detailed-help", '-',
 
1074
                additional_error))
 
1075
              goto failure;
 
1076
          
1004
1077
          }
1005
1078
          /* show the output of --version instead of generating code.  */
1006
1079
          else if (strcmp (long_options[option_index].name, "show-version") == 0)
1007
1080
          {
1008
 
            if (local_args_info.show_version_given || (check_ambiguity && args_info->show_version_given))
1009
 
              {
1010
 
                fprintf (stderr, "%s: `--show-version' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1011
 
                goto failure;
1012
 
              }
1013
 
            if (args_info->show_version_given && ! override)
1014
 
              continue;
1015
 
            local_args_info.show_version_given = 1;
1016
 
            args_info->show_version_given = 1;
1017
 
            break;
 
1081
          
 
1082
          
 
1083
            if (update_arg( 0 , 
 
1084
                 0 , &(args_info->show_version_given),
 
1085
                &(local_args_info.show_version_given), optarg, 0, 0, ARG_NO,
 
1086
                check_ambiguity, override, 0, 0,
 
1087
                "show-version", '-',
 
1088
                additional_error))
 
1089
              goto failure;
 
1090
          
1018
1091
          }
1019
1092
          
1020
1093
          break;
1120
1193
  params.initialize = initialize;
1121
1194
  params.check_required = check_required;
1122
1195
  params.check_ambiguity = 0;
 
1196
  params.print_errors = 1;
1123
1197
 
1124
1198
  return cmdline_parser_string_ext(cmdline, args_info, prog_name, &params);
1125
1199
}