| 1 | /* | 
| 2 | File autogenerated by gengetopt version 2.22.4 | 
| 3 | generated with the following command: | 
| 4 | gengetopt --file-name=DynamicPropsCmd --unamed-opts | 
| 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 | #ifndef FIX_UNUSED | 
| 21 | #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ | 
| 22 | #endif | 
| 23 |  | 
| 24 | #ifdef WIN32 | 
| 25 | #include "utils/wingetopt.h" | 
| 26 | #else | 
| 27 | #include <getopt.h> | 
| 28 | #endif | 
| 29 |  | 
| 30 | #include "DynamicPropsCmd.h" | 
| 31 |  | 
| 32 | const char *gengetopt_args_info_purpose = ""; | 
| 33 |  | 
| 34 | const char *gengetopt_args_info_usage = "Usage: DynamicProps [OPTIONS]... [FILES]..."; | 
| 35 |  | 
| 36 | const char *gengetopt_args_info_description = ""; | 
| 37 |  | 
| 38 | const char *gengetopt_args_info_help[] = { | 
| 39 | "  -h, --help                    Print help and exit", | 
| 40 | "  -V, --version                 Print version and exit", | 
| 41 | "  -i, --input=filename          input dump file", | 
| 42 | "  -o, --output=filename         output file name", | 
| 43 | "      --sele1=selection script  select first stuntdouble set", | 
| 44 | "      --sele2=selection script  select second stuntdouble set (if sele2 is not \n                                  set, use script from sele1)", | 
| 45 | "      --order=INT               Lengendre Polynomial Order", | 
| 46 | "  -m, --memory=memory specification\n                                Available memory (defaults to 2G)  \n                                  (default=`2G')", | 
| 47 | "\n Group: dynamicProps\n   an option of this group is required", | 
| 48 | "  -s, --selecorr                selection correlation function", | 
| 49 | "  -r, --rcorr                   rmsd", | 
| 50 | "  -v, --vcorr                   velocity correlation function", | 
| 51 | "  -d, --dcorr                   dipole correlation function", | 
| 52 | "  -l, --lcorr                   Lengendre correlation function", | 
| 53 | "  -M, --sdcorr                  System dipole correlation function", | 
| 54 | "      --r_rcorr                 Radial rmsd", | 
| 55 | "      --thetacorr               Angular rmsd", | 
| 56 | "      --drcorr                  Directional rmsd for particles with unit \n                                  vectors", | 
| 57 | "      --helfandEcorr            Helfand moment for thermal conductvity", | 
| 58 | "  -p, --momentum                Helfand momentum for viscosity", | 
| 59 | "      --stresscorr              Stress tensor correlation function", | 
| 60 | 0 | 
| 61 | }; | 
| 62 |  | 
| 63 | typedef enum {ARG_NO | 
| 64 | , ARG_STRING | 
| 65 | , ARG_INT | 
| 66 | } cmdline_parser_arg_type; | 
| 67 |  | 
| 68 | static | 
| 69 | void clear_given (struct gengetopt_args_info *args_info); | 
| 70 | static | 
| 71 | void clear_args (struct gengetopt_args_info *args_info); | 
| 72 |  | 
| 73 | static int | 
| 74 | cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, | 
| 75 | struct cmdline_parser_params *params, const char *additional_error); | 
| 76 |  | 
| 77 | static int | 
| 78 | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); | 
| 79 |  | 
| 80 | static char * | 
| 81 | gengetopt_strdup (const char *s); | 
| 82 |  | 
| 83 | static | 
| 84 | void clear_given (struct gengetopt_args_info *args_info) | 
| 85 | { | 
| 86 | args_info->help_given = 0 ; | 
| 87 | args_info->version_given = 0 ; | 
| 88 | args_info->input_given = 0 ; | 
| 89 | args_info->output_given = 0 ; | 
| 90 | args_info->sele1_given = 0 ; | 
| 91 | args_info->sele2_given = 0 ; | 
| 92 | args_info->order_given = 0 ; | 
| 93 | args_info->memory_given = 0 ; | 
| 94 | args_info->selecorr_given = 0 ; | 
| 95 | args_info->rcorr_given = 0 ; | 
| 96 | args_info->vcorr_given = 0 ; | 
| 97 | args_info->dcorr_given = 0 ; | 
| 98 | args_info->lcorr_given = 0 ; | 
| 99 | args_info->sdcorr_given = 0 ; | 
| 100 | args_info->r_rcorr_given = 0 ; | 
| 101 | args_info->thetacorr_given = 0 ; | 
| 102 | args_info->drcorr_given = 0 ; | 
| 103 | args_info->helfandEcorr_given = 0 ; | 
| 104 | args_info->momentum_given = 0 ; | 
| 105 | args_info->stresscorr_given = 0 ; | 
| 106 | args_info->dynamicProps_group_counter = 0 ; | 
| 107 | } | 
| 108 |  | 
| 109 | static | 
| 110 | void clear_args (struct gengetopt_args_info *args_info) | 
| 111 | { | 
| 112 | FIX_UNUSED (args_info); | 
| 113 | args_info->input_arg = NULL; | 
| 114 | args_info->input_orig = NULL; | 
| 115 | args_info->output_arg = NULL; | 
| 116 | args_info->output_orig = NULL; | 
| 117 | args_info->sele1_arg = NULL; | 
| 118 | args_info->sele1_orig = NULL; | 
| 119 | args_info->sele2_arg = NULL; | 
| 120 | args_info->sele2_orig = NULL; | 
| 121 | args_info->order_orig = NULL; | 
| 122 | args_info->memory_arg = gengetopt_strdup ("2G"); | 
| 123 | args_info->memory_orig = NULL; | 
| 124 |  | 
| 125 | } | 
| 126 |  | 
| 127 | static | 
| 128 | void init_args_info(struct gengetopt_args_info *args_info) | 
| 129 | { | 
| 130 |  | 
| 131 |  | 
| 132 | args_info->help_help = gengetopt_args_info_help[0] ; | 
| 133 | args_info->version_help = gengetopt_args_info_help[1] ; | 
| 134 | args_info->input_help = gengetopt_args_info_help[2] ; | 
| 135 | args_info->output_help = gengetopt_args_info_help[3] ; | 
| 136 | args_info->sele1_help = gengetopt_args_info_help[4] ; | 
| 137 | args_info->sele2_help = gengetopt_args_info_help[5] ; | 
| 138 | args_info->order_help = gengetopt_args_info_help[6] ; | 
| 139 | args_info->memory_help = gengetopt_args_info_help[7] ; | 
| 140 | args_info->selecorr_help = gengetopt_args_info_help[9] ; | 
| 141 | args_info->rcorr_help = gengetopt_args_info_help[10] ; | 
| 142 | args_info->vcorr_help = gengetopt_args_info_help[11] ; | 
| 143 | args_info->dcorr_help = gengetopt_args_info_help[12] ; | 
| 144 | args_info->lcorr_help = gengetopt_args_info_help[13] ; | 
| 145 | args_info->sdcorr_help = gengetopt_args_info_help[14] ; | 
| 146 | args_info->r_rcorr_help = gengetopt_args_info_help[15] ; | 
| 147 | args_info->thetacorr_help = gengetopt_args_info_help[16] ; | 
| 148 | args_info->drcorr_help = gengetopt_args_info_help[17] ; | 
| 149 | args_info->helfandEcorr_help = gengetopt_args_info_help[18] ; | 
| 150 | args_info->momentum_help = gengetopt_args_info_help[19] ; | 
| 151 | args_info->stresscorr_help = gengetopt_args_info_help[20] ; | 
| 152 |  | 
| 153 | } | 
| 154 |  | 
| 155 | void | 
| 156 | cmdline_parser_print_version (void) | 
| 157 | { | 
| 158 | printf ("%s %s\n", | 
| 159 | (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), | 
| 160 | CMDLINE_PARSER_VERSION); | 
| 161 | } | 
| 162 |  | 
| 163 | static void print_help_common(void) { | 
| 164 | cmdline_parser_print_version (); | 
| 165 |  | 
| 166 | if (strlen(gengetopt_args_info_purpose) > 0) | 
| 167 | printf("\n%s\n", gengetopt_args_info_purpose); | 
| 168 |  | 
| 169 | if (strlen(gengetopt_args_info_usage) > 0) | 
| 170 | printf("\n%s\n", gengetopt_args_info_usage); | 
| 171 |  | 
| 172 | printf("\n"); | 
| 173 |  | 
| 174 | if (strlen(gengetopt_args_info_description) > 0) | 
| 175 | printf("%s\n\n", gengetopt_args_info_description); | 
| 176 | } | 
| 177 |  | 
| 178 | void | 
| 179 | cmdline_parser_print_help (void) | 
| 180 | { | 
| 181 | int i = 0; | 
| 182 | print_help_common(); | 
| 183 | while (gengetopt_args_info_help[i]) | 
| 184 | printf("%s\n", gengetopt_args_info_help[i++]); | 
| 185 | } | 
| 186 |  | 
| 187 | void | 
| 188 | cmdline_parser_init (struct gengetopt_args_info *args_info) | 
| 189 | { | 
| 190 | clear_given (args_info); | 
| 191 | clear_args (args_info); | 
| 192 | init_args_info (args_info); | 
| 193 |  | 
| 194 | args_info->inputs = 0; | 
| 195 | args_info->inputs_num = 0; | 
| 196 | } | 
| 197 |  | 
| 198 | void | 
| 199 | cmdline_parser_params_init(struct cmdline_parser_params *params) | 
| 200 | { | 
| 201 | if (params) | 
| 202 | { | 
| 203 | params->override = 0; | 
| 204 | params->initialize = 1; | 
| 205 | params->check_required = 1; | 
| 206 | params->check_ambiguity = 0; | 
| 207 | params->print_errors = 1; | 
| 208 | } | 
| 209 | } | 
| 210 |  | 
| 211 | struct cmdline_parser_params * | 
| 212 | cmdline_parser_params_create(void) | 
| 213 | { | 
| 214 | struct cmdline_parser_params *params = | 
| 215 | (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); | 
| 216 | cmdline_parser_params_init(params); | 
| 217 | return params; | 
| 218 | } | 
| 219 |  | 
| 220 | static void | 
| 221 | free_string_field (char **s) | 
| 222 | { | 
| 223 | if (*s) | 
| 224 | { | 
| 225 | free (*s); | 
| 226 | *s = 0; | 
| 227 | } | 
| 228 | } | 
| 229 |  | 
| 230 |  | 
| 231 | static void | 
| 232 | cmdline_parser_release (struct gengetopt_args_info *args_info) | 
| 233 | { | 
| 234 | unsigned int i; | 
| 235 | free_string_field (&(args_info->input_arg)); | 
| 236 | free_string_field (&(args_info->input_orig)); | 
| 237 | free_string_field (&(args_info->output_arg)); | 
| 238 | free_string_field (&(args_info->output_orig)); | 
| 239 | free_string_field (&(args_info->sele1_arg)); | 
| 240 | free_string_field (&(args_info->sele1_orig)); | 
| 241 | free_string_field (&(args_info->sele2_arg)); | 
| 242 | free_string_field (&(args_info->sele2_orig)); | 
| 243 | free_string_field (&(args_info->order_orig)); | 
| 244 | free_string_field (&(args_info->memory_arg)); | 
| 245 | free_string_field (&(args_info->memory_orig)); | 
| 246 |  | 
| 247 |  | 
| 248 | for (i = 0; i < args_info->inputs_num; ++i) | 
| 249 | free (args_info->inputs [i]); | 
| 250 |  | 
| 251 | if (args_info->inputs_num) | 
| 252 | free (args_info->inputs); | 
| 253 |  | 
| 254 | clear_given (args_info); | 
| 255 | } | 
| 256 |  | 
| 257 |  | 
| 258 | static void | 
| 259 | write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) | 
| 260 | { | 
| 261 | FIX_UNUSED (values); | 
| 262 | if (arg) { | 
| 263 | fprintf(outfile, "%s=\"%s\"\n", opt, arg); | 
| 264 | } else { | 
| 265 | fprintf(outfile, "%s\n", opt); | 
| 266 | } | 
| 267 | } | 
| 268 |  | 
| 269 |  | 
| 270 | int | 
| 271 | cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) | 
| 272 | { | 
| 273 | int i = 0; | 
| 274 |  | 
| 275 | if (!outfile) | 
| 276 | { | 
| 277 | fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); | 
| 278 | return EXIT_FAILURE; | 
| 279 | } | 
| 280 |  | 
| 281 | if (args_info->help_given) | 
| 282 | write_into_file(outfile, "help", 0, 0 ); | 
| 283 | if (args_info->version_given) | 
| 284 | write_into_file(outfile, "version", 0, 0 ); | 
| 285 | if (args_info->input_given) | 
| 286 | write_into_file(outfile, "input", args_info->input_orig, 0); | 
| 287 | if (args_info->output_given) | 
| 288 | write_into_file(outfile, "output", args_info->output_orig, 0); | 
| 289 | if (args_info->sele1_given) | 
| 290 | write_into_file(outfile, "sele1", args_info->sele1_orig, 0); | 
| 291 | if (args_info->sele2_given) | 
| 292 | write_into_file(outfile, "sele2", args_info->sele2_orig, 0); | 
| 293 | if (args_info->order_given) | 
| 294 | write_into_file(outfile, "order", args_info->order_orig, 0); | 
| 295 | if (args_info->memory_given) | 
| 296 | write_into_file(outfile, "memory", args_info->memory_orig, 0); | 
| 297 | if (args_info->selecorr_given) | 
| 298 | write_into_file(outfile, "selecorr", 0, 0 ); | 
| 299 | if (args_info->rcorr_given) | 
| 300 | write_into_file(outfile, "rcorr", 0, 0 ); | 
| 301 | if (args_info->vcorr_given) | 
| 302 | write_into_file(outfile, "vcorr", 0, 0 ); | 
| 303 | if (args_info->dcorr_given) | 
| 304 | write_into_file(outfile, "dcorr", 0, 0 ); | 
| 305 | if (args_info->lcorr_given) | 
| 306 | write_into_file(outfile, "lcorr", 0, 0 ); | 
| 307 | if (args_info->sdcorr_given) | 
| 308 | write_into_file(outfile, "sdcorr", 0, 0 ); | 
| 309 | if (args_info->r_rcorr_given) | 
| 310 | write_into_file(outfile, "r_rcorr", 0, 0 ); | 
| 311 | if (args_info->thetacorr_given) | 
| 312 | write_into_file(outfile, "thetacorr", 0, 0 ); | 
| 313 | if (args_info->drcorr_given) | 
| 314 | write_into_file(outfile, "drcorr", 0, 0 ); | 
| 315 | if (args_info->helfandEcorr_given) | 
| 316 | write_into_file(outfile, "helfandEcorr", 0, 0 ); | 
| 317 | if (args_info->momentum_given) | 
| 318 | write_into_file(outfile, "momentum", 0, 0 ); | 
| 319 | if (args_info->stresscorr_given) | 
| 320 | write_into_file(outfile, "stresscorr", 0, 0 ); | 
| 321 |  | 
| 322 |  | 
| 323 | i = EXIT_SUCCESS; | 
| 324 | return i; | 
| 325 | } | 
| 326 |  | 
| 327 | int | 
| 328 | cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) | 
| 329 | { | 
| 330 | FILE *outfile; | 
| 331 | int i = 0; | 
| 332 |  | 
| 333 | outfile = fopen(filename, "w"); | 
| 334 |  | 
| 335 | if (!outfile) | 
| 336 | { | 
| 337 | fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); | 
| 338 | return EXIT_FAILURE; | 
| 339 | } | 
| 340 |  | 
| 341 | i = cmdline_parser_dump(outfile, args_info); | 
| 342 | fclose (outfile); | 
| 343 |  | 
| 344 | return i; | 
| 345 | } | 
| 346 |  | 
| 347 | void | 
| 348 | cmdline_parser_free (struct gengetopt_args_info *args_info) | 
| 349 | { | 
| 350 | cmdline_parser_release (args_info); | 
| 351 | } | 
| 352 |  | 
| 353 | /** @brief replacement of strdup, which is not standard */ | 
| 354 | char * | 
| 355 | gengetopt_strdup (const char *s) | 
| 356 | { | 
| 357 | char *result = 0; | 
| 358 | if (!s) | 
| 359 | return result; | 
| 360 |  | 
| 361 | result = (char*)malloc(strlen(s) + 1); | 
| 362 | if (result == (char*)0) | 
| 363 | return (char*)0; | 
| 364 | strcpy(result, s); | 
| 365 | return result; | 
| 366 | } | 
| 367 |  | 
| 368 | static void | 
| 369 | reset_group_dynamicProps(struct gengetopt_args_info *args_info) | 
| 370 | { | 
| 371 | if (! args_info->dynamicProps_group_counter) | 
| 372 | return; | 
| 373 |  | 
| 374 | args_info->selecorr_given = 0 ; | 
| 375 | args_info->rcorr_given = 0 ; | 
| 376 | args_info->vcorr_given = 0 ; | 
| 377 | args_info->dcorr_given = 0 ; | 
| 378 | args_info->lcorr_given = 0 ; | 
| 379 | args_info->sdcorr_given = 0 ; | 
| 380 | args_info->r_rcorr_given = 0 ; | 
| 381 | args_info->thetacorr_given = 0 ; | 
| 382 | args_info->drcorr_given = 0 ; | 
| 383 | args_info->helfandEcorr_given = 0 ; | 
| 384 | args_info->momentum_given = 0 ; | 
| 385 | args_info->stresscorr_given = 0 ; | 
| 386 |  | 
| 387 | args_info->dynamicProps_group_counter = 0; | 
| 388 | } | 
| 389 |  | 
| 390 | int | 
| 391 | cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) | 
| 392 | { | 
| 393 | return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); | 
| 394 | } | 
| 395 |  | 
| 396 | int | 
| 397 | cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, | 
| 398 | struct cmdline_parser_params *params) | 
| 399 | { | 
| 400 | int result; | 
| 401 | result = cmdline_parser_internal (argc, argv, args_info, params, 0); | 
| 402 |  | 
| 403 | if (result == EXIT_FAILURE) | 
| 404 | { | 
| 405 | cmdline_parser_free (args_info); | 
| 406 | exit (EXIT_FAILURE); | 
| 407 | } | 
| 408 |  | 
| 409 | return result; | 
| 410 | } | 
| 411 |  | 
| 412 | int | 
| 413 | cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) | 
| 414 | { | 
| 415 | int result; | 
| 416 | struct cmdline_parser_params params; | 
| 417 |  | 
| 418 | params.override = override; | 
| 419 | params.initialize = initialize; | 
| 420 | params.check_required = check_required; | 
| 421 | params.check_ambiguity = 0; | 
| 422 | params.print_errors = 1; | 
| 423 |  | 
| 424 | result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); | 
| 425 |  | 
| 426 | if (result == EXIT_FAILURE) | 
| 427 | { | 
| 428 | cmdline_parser_free (args_info); | 
| 429 | exit (EXIT_FAILURE); | 
| 430 | } | 
| 431 |  | 
| 432 | return result; | 
| 433 | } | 
| 434 |  | 
| 435 | int | 
| 436 | cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) | 
| 437 | { | 
| 438 | int result = EXIT_SUCCESS; | 
| 439 |  | 
| 440 | if (cmdline_parser_required2(args_info, prog_name, 0) > 0) | 
| 441 | result = EXIT_FAILURE; | 
| 442 |  | 
| 443 | if (result == EXIT_FAILURE) | 
| 444 | { | 
| 445 | cmdline_parser_free (args_info); | 
| 446 | exit (EXIT_FAILURE); | 
| 447 | } | 
| 448 |  | 
| 449 | return result; | 
| 450 | } | 
| 451 |  | 
| 452 | int | 
| 453 | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) | 
| 454 | { | 
| 455 | int error = 0; | 
| 456 | FIX_UNUSED (additional_error); | 
| 457 |  | 
| 458 | /* checks for required options */ | 
| 459 | if (! args_info->input_given) | 
| 460 | { | 
| 461 | fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); | 
| 462 | error = 1; | 
| 463 | } | 
| 464 |  | 
| 465 | if (args_info->dynamicProps_group_counter == 0) | 
| 466 | { | 
| 467 | fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", prog_name, args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); | 
| 468 | error = 1; | 
| 469 | } | 
| 470 |  | 
| 471 |  | 
| 472 | /* checks for dependences among options */ | 
| 473 |  | 
| 474 | return error; | 
| 475 | } | 
| 476 |  | 
| 477 |  | 
| 478 | static char *package_name = 0; | 
| 479 |  | 
| 480 | /** | 
| 481 | * @brief updates an option | 
| 482 | * @param field the generic pointer to the field to update | 
| 483 | * @param orig_field the pointer to the orig field | 
| 484 | * @param field_given the pointer to the number of occurrence of this option | 
| 485 | * @param prev_given the pointer to the number of occurrence already seen | 
| 486 | * @param value the argument for this option (if null no arg was specified) | 
| 487 | * @param possible_values the possible values for this option (if specified) | 
| 488 | * @param default_value the default value (in case the option only accepts fixed values) | 
| 489 | * @param arg_type the type of this option | 
| 490 | * @param check_ambiguity @see cmdline_parser_params.check_ambiguity | 
| 491 | * @param override @see cmdline_parser_params.override | 
| 492 | * @param no_free whether to free a possible previous value | 
| 493 | * @param multiple_option whether this is a multiple option | 
| 494 | * @param long_opt the corresponding long option | 
| 495 | * @param short_opt the corresponding short option (or '-' if none) | 
| 496 | * @param additional_error possible further error specification | 
| 497 | */ | 
| 498 | static | 
| 499 | int update_arg(void *field, char **orig_field, | 
| 500 | unsigned int *field_given, unsigned int *prev_given, | 
| 501 | char *value, const char *possible_values[], | 
| 502 | const char *default_value, | 
| 503 | cmdline_parser_arg_type arg_type, | 
| 504 | int check_ambiguity, int override, | 
| 505 | int no_free, int multiple_option, | 
| 506 | const char *long_opt, char short_opt, | 
| 507 | const char *additional_error) | 
| 508 | { | 
| 509 | char *stop_char = 0; | 
| 510 | const char *val = value; | 
| 511 | int found; | 
| 512 | char **string_field; | 
| 513 | FIX_UNUSED (field); | 
| 514 |  | 
| 515 | stop_char = 0; | 
| 516 | found = 0; | 
| 517 |  | 
| 518 | if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) | 
| 519 | { | 
| 520 | if (short_opt != '-') | 
| 521 | fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", | 
| 522 | package_name, long_opt, short_opt, | 
| 523 | (additional_error ? additional_error : "")); | 
| 524 | else | 
| 525 | fprintf (stderr, "%s: `--%s' option given more than once%s\n", | 
| 526 | package_name, long_opt, | 
| 527 | (additional_error ? additional_error : "")); | 
| 528 | return 1; /* failure */ | 
| 529 | } | 
| 530 |  | 
| 531 | FIX_UNUSED (default_value); | 
| 532 |  | 
| 533 | if (field_given && *field_given && ! override) | 
| 534 | return 0; | 
| 535 | if (prev_given) | 
| 536 | (*prev_given)++; | 
| 537 | if (field_given) | 
| 538 | (*field_given)++; | 
| 539 | if (possible_values) | 
| 540 | val = possible_values[found]; | 
| 541 |  | 
| 542 | switch(arg_type) { | 
| 543 | case ARG_INT: | 
| 544 | if (val) *((int *)field) = strtol (val, &stop_char, 0); | 
| 545 | break; | 
| 546 | case ARG_STRING: | 
| 547 | if (val) { | 
| 548 | string_field = (char **)field; | 
| 549 | if (!no_free && *string_field) | 
| 550 | free (*string_field); /* free previous string */ | 
| 551 | *string_field = gengetopt_strdup (val); | 
| 552 | } | 
| 553 | break; | 
| 554 | default: | 
| 555 | break; | 
| 556 | }; | 
| 557 |  | 
| 558 | /* check numeric conversion */ | 
| 559 | switch(arg_type) { | 
| 560 | case ARG_INT: | 
| 561 | if (val && !(stop_char && *stop_char == '\0')) { | 
| 562 | fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); | 
| 563 | return 1; /* failure */ | 
| 564 | } | 
| 565 | break; | 
| 566 | default: | 
| 567 | ; | 
| 568 | }; | 
| 569 |  | 
| 570 | /* store the original value */ | 
| 571 | switch(arg_type) { | 
| 572 | case ARG_NO: | 
| 573 | break; | 
| 574 | default: | 
| 575 | if (value && orig_field) { | 
| 576 | if (no_free) { | 
| 577 | *orig_field = value; | 
| 578 | } else { | 
| 579 | if (*orig_field) | 
| 580 | free (*orig_field); /* free previous string */ | 
| 581 | *orig_field = gengetopt_strdup (value); | 
| 582 | } | 
| 583 | } | 
| 584 | }; | 
| 585 |  | 
| 586 | return 0; /* OK */ | 
| 587 | } | 
| 588 |  | 
| 589 |  | 
| 590 | int | 
| 591 | cmdline_parser_internal ( | 
| 592 | int argc, char **argv, struct gengetopt_args_info *args_info, | 
| 593 | struct cmdline_parser_params *params, const char *additional_error) | 
| 594 | { | 
| 595 | int c;        /* Character of the parsed option.  */ | 
| 596 |  | 
| 597 | int error = 0; | 
| 598 | struct gengetopt_args_info local_args_info; | 
| 599 |  | 
| 600 | int override; | 
| 601 | int initialize; | 
| 602 | int check_required; | 
| 603 | int check_ambiguity; | 
| 604 |  | 
| 605 | package_name = argv[0]; | 
| 606 |  | 
| 607 | override = params->override; | 
| 608 | initialize = params->initialize; | 
| 609 | check_required = params->check_required; | 
| 610 | check_ambiguity = params->check_ambiguity; | 
| 611 |  | 
| 612 | if (initialize) | 
| 613 | cmdline_parser_init (args_info); | 
| 614 |  | 
| 615 | cmdline_parser_init (&local_args_info); | 
| 616 |  | 
| 617 | optarg = 0; | 
| 618 | optind = 0; | 
| 619 | opterr = params->print_errors; | 
| 620 | optopt = '?'; | 
| 621 |  | 
| 622 | while (1) | 
| 623 | { | 
| 624 | int option_index = 0; | 
| 625 |  | 
| 626 | static struct option long_options[] = { | 
| 627 | { "help",       0, NULL, 'h' }, | 
| 628 | { "version",    0, NULL, 'V' }, | 
| 629 | { "input",      1, NULL, 'i' }, | 
| 630 | { "output",     1, NULL, 'o' }, | 
| 631 | { "sele1",      1, NULL, 0 }, | 
| 632 | { "sele2",      1, NULL, 0 }, | 
| 633 | { "order",      1, NULL, 0 }, | 
| 634 | { "memory",     1, NULL, 'm' }, | 
| 635 | { "selecorr",   0, NULL, 's' }, | 
| 636 | { "rcorr",      0, NULL, 'r' }, | 
| 637 | { "vcorr",      0, NULL, 'v' }, | 
| 638 | { "dcorr",      0, NULL, 'd' }, | 
| 639 | { "lcorr",      0, NULL, 'l' }, | 
| 640 | { "sdcorr",     0, NULL, 'M' }, | 
| 641 | { "r_rcorr",    0, NULL, 0 }, | 
| 642 | { "thetacorr",  0, NULL, 0 }, | 
| 643 | { "drcorr",     0, NULL, 0 }, | 
| 644 | { "helfandEcorr",       0, NULL, 0 }, | 
| 645 | { "momentum",   0, NULL, 'p' }, | 
| 646 | { "stresscorr", 0, NULL, 0 }, | 
| 647 | { 0,  0, 0, 0 } | 
| 648 | }; | 
| 649 |  | 
| 650 | c = getopt_long (argc, argv, "hVi:o:m:srvdlMp", long_options, &option_index); | 
| 651 |  | 
| 652 | if (c == -1) break;       /* Exit from `while (1)' loop.  */ | 
| 653 |  | 
| 654 | switch (c) | 
| 655 | { | 
| 656 | case 'h':       /* Print help and exit.  */ | 
| 657 | cmdline_parser_print_help (); | 
| 658 | cmdline_parser_free (&local_args_info); | 
| 659 | exit (EXIT_SUCCESS); | 
| 660 |  | 
| 661 | case 'V':       /* Print version and exit.  */ | 
| 662 | cmdline_parser_print_version (); | 
| 663 | cmdline_parser_free (&local_args_info); | 
| 664 | exit (EXIT_SUCCESS); | 
| 665 |  | 
| 666 | case 'i':       /* input dump file.  */ | 
| 667 |  | 
| 668 |  | 
| 669 | if (update_arg( (void *)&(args_info->input_arg), | 
| 670 | &(args_info->input_orig), &(args_info->input_given), | 
| 671 | &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, | 
| 672 | check_ambiguity, override, 0, 0, | 
| 673 | "input", 'i', | 
| 674 | additional_error)) | 
| 675 | goto failure; | 
| 676 |  | 
| 677 | break; | 
| 678 | case 'o':       /* output file name.  */ | 
| 679 |  | 
| 680 |  | 
| 681 | if (update_arg( (void *)&(args_info->output_arg), | 
| 682 | &(args_info->output_orig), &(args_info->output_given), | 
| 683 | &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, | 
| 684 | check_ambiguity, override, 0, 0, | 
| 685 | "output", 'o', | 
| 686 | additional_error)) | 
| 687 | goto failure; | 
| 688 |  | 
| 689 | break; | 
| 690 | case 'm':       /* Available memory (defaults to 2G).  */ | 
| 691 |  | 
| 692 |  | 
| 693 | if (update_arg( (void *)&(args_info->memory_arg), | 
| 694 | &(args_info->memory_orig), &(args_info->memory_given), | 
| 695 | &(local_args_info.memory_given), optarg, 0, "2G", ARG_STRING, | 
| 696 | check_ambiguity, override, 0, 0, | 
| 697 | "memory", 'm', | 
| 698 | additional_error)) | 
| 699 | goto failure; | 
| 700 |  | 
| 701 | break; | 
| 702 | case 's':       /* selection correlation function.  */ | 
| 703 |  | 
| 704 | if (args_info->dynamicProps_group_counter && override) | 
| 705 | reset_group_dynamicProps (args_info); | 
| 706 | args_info->dynamicProps_group_counter += 1; | 
| 707 |  | 
| 708 | if (update_arg( 0 , | 
| 709 | 0 , &(args_info->selecorr_given), | 
| 710 | &(local_args_info.selecorr_given), optarg, 0, 0, ARG_NO, | 
| 711 | check_ambiguity, override, 0, 0, | 
| 712 | "selecorr", 's', | 
| 713 | additional_error)) | 
| 714 | goto failure; | 
| 715 |  | 
| 716 | break; | 
| 717 | case 'r':       /* rmsd.  */ | 
| 718 |  | 
| 719 | if (args_info->dynamicProps_group_counter && override) | 
| 720 | reset_group_dynamicProps (args_info); | 
| 721 | args_info->dynamicProps_group_counter += 1; | 
| 722 |  | 
| 723 | if (update_arg( 0 , | 
| 724 | 0 , &(args_info->rcorr_given), | 
| 725 | &(local_args_info.rcorr_given), optarg, 0, 0, ARG_NO, | 
| 726 | check_ambiguity, override, 0, 0, | 
| 727 | "rcorr", 'r', | 
| 728 | additional_error)) | 
| 729 | goto failure; | 
| 730 |  | 
| 731 | break; | 
| 732 | case 'v':       /* velocity correlation function.  */ | 
| 733 |  | 
| 734 | if (args_info->dynamicProps_group_counter && override) | 
| 735 | reset_group_dynamicProps (args_info); | 
| 736 | args_info->dynamicProps_group_counter += 1; | 
| 737 |  | 
| 738 | if (update_arg( 0 , | 
| 739 | 0 , &(args_info->vcorr_given), | 
| 740 | &(local_args_info.vcorr_given), optarg, 0, 0, ARG_NO, | 
| 741 | check_ambiguity, override, 0, 0, | 
| 742 | "vcorr", 'v', | 
| 743 | additional_error)) | 
| 744 | goto failure; | 
| 745 |  | 
| 746 | break; | 
| 747 | case 'd':       /* dipole correlation function.  */ | 
| 748 |  | 
| 749 | if (args_info->dynamicProps_group_counter && override) | 
| 750 | reset_group_dynamicProps (args_info); | 
| 751 | args_info->dynamicProps_group_counter += 1; | 
| 752 |  | 
| 753 | if (update_arg( 0 , | 
| 754 | 0 , &(args_info->dcorr_given), | 
| 755 | &(local_args_info.dcorr_given), optarg, 0, 0, ARG_NO, | 
| 756 | check_ambiguity, override, 0, 0, | 
| 757 | "dcorr", 'd', | 
| 758 | additional_error)) | 
| 759 | goto failure; | 
| 760 |  | 
| 761 | break; | 
| 762 | case 'l':       /* Lengendre correlation function.  */ | 
| 763 |  | 
| 764 | if (args_info->dynamicProps_group_counter && override) | 
| 765 | reset_group_dynamicProps (args_info); | 
| 766 | args_info->dynamicProps_group_counter += 1; | 
| 767 |  | 
| 768 | if (update_arg( 0 , | 
| 769 | 0 , &(args_info->lcorr_given), | 
| 770 | &(local_args_info.lcorr_given), optarg, 0, 0, ARG_NO, | 
| 771 | check_ambiguity, override, 0, 0, | 
| 772 | "lcorr", 'l', | 
| 773 | additional_error)) | 
| 774 | goto failure; | 
| 775 |  | 
| 776 | break; | 
| 777 | case 'M':       /* System dipole correlation function.  */ | 
| 778 |  | 
| 779 | if (args_info->dynamicProps_group_counter && override) | 
| 780 | reset_group_dynamicProps (args_info); | 
| 781 | args_info->dynamicProps_group_counter += 1; | 
| 782 |  | 
| 783 | if (update_arg( 0 , | 
| 784 | 0 , &(args_info->sdcorr_given), | 
| 785 | &(local_args_info.sdcorr_given), optarg, 0, 0, ARG_NO, | 
| 786 | check_ambiguity, override, 0, 0, | 
| 787 | "sdcorr", 'M', | 
| 788 | additional_error)) | 
| 789 | goto failure; | 
| 790 |  | 
| 791 | break; | 
| 792 | case 'p':       /* Helfand momentum for viscosity.  */ | 
| 793 |  | 
| 794 | if (args_info->dynamicProps_group_counter && override) | 
| 795 | reset_group_dynamicProps (args_info); | 
| 796 | args_info->dynamicProps_group_counter += 1; | 
| 797 |  | 
| 798 | if (update_arg( 0 , | 
| 799 | 0 , &(args_info->momentum_given), | 
| 800 | &(local_args_info.momentum_given), optarg, 0, 0, ARG_NO, | 
| 801 | check_ambiguity, override, 0, 0, | 
| 802 | "momentum", 'p', | 
| 803 | additional_error)) | 
| 804 | goto failure; | 
| 805 |  | 
| 806 | break; | 
| 807 |  | 
| 808 | case 0: /* Long option with no short option */ | 
| 809 | /* select first stuntdouble set.  */ | 
| 810 | if (strcmp (long_options[option_index].name, "sele1") == 0) | 
| 811 | { | 
| 812 |  | 
| 813 |  | 
| 814 | if (update_arg( (void *)&(args_info->sele1_arg), | 
| 815 | &(args_info->sele1_orig), &(args_info->sele1_given), | 
| 816 | &(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING, | 
| 817 | check_ambiguity, override, 0, 0, | 
| 818 | "sele1", '-', | 
| 819 | additional_error)) | 
| 820 | goto failure; | 
| 821 |  | 
| 822 | } | 
| 823 | /* select second stuntdouble set (if sele2 is not set, use script from sele1).  */ | 
| 824 | else if (strcmp (long_options[option_index].name, "sele2") == 0) | 
| 825 | { | 
| 826 |  | 
| 827 |  | 
| 828 | if (update_arg( (void *)&(args_info->sele2_arg), | 
| 829 | &(args_info->sele2_orig), &(args_info->sele2_given), | 
| 830 | &(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING, | 
| 831 | check_ambiguity, override, 0, 0, | 
| 832 | "sele2", '-', | 
| 833 | additional_error)) | 
| 834 | goto failure; | 
| 835 |  | 
| 836 | } | 
| 837 | /* Lengendre Polynomial Order.  */ | 
| 838 | else if (strcmp (long_options[option_index].name, "order") == 0) | 
| 839 | { | 
| 840 |  | 
| 841 |  | 
| 842 | if (update_arg( (void *)&(args_info->order_arg), | 
| 843 | &(args_info->order_orig), &(args_info->order_given), | 
| 844 | &(local_args_info.order_given), optarg, 0, 0, ARG_INT, | 
| 845 | check_ambiguity, override, 0, 0, | 
| 846 | "order", '-', | 
| 847 | additional_error)) | 
| 848 | goto failure; | 
| 849 |  | 
| 850 | } | 
| 851 | /* Radial rmsd.  */ | 
| 852 | else if (strcmp (long_options[option_index].name, "r_rcorr") == 0) | 
| 853 | { | 
| 854 |  | 
| 855 | if (args_info->dynamicProps_group_counter && override) | 
| 856 | reset_group_dynamicProps (args_info); | 
| 857 | args_info->dynamicProps_group_counter += 1; | 
| 858 |  | 
| 859 | if (update_arg( 0 , | 
| 860 | 0 , &(args_info->r_rcorr_given), | 
| 861 | &(local_args_info.r_rcorr_given), optarg, 0, 0, ARG_NO, | 
| 862 | check_ambiguity, override, 0, 0, | 
| 863 | "r_rcorr", '-', | 
| 864 | additional_error)) | 
| 865 | goto failure; | 
| 866 |  | 
| 867 | } | 
| 868 | /* Angular rmsd.  */ | 
| 869 | else if (strcmp (long_options[option_index].name, "thetacorr") == 0) | 
| 870 | { | 
| 871 |  | 
| 872 | if (args_info->dynamicProps_group_counter && override) | 
| 873 | reset_group_dynamicProps (args_info); | 
| 874 | args_info->dynamicProps_group_counter += 1; | 
| 875 |  | 
| 876 | if (update_arg( 0 , | 
| 877 | 0 , &(args_info->thetacorr_given), | 
| 878 | &(local_args_info.thetacorr_given), optarg, 0, 0, ARG_NO, | 
| 879 | check_ambiguity, override, 0, 0, | 
| 880 | "thetacorr", '-', | 
| 881 | additional_error)) | 
| 882 | goto failure; | 
| 883 |  | 
| 884 | } | 
| 885 | /* Directional rmsd for particles with unit vectors.  */ | 
| 886 | else if (strcmp (long_options[option_index].name, "drcorr") == 0) | 
| 887 | { | 
| 888 |  | 
| 889 | if (args_info->dynamicProps_group_counter && override) | 
| 890 | reset_group_dynamicProps (args_info); | 
| 891 | args_info->dynamicProps_group_counter += 1; | 
| 892 |  | 
| 893 | if (update_arg( 0 , | 
| 894 | 0 , &(args_info->drcorr_given), | 
| 895 | &(local_args_info.drcorr_given), optarg, 0, 0, ARG_NO, | 
| 896 | check_ambiguity, override, 0, 0, | 
| 897 | "drcorr", '-', | 
| 898 | additional_error)) | 
| 899 | goto failure; | 
| 900 |  | 
| 901 | } | 
| 902 | /* Helfand moment for thermal conductvity.  */ | 
| 903 | else if (strcmp (long_options[option_index].name, "helfandEcorr") == 0) | 
| 904 | { | 
| 905 |  | 
| 906 | if (args_info->dynamicProps_group_counter && override) | 
| 907 | reset_group_dynamicProps (args_info); | 
| 908 | args_info->dynamicProps_group_counter += 1; | 
| 909 |  | 
| 910 | if (update_arg( 0 , | 
| 911 | 0 , &(args_info->helfandEcorr_given), | 
| 912 | &(local_args_info.helfandEcorr_given), optarg, 0, 0, ARG_NO, | 
| 913 | check_ambiguity, override, 0, 0, | 
| 914 | "helfandEcorr", '-', | 
| 915 | additional_error)) | 
| 916 | goto failure; | 
| 917 |  | 
| 918 | } | 
| 919 | /* Stress tensor correlation function.  */ | 
| 920 | else if (strcmp (long_options[option_index].name, "stresscorr") == 0) | 
| 921 | { | 
| 922 |  | 
| 923 | if (args_info->dynamicProps_group_counter && override) | 
| 924 | reset_group_dynamicProps (args_info); | 
| 925 | args_info->dynamicProps_group_counter += 1; | 
| 926 |  | 
| 927 | if (update_arg( 0 , | 
| 928 | 0 , &(args_info->stresscorr_given), | 
| 929 | &(local_args_info.stresscorr_given), optarg, 0, 0, ARG_NO, | 
| 930 | check_ambiguity, override, 0, 0, | 
| 931 | "stresscorr", '-', | 
| 932 | additional_error)) | 
| 933 | goto failure; | 
| 934 |  | 
| 935 | } | 
| 936 |  | 
| 937 | break; | 
| 938 | case '?':       /* Invalid option.  */ | 
| 939 | /* `getopt_long' already printed an error message.  */ | 
| 940 | goto failure; | 
| 941 |  | 
| 942 | default:        /* bug: option not considered.  */ | 
| 943 | fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); | 
| 944 | abort (); | 
| 945 | } /* switch */ | 
| 946 | } /* while */ | 
| 947 |  | 
| 948 | if (args_info->dynamicProps_group_counter > 1) | 
| 949 | { | 
| 950 | fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required%s.\n", argv[0], args_info->dynamicProps_group_counter, (additional_error ? additional_error : "")); | 
| 951 | error = 1; | 
| 952 | } | 
| 953 |  | 
| 954 |  | 
| 955 |  | 
| 956 | if (check_required) | 
| 957 | { | 
| 958 | error += cmdline_parser_required2 (args_info, argv[0], additional_error); | 
| 959 | } | 
| 960 |  | 
| 961 | cmdline_parser_release (&local_args_info); | 
| 962 |  | 
| 963 | if ( error ) | 
| 964 | return (EXIT_FAILURE); | 
| 965 |  | 
| 966 | if (optind < argc) | 
| 967 | { | 
| 968 | int i = 0 ; | 
| 969 | int found_prog_name = 0; | 
| 970 | /* whether program name, i.e., argv[0], is in the remaining args | 
| 971 | (this may happen with some implementations of getopt, | 
| 972 | but surely not with the one included by gengetopt) */ | 
| 973 |  | 
| 974 | i = optind; | 
| 975 | while (i < argc) | 
| 976 | if (argv[i++] == argv[0]) { | 
| 977 | found_prog_name = 1; | 
| 978 | break; | 
| 979 | } | 
| 980 | i = 0; | 
| 981 |  | 
| 982 | args_info->inputs_num = argc - optind - found_prog_name; | 
| 983 | args_info->inputs = | 
| 984 | (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; | 
| 985 | while (optind < argc) | 
| 986 | if (argv[optind++] != argv[0]) | 
| 987 | args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; | 
| 988 | } | 
| 989 |  | 
| 990 | return 0; | 
| 991 |  | 
| 992 | failure: | 
| 993 |  | 
| 994 | cmdline_parser_release (&local_args_info); | 
| 995 | return (EXIT_FAILURE); | 
| 996 | } |