ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/simpleBuilder/simpleBuilderCmd.cpp
(Generate patch)

Comparing branches/development/src/applications/simpleBuilder/simpleBuilderCmd.c (file contents):
Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC vs.
Revision 1630 by gezelter, Wed Sep 14 21:40:12 2011 UTC

# Line 1 | Line 1
1   /*
2 <  File autogenerated by gengetopt version 2.16
2 >  File autogenerated by gengetopt version 2.22.4
3    generated with the following command:
4 <  gengetopt -F simpleBuilderCmd --unamed-opts
4 >  gengetopt -F simpleBuilderCmd -u
5  
6    The developers of gengetopt consider the fixed text that goes in all
7    gengetopt output files to be in the public domain:
# Line 17 | Line 17
17   #include <stdlib.h>
18   #include <string.h>
19  
20 < #include "getopt.h"
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 "simpleBuilderCmd.h"
27  
28 + const char *gengetopt_args_info_purpose = "";
29 +
30 + const char *gengetopt_args_info_usage = "Usage: simpleBuilder [OPTIONS]... [FILES]...";
31 +
32 + const char *gengetopt_args_info_description = "";
33 +
34 + const char *gengetopt_args_info_help[] = {
35 +  "  -h, --help            Print help and exit",
36 +  "  -V, --version         Print version and exit",
37 +  "  -o, --output=STRING   Output file name",
38 +  "      --density=DOUBLE  density (g/cm^3)",
39 +  "      --nx=INT          number of unit cells in x",
40 +  "      --ny=INT          number of unit cells in y",
41 +  "      --nz=INT          number of unit cells in z",
42 +    0
43 + };
44 +
45 + typedef enum {ARG_NO
46 +  , ARG_STRING
47 +  , ARG_INT
48 +  , ARG_DOUBLE
49 + } cmdline_parser_arg_type;
50 +
51   static
52   void clear_given (struct gengetopt_args_info *args_info);
53   static
54   void clear_args (struct gengetopt_args_info *args_info);
55  
56   static int
57 < cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
57 > cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
58 >                        struct cmdline_parser_params *params, const char *additional_error);
59  
60   static int
61   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
# Line 50 | Line 78 | void clear_args (struct gengetopt_args_info *args_info
78   static
79   void clear_args (struct gengetopt_args_info *args_info)
80   {
81 +  FIX_UNUSED (args_info);
82    args_info->output_arg = NULL;
83    args_info->output_orig = NULL;
84    args_info->density_orig = NULL;
# Line 59 | Line 88 | void clear_args (struct gengetopt_args_info *args_info
88    
89   }
90  
91 + static
92 + void init_args_info(struct gengetopt_args_info *args_info)
93 + {
94 +
95 +
96 +  args_info->help_help = gengetopt_args_info_help[0] ;
97 +  args_info->version_help = gengetopt_args_info_help[1] ;
98 +  args_info->output_help = gengetopt_args_info_help[2] ;
99 +  args_info->density_help = gengetopt_args_info_help[3] ;
100 +  args_info->nx_help = gengetopt_args_info_help[4] ;
101 +  args_info->ny_help = gengetopt_args_info_help[5] ;
102 +  args_info->nz_help = gengetopt_args_info_help[6] ;
103 +  
104 + }
105 +
106   void
107   cmdline_parser_print_version (void)
108   {
109 <  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
109 >  printf ("%s %s\n",
110 >     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
111 >     CMDLINE_PARSER_VERSION);
112   }
113  
114 + static void print_help_common(void) {
115 +  cmdline_parser_print_version ();
116 +
117 +  if (strlen(gengetopt_args_info_purpose) > 0)
118 +    printf("\n%s\n", gengetopt_args_info_purpose);
119 +
120 +  if (strlen(gengetopt_args_info_usage) > 0)
121 +    printf("\n%s\n", gengetopt_args_info_usage);
122 +
123 +  printf("\n");
124 +
125 +  if (strlen(gengetopt_args_info_description) > 0)
126 +    printf("%s\n\n", gengetopt_args_info_description);
127 + }
128 +
129   void
130   cmdline_parser_print_help (void)
131   {
132 <  cmdline_parser_print_version ();
133 <  printf("\nUsage: simpleBuilder [OPTIONS]... [FILES]...\n\n");
134 <  printf("%s\n","  -h, --help            Print help and exit");
135 <  printf("%s\n","  -V, --version         Print version and exit");
75 <  printf("%s\n","  -o, --output=STRING   Output file name");
76 <  printf("%s\n","      --density=DOUBLE  density (g/cm^3)");
77 <  printf("%s\n","      --nx=INT          number of unit cells in x");
78 <  printf("%s\n","      --ny=INT          number of unit cells in y");
79 <  printf("%s\n","      --nz=INT          number of unit cells in z");
80 <  
132 >  int i = 0;
133 >  print_help_common();
134 >  while (gengetopt_args_info_help[i])
135 >    printf("%s\n", gengetopt_args_info_help[i++]);
136   }
137  
138   void
# Line 85 | Line 140 | cmdline_parser_init (struct gengetopt_args_info *args_
140   {
141    clear_given (args_info);
142    clear_args (args_info);
143 +  init_args_info (args_info);
144  
145 <  args_info->inputs = NULL;
145 >  args_info->inputs = 0;
146    args_info->inputs_num = 0;
147   }
148  
149 + void
150 + cmdline_parser_params_init(struct cmdline_parser_params *params)
151 + {
152 +  if (params)
153 +    {
154 +      params->override = 0;
155 +      params->initialize = 1;
156 +      params->check_required = 1;
157 +      params->check_ambiguity = 0;
158 +      params->print_errors = 1;
159 +    }
160 + }
161 +
162 + struct cmdline_parser_params *
163 + cmdline_parser_params_create(void)
164 + {
165 +  struct cmdline_parser_params *params =
166 +    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
167 +  cmdline_parser_params_init(params);  
168 +  return params;
169 + }
170 +
171   static void
172 < cmdline_parser_release (struct gengetopt_args_info *args_info)
172 > free_string_field (char **s)
173   {
174 <  
97 <  unsigned int i;
98 <  if (args_info->output_arg)
174 >  if (*s)
175      {
176 <      free (args_info->output_arg); /* free previous argument */
177 <      args_info->output_arg = 0;
176 >      free (*s);
177 >      *s = 0;
178      }
179 <  if (args_info->output_orig)
180 <    {
181 <      free (args_info->output_orig); /* free previous argument */
182 <      args_info->output_orig = 0;
183 <    }
184 <  if (args_info->density_orig)
185 <    {
186 <      free (args_info->density_orig); /* free previous argument */
187 <      args_info->density_orig = 0;
188 <    }
189 <  if (args_info->nx_orig)
190 <    {
191 <      free (args_info->nx_orig); /* free previous argument */
116 <      args_info->nx_orig = 0;
117 <    }
118 <  if (args_info->ny_orig)
119 <    {
120 <      free (args_info->ny_orig); /* free previous argument */
121 <      args_info->ny_orig = 0;
122 <    }
123 <  if (args_info->nz_orig)
124 <    {
125 <      free (args_info->nz_orig); /* free previous argument */
126 <      args_info->nz_orig = 0;
127 <    }
179 > }
180 >
181 >
182 > static void
183 > cmdline_parser_release (struct gengetopt_args_info *args_info)
184 > {
185 >  unsigned int i;
186 >  free_string_field (&(args_info->output_arg));
187 >  free_string_field (&(args_info->output_orig));
188 >  free_string_field (&(args_info->density_orig));
189 >  free_string_field (&(args_info->nx_orig));
190 >  free_string_field (&(args_info->ny_orig));
191 >  free_string_field (&(args_info->nz_orig));
192    
193 +  
194    for (i = 0; i < args_info->inputs_num; ++i)
195      free (args_info->inputs [i]);
196 <  
196 >
197    if (args_info->inputs_num)
198      free (args_info->inputs);
199 <  
199 >
200    clear_given (args_info);
201   }
202  
203 +
204 + static void
205 + write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
206 + {
207 +  FIX_UNUSED (values);
208 +  if (arg) {
209 +    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
210 +  } else {
211 +    fprintf(outfile, "%s\n", opt);
212 +  }
213 + }
214 +
215 +
216   int
217 + cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
218 + {
219 +  int i = 0;
220 +
221 +  if (!outfile)
222 +    {
223 +      fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
224 +      return EXIT_FAILURE;
225 +    }
226 +
227 +  if (args_info->help_given)
228 +    write_into_file(outfile, "help", 0, 0 );
229 +  if (args_info->version_given)
230 +    write_into_file(outfile, "version", 0, 0 );
231 +  if (args_info->output_given)
232 +    write_into_file(outfile, "output", args_info->output_orig, 0);
233 +  if (args_info->density_given)
234 +    write_into_file(outfile, "density", args_info->density_orig, 0);
235 +  if (args_info->nx_given)
236 +    write_into_file(outfile, "nx", args_info->nx_orig, 0);
237 +  if (args_info->ny_given)
238 +    write_into_file(outfile, "ny", args_info->ny_orig, 0);
239 +  if (args_info->nz_given)
240 +    write_into_file(outfile, "nz", args_info->nz_orig, 0);
241 +  
242 +
243 +  i = EXIT_SUCCESS;
244 +  return i;
245 + }
246 +
247 + int
248   cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
249   {
250    FILE *outfile;
# Line 149 | Line 258 | cmdline_parser_file_save(const char *filename, struct
258        return EXIT_FAILURE;
259      }
260  
261 <  if (args_info->help_given) {
153 <    fprintf(outfile, "%s\n", "help");
154 <  }
155 <  if (args_info->version_given) {
156 <    fprintf(outfile, "%s\n", "version");
157 <  }
158 <  if (args_info->output_given) {
159 <    if (args_info->output_orig) {
160 <      fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
161 <    } else {
162 <      fprintf(outfile, "%s\n", "output");
163 <    }
164 <  }
165 <  if (args_info->density_given) {
166 <    if (args_info->density_orig) {
167 <      fprintf(outfile, "%s=\"%s\"\n", "density", args_info->density_orig);
168 <    } else {
169 <      fprintf(outfile, "%s\n", "density");
170 <    }
171 <  }
172 <  if (args_info->nx_given) {
173 <    if (args_info->nx_orig) {
174 <      fprintf(outfile, "%s=\"%s\"\n", "nx", args_info->nx_orig);
175 <    } else {
176 <      fprintf(outfile, "%s\n", "nx");
177 <    }
178 <  }
179 <  if (args_info->ny_given) {
180 <    if (args_info->ny_orig) {
181 <      fprintf(outfile, "%s=\"%s\"\n", "ny", args_info->ny_orig);
182 <    } else {
183 <      fprintf(outfile, "%s\n", "ny");
184 <    }
185 <  }
186 <  if (args_info->nz_given) {
187 <    if (args_info->nz_orig) {
188 <      fprintf(outfile, "%s=\"%s\"\n", "nz", args_info->nz_orig);
189 <    } else {
190 <      fprintf(outfile, "%s\n", "nz");
191 <    }
192 <  }
193 <  
261 >  i = cmdline_parser_dump(outfile, args_info);
262    fclose (outfile);
263  
196  i = EXIT_SUCCESS;
264    return i;
265   }
266  
# Line 203 | Line 270 | cmdline_parser_free (struct gengetopt_args_info *args_
270    cmdline_parser_release (args_info);
271   }
272  
273 <
207 < /* gengetopt_strdup() */
208 < /* strdup.c replacement of strdup, which is not standard */
273 > /** @brief replacement of strdup, which is not standard */
274   char *
275   gengetopt_strdup (const char *s)
276   {
277 <  char *result = NULL;
277 >  char *result = 0;
278    if (!s)
279      return result;
280  
# Line 221 | Line 286 | int
286   }
287  
288   int
289 < cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
289 > cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
290   {
291    return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
292   }
293  
294   int
295 < cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
295 > cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
296 >                   struct cmdline_parser_params *params)
297   {
298    int result;
299 +  result = cmdline_parser_internal (argc, argv, args_info, params, 0);
300  
301 <  result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
301 >  if (result == EXIT_FAILURE)
302 >    {
303 >      cmdline_parser_free (args_info);
304 >      exit (EXIT_FAILURE);
305 >    }
306 >  
307 >  return result;
308 > }
309  
310 + int
311 + cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
312 + {
313 +  int result;
314 +  struct cmdline_parser_params params;
315 +  
316 +  params.override = override;
317 +  params.initialize = initialize;
318 +  params.check_required = check_required;
319 +  params.check_ambiguity = 0;
320 +  params.print_errors = 1;
321 +
322 +  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
323 +
324    if (result == EXIT_FAILURE)
325      {
326        cmdline_parser_free (args_info);
# Line 247 | Line 335 | cmdline_parser_required (struct gengetopt_args_info *a
335   {
336    int result = EXIT_SUCCESS;
337  
338 <  if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
338 >  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
339      result = EXIT_FAILURE;
340  
341    if (result == EXIT_FAILURE)
# Line 263 | Line 351 | cmdline_parser_required2 (struct gengetopt_args_info *
351   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
352   {
353    int error = 0;
354 +  FIX_UNUSED (additional_error);
355  
356 +  /* checks for required options */
357    if (! args_info->output_given)
358      {
359        fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
360        error = 1;
361      }
362 +  
363    if (! args_info->density_given)
364      {
365        fprintf (stderr, "%s: '--density' option required%s\n", prog_name, (additional_error ? additional_error : ""));
366        error = 1;
367      }
368 +  
369    if (! args_info->nx_given)
370      {
371        fprintf (stderr, "%s: '--nx' option required%s\n", prog_name, (additional_error ? additional_error : ""));
372        error = 1;
373      }
374 +  
375    if (! args_info->ny_given)
376      {
377        fprintf (stderr, "%s: '--ny' option required%s\n", prog_name, (additional_error ? additional_error : ""));
378        error = 1;
379      }
380 +  
381    if (! args_info->nz_given)
382      {
383        fprintf (stderr, "%s: '--nz' option required%s\n", prog_name, (additional_error ? additional_error : ""));
384        error = 1;
385      }
386 +  
387 +  
388 +  /* checks for dependences among options */
389  
390    return error;
391   }
392  
393 +
394 + static char *package_name = 0;
395 +
396 + /**
397 + * @brief updates an option
398 + * @param field the generic pointer to the field to update
399 + * @param orig_field the pointer to the orig field
400 + * @param field_given the pointer to the number of occurrence of this option
401 + * @param prev_given the pointer to the number of occurrence already seen
402 + * @param value the argument for this option (if null no arg was specified)
403 + * @param possible_values the possible values for this option (if specified)
404 + * @param default_value the default value (in case the option only accepts fixed values)
405 + * @param arg_type the type of this option
406 + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
407 + * @param override @see cmdline_parser_params.override
408 + * @param no_free whether to free a possible previous value
409 + * @param multiple_option whether this is a multiple option
410 + * @param long_opt the corresponding long option
411 + * @param short_opt the corresponding short option (or '-' if none)
412 + * @param additional_error possible further error specification
413 + */
414 + static
415 + int update_arg(void *field, char **orig_field,
416 +               unsigned int *field_given, unsigned int *prev_given,
417 +               char *value, const char *possible_values[],
418 +               const char *default_value,
419 +               cmdline_parser_arg_type arg_type,
420 +               int check_ambiguity, int override,
421 +               int no_free, int multiple_option,
422 +               const char *long_opt, char short_opt,
423 +               const char *additional_error)
424 + {
425 +  char *stop_char = 0;
426 +  const char *val = value;
427 +  int found;
428 +  char **string_field;
429 +  FIX_UNUSED (field);
430 +
431 +  stop_char = 0;
432 +  found = 0;
433 +
434 +  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
435 +    {
436 +      if (short_opt != '-')
437 +        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
438 +               package_name, long_opt, short_opt,
439 +               (additional_error ? additional_error : ""));
440 +      else
441 +        fprintf (stderr, "%s: `--%s' option given more than once%s\n",
442 +               package_name, long_opt,
443 +               (additional_error ? additional_error : ""));
444 +      return 1; /* failure */
445 +    }
446 +
447 +  FIX_UNUSED (default_value);
448 +    
449 +  if (field_given && *field_given && ! override)
450 +    return 0;
451 +  if (prev_given)
452 +    (*prev_given)++;
453 +  if (field_given)
454 +    (*field_given)++;
455 +  if (possible_values)
456 +    val = possible_values[found];
457 +
458 +  switch(arg_type) {
459 +  case ARG_INT:
460 +    if (val) *((int *)field) = strtol (val, &stop_char, 0);
461 +    break;
462 +  case ARG_DOUBLE:
463 +    if (val) *((double *)field) = strtod (val, &stop_char);
464 +    break;
465 +  case ARG_STRING:
466 +    if (val) {
467 +      string_field = (char **)field;
468 +      if (!no_free && *string_field)
469 +        free (*string_field); /* free previous string */
470 +      *string_field = gengetopt_strdup (val);
471 +    }
472 +    break;
473 +  default:
474 +    break;
475 +  };
476 +
477 +  /* check numeric conversion */
478 +  switch(arg_type) {
479 +  case ARG_INT:
480 +  case ARG_DOUBLE:
481 +    if (val && !(stop_char && *stop_char == '\0')) {
482 +      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
483 +      return 1; /* failure */
484 +    }
485 +    break;
486 +  default:
487 +    ;
488 +  };
489 +
490 +  /* store the original value */
491 +  switch(arg_type) {
492 +  case ARG_NO:
493 +    break;
494 +  default:
495 +    if (value && orig_field) {
496 +      if (no_free) {
497 +        *orig_field = value;
498 +      } else {
499 +        if (*orig_field)
500 +          free (*orig_field); /* free previous string */
501 +        *orig_field = gengetopt_strdup (value);
502 +      }
503 +    }
504 +  };
505 +
506 +  return 0; /* OK */
507 + }
508 +
509 +
510   int
511 < cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
511 > cmdline_parser_internal (
512 >  int argc, char **argv, struct gengetopt_args_info *args_info,
513 >                        struct cmdline_parser_params *params, const char *additional_error)
514   {
515    int c;        /* Character of the parsed option.  */
516  
517    int error = 0;
518    struct gengetopt_args_info local_args_info;
519 +  
520 +  int override;
521 +  int initialize;
522 +  int check_required;
523 +  int check_ambiguity;
524 +  
525 +  package_name = argv[0];
526 +  
527 +  override = params->override;
528 +  initialize = params->initialize;
529 +  check_required = params->check_required;
530 +  check_ambiguity = params->check_ambiguity;
531  
532    if (initialize)
533      cmdline_parser_init (args_info);
# Line 308 | Line 536 | cmdline_parser_internal (int argc, char * const *argv,
536  
537    optarg = 0;
538    optind = 0;
539 <  opterr = 1;
539 >  opterr = params->print_errors;
540    optopt = '?';
541  
542    while (1)
543      {
544        int option_index = 0;
317      char *stop_char;
545  
546        static struct option long_options[] = {
547          { "help",       0, NULL, 'h' },
# Line 324 | Line 551 | cmdline_parser_internal (int argc, char * const *argv,
551          { "nx", 1, NULL, 0 },
552          { "ny", 1, NULL, 0 },
553          { "nz", 1, NULL, 0 },
554 <        { NULL, 0, NULL, 0 }
554 >        { 0,  0, 0, 0 }
555        };
556  
330      stop_char = 0;
557        c = getopt_long (argc, argv, "hVo:", long_options, &option_index);
558  
559        if (c == -1) break;       /* Exit from `while (1)' loop.  */
# Line 345 | Line 571 | cmdline_parser_internal (int argc, char * const *argv,
571            exit (EXIT_SUCCESS);
572  
573          case 'o':       /* Output file name.  */
574 <          if (local_args_info.output_given)
575 <            {
576 <              fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
577 <              goto failure;
578 <            }
579 <          if (args_info->output_given && ! override)
580 <            continue;
581 <          local_args_info.output_given = 1;
582 <          args_info->output_given = 1;
583 <          if (args_info->output_arg)
358 <            free (args_info->output_arg); /* free previous string */
359 <          args_info->output_arg = gengetopt_strdup (optarg);
360 <          if (args_info->output_orig)
361 <            free (args_info->output_orig); /* free previous string */
362 <          args_info->output_orig = gengetopt_strdup (optarg);
574 >        
575 >        
576 >          if (update_arg( (void *)&(args_info->output_arg),
577 >               &(args_info->output_orig), &(args_info->output_given),
578 >              &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
579 >              check_ambiguity, override, 0, 0,
580 >              "output", 'o',
581 >              additional_error))
582 >            goto failure;
583 >        
584            break;
585  
365
586          case 0: /* Long option with no short option */
587            /* density (g/cm^3).  */
588            if (strcmp (long_options[option_index].name, "density") == 0)
589            {
590 <            if (local_args_info.density_given)
591 <              {
592 <                fprintf (stderr, "%s: `--density' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
593 <                goto failure;
594 <              }
595 <            if (args_info->density_given && ! override)
596 <              continue;
597 <            local_args_info.density_given = 1;
378 <            args_info->density_given = 1;
379 <            args_info->density_arg = strtod (optarg, &stop_char);
380 <            if (!(stop_char && *stop_char == '\0')) {
381 <              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
590 >          
591 >          
592 >            if (update_arg( (void *)&(args_info->density_arg),
593 >                 &(args_info->density_orig), &(args_info->density_given),
594 >                &(local_args_info.density_given), optarg, 0, 0, ARG_DOUBLE,
595 >                check_ambiguity, override, 0, 0,
596 >                "density", '-',
597 >                additional_error))
598                goto failure;
599 <            }
384 <            if (args_info->density_orig)
385 <              free (args_info->density_orig); /* free previous string */
386 <            args_info->density_orig = gengetopt_strdup (optarg);
599 >          
600            }
601            /* number of unit cells in x.  */
602            else if (strcmp (long_options[option_index].name, "nx") == 0)
603            {
604 <            if (local_args_info.nx_given)
605 <              {
606 <                fprintf (stderr, "%s: `--nx' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
607 <                goto failure;
608 <              }
609 <            if (args_info->nx_given && ! override)
610 <              continue;
611 <            local_args_info.nx_given = 1;
399 <            args_info->nx_given = 1;
400 <            args_info->nx_arg = strtol (optarg, &stop_char, 0);
401 <            if (!(stop_char && *stop_char == '\0')) {
402 <              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
604 >          
605 >          
606 >            if (update_arg( (void *)&(args_info->nx_arg),
607 >                 &(args_info->nx_orig), &(args_info->nx_given),
608 >                &(local_args_info.nx_given), optarg, 0, 0, ARG_INT,
609 >                check_ambiguity, override, 0, 0,
610 >                "nx", '-',
611 >                additional_error))
612                goto failure;
613 <            }
405 <            if (args_info->nx_orig)
406 <              free (args_info->nx_orig); /* free previous string */
407 <            args_info->nx_orig = gengetopt_strdup (optarg);
613 >          
614            }
615            /* number of unit cells in y.  */
616            else if (strcmp (long_options[option_index].name, "ny") == 0)
617            {
618 <            if (local_args_info.ny_given)
619 <              {
620 <                fprintf (stderr, "%s: `--ny' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
621 <                goto failure;
622 <              }
623 <            if (args_info->ny_given && ! override)
624 <              continue;
625 <            local_args_info.ny_given = 1;
420 <            args_info->ny_given = 1;
421 <            args_info->ny_arg = strtol (optarg, &stop_char, 0);
422 <            if (!(stop_char && *stop_char == '\0')) {
423 <              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
618 >          
619 >          
620 >            if (update_arg( (void *)&(args_info->ny_arg),
621 >                 &(args_info->ny_orig), &(args_info->ny_given),
622 >                &(local_args_info.ny_given), optarg, 0, 0, ARG_INT,
623 >                check_ambiguity, override, 0, 0,
624 >                "ny", '-',
625 >                additional_error))
626                goto failure;
627 <            }
426 <            if (args_info->ny_orig)
427 <              free (args_info->ny_orig); /* free previous string */
428 <            args_info->ny_orig = gengetopt_strdup (optarg);
627 >          
628            }
629            /* number of unit cells in z.  */
630            else if (strcmp (long_options[option_index].name, "nz") == 0)
631            {
632 <            if (local_args_info.nz_given)
633 <              {
634 <                fprintf (stderr, "%s: `--nz' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
635 <                goto failure;
636 <              }
637 <            if (args_info->nz_given && ! override)
638 <              continue;
639 <            local_args_info.nz_given = 1;
441 <            args_info->nz_given = 1;
442 <            args_info->nz_arg = strtol (optarg, &stop_char, 0);
443 <            if (!(stop_char && *stop_char == '\0')) {
444 <              fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
632 >          
633 >          
634 >            if (update_arg( (void *)&(args_info->nz_arg),
635 >                 &(args_info->nz_orig), &(args_info->nz_given),
636 >                &(local_args_info.nz_given), optarg, 0, 0, ARG_INT,
637 >                check_ambiguity, override, 0, 0,
638 >                "nz", '-',
639 >                additional_error))
640                goto failure;
641 <            }
447 <            if (args_info->nz_orig)
448 <              free (args_info->nz_orig); /* free previous string */
449 <            args_info->nz_orig = gengetopt_strdup (optarg);
641 >          
642            }
643            
644            break;
# Line 475 | Line 667 | cmdline_parser_internal (int argc, char * const *argv,
667    if (optind < argc)
668      {
669        int i = 0 ;
670 +      int found_prog_name = 0;
671 +      /* whether program name, i.e., argv[0], is in the remaining args
672 +         (this may happen with some implementations of getopt,
673 +          but surely not with the one included by gengetopt) */
674  
675 <      args_info->inputs_num = argc - optind ;
675 >      i = optind;
676 >      while (i < argc)
677 >        if (argv[i++] == argv[0]) {
678 >          found_prog_name = 1;
679 >          break;
680 >        }
681 >      i = 0;
682 >
683 >      args_info->inputs_num = argc - optind - found_prog_name;
684        args_info->inputs =
685          (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
686        while (optind < argc)
687 <        args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
687 >        if (argv[optind++] != argv[0])
688 >          args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
689      }
690  
691    return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines