ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/hydrodynamics/HydroCmd.cpp
(Generate patch)

Comparing:
trunk/src/applications/hydrodynamics/HydroCmd.c (file contents), Revision 921 by tim, Wed Mar 29 18:09:26 2006 UTC vs.
branches/development/src/applications/hydrodynamics/HydroCmd.cpp (file contents), Revision 1832 by gezelter, Thu Jan 10 18:15:02 2013 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 HydroCmd
4 >  gengetopt --file-name=HydroCmd --unamed-opts
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 > #ifdef WIN32
25 > #include "utils/wingetopt.h"
26 > #else
27 > #include <getopt.h>
28 > #endif
29  
30   #include "HydroCmd.h"
31  
32 + const char *gengetopt_args_info_purpose = "\n+--------------------------------------------------------------------------+\n|    ____                    __  ___ ____                                  |\n|   / __ \\____  ___  ____   /  |/  // __ \\  The Open Molecular Dynamics    |\n|  / / / / __ \\/ _ \\/ __ \\ / /|_/ // / / /  Engine (formerly OOPSE).       |\n| / /_/ / /_/ /  __/ / / // /  / // /_/ /                                  |\n| \\____/ .___/\\___/_/ /_//_/  /_//_____/    Copyright 2004-2013 by the     |\n|     /_/                                   University of Notre Dame.      |\n|                                                                          |\n|                                           http://www.openmd.net          |\n|                                                                          |\n| OpenMD is an OpenScience project.  All source code is available for      |\n| any use whatsoever under a BSD-style license.                            |\n|                                                                          |\n| Support OpenScience!  If you use OpenMD or its source code in your       |\n| research, please cite the appropriate papers when you publish your       |\n| work.  Good starting points are:                                         |\n|                                                                          |\n| [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).                  |\n| [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).               |\n| [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).               |\n| [4] Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).                |\n| [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |\n| [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).                   |\n+--------------------------------------------------------------------------+";
33 +
34 + const char *gengetopt_args_info_usage = "Usage: Hydro [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 +  "  -i, --input=filename  input MetaData (md) file",
42 +  "  -o, --output=STRING   output file prefix  (default=`hydro')",
43 +  "      --model=STRING    hydrodynamics model (supports RoughShell and BeadModel)",
44 +  "  -b, --beads           generate the beads only, hydrodynamics will be \n                          performed  (default=off)",
45 +    0
46 + };
47 +
48 + typedef enum {ARG_NO
49 +  , ARG_FLAG
50 +  , ARG_STRING
51 + } cmdline_parser_arg_type;
52 +
53 + static
54 + void clear_given (struct gengetopt_args_info *args_info);
55 + static
56 + void clear_args (struct gengetopt_args_info *args_info);
57 +
58 + static int
59 + cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
60 +                        struct cmdline_parser_params *params, const char *additional_error);
61 +
62 + static int
63 + cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
64 +
65 + static char *
66 + gengetopt_strdup (const char *s);
67 +
68 + static
69 + void clear_given (struct gengetopt_args_info *args_info)
70 + {
71 +  args_info->help_given = 0 ;
72 +  args_info->version_given = 0 ;
73 +  args_info->input_given = 0 ;
74 +  args_info->output_given = 0 ;
75 +  args_info->model_given = 0 ;
76 +  args_info->beads_given = 0 ;
77 + }
78 +
79 + static
80 + void clear_args (struct gengetopt_args_info *args_info)
81 + {
82 +  FIX_UNUSED (args_info);
83 +  args_info->input_arg = NULL;
84 +  args_info->input_orig = NULL;
85 +  args_info->output_arg = gengetopt_strdup ("hydro");
86 +  args_info->output_orig = NULL;
87 +  args_info->model_arg = NULL;
88 +  args_info->model_orig = NULL;
89 +  args_info->beads_flag = 0;
90 +  
91 + }
92 +
93 + static
94 + void init_args_info(struct gengetopt_args_info *args_info)
95 + {
96 +
97 +
98 +  args_info->help_help = gengetopt_args_info_help[0] ;
99 +  args_info->version_help = gengetopt_args_info_help[1] ;
100 +  args_info->input_help = gengetopt_args_info_help[2] ;
101 +  args_info->output_help = gengetopt_args_info_help[3] ;
102 +  args_info->model_help = gengetopt_args_info_help[4] ;
103 +  args_info->beads_help = gengetopt_args_info_help[5] ;
104 +  
105 + }
106 +
107   void
108   cmdline_parser_print_version (void)
109   {
110 <  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
110 >  printf ("%s %s\n",
111 >     (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
112 >     CMDLINE_PARSER_VERSION);
113   }
114  
115 + static void print_help_common(void) {
116 +  cmdline_parser_print_version ();
117 +
118 +  if (strlen(gengetopt_args_info_purpose) > 0)
119 +    printf("\n%s\n", gengetopt_args_info_purpose);
120 +
121 +  if (strlen(gengetopt_args_info_usage) > 0)
122 +    printf("\n%s\n", gengetopt_args_info_usage);
123 +
124 +  printf("\n");
125 +
126 +  if (strlen(gengetopt_args_info_description) > 0)
127 +    printf("%s\n\n", gengetopt_args_info_description);
128 + }
129 +
130   void
131   cmdline_parser_print_help (void)
132   {
133 <  cmdline_parser_print_version ();
134 <  printf("\n"
135 <  "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE);
136 <  printf("\n");
38 <  printf("  -h, --help            Print help and exit\n");
39 <  printf("  -V, --version         Print version and exit\n");
40 <  printf("  -i, --input=filename  input dump file\n");
41 <  printf("  -o, --output=STRING   output file prefix  (default=`hydro')\n");
42 <  printf("      --model=STRING    hydrodynamics model (support RoughShell and BeadModel)\n");
43 <  printf("  -b, --beads           generate the beads only, hydrodynamics will be \n                          performed  (default=off)\n");
133 >  int i = 0;
134 >  print_help_common();
135 >  while (gengetopt_args_info_help[i])
136 >    printf("%s\n", gengetopt_args_info_help[i++]);
137   }
138  
139 + void
140 + cmdline_parser_init (struct gengetopt_args_info *args_info)
141 + {
142 +  clear_given (args_info);
143 +  clear_args (args_info);
144 +  init_args_info (args_info);
145  
146 < static char *gengetopt_strdup (const char *s);
146 >  args_info->inputs = 0;
147 >  args_info->inputs_num = 0;
148 > }
149  
150 < /* gengetopt_strdup() */
151 < /* strdup.c replacement of strdup, which is not standard */
150 > void
151 > cmdline_parser_params_init(struct cmdline_parser_params *params)
152 > {
153 >  if (params)
154 >    {
155 >      params->override = 0;
156 >      params->initialize = 1;
157 >      params->check_required = 1;
158 >      params->check_ambiguity = 0;
159 >      params->print_errors = 1;
160 >    }
161 > }
162 >
163 > struct cmdline_parser_params *
164 > cmdline_parser_params_create(void)
165 > {
166 >  struct cmdline_parser_params *params =
167 >    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
168 >  cmdline_parser_params_init(params);  
169 >  return params;
170 > }
171 >
172 > static void
173 > free_string_field (char **s)
174 > {
175 >  if (*s)
176 >    {
177 >      free (*s);
178 >      *s = 0;
179 >    }
180 > }
181 >
182 >
183 > static void
184 > cmdline_parser_release (struct gengetopt_args_info *args_info)
185 > {
186 >  unsigned int i;
187 >  free_string_field (&(args_info->input_arg));
188 >  free_string_field (&(args_info->input_orig));
189 >  free_string_field (&(args_info->output_arg));
190 >  free_string_field (&(args_info->output_orig));
191 >  free_string_field (&(args_info->model_arg));
192 >  free_string_field (&(args_info->model_orig));
193 >  
194 >  
195 >  for (i = 0; i < args_info->inputs_num; ++i)
196 >    free (args_info->inputs [i]);
197 >
198 >  if (args_info->inputs_num)
199 >    free (args_info->inputs);
200 >
201 >  clear_given (args_info);
202 > }
203 >
204 >
205 > static void
206 > write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
207 > {
208 >  FIX_UNUSED (values);
209 >  if (arg) {
210 >    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
211 >  } else {
212 >    fprintf(outfile, "%s\n", opt);
213 >  }
214 > }
215 >
216 >
217 > int
218 > cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
219 > {
220 >  int i = 0;
221 >
222 >  if (!outfile)
223 >    {
224 >      fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
225 >      return EXIT_FAILURE;
226 >    }
227 >
228 >  if (args_info->help_given)
229 >    write_into_file(outfile, "help", 0, 0 );
230 >  if (args_info->version_given)
231 >    write_into_file(outfile, "version", 0, 0 );
232 >  if (args_info->input_given)
233 >    write_into_file(outfile, "input", args_info->input_orig, 0);
234 >  if (args_info->output_given)
235 >    write_into_file(outfile, "output", args_info->output_orig, 0);
236 >  if (args_info->model_given)
237 >    write_into_file(outfile, "model", args_info->model_orig, 0);
238 >  if (args_info->beads_given)
239 >    write_into_file(outfile, "beads", 0, 0 );
240 >  
241 >
242 >  i = EXIT_SUCCESS;
243 >  return i;
244 > }
245 >
246 > int
247 > cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
248 > {
249 >  FILE *outfile;
250 >  int i = 0;
251 >
252 >  outfile = fopen(filename, "w");
253 >
254 >  if (!outfile)
255 >    {
256 >      fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
257 >      return EXIT_FAILURE;
258 >    }
259 >
260 >  i = cmdline_parser_dump(outfile, args_info);
261 >  fclose (outfile);
262 >
263 >  return i;
264 > }
265 >
266 > void
267 > cmdline_parser_free (struct gengetopt_args_info *args_info)
268 > {
269 >  cmdline_parser_release (args_info);
270 > }
271 >
272 > /** @brief replacement of strdup, which is not standard */
273   char *
274   gengetopt_strdup (const char *s)
275   {
276 <  char *result = (char*)malloc(strlen(s) + 1);
276 >  char *result = 0;
277 >  if (!s)
278 >    return result;
279 >
280 >  result = (char*)malloc(strlen(s) + 1);
281    if (result == (char*)0)
282      return (char*)0;
283    strcpy(result, s);
# Line 59 | Line 285 | int
285   }
286  
287   int
288 < cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
288 > cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
289   {
290 <  int c;        /* Character of the parsed option.  */
291 <  int missing_required_options = 0;
290 >  return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
291 > }
292  
293 <  args_info->help_given = 0 ;
294 <  args_info->version_given = 0 ;
295 <  args_info->input_given = 0 ;
296 <  args_info->output_given = 0 ;
297 <  args_info->model_given = 0 ;
298 <  args_info->beads_given = 0 ;
299 < #define clear_args() { \
300 <  args_info->input_arg = NULL; \
301 <  args_info->output_arg = gengetopt_strdup("hydro") ;\
302 <  args_info->model_arg = NULL; \
303 <  args_info->beads_flag = 0;\
293 > int
294 > cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
295 >                   struct cmdline_parser_params *params)
296 > {
297 >  int result;
298 >  result = cmdline_parser_internal (argc, argv, args_info, params, 0);
299 >
300 >  if (result == EXIT_FAILURE)
301 >    {
302 >      cmdline_parser_free (args_info);
303 >      exit (EXIT_FAILURE);
304 >    }
305 >  
306 >  return result;
307   }
308  
309 <  clear_args();
309 > int
310 > cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
311 > {
312 >  int result;
313 >  struct cmdline_parser_params params;
314 >  
315 >  params.override = override;
316 >  params.initialize = initialize;
317 >  params.check_required = check_required;
318 >  params.check_ambiguity = 0;
319 >  params.print_errors = 1;
320  
321 +  result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
322 +
323 +  if (result == EXIT_FAILURE)
324 +    {
325 +      cmdline_parser_free (args_info);
326 +      exit (EXIT_FAILURE);
327 +    }
328 +  
329 +  return result;
330 + }
331 +
332 + int
333 + cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
334 + {
335 +  int result = EXIT_SUCCESS;
336 +
337 +  if (cmdline_parser_required2(args_info, prog_name, 0) > 0)
338 +    result = EXIT_FAILURE;
339 +
340 +  if (result == EXIT_FAILURE)
341 +    {
342 +      cmdline_parser_free (args_info);
343 +      exit (EXIT_FAILURE);
344 +    }
345 +  
346 +  return result;
347 + }
348 +
349 + int
350 + cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
351 + {
352 +  int error = 0;
353 +  FIX_UNUSED (additional_error);
354 +
355 +  /* checks for required options */
356 +  if (! args_info->input_given)
357 +    {
358 +      fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : ""));
359 +      error = 1;
360 +    }
361 +  
362 +  if (! args_info->model_given)
363 +    {
364 +      fprintf (stderr, "%s: '--model' option required%s\n", prog_name, (additional_error ? additional_error : ""));
365 +      error = 1;
366 +    }
367 +  
368 +  
369 +  /* checks for dependences among options */
370 +
371 +  return error;
372 + }
373 +
374 +
375 + static char *package_name = 0;
376 +
377 + /**
378 + * @brief updates an option
379 + * @param field the generic pointer to the field to update
380 + * @param orig_field the pointer to the orig field
381 + * @param field_given the pointer to the number of occurrence of this option
382 + * @param prev_given the pointer to the number of occurrence already seen
383 + * @param value the argument for this option (if null no arg was specified)
384 + * @param possible_values the possible values for this option (if specified)
385 + * @param default_value the default value (in case the option only accepts fixed values)
386 + * @param arg_type the type of this option
387 + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
388 + * @param override @see cmdline_parser_params.override
389 + * @param no_free whether to free a possible previous value
390 + * @param multiple_option whether this is a multiple option
391 + * @param long_opt the corresponding long option
392 + * @param short_opt the corresponding short option (or '-' if none)
393 + * @param additional_error possible further error specification
394 + */
395 + static
396 + int update_arg(void *field, char **orig_field,
397 +               unsigned int *field_given, unsigned int *prev_given,
398 +               char *value, const char *possible_values[],
399 +               const char *default_value,
400 +               cmdline_parser_arg_type arg_type,
401 +               int check_ambiguity, int override,
402 +               int no_free, int multiple_option,
403 +               const char *long_opt, char short_opt,
404 +               const char *additional_error)
405 + {
406 +  char *stop_char = 0;
407 +  const char *val = value;
408 +  int found;
409 +  char **string_field;
410 +  FIX_UNUSED (field);
411 +
412 +  stop_char = 0;
413 +  found = 0;
414 +
415 +  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
416 +    {
417 +      if (short_opt != '-')
418 +        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
419 +               package_name, long_opt, short_opt,
420 +               (additional_error ? additional_error : ""));
421 +      else
422 +        fprintf (stderr, "%s: `--%s' option given more than once%s\n",
423 +               package_name, long_opt,
424 +               (additional_error ? additional_error : ""));
425 +      return 1; /* failure */
426 +    }
427 +
428 +  FIX_UNUSED (default_value);
429 +    
430 +  if (field_given && *field_given && ! override)
431 +    return 0;
432 +  if (prev_given)
433 +    (*prev_given)++;
434 +  if (field_given)
435 +    (*field_given)++;
436 +  if (possible_values)
437 +    val = possible_values[found];
438 +
439 +  switch(arg_type) {
440 +  case ARG_FLAG:
441 +    *((int *)field) = !*((int *)field);
442 +    break;
443 +  case ARG_STRING:
444 +    if (val) {
445 +      string_field = (char **)field;
446 +      if (!no_free && *string_field)
447 +        free (*string_field); /* free previous string */
448 +      *string_field = gengetopt_strdup (val);
449 +    }
450 +    break;
451 +  default:
452 +    break;
453 +  };
454 +
455 +
456 +  /* store the original value */
457 +  switch(arg_type) {
458 +  case ARG_NO:
459 +  case ARG_FLAG:
460 +    break;
461 +  default:
462 +    if (value && orig_field) {
463 +      if (no_free) {
464 +        *orig_field = value;
465 +      } else {
466 +        if (*orig_field)
467 +          free (*orig_field); /* free previous string */
468 +        *orig_field = gengetopt_strdup (value);
469 +      }
470 +    }
471 +  };
472 +
473 +  return 0; /* OK */
474 + }
475 +
476 +
477 + int
478 + cmdline_parser_internal (
479 +  int argc, char **argv, struct gengetopt_args_info *args_info,
480 +                        struct cmdline_parser_params *params, const char *additional_error)
481 + {
482 +  int c;        /* Character of the parsed option.  */
483 +
484 +  int error = 0;
485 +  struct gengetopt_args_info local_args_info;
486 +  
487 +  int override;
488 +  int initialize;
489 +  int check_required;
490 +  int check_ambiguity;
491 +  
492 +  package_name = argv[0];
493 +  
494 +  override = params->override;
495 +  initialize = params->initialize;
496 +  check_required = params->check_required;
497 +  check_ambiguity = params->check_ambiguity;
498 +
499 +  if (initialize)
500 +    cmdline_parser_init (args_info);
501 +
502 +  cmdline_parser_init (&local_args_info);
503 +
504    optarg = 0;
505 <  optind = 1;
506 <  opterr = 1;
505 >  optind = 0;
506 >  opterr = params->print_errors;
507    optopt = '?';
508  
509    while (1)
510      {
511        int option_index = 0;
90      char *stop_char;
512  
513        static struct option long_options[] = {
514          { "help",       0, NULL, 'h' },
# Line 96 | Line 517 | cmdline_parser (int argc, char * const *argv, struct g
517          { "output",     1, NULL, 'o' },
518          { "model",      1, NULL, 0 },
519          { "beads",      0, NULL, 'b' },
520 <        { NULL, 0, NULL, 0 }
520 >        { 0,  0, 0, 0 }
521        };
522  
102      stop_char = 0;
523        c = getopt_long (argc, argv, "hVi:o:b", long_options, &option_index);
524  
525        if (c == -1) break;       /* Exit from `while (1)' loop.  */
# Line 107 | Line 527 | cmdline_parser (int argc, char * const *argv, struct g
527        switch (c)
528          {
529          case 'h':       /* Print help and exit.  */
110          clear_args ();
530            cmdline_parser_print_help ();
531 +          cmdline_parser_free (&local_args_info);
532            exit (EXIT_SUCCESS);
533  
534          case 'V':       /* Print version and exit.  */
115          clear_args ();
535            cmdline_parser_print_version ();
536 +          cmdline_parser_free (&local_args_info);
537            exit (EXIT_SUCCESS);
538  
539 <        case 'i':       /* input dump file.  */
540 <          if (args_info->input_given)
541 <            {
542 <              fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE);
543 <              clear_args ();
544 <              exit (EXIT_FAILURE);
545 <            }
546 <          args_info->input_given = 1;
547 <          args_info->input_arg = gengetopt_strdup (optarg);
539 >        case 'i':       /* input MetaData (md) file.  */
540 >        
541 >        
542 >          if (update_arg( (void *)&(args_info->input_arg),
543 >               &(args_info->input_orig), &(args_info->input_given),
544 >              &(local_args_info.input_given), optarg, 0, 0, ARG_STRING,
545 >              check_ambiguity, override, 0, 0,
546 >              "input", 'i',
547 >              additional_error))
548 >            goto failure;
549 >        
550            break;
129
551          case 'o':       /* output file prefix.  */
552 <          if (args_info->output_given)
553 <            {
554 <              fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
555 <              clear_args ();
556 <              exit (EXIT_FAILURE);
557 <            }
558 <          args_info->output_given = 1;
559 <          if (args_info->output_arg)
560 <            free (args_info->output_arg); /* free default string */
561 <          args_info->output_arg = gengetopt_strdup (optarg);
552 >        
553 >        
554 >          if (update_arg( (void *)&(args_info->output_arg),
555 >               &(args_info->output_orig), &(args_info->output_given),
556 >              &(local_args_info.output_given), optarg, 0, "hydro", ARG_STRING,
557 >              check_ambiguity, override, 0, 0,
558 >              "output", 'o',
559 >              additional_error))
560 >            goto failure;
561 >        
562            break;
142
563          case 'b':       /* generate the beads only, hydrodynamics will be performed.  */
564 <          if (args_info->beads_given)
565 <            {
566 <              fprintf (stderr, "%s: `--beads' (`-b') option given more than once\n", CMDLINE_PARSER_PACKAGE);
567 <              clear_args ();
568 <              exit (EXIT_FAILURE);
569 <            }
570 <          args_info->beads_given = 1;
571 <          args_info->beads_flag = !(args_info->beads_flag);
564 >        
565 >        
566 >          if (update_arg((void *)&(args_info->beads_flag), 0, &(args_info->beads_given),
567 >              &(local_args_info.beads_given), optarg, 0, 0, ARG_FLAG,
568 >              check_ambiguity, override, 1, 0, "beads", 'b',
569 >              additional_error))
570 >            goto failure;
571 >        
572            break;
573  
154
574          case 0: /* Long option with no short option */
575 <          /* hydrodynamics model (support RoughShell and BeadModel).  */
575 >          /* hydrodynamics model (supports RoughShell and BeadModel).  */
576            if (strcmp (long_options[option_index].name, "model") == 0)
577            {
578 <            if (args_info->model_given)
579 <              {
580 <                fprintf (stderr, "%s: `--model' option given more than once\n", CMDLINE_PARSER_PACKAGE);
581 <                clear_args ();
582 <                exit (EXIT_FAILURE);
583 <              }
584 <            args_info->model_given = 1;
585 <            args_info->model_arg = gengetopt_strdup (optarg);
586 <            break;
578 >          
579 >          
580 >            if (update_arg( (void *)&(args_info->model_arg),
581 >                 &(args_info->model_orig), &(args_info->model_given),
582 >                &(local_args_info.model_given), optarg, 0, 0, ARG_STRING,
583 >                check_ambiguity, override, 0, 0,
584 >                "model", '-',
585 >                additional_error))
586 >              goto failure;
587 >          
588            }
589            
590 <
590 >          break;
591          case '?':       /* Invalid option.  */
592            /* `getopt_long' already printed an error message.  */
593 <          exit (EXIT_FAILURE);
593 >          goto failure;
594  
595          default:        /* bug: option not considered.  */
596 <          fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
596 >          fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
597            abort ();
598          } /* switch */
599      } /* while */
600  
601  
602 <  if (! args_info->input_given)
602 >
603 >  if (check_required)
604      {
605 <      fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE);
185 <      missing_required_options = 1;
605 >      error += cmdline_parser_required2 (args_info, argv[0], additional_error);
606      }
607 <  if (! args_info->model_given)
607 >
608 >  cmdline_parser_release (&local_args_info);
609 >
610 >  if ( error )
611 >    return (EXIT_FAILURE);
612 >
613 >  if (optind < argc)
614      {
615 <      fprintf (stderr, "%s: '--model' option required\n", CMDLINE_PARSER_PACKAGE);
616 <      missing_required_options = 1;
615 >      int i = 0 ;
616 >      int found_prog_name = 0;
617 >      /* whether program name, i.e., argv[0], is in the remaining args
618 >         (this may happen with some implementations of getopt,
619 >          but surely not with the one included by gengetopt) */
620 >
621 >      i = optind;
622 >      while (i < argc)
623 >        if (argv[i++] == argv[0]) {
624 >          found_prog_name = 1;
625 >          break;
626 >        }
627 >      i = 0;
628 >
629 >      args_info->inputs_num = argc - optind - found_prog_name;
630 >      args_info->inputs =
631 >        (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
632 >      while (optind < argc)
633 >        if (argv[optind++] != argv[0])
634 >          args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
635      }
192  if ( missing_required_options )
193    exit (EXIT_FAILURE);
636  
637    return 0;
638 +
639 + failure:
640 +  
641 +  cmdline_parser_release (&local_args_info);
642 +  return (EXIT_FAILURE);
643   }

Comparing:
trunk/src/applications/hydrodynamics/HydroCmd.c (property svn:keywords), Revision 921 by tim, Wed Mar 29 18:09:26 2006 UTC vs.
branches/development/src/applications/hydrodynamics/HydroCmd.cpp (property svn:keywords), Revision 1832 by gezelter, Thu Jan 10 18:15:02 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines