| 1 | chuckv | 2164 | /* | 
| 2 | chuckv | 2215 | File autogenerated by gengetopt version 2.13 | 
| 3 | chuckv | 2164 | generated with the following command: | 
| 4 |  |  | gengetopt -u --file-name=nanorodBuilderCmd | 
| 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 |  |  | #include "getopt.h" | 
| 21 |  |  |  | 
| 22 |  |  | #include "nanorodBuilderCmd.h" | 
| 23 |  |  |  | 
| 24 |  |  | static | 
| 25 |  |  | void clear_given (struct gengetopt_args_info *args_info); | 
| 26 |  |  | static | 
| 27 |  |  | void clear_args (struct gengetopt_args_info *args_info); | 
| 28 |  |  |  | 
| 29 |  |  | static int | 
| 30 |  |  | 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); | 
| 31 |  |  |  | 
| 32 | chuckv | 2215 | static int | 
| 33 |  |  | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); | 
| 34 |  |  |  | 
| 35 | chuckv | 2164 | static char * | 
| 36 |  |  | gengetopt_strdup (const char *s); | 
| 37 |  |  |  | 
| 38 |  |  | static | 
| 39 |  |  | void clear_given (struct gengetopt_args_info *args_info) | 
| 40 |  |  | { | 
| 41 |  |  | args_info->help_given = 0 ; | 
| 42 |  |  | args_info->version_given = 0 ; | 
| 43 |  |  | args_info->output_given = 0 ; | 
| 44 |  |  | args_info->latticetype_given = 0 ; | 
| 45 |  |  | args_info->length_given = 0 ; | 
| 46 |  |  | args_info->width_given = 0 ; | 
| 47 |  |  | args_info->latticeCnst_given = 0 ; | 
| 48 |  |  | args_info->genGeomview_given = 0 ; | 
| 49 | chuckv | 2218 | args_info->twinnedCrystal_given = 0 ; | 
| 50 | chuckv | 2164 | } | 
| 51 |  |  |  | 
| 52 |  |  | static | 
| 53 |  |  | void clear_args (struct gengetopt_args_info *args_info) | 
| 54 |  |  | { | 
| 55 |  |  | args_info->output_arg = NULL; | 
| 56 |  |  | args_info->latticetype_arg = gengetopt_strdup ("fcc"); | 
| 57 | chuckv | 2215 | args_info->genGeomview_flag = 0; | 
| 58 | chuckv | 2218 | args_info->twinnedCrystal_flag = 0; | 
| 59 | chuckv | 2164 | } | 
| 60 |  |  |  | 
| 61 |  |  | void | 
| 62 |  |  | cmdline_parser_print_version (void) | 
| 63 |  |  | { | 
| 64 |  |  | printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); | 
| 65 |  |  | } | 
| 66 |  |  |  | 
| 67 |  |  | void | 
| 68 |  |  | cmdline_parser_print_help (void) | 
| 69 |  |  | { | 
| 70 |  |  | cmdline_parser_print_version (); | 
| 71 | chuckv | 2215 | printf("\n%s\n", "Builds penta-hexagonal nanorods and outputs a xyz input file"); | 
| 72 |  |  | printf("\nUsage: nanorodBuilder [OPTIONS]... [FILES]...\n\n"); | 
| 73 | chuckv | 2164 | printf("%s\n","  -h, --help                Print help and exit"); | 
| 74 |  |  | printf("%s\n","  -V, --version             Print version and exit"); | 
| 75 |  |  | printf("%s\n","  -o, --output=STRING       Output file name"); | 
| 76 |  |  | printf("%s\n","      --latticetype=STRING  Lattice type string. Valid types are fcc,hcp,bcc.  \n                              (default=`fcc')"); | 
| 77 |  |  | printf("%s\n","      --length=DOUBLE       length of nanorod in Angstroms"); | 
| 78 |  |  | printf("%s\n","      --width=DOUBLE        diameter  of nanorod in Angstroms"); | 
| 79 |  |  | printf("%s\n","      --latticeCnst=DOUBLE  lattice spacing in Angstrons for cubic lattice"); | 
| 80 | chuckv | 2215 | printf("%s\n","      --genGeomview         generate a geomview file with the object geometry  \n                              (default=off)"); | 
| 81 | chuckv | 2218 | printf("%s\n","      --twinnedCrystal      generate a twinned crystal nanorod  (default=off)"); | 
| 82 | chuckv | 2215 |  | 
| 83 | chuckv | 2164 | } | 
| 84 |  |  |  | 
| 85 |  |  | void | 
| 86 |  |  | cmdline_parser_init (struct gengetopt_args_info *args_info) | 
| 87 |  |  | { | 
| 88 |  |  | clear_given (args_info); | 
| 89 |  |  | clear_args (args_info); | 
| 90 |  |  |  | 
| 91 |  |  | args_info->inputs = NULL; | 
| 92 |  |  | args_info->inputs_num = 0; | 
| 93 |  |  | } | 
| 94 |  |  |  | 
| 95 |  |  | void | 
| 96 |  |  | cmdline_parser_free (struct gengetopt_args_info *args_info) | 
| 97 |  |  | { | 
| 98 |  |  |  | 
| 99 | chuckv | 2215 | unsigned int i; | 
| 100 | chuckv | 2164 | if (args_info->output_arg) | 
| 101 |  |  | { | 
| 102 |  |  | free (args_info->output_arg); /* free previous argument */ | 
| 103 |  |  | args_info->output_arg = 0; | 
| 104 |  |  | } | 
| 105 |  |  | if (args_info->latticetype_arg) | 
| 106 |  |  | { | 
| 107 |  |  | free (args_info->latticetype_arg); /* free previous argument */ | 
| 108 |  |  | args_info->latticetype_arg = 0; | 
| 109 |  |  | } | 
| 110 |  |  |  | 
| 111 |  |  | for (i = 0; i < args_info->inputs_num; ++i) | 
| 112 |  |  | free (args_info->inputs [i]); | 
| 113 |  |  |  | 
| 114 |  |  | if (args_info->inputs_num) | 
| 115 |  |  | free (args_info->inputs); | 
| 116 |  |  |  | 
| 117 |  |  | clear_given (args_info); | 
| 118 |  |  | } | 
| 119 |  |  |  | 
| 120 |  |  | /* gengetopt_strdup() */ | 
| 121 |  |  | /* strdup.c replacement of strdup, which is not standard */ | 
| 122 |  |  | char * | 
| 123 |  |  | gengetopt_strdup (const char *s) | 
| 124 |  |  | { | 
| 125 |  |  | char *result = NULL; | 
| 126 |  |  | if (!s) | 
| 127 |  |  | return result; | 
| 128 |  |  |  | 
| 129 |  |  | result = (char*)malloc(strlen(s) + 1); | 
| 130 |  |  | if (result == (char*)0) | 
| 131 |  |  | return (char*)0; | 
| 132 |  |  | strcpy(result, s); | 
| 133 |  |  | return result; | 
| 134 |  |  | } | 
| 135 |  |  |  | 
| 136 |  |  | int | 
| 137 |  |  | cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) | 
| 138 |  |  | { | 
| 139 | chuckv | 2215 | return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); | 
| 140 | chuckv | 2164 | } | 
| 141 |  |  |  | 
| 142 |  |  | int | 
| 143 | chuckv | 2215 | cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) | 
| 144 | chuckv | 2164 | { | 
| 145 |  |  | int result; | 
| 146 | chuckv | 2215 |  | 
| 147 |  |  | result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); | 
| 148 |  |  |  | 
| 149 |  |  | if (result == EXIT_FAILURE) | 
| 150 |  |  | { | 
| 151 |  |  | cmdline_parser_free (args_info); | 
| 152 |  |  | exit (EXIT_FAILURE); | 
| 153 |  |  | } | 
| 154 | chuckv | 2164 |  | 
| 155 | chuckv | 2215 | return result; | 
| 156 |  |  | } | 
| 157 |  |  |  | 
| 158 |  |  | int | 
| 159 |  |  | cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) | 
| 160 |  |  | { | 
| 161 |  |  | int result = EXIT_SUCCESS; | 
| 162 |  |  |  | 
| 163 |  |  | if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) | 
| 164 |  |  | result = EXIT_FAILURE; | 
| 165 |  |  |  | 
| 166 | chuckv | 2164 | if (result == EXIT_FAILURE) | 
| 167 |  |  | { | 
| 168 |  |  | cmdline_parser_free (args_info); | 
| 169 |  |  | exit (EXIT_FAILURE); | 
| 170 |  |  | } | 
| 171 |  |  |  | 
| 172 |  |  | return result; | 
| 173 |  |  | } | 
| 174 |  |  |  | 
| 175 |  |  | int | 
| 176 | chuckv | 2215 | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) | 
| 177 |  |  | { | 
| 178 |  |  | int error = 0; | 
| 179 |  |  |  | 
| 180 |  |  | if (! args_info->length_given) | 
| 181 |  |  | { | 
| 182 |  |  | fprintf (stderr, "%s: '--length' option required%s\n", prog_name, (additional_error ? additional_error : "")); | 
| 183 |  |  | error = 1; | 
| 184 |  |  | } | 
| 185 |  |  | if (! args_info->width_given) | 
| 186 |  |  | { | 
| 187 |  |  | fprintf (stderr, "%s: '--width' option required%s\n", prog_name, (additional_error ? additional_error : "")); | 
| 188 |  |  | error = 1; | 
| 189 |  |  | } | 
| 190 |  |  | if (! args_info->latticeCnst_given) | 
| 191 |  |  | { | 
| 192 |  |  | fprintf (stderr, "%s: '--latticeCnst' option required%s\n", prog_name, (additional_error ? additional_error : "")); | 
| 193 |  |  | error = 1; | 
| 194 |  |  | } | 
| 195 |  |  |  | 
| 196 |  |  | return error; | 
| 197 |  |  | } | 
| 198 |  |  |  | 
| 199 |  |  | int | 
| 200 | chuckv | 2164 | 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) | 
| 201 |  |  | { | 
| 202 |  |  | int c;        /* Character of the parsed option.  */ | 
| 203 | chuckv | 2215 |  | 
| 204 | chuckv | 2164 | int error = 0; | 
| 205 |  |  | struct gengetopt_args_info local_args_info; | 
| 206 |  |  |  | 
| 207 |  |  | if (initialize) | 
| 208 |  |  | cmdline_parser_init (args_info); | 
| 209 |  |  |  | 
| 210 |  |  | cmdline_parser_init (&local_args_info); | 
| 211 |  |  |  | 
| 212 |  |  | optarg = 0; | 
| 213 |  |  | optind = 1; | 
| 214 |  |  | opterr = 1; | 
| 215 |  |  | optopt = '?'; | 
| 216 |  |  |  | 
| 217 |  |  | while (1) | 
| 218 |  |  | { | 
| 219 |  |  | int option_index = 0; | 
| 220 |  |  | char *stop_char; | 
| 221 |  |  |  | 
| 222 |  |  | static struct option long_options[] = { | 
| 223 |  |  | { "help",       0, NULL, 'h' }, | 
| 224 |  |  | { "version",    0, NULL, 'V' }, | 
| 225 |  |  | { "output",     1, NULL, 'o' }, | 
| 226 |  |  | { "latticetype",        1, NULL, 0 }, | 
| 227 |  |  | { "length",     1, NULL, 0 }, | 
| 228 |  |  | { "width",      1, NULL, 0 }, | 
| 229 |  |  | { "latticeCnst",        1, NULL, 0 }, | 
| 230 | chuckv | 2215 | { "genGeomview",        0, NULL, 0 }, | 
| 231 | chuckv | 2218 | { "twinnedCrystal",     0, NULL, 0 }, | 
| 232 | chuckv | 2164 | { NULL, 0, NULL, 0 } | 
| 233 |  |  | }; | 
| 234 |  |  |  | 
| 235 |  |  | stop_char = 0; | 
| 236 |  |  | c = getopt_long (argc, argv, "hVo:", long_options, &option_index); | 
| 237 |  |  |  | 
| 238 |  |  | if (c == -1) break;       /* Exit from `while (1)' loop.  */ | 
| 239 |  |  |  | 
| 240 |  |  | switch (c) | 
| 241 |  |  | { | 
| 242 |  |  | case 'h':       /* Print help and exit.  */ | 
| 243 |  |  | cmdline_parser_print_help (); | 
| 244 |  |  | exit (EXIT_SUCCESS); | 
| 245 |  |  |  | 
| 246 |  |  | case 'V':       /* Print version and exit.  */ | 
| 247 |  |  | cmdline_parser_print_version (); | 
| 248 |  |  | exit (EXIT_SUCCESS); | 
| 249 |  |  |  | 
| 250 |  |  | case 'o':       /* Output file name.  */ | 
| 251 |  |  | if (local_args_info.output_given) | 
| 252 |  |  | { | 
| 253 | chuckv | 2215 | fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); | 
| 254 | chuckv | 2164 | goto failure; | 
| 255 |  |  | } | 
| 256 |  |  | if (args_info->output_given && ! override) | 
| 257 |  |  | continue; | 
| 258 |  |  | local_args_info.output_given = 1; | 
| 259 |  |  | args_info->output_given = 1; | 
| 260 |  |  | if (args_info->output_arg) | 
| 261 |  |  | free (args_info->output_arg); /* free previous string */ | 
| 262 |  |  | args_info->output_arg = gengetopt_strdup (optarg); | 
| 263 |  |  | break; | 
| 264 |  |  |  | 
| 265 |  |  |  | 
| 266 |  |  | case 0: /* Long option with no short option */ | 
| 267 |  |  | /* Lattice type string. Valid types are fcc,hcp,bcc..  */ | 
| 268 |  |  | if (strcmp (long_options[option_index].name, "latticetype") == 0) | 
| 269 | chuckv | 2215 | { | 
| 270 |  |  | if (local_args_info.latticetype_given) | 
| 271 |  |  | { | 
| 272 |  |  | fprintf (stderr, "%s: `--latticetype' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); | 
| 273 |  |  | goto failure; | 
| 274 |  |  | } | 
| 275 |  |  | if (args_info->latticetype_given && ! override) | 
| 276 |  |  | continue; | 
| 277 |  |  | local_args_info.latticetype_given = 1; | 
| 278 |  |  | args_info->latticetype_given = 1; | 
| 279 |  |  | if (args_info->latticetype_arg) | 
| 280 |  |  | free (args_info->latticetype_arg); /* free previous string */ | 
| 281 |  |  | args_info->latticetype_arg = gengetopt_strdup (optarg); | 
| 282 |  |  | } | 
| 283 | chuckv | 2164 | /* length of nanorod in Angstroms.  */ | 
| 284 |  |  | else if (strcmp (long_options[option_index].name, "length") == 0) | 
| 285 | chuckv | 2215 | { | 
| 286 |  |  | if (local_args_info.length_given) | 
| 287 |  |  | { | 
| 288 |  |  | fprintf (stderr, "%s: `--length' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); | 
| 289 |  |  | goto failure; | 
| 290 |  |  | } | 
| 291 |  |  | if (args_info->length_given && ! override) | 
| 292 |  |  | continue; | 
| 293 |  |  | local_args_info.length_given = 1; | 
| 294 |  |  | args_info->length_given = 1; | 
| 295 |  |  | args_info->length_arg = strtod (optarg, NULL); | 
| 296 |  |  | } | 
| 297 | chuckv | 2164 | /* diameter  of nanorod in Angstroms.  */ | 
| 298 |  |  | else if (strcmp (long_options[option_index].name, "width") == 0) | 
| 299 | chuckv | 2215 | { | 
| 300 |  |  | if (local_args_info.width_given) | 
| 301 |  |  | { | 
| 302 |  |  | fprintf (stderr, "%s: `--width' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); | 
| 303 |  |  | goto failure; | 
| 304 |  |  | } | 
| 305 |  |  | if (args_info->width_given && ! override) | 
| 306 |  |  | continue; | 
| 307 |  |  | local_args_info.width_given = 1; | 
| 308 |  |  | args_info->width_given = 1; | 
| 309 |  |  | args_info->width_arg = strtod (optarg, NULL); | 
| 310 |  |  | } | 
| 311 | chuckv | 2164 | /* lattice spacing in Angstrons for cubic lattice.  */ | 
| 312 |  |  | else if (strcmp (long_options[option_index].name, "latticeCnst") == 0) | 
| 313 | chuckv | 2215 | { | 
| 314 |  |  | if (local_args_info.latticeCnst_given) | 
| 315 |  |  | { | 
| 316 |  |  | fprintf (stderr, "%s: `--latticeCnst' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); | 
| 317 |  |  | goto failure; | 
| 318 |  |  | } | 
| 319 |  |  | if (args_info->latticeCnst_given && ! override) | 
| 320 |  |  | continue; | 
| 321 |  |  | local_args_info.latticeCnst_given = 1; | 
| 322 |  |  | args_info->latticeCnst_given = 1; | 
| 323 |  |  | args_info->latticeCnst_arg = strtod (optarg, NULL); | 
| 324 |  |  | } | 
| 325 | chuckv | 2164 | /* generate a geomview file with the object geometry.  */ | 
| 326 |  |  | else if (strcmp (long_options[option_index].name, "genGeomview") == 0) | 
| 327 | chuckv | 2215 | { | 
| 328 |  |  | if (local_args_info.genGeomview_given) | 
| 329 |  |  | { | 
| 330 |  |  | fprintf (stderr, "%s: `--genGeomview' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); | 
| 331 |  |  | goto failure; | 
| 332 |  |  | } | 
| 333 |  |  | if (args_info->genGeomview_given && ! override) | 
| 334 |  |  | continue; | 
| 335 |  |  | local_args_info.genGeomview_given = 1; | 
| 336 |  |  | args_info->genGeomview_given = 1; | 
| 337 |  |  | args_info->genGeomview_flag = !(args_info->genGeomview_flag); | 
| 338 |  |  | } | 
| 339 | chuckv | 2218 | /* generate a twinned crystal nanorod.  */ | 
| 340 |  |  | else if (strcmp (long_options[option_index].name, "twinnedCrystal") == 0) | 
| 341 |  |  | { | 
| 342 |  |  | if (local_args_info.twinnedCrystal_given) | 
| 343 |  |  | { | 
| 344 |  |  | fprintf (stderr, "%s: `--twinnedCrystal' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); | 
| 345 |  |  | goto failure; | 
| 346 |  |  | } | 
| 347 |  |  | if (args_info->twinnedCrystal_given && ! override) | 
| 348 |  |  | continue; | 
| 349 |  |  | local_args_info.twinnedCrystal_given = 1; | 
| 350 |  |  | args_info->twinnedCrystal_given = 1; | 
| 351 |  |  | args_info->twinnedCrystal_flag = !(args_info->twinnedCrystal_flag); | 
| 352 |  |  | } | 
| 353 | chuckv | 2164 |  | 
| 354 |  |  | break; | 
| 355 |  |  | case '?':       /* Invalid option.  */ | 
| 356 |  |  | /* `getopt_long' already printed an error message.  */ | 
| 357 |  |  | goto failure; | 
| 358 |  |  |  | 
| 359 |  |  | default:        /* bug: option not considered.  */ | 
| 360 |  |  | fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); | 
| 361 |  |  | abort (); | 
| 362 |  |  | } /* switch */ | 
| 363 |  |  | } /* while */ | 
| 364 |  |  |  | 
| 365 |  |  |  | 
| 366 |  |  |  | 
| 367 |  |  | if (check_required) | 
| 368 |  |  | { | 
| 369 | chuckv | 2215 | error += cmdline_parser_required2 (args_info, argv[0], additional_error); | 
| 370 | chuckv | 2164 | } | 
| 371 |  |  |  | 
| 372 | chuckv | 2215 | cmdline_parser_free (&local_args_info); | 
| 373 | chuckv | 2164 |  | 
| 374 |  |  | if ( error ) | 
| 375 |  |  | return (EXIT_FAILURE); | 
| 376 |  |  |  | 
| 377 |  |  | if (optind < argc) | 
| 378 |  |  | { | 
| 379 |  |  | int i = 0 ; | 
| 380 | chuckv | 2215 |  | 
| 381 | chuckv | 2164 | args_info->inputs_num = argc - optind ; | 
| 382 | chuckv | 2215 | args_info->inputs = | 
| 383 | chuckv | 2164 | (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; | 
| 384 |  |  | while (optind < argc) | 
| 385 | chuckv | 2215 | args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; | 
| 386 | chuckv | 2164 | } | 
| 387 | chuckv | 2215 |  | 
| 388 | chuckv | 2164 | return 0; | 
| 389 |  |  |  | 
| 390 | chuckv | 2215 | failure: | 
| 391 |  |  |  | 
| 392 | chuckv | 2164 | cmdline_parser_free (&local_args_info); | 
| 393 |  |  | return (EXIT_FAILURE); | 
| 394 |  |  | } |