--- trunk/src/applications/hydrodynamics/HydroCmd.c 2006/02/23 23:16:43 892 +++ trunk/src/applications/hydrodynamics/HydroCmd.c 2006/04/17 21:49:12 938 @@ -1,27 +1,64 @@ /* - File autogenerated by gengetopt version 2.11 + File autogenerated by gengetopt version 2.16 generated with the following command: - /home/maul/gezelter/tim/program/gengetopt-2.11/src/gengetopt -F HydroCmd + gengetopt -F HydroCmd 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 "HydroCmd.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->model_given = 0 ; + args_info->beads_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 = gengetopt_strdup ("hydro"); + args_info->output_orig = NULL; + args_info->model_arg = NULL; + args_info->model_orig = NULL; + args_info->beads_flag = 0; + +} + void cmdline_parser_print_version (void) { @@ -32,28 +69,129 @@ 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=STRING output file prefix (default=`hydro')\n"); - printf(" --viscosity=DOUBLE viscosity of solvent\n"); - printf(" --temperature=DOUBLE temperature of the system\n"); - printf(" --sigma=DOUBLE diameter of beads(use with rough shell model)\n"); - printf(" --model=STRING hydrodynamics model (support RoughShell and \n BeadModel)\n"); + printf("\nUsage: Hydro [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=STRING output file prefix (default=`hydro')"); + printf("%s\n"," --model=STRING hydrodynamics model (support RoughShell and BeadModel)"); + printf("%s\n"," -b, --beads generate the beads only, hydrodynamics will be \n performed (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->model_arg) + { + free (args_info->model_arg); /* free previous argument */ + args_info->model_arg = 0; + } + if (args_info->model_orig) + { + free (args_info->model_orig); /* free previous argument */ + args_info->model_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->model_given) { + if (args_info->model_orig) { + fprintf(outfile, "%s=\"%s\"\n", "model", args_info->model_orig); + } else { + fprintf(outfile, "%s\n", "model"); + } + } + if (args_info->beads_given) { + fprintf(outfile, "%s\n", "beads"); + } + + 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); @@ -63,27 +201,77 @@ 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->viscosity_given = 0 ; - args_info->temperature_given = 0 ; - args_info->sigma_given = 0 ; - args_info->model_given = 0 ; -#define clear_args() { \ - args_info->input_arg = NULL; \ - args_info->output_arg = gengetopt_strdup("hydro") ;\ - args_info->model_arg = NULL; \ +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; + } + if (! args_info->model_given) + { + fprintf (stderr, "%s: '--model' 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); + printf("\n%s\n", "\n+----------------------------------------------------------------------+ \n| ____ ____ ____ _____ ______ The OpenSource, Object-oriented | \n| / __ \\/ __ \\/ __ \\/ ___// ____/ Parallel Simulation Engine. | \n| / / / / / / / /_/ /\\__ \\/ __/ | \n| / /_/ / /_/ / ____/___/ / /___ Copyright 2004-2006 by the | \n| \\____/\\____/_/ /____/_____/ University of Notre Dame. | \n| | \n| http://www.oopse.org |\n| | \n| OOPSE is an OpenScience project. All source code is available for |\n| any use subject to only one condition: | \n| |\n| Any published work resulting from the use of this code must cite the | \n| following paper: M. A. Meineke, C. F. Vardeman II, T. Lin, | \n| C. J. Fennell, and J. D. Gezelter, | \n| J. Comput. Chem. 26, pp. 252-271 (2005). | \n+----------------------------------------------------------------------+"); + optarg = 0; - optind = 1; + optind = 0; opterr = 1; optopt = '?'; @@ -97,146 +285,127 @@ cmdline_parser (int argc, char * const *argv, struct g { "version", 0, NULL, 'V' }, { "input", 1, NULL, 'i' }, { "output", 1, NULL, 'o' }, - { "viscosity", 1, NULL, 0 }, - { "temperature", 1, NULL, 0 }, - { "sigma", 1, NULL, 0 }, { "model", 1, NULL, 0 }, + { "beads", 0, NULL, 'b' }, { NULL, 0, NULL, 0 } }; stop_char = 0; - c = getopt_long (argc, argv, "hVi:o:", long_options, &option_index); + c = getopt_long (argc, argv, "hVi:o: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 prefix. */ - 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 default string */ + 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 'b': /* generate the beads only, hydrodynamics will be performed. */ + if (local_args_info.beads_given) + { + fprintf (stderr, "%s: `--beads' (`-b') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->beads_given && ! override) + continue; + local_args_info.beads_given = 1; + args_info->beads_given = 1; + args_info->beads_flag = !(args_info->beads_flag); + break; + case 0: /* Long option with no short option */ - /* viscosity of solvent. */ - if (strcmp (long_options[option_index].name, "viscosity") == 0) - { - if (args_info->viscosity_given) - { - fprintf (stderr, "%s: `--viscosity' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); - } - args_info->viscosity_given = 1; - args_info->viscosity_arg = strtod (optarg, NULL); - break; - } - - /* temperature of the system. */ - else if (strcmp (long_options[option_index].name, "temperature") == 0) - { - if (args_info->temperature_given) - { - fprintf (stderr, "%s: `--temperature' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); - } - args_info->temperature_given = 1; - args_info->temperature_arg = strtod (optarg, NULL); - break; - } - - /* diameter of beads(use with rough shell model). */ - else if (strcmp (long_options[option_index].name, "sigma") == 0) - { - if (args_info->sigma_given) - { - fprintf (stderr, "%s: `--sigma' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); - } - args_info->sigma_given = 1; - args_info->sigma_arg = strtod (optarg, NULL); - break; - } - /* hydrodynamics model (support RoughShell and BeadModel). */ - else if (strcmp (long_options[option_index].name, "model") == 0) + if (strcmp (long_options[option_index].name, "model") == 0) { - if (args_info->model_given) + if (local_args_info.model_given) { - fprintf (stderr, "%s: `--model' option given more than once\n", CMDLINE_PARSER_PACKAGE); - clear_args (); - exit (EXIT_FAILURE); + fprintf (stderr, "%s: `--model' option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; } + if (args_info->model_given && ! override) + continue; + local_args_info.model_given = 1; args_info->model_given = 1; + if (args_info->model_arg) + free (args_info->model_arg); /* free previous string */ args_info->model_arg = gengetopt_strdup (optarg); - break; + if (args_info->model_orig) + free (args_info->model_orig); /* free previous string */ + args_info->model_orig = gengetopt_strdup (optarg); } - + 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 (! args_info->viscosity_given) - { - fprintf (stderr, "%s: '--viscosity' option required\n", CMDLINE_PARSER_PACKAGE); - missing_required_options = 1; - } - if (! args_info->temperature_given) - { - fprintf (stderr, "%s: '--temperature' option required\n", CMDLINE_PARSER_PACKAGE); - missing_required_options = 1; - } - if (! args_info->model_given) - { - fprintf (stderr, "%s: '--model' option required\n", CMDLINE_PARSER_PACKAGE); - missing_required_options = 1; - } - if ( missing_required_options ) - exit (EXIT_FAILURE); + cmdline_parser_release (&local_args_info); + + if ( error ) + goto failure; + return 0; + +failure: + + cmdline_parser_print_help (); + cmdline_parser_release (&local_args_info); + return (EXIT_FAILURE); }