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

Comparing:
trunk/src/applications/thermalizer/thermalizerCmd.c (file contents), Revision 1083 by gezelter, Fri Oct 20 14:59:05 2006 UTC vs.
branches/development/src/applications/thermalizer/thermalizerCmd.c (file contents), Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC

# Line 1 | Line 1
1   /*
2 <  File autogenerated by gengetopt version 2.17
2 >  File autogenerated by gengetopt version 2.22
3    generated with the following command:
4 <  gengetopt -F thermalizerCmd --unamed-opts
4 >  gengetopt -u -F thermalizerCmd
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 21 | Line 21
21  
22   #include "thermalizerCmd.h"
23  
24 < const char *gengetopt_args_info_purpose = "Resamples the velocities for all the integrable objects in an OOPSE file from a \nMaxwell-Boltzmann distribution.";
24 > const char *gengetopt_args_info_purpose = "Resamples the velocities for all the integrable objects in an OpenMD file from \na Maxwell-Boltzmann distribution.";
25  
26   const char *gengetopt_args_info_usage = "Usage: thermalizer [OPTIONS]... [FILES]...";
27  
28 + const char *gengetopt_args_info_description = "";
29 +
30   const char *gengetopt_args_info_help[] = {
31    "  -h, --help                Print help and exit",
32    "  -V, --version             Print version and exit",
# Line 33 | Line 35 | const char *gengetopt_args_info_help[] = {
35      0
36   };
37  
38 + typedef enum {ARG_NO
39 +  , ARG_STRING
40 +  , ARG_DOUBLE
41 + } cmdline_parser_arg_type;
42 +
43   static
44   void clear_given (struct gengetopt_args_info *args_info);
45   static
46   void clear_args (struct gengetopt_args_info *args_info);
47  
48   static int
49 < 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);
49 > cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
50 >                        struct cmdline_parser_params *params, const char *additional_error);
51  
52   static int
53   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
# Line 68 | Line 76 | void init_args_info(struct gengetopt_args_info *args_i
76   static
77   void init_args_info(struct gengetopt_args_info *args_info)
78   {
79 +
80 +
81    args_info->help_help = gengetopt_args_info_help[0] ;
82    args_info->version_help = gengetopt_args_info_help[1] ;
83    args_info->output_help = gengetopt_args_info_help[2] ;
# Line 81 | Line 91 | cmdline_parser_print_version (void)
91    printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
92   }
93  
94 < void
85 < cmdline_parser_print_help (void)
86 < {
87 <  int i = 0;
94 > static void print_help_common(void) {
95    cmdline_parser_print_version ();
96  
97    if (strlen(gengetopt_args_info_purpose) > 0)
98      printf("\n%s\n", gengetopt_args_info_purpose);
99  
100 <  printf("\n%s\n\n", gengetopt_args_info_usage);
100 >  if (strlen(gengetopt_args_info_usage) > 0)
101 >    printf("\n%s\n", gengetopt_args_info_usage);
102 >
103 >  printf("\n");
104 >
105 >  if (strlen(gengetopt_args_info_description) > 0)
106 >    printf("%s\n", gengetopt_args_info_description);
107 > }
108 >
109 > void
110 > cmdline_parser_print_help (void)
111 > {
112 >  int i = 0;
113 >  print_help_common();
114    while (gengetopt_args_info_help[i])
115      printf("%s\n", gengetopt_args_info_help[i++]);
116   }
# Line 106 | Line 126 | cmdline_parser_init (struct gengetopt_args_info *args_
126    args_info->inputs_num = 0;
127   }
128  
129 + void
130 + cmdline_parser_params_init(struct cmdline_parser_params *params)
131 + {
132 +  if (params)
133 +    {
134 +      params->override = 0;
135 +      params->initialize = 1;
136 +      params->check_required = 1;
137 +      params->check_ambiguity = 0;
138 +      params->print_errors = 1;
139 +    }
140 + }
141 +
142 + struct cmdline_parser_params *
143 + cmdline_parser_params_create(void)
144 + {
145 +  struct cmdline_parser_params *params =
146 +    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
147 +  cmdline_parser_params_init(params);  
148 +  return params;
149 + }
150 +
151   static void
152 < cmdline_parser_release (struct gengetopt_args_info *args_info)
152 > free_string_field (char **s)
153   {
154 <  
113 <  unsigned int i;
114 <  if (args_info->output_arg)
154 >  if (*s)
155      {
156 <      free (args_info->output_arg); /* free previous argument */
157 <      args_info->output_arg = 0;
156 >      free (*s);
157 >      *s = 0;
158      }
159 <  if (args_info->output_orig)
160 <    {
161 <      free (args_info->output_orig); /* free previous argument */
162 <      args_info->output_orig = 0;
163 <    }
164 <  if (args_info->temperature_orig)
165 <    {
166 <      free (args_info->temperature_orig); /* free previous argument */
167 <      args_info->temperature_orig = 0;
168 <    }
159 > }
160 >
161 >
162 > static void
163 > cmdline_parser_release (struct gengetopt_args_info *args_info)
164 > {
165 >  unsigned int i;
166 >  free_string_field (&(args_info->output_arg));
167 >  free_string_field (&(args_info->output_orig));
168 >  free_string_field (&(args_info->temperature_orig));
169    
170 +  
171    for (i = 0; i < args_info->inputs_num; ++i)
172      free (args_info->inputs [i]);
173 <  
173 >
174    if (args_info->inputs_num)
175      free (args_info->inputs);
176 <  
176 >
177    clear_given (args_info);
178   }
179  
180 +
181 + static void
182 + write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
183 + {
184 +  if (arg) {
185 +    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
186 +  } else {
187 +    fprintf(outfile, "%s\n", opt);
188 +  }
189 + }
190 +
191 +
192   int
193 + cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
194 + {
195 +  int i = 0;
196 +
197 +  if (!outfile)
198 +    {
199 +      fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
200 +      return EXIT_FAILURE;
201 +    }
202 +
203 +  if (args_info->help_given)
204 +    write_into_file(outfile, "help", 0, 0 );
205 +  if (args_info->version_given)
206 +    write_into_file(outfile, "version", 0, 0 );
207 +  if (args_info->output_given)
208 +    write_into_file(outfile, "output", args_info->output_orig, 0);
209 +  if (args_info->temperature_given)
210 +    write_into_file(outfile, "temperature", args_info->temperature_orig, 0);
211 +  
212 +
213 +  i = EXIT_SUCCESS;
214 +  return i;
215 + }
216 +
217 + int
218   cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
219   {
220    FILE *outfile;
# Line 150 | Line 228 | cmdline_parser_file_save(const char *filename, struct
228        return EXIT_FAILURE;
229      }
230  
231 <  if (args_info->help_given) {
154 <    fprintf(outfile, "%s\n", "help");
155 <  }
156 <  if (args_info->version_given) {
157 <    fprintf(outfile, "%s\n", "version");
158 <  }
159 <  if (args_info->output_given) {
160 <    if (args_info->output_orig) {
161 <      fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
162 <    } else {
163 <      fprintf(outfile, "%s\n", "output");
164 <    }
165 <  }
166 <  if (args_info->temperature_given) {
167 <    if (args_info->temperature_orig) {
168 <      fprintf(outfile, "%s=\"%s\"\n", "temperature", args_info->temperature_orig);
169 <    } else {
170 <      fprintf(outfile, "%s\n", "temperature");
171 <    }
172 <  }
173 <  
231 >  i = cmdline_parser_dump(outfile, args_info);
232    fclose (outfile);
233  
176  i = EXIT_SUCCESS;
234    return i;
235   }
236  
# Line 183 | Line 240 | cmdline_parser_free (struct gengetopt_args_info *args_
240    cmdline_parser_release (args_info);
241   }
242  
243 <
187 < /* gengetopt_strdup() */
188 < /* strdup.c replacement of strdup, which is not standard */
243 > /** @brief replacement of strdup, which is not standard */
244   char *
245   gengetopt_strdup (const char *s)
246   {
# Line 207 | Line 262 | int
262   }
263  
264   int
265 + cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info,
266 +                   struct cmdline_parser_params *params)
267 + {
268 +  int result;
269 +  result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
270 +
271 +  if (result == EXIT_FAILURE)
272 +    {
273 +      cmdline_parser_free (args_info);
274 +      exit (EXIT_FAILURE);
275 +    }
276 +  
277 +  return result;
278 + }
279 +
280 + int
281   cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
282   {
283    int result;
284 +  struct cmdline_parser_params params;
285 +  
286 +  params.override = override;
287 +  params.initialize = initialize;
288 +  params.check_required = check_required;
289 +  params.check_ambiguity = 0;
290 +  params.print_errors = 1;
291  
292 <  result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
292 >  result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
293  
294    if (result == EXIT_FAILURE)
295      {
# Line 263 | Line 341 | cmdline_parser_required2 (struct gengetopt_args_info *
341    return error;
342   }
343  
344 +
345 + static char *package_name = 0;
346 +
347 + /**
348 + * @brief updates an option
349 + * @param field the generic pointer to the field to update
350 + * @param orig_field the pointer to the orig field
351 + * @param field_given the pointer to the number of occurrence of this option
352 + * @param prev_given the pointer to the number of occurrence already seen
353 + * @param value the argument for this option (if null no arg was specified)
354 + * @param possible_values the possible values for this option (if specified)
355 + * @param default_value the default value (in case the option only accepts fixed values)
356 + * @param arg_type the type of this option
357 + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
358 + * @param override @see cmdline_parser_params.override
359 + * @param no_free whether to free a possible previous value
360 + * @param multiple_option whether this is a multiple option
361 + * @param long_opt the corresponding long option
362 + * @param short_opt the corresponding short option (or '-' if none)
363 + * @param additional_error possible further error specification
364 + */
365 + static
366 + int update_arg(void *field, char **orig_field,
367 +               unsigned int *field_given, unsigned int *prev_given,
368 +               char *value, char *possible_values[], const char *default_value,
369 +               cmdline_parser_arg_type arg_type,
370 +               int check_ambiguity, int override,
371 +               int no_free, int multiple_option,
372 +               const char *long_opt, char short_opt,
373 +               const char *additional_error)
374 + {
375 +  char *stop_char = 0;
376 +  const char *val = value;
377 +  int found;
378 +  char **string_field;
379 +
380 +  stop_char = 0;
381 +  found = 0;
382 +
383 +  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
384 +    {
385 +      if (short_opt != '-')
386 +        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
387 +               package_name, long_opt, short_opt,
388 +               (additional_error ? additional_error : ""));
389 +      else
390 +        fprintf (stderr, "%s: `--%s' option given more than once%s\n",
391 +               package_name, long_opt,
392 +               (additional_error ? additional_error : ""));
393 +      return 1; /* failure */
394 +    }
395 +
396 +    
397 +  if (field_given && *field_given && ! override)
398 +    return 0;
399 +  if (prev_given)
400 +    (*prev_given)++;
401 +  if (field_given)
402 +    (*field_given)++;
403 +  if (possible_values)
404 +    val = possible_values[found];
405 +
406 +  switch(arg_type) {
407 +  case ARG_DOUBLE:
408 +    if (val) *((double *)field) = strtod (val, &stop_char);
409 +    break;
410 +  case ARG_STRING:
411 +    if (val) {
412 +      string_field = (char **)field;
413 +      if (!no_free && *string_field)
414 +        free (*string_field); /* free previous string */
415 +      *string_field = gengetopt_strdup (val);
416 +    }
417 +    break;
418 +  default:
419 +    break;
420 +  };
421 +
422 +  /* check numeric conversion */
423 +  switch(arg_type) {
424 +  case ARG_DOUBLE:
425 +    if (val && !(stop_char && *stop_char == '\0')) {
426 +      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
427 +      return 1; /* failure */
428 +    }
429 +    break;
430 +  default:
431 +    ;
432 +  };
433 +
434 +  /* store the original value */
435 +  switch(arg_type) {
436 +  case ARG_NO:
437 +    break;
438 +  default:
439 +    if (value && orig_field) {
440 +      if (no_free) {
441 +        *orig_field = value;
442 +      } else {
443 +        if (*orig_field)
444 +          free (*orig_field); /* free previous string */
445 +        *orig_field = gengetopt_strdup (value);
446 +      }
447 +    }
448 +  };
449 +
450 +  return 0; /* OK */
451 + }
452 +
453 +
454   int
455 < 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)
455 > cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
456 >                        struct cmdline_parser_params *params, const char *additional_error)
457   {
458    int c;        /* Character of the parsed option.  */
459  
460    int error = 0;
461    struct gengetopt_args_info local_args_info;
462 +  
463 +  int override;
464 +  int initialize;
465 +  int check_required;
466 +  int check_ambiguity;
467 +  
468 +  package_name = argv[0];
469 +  
470 +  override = params->override;
471 +  initialize = params->initialize;
472 +  check_required = params->check_required;
473 +  check_ambiguity = params->check_ambiguity;
474  
475    if (initialize)
476      cmdline_parser_init (args_info);
# Line 278 | Line 479 | cmdline_parser_internal (int argc, char * const *argv,
479  
480    optarg = 0;
481    optind = 0;
482 <  opterr = 1;
482 >  opterr = params->print_errors;
483    optopt = '?';
484  
485    while (1)
486      {
487        int option_index = 0;
287      char *stop_char;
488  
489        static struct option long_options[] = {
490          { "help",       0, NULL, 'h' },
# Line 294 | Line 494 | cmdline_parser_internal (int argc, char * const *argv,
494          { NULL, 0, NULL, 0 }
495        };
496  
297      stop_char = 0;
497        c = getopt_long (argc, argv, "hVo:t:", long_options, &option_index);
498  
499        if (c == -1) break;       /* Exit from `while (1)' loop.  */
# Line 312 | Line 511 | cmdline_parser_internal (int argc, char * const *argv,
511            exit (EXIT_SUCCESS);
512  
513          case 'o':       /* Output file name.  */
514 <          if (local_args_info.output_given)
515 <            {
516 <              fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
517 <              goto failure;
518 <            }
519 <          if (args_info->output_given && ! override)
520 <            continue;
521 <          local_args_info.output_given = 1;
522 <          args_info->output_given = 1;
523 <          if (args_info->output_arg)
325 <            free (args_info->output_arg); /* free previous string */
326 <          args_info->output_arg = gengetopt_strdup (optarg);
327 <          if (args_info->output_orig)
328 <            free (args_info->output_orig); /* free previous string */
329 <          args_info->output_orig = gengetopt_strdup (optarg);
514 >        
515 >        
516 >          if (update_arg( (void *)&(args_info->output_arg),
517 >               &(args_info->output_orig), &(args_info->output_given),
518 >              &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
519 >              check_ambiguity, override, 0, 0,
520 >              "output", 'o',
521 >              additional_error))
522 >            goto failure;
523 >        
524            break;
331
525          case 't':       /* temperature (K).  */
526 <          if (local_args_info.temperature_given)
527 <            {
528 <              fprintf (stderr, "%s: `--temperature' (`-t') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
529 <              goto failure;
530 <            }
531 <          if (args_info->temperature_given && ! override)
532 <            continue;
533 <          local_args_info.temperature_given = 1;
341 <          args_info->temperature_given = 1;
342 <          args_info->temperature_arg = strtod (optarg, &stop_char);
343 <          if (!(stop_char && *stop_char == '\0')) {
344 <            fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
526 >        
527 >        
528 >          if (update_arg( (void *)&(args_info->temperature_arg),
529 >               &(args_info->temperature_orig), &(args_info->temperature_given),
530 >              &(local_args_info.temperature_given), optarg, 0, 0, ARG_DOUBLE,
531 >              check_ambiguity, override, 0, 0,
532 >              "temperature", 't',
533 >              additional_error))
534              goto failure;
535 <          }
347 <          if (args_info->temperature_orig)
348 <            free (args_info->temperature_orig); /* free previous string */
349 <          args_info->temperature_orig = gengetopt_strdup (optarg);
535 >        
536            break;
537  
352
538          case 0: /* Long option with no short option */
539          case '?':       /* Invalid option.  */
540            /* `getopt_long' already printed an error message.  */

Comparing:
trunk/src/applications/thermalizer/thermalizerCmd.c (property svn:keywords), Revision 1083 by gezelter, Fri Oct 20 14:59:05 2006 UTC vs.
branches/development/src/applications/thermalizer/thermalizerCmd.c (property svn:keywords), Revision 1465 by chuckv, Fri Jul 9 23:08:25 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines