--- trunk/src/applications/dump2Xyz/Dump2XYZCmd.c 2005/03/09 18:46:16 415 +++ trunk/src/applications/dump2Xyz/Dump2XYZCmd.c 2010/05/10 17:28:26 1442 @@ -1,27 +1,97 @@ /* - File autogenerated by gengetopt version 2.11 + File autogenerated by gengetopt version 2.15 generated with the following command: - /home/maul/gezelter/tim/bin/gengetopt -F Dump2XYZCmd + gengetopt -i Dump2XYZ.ggo -F Dump2XYZCmd The developers of gengetopt consider the fixed text that goes in all gengetopt output files to be in the public domain: we make no copyright claims on it. */ - -#include -#include -#include - /* If we use autoconf. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include +#include +#include + #include "getopt.h" #include "Dump2XYZCmd.h" +static +void clear_given (struct gengetopt_args_info *args_info); +static +void clear_args (struct gengetopt_args_info *args_info); + +static int +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); + +static int +cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); + +static char * +gengetopt_strdup (const char *s); + +static +void clear_given (struct gengetopt_args_info *args_info) +{ + args_info->help_given = 0 ; + args_info->version_given = 0 ; + args_info->input_given = 0 ; + args_info->output_given = 0 ; + args_info->frame_given = 0 ; + args_info->water_given = 0 ; + args_info->periodicBox_given = 0 ; + args_info->zconstraint_given = 0 ; + args_info->rigidbody_given = 0 ; + args_info->watertype_given = 0 ; + args_info->selection_given = 0 ; + args_info->originsele_given = 0 ; + args_info->refsele_given = 0 ; + args_info->repeatX_given = 0 ; + args_info->repeatY_given = 0 ; + args_info->repeatZ_given = 0 ; + args_info->gb_given = 0 ; + args_info->basetype_given = 0 ; + args_info->printPosOnly_given = 0 ; +} + +static +void clear_args (struct gengetopt_args_info *args_info) +{ + args_info->input_arg = NULL; + args_info->input_orig = NULL; + args_info->output_arg = NULL; + args_info->output_orig = NULL; + args_info->frame_arg = 1; + args_info->frame_orig = NULL; + args_info->water_flag = 0; + args_info->periodicBox_flag = 0; + args_info->zconstraint_flag = 0; + args_info->rigidbody_flag = 0; + args_info->watertype_flag = 1; + args_info->selection_arg = NULL; + args_info->selection_orig = NULL; + args_info->originsele_arg = NULL; + args_info->originsele_orig = NULL; + args_info->refsele_arg = NULL; + args_info->refsele_orig = NULL; + args_info->repeatX_arg = 0; + args_info->repeatX_orig = NULL; + args_info->repeatY_arg = 0; + args_info->repeatY_orig = NULL; + args_info->repeatZ_arg = 0; + args_info->repeatZ_orig = NULL; + args_info->gb_arg = NULL; + args_info->gb_orig = NULL; + args_info->basetype_flag = 0; + args_info->printPosOnly_flag = 0; + +} + void cmdline_parser_print_version (void) { @@ -32,36 +102,259 @@ cmdline_parser_print_help (void) cmdline_parser_print_help (void) { cmdline_parser_print_version (); - printf("\n" - "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE); - printf("\n"); - printf(" -h, --help Print help and exit\n"); - printf(" -V, --version Print version and exit\n"); - printf(" -i, --input=filename input dump file\n"); - printf(" -o, --output=filename output file name\n"); - printf(" -n, --frame=INT print every n frame (default=`1')\n"); - printf(" -w, --water skip the the waters (default=off)\n"); - printf(" -m, --periodicBox map to the periodic box (default=off)\n"); - printf(" -z, --zconstraint replace the atom types of zconstraint \n molecules (default=off)\n"); - printf(" -r, --rigidbody add a pseudo COM atom to rigidbody \n (default=off)\n"); - printf(" -t, --watertype replace the atom type of water model \n (default=on)\n"); - printf(" -s, --selection=selection script general selection syntax\n"); - printf(" --originsele=selection script select origin\n"); - printf(" --refsele=selection script select reference\n"); - printf(" --repeatX=INT The number of images to repeat in the x \n direction (default=`0')\n"); - printf(" --repeatY=INT The number of images to repeat in the y \n direction (default=`0')\n"); - printf(" --repeatZ=INT The number of images to repeat in the z \n direction (default=`0')\n"); + printf("\nUsage: Dump2XYZ [OPTIONS]...\n\n"); + printf("%s\n"," -h, --help Print help and exit"); + printf("%s\n"," -V, --version Print version and exit"); + printf("%s\n"," -i, --input=filename input dump file"); + printf("%s\n"," -o, --output=filename output file name"); + printf("%s\n"," -n, --frame=INT print every n frame (default=`1')"); + printf("%s\n"," -w, --water skip the the waters (default=off)"); + printf("%s\n"," -m, --periodicBox map to the periodic box (default=off)"); + printf("%s\n"," -z, --zconstraint replace the atom types of zconstraint molecules \n (default=off)"); + printf("%s\n"," -r, --rigidbody add a pseudo COM atom to rigidbody \n (default=off)"); + printf("%s\n"," -t, --watertype replace the atom type of water model \n (default=on)"); + printf("%s\n"," -s, --selection=selection script\n general selection syntax"); + printf("%s\n"," --originsele=selection script\n select origin"); + printf("%s\n"," --refsele=selection script\n select reference"); + printf("%s\n"," --repeatX=INT The number of images to repeat in the x \n direction (default=`0')"); + printf("%s\n"," --repeatY=INT The number of images to repeat in the y \n direction (default=`0')"); + printf("%s\n"," --repeatZ=INT The number of images to repeat in the z \n direction (default=`0')"); + printf("%s\n"," --gb=atomtype Replace the Gay-Berne atom with four linear \n atoms"); + printf("%s\n"," -b, --basetype Convert to base atom type (default=off)"); + printf("%s\n"," --printPosOnly Print only positions in xyz file (default=off)"); + } +void +cmdline_parser_init (struct gengetopt_args_info *args_info) +{ + clear_given (args_info); + clear_args (args_info); +} -static char *gengetopt_strdup (const char *s); +static void +cmdline_parser_release (struct gengetopt_args_info *args_info) +{ + + if (args_info->input_arg) + { + free (args_info->input_arg); /* free previous argument */ + args_info->input_arg = 0; + } + if (args_info->input_orig) + { + free (args_info->input_orig); /* free previous argument */ + args_info->input_orig = 0; + } + if (args_info->output_arg) + { + free (args_info->output_arg); /* free previous argument */ + args_info->output_arg = 0; + } + if (args_info->output_orig) + { + free (args_info->output_orig); /* free previous argument */ + args_info->output_orig = 0; + } + if (args_info->frame_orig) + { + free (args_info->frame_orig); /* free previous argument */ + args_info->frame_orig = 0; + } + if (args_info->selection_arg) + { + free (args_info->selection_arg); /* free previous argument */ + args_info->selection_arg = 0; + } + if (args_info->selection_orig) + { + free (args_info->selection_orig); /* free previous argument */ + args_info->selection_orig = 0; + } + if (args_info->originsele_arg) + { + free (args_info->originsele_arg); /* free previous argument */ + args_info->originsele_arg = 0; + } + if (args_info->originsele_orig) + { + free (args_info->originsele_orig); /* free previous argument */ + args_info->originsele_orig = 0; + } + if (args_info->refsele_arg) + { + free (args_info->refsele_arg); /* free previous argument */ + args_info->refsele_arg = 0; + } + if (args_info->refsele_orig) + { + free (args_info->refsele_orig); /* free previous argument */ + args_info->refsele_orig = 0; + } + if (args_info->repeatX_orig) + { + free (args_info->repeatX_orig); /* free previous argument */ + args_info->repeatX_orig = 0; + } + if (args_info->repeatY_orig) + { + free (args_info->repeatY_orig); /* free previous argument */ + args_info->repeatY_orig = 0; + } + if (args_info->repeatZ_orig) + { + free (args_info->repeatZ_orig); /* free previous argument */ + args_info->repeatZ_orig = 0; + } + if (args_info->gb_arg) + { + free (args_info->gb_arg); /* free previous argument */ + args_info->gb_arg = 0; + } + if (args_info->gb_orig) + { + free (args_info->gb_orig); /* free previous argument */ + args_info->gb_orig = 0; + } + + 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->input_given) { + if (args_info->input_orig) { + fprintf(outfile, "%s=\"%s\"\n", "input", args_info->input_orig); + } else { + fprintf(outfile, "%s\n", "input"); + } + } + 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->frame_given) { + if (args_info->frame_orig) { + fprintf(outfile, "%s=\"%s\"\n", "frame", args_info->frame_orig); + } else { + fprintf(outfile, "%s\n", "frame"); + } + } + if (args_info->water_given) { + fprintf(outfile, "%s\n", "water"); + } + if (args_info->periodicBox_given) { + fprintf(outfile, "%s\n", "periodicBox"); + } + if (args_info->zconstraint_given) { + fprintf(outfile, "%s\n", "zconstraint"); + } + if (args_info->rigidbody_given) { + fprintf(outfile, "%s\n", "rigidbody"); + } + if (args_info->watertype_given) { + fprintf(outfile, "%s\n", "watertype"); + } + if (args_info->selection_given) { + if (args_info->selection_orig) { + fprintf(outfile, "%s=\"%s\"\n", "selection", args_info->selection_orig); + } else { + fprintf(outfile, "%s\n", "selection"); + } + } + if (args_info->originsele_given) { + if (args_info->originsele_orig) { + fprintf(outfile, "%s=\"%s\"\n", "originsele", args_info->originsele_orig); + } else { + fprintf(outfile, "%s\n", "originsele"); + } + } + if (args_info->refsele_given) { + if (args_info->refsele_orig) { + fprintf(outfile, "%s=\"%s\"\n", "refsele", args_info->refsele_orig); + } else { + fprintf(outfile, "%s\n", "refsele"); + } + } + if (args_info->repeatX_given) { + if (args_info->repeatX_orig) { + fprintf(outfile, "%s=\"%s\"\n", "repeatX", args_info->repeatX_orig); + } else { + fprintf(outfile, "%s\n", "repeatX"); + } + } + if (args_info->repeatY_given) { + if (args_info->repeatY_orig) { + fprintf(outfile, "%s=\"%s\"\n", "repeatY", args_info->repeatY_orig); + } else { + fprintf(outfile, "%s\n", "repeatY"); + } + } + if (args_info->repeatZ_given) { + if (args_info->repeatZ_orig) { + fprintf(outfile, "%s=\"%s\"\n", "repeatZ", args_info->repeatZ_orig); + } else { + fprintf(outfile, "%s\n", "repeatZ"); + } + } + if (args_info->gb_given) { + if (args_info->gb_orig) { + fprintf(outfile, "%s=\"%s\"\n", "gb", args_info->gb_orig); + } else { + fprintf(outfile, "%s\n", "gb"); + } + } + if (args_info->basetype_given) { + fprintf(outfile, "%s\n", "basetype"); + } + if (args_info->printPosOnly_given) { + fprintf(outfile, "%s\n", "printPosOnly"); + } + + 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 * gengetopt_strdup (const char *s) { - char *result = (char*)malloc(strlen(s) + 1); + char *result = NULL; + if (!s) + return result; + + result = (char*)malloc(strlen(s) + 1); if (result == (char*)0) return (char*)0; strcpy(result, s); @@ -71,44 +364,69 @@ cmdline_parser (int argc, char * const *argv, struct g int cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) { - int c; /* Character of the parsed option. */ - int missing_required_options = 0; + return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); +} - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->input_given = 0 ; - args_info->output_given = 0 ; - args_info->frame_given = 0 ; - args_info->water_given = 0 ; - args_info->periodicBox_given = 0 ; - args_info->zconstraint_given = 0 ; - args_info->rigidbody_given = 0 ; - args_info->watertype_given = 0 ; - args_info->selection_given = 0 ; - args_info->originsele_given = 0 ; - args_info->refsele_given = 0 ; - args_info->repeatX_given = 0 ; - args_info->repeatY_given = 0 ; - args_info->repeatZ_given = 0 ; -#define clear_args() { \ - args_info->input_arg = NULL; \ - args_info->output_arg = NULL; \ - args_info->frame_arg = 1 ;\ - args_info->water_flag = 0;\ - args_info->periodicBox_flag = 0;\ - args_info->zconstraint_flag = 0;\ - args_info->rigidbody_flag = 0;\ - args_info->watertype_flag = 1;\ - args_info->selection_arg = NULL; \ - args_info->originsele_arg = NULL; \ - args_info->refsele_arg = NULL; \ - args_info->repeatX_arg = 0 ;\ - args_info->repeatY_arg = 0 ;\ - args_info->repeatZ_arg = 0 ;\ +int +cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) +{ + int result; + + result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); + + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; } - clear_args(); +int +cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) +{ + int result = EXIT_SUCCESS; + if (cmdline_parser_required2(args_info, prog_name, NULL) > 0) + result = EXIT_FAILURE; + + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) +{ + int error = 0; + + if (! args_info->input_given) + { + fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); + error = 1; + } + + return error; +} + +int +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) +{ + int c; /* Character of the parsed option. */ + + int error = 0; + struct gengetopt_args_info local_args_info; + + if (initialize) + cmdline_parser_init (args_info); + + cmdline_parser_init (&local_args_info); + optarg = 0; optind = 1; opterr = 1; @@ -136,216 +454,345 @@ cmdline_parser (int argc, char * const *argv, struct g { "repeatX", 1, NULL, 0 }, { "repeatY", 1, NULL, 0 }, { "repeatZ", 1, NULL, 0 }, + { "gb", 1, NULL, 0 }, + { "basetype", 0, NULL, 'b' }, + { "printPosOnly", 0, NULL, 0 }, { NULL, 0, NULL, 0 } }; stop_char = 0; - c = getopt_long (argc, argv, "hVi:o:n:wmzrts:", long_options, &option_index); + c = getopt_long (argc, argv, "hVi:o:n:wmzrts:b", long_options, &option_index); if (c == -1) break; /* Exit from `while (1)' loop. */ switch (c) { case 'h': /* Print help and exit. */ - clear_args (); cmdline_parser_print_help (); + cmdline_parser_free (&local_args_info); exit (EXIT_SUCCESS); case 'V': /* Print version and exit. */ - clear_args (); cmdline_parser_print_version (); + cmdline_parser_free (&local_args_info); exit (EXIT_SUCCESS); case 'i': /* input dump file. */ - if (args_info->input_given) + if (local_args_info.input_given) { - fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->input_given && ! override) + continue; + local_args_info.input_given = 1; args_info->input_given = 1; + if (args_info->input_arg) + free (args_info->input_arg); /* free previous string */ args_info->input_arg = gengetopt_strdup (optarg); + if (args_info->input_orig) + free (args_info->input_orig); /* free previous string */ + args_info->input_orig = gengetopt_strdup (optarg); break; case 'o': /* output file name. */ - if (args_info->output_given) + if (local_args_info.output_given) { - fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->output_given && ! override) + continue; + local_args_info.output_given = 1; args_info->output_given = 1; + 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 'n': /* print every n frame. */ - if (args_info->frame_given) + if (local_args_info.frame_given) { - fprintf (stderr, "%s: `--frame' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--frame' (`-n') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->frame_given && ! override) + continue; + local_args_info.frame_given = 1; args_info->frame_given = 1; - args_info->frame_arg = strtol (optarg,&stop_char,0); + args_info->frame_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->frame_orig) + free (args_info->frame_orig); /* free previous string */ + args_info->frame_orig = gengetopt_strdup (optarg); break; case 'w': /* skip the the waters. */ - if (args_info->water_given) + if (local_args_info.water_given) { - fprintf (stderr, "%s: `--water' (`-w') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--water' (`-w') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->water_given && ! override) + continue; + local_args_info.water_given = 1; args_info->water_given = 1; args_info->water_flag = !(args_info->water_flag); break; case 'm': /* map to the periodic box. */ - if (args_info->periodicBox_given) + if (local_args_info.periodicBox_given) { - fprintf (stderr, "%s: `--periodicBox' (`-m') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--periodicBox' (`-m') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->periodicBox_given && ! override) + continue; + local_args_info.periodicBox_given = 1; args_info->periodicBox_given = 1; args_info->periodicBox_flag = !(args_info->periodicBox_flag); break; case 'z': /* replace the atom types of zconstraint molecules. */ - if (args_info->zconstraint_given) + if (local_args_info.zconstraint_given) { - fprintf (stderr, "%s: `--zconstraint' (`-z') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--zconstraint' (`-z') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->zconstraint_given && ! override) + continue; + local_args_info.zconstraint_given = 1; args_info->zconstraint_given = 1; args_info->zconstraint_flag = !(args_info->zconstraint_flag); break; case 'r': /* add a pseudo COM atom to rigidbody. */ - if (args_info->rigidbody_given) + if (local_args_info.rigidbody_given) { - fprintf (stderr, "%s: `--rigidbody' (`-r') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--rigidbody' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->rigidbody_given && ! override) + continue; + local_args_info.rigidbody_given = 1; args_info->rigidbody_given = 1; args_info->rigidbody_flag = !(args_info->rigidbody_flag); break; case 't': /* replace the atom type of water model. */ - if (args_info->watertype_given) + if (local_args_info.watertype_given) { - fprintf (stderr, "%s: `--watertype' (`-t') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--watertype' (`-t') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->watertype_given && ! override) + continue; + local_args_info.watertype_given = 1; args_info->watertype_given = 1; args_info->watertype_flag = !(args_info->watertype_flag); break; case 's': /* general selection syntax. */ - if (args_info->selection_given) + if (local_args_info.selection_given) { - fprintf (stderr, "%s: `--selection' (`-s') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--selection' (`-s') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->selection_given && ! override) + continue; + local_args_info.selection_given = 1; args_info->selection_given = 1; + if (args_info->selection_arg) + free (args_info->selection_arg); /* free previous string */ args_info->selection_arg = gengetopt_strdup (optarg); + if (args_info->selection_orig) + free (args_info->selection_orig); /* free previous string */ + args_info->selection_orig = gengetopt_strdup (optarg); break; + case 'b': /* Convert to base atom type. */ + if (local_args_info.basetype_given) + { + fprintf (stderr, "%s: `--basetype' (`-b') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->basetype_given && ! override) + continue; + local_args_info.basetype_given = 1; + args_info->basetype_given = 1; + args_info->basetype_flag = !(args_info->basetype_flag); + break; + case 0: /* Long option with no short option */ /* select origin. */ if (strcmp (long_options[option_index].name, "originsele") == 0) { - if (args_info->originsele_given) + if (local_args_info.originsele_given) { - fprintf (stderr, "%s: `--originsele' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--originsele' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->originsele_given && ! override) + continue; + local_args_info.originsele_given = 1; args_info->originsele_given = 1; + if (args_info->originsele_arg) + free (args_info->originsele_arg); /* free previous string */ args_info->originsele_arg = gengetopt_strdup (optarg); - break; + if (args_info->originsele_orig) + free (args_info->originsele_orig); /* free previous string */ + args_info->originsele_orig = gengetopt_strdup (optarg); } - /* select reference. */ else if (strcmp (long_options[option_index].name, "refsele") == 0) { - if (args_info->refsele_given) + if (local_args_info.refsele_given) { - fprintf (stderr, "%s: `--refsele' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--refsele' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->refsele_given && ! override) + continue; + local_args_info.refsele_given = 1; args_info->refsele_given = 1; + if (args_info->refsele_arg) + free (args_info->refsele_arg); /* free previous string */ args_info->refsele_arg = gengetopt_strdup (optarg); - break; + if (args_info->refsele_orig) + free (args_info->refsele_orig); /* free previous string */ + args_info->refsele_orig = gengetopt_strdup (optarg); } - /* The number of images to repeat in the x direction. */ else if (strcmp (long_options[option_index].name, "repeatX") == 0) { - if (args_info->repeatX_given) + if (local_args_info.repeatX_given) { - fprintf (stderr, "%s: `--repeatX' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--repeatX' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->repeatX_given && ! override) + continue; + local_args_info.repeatX_given = 1; args_info->repeatX_given = 1; - args_info->repeatX_arg = strtol (optarg,&stop_char,0); - break; + args_info->repeatX_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->repeatX_orig) + free (args_info->repeatX_orig); /* free previous string */ + args_info->repeatX_orig = gengetopt_strdup (optarg); } - /* The number of images to repeat in the y direction. */ else if (strcmp (long_options[option_index].name, "repeatY") == 0) { - if (args_info->repeatY_given) + if (local_args_info.repeatY_given) { - fprintf (stderr, "%s: `--repeatY' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--repeatY' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->repeatY_given && ! override) + continue; + local_args_info.repeatY_given = 1; args_info->repeatY_given = 1; - args_info->repeatY_arg = strtol (optarg,&stop_char,0); - break; + args_info->repeatY_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->repeatY_orig) + free (args_info->repeatY_orig); /* free previous string */ + args_info->repeatY_orig = gengetopt_strdup (optarg); } - /* The number of images to repeat in the z direction. */ else if (strcmp (long_options[option_index].name, "repeatZ") == 0) { - if (args_info->repeatZ_given) + if (local_args_info.repeatZ_given) { - fprintf (stderr, "%s: `--repeatZ' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--repeatZ' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->repeatZ_given && ! override) + continue; + local_args_info.repeatZ_given = 1; args_info->repeatZ_given = 1; - args_info->repeatZ_arg = strtol (optarg,&stop_char,0); - break; + args_info->repeatZ_arg = strtol (optarg, &stop_char, 0); + if (!(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg); + goto failure; + } + if (args_info->repeatZ_orig) + free (args_info->repeatZ_orig); /* free previous string */ + args_info->repeatZ_orig = gengetopt_strdup (optarg); } + /* Replace the Gay-Berne atom with four linear atoms. */ + else if (strcmp (long_options[option_index].name, "gb") == 0) + { + if (local_args_info.gb_given) + { + fprintf (stderr, "%s: `--gb' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->gb_given && ! override) + continue; + local_args_info.gb_given = 1; + args_info->gb_given = 1; + if (args_info->gb_arg) + free (args_info->gb_arg); /* free previous string */ + args_info->gb_arg = gengetopt_strdup (optarg); + if (args_info->gb_orig) + free (args_info->gb_orig); /* free previous string */ + args_info->gb_orig = gengetopt_strdup (optarg); + } + /* Print only positions in xyz file. */ + else if (strcmp (long_options[option_index].name, "printPosOnly") == 0) + { + if (local_args_info.printPosOnly_given) + { + fprintf (stderr, "%s: `--printPosOnly' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->printPosOnly_given && ! override) + continue; + local_args_info.printPosOnly_given = 1; + args_info->printPosOnly_given = 1; + args_info->printPosOnly_flag = !(args_info->printPosOnly_flag); + } - + break; case '?': /* Invalid option. */ /* `getopt_long' already printed an error message. */ - exit (EXIT_FAILURE); + goto failure; default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); + fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); abort (); } /* switch */ } /* while */ - if (! args_info->input_given) + + if (check_required) { - fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); - missing_required_options = 1; + error += cmdline_parser_required2 (args_info, argv[0], additional_error); } - if ( missing_required_options ) - exit (EXIT_FAILURE); + cmdline_parser_release (&local_args_info); + + if ( error ) + return (EXIT_FAILURE); + return 0; + +failure: + + cmdline_parser_release (&local_args_info); + return (EXIT_FAILURE); }