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

Comparing:
trunk/src/applications/nanoparticleBuilder/nanoparticleBuilderCmd.c (file contents), Revision 653 by chuckv, Tue Oct 11 21:57:22 2005 UTC vs.
branches/development/src/applications/nanoparticleBuilder/nanoparticleBuilderCmd.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.13
2 >  File autogenerated by gengetopt version 2.22
3    generated with the following command:
4    gengetopt -u -F nanoparticleBuilderCmd
5  
# Line 21 | Line 21
21  
22   #include "nanoparticleBuilderCmd.h"
23  
24 + const char *gengetopt_args_info_purpose = "Builds spherical random or core-shell nanoparticles and outputs an OpenMD \nstartup file";
25 +
26 + const char *gengetopt_args_info_usage = "Usage: nanoparticleBuilder [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",
33 +  "  -o, --output=STRING           Output file name",
34 +  "      --latticeConstant=DOUBLE  Lattice spacing in Angstroms for cubic lattice.",
35 +  "      --radius=DOUBLE           Nanoparticle radius in Angstroms",
36 +  "      --shellRadius=DOUBLE      Radius containing within it only molecules of a \n                                  specific component. Specified for each \n                                  component > 1 in the template file.",
37 +  "      --molFraction=DOUBLE      Builds a multi-component random alloy \n                                  nanoparticle. A mole Fraction must be \n                                  specified for each component > 1 in the \n                                  template file.",
38 +  "      --vacancyPercent=DOUBLE   Percentage of atoms to remove from within \n                                  vacancy range",
39 +  "      --vacancyInnerRadius=DOUBLE\n                                Radius arround core-shell where vacancies \n                                  should be located.",
40 +  "      --vacancyOuterRadius=DOUBLE\n                                Radius arround core-shell where vacancies \n                                  should be located.",
41 +    0
42 + };
43 +
44 + typedef enum {ARG_NO
45 +  , ARG_STRING
46 +  , ARG_DOUBLE
47 + } cmdline_parser_arg_type;
48 +
49   static
50   void clear_given (struct gengetopt_args_info *args_info);
51   static
52   void clear_args (struct gengetopt_args_info *args_info);
53  
54   static int
55 < 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);
55 > cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
56 >                        struct cmdline_parser_params *params, const char *additional_error);
57  
58   static int
59   cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
60  
35 struct ShellRadius_list
36 {
37  double ShellRadius_arg;
38  struct ShellRadius_list * next;
39 };
40
41 struct molFraction_list
42 {
43  double molFraction_arg;
44  struct molFraction_list * next;
45 };
46
47 struct vacancyRadius_list
48 {
49  double vacancyRadius_arg;
50  struct vacancyRadius_list * next;
51 };
52
61   static char *
62   gengetopt_strdup (const char *s);
63  
# Line 59 | Line 67 | void clear_given (struct gengetopt_args_info *args_inf
67    args_info->help_given = 0 ;
68    args_info->version_given = 0 ;
69    args_info->output_given = 0 ;
70 <  args_info->latticetype_given = 0 ;
63 <  args_info->latticeCnst_given = 0 ;
70 >  args_info->latticeConstant_given = 0 ;
71    args_info->radius_given = 0 ;
72 <  args_info->ShellRadius_given = 0 ;
72 >  args_info->shellRadius_given = 0 ;
73    args_info->molFraction_given = 0 ;
74 <  args_info->vacancyPCT_given = 0 ;
75 <  args_info->vacancyRadius_given = 0 ;
74 >  args_info->vacancyPercent_given = 0 ;
75 >  args_info->vacancyInnerRadius_given = 0 ;
76 >  args_info->vacancyOuterRadius_given = 0 ;
77   }
78  
79   static
80   void clear_args (struct gengetopt_args_info *args_info)
81   {
82    args_info->output_arg = NULL;
83 <  args_info->latticetype_arg = gengetopt_strdup ("fcc");
84 <  args_info->ShellRadius_arg = NULL;
83 >  args_info->output_orig = NULL;
84 >  args_info->latticeConstant_orig = NULL;
85 >  args_info->radius_orig = NULL;
86 >  args_info->shellRadius_arg = NULL;
87 >  args_info->shellRadius_orig = NULL;
88    args_info->molFraction_arg = NULL;
89 <  args_info->vacancyRadius_arg = NULL;
89 >  args_info->molFraction_orig = NULL;
90 >  args_info->vacancyPercent_orig = NULL;
91 >  args_info->vacancyInnerRadius_orig = NULL;
92 >  args_info->vacancyOuterRadius_orig = NULL;
93 >  
94   }
95  
96 + static
97 + void init_args_info(struct gengetopt_args_info *args_info)
98 + {
99 +
100 +
101 +  args_info->help_help = gengetopt_args_info_help[0] ;
102 +  args_info->version_help = gengetopt_args_info_help[1] ;
103 +  args_info->output_help = gengetopt_args_info_help[2] ;
104 +  args_info->latticeConstant_help = gengetopt_args_info_help[3] ;
105 +  args_info->radius_help = gengetopt_args_info_help[4] ;
106 +  args_info->shellRadius_help = gengetopt_args_info_help[5] ;
107 +  args_info->shellRadius_min = -1;
108 +  args_info->shellRadius_max = -1;
109 +  args_info->molFraction_help = gengetopt_args_info_help[6] ;
110 +  args_info->molFraction_min = -1;
111 +  args_info->molFraction_max = -1;
112 +  args_info->vacancyPercent_help = gengetopt_args_info_help[7] ;
113 +  args_info->vacancyInnerRadius_help = gengetopt_args_info_help[8] ;
114 +  args_info->vacancyOuterRadius_help = gengetopt_args_info_help[9] ;
115 +  
116 + }
117 +
118   void
119   cmdline_parser_print_version (void)
120   {
121    printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
122   }
123  
124 + static void print_help_common(void) {
125 +  cmdline_parser_print_version ();
126 +
127 +  if (strlen(gengetopt_args_info_purpose) > 0)
128 +    printf("\n%s\n", gengetopt_args_info_purpose);
129 +
130 +  if (strlen(gengetopt_args_info_usage) > 0)
131 +    printf("\n%s\n", gengetopt_args_info_usage);
132 +
133 +  printf("\n");
134 +
135 +  if (strlen(gengetopt_args_info_description) > 0)
136 +    printf("%s\n", gengetopt_args_info_description);
137 + }
138 +
139   void
140   cmdline_parser_print_help (void)
141   {
142 <  cmdline_parser_print_version ();
143 <  printf("\n%s\n", "Builds spherical random or core-shell nanoparticles and outputs a xyz input \nfile");
144 <  printf("\nUsage: nanoparticleBuilder [OPTIONS]... [FILES]...\n\n");
145 <  printf("%s\n","  -h, --help                  Print help and exit");
94 <  printf("%s\n","  -V, --version               Print version and exit");
95 <  printf("%s\n","  -o, --output=STRING         Output file name");
96 <  printf("%s\n","      --latticetype=STRING    Lattice type string. Valid types are fcc,hcp,bcc. \n                                 (default=`fcc')");
97 <  printf("%s\n","      --latticeCnst=DOUBLE    Lattice spacing in Angstroms for cubic lattice.");
98 <  printf("%s\n","      --radius=DOUBLE         Nanoparticle radius in Angstroms");
99 <  printf("%s\n","      --ShellRadius=DOUBLE    Radius from the center of the particle to start a \n                                new shell in multi-component core-shell \n                                particle. Specified for each component > 1 in \n                                md file.");
100 <  printf("%s\n","      --molFraction=DOUBLE    (Default) Builds a multi-component random mixed \n                                nanoparticle. Mole Fraction must be specified \n                                for each componet > 1 in MD file.");
101 <  printf("%s\n","      --vacancyPCT=DOUBLE     Percentage of vacancies to build");
102 <  printf("%s\n","      --vacancyRadius=DOUBLE  Radius arround core-shell where vacancies should \n                                be located.");
103 <  
142 >  int i = 0;
143 >  print_help_common();
144 >  while (gengetopt_args_info_help[i])
145 >    printf("%s\n", gengetopt_args_info_help[i++]);
146   }
147  
148   void
# Line 108 | Line 150 | cmdline_parser_init (struct gengetopt_args_info *args_
150   {
151    clear_given (args_info);
152    clear_args (args_info);
153 +  init_args_info (args_info);
154  
155    args_info->inputs = NULL;
156    args_info->inputs_num = 0;
157   }
158  
159   void
160 < cmdline_parser_free (struct gengetopt_args_info *args_info)
160 > cmdline_parser_params_init(struct cmdline_parser_params *params)
161   {
162 <  
163 <  unsigned int i;
164 <  if (args_info->output_arg)
165 <    {
166 <      free (args_info->output_arg); /* free previous argument */
167 <      args_info->output_arg = 0;
162 >  if (params)
163 >    {
164 >      params->override = 0;
165 >      params->initialize = 1;
166 >      params->check_required = 1;
167 >      params->check_ambiguity = 0;
168 >      params->print_errors = 1;
169      }
170 <  if (args_info->latticetype_arg)
170 > }
171 >
172 > struct cmdline_parser_params *
173 > cmdline_parser_params_create(void)
174 > {
175 >  struct cmdline_parser_params *params =
176 >    (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
177 >  cmdline_parser_params_init(params);  
178 >  return params;
179 > }
180 >
181 > static void
182 > free_string_field (char **s)
183 > {
184 >  if (*s)
185      {
186 <      free (args_info->latticetype_arg); /* free previous argument */
187 <      args_info->latticetype_arg = 0;
186 >      free (*s);
187 >      *s = 0;
188      }
189 <  if (args_info->ShellRadius_arg)
190 <    {
191 <      free (args_info->ShellRadius_arg); /* free previous argument */
192 <      args_info->ShellRadius_arg = 0;
193 <    }
194 <  if (args_info->molFraction_arg)
195 <    {
196 <      free (args_info->molFraction_arg); /* free previous argument */
197 <      args_info->molFraction_arg = 0;
198 <    }
199 <  if (args_info->vacancyRadius_arg)
200 <    {
201 <      free (args_info->vacancyRadius_arg); /* free previous argument */
202 <      args_info->vacancyRadius_arg = 0;
203 <    }
189 > }
190 >
191 > /** @brief generic value variable */
192 > union generic_value {
193 >    double double_arg;
194 >    char *string_arg;
195 > };
196 >
197 > /** @brief holds temporary values for multiple options */
198 > struct generic_list
199 > {
200 >  union generic_value arg;
201 >  char *orig;
202 >  struct generic_list *next;
203 > };
204 >
205 > /**
206 > * @brief add a node at the head of the list
207 > */
208 > static void add_node(struct generic_list **list) {
209 >  struct generic_list *new_node = (struct generic_list *) malloc (sizeof (struct generic_list));
210 >  new_node->next = *list;
211 >  *list = new_node;
212 >  new_node->arg.string_arg = NULL;
213 >  new_node->orig = NULL;
214 > }
215 >
216 > static void
217 > free_multiple_field(unsigned int len, void **arg, char ***orig)
218 > {
219 >  unsigned int i;
220 >  if (*arg) {
221 >    for (i = 0; i < len; ++i)
222 >      {
223 >        free_string_field(&((*orig)[i]));
224 >      }
225 >
226 >    free (*arg);
227 >    *arg = 0;
228 >    free (*orig);
229 >    *orig = 0;
230 >  }
231 > }
232 >
233 >
234 > static void
235 > cmdline_parser_release (struct gengetopt_args_info *args_info)
236 > {
237 >  unsigned int i;
238 >  free_string_field (&(args_info->output_arg));
239 >  free_string_field (&(args_info->output_orig));
240 >  free_string_field (&(args_info->latticeConstant_orig));
241 >  free_string_field (&(args_info->radius_orig));
242 >  free_multiple_field (args_info->shellRadius_given, (void **)&(args_info->shellRadius_arg), &(args_info->shellRadius_orig));
243 >  free_multiple_field (args_info->molFraction_given, (void **)&(args_info->molFraction_arg), &(args_info->molFraction_orig));
244 >  free_string_field (&(args_info->vacancyPercent_orig));
245 >  free_string_field (&(args_info->vacancyInnerRadius_orig));
246 >  free_string_field (&(args_info->vacancyOuterRadius_orig));
247    
248 +  
249    for (i = 0; i < args_info->inputs_num; ++i)
250      free (args_info->inputs [i]);
251 <  
251 >
252    if (args_info->inputs_num)
253      free (args_info->inputs);
254 <  
254 >
255    clear_given (args_info);
256   }
257  
258 < /* gengetopt_strdup() */
259 < /* strdup.c replacement of strdup, which is not standard */
258 >
259 > static void
260 > write_into_file(FILE *outfile, const char *opt, const char *arg, char *values[])
261 > {
262 >  if (arg) {
263 >    fprintf(outfile, "%s=\"%s\"\n", opt, arg);
264 >  } else {
265 >    fprintf(outfile, "%s\n", opt);
266 >  }
267 > }
268 >
269 > static void
270 > write_multiple_into_file(FILE *outfile, int len, const char *opt, char **arg, char *values[])
271 > {
272 >  int i;
273 >  
274 >  for (i = 0; i < len; ++i)
275 >    write_into_file(outfile, opt, (arg ? arg[i] : 0), values);
276 > }
277 >
278 > int
279 > cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
280 > {
281 >  int i = 0;
282 >
283 >  if (!outfile)
284 >    {
285 >      fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
286 >      return EXIT_FAILURE;
287 >    }
288 >
289 >  if (args_info->help_given)
290 >    write_into_file(outfile, "help", 0, 0 );
291 >  if (args_info->version_given)
292 >    write_into_file(outfile, "version", 0, 0 );
293 >  if (args_info->output_given)
294 >    write_into_file(outfile, "output", args_info->output_orig, 0);
295 >  if (args_info->latticeConstant_given)
296 >    write_into_file(outfile, "latticeConstant", args_info->latticeConstant_orig, 0);
297 >  if (args_info->radius_given)
298 >    write_into_file(outfile, "radius", args_info->radius_orig, 0);
299 >  write_multiple_into_file(outfile, args_info->shellRadius_given, "shellRadius", args_info->shellRadius_orig, 0);
300 >  write_multiple_into_file(outfile, args_info->molFraction_given, "molFraction", args_info->molFraction_orig, 0);
301 >  if (args_info->vacancyPercent_given)
302 >    write_into_file(outfile, "vacancyPercent", args_info->vacancyPercent_orig, 0);
303 >  if (args_info->vacancyInnerRadius_given)
304 >    write_into_file(outfile, "vacancyInnerRadius", args_info->vacancyInnerRadius_orig, 0);
305 >  if (args_info->vacancyOuterRadius_given)
306 >    write_into_file(outfile, "vacancyOuterRadius", args_info->vacancyOuterRadius_orig, 0);
307 >  
308 >
309 >  i = EXIT_SUCCESS;
310 >  return i;
311 > }
312 >
313 > int
314 > cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
315 > {
316 >  FILE *outfile;
317 >  int i = 0;
318 >
319 >  outfile = fopen(filename, "w");
320 >
321 >  if (!outfile)
322 >    {
323 >      fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
324 >      return EXIT_FAILURE;
325 >    }
326 >
327 >  i = cmdline_parser_dump(outfile, args_info);
328 >  fclose (outfile);
329 >
330 >  return i;
331 > }
332 >
333 > void
334 > cmdline_parser_free (struct gengetopt_args_info *args_info)
335 > {
336 >  cmdline_parser_release (args_info);
337 > }
338 >
339 > /** @brief replacement of strdup, which is not standard */
340   char *
341   gengetopt_strdup (const char *s)
342   {
# Line 173 | Line 355 | get_multiple_arg_token(const char *arg)
355   get_multiple_arg_token(const char *arg)
356   {
357    char *tok, *ret;
358 <  size_t len;
358 >  size_t len, num_of_escape, i, j;
359  
360    if (!arg)
361      return NULL;
362  
363    tok = strchr (arg, ',');
364 +  num_of_escape = 0;
365  
366 +  /* make sure it is not escaped */
367 +  while (tok)
368 +    {
369 +      if (*(tok-1) == '\\')
370 +        {
371 +          /* find the next one */
372 +          tok = strchr (tok+1, ',');
373 +          ++num_of_escape;
374 +        }
375 +      else
376 +        break;
377 +    }
378 +
379    if (tok)
380      len = (size_t)(tok - arg + 1);
381    else
382      len = strlen (arg) + 1;
383  
384 +  len -= num_of_escape;
385 +
386    ret = (char *) malloc (len);
387 <  strncpy (ret, arg, len-1);
387 >
388 >  i = 0;
389 >  j = 0;
390 >  while (arg[i] && (j < len-1))
391 >    {
392 >      if (arg[i] == '\\' &&
393 >          arg[ i + 1 ] &&
394 >          arg[ i + 1 ] == ',')
395 >        ++i;
396 >
397 >      ret[j++] = arg[i++];
398 >    }
399 >
400    ret[len-1] = '\0';
401  
402    return ret;
# Line 202 | Line 412 | get_multiple_arg_token_next(const char *arg)
412  
413    tok = strchr (arg, ',');
414  
415 +  /* make sure it is not escaped */
416 +  while (tok)
417 +    {
418 +      if (*(tok-1) == '\\')
419 +        {
420 +          /* find the next one */
421 +          tok = strchr (tok+1, ',');
422 +        }
423 +      else
424 +        break;
425 +    }
426 +
427    if (! tok || strlen(tok) == 1)
428      return 0;
429  
430    return tok+1;
431   }
432  
433 + static int
434 + check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc);
435 +
436   int
437 + check_multiple_option_occurrences(const char *prog_name, unsigned int option_given, int min, int max, const char *option_desc)
438 + {
439 +  int error = 0;
440 +
441 +  if (option_given && ! (min < 0 && max < 0))
442 +    {
443 +      if (min >= 0 && max >= 0)
444 +        {
445 +          if (min == max)
446 +            {
447 +              /* specific occurrences */
448 +              if (option_given != min)
449 +                {
450 +                  fprintf (stderr, "%s: %s option occurrences must be %d\n",
451 +                    prog_name, option_desc, min);
452 +                  error = 1;
453 +                }
454 +            }
455 +          else if (option_given < min
456 +              || option_given > max)
457 +            {
458 +              /* range occurrences */
459 +              fprintf (stderr, "%s: %s option occurrences must be between %d and %d\n",
460 +                prog_name, option_desc, min, max);
461 +              error = 1;
462 +            }
463 +        }
464 +      else if (min >= 0)
465 +        {
466 +          /* at least check */
467 +          if (option_given < min)
468 +            {
469 +              fprintf (stderr, "%s: %s option occurrences must be at least %d\n",
470 +                prog_name, option_desc, min);
471 +              error = 1;
472 +            }
473 +        }
474 +      else if (max >= 0)
475 +        {
476 +          /* at most check */
477 +          if (option_given > max)
478 +            {
479 +              fprintf (stderr, "%s: %s option occurrences must be at most %d\n",
480 +                prog_name, option_desc, max);
481 +              error = 1;
482 +            }
483 +        }
484 +    }
485 +    
486 +  return error;
487 + }
488 + int
489   cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
490   {
491    return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
492   }
493  
494   int
495 + cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info,
496 +                   struct cmdline_parser_params *params)
497 + {
498 +  int result;
499 +  result = cmdline_parser_internal (argc, argv, args_info, params, NULL);
500 +
501 +  if (result == EXIT_FAILURE)
502 +    {
503 +      cmdline_parser_free (args_info);
504 +      exit (EXIT_FAILURE);
505 +    }
506 +  
507 +  return result;
508 + }
509 +
510 + int
511   cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
512   {
513    int result;
514 +  struct cmdline_parser_params params;
515 +  
516 +  params.override = override;
517 +  params.initialize = initialize;
518 +  params.check_required = check_required;
519 +  params.check_ambiguity = 0;
520 +  params.print_errors = 1;
521  
522 <  result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
522 >  result = cmdline_parser_internal (argc, argv, args_info, &params, NULL);
523  
524    if (result == EXIT_FAILURE)
525      {
# Line 252 | Line 552 | cmdline_parser_required2 (struct gengetopt_args_info *
552   {
553    int error = 0;
554  
555 <  if (! args_info->latticeCnst_given)
555 >  /* checks for required options */
556 >  if (! args_info->output_given)
557      {
558 <      fprintf (stderr, "%s: '--latticeCnst' option required%s\n", prog_name, (additional_error ? additional_error : ""));
558 >      fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
559        error = 1;
560      }
561 +  
562 +  if (! args_info->latticeConstant_given)
563 +    {
564 +      fprintf (stderr, "%s: '--latticeConstant' option required%s\n", prog_name, (additional_error ? additional_error : ""));
565 +      error = 1;
566 +    }
567 +  
568    if (! args_info->radius_given)
569      {
570        fprintf (stderr, "%s: '--radius' option required%s\n", prog_name, (additional_error ? additional_error : ""));
571        error = 1;
572      }
573 +  
574 +  if (check_multiple_option_occurrences(prog_name, args_info->shellRadius_given, args_info->shellRadius_min, args_info->shellRadius_max, "'--shellRadius'"))
575 +     error = 1;
576 +  
577 +  if (check_multiple_option_occurrences(prog_name, args_info->molFraction_given, args_info->molFraction_min, args_info->molFraction_max, "'--molFraction'"))
578 +     error = 1;
579 +  
580 +  
581 +  /* checks for dependences among options */
582  
583    return error;
584   }
585  
586 < int
587 < 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)
586 >
587 > static char *package_name = 0;
588 >
589 > /**
590 > * @brief updates an option
591 > * @param field the generic pointer to the field to update
592 > * @param orig_field the pointer to the orig field
593 > * @param field_given the pointer to the number of occurrence of this option
594 > * @param prev_given the pointer to the number of occurrence already seen
595 > * @param value the argument for this option (if null no arg was specified)
596 > * @param possible_values the possible values for this option (if specified)
597 > * @param default_value the default value (in case the option only accepts fixed values)
598 > * @param arg_type the type of this option
599 > * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
600 > * @param override @see cmdline_parser_params.override
601 > * @param no_free whether to free a possible previous value
602 > * @param multiple_option whether this is a multiple option
603 > * @param long_opt the corresponding long option
604 > * @param short_opt the corresponding short option (or '-' if none)
605 > * @param additional_error possible further error specification
606 > */
607 > static
608 > int update_arg(void *field, char **orig_field,
609 >               unsigned int *field_given, unsigned int *prev_given,
610 >               char *value, char *possible_values[], const char *default_value,
611 >               cmdline_parser_arg_type arg_type,
612 >               int check_ambiguity, int override,
613 >               int no_free, int multiple_option,
614 >               const char *long_opt, char short_opt,
615 >               const char *additional_error)
616   {
617 <  int c;        /* Character of the parsed option.  */
618 <  char *multi_token, *multi_next; /* for multiple options */
617 >  char *stop_char = 0;
618 >  const char *val = value;
619 >  int found;
620 >  char **string_field;
621  
622 <  int i;        /* Counter */
622 >  stop_char = 0;
623 >  found = 0;
624  
625 <  struct ShellRadius_list * ShellRadius_list = NULL,* ShellRadius_new = NULL;
626 <  struct molFraction_list * molFraction_list = NULL,* molFraction_new = NULL;
627 <  struct vacancyRadius_list * vacancyRadius_list = NULL,* vacancyRadius_new = NULL;
625 >  if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
626 >    {
627 >      if (short_opt != '-')
628 >        fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
629 >               package_name, long_opt, short_opt,
630 >               (additional_error ? additional_error : ""));
631 >      else
632 >        fprintf (stderr, "%s: `--%s' option given more than once%s\n",
633 >               package_name, long_opt,
634 >               (additional_error ? additional_error : ""));
635 >      return 1; /* failure */
636 >    }
637 >
638 >    
639 >  if (field_given && *field_given && ! override)
640 >    return 0;
641 >  if (prev_given)
642 >    (*prev_given)++;
643 >  if (field_given)
644 >    (*field_given)++;
645 >  if (possible_values)
646 >    val = possible_values[found];
647 >
648 >  switch(arg_type) {
649 >  case ARG_DOUBLE:
650 >    if (val) *((double *)field) = strtod (val, &stop_char);
651 >    break;
652 >  case ARG_STRING:
653 >    if (val) {
654 >      string_field = (char **)field;
655 >      if (!no_free && *string_field)
656 >        free (*string_field); /* free previous string */
657 >      *string_field = gengetopt_strdup (val);
658 >    }
659 >    break;
660 >  default:
661 >    break;
662 >  };
663 >
664 >  /* check numeric conversion */
665 >  switch(arg_type) {
666 >  case ARG_DOUBLE:
667 >    if (val && !(stop_char && *stop_char == '\0')) {
668 >      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
669 >      return 1; /* failure */
670 >    }
671 >    break;
672 >  default:
673 >    ;
674 >  };
675 >
676 >  /* store the original value */
677 >  switch(arg_type) {
678 >  case ARG_NO:
679 >    break;
680 >  default:
681 >    if (value && orig_field) {
682 >      if (no_free) {
683 >        *orig_field = value;
684 >      } else {
685 >        if (*orig_field)
686 >          free (*orig_field); /* free previous string */
687 >        *orig_field = gengetopt_strdup (value);
688 >      }
689 >    }
690 >  };
691 >
692 >  return 0; /* OK */
693 > }
694 >
695 > /**
696 > * @brief store information about a multiple option in a temporary list
697 > * @param list where to (temporarily) store multiple options
698 > */
699 > static
700 > int update_multiple_arg_temp(struct generic_list **list,
701 >               unsigned int *prev_given, const char *val,
702 >               char *possible_values[], const char *default_value,
703 >               cmdline_parser_arg_type arg_type,
704 >               const char *long_opt, char short_opt,
705 >               const char *additional_error)
706 > {
707 >  char *multi_token, *multi_next; /* store single arguments */
708 >
709 >  if (arg_type == ARG_NO) {
710 >    (*prev_given)++;
711 >    return 0; /* OK */
712 >  }
713 >
714 >  multi_token = get_multiple_arg_token(val);
715 >  multi_next = get_multiple_arg_token_next (val);
716 >
717 >  while (1)
718 >    {
719 >      add_node (list);
720 >      if (update_arg((void *)&((*list)->arg), &((*list)->orig), 0,
721 >          prev_given, multi_token, possible_values, default_value,
722 >          arg_type, 0, 1, 1, 1, long_opt, short_opt, additional_error)) {
723 >        if (multi_token) free(multi_token);
724 >        return 1; /* failure */
725 >      }
726 >
727 >      if (multi_next)
728 >        {
729 >          multi_token = get_multiple_arg_token(multi_next);
730 >          multi_next = get_multiple_arg_token_next (multi_next);
731 >        }
732 >      else
733 >        break;
734 >    }
735 >
736 >  return 0; /* OK */
737 > }
738 >
739 > /**
740 > * @brief free the passed list (including possible string argument)
741 > */
742 > static
743 > void free_list(struct generic_list *list, short string_arg)
744 > {
745 >  if (list) {
746 >    struct generic_list *tmp;
747 >    while (list)
748 >      {
749 >        tmp = list;
750 >        if (string_arg && list->arg.string_arg)
751 >          free (list->arg.string_arg);
752 >        if (list->orig)
753 >          free (list->orig);
754 >        list = list->next;
755 >        free (tmp);
756 >      }
757 >  }
758 > }
759 >
760 > /**
761 > * @brief updates a multiple option starting from the passed list
762 > */
763 > static
764 > void update_multiple_arg(void *field, char ***orig_field,
765 >               unsigned int field_given, unsigned int prev_given, union generic_value *default_value,
766 >               cmdline_parser_arg_type arg_type,
767 >               struct generic_list *list)
768 > {
769 >  int i;
770 >  struct generic_list *tmp;
771 >
772 >  if (prev_given && list) {
773 >    *orig_field = (char **) realloc (*orig_field, (field_given + prev_given) * sizeof (char *));
774 >
775 >    switch(arg_type) {
776 >    case ARG_DOUBLE:
777 >      *((double **)field) = (double *)realloc (*((double **)field), (field_given + prev_given) * sizeof (double)); break;
778 >    case ARG_STRING:
779 >      *((char ***)field) = (char **)realloc (*((char ***)field), (field_given + prev_given) * sizeof (char *)); break;
780 >    default:
781 >      break;
782 >    };
783 >    
784 >    for (i = (prev_given - 1); i >= 0; --i)
785 >      {
786 >        tmp = list;
787 >        
788 >        switch(arg_type) {
789 >        case ARG_DOUBLE:
790 >          (*((double **)field))[i + field_given] = tmp->arg.double_arg; break;
791 >        case ARG_STRING:
792 >          (*((char ***)field))[i + field_given] = tmp->arg.string_arg; break;
793 >        default:
794 >          break;
795 >        }        
796 >        (*orig_field) [i + field_given] = list->orig;
797 >        list = list->next;
798 >        free (tmp);
799 >      }
800 >  } else { /* set the default value */
801 >    if (default_value && ! field_given) {
802 >      switch(arg_type) {
803 >      case ARG_DOUBLE:
804 >        if (! *((double **)field)) {
805 >          *((double **)field) = (double *)malloc (sizeof (double));
806 >          (*((double **)field))[0] = default_value->double_arg;
807 >        }
808 >        break;
809 >      case ARG_STRING:
810 >        if (! *((char ***)field)) {
811 >          *((char ***)field) = (char **)malloc (sizeof (char *));
812 >          (*((char ***)field))[0] = gengetopt_strdup(default_value->string_arg);
813 >        }
814 >        break;
815 >      default: break;
816 >      }
817 >      if (!(*orig_field)) {
818 >        *orig_field = (char **) malloc (sizeof (char *));
819 >        (*orig_field)[0] = NULL;
820 >      }
821 >    }
822 >  }
823 > }
824 >
825 > int
826 > cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info,
827 >                        struct cmdline_parser_params *params, const char *additional_error)
828 > {
829 >  int c;        /* Character of the parsed option.  */
830 >
831 >  struct generic_list * shellRadius_list = NULL;
832 >  struct generic_list * molFraction_list = NULL;
833    int error = 0;
834    struct gengetopt_args_info local_args_info;
835 +  
836 +  int override;
837 +  int initialize;
838 +  int check_required;
839 +  int check_ambiguity;
840 +  
841 +  package_name = argv[0];
842 +  
843 +  override = params->override;
844 +  initialize = params->initialize;
845 +  check_required = params->check_required;
846 +  check_ambiguity = params->check_ambiguity;
847  
848    if (initialize)
849      cmdline_parser_init (args_info);
# Line 286 | Line 851 | cmdline_parser_internal (int argc, char * const *argv,
851    cmdline_parser_init (&local_args_info);
852  
853    optarg = 0;
854 <  optind = 1;
855 <  opterr = 1;
854 >  optind = 0;
855 >  opterr = params->print_errors;
856    optopt = '?';
857  
858    while (1)
859      {
860        int option_index = 0;
296      char *stop_char;
861  
862        static struct option long_options[] = {
863          { "help",       0, NULL, 'h' },
864          { "version",    0, NULL, 'V' },
865          { "output",     1, NULL, 'o' },
866 <        { "latticetype",        1, NULL, 0 },
303 <        { "latticeCnst",        1, NULL, 0 },
866 >        { "latticeConstant",    1, NULL, 0 },
867          { "radius",     1, NULL, 0 },
868 <        { "ShellRadius",        1, NULL, 0 },
868 >        { "shellRadius",        1, NULL, 0 },
869          { "molFraction",        1, NULL, 0 },
870 <        { "vacancyPCT", 1, NULL, 0 },
871 <        { "vacancyRadius",      1, NULL, 0 },
870 >        { "vacancyPercent",     1, NULL, 0 },
871 >        { "vacancyInnerRadius", 1, NULL, 0 },
872 >        { "vacancyOuterRadius", 1, NULL, 0 },
873          { NULL, 0, NULL, 0 }
874        };
875  
312      stop_char = 0;
876        c = getopt_long (argc, argv, "hVo:", long_options, &option_index);
877  
878        if (c == -1) break;       /* Exit from `while (1)' loop.  */
# Line 318 | Line 881 | cmdline_parser_internal (int argc, char * const *argv,
881          {
882          case 'h':       /* Print help and exit.  */
883            cmdline_parser_print_help ();
884 +          cmdline_parser_free (&local_args_info);
885            exit (EXIT_SUCCESS);
886  
887          case 'V':       /* Print version and exit.  */
888            cmdline_parser_print_version ();
889 +          cmdline_parser_free (&local_args_info);
890            exit (EXIT_SUCCESS);
891  
892          case 'o':       /* Output file name.  */
893 <          if (local_args_info.output_given)
894 <            {
895 <              fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
896 <              goto failure;
897 <            }
898 <          if (args_info->output_given && ! override)
899 <            continue;
900 <          local_args_info.output_given = 1;
901 <          args_info->output_given = 1;
902 <          if (args_info->output_arg)
338 <            free (args_info->output_arg); /* free previous string */
339 <          args_info->output_arg = gengetopt_strdup (optarg);
893 >        
894 >        
895 >          if (update_arg( (void *)&(args_info->output_arg),
896 >               &(args_info->output_orig), &(args_info->output_given),
897 >              &(local_args_info.output_given), optarg, 0, 0, ARG_STRING,
898 >              check_ambiguity, override, 0, 0,
899 >              "output", 'o',
900 >              additional_error))
901 >            goto failure;
902 >        
903            break;
904  
342
905          case 0: /* Long option with no short option */
344          /* Lattice type string. Valid types are fcc,hcp,bcc..  */
345          if (strcmp (long_options[option_index].name, "latticetype") == 0)
346          {
347            if (local_args_info.latticetype_given)
348              {
349                fprintf (stderr, "%s: `--latticetype' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
350                goto failure;
351              }
352            if (args_info->latticetype_given && ! override)
353              continue;
354            local_args_info.latticetype_given = 1;
355            args_info->latticetype_given = 1;
356            if (args_info->latticetype_arg)
357              free (args_info->latticetype_arg); /* free previous string */
358            args_info->latticetype_arg = gengetopt_strdup (optarg);
359          }
906            /* Lattice spacing in Angstroms for cubic lattice..  */
907 <          else if (strcmp (long_options[option_index].name, "latticeCnst") == 0)
907 >          if (strcmp (long_options[option_index].name, "latticeConstant") == 0)
908            {
909 <            if (local_args_info.latticeCnst_given)
910 <              {
911 <                fprintf (stderr, "%s: `--latticeCnst' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
912 <                goto failure;
913 <              }
914 <            if (args_info->latticeCnst_given && ! override)
915 <              continue;
916 <            local_args_info.latticeCnst_given = 1;
917 <            args_info->latticeCnst_given = 1;
918 <            args_info->latticeCnst_arg = strtod (optarg, NULL);
909 >          
910 >          
911 >            if (update_arg( (void *)&(args_info->latticeConstant_arg),
912 >                 &(args_info->latticeConstant_orig), &(args_info->latticeConstant_given),
913 >                &(local_args_info.latticeConstant_given), optarg, 0, 0, ARG_DOUBLE,
914 >                check_ambiguity, override, 0, 0,
915 >                "latticeConstant", '-',
916 >                additional_error))
917 >              goto failure;
918 >          
919            }
920            /* Nanoparticle radius in Angstroms.  */
921            else if (strcmp (long_options[option_index].name, "radius") == 0)
922            {
923 <            if (local_args_info.radius_given)
378 <              {
379 <                fprintf (stderr, "%s: `--radius' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
380 <                goto failure;
381 <              }
382 <            if (args_info->radius_given && ! override)
383 <              continue;
384 <            local_args_info.radius_given = 1;
385 <            args_info->radius_given = 1;
386 <            args_info->radius_arg = strtod (optarg, NULL);
387 <          }
388 <          /* Radius from the center of the particle to start a new shell in multi-component core-shell particle. Specified for each component > 1 in md file..  */
389 <          else if (strcmp (long_options[option_index].name, "ShellRadius") == 0)
390 <          {
391 <            local_args_info.ShellRadius_given++;
923 >          
924            
925 <            multi_token = get_multiple_arg_token(optarg);
926 <            multi_next = get_multiple_arg_token_next (optarg);
925 >            if (update_arg( (void *)&(args_info->radius_arg),
926 >                 &(args_info->radius_orig), &(args_info->radius_given),
927 >                &(local_args_info.radius_given), optarg, 0, 0, ARG_DOUBLE,
928 >                check_ambiguity, override, 0, 0,
929 >                "radius", '-',
930 >                additional_error))
931 >              goto failure;
932            
933 <            while (1)
934 <              {
935 <                ShellRadius_new = (struct ShellRadius_list *) malloc (sizeof (struct ShellRadius_list));
936 <                ShellRadius_new->next = ShellRadius_list;
400 <                ShellRadius_list = ShellRadius_new;
401 <                ShellRadius_new->ShellRadius_arg = strtod (multi_token, NULL);
402 <                free (multi_token);
933 >          }
934 >          /* Radius containing within it only molecules of a specific component. Specified for each component > 1 in the template file..  */
935 >          else if (strcmp (long_options[option_index].name, "shellRadius") == 0)
936 >          {
937            
938 <                if (multi_next)
939 <                  {
940 <                    multi_token = get_multiple_arg_token(multi_next);
941 <                    multi_next = get_multiple_arg_token_next (multi_next);
942 <                    local_args_info.ShellRadius_given++;
943 <                  }
410 <                else
411 <                  break;
412 <              }
413 <            break;
938 >            if (update_multiple_arg_temp(&shellRadius_list,
939 >                &(local_args_info.shellRadius_given), optarg, 0, 0, ARG_DOUBLE,
940 >                "shellRadius", '-',
941 >                additional_error))
942 >              goto failure;
943 >          
944            }
945 <          /* (Default) Builds a multi-component random mixed nanoparticle. Mole Fraction must be specified for each componet > 1 in MD file..  */
945 >          /* Builds a multi-component random alloy nanoparticle. A mole Fraction must be specified for each component > 1 in the template file..  */
946            else if (strcmp (long_options[option_index].name, "molFraction") == 0)
947            {
418            local_args_info.molFraction_given++;
948            
949 <            multi_token = get_multiple_arg_token(optarg);
950 <            multi_next = get_multiple_arg_token_next (optarg);
949 >            if (update_multiple_arg_temp(&molFraction_list,
950 >                &(local_args_info.molFraction_given), optarg, 0, 0, ARG_DOUBLE,
951 >                "molFraction", '-',
952 >                additional_error))
953 >              goto failure;
954            
955 <            while (1)
956 <              {
957 <                molFraction_new = (struct molFraction_list *) malloc (sizeof (struct molFraction_list));
958 <                molFraction_new->next = molFraction_list;
427 <                molFraction_list = molFraction_new;
428 <                molFraction_new->molFraction_arg = strtod (multi_token, NULL);
429 <                free (multi_token);
955 >          }
956 >          /* Percentage of atoms to remove from within vacancy range.  */
957 >          else if (strcmp (long_options[option_index].name, "vacancyPercent") == 0)
958 >          {
959            
960 <                if (multi_next)
961 <                  {
962 <                    multi_token = get_multiple_arg_token(multi_next);
963 <                    multi_next = get_multiple_arg_token_next (multi_next);
964 <                    local_args_info.molFraction_given++;
965 <                  }
966 <                else
967 <                  break;
968 <              }
440 <            break;
960 >          
961 >            if (update_arg( (void *)&(args_info->vacancyPercent_arg),
962 >                 &(args_info->vacancyPercent_orig), &(args_info->vacancyPercent_given),
963 >                &(local_args_info.vacancyPercent_given), optarg, 0, 0, ARG_DOUBLE,
964 >                check_ambiguity, override, 0, 0,
965 >                "vacancyPercent", '-',
966 >                additional_error))
967 >              goto failure;
968 >          
969            }
970 <          /* Percentage of vacancies to build.  */
971 <          else if (strcmp (long_options[option_index].name, "vacancyPCT") == 0)
970 >          /* Radius arround core-shell where vacancies should be located..  */
971 >          else if (strcmp (long_options[option_index].name, "vacancyInnerRadius") == 0)
972            {
973 <            if (local_args_info.vacancyPCT_given)
974 <              {
975 <                fprintf (stderr, "%s: `--vacancyPCT' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
976 <                goto failure;
977 <              }
978 <            if (args_info->vacancyPCT_given && ! override)
979 <              continue;
980 <            local_args_info.vacancyPCT_given = 1;
981 <            args_info->vacancyPCT_given = 1;
982 <            args_info->vacancyPCT_arg = strtod (optarg, NULL);
973 >          
974 >          
975 >            if (update_arg( (void *)&(args_info->vacancyInnerRadius_arg),
976 >                 &(args_info->vacancyInnerRadius_orig), &(args_info->vacancyInnerRadius_given),
977 >                &(local_args_info.vacancyInnerRadius_given), optarg, 0, 0, ARG_DOUBLE,
978 >                check_ambiguity, override, 0, 0,
979 >                "vacancyInnerRadius", '-',
980 >                additional_error))
981 >              goto failure;
982 >          
983            }
984            /* Radius arround core-shell where vacancies should be located..  */
985 <          else if (strcmp (long_options[option_index].name, "vacancyRadius") == 0)
985 >          else if (strcmp (long_options[option_index].name, "vacancyOuterRadius") == 0)
986            {
459            local_args_info.vacancyRadius_given++;
987            
461            multi_token = get_multiple_arg_token(optarg);
462            multi_next = get_multiple_arg_token_next (optarg);
988            
989 <            while (1)
990 <              {
991 <                vacancyRadius_new = (struct vacancyRadius_list *) malloc (sizeof (struct vacancyRadius_list));
992 <                vacancyRadius_new->next = vacancyRadius_list;
993 <                vacancyRadius_list = vacancyRadius_new;
994 <                vacancyRadius_new->vacancyRadius_arg = strtod (multi_token, NULL);
995 <                free (multi_token);
989 >            if (update_arg( (void *)&(args_info->vacancyOuterRadius_arg),
990 >                 &(args_info->vacancyOuterRadius_orig), &(args_info->vacancyOuterRadius_given),
991 >                &(local_args_info.vacancyOuterRadius_given), optarg, 0, 0, ARG_DOUBLE,
992 >                check_ambiguity, override, 0, 0,
993 >                "vacancyOuterRadius", '-',
994 >                additional_error))
995 >              goto failure;
996            
472                if (multi_next)
473                  {
474                    multi_token = get_multiple_arg_token(multi_next);
475                    multi_next = get_multiple_arg_token_next (multi_next);
476                    local_args_info.vacancyRadius_given++;
477                  }
478                else
479                  break;
480              }
481            break;
997            }
998            
999            break;
# Line 493 | Line 1008 | cmdline_parser_internal (int argc, char * const *argv,
1008      } /* while */
1009  
1010  
1011 <  if (local_args_info.ShellRadius_given && ShellRadius_list)
1012 <    {
1013 <      struct ShellRadius_list *tmp;
1014 <      args_info->ShellRadius_arg = (double *) realloc (args_info->ShellRadius_arg, (args_info->ShellRadius_given + local_args_info.ShellRadius_given) * sizeof (double));
1015 <      for (i = (local_args_info.ShellRadius_given - 1); i >= 0; --i)
1016 <        {
1017 <          tmp = ShellRadius_list;
1018 <          args_info->ShellRadius_arg [i + args_info->ShellRadius_given] = ShellRadius_list->ShellRadius_arg;
504 <          ShellRadius_list = ShellRadius_list->next;
505 <          free (tmp);
506 <        }
507 <    }
508 <  
509 <  if (local_args_info.molFraction_given && molFraction_list)
510 <    {
511 <      struct molFraction_list *tmp;
512 <      args_info->molFraction_arg = (double *) realloc (args_info->molFraction_arg, (args_info->molFraction_given + local_args_info.molFraction_given) * sizeof (double));
513 <      for (i = (local_args_info.molFraction_given - 1); i >= 0; --i)
514 <        {
515 <          tmp = molFraction_list;
516 <          args_info->molFraction_arg [i + args_info->molFraction_given] = molFraction_list->molFraction_arg;
517 <          molFraction_list = molFraction_list->next;
518 <          free (tmp);
519 <        }
520 <    }
521 <  
522 <  if (local_args_info.vacancyRadius_given && vacancyRadius_list)
523 <    {
524 <      struct vacancyRadius_list *tmp;
525 <      args_info->vacancyRadius_arg = (double *) realloc (args_info->vacancyRadius_arg, (args_info->vacancyRadius_given + local_args_info.vacancyRadius_given) * sizeof (double));
526 <      for (i = (local_args_info.vacancyRadius_given - 1); i >= 0; --i)
527 <        {
528 <          tmp = vacancyRadius_list;
529 <          args_info->vacancyRadius_arg [i + args_info->vacancyRadius_given] = vacancyRadius_list->vacancyRadius_arg;
530 <          vacancyRadius_list = vacancyRadius_list->next;
531 <          free (tmp);
532 <        }
533 <    }
534 <  
1011 >  update_multiple_arg((void *)&(args_info->shellRadius_arg),
1012 >    &(args_info->shellRadius_orig), args_info->shellRadius_given,
1013 >    local_args_info.shellRadius_given, 0 ,
1014 >    ARG_DOUBLE, shellRadius_list);
1015 >  update_multiple_arg((void *)&(args_info->molFraction_arg),
1016 >    &(args_info->molFraction_orig), args_info->molFraction_given,
1017 >    local_args_info.molFraction_given, 0 ,
1018 >    ARG_DOUBLE, molFraction_list);
1019  
1020 <  args_info->ShellRadius_given += local_args_info.ShellRadius_given;
1021 <  local_args_info.ShellRadius_given = 0;
1020 >  args_info->shellRadius_given += local_args_info.shellRadius_given;
1021 >  local_args_info.shellRadius_given = 0;
1022    args_info->molFraction_given += local_args_info.molFraction_given;
1023    local_args_info.molFraction_given = 0;
540  args_info->vacancyRadius_given += local_args_info.vacancyRadius_given;
541  local_args_info.vacancyRadius_given = 0;
1024    
1025    if (check_required)
1026      {
1027        error += cmdline_parser_required2 (args_info, argv[0], additional_error);
1028      }
1029  
1030 <  cmdline_parser_free (&local_args_info);
1030 >  cmdline_parser_release (&local_args_info);
1031  
1032    if ( error )
1033      return (EXIT_FAILURE);
# Line 553 | Line 1035 | cmdline_parser_internal (int argc, char * const *argv,
1035    if (optind < argc)
1036      {
1037        int i = 0 ;
1038 +      int found_prog_name = 0;
1039 +      /* whether program name, i.e., argv[0], is in the remaining args
1040 +         (this may happen with some implementations of getopt,
1041 +          but surely not with the one included by gengetopt) */
1042  
1043 <      args_info->inputs_num = argc - optind ;
1043 >      i = optind;
1044 >      while (i < argc)
1045 >        if (argv[i++] == argv[0]) {
1046 >          found_prog_name = 1;
1047 >          break;
1048 >        }
1049 >      i = 0;
1050 >
1051 >      args_info->inputs_num = argc - optind - found_prog_name;
1052        args_info->inputs =
1053          (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
1054        while (optind < argc)
1055 <        args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
1055 >        if (argv[optind++] != argv[0])
1056 >          args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
1057      }
1058  
1059    return 0;
1060  
1061   failure:
1062 <  if (ShellRadius_list)
1063 <    {
569 <      struct ShellRadius_list *tmp;
570 <      while (ShellRadius_list)
571 <        {
572 <          tmp = ShellRadius_list;
573 <          ShellRadius_list = ShellRadius_list->next;
574 <          free (tmp);
575 <        }
576 <    }
577 <  if (molFraction_list)
578 <    {
579 <      struct molFraction_list *tmp;
580 <      while (molFraction_list)
581 <        {
582 <          tmp = molFraction_list;
583 <          molFraction_list = molFraction_list->next;
584 <          free (tmp);
585 <        }
586 <    }
587 <  if (vacancyRadius_list)
588 <    {
589 <      struct vacancyRadius_list *tmp;
590 <      while (vacancyRadius_list)
591 <        {
592 <          tmp = vacancyRadius_list;
593 <          vacancyRadius_list = vacancyRadius_list->next;
594 <          free (tmp);
595 <        }
596 <    }
1062 >  free_list (shellRadius_list, 0 );
1063 >  free_list (molFraction_list, 0 );
1064    
1065 <  cmdline_parser_free (&local_args_info);
1065 >  cmdline_parser_release (&local_args_info);
1066    return (EXIT_FAILURE);
1067   }

Comparing:
trunk/src/applications/nanoparticleBuilder/nanoparticleBuilderCmd.c (property svn:keywords), Revision 653 by chuckv, Tue Oct 11 21:57:22 2005 UTC vs.
branches/development/src/applications/nanoparticleBuilder/nanoparticleBuilderCmd.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