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