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.
trunk/src/applications/thermalizer/thermalizerCmd.cpp (file contents), Revision 1782 by gezelter, Wed Aug 22 02:28:28 2012 UTC

# Line 1 | Line 1
1   /*
2 <  File autogenerated by gengetopt version 2.17
2 >  File autogenerated by gengetopt version 2.22.4
3    generated with the following command:
4 <  gengetopt -F thermalizerCmd --unamed-opts
4 >  gengetopt -F thermalizerCmd -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 "thermalizerCmd.h"
27  
28 < const char *gengetopt_args_info_purpose = "Resamples the velocities for all the integrable objects in an OOPSE file from a \nMaxwell-Boltzmann distribution.";
28 > const char *gengetopt_args_info_purpose = "Resamples the velocities for all the integrable objects in an OpenMD file from \na Maxwell-Boltzmann distribution.";
29  
30   const char *gengetopt_args_info_usage = "Usage: thermalizer [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",
# Line 33 | Line 39 | const char *gengetopt_args_info_help[] = {
39      0
40   };
41  
42 + typedef enum {ARG_NO
43 +  , ARG_STRING
44 +  , ARG_DOUBLE
45 + } cmdline_parser_arg_type;
46 +
47   static
48   void clear_given (struct gengetopt_args_info *args_info);
49   static
50   void clear_args (struct gengetopt_args_info *args_info);
51  
52   static int
53 < 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);
53 > cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
54 >                        struct cmdline_parser_params *params, const char *additional_error);
55  
56   static int
57   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
# Line 59 | Line 71 | void clear_args (struct gengetopt_args_info *args_info
71   static
72   void clear_args (struct gengetopt_args_info *args_info)
73   {
74 +  FIX_UNUSED (args_info);
75    args_info->output_arg = NULL;
76    args_info->output_orig = NULL;
77    args_info->temperature_orig = NULL;
# Line 68 | Line 81 | void init_args_info(struct gengetopt_args_info *args_i
81   static
82   void init_args_info(struct gengetopt_args_info *args_info)
83   {
84 +
85 +
86    args_info->help_help = gengetopt_args_info_help[0] ;
87    args_info->version_help = gengetopt_args_info_help[1] ;
88    args_info->output_help = gengetopt_args_info_help[2] ;
# Line 78 | Line 93 | cmdline_parser_print_version (void)
93   void
94   cmdline_parser_print_version (void)
95   {
96 <  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
96 >  printf ("%s %s\n",
97 >     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
98 >     CMDLINE_PARSER_VERSION);
99   }
100  
101 < void
85 < cmdline_parser_print_help (void)
86 < {
87 <  int i = 0;
101 > static void print_help_common(void) {
102    cmdline_parser_print_version ();
103  
104    if (strlen(gengetopt_args_info_purpose) > 0)
105      printf("\n%s\n", gengetopt_args_info_purpose);
106  
107 <  printf("\n%s\n\n", gengetopt_args_info_usage);
107 >  if (strlen(gengetopt_args_info_usage) > 0)
108 >    printf("\n%s\n", gengetopt_args_info_usage);
109 >
110 >  printf("\n");
111 >
112 >  if (strlen(gengetopt_args_info_description) > 0)
113 >    printf("%s\n\n", gengetopt_args_info_description);
114 > }
115 >
116 > void
117 > cmdline_parser_print_help (void)
118 > {
119 >  int i = 0;
120 >  print_help_common();
121    while (gengetopt_args_info_help[i])
122      printf("%s\n", gengetopt_args_info_help[i++]);
123   }
# Line 102 | Line 129 | cmdline_parser_init (struct gengetopt_args_info *args_
129    clear_args (args_info);
130    init_args_info (args_info);
131  
132 <  args_info->inputs = NULL;
132 >  args_info->inputs = 0;
133    args_info->inputs_num = 0;
134   }
135  
136 + void
137 + cmdline_parser_params_init(struct cmdline_parser_params *params)
138 + {
139 +  if (params)
140 +    {
141 +      params->override = 0;
142 +      params->initialize = 1;
143 +      params->check_required = 1;
144 +      params->check_ambiguity = 0;
145 +      params->print_errors = 1;
146 +    }
147 + }
148 +
149 + struct cmdline_parser_params *
150 + cmdline_parser_params_create(void)
151 + {
152 +  struct cmdline_parser_params *params =
153 +    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
154 +  cmdline_parser_params_init(params);  
155 +  return params;
156 + }
157 +
158   static void
159 < cmdline_parser_release (struct gengetopt_args_info *args_info)
159 > free_string_field (char **s)
160   {
161 <  
113 <  unsigned int i;
114 <  if (args_info->output_arg)
161 >  if (*s)
162      {
163 <      free (args_info->output_arg); /* free previous argument */
164 <      args_info->output_arg = 0;
163 >      free (*s);
164 >      *s = 0;
165      }
166 <  if (args_info->output_orig)
167 <    {
168 <      free (args_info->output_orig); /* free previous argument */
169 <      args_info->output_orig = 0;
170 <    }
171 <  if (args_info->temperature_orig)
172 <    {
173 <      free (args_info->temperature_orig); /* free previous argument */
174 <      args_info->temperature_orig = 0;
175 <    }
166 > }
167 >
168 >
169 > static void
170 > cmdline_parser_release (struct gengetopt_args_info *args_info)
171 > {
172 >  unsigned int i;
173 >  free_string_field (&(args_info->output_arg));
174 >  free_string_field (&(args_info->output_orig));
175 >  free_string_field (&(args_info->temperature_orig));
176    
177 +  
178    for (i = 0; i < args_info->inputs_num; ++i)
179      free (args_info->inputs [i]);
180 <  
180 >
181    if (args_info->inputs_num)
182      free (args_info->inputs);
183 <  
183 >
184    clear_given (args_info);
185   }
186  
187 +
188 + static void
189 + write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
190 + {
191 +  FIX_UNUSED (values);
192 +  if (arg) {
193 +    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
194 +  } else {
195 +    fprintf(outfile, "%s\n", opt);
196 +  }
197 + }
198 +
199 +
200   int
201 + cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
202 + {
203 +  int i = 0;
204 +
205 +  if (!outfile)
206 +    {
207 +      fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
208 +      return EXIT_FAILURE;
209 +    }
210 +
211 +  if (args_info->help_given)
212 +    write_into_file(outfile, "help", 0, 0 );
213 +  if (args_info->version_given)
214 +    write_into_file(outfile, "version", 0, 0 );
215 +  if (args_info->output_given)
216 +    write_into_file(outfile, "output", args_info->output_orig, 0);
217 +  if (args_info->temperature_given)
218 +    write_into_file(outfile, "temperature", args_info->temperature_orig, 0);
219 +  
220 +
221 +  i = EXIT_SUCCESS;
222 +  return i;
223 + }
224 +
225 + int
226   cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
227   {
228    FILE *outfile;
# Line 150 | Line 236 | cmdline_parser_file_save(const char *filename, struct
236        return EXIT_FAILURE;
237      }
238  
239 <  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 <  
239 >  i = cmdline_parser_dump(outfile, args_info);
240    fclose (outfile);
241  
176  i = EXIT_SUCCESS;
242    return i;
243   }
244  
# Line 183 | Line 248 | cmdline_parser_free (struct gengetopt_args_info *args_
248    cmdline_parser_release (args_info);
249   }
250  
251 <
187 < /* gengetopt_strdup() */
188 < /* strdup.c replacement of strdup, which is not standard */
251 > /** @brief replacement of strdup, which is not standard */
252   char *
253   gengetopt_strdup (const char *s)
254   {
255 <  char *result = NULL;
255 >  char *result = 0;
256    if (!s)
257      return result;
258  
# Line 201 | Line 264 | int
264   }
265  
266   int
267 < cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
267 > cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
268   {
269    return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
270   }
271  
272   int
273 < cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
273 > cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
274 >                   struct cmdline_parser_params *params)
275   {
276    int result;
277 +  result = cmdline_parser_internal (argc, argv, args_info, params, 0);
278  
279 <  result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
279 >  if (result == EXIT_FAILURE)
280 >    {
281 >      cmdline_parser_free (args_info);
282 >      exit (EXIT_FAILURE);
283 >    }
284 >  
285 >  return result;
286 > }
287 >
288 > int
289 > cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
290 > {
291 >  int result;
292 >  struct cmdline_parser_params params;
293 >  
294 >  params.override = override;
295 >  params.initialize = initialize;
296 >  params.check_required = check_required;
297 >  params.check_ambiguity = 0;
298 >  params.print_errors = 1;
299  
300 +  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
301 +
302    if (result == EXIT_FAILURE)
303      {
304        cmdline_parser_free (args_info);
# Line 227 | Line 313 | cmdline_parser_required (struct gengetopt_args_info *a
313   {
314    int result = EXIT_SUCCESS;
315  
316 <  if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
316 >  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
317      result = EXIT_FAILURE;
318  
319    if (result == EXIT_FAILURE)
# Line 243 | Line 329 | cmdline_parser_required2 (struct gengetopt_args_info *
329   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
330   {
331    int error = 0;
332 +  FIX_UNUSED (additional_error);
333  
334    /* checks for required options */
335    if (! args_info->output_given)
# Line 263 | Line 350 | cmdline_parser_required2 (struct gengetopt_args_info *
350    return error;
351   }
352  
353 +
354 + static char *package_name = 0;
355 +
356 + /**
357 + * @brief updates an option
358 + * @param field the generic pointer to the field to update
359 + * @param orig_field the pointer to the orig field
360 + * @param field_given the pointer to the number of occurrence of this option
361 + * @param prev_given the pointer to the number of occurrence already seen
362 + * @param value the argument for this option (if null no arg was specified)
363 + * @param possible_values the possible values for this option (if specified)
364 + * @param default_value the default value (in case the option only accepts fixed values)
365 + * @param arg_type the type of this option
366 + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
367 + * @param override @see cmdline_parser_params.override
368 + * @param no_free whether to free a possible previous value
369 + * @param multiple_option whether this is a multiple option
370 + * @param long_opt the corresponding long option
371 + * @param short_opt the corresponding short option (or '-' if none)
372 + * @param additional_error possible further error specification
373 + */
374 + static
375 + int update_arg(void *field, char **orig_field,
376 +               unsigned int *field_given, unsigned int *prev_given,
377 +               char *value, const char *possible_values[],
378 +               const char *default_value,
379 +               cmdline_parser_arg_type arg_type,
380 +               int check_ambiguity, int override,
381 +               int no_free, int multiple_option,
382 +               const char *long_opt, char short_opt,
383 +               const char *additional_error)
384 + {
385 +  char *stop_char = 0;
386 +  const char *val = value;
387 +  int found;
388 +  char **string_field;
389 +  FIX_UNUSED (field);
390 +
391 +  stop_char = 0;
392 +  found = 0;
393 +
394 +  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
395 +    {
396 +      if (short_opt != '-')
397 +        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
398 +               package_name, long_opt, short_opt,
399 +               (additional_error ? additional_error : ""));
400 +      else
401 +        fprintf (stderr, "%s: `--%s' option given more than once%s\n",
402 +               package_name, long_opt,
403 +               (additional_error ? additional_error : ""));
404 +      return 1; /* failure */
405 +    }
406 +
407 +  FIX_UNUSED (default_value);
408 +    
409 +  if (field_given && *field_given && ! override)
410 +    return 0;
411 +  if (prev_given)
412 +    (*prev_given)++;
413 +  if (field_given)
414 +    (*field_given)++;
415 +  if (possible_values)
416 +    val = possible_values[found];
417 +
418 +  switch(arg_type) {
419 +  case ARG_DOUBLE:
420 +    if (val) *((double *)field) = strtod (val, &stop_char);
421 +    break;
422 +  case ARG_STRING:
423 +    if (val) {
424 +      string_field = (char **)field;
425 +      if (!no_free && *string_field)
426 +        free (*string_field); /* free previous string */
427 +      *string_field = gengetopt_strdup (val);
428 +    }
429 +    break;
430 +  default:
431 +    break;
432 +  };
433 +
434 +  /* check numeric conversion */
435 +  switch(arg_type) {
436 +  case ARG_DOUBLE:
437 +    if (val && !(stop_char && *stop_char == '\0')) {
438 +      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
439 +      return 1; /* failure */
440 +    }
441 +    break;
442 +  default:
443 +    ;
444 +  };
445 +
446 +  /* store the original value */
447 +  switch(arg_type) {
448 +  case ARG_NO:
449 +    break;
450 +  default:
451 +    if (value && orig_field) {
452 +      if (no_free) {
453 +        *orig_field = value;
454 +      } else {
455 +        if (*orig_field)
456 +          free (*orig_field); /* free previous string */
457 +        *orig_field = gengetopt_strdup (value);
458 +      }
459 +    }
460 +  };
461 +
462 +  return 0; /* OK */
463 + }
464 +
465 +
466   int
467 < 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)
467 > cmdline_parser_internal (
468 >  int argc, char **argv, struct gengetopt_args_info *args_info,
469 >                        struct cmdline_parser_params *params, const char *additional_error)
470   {
471    int c;        /* Character of the parsed option.  */
472  
473    int error = 0;
474    struct gengetopt_args_info local_args_info;
475 +  
476 +  int override;
477 +  int initialize;
478 +  int check_required;
479 +  int check_ambiguity;
480 +  
481 +  package_name = argv[0];
482 +  
483 +  override = params->override;
484 +  initialize = params->initialize;
485 +  check_required = params->check_required;
486 +  check_ambiguity = params->check_ambiguity;
487  
488    if (initialize)
489      cmdline_parser_init (args_info);
# Line 278 | Line 492 | cmdline_parser_internal (int argc, char * const *argv,
492  
493    optarg = 0;
494    optind = 0;
495 <  opterr = 1;
495 >  opterr = params->print_errors;
496    optopt = '?';
497  
498    while (1)
499      {
500        int option_index = 0;
287      char *stop_char;
501  
502        static struct option long_options[] = {
503          { "help",       0, NULL, 'h' },
504          { "version",    0, NULL, 'V' },
505          { "output",     1, NULL, 'o' },
506          { "temperature",        1, NULL, 't' },
507 <        { NULL, 0, NULL, 0 }
507 >        { 0,  0, 0, 0 }
508        };
509  
297      stop_char = 0;
510        c = getopt_long (argc, argv, "hVo:t:", long_options, &option_index);
511  
512        if (c == -1) break;       /* Exit from `while (1)' loop.  */
# Line 312 | Line 524 | cmdline_parser_internal (int argc, char * const *argv,
524            exit (EXIT_SUCCESS);
525  
526          case 'o':       /* Output file name.  */
527 <          if (local_args_info.output_given)
528 <            {
529 <              fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
530 <              goto failure;
531 <            }
532 <          if (args_info->output_given && ! override)
533 <            continue;
534 <          local_args_info.output_given = 1;
535 <          args_info->output_given = 1;
536 <          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);
527 >        
528 >        
529 >          if (update_arg( (void *)&(args_info->output_arg),
530 >               &(args_info->output_orig), &(args_info->output_given),
531 >              &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
532 >              check_ambiguity, override, 0, 0,
533 >              "output", 'o',
534 >              additional_error))
535 >            goto failure;
536 >        
537            break;
331
538          case 't':       /* temperature (K).  */
539 <          if (local_args_info.temperature_given)
540 <            {
541 <              fprintf (stderr, "%s: `--temperature' (`-t') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
542 <              goto failure;
543 <            }
544 <          if (args_info->temperature_given && ! override)
545 <            continue;
546 <          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);
539 >        
540 >        
541 >          if (update_arg( (void *)&(args_info->temperature_arg),
542 >               &(args_info->temperature_orig), &(args_info->temperature_given),
543 >              &(local_args_info.temperature_given), optarg, 0, 0, ARG_DOUBLE,
544 >              check_ambiguity, override, 0, 0,
545 >              "temperature", 't',
546 >              additional_error))
547              goto failure;
548 <          }
347 <          if (args_info->temperature_orig)
348 <            free (args_info->temperature_orig); /* free previous string */
349 <          args_info->temperature_orig = gengetopt_strdup (optarg);
548 >        
549            break;
550  
352
551          case 0: /* Long option with no short option */
552          case '?':       /* Invalid option.  */
553            /* `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.
trunk/src/applications/thermalizer/thermalizerCmd.cpp (property svn:keywords), Revision 1782 by gezelter, Wed Aug 22 02:28:28 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines