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 12 by tim, Tue Sep 28 23:24:25 2004 UTC vs.
branches/development/src/applications/simpleBuilder/simpleBuilderCmd.c (file contents), Revision 1630 by gezelter, Wed Sep 14 21:40:12 2011 UTC

# Line 1 | Line 1
1   /*
2 <  File autogenerated by gengetopt version 2.11
2 >  File autogenerated by gengetopt version 2.22.4
3    generated with the following command:
4 <  /home/maul/gezelter/tim/program/gengetopt-2.11/src/gengetopt -F simpleBuilderCmd -u
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:
8    we make no copyright claims on it.
9   */
10  
11 + /* If we use autoconf.  */
12 + #ifdef HAVE_CONFIG_H
13 + #include "config.h"
14 + #endif
15  
16   #include <stdio.h>
17   #include <stdlib.h>
18   #include <string.h>
19  
20 < /* If we use autoconf.  */
21 < #ifdef HAVE_CONFIG_H
18 < #include "config.h"
20 > #ifndef FIX_UNUSED
21 > #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
22   #endif
23  
24 < #include "getopt.h"
24 > #include <getopt.h>
25  
26 < #include "applications/simpleBuilder/simpleBuilderCmd.h"
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 **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);
62 +
63 + static char *
64 + gengetopt_strdup (const char *s);
65 +
66 + static
67 + void clear_given (struct gengetopt_args_info *args_info)
68 + {
69 +  args_info->help_given = 0 ;
70 +  args_info->version_given = 0 ;
71 +  args_info->output_given = 0 ;
72 +  args_info->density_given = 0 ;
73 +  args_info->nx_given = 0 ;
74 +  args_info->ny_given = 0 ;
75 +  args_info->nz_given = 0 ;
76 + }
77 +
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;
85 +  args_info->nx_orig = NULL;
86 +  args_info->ny_orig = NULL;
87 +  args_info->nz_orig = NULL;
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("\n"
134 <  "Usage: %s [OPTIONS]... [FILES]...\n", CMDLINE_PARSER_PACKAGE);
135 <  printf("\n");
38 <  printf("  -h, --help                Print help and exit\n");
39 <  printf("  -V, --version             Print version and exit\n");
40 <  printf("  -o, --output=STRING       Output file name\n");
41 <  printf("      --latticetype=STRING  Lattice type string. Valid types are fcc,hcp,bcc \n                              and hcp-water.  (default=`fcc')\n");
42 <  printf("      --density=DOUBLE      density (g/cm^3)\n");
43 <  printf("      --nx=INT              number of unit cells in x\n");
44 <  printf("      --ny=INT              number of unit cells in y\n");
45 <  printf("      --nz=INT              number of unit cells in z\n");
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
139 + cmdline_parser_init (struct gengetopt_args_info *args_info)
140 + {
141 +  clear_given (args_info);
142 +  clear_args (args_info);
143 +  init_args_info (args_info);
144  
145 < static char *gengetopt_strdup (const char *s);
145 >  args_info->inputs = 0;
146 >  args_info->inputs_num = 0;
147 > }
148  
149 < /* gengetopt_strdup() */
150 < /* strdup.c replacement of strdup, which is not standard */
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 > free_string_field (char **s)
173 > {
174 >  if (*s)
175 >    {
176 >      free (*s);
177 >      *s = 0;
178 >    }
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 >
197 >  if (args_info->inputs_num)
198 >    free (args_info->inputs);
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;
251 >  int i = 0;
252 >
253 >  outfile = fopen(filename, "w");
254 >
255 >  if (!outfile)
256 >    {
257 >      fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
258 >      return EXIT_FAILURE;
259 >    }
260 >
261 >  i = cmdline_parser_dump(outfile, args_info);
262 >  fclose (outfile);
263 >
264 >  return i;
265 > }
266 >
267 > void
268 > cmdline_parser_free (struct gengetopt_args_info *args_info)
269 > {
270 >  cmdline_parser_release (args_info);
271 > }
272 >
273 > /** @brief replacement of strdup, which is not standard */
274   char *
275   gengetopt_strdup (const char *s)
276   {
277 <  char *result = (char*)malloc(strlen(s) + 1);
277 >  char *result = 0;
278 >  if (!s)
279 >    return result;
280 >
281 >  result = (char*)malloc(strlen(s) + 1);
282    if (result == (char*)0)
283      return (char*)0;
284    strcpy(result, s);
# Line 61 | 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 <  int c;        /* Character of the parsed option.  */
292 <  int missing_required_options = 0;
291 >  return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
292 > }
293  
294 <  args_info->help_given = 0 ;
295 <  args_info->version_given = 0 ;
296 <  args_info->output_given = 0 ;
297 <  args_info->latticetype_given = 0 ;
298 <  args_info->density_given = 0 ;
299 <  args_info->nx_given = 0 ;
300 <  args_info->ny_given = 0 ;
301 <  args_info->nz_given = 0 ;
302 < #define clear_args() { \
303 <  args_info->output_arg = NULL; \
304 <  args_info->latticetype_arg = gengetopt_strdup("fcc") ;\
294 > int
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 >  if (result == EXIT_FAILURE)
302 >    {
303 >      cmdline_parser_free (args_info);
304 >      exit (EXIT_FAILURE);
305 >    }
306 >  
307 >  return result;
308   }
309  
310 <  clear_args();
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 <  args_info->inputs = NULL;
85 <  args_info->inputs_num = 0;
322 >  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
323  
324 +  if (result == EXIT_FAILURE)
325 +    {
326 +      cmdline_parser_free (args_info);
327 +      exit (EXIT_FAILURE);
328 +    }
329 +  
330 +  return result;
331 + }
332 +
333 + int
334 + cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
335 + {
336 +  int result = EXIT_SUCCESS;
337 +
338 +  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
339 +    result = EXIT_FAILURE;
340 +
341 +  if (result == EXIT_FAILURE)
342 +    {
343 +      cmdline_parser_free (args_info);
344 +      exit (EXIT_FAILURE);
345 +    }
346 +  
347 +  return result;
348 + }
349 +
350 + int
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 (
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);
534 +
535 +  cmdline_parser_init (&local_args_info);
536 +
537    optarg = 0;
538 <  optind = 1;
539 <  opterr = 1;
538 >  optind = 0;
539 >  opterr = params->print_errors;
540    optopt = '?';
541  
542    while (1)
543      {
544        int option_index = 0;
95      char *stop_char;
545  
546        static struct option long_options[] = {
547          { "help",       0, NULL, 'h' },
548          { "version",    0, NULL, 'V' },
549          { "output",     1, NULL, 'o' },
101        { "latticetype",        1, NULL, 0 },
550          { "density",    1, NULL, 0 },
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  
109      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 114 | Line 561 | cmdline_parser (int argc, char * const *argv, struct g
561        switch (c)
562          {
563          case 'h':       /* Print help and exit.  */
117          clear_args ();
564            cmdline_parser_print_help ();
565 +          cmdline_parser_free (&local_args_info);
566            exit (EXIT_SUCCESS);
567  
568          case 'V':       /* Print version and exit.  */
122          clear_args ();
569            cmdline_parser_print_version ();
570 +          cmdline_parser_free (&local_args_info);
571            exit (EXIT_SUCCESS);
572  
573          case 'o':       /* Output file name.  */
574 <          if (args_info->output_given)
575 <            {
576 <              fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
577 <              clear_args ();
578 <              exit (EXIT_FAILURE);
579 <            }
580 <          args_info->output_given = 1;
581 <          args_info->output_arg = 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  
137
586          case 0: /* Long option with no short option */
139          /* Lattice type string. Valid types are fcc,hcp,bcc and hcp-water..  */
140          if (strcmp (long_options[option_index].name, "latticetype") == 0)
141          {
142            if (args_info->latticetype_given)
143              {
144                fprintf (stderr, "%s: `--latticetype' option given more than once\n", CMDLINE_PARSER_PACKAGE);
145                clear_args ();
146                exit (EXIT_FAILURE);
147              }
148            args_info->latticetype_given = 1;
149            if (args_info->latticetype_arg)
150              free (args_info->latticetype_arg); /* free default string */
151            args_info->latticetype_arg = gengetopt_strdup (optarg);
152            break;
153          }
154          
587            /* density (g/cm^3).  */
588 <          else if (strcmp (long_options[option_index].name, "density") == 0)
588 >          if (strcmp (long_options[option_index].name, "density") == 0)
589            {
158            if (args_info->density_given)
159              {
160                fprintf (stderr, "%s: `--density' option given more than once\n", CMDLINE_PARSER_PACKAGE);
161                clear_args ();
162                exit (EXIT_FAILURE);
163              }
164            args_info->density_given = 1;
165            args_info->density_arg = strtod (optarg, NULL);
166            break;
167          }
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 +          
600 +          }
601            /* number of unit cells in x.  */
602            else if (strcmp (long_options[option_index].name, "nx") == 0)
603            {
172            if (args_info->nx_given)
173              {
174                fprintf (stderr, "%s: `--nx' option given more than once\n", CMDLINE_PARSER_PACKAGE);
175                clear_args ();
176                exit (EXIT_FAILURE);
177              }
178            args_info->nx_given = 1;
179            args_info->nx_arg = strtol (optarg,&stop_char,0);
180            break;
181          }
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 +          
614 +          }
615            /* number of unit cells in y.  */
616            else if (strcmp (long_options[option_index].name, "ny") == 0)
617            {
186            if (args_info->ny_given)
187              {
188                fprintf (stderr, "%s: `--ny' option given more than once\n", CMDLINE_PARSER_PACKAGE);
189                clear_args ();
190                exit (EXIT_FAILURE);
191              }
192            args_info->ny_given = 1;
193            args_info->ny_arg = strtol (optarg,&stop_char,0);
194            break;
195          }
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 +          
628 +          }
629            /* number of unit cells in z.  */
630            else if (strcmp (long_options[option_index].name, "nz") == 0)
631            {
632 <            if (args_info->nz_given)
633 <              {
634 <                fprintf (stderr, "%s: `--nz' option given more than once\n", CMDLINE_PARSER_PACKAGE);
635 <                clear_args ();
636 <                exit (EXIT_FAILURE);
637 <              }
638 <            args_info->nz_given = 1;
639 <            args_info->nz_arg = strtol (optarg,&stop_char,0);
640 <            break;
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 >          
642            }
643            
644 <
644 >          break;
645          case '?':       /* Invalid option.  */
646            /* `getopt_long' already printed an error message.  */
647 <          exit (EXIT_FAILURE);
647 >          goto failure;
648  
649          default:        /* bug: option not considered.  */
650 <          fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
650 >          fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
651            abort ();
652          } /* switch */
653      } /* while */
654  
655  
656 <  if (! args_info->density_given)
656 >
657 >  if (check_required)
658      {
659 <      fprintf (stderr, "%s: '--density' option required\n", CMDLINE_PARSER_PACKAGE);
226 <      missing_required_options = 1;
659 >      error += cmdline_parser_required2 (args_info, argv[0], additional_error);
660      }
228  if (! args_info->nx_given)
229    {
230      fprintf (stderr, "%s: '--nx' option required\n", CMDLINE_PARSER_PACKAGE);
231      missing_required_options = 1;
232    }
233  if (! args_info->ny_given)
234    {
235      fprintf (stderr, "%s: '--ny' option required\n", CMDLINE_PARSER_PACKAGE);
236      missing_required_options = 1;
237    }
238  if (! args_info->nz_given)
239    {
240      fprintf (stderr, "%s: '--nz' option required\n", CMDLINE_PARSER_PACKAGE);
241      missing_required_options = 1;
242    }
243  if ( missing_required_options )
244    exit (EXIT_FAILURE);
661  
662 +  cmdline_parser_release (&local_args_info);
663 +
664 +  if ( error )
665 +    return (EXIT_FAILURE);
666 +
667    if (optind < argc)
668      {
669        int i = 0 ;
670 <  
671 <      args_info->inputs_num = argc - optind ;
672 <      args_info->inputs =
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 >      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 <  
690 >
691    return 0;
692 +
693 + failure:
694 +  
695 +  cmdline_parser_release (&local_args_info);
696 +  return (EXIT_FAILURE);
697   }

Comparing:
trunk/src/applications/simpleBuilder/simpleBuilderCmd.c (property svn:keywords), Revision 12 by tim, Tue Sep 28 23:24:25 2004 UTC vs.
branches/development/src/applications/simpleBuilder/simpleBuilderCmd.c (property svn:keywords), Revision 1630 by gezelter, Wed Sep 14 21:40:12 2011 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines