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

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

Comparing:
trunk/src/applications/simpleBuilder/simpleBuilderCmd.c (property svn:keywords), Revision 1067 by gezelter, Tue Oct 10 18:34:12 2006 UTC vs.
trunk/src/applications/simpleBuilder/simpleBuilderCmd.cpp (property svn:keywords), Revision 1795 by gezelter, Fri Sep 7 18:13:55 2012 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines