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