--- trunk/src/applications/dump2Xyz/Dump2XYZCmd.c 2004/09/28 23:24:25 12 +++ trunk/src/applications/dump2Xyz/Dump2XYZCmd.c 2010/05/10 17:28:26 1442 @@ -1,28 +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/program/gengetopt-2.11/src/gengetopt --file-name=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 "applications/dump2Xyz/Dump2XYZCmd.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) { @@ -33,35 +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(" -d, --dipole print the dipole moments (default=off)\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 molecules \n (default=off)\n"); - printf(" -r, --rigidbody add a pseudo COM atom to rigidbody (default=off)\n"); - printf(" -t, --watertype replace the atom type of water model (default=on)\n"); - printf(" -s, --ignore=atomtype ignore the atom types\n"); - printf(" --repeatX=INT The number of images to repeat in the x direction \n (default=`0')\n"); - printf(" --repeatY=INT The number of images to repeat in the y direction \n (default=`0')\n"); - printf(" --repeatZ=INT The number of images to repeat in the z direction \n (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,50 +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 i; /* Counter */ - struct ignore_list - { - char * ignore_arg; - struct ignore_list * next; - }; - struct ignore_list * ignore_list = NULL,* ignore_new = NULL; + return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); +} + +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); + } - int missing_required_options = 0; + return result; +} - 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->dipole_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->ignore_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->dipole_flag = 0;\ - 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->ignore_arg = NULL; \ - args_info->repeatX_arg = 0 ;\ - args_info->repeatY_arg = 0 ;\ - args_info->repeatZ_arg = 0 ;\ +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; } - clear_args(); +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; @@ -131,216 +443,356 @@ cmdline_parser (int argc, char * const *argv, struct g { "input", 1, NULL, 'i' }, { "output", 1, NULL, 'o' }, { "frame", 1, NULL, 'n' }, - { "dipole", 0, NULL, 'd' }, { "water", 0, NULL, 'w' }, { "periodicBox", 0, NULL, 'm' }, { "zconstraint", 0, NULL, 'z' }, { "rigidbody", 0, NULL, 'r' }, { "watertype", 0, NULL, 't' }, - { "ignore", 1, NULL, 's' }, + { "selection", 1, NULL, 's' }, + { "originsele", 1, NULL, 0 }, + { "refsele", 1, NULL, 0 }, { "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:dwmzrts:", 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 'd': /* print the dipole moments. */ - if (args_info->dipole_given) - { - fprintf (stderr, "%s: `--dipole' (`-d') option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); - } - args_info->dipole_given = 1; - args_info->dipole_flag = !(args_info->dipole_flag); - 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': /* ignore the atom types. */ - args_info->ignore_given++; - ignore_new = (struct ignore_list *) malloc (sizeof (struct ignore_list)); - ignore_new->next = ignore_list; - ignore_list = ignore_new; - ignore_new->ignore_arg = gengetopt_strdup (optarg); + case 's': /* general selection syntax. */ + if (local_args_info.selection_given) + { + 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 */ - /* The number of images to repeat in the x direction. */ - if (strcmp (long_options[option_index].name, "repeatX") == 0) + /* select origin. */ + if (strcmp (long_options[option_index].name, "originsele") == 0) { - if (args_info->repeatX_given) + if (local_args_info.originsele_given) { - fprintf (stderr, "%s: `--repeatX' 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); + 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 (local_args_info.refsele_given) + { + 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); + 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 (local_args_info.repeatX_given) + { + 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) - { - fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); - missing_required_options = 1; - } - if ( missing_required_options ) - exit (EXIT_FAILURE); - if (args_info->ignore_given) + if (check_required) { - args_info->ignore_arg = (char * *) malloc (args_info->ignore_given * sizeof (char *)); - for (i = 0; i < args_info->ignore_given; i++) - { - args_info->ignore_arg [i] = ignore_list->ignore_arg; - ignore_list = ignore_list->next; - } + error += cmdline_parser_required2 (args_info, argv[0], additional_error); } - + + cmdline_parser_release (&local_args_info); + + if ( error ) + return (EXIT_FAILURE); + return 0; + +failure: + + cmdline_parser_release (&local_args_info); + return (EXIT_FAILURE); }