| 37 | 
  | 
  printf("\n"); | 
| 38 | 
  | 
  printf("  -h, --help                Print help and exit\n"); | 
| 39 | 
  | 
  printf("  -V, --version             Print version and exit\n"); | 
| 40 | 
– | 
  printf("  -I, --include=STRING      File name that should be included at the top of \n                              the output bass file.\n"); | 
| 40 | 
  | 
  printf("  -o, --output=STRING       Output file name\n"); | 
| 41 | 
< | 
  printf("      --latticetype=STRING  Lattice type string. Valid types are fcc,hcp,bcc \n                              and hcp-water.\n"); | 
| 41 | 
> | 
  printf("      --latticetype=STRING  Lattice type string. Valid types are fcc,hcp,bcc \n                              and hcp-water.  (default=`fcc')\n"); | 
| 42 | 
  | 
  printf("      --density=DOUBLE      density g/cm^3\n"); | 
| 43 | 
  | 
  printf("      --ndensity=DOUBLE     number density\n"); | 
| 44 | 
  | 
  printf("      --nx=INT              number of unit cells in x\n"); | 
| 45 | 
  | 
  printf("      --ny=INT              number of unit cells in y\n"); | 
| 46 | 
  | 
  printf("      --nz=INT              number of unit cells in z\n"); | 
| 48 | 
– | 
  printf("      --a1=DOUBLE           lattice spacing in Angstroms h - for cubic \n                              lattice, specify this parameter\n"); | 
| 49 | 
– | 
  printf("      --a2=DOUBLE           lattice spacing in Angstroms k\n"); | 
| 50 | 
– | 
  printf("      --a3=DOUBLE           lattice spacing in Angstroms l\n"); | 
| 47 | 
  | 
} | 
| 48 | 
  | 
 | 
| 49 | 
  | 
 | 
| 65 | 
  | 
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) | 
| 66 | 
  | 
{ | 
| 67 | 
  | 
  int c;        /* Character of the parsed option.  */ | 
| 72 | 
– | 
  int i;        /* Counter */ | 
| 73 | 
– | 
  struct include_list | 
| 74 | 
– | 
  { | 
| 75 | 
– | 
    char * include_arg; | 
| 76 | 
– | 
    struct include_list * next; | 
| 77 | 
– | 
  }; | 
| 78 | 
– | 
  struct include_list * include_list = NULL,* include_new = NULL; | 
| 79 | 
– | 
   | 
| 68 | 
  | 
  int missing_required_options = 0; | 
| 69 | 
  | 
 | 
| 70 | 
  | 
  args_info->help_given = 0 ; | 
| 71 | 
  | 
  args_info->version_given = 0 ; | 
| 84 | 
– | 
  args_info->include_given = 0 ; | 
| 72 | 
  | 
  args_info->output_given = 0 ; | 
| 73 | 
  | 
  args_info->latticetype_given = 0 ; | 
| 74 | 
  | 
  args_info->density_given = 0 ; | 
| 76 | 
  | 
  args_info->nx_given = 0 ; | 
| 77 | 
  | 
  args_info->ny_given = 0 ; | 
| 78 | 
  | 
  args_info->nz_given = 0 ; | 
| 92 | 
– | 
  args_info->a1_given = 0 ; | 
| 93 | 
– | 
  args_info->a2_given = 0 ; | 
| 94 | 
– | 
  args_info->a3_given = 0 ; | 
| 79 | 
  | 
#define clear_args() { \ | 
| 96 | 
– | 
  args_info->include_arg = NULL; \ | 
| 80 | 
  | 
  args_info->output_arg = NULL; \ | 
| 81 | 
< | 
  args_info->latticetype_arg = NULL; \ | 
| 81 | 
> | 
  args_info->latticetype_arg = gengetopt_strdup("fcc") ;\ | 
| 82 | 
  | 
} | 
| 83 | 
  | 
 | 
| 84 | 
  | 
  clear_args(); | 
