--- trunk/src/applications/nanoparticleBuilder/nanoparticleBuilderCmd.c 2006/10/11 19:24:37 1068 +++ trunk/src/applications/nanoparticleBuilder/nanoparticleBuilderCmd.c 2006/10/13 20:16:59 1069 @@ -1,7 +1,7 @@ /* - File autogenerated by gengetopt version 2.13 + File autogenerated by gengetopt version 2.15 generated with the following command: - gengetopt -u -F nanoparticleBuilderCmd + gengetopt -u -i nanoparticleBuilder.ggo -F nanoparticleBuilderCmd The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: @@ -35,18 +35,21 @@ struct ShellRadius_list struct ShellRadius_list { double ShellRadius_arg; + char *ShellRadius_orig; struct ShellRadius_list * next; }; struct molFraction_list { double molFraction_arg; + char *molFraction_orig; struct molFraction_list * next; }; struct vacancyRadius_list { double vacancyRadius_arg; + char *vacancyRadius_orig; struct vacancyRadius_list * next; }; @@ -59,7 +62,6 @@ void clear_given (struct gengetopt_args_info *args_inf args_info->help_given = 0 ; args_info->version_given = 0 ; args_info->output_given = 0 ; - args_info->latticetype_given = 0 ; args_info->latticeCnst_given = 0 ; args_info->radius_given = 0 ; args_info->ShellRadius_given = 0 ; @@ -72,10 +74,17 @@ void clear_args (struct gengetopt_args_info *args_info void clear_args (struct gengetopt_args_info *args_info) { args_info->output_arg = NULL; - args_info->latticetype_arg = gengetopt_strdup ("fcc"); + args_info->output_orig = NULL; + args_info->latticeCnst_orig = NULL; + args_info->radius_orig = NULL; args_info->ShellRadius_arg = NULL; + args_info->ShellRadius_orig = NULL; args_info->molFraction_arg = NULL; + args_info->molFraction_orig = NULL; + args_info->vacancyPCT_orig = NULL; args_info->vacancyRadius_arg = NULL; + args_info->vacancyRadius_orig = NULL; + } void @@ -93,7 +102,6 @@ cmdline_parser_print_help (void) printf("%s\n"," -h, --help Print help and exit"); printf("%s\n"," -V, --version Print version and exit"); printf("%s\n"," -o, --output=STRING Output file name"); - printf("%s\n"," --latticetype=STRING Lattice type string. Valid types are fcc,hcp,bcc. \n (default=`fcc')"); printf("%s\n"," --latticeCnst=DOUBLE Lattice spacing in Angstroms for cubic lattice."); printf("%s\n"," --radius=DOUBLE Nanoparticle radius in Angstroms"); 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."); @@ -113,8 +121,8 @@ cmdline_parser_init (struct gengetopt_args_info *args_ args_info->inputs_num = 0; } -void -cmdline_parser_free (struct gengetopt_args_info *args_info) +static void +cmdline_parser_release (struct gengetopt_args_info *args_info) { unsigned int i; @@ -123,25 +131,70 @@ cmdline_parser_free (struct gengetopt_args_info *args_ free (args_info->output_arg); /* free previous argument */ args_info->output_arg = 0; } - if (args_info->latticetype_arg) + if (args_info->output_orig) { - free (args_info->latticetype_arg); /* free previous argument */ - args_info->latticetype_arg = 0; + free (args_info->output_orig); /* free previous argument */ + args_info->output_orig = 0; } + if (args_info->latticeCnst_orig) + { + free (args_info->latticeCnst_orig); /* free previous argument */ + args_info->latticeCnst_orig = 0; + } + if (args_info->radius_orig) + { + free (args_info->radius_orig); /* free previous argument */ + args_info->radius_orig = 0; + } if (args_info->ShellRadius_arg) { + for (i = 0; i < args_info->ShellRadius_given; ++i) + { + if (args_info->ShellRadius_orig [i]) + { + free (args_info->ShellRadius_orig [i]); /* free previous argument */ + args_info->ShellRadius_orig [i] = 0; + } + } free (args_info->ShellRadius_arg); /* free previous argument */ args_info->ShellRadius_arg = 0; + free (args_info->ShellRadius_orig); /* free previous argument */ + args_info->ShellRadius_orig = 0; } if (args_info->molFraction_arg) { + for (i = 0; i < args_info->molFraction_given; ++i) + { + if (args_info->molFraction_orig [i]) + { + free (args_info->molFraction_orig [i]); /* free previous argument */ + args_info->molFraction_orig [i] = 0; + } + } free (args_info->molFraction_arg); /* free previous argument */ args_info->molFraction_arg = 0; + free (args_info->molFraction_orig); /* free previous argument */ + args_info->molFraction_orig = 0; } + if (args_info->vacancyPCT_orig) + { + free (args_info->vacancyPCT_orig); /* free previous argument */ + args_info->vacancyPCT_orig = 0; + } if (args_info->vacancyRadius_arg) { + for (i = 0; i < args_info->vacancyRadius_given; ++i) + { + if (args_info->vacancyRadius_orig [i]) + { + free (args_info->vacancyRadius_orig [i]); /* free previous argument */ + args_info->vacancyRadius_orig [i] = 0; + } + } free (args_info->vacancyRadius_arg); /* free previous argument */ args_info->vacancyRadius_arg = 0; + free (args_info->vacancyRadius_orig); /* free previous argument */ + args_info->vacancyRadius_orig = 0; } for (i = 0; i < args_info->inputs_num; ++i) @@ -153,6 +206,98 @@ cmdline_parser_free (struct gengetopt_args_info *args_ clear_given (args_info); } +int +cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) +{ + FILE *outfile; + int i = 0; + + outfile = fopen(filename, "w"); + + if (!outfile) + { + fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); + return EXIT_FAILURE; + } + + if (args_info->help_given) { + fprintf(outfile, "%s\n", "help"); + } + if (args_info->version_given) { + fprintf(outfile, "%s\n", "version"); + } + if (args_info->output_given) { + if (args_info->output_orig) { + fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig); + } else { + fprintf(outfile, "%s\n", "output"); + } + } + if (args_info->latticeCnst_given) { + if (args_info->latticeCnst_orig) { + fprintf(outfile, "%s=\"%s\"\n", "latticeCnst", args_info->latticeCnst_orig); + } else { + fprintf(outfile, "%s\n", "latticeCnst"); + } + } + if (args_info->radius_given) { + if (args_info->radius_orig) { + fprintf(outfile, "%s=\"%s\"\n", "radius", args_info->radius_orig); + } else { + fprintf(outfile, "%s\n", "radius"); + } + } + if (args_info->ShellRadius_orig) + { + for (i = 0; i < args_info->ShellRadius_given; ++i) + { + if (args_info->ShellRadius_orig [i]) + { + fprintf(outfile, "%s=\"%s\"\n", "ShellRadius", args_info->ShellRadius_orig [i]); + } + } + } + if (args_info->molFraction_orig) + { + for (i = 0; i < args_info->molFraction_given; ++i) + { + if (args_info->molFraction_orig [i]) + { + fprintf(outfile, "%s=\"%s\"\n", "molFraction", args_info->molFraction_orig [i]); + } + } + } + if (args_info->vacancyPCT_given) { + if (args_info->vacancyPCT_orig) { + fprintf(outfile, "%s=\"%s\"\n", "vacancyPCT", args_info->vacancyPCT_orig); + } else { + fprintf(outfile, "%s\n", "vacancyPCT"); + } + } + if (args_info->vacancyRadius_orig) + { + for (i = 0; i < args_info->vacancyRadius_given; ++i) + { + if (args_info->vacancyRadius_orig [i]) + { + fprintf(outfile, "%s=\"%s\"\n", "vacancyRadius", args_info->vacancyRadius_orig [i]); + } + } + } + + fclose (outfile); + + i = EXIT_SUCCESS; + return i; +} + +void +cmdline_parser_free (struct gengetopt_args_info *args_info) +{ + cmdline_parser_release (args_info); +} + + /* gengetopt_strdup() */ /* strdup.c replacement of strdup, which is not standard */ char * @@ -299,7 +444,6 @@ cmdline_parser_internal (int argc, char * const *argv, { "help", 0, NULL, 'h' }, { "version", 0, NULL, 'V' }, { "output", 1, NULL, 'o' }, - { "latticetype", 1, NULL, 0 }, { "latticeCnst", 1, NULL, 0 }, { "radius", 1, NULL, 0 }, { "ShellRadius", 1, NULL, 0 }, @@ -318,10 +462,12 @@ cmdline_parser_internal (int argc, char * const *argv, { case 'h': /* Print help and exit. */ cmdline_parser_print_help (); + cmdline_parser_free (&local_args_info); exit (EXIT_SUCCESS); case 'V': /* Print version and exit. */ cmdline_parser_print_version (); + cmdline_parser_free (&local_args_info); exit (EXIT_SUCCESS); case 'o': /* Output file name. */ @@ -337,28 +483,15 @@ cmdline_parser_internal (int argc, char * const *argv, if (args_info->output_arg) free (args_info->output_arg); /* free previous string */ args_info->output_arg = gengetopt_strdup (optarg); + if (args_info->output_orig) + free (args_info->output_orig); /* free previous string */ + args_info->output_orig = gengetopt_strdup (optarg); break; case 0: /* Long option with no short option */ - /* Lattice type string. Valid types are fcc,hcp,bcc.. */ - if (strcmp (long_options[option_index].name, "latticetype") == 0) - { - if (local_args_info.latticetype_given) - { - fprintf (stderr, "%s: `--latticetype' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); - goto failure; - } - if (args_info->latticetype_given && ! override) - continue; - local_args_info.latticetype_given = 1; - args_info->latticetype_given = 1; - if (args_info->latticetype_arg) - free (args_info->latticetype_arg); /* free previous string */ - args_info->latticetype_arg = gengetopt_strdup (optarg); - } /* Lattice spacing in Angstroms for cubic lattice.. */ - else if (strcmp (long_options[option_index].name, "latticeCnst") == 0) + if (strcmp (long_options[option_index].name, "latticeCnst") == 0) { if (local_args_info.latticeCnst_given) { @@ -369,7 +502,14 @@ cmdline_parser_internal (int argc, char * const *argv, continue; local_args_info.latticeCnst_given = 1; args_info->latticeCnst_given = 1; - args_info->latticeCnst_arg = strtod (optarg, NULL); + args_info->latticeCnst_arg = strtod (optarg, &stop_char); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->latticeCnst_orig) + free (args_info->latticeCnst_orig); /* free previous string */ + args_info->latticeCnst_orig = gengetopt_strdup (optarg); } /* Nanoparticle radius in Angstroms. */ else if (strcmp (long_options[option_index].name, "radius") == 0) @@ -383,7 +523,14 @@ cmdline_parser_internal (int argc, char * const *argv, continue; local_args_info.radius_given = 1; args_info->radius_given = 1; - args_info->radius_arg = strtod (optarg, NULL); + args_info->radius_arg = strtod (optarg, &stop_char); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->radius_orig) + free (args_info->radius_orig); /* free previous string */ + args_info->radius_orig = gengetopt_strdup (optarg); } /* 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.. */ else if (strcmp (long_options[option_index].name, "ShellRadius") == 0) @@ -398,8 +545,12 @@ cmdline_parser_internal (int argc, char * const *argv, ShellRadius_new = (struct ShellRadius_list *) malloc (sizeof (struct ShellRadius_list)); ShellRadius_new->next = ShellRadius_list; ShellRadius_list = ShellRadius_new; - ShellRadius_new->ShellRadius_arg = strtod (multi_token, NULL); - free (multi_token); + ShellRadius_new->ShellRadius_arg = strtod (multi_token, &stop_char); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], multi_token); + goto failure; + } + ShellRadius_new->ShellRadius_orig = multi_token; if (multi_next) { @@ -425,8 +576,12 @@ cmdline_parser_internal (int argc, char * const *argv, molFraction_new = (struct molFraction_list *) malloc (sizeof (struct molFraction_list)); molFraction_new->next = molFraction_list; molFraction_list = molFraction_new; - molFraction_new->molFraction_arg = strtod (multi_token, NULL); - free (multi_token); + molFraction_new->molFraction_arg = strtod (multi_token, &stop_char); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], multi_token); + goto failure; + } + molFraction_new->molFraction_orig = multi_token; if (multi_next) { @@ -451,7 +606,14 @@ cmdline_parser_internal (int argc, char * const *argv, continue; local_args_info.vacancyPCT_given = 1; args_info->vacancyPCT_given = 1; - args_info->vacancyPCT_arg = strtod (optarg, NULL); + args_info->vacancyPCT_arg = strtod (optarg, &stop_char); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->vacancyPCT_orig) + free (args_info->vacancyPCT_orig); /* free previous string */ + args_info->vacancyPCT_orig = gengetopt_strdup (optarg); } /* Radius arround core-shell where vacancies should be located.. */ else if (strcmp (long_options[option_index].name, "vacancyRadius") == 0) @@ -466,8 +628,12 @@ cmdline_parser_internal (int argc, char * const *argv, vacancyRadius_new = (struct vacancyRadius_list *) malloc (sizeof (struct vacancyRadius_list)); vacancyRadius_new->next = vacancyRadius_list; vacancyRadius_list = vacancyRadius_new; - vacancyRadius_new->vacancyRadius_arg = strtod (multi_token, NULL); - free (multi_token); + vacancyRadius_new->vacancyRadius_arg = strtod (multi_token, &stop_char); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], multi_token); + goto failure; + } + vacancyRadius_new->vacancyRadius_orig = multi_token; if (multi_next) { @@ -497,10 +663,12 @@ cmdline_parser_internal (int argc, char * const *argv, { struct ShellRadius_list *tmp; args_info->ShellRadius_arg = (double *) realloc (args_info->ShellRadius_arg, (args_info->ShellRadius_given + local_args_info.ShellRadius_given) * sizeof (double)); + args_info->ShellRadius_orig = (char **) realloc (args_info->ShellRadius_orig, (args_info->ShellRadius_given + local_args_info.ShellRadius_given) * sizeof (char *)); for (i = (local_args_info.ShellRadius_given - 1); i >= 0; --i) { tmp = ShellRadius_list; args_info->ShellRadius_arg [i + args_info->ShellRadius_given] = ShellRadius_list->ShellRadius_arg; + args_info->ShellRadius_orig [i + args_info->ShellRadius_given] = ShellRadius_list->ShellRadius_orig; ShellRadius_list = ShellRadius_list->next; free (tmp); } @@ -510,10 +678,12 @@ cmdline_parser_internal (int argc, char * const *argv, { struct molFraction_list *tmp; args_info->molFraction_arg = (double *) realloc (args_info->molFraction_arg, (args_info->molFraction_given + local_args_info.molFraction_given) * sizeof (double)); + args_info->molFraction_orig = (char **) realloc (args_info->molFraction_orig, (args_info->molFraction_given + local_args_info.molFraction_given) * sizeof (char *)); for (i = (local_args_info.molFraction_given - 1); i >= 0; --i) { tmp = molFraction_list; args_info->molFraction_arg [i + args_info->molFraction_given] = molFraction_list->molFraction_arg; + args_info->molFraction_orig [i + args_info->molFraction_given] = molFraction_list->molFraction_orig; molFraction_list = molFraction_list->next; free (tmp); } @@ -523,10 +693,12 @@ cmdline_parser_internal (int argc, char * const *argv, { struct vacancyRadius_list *tmp; args_info->vacancyRadius_arg = (double *) realloc (args_info->vacancyRadius_arg, (args_info->vacancyRadius_given + local_args_info.vacancyRadius_given) * sizeof (double)); + args_info->vacancyRadius_orig = (char **) realloc (args_info->vacancyRadius_orig, (args_info->vacancyRadius_given + local_args_info.vacancyRadius_given) * sizeof (char *)); for (i = (local_args_info.vacancyRadius_given - 1); i >= 0; --i) { tmp = vacancyRadius_list; args_info->vacancyRadius_arg [i + args_info->vacancyRadius_given] = vacancyRadius_list->vacancyRadius_arg; + args_info->vacancyRadius_orig [i + args_info->vacancyRadius_given] = vacancyRadius_list->vacancyRadius_orig; vacancyRadius_list = vacancyRadius_list->next; free (tmp); } @@ -545,7 +717,7 @@ cmdline_parser_internal (int argc, char * const *argv, error += cmdline_parser_required2 (args_info, argv[0], additional_error); } - cmdline_parser_free (&local_args_info); + cmdline_parser_release (&local_args_info); if ( error ) return (EXIT_FAILURE); @@ -570,6 +742,7 @@ failure: while (ShellRadius_list) { tmp = ShellRadius_list; + free (ShellRadius_list->ShellRadius_orig); ShellRadius_list = ShellRadius_list->next; free (tmp); } @@ -580,6 +753,7 @@ failure: while (molFraction_list) { tmp = molFraction_list; + free (molFraction_list->molFraction_orig); molFraction_list = molFraction_list->next; free (tmp); } @@ -590,11 +764,12 @@ failure: while (vacancyRadius_list) { tmp = vacancyRadius_list; + free (vacancyRadius_list->vacancyRadius_orig); vacancyRadius_list = vacancyRadius_list->next; free (tmp); } } - cmdline_parser_free (&local_args_info); + cmdline_parser_release (&local_args_info); return (EXIT_FAILURE); }