| 1 | /* | 
| 2 | File autogenerated by gengetopt version 2.22.4 | 
| 3 | generated with the following command: | 
| 4 | gengetopt --file-name=SequentialPropsCmd --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 "SequentialPropsCmd.h" | 
| 31 |  | 
| 32 | const char *gengetopt_args_info_purpose = ""; | 
| 33 |  | 
| 34 | const char *gengetopt_args_info_usage = "Usage: SequentialProps [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 | "  -n, --nbins=INT               Number of bins  (default=`100')", | 
| 46 | "  -z, --referenceZ=DOUBLE       Reference z-height of solid surface", | 
| 47 | "  -r, --dropletR=DOUBLE         Droplet radius in angstroms", | 
| 48 | "\n Group: sequentialProps\n   an option of this group is required", | 
| 49 | "  -c, --com                     selection center of mass", | 
| 50 | "      --ca1                     contact angle of selection (using center of \n                                  mass)", | 
| 51 | "      --ca2                     contact angle of selection (using density \n                                  profile)", | 
| 52 | 0 | 
| 53 | }; | 
| 54 |  | 
| 55 | typedef enum {ARG_NO | 
| 56 | , ARG_STRING | 
| 57 | , ARG_INT | 
| 58 | , ARG_DOUBLE | 
| 59 | } cmdline_parser_arg_type; | 
| 60 |  | 
| 61 | static | 
| 62 | void clear_given (struct gengetopt_args_info *args_info); | 
| 63 | static | 
| 64 | void clear_args (struct gengetopt_args_info *args_info); | 
| 65 |  | 
| 66 | static int | 
| 67 | cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info, | 
| 68 | struct cmdline_parser_params *params, const char *additional_error); | 
| 69 |  | 
| 70 | static int | 
| 71 | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error); | 
| 72 |  | 
| 73 | static char * | 
| 74 | gengetopt_strdup (const char *s); | 
| 75 |  | 
| 76 | static | 
| 77 | void clear_given (struct gengetopt_args_info *args_info) | 
| 78 | { | 
| 79 | args_info->help_given = 0 ; | 
| 80 | args_info->version_given = 0 ; | 
| 81 | args_info->input_given = 0 ; | 
| 82 | args_info->output_given = 0 ; | 
| 83 | args_info->sele1_given = 0 ; | 
| 84 | args_info->sele2_given = 0 ; | 
| 85 | args_info->nbins_given = 0 ; | 
| 86 | args_info->referenceZ_given = 0 ; | 
| 87 | args_info->dropletR_given = 0 ; | 
| 88 | args_info->com_given = 0 ; | 
| 89 | args_info->ca1_given = 0 ; | 
| 90 | args_info->ca2_given = 0 ; | 
| 91 | args_info->sequentialProps_group_counter = 0 ; | 
| 92 | } | 
| 93 |  | 
| 94 | static | 
| 95 | void clear_args (struct gengetopt_args_info *args_info) | 
| 96 | { | 
| 97 | FIX_UNUSED (args_info); | 
| 98 | args_info->input_arg = NULL; | 
| 99 | args_info->input_orig = NULL; | 
| 100 | args_info->output_arg = NULL; | 
| 101 | args_info->output_orig = NULL; | 
| 102 | args_info->sele1_arg = NULL; | 
| 103 | args_info->sele1_orig = NULL; | 
| 104 | args_info->sele2_arg = NULL; | 
| 105 | args_info->sele2_orig = NULL; | 
| 106 | args_info->nbins_arg = 100; | 
| 107 | args_info->nbins_orig = NULL; | 
| 108 | args_info->referenceZ_orig = NULL; | 
| 109 | args_info->dropletR_orig = NULL; | 
| 110 |  | 
| 111 | } | 
| 112 |  | 
| 113 | static | 
| 114 | void init_args_info(struct gengetopt_args_info *args_info) | 
| 115 | { | 
| 116 |  | 
| 117 |  | 
| 118 | args_info->help_help = gengetopt_args_info_help[0] ; | 
| 119 | args_info->version_help = gengetopt_args_info_help[1] ; | 
| 120 | args_info->input_help = gengetopt_args_info_help[2] ; | 
| 121 | args_info->output_help = gengetopt_args_info_help[3] ; | 
| 122 | args_info->sele1_help = gengetopt_args_info_help[4] ; | 
| 123 | args_info->sele2_help = gengetopt_args_info_help[5] ; | 
| 124 | args_info->nbins_help = gengetopt_args_info_help[6] ; | 
| 125 | args_info->referenceZ_help = gengetopt_args_info_help[7] ; | 
| 126 | args_info->dropletR_help = gengetopt_args_info_help[8] ; | 
| 127 | args_info->com_help = gengetopt_args_info_help[10] ; | 
| 128 | args_info->ca1_help = gengetopt_args_info_help[11] ; | 
| 129 | args_info->ca2_help = gengetopt_args_info_help[12] ; | 
| 130 |  | 
| 131 | } | 
| 132 |  | 
| 133 | void | 
| 134 | cmdline_parser_print_version (void) | 
| 135 | { | 
| 136 | printf ("%s %s\n", | 
| 137 | (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), | 
| 138 | CMDLINE_PARSER_VERSION); | 
| 139 | } | 
| 140 |  | 
| 141 | static void print_help_common(void) { | 
| 142 | cmdline_parser_print_version (); | 
| 143 |  | 
| 144 | if (strlen(gengetopt_args_info_purpose) > 0) | 
| 145 | printf("\n%s\n", gengetopt_args_info_purpose); | 
| 146 |  | 
| 147 | if (strlen(gengetopt_args_info_usage) > 0) | 
| 148 | printf("\n%s\n", gengetopt_args_info_usage); | 
| 149 |  | 
| 150 | printf("\n"); | 
| 151 |  | 
| 152 | if (strlen(gengetopt_args_info_description) > 0) | 
| 153 | printf("%s\n\n", gengetopt_args_info_description); | 
| 154 | } | 
| 155 |  | 
| 156 | void | 
| 157 | cmdline_parser_print_help (void) | 
| 158 | { | 
| 159 | int i = 0; | 
| 160 | print_help_common(); | 
| 161 | while (gengetopt_args_info_help[i]) | 
| 162 | printf("%s\n", gengetopt_args_info_help[i++]); | 
| 163 | } | 
| 164 |  | 
| 165 | void | 
| 166 | cmdline_parser_init (struct gengetopt_args_info *args_info) | 
| 167 | { | 
| 168 | clear_given (args_info); | 
| 169 | clear_args (args_info); | 
| 170 | init_args_info (args_info); | 
| 171 |  | 
| 172 | args_info->inputs = 0; | 
| 173 | args_info->inputs_num = 0; | 
| 174 | } | 
| 175 |  | 
| 176 | void | 
| 177 | cmdline_parser_params_init(struct cmdline_parser_params *params) | 
| 178 | { | 
| 179 | if (params) | 
| 180 | { | 
| 181 | params->override = 0; | 
| 182 | params->initialize = 1; | 
| 183 | params->check_required = 1; | 
| 184 | params->check_ambiguity = 0; | 
| 185 | params->print_errors = 1; | 
| 186 | } | 
| 187 | } | 
| 188 |  | 
| 189 | struct cmdline_parser_params * | 
| 190 | cmdline_parser_params_create(void) | 
| 191 | { | 
| 192 | struct cmdline_parser_params *params = | 
| 193 | (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); | 
| 194 | cmdline_parser_params_init(params); | 
| 195 | return params; | 
| 196 | } | 
| 197 |  | 
| 198 | static void | 
| 199 | free_string_field (char **s) | 
| 200 | { | 
| 201 | if (*s) | 
| 202 | { | 
| 203 | free (*s); | 
| 204 | *s = 0; | 
| 205 | } | 
| 206 | } | 
| 207 |  | 
| 208 |  | 
| 209 | static void | 
| 210 | cmdline_parser_release (struct gengetopt_args_info *args_info) | 
| 211 | { | 
| 212 | unsigned int i; | 
| 213 | free_string_field (&(args_info->input_arg)); | 
| 214 | free_string_field (&(args_info->input_orig)); | 
| 215 | free_string_field (&(args_info->output_arg)); | 
| 216 | free_string_field (&(args_info->output_orig)); | 
| 217 | free_string_field (&(args_info->sele1_arg)); | 
| 218 | free_string_field (&(args_info->sele1_orig)); | 
| 219 | free_string_field (&(args_info->sele2_arg)); | 
| 220 | free_string_field (&(args_info->sele2_orig)); | 
| 221 | free_string_field (&(args_info->nbins_orig)); | 
| 222 | free_string_field (&(args_info->referenceZ_orig)); | 
| 223 | free_string_field (&(args_info->dropletR_orig)); | 
| 224 |  | 
| 225 |  | 
| 226 | for (i = 0; i < args_info->inputs_num; ++i) | 
| 227 | free (args_info->inputs [i]); | 
| 228 |  | 
| 229 | if (args_info->inputs_num) | 
| 230 | free (args_info->inputs); | 
| 231 |  | 
| 232 | clear_given (args_info); | 
| 233 | } | 
| 234 |  | 
| 235 |  | 
| 236 | static void | 
| 237 | write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) | 
| 238 | { | 
| 239 | FIX_UNUSED (values); | 
| 240 | if (arg) { | 
| 241 | fprintf(outfile, "%s=\"%s\"\n", opt, arg); | 
| 242 | } else { | 
| 243 | fprintf(outfile, "%s\n", opt); | 
| 244 | } | 
| 245 | } | 
| 246 |  | 
| 247 |  | 
| 248 | int | 
| 249 | cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) | 
| 250 | { | 
| 251 | int i = 0; | 
| 252 |  | 
| 253 | if (!outfile) | 
| 254 | { | 
| 255 | fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); | 
| 256 | return EXIT_FAILURE; | 
| 257 | } | 
| 258 |  | 
| 259 | if (args_info->help_given) | 
| 260 | write_into_file(outfile, "help", 0, 0 ); | 
| 261 | if (args_info->version_given) | 
| 262 | write_into_file(outfile, "version", 0, 0 ); | 
| 263 | if (args_info->input_given) | 
| 264 | write_into_file(outfile, "input", args_info->input_orig, 0); | 
| 265 | if (args_info->output_given) | 
| 266 | write_into_file(outfile, "output", args_info->output_orig, 0); | 
| 267 | if (args_info->sele1_given) | 
| 268 | write_into_file(outfile, "sele1", args_info->sele1_orig, 0); | 
| 269 | if (args_info->sele2_given) | 
| 270 | write_into_file(outfile, "sele2", args_info->sele2_orig, 0); | 
| 271 | if (args_info->nbins_given) | 
| 272 | write_into_file(outfile, "nbins", args_info->nbins_orig, 0); | 
| 273 | if (args_info->referenceZ_given) | 
| 274 | write_into_file(outfile, "referenceZ", args_info->referenceZ_orig, 0); | 
| 275 | if (args_info->dropletR_given) | 
| 276 | write_into_file(outfile, "dropletR", args_info->dropletR_orig, 0); | 
| 277 | if (args_info->com_given) | 
| 278 | write_into_file(outfile, "com", 0, 0 ); | 
| 279 | if (args_info->ca1_given) | 
| 280 | write_into_file(outfile, "ca1", 0, 0 ); | 
| 281 | if (args_info->ca2_given) | 
| 282 | write_into_file(outfile, "ca2", 0, 0 ); | 
| 283 |  | 
| 284 |  | 
| 285 | i = EXIT_SUCCESS; | 
| 286 | return i; | 
| 287 | } | 
| 288 |  | 
| 289 | int | 
| 290 | cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) | 
| 291 | { | 
| 292 | FILE *outfile; | 
| 293 | int i = 0; | 
| 294 |  | 
| 295 | outfile = fopen(filename, "w"); | 
| 296 |  | 
| 297 | if (!outfile) | 
| 298 | { | 
| 299 | fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); | 
| 300 | return EXIT_FAILURE; | 
| 301 | } | 
| 302 |  | 
| 303 | i = cmdline_parser_dump(outfile, args_info); | 
| 304 | fclose (outfile); | 
| 305 |  | 
| 306 | return i; | 
| 307 | } | 
| 308 |  | 
| 309 | void | 
| 310 | cmdline_parser_free (struct gengetopt_args_info *args_info) | 
| 311 | { | 
| 312 | cmdline_parser_release (args_info); | 
| 313 | } | 
| 314 |  | 
| 315 | /** @brief replacement of strdup, which is not standard */ | 
| 316 | char * | 
| 317 | gengetopt_strdup (const char *s) | 
| 318 | { | 
| 319 | char *result = 0; | 
| 320 | if (!s) | 
| 321 | return result; | 
| 322 |  | 
| 323 | result = (char*)malloc(strlen(s) + 1); | 
| 324 | if (result == (char*)0) | 
| 325 | return (char*)0; | 
| 326 | strcpy(result, s); | 
| 327 | return result; | 
| 328 | } | 
| 329 |  | 
| 330 | static void | 
| 331 | reset_group_sequentialProps(struct gengetopt_args_info *args_info) | 
| 332 | { | 
| 333 | if (! args_info->sequentialProps_group_counter) | 
| 334 | return; | 
| 335 |  | 
| 336 | args_info->com_given = 0 ; | 
| 337 | args_info->ca1_given = 0 ; | 
| 338 | args_info->ca2_given = 0 ; | 
| 339 |  | 
| 340 | args_info->sequentialProps_group_counter = 0; | 
| 341 | } | 
| 342 |  | 
| 343 | int | 
| 344 | cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info) | 
| 345 | { | 
| 346 | return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); | 
| 347 | } | 
| 348 |  | 
| 349 | int | 
| 350 | cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info, | 
| 351 | struct cmdline_parser_params *params) | 
| 352 | { | 
| 353 | int result; | 
| 354 | result = cmdline_parser_internal (argc, argv, args_info, params, 0); | 
| 355 |  | 
| 356 | if (result == EXIT_FAILURE) | 
| 357 | { | 
| 358 | cmdline_parser_free (args_info); | 
| 359 | exit (EXIT_FAILURE); | 
| 360 | } | 
| 361 |  | 
| 362 | return result; | 
| 363 | } | 
| 364 |  | 
| 365 | int | 
| 366 | cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) | 
| 367 | { | 
| 368 | int result; | 
| 369 | struct cmdline_parser_params params; | 
| 370 |  | 
| 371 | params.override = override; | 
| 372 | params.initialize = initialize; | 
| 373 | params.check_required = check_required; | 
| 374 | params.check_ambiguity = 0; | 
| 375 | params.print_errors = 1; | 
| 376 |  | 
| 377 | result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); | 
| 378 |  | 
| 379 | if (result == EXIT_FAILURE) | 
| 380 | { | 
| 381 | cmdline_parser_free (args_info); | 
| 382 | exit (EXIT_FAILURE); | 
| 383 | } | 
| 384 |  | 
| 385 | return result; | 
| 386 | } | 
| 387 |  | 
| 388 | int | 
| 389 | cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) | 
| 390 | { | 
| 391 | int result = EXIT_SUCCESS; | 
| 392 |  | 
| 393 | if (cmdline_parser_required2(args_info, prog_name, 0) > 0) | 
| 394 | result = EXIT_FAILURE; | 
| 395 |  | 
| 396 | if (result == EXIT_FAILURE) | 
| 397 | { | 
| 398 | cmdline_parser_free (args_info); | 
| 399 | exit (EXIT_FAILURE); | 
| 400 | } | 
| 401 |  | 
| 402 | return result; | 
| 403 | } | 
| 404 |  | 
| 405 | int | 
| 406 | cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error) | 
| 407 | { | 
| 408 | int error = 0; | 
| 409 | FIX_UNUSED (additional_error); | 
| 410 |  | 
| 411 | /* checks for required options */ | 
| 412 | if (! args_info->input_given) | 
| 413 | { | 
| 414 | fprintf (stderr, "%s: '--input' ('-i') option required%s\n", prog_name, (additional_error ? additional_error : "")); | 
| 415 | error = 1; | 
| 416 | } | 
| 417 |  | 
| 418 | if (args_info->sequentialProps_group_counter == 0) | 
| 419 | { | 
| 420 | fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", prog_name, args_info->sequentialProps_group_counter, (additional_error ? additional_error : "")); | 
| 421 | error = 1; | 
| 422 | } | 
| 423 |  | 
| 424 |  | 
| 425 | /* checks for dependences among options */ | 
| 426 |  | 
| 427 | return error; | 
| 428 | } | 
| 429 |  | 
| 430 |  | 
| 431 | static char *package_name = 0; | 
| 432 |  | 
| 433 | /** | 
| 434 | * @brief updates an option | 
| 435 | * @param field the generic pointer to the field to update | 
| 436 | * @param orig_field the pointer to the orig field | 
| 437 | * @param field_given the pointer to the number of occurrence of this option | 
| 438 | * @param prev_given the pointer to the number of occurrence already seen | 
| 439 | * @param value the argument for this option (if null no arg was specified) | 
| 440 | * @param possible_values the possible values for this option (if specified) | 
| 441 | * @param default_value the default value (in case the option only accepts fixed values) | 
| 442 | * @param arg_type the type of this option | 
| 443 | * @param check_ambiguity @see cmdline_parser_params.check_ambiguity | 
| 444 | * @param override @see cmdline_parser_params.override | 
| 445 | * @param no_free whether to free a possible previous value | 
| 446 | * @param multiple_option whether this is a multiple option | 
| 447 | * @param long_opt the corresponding long option | 
| 448 | * @param short_opt the corresponding short option (or '-' if none) | 
| 449 | * @param additional_error possible further error specification | 
| 450 | */ | 
| 451 | static | 
| 452 | int update_arg(void *field, char **orig_field, | 
| 453 | unsigned int *field_given, unsigned int *prev_given, | 
| 454 | char *value, const char *possible_values[], | 
| 455 | const char *default_value, | 
| 456 | cmdline_parser_arg_type arg_type, | 
| 457 | int check_ambiguity, int override, | 
| 458 | int no_free, int multiple_option, | 
| 459 | const char *long_opt, char short_opt, | 
| 460 | const char *additional_error) | 
| 461 | { | 
| 462 | char *stop_char = 0; | 
| 463 | const char *val = value; | 
| 464 | int found; | 
| 465 | char **string_field; | 
| 466 | FIX_UNUSED (field); | 
| 467 |  | 
| 468 | stop_char = 0; | 
| 469 | found = 0; | 
| 470 |  | 
| 471 | if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) | 
| 472 | { | 
| 473 | if (short_opt != '-') | 
| 474 | fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", | 
| 475 | package_name, long_opt, short_opt, | 
| 476 | (additional_error ? additional_error : "")); | 
| 477 | else | 
| 478 | fprintf (stderr, "%s: `--%s' option given more than once%s\n", | 
| 479 | package_name, long_opt, | 
| 480 | (additional_error ? additional_error : "")); | 
| 481 | return 1; /* failure */ | 
| 482 | } | 
| 483 |  | 
| 484 | FIX_UNUSED (default_value); | 
| 485 |  | 
| 486 | if (field_given && *field_given && ! override) | 
| 487 | return 0; | 
| 488 | if (prev_given) | 
| 489 | (*prev_given)++; | 
| 490 | if (field_given) | 
| 491 | (*field_given)++; | 
| 492 | if (possible_values) | 
| 493 | val = possible_values[found]; | 
| 494 |  | 
| 495 | switch(arg_type) { | 
| 496 | case ARG_INT: | 
| 497 | if (val) *((int *)field) = strtol (val, &stop_char, 0); | 
| 498 | break; | 
| 499 | case ARG_DOUBLE: | 
| 500 | if (val) *((double *)field) = strtod (val, &stop_char); | 
| 501 | break; | 
| 502 | case ARG_STRING: | 
| 503 | if (val) { | 
| 504 | string_field = (char **)field; | 
| 505 | if (!no_free && *string_field) | 
| 506 | free (*string_field); /* free previous string */ | 
| 507 | *string_field = gengetopt_strdup (val); | 
| 508 | } | 
| 509 | break; | 
| 510 | default: | 
| 511 | break; | 
| 512 | }; | 
| 513 |  | 
| 514 | /* check numeric conversion */ | 
| 515 | switch(arg_type) { | 
| 516 | case ARG_INT: | 
| 517 | case ARG_DOUBLE: | 
| 518 | if (val && !(stop_char && *stop_char == '\0')) { | 
| 519 | fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val); | 
| 520 | return 1; /* failure */ | 
| 521 | } | 
| 522 | break; | 
| 523 | default: | 
| 524 | ; | 
| 525 | }; | 
| 526 |  | 
| 527 | /* store the original value */ | 
| 528 | switch(arg_type) { | 
| 529 | case ARG_NO: | 
| 530 | break; | 
| 531 | default: | 
| 532 | if (value && orig_field) { | 
| 533 | if (no_free) { | 
| 534 | *orig_field = value; | 
| 535 | } else { | 
| 536 | if (*orig_field) | 
| 537 | free (*orig_field); /* free previous string */ | 
| 538 | *orig_field = gengetopt_strdup (value); | 
| 539 | } | 
| 540 | } | 
| 541 | }; | 
| 542 |  | 
| 543 | return 0; /* OK */ | 
| 544 | } | 
| 545 |  | 
| 546 |  | 
| 547 | int | 
| 548 | cmdline_parser_internal ( | 
| 549 | int argc, char **argv, struct gengetopt_args_info *args_info, | 
| 550 | struct cmdline_parser_params *params, const char *additional_error) | 
| 551 | { | 
| 552 | int c;        /* Character of the parsed option.  */ | 
| 553 |  | 
| 554 | int error = 0; | 
| 555 | struct gengetopt_args_info local_args_info; | 
| 556 |  | 
| 557 | int override; | 
| 558 | int initialize; | 
| 559 | int check_required; | 
| 560 | int check_ambiguity; | 
| 561 |  | 
| 562 | package_name = argv[0]; | 
| 563 |  | 
| 564 | override = params->override; | 
| 565 | initialize = params->initialize; | 
| 566 | check_required = params->check_required; | 
| 567 | check_ambiguity = params->check_ambiguity; | 
| 568 |  | 
| 569 | if (initialize) | 
| 570 | cmdline_parser_init (args_info); | 
| 571 |  | 
| 572 | cmdline_parser_init (&local_args_info); | 
| 573 |  | 
| 574 | optarg = 0; | 
| 575 | optind = 0; | 
| 576 | opterr = params->print_errors; | 
| 577 | optopt = '?'; | 
| 578 |  | 
| 579 | while (1) | 
| 580 | { | 
| 581 | int option_index = 0; | 
| 582 |  | 
| 583 | static struct option long_options[] = { | 
| 584 | { "help",       0, NULL, 'h' }, | 
| 585 | { "version",    0, NULL, 'V' }, | 
| 586 | { "input",      1, NULL, 'i' }, | 
| 587 | { "output",     1, NULL, 'o' }, | 
| 588 | { "sele1",      1, NULL, 0 }, | 
| 589 | { "sele2",      1, NULL, 0 }, | 
| 590 | { "nbins",      1, NULL, 'n' }, | 
| 591 | { "referenceZ", 1, NULL, 'z' }, | 
| 592 | { "dropletR",   1, NULL, 'r' }, | 
| 593 | { "com",        0, NULL, 'c' }, | 
| 594 | { "ca1",        0, NULL, 0 }, | 
| 595 | { "ca2",        0, NULL, 0 }, | 
| 596 | { 0,  0, 0, 0 } | 
| 597 | }; | 
| 598 |  | 
| 599 | c = getopt_long (argc, argv, "hVi:o:n:z:r:c", long_options, &option_index); | 
| 600 |  | 
| 601 | if (c == -1) break;       /* Exit from `while (1)' loop.  */ | 
| 602 |  | 
| 603 | switch (c) | 
| 604 | { | 
| 605 | case 'h':       /* Print help and exit.  */ | 
| 606 | cmdline_parser_print_help (); | 
| 607 | cmdline_parser_free (&local_args_info); | 
| 608 | exit (EXIT_SUCCESS); | 
| 609 |  | 
| 610 | case 'V':       /* Print version and exit.  */ | 
| 611 | cmdline_parser_print_version (); | 
| 612 | cmdline_parser_free (&local_args_info); | 
| 613 | exit (EXIT_SUCCESS); | 
| 614 |  | 
| 615 | case 'i':       /* input dump file.  */ | 
| 616 |  | 
| 617 |  | 
| 618 | if (update_arg( (void *)&(args_info->input_arg), | 
| 619 | &(args_info->input_orig), &(args_info->input_given), | 
| 620 | &(local_args_info.input_given), optarg, 0, 0, ARG_STRING, | 
| 621 | check_ambiguity, override, 0, 0, | 
| 622 | "input", 'i', | 
| 623 | additional_error)) | 
| 624 | goto failure; | 
| 625 |  | 
| 626 | break; | 
| 627 | case 'o':       /* output file name.  */ | 
| 628 |  | 
| 629 |  | 
| 630 | if (update_arg( (void *)&(args_info->output_arg), | 
| 631 | &(args_info->output_orig), &(args_info->output_given), | 
| 632 | &(local_args_info.output_given), optarg, 0, 0, ARG_STRING, | 
| 633 | check_ambiguity, override, 0, 0, | 
| 634 | "output", 'o', | 
| 635 | additional_error)) | 
| 636 | goto failure; | 
| 637 |  | 
| 638 | break; | 
| 639 | case 'n':       /* Number of bins.  */ | 
| 640 |  | 
| 641 |  | 
| 642 | if (update_arg( (void *)&(args_info->nbins_arg), | 
| 643 | &(args_info->nbins_orig), &(args_info->nbins_given), | 
| 644 | &(local_args_info.nbins_given), optarg, 0, "100", ARG_INT, | 
| 645 | check_ambiguity, override, 0, 0, | 
| 646 | "nbins", 'n', | 
| 647 | additional_error)) | 
| 648 | goto failure; | 
| 649 |  | 
| 650 | break; | 
| 651 | case 'z':       /* Reference z-height of solid surface.  */ | 
| 652 |  | 
| 653 |  | 
| 654 | if (update_arg( (void *)&(args_info->referenceZ_arg), | 
| 655 | &(args_info->referenceZ_orig), &(args_info->referenceZ_given), | 
| 656 | &(local_args_info.referenceZ_given), optarg, 0, 0, ARG_DOUBLE, | 
| 657 | check_ambiguity, override, 0, 0, | 
| 658 | "referenceZ", 'z', | 
| 659 | additional_error)) | 
| 660 | goto failure; | 
| 661 |  | 
| 662 | break; | 
| 663 | case 'r':       /* Droplet radius in angstroms.  */ | 
| 664 |  | 
| 665 |  | 
| 666 | if (update_arg( (void *)&(args_info->dropletR_arg), | 
| 667 | &(args_info->dropletR_orig), &(args_info->dropletR_given), | 
| 668 | &(local_args_info.dropletR_given), optarg, 0, 0, ARG_DOUBLE, | 
| 669 | check_ambiguity, override, 0, 0, | 
| 670 | "dropletR", 'r', | 
| 671 | additional_error)) | 
| 672 | goto failure; | 
| 673 |  | 
| 674 | break; | 
| 675 | case 'c':       /* selection center of mass.  */ | 
| 676 |  | 
| 677 | if (args_info->sequentialProps_group_counter && override) | 
| 678 | reset_group_sequentialProps (args_info); | 
| 679 | args_info->sequentialProps_group_counter += 1; | 
| 680 |  | 
| 681 | if (update_arg( 0 , | 
| 682 | 0 , &(args_info->com_given), | 
| 683 | &(local_args_info.com_given), optarg, 0, 0, ARG_NO, | 
| 684 | check_ambiguity, override, 0, 0, | 
| 685 | "com", 'c', | 
| 686 | additional_error)) | 
| 687 | goto failure; | 
| 688 |  | 
| 689 | break; | 
| 690 |  | 
| 691 | case 0: /* Long option with no short option */ | 
| 692 | /* select first stuntdouble set.  */ | 
| 693 | if (strcmp (long_options[option_index].name, "sele1") == 0) | 
| 694 | { | 
| 695 |  | 
| 696 |  | 
| 697 | if (update_arg( (void *)&(args_info->sele1_arg), | 
| 698 | &(args_info->sele1_orig), &(args_info->sele1_given), | 
| 699 | &(local_args_info.sele1_given), optarg, 0, 0, ARG_STRING, | 
| 700 | check_ambiguity, override, 0, 0, | 
| 701 | "sele1", '-', | 
| 702 | additional_error)) | 
| 703 | goto failure; | 
| 704 |  | 
| 705 | } | 
| 706 | /* select second stuntdouble set (if sele2 is not set, use script from sele1).  */ | 
| 707 | else if (strcmp (long_options[option_index].name, "sele2") == 0) | 
| 708 | { | 
| 709 |  | 
| 710 |  | 
| 711 | if (update_arg( (void *)&(args_info->sele2_arg), | 
| 712 | &(args_info->sele2_orig), &(args_info->sele2_given), | 
| 713 | &(local_args_info.sele2_given), optarg, 0, 0, ARG_STRING, | 
| 714 | check_ambiguity, override, 0, 0, | 
| 715 | "sele2", '-', | 
| 716 | additional_error)) | 
| 717 | goto failure; | 
| 718 |  | 
| 719 | } | 
| 720 | /* contact angle of selection (using center of mass).  */ | 
| 721 | else if (strcmp (long_options[option_index].name, "ca1") == 0) | 
| 722 | { | 
| 723 |  | 
| 724 | if (args_info->sequentialProps_group_counter && override) | 
| 725 | reset_group_sequentialProps (args_info); | 
| 726 | args_info->sequentialProps_group_counter += 1; | 
| 727 |  | 
| 728 | if (update_arg( 0 , | 
| 729 | 0 , &(args_info->ca1_given), | 
| 730 | &(local_args_info.ca1_given), optarg, 0, 0, ARG_NO, | 
| 731 | check_ambiguity, override, 0, 0, | 
| 732 | "ca1", '-', | 
| 733 | additional_error)) | 
| 734 | goto failure; | 
| 735 |  | 
| 736 | } | 
| 737 | /* contact angle of selection (using density profile).  */ | 
| 738 | else if (strcmp (long_options[option_index].name, "ca2") == 0) | 
| 739 | { | 
| 740 |  | 
| 741 | if (args_info->sequentialProps_group_counter && override) | 
| 742 | reset_group_sequentialProps (args_info); | 
| 743 | args_info->sequentialProps_group_counter += 1; | 
| 744 |  | 
| 745 | if (update_arg( 0 , | 
| 746 | 0 , &(args_info->ca2_given), | 
| 747 | &(local_args_info.ca2_given), optarg, 0, 0, ARG_NO, | 
| 748 | check_ambiguity, override, 0, 0, | 
| 749 | "ca2", '-', | 
| 750 | additional_error)) | 
| 751 | goto failure; | 
| 752 |  | 
| 753 | } | 
| 754 |  | 
| 755 | break; | 
| 756 | case '?':       /* Invalid option.  */ | 
| 757 | /* `getopt_long' already printed an error message.  */ | 
| 758 | goto failure; | 
| 759 |  | 
| 760 | default:        /* bug: option not considered.  */ | 
| 761 | fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); | 
| 762 | abort (); | 
| 763 | } /* switch */ | 
| 764 | } /* while */ | 
| 765 |  | 
| 766 | if (args_info->sequentialProps_group_counter > 1) | 
| 767 | { | 
| 768 | fprintf (stderr, "%s: %d options of group sequentialProps were given. One is required%s.\n", argv[0], args_info->sequentialProps_group_counter, (additional_error ? additional_error : "")); | 
| 769 | error = 1; | 
| 770 | } | 
| 771 |  | 
| 772 |  | 
| 773 |  | 
| 774 | if (check_required) | 
| 775 | { | 
| 776 | error += cmdline_parser_required2 (args_info, argv[0], additional_error); | 
| 777 | } | 
| 778 |  | 
| 779 | cmdline_parser_release (&local_args_info); | 
| 780 |  | 
| 781 | if ( error ) | 
| 782 | return (EXIT_FAILURE); | 
| 783 |  | 
| 784 | if (optind < argc) | 
| 785 | { | 
| 786 | int i = 0 ; | 
| 787 | int found_prog_name = 0; | 
| 788 | /* whether program name, i.e., argv[0], is in the remaining args | 
| 789 | (this may happen with some implementations of getopt, | 
| 790 | but surely not with the one included by gengetopt) */ | 
| 791 |  | 
| 792 | i = optind; | 
| 793 | while (i < argc) | 
| 794 | if (argv[i++] == argv[0]) { | 
| 795 | found_prog_name = 1; | 
| 796 | break; | 
| 797 | } | 
| 798 | i = 0; | 
| 799 |  | 
| 800 | args_info->inputs_num = argc - optind - found_prog_name; | 
| 801 | args_info->inputs = | 
| 802 | (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; | 
| 803 | while (optind < argc) | 
| 804 | if (argv[optind++] != argv[0]) | 
| 805 | args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ; | 
| 806 | } | 
| 807 |  | 
| 808 | return 0; | 
| 809 |  | 
| 810 | failure: | 
| 811 |  | 
| 812 | cmdline_parser_release (&local_args_info); | 
| 813 | return (EXIT_FAILURE); | 
| 814 | } |