| 99 | 
  | 
      static struct option long_options[] = { | 
| 100 | 
  | 
        { "help",       0, NULL, 'h' }, | 
| 101 | 
  | 
        { "version",    0, NULL, 'V' }, | 
| 119 | 
– | 
        { "include",    1, NULL, 'I' }, | 
| 102 | 
  | 
        { "output",     1, NULL, 'o' }, | 
| 103 | 
  | 
        { "latticetype",        1, NULL, 0 }, | 
| 104 | 
  | 
        { "density",    1, NULL, 0 }, | 
| 106 | 
  | 
        { "nx", 1, NULL, 0 }, | 
| 107 | 
  | 
        { "ny", 1, NULL, 0 }, | 
| 108 | 
  | 
        { "nz", 1, NULL, 0 }, | 
| 127 | 
– | 
        { "a1", 1, NULL, 0 }, | 
| 128 | 
– | 
        { "a2", 1, NULL, 0 }, | 
| 129 | 
– | 
        { "a3", 1, NULL, 0 }, | 
| 109 | 
  | 
        { NULL, 0, NULL, 0 } | 
| 110 | 
  | 
      }; | 
| 111 | 
  | 
 | 
| 112 | 
  | 
      stop_char = 0; | 
| 113 | 
< | 
      c = getopt_long (argc, argv, "hVI:o:", long_options, &option_index); | 
| 113 | 
> | 
      c = getopt_long (argc, argv, "hVo:", long_options, &option_index); | 
| 114 | 
  | 
 | 
| 115 | 
  | 
      if (c == -1) break;       /* Exit from `while (1)' loop.  */ | 
| 116 | 
  | 
 | 
| 126 | 
  | 
          cmdline_parser_print_version (); | 
| 127 | 
  | 
          exit (EXIT_SUCCESS); | 
| 128 | 
  | 
 | 
| 150 | 
– | 
        case 'I':       /* File name that should be included at the top of the output bass file..  */ | 
| 151 | 
– | 
          args_info->include_given++; | 
| 152 | 
– | 
          include_new = (struct include_list *) malloc (sizeof (struct include_list)); | 
| 153 | 
– | 
          include_new->next = include_list; | 
| 154 | 
– | 
          include_list = include_new; | 
| 155 | 
– | 
          include_new->include_arg = gengetopt_strdup (optarg); | 
| 156 | 
– | 
          break; | 
| 157 | 
– | 
 | 
| 129 | 
  | 
        case 'o':       /* Output file name.  */ | 
| 130 | 
  | 
          if (args_info->output_given) | 
| 131 | 
  | 
            { | 
| 149 | 
  | 
                exit (EXIT_FAILURE); | 
| 150 | 
  | 
              } | 
| 151 | 
  | 
            args_info->latticetype_given = 1; | 
| 152 | 
+ | 
            if (args_info->latticetype_arg) | 
| 153 | 
+ | 
              free (args_info->latticetype_arg); /* free default string */ | 
| 154 | 
  | 
            args_info->latticetype_arg = gengetopt_strdup (optarg); | 
| 155 | 
  | 
            break; | 
| 156 | 
  | 
          } | 
| 222 | 
  | 
              } | 
| 223 | 
  | 
            args_info->nz_given = 1; | 
| 224 | 
  | 
            args_info->nz_arg = strtol (optarg,&stop_char,0); | 
| 252 | 
– | 
            break; | 
| 253 | 
– | 
          } | 
| 254 | 
– | 
           | 
| 255 | 
– | 
          /* lattice spacing in Angstroms h - for cubic lattice, specify this parameter.  */ | 
| 256 | 
– | 
          else if (strcmp (long_options[option_index].name, "a1") == 0) | 
| 257 | 
– | 
          { | 
| 258 | 
– | 
            if (args_info->a1_given) | 
| 259 | 
– | 
              { | 
| 260 | 
– | 
                fprintf (stderr, "%s: `--a1' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 261 | 
– | 
                clear_args (); | 
| 262 | 
– | 
                exit (EXIT_FAILURE); | 
| 263 | 
– | 
              } | 
| 264 | 
– | 
            args_info->a1_given = 1; | 
| 265 | 
– | 
            args_info->a1_arg = strtod (optarg, NULL); | 
| 225 | 
  | 
            break; | 
| 226 | 
  | 
          } | 
| 227 | 
  | 
           | 
| 269 | 
– | 
          /* lattice spacing in Angstroms k.  */ | 
| 270 | 
– | 
          else if (strcmp (long_options[option_index].name, "a2") == 0) | 
| 271 | 
– | 
          { | 
| 272 | 
– | 
            if (args_info->a2_given) | 
| 273 | 
– | 
              { | 
| 274 | 
– | 
                fprintf (stderr, "%s: `--a2' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 275 | 
– | 
                clear_args (); | 
| 276 | 
– | 
                exit (EXIT_FAILURE); | 
| 277 | 
– | 
              } | 
| 278 | 
– | 
            args_info->a2_given = 1; | 
| 279 | 
– | 
            args_info->a2_arg = strtod (optarg, NULL); | 
| 280 | 
– | 
            break; | 
| 281 | 
– | 
          } | 
| 282 | 
– | 
           | 
| 283 | 
– | 
          /* lattice spacing in Angstroms l.  */ | 
| 284 | 
– | 
          else if (strcmp (long_options[option_index].name, "a3") == 0) | 
| 285 | 
– | 
          { | 
| 286 | 
– | 
            if (args_info->a3_given) | 
| 287 | 
– | 
              { | 
| 288 | 
– | 
                fprintf (stderr, "%s: `--a3' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 289 | 
– | 
                clear_args (); | 
| 290 | 
– | 
                exit (EXIT_FAILURE); | 
| 291 | 
– | 
              } | 
| 292 | 
– | 
            args_info->a3_given = 1; | 
| 293 | 
– | 
            args_info->a3_arg = strtod (optarg, NULL); | 
| 294 | 
– | 
            break; | 
| 295 | 
– | 
          } | 
| 296 | 
– | 
           | 
| 228 | 
  | 
 | 
| 229 | 
  | 
        case '?':       /* Invalid option.  */ | 
| 230 | 
  | 
          /* `getopt_long' already printed an error message.  */ | 
| 252 | 
  | 
      fprintf (stderr, "%s: '--nz' option required\n", CMDLINE_PARSER_PACKAGE); | 
| 253 | 
  | 
      missing_required_options = 1; | 
| 254 | 
  | 
    } | 
| 324 | 
– | 
  if (! args_info->a1_given) | 
| 325 | 
– | 
    { | 
| 326 | 
– | 
      fprintf (stderr, "%s: '--a1' option required\n", CMDLINE_PARSER_PACKAGE); | 
| 327 | 
– | 
      missing_required_options = 1; | 
| 328 | 
– | 
    } | 
| 255 | 
  | 
  if ( missing_required_options ) | 
| 256 | 
  | 
    exit (EXIT_FAILURE); | 
| 257 | 
  | 
 | 
| 332 | 
– | 
  if (args_info->include_given) | 
| 333 | 
– | 
    { | 
| 334 | 
– | 
      args_info->include_arg = (char * *) malloc (args_info->include_given * sizeof (char *)); | 
| 335 | 
– | 
      for (i = 0; i < args_info->include_given; i++) | 
| 336 | 
– | 
        { | 
| 337 | 
– | 
          args_info->include_arg [i] = include_list->include_arg; | 
| 338 | 
– | 
          include_list = include_list->next; | 
| 339 | 
– | 
        } | 
| 340 | 
– | 
    } | 
| 341 | 
– | 
   | 
| 258 | 
  | 
  if (optind < argc) | 
| 259 | 
  | 
    { | 
| 260 | 
  | 
      int i = 0 ; |