| 1 | 
tim | 
1424 | 
/* | 
| 2 | 
  | 
  | 
  File autogenerated by gengetopt version 2.11 | 
| 3 | 
  | 
  | 
  generated with the following command: | 
| 4 | 
  | 
  | 
  /home/maul/gezelter/tim/program/gengetopt-2.11/src/gengetopt -F simpleBuilderCmd -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 | 
  | 
  | 
 | 
| 12 | 
  | 
  | 
#include <stdio.h> | 
| 13 | 
  | 
  | 
#include <stdlib.h> | 
| 14 | 
  | 
  | 
#include <string.h> | 
| 15 | 
  | 
  | 
 | 
| 16 | 
  | 
  | 
/* If we use autoconf.  */ | 
| 17 | 
  | 
  | 
#ifdef HAVE_CONFIG_H | 
| 18 | 
  | 
  | 
#include "config.h" | 
| 19 | 
  | 
  | 
#endif | 
| 20 | 
  | 
  | 
 | 
| 21 | 
  | 
  | 
#include "getopt.h" | 
| 22 | 
  | 
  | 
 | 
| 23 | 
  | 
  | 
#include "simpleBuilderCmd.h" | 
| 24 | 
  | 
  | 
 | 
| 25 | 
  | 
  | 
void | 
| 26 | 
  | 
  | 
cmdline_parser_print_version (void) | 
| 27 | 
  | 
  | 
{ | 
| 28 | 
  | 
  | 
  printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); | 
| 29 | 
  | 
  | 
} | 
| 30 | 
  | 
  | 
 | 
| 31 | 
  | 
  | 
void | 
| 32 | 
  | 
  | 
cmdline_parser_print_help (void) | 
| 33 | 
  | 
  | 
{ | 
| 34 | 
  | 
  | 
  cmdline_parser_print_version (); | 
| 35 | 
  | 
  | 
  printf("\n" | 
| 36 | 
  | 
  | 
  "Usage: %s [OPTIONS]... [FILES]...\n", CMDLINE_PARSER_PACKAGE); | 
| 37 | 
  | 
  | 
  printf("\n"); | 
| 38 | 
  | 
  | 
  printf("  -h, --help                Print help and exit\n"); | 
| 39 | 
  | 
  | 
  printf("  -V, --version             Print version and exit\n"); | 
| 40 | 
  | 
  | 
  printf("  -o, --output=STRING       Output file name\n"); | 
| 41 | 
tim | 
1432 | 
  printf("      --latticetype=STRING  Lattice type string. Valid types are fcc,hcp,bcc \n                              and hcp-water.  (default=`fcc')\n"); | 
| 42 | 
tim | 
1436 | 
  printf("      --density=DOUBLE      density (g/cm^3)\n"); | 
| 43 | 
tim | 
1424 | 
  printf("      --nx=INT              number of unit cells in x\n"); | 
| 44 | 
  | 
  | 
  printf("      --ny=INT              number of unit cells in y\n"); | 
| 45 | 
  | 
  | 
  printf("      --nz=INT              number of unit cells in z\n"); | 
| 46 | 
  | 
  | 
} | 
| 47 | 
  | 
  | 
 | 
| 48 | 
  | 
  | 
 | 
| 49 | 
  | 
  | 
static char *gengetopt_strdup (const char *s); | 
| 50 | 
  | 
  | 
 | 
| 51 | 
  | 
  | 
/* gengetopt_strdup() */ | 
| 52 | 
  | 
  | 
/* strdup.c replacement of strdup, which is not standard */ | 
| 53 | 
  | 
  | 
char * | 
| 54 | 
  | 
  | 
gengetopt_strdup (const char *s) | 
| 55 | 
  | 
  | 
{ | 
| 56 | 
  | 
  | 
  char *result = (char*)malloc(strlen(s) + 1); | 
| 57 | 
  | 
  | 
  if (result == (char*)0) | 
| 58 | 
  | 
  | 
    return (char*)0; | 
| 59 | 
  | 
  | 
  strcpy(result, s); | 
| 60 | 
  | 
  | 
  return result; | 
| 61 | 
  | 
  | 
} | 
| 62 | 
  | 
  | 
 | 
| 63 | 
  | 
  | 
int | 
| 64 | 
  | 
  | 
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) | 
| 65 | 
  | 
  | 
{ | 
| 66 | 
  | 
  | 
  int c;        /* Character of the parsed option.  */ | 
| 67 | 
  | 
  | 
  int missing_required_options = 0; | 
| 68 | 
  | 
  | 
 | 
| 69 | 
  | 
  | 
  args_info->help_given = 0 ; | 
| 70 | 
  | 
  | 
  args_info->version_given = 0 ; | 
| 71 | 
  | 
  | 
  args_info->output_given = 0 ; | 
| 72 | 
  | 
  | 
  args_info->latticetype_given = 0 ; | 
| 73 | 
  | 
  | 
  args_info->density_given = 0 ; | 
| 74 | 
  | 
  | 
  args_info->nx_given = 0 ; | 
| 75 | 
  | 
  | 
  args_info->ny_given = 0 ; | 
| 76 | 
  | 
  | 
  args_info->nz_given = 0 ; | 
| 77 | 
  | 
  | 
#define clear_args() { \ | 
| 78 | 
  | 
  | 
  args_info->output_arg = NULL; \ | 
| 79 | 
tim | 
1432 | 
  args_info->latticetype_arg = gengetopt_strdup("fcc") ;\ | 
| 80 | 
tim | 
1424 | 
} | 
| 81 | 
  | 
  | 
 | 
| 82 | 
  | 
  | 
  clear_args(); | 
| 83 | 
  | 
  | 
 | 
| 84 | 
  | 
  | 
  args_info->inputs = NULL; | 
| 85 | 
  | 
  | 
  args_info->inputs_num = 0; | 
| 86 | 
  | 
  | 
 | 
| 87 | 
  | 
  | 
  optarg = 0; | 
| 88 | 
  | 
  | 
  optind = 1; | 
| 89 | 
  | 
  | 
  opterr = 1; | 
| 90 | 
  | 
  | 
  optopt = '?'; | 
| 91 | 
  | 
  | 
 | 
| 92 | 
  | 
  | 
  while (1) | 
| 93 | 
  | 
  | 
    { | 
| 94 | 
  | 
  | 
      int option_index = 0; | 
| 95 | 
  | 
  | 
      char *stop_char; | 
| 96 | 
  | 
  | 
 | 
| 97 | 
  | 
  | 
      static struct option long_options[] = { | 
| 98 | 
  | 
  | 
        { "help",       0, NULL, 'h' }, | 
| 99 | 
  | 
  | 
        { "version",    0, NULL, 'V' }, | 
| 100 | 
  | 
  | 
        { "output",     1, NULL, 'o' }, | 
| 101 | 
  | 
  | 
        { "latticetype",        1, NULL, 0 }, | 
| 102 | 
  | 
  | 
        { "density",    1, NULL, 0 }, | 
| 103 | 
  | 
  | 
        { "nx", 1, NULL, 0 }, | 
| 104 | 
  | 
  | 
        { "ny", 1, NULL, 0 }, | 
| 105 | 
  | 
  | 
        { "nz", 1, NULL, 0 }, | 
| 106 | 
  | 
  | 
        { NULL, 0, NULL, 0 } | 
| 107 | 
  | 
  | 
      }; | 
| 108 | 
  | 
  | 
 | 
| 109 | 
  | 
  | 
      stop_char = 0; | 
| 110 | 
tim | 
1432 | 
      c = getopt_long (argc, argv, "hVo:", long_options, &option_index); | 
| 111 | 
tim | 
1424 | 
 | 
| 112 | 
  | 
  | 
      if (c == -1) break;       /* Exit from `while (1)' loop.  */ | 
| 113 | 
  | 
  | 
 | 
| 114 | 
  | 
  | 
      switch (c) | 
| 115 | 
  | 
  | 
        { | 
| 116 | 
  | 
  | 
        case 'h':       /* Print help and exit.  */ | 
| 117 | 
  | 
  | 
          clear_args (); | 
| 118 | 
  | 
  | 
          cmdline_parser_print_help (); | 
| 119 | 
  | 
  | 
          exit (EXIT_SUCCESS); | 
| 120 | 
  | 
  | 
 | 
| 121 | 
  | 
  | 
        case 'V':       /* Print version and exit.  */ | 
| 122 | 
  | 
  | 
          clear_args (); | 
| 123 | 
  | 
  | 
          cmdline_parser_print_version (); | 
| 124 | 
  | 
  | 
          exit (EXIT_SUCCESS); | 
| 125 | 
  | 
  | 
 | 
| 126 | 
  | 
  | 
        case 'o':       /* Output file name.  */ | 
| 127 | 
  | 
  | 
          if (args_info->output_given) | 
| 128 | 
  | 
  | 
            { | 
| 129 | 
  | 
  | 
              fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 130 | 
  | 
  | 
              clear_args (); | 
| 131 | 
  | 
  | 
              exit (EXIT_FAILURE); | 
| 132 | 
  | 
  | 
            } | 
| 133 | 
  | 
  | 
          args_info->output_given = 1; | 
| 134 | 
  | 
  | 
          args_info->output_arg = gengetopt_strdup (optarg); | 
| 135 | 
  | 
  | 
          break; | 
| 136 | 
  | 
  | 
 | 
| 137 | 
  | 
  | 
 | 
| 138 | 
  | 
  | 
        case 0: /* Long option with no short option */ | 
| 139 | 
  | 
  | 
          /* Lattice type string. Valid types are fcc,hcp,bcc and hcp-water..  */ | 
| 140 | 
  | 
  | 
          if (strcmp (long_options[option_index].name, "latticetype") == 0) | 
| 141 | 
  | 
  | 
          { | 
| 142 | 
  | 
  | 
            if (args_info->latticetype_given) | 
| 143 | 
  | 
  | 
              { | 
| 144 | 
  | 
  | 
                fprintf (stderr, "%s: `--latticetype' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 145 | 
  | 
  | 
                clear_args (); | 
| 146 | 
  | 
  | 
                exit (EXIT_FAILURE); | 
| 147 | 
  | 
  | 
              } | 
| 148 | 
  | 
  | 
            args_info->latticetype_given = 1; | 
| 149 | 
tim | 
1432 | 
            if (args_info->latticetype_arg) | 
| 150 | 
  | 
  | 
              free (args_info->latticetype_arg); /* free default string */ | 
| 151 | 
tim | 
1424 | 
            args_info->latticetype_arg = gengetopt_strdup (optarg); | 
| 152 | 
  | 
  | 
            break; | 
| 153 | 
  | 
  | 
          } | 
| 154 | 
  | 
  | 
           | 
| 155 | 
tim | 
1436 | 
          /* density (g/cm^3).  */ | 
| 156 | 
tim | 
1424 | 
          else if (strcmp (long_options[option_index].name, "density") == 0) | 
| 157 | 
  | 
  | 
          { | 
| 158 | 
  | 
  | 
            if (args_info->density_given) | 
| 159 | 
  | 
  | 
              { | 
| 160 | 
  | 
  | 
                fprintf (stderr, "%s: `--density' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 161 | 
  | 
  | 
                clear_args (); | 
| 162 | 
  | 
  | 
                exit (EXIT_FAILURE); | 
| 163 | 
  | 
  | 
              } | 
| 164 | 
  | 
  | 
            args_info->density_given = 1; | 
| 165 | 
  | 
  | 
            args_info->density_arg = strtod (optarg, NULL); | 
| 166 | 
  | 
  | 
            break; | 
| 167 | 
  | 
  | 
          } | 
| 168 | 
  | 
  | 
           | 
| 169 | 
  | 
  | 
          /* number of unit cells in x.  */ | 
| 170 | 
  | 
  | 
          else if (strcmp (long_options[option_index].name, "nx") == 0) | 
| 171 | 
  | 
  | 
          { | 
| 172 | 
  | 
  | 
            if (args_info->nx_given) | 
| 173 | 
  | 
  | 
              { | 
| 174 | 
  | 
  | 
                fprintf (stderr, "%s: `--nx' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 175 | 
  | 
  | 
                clear_args (); | 
| 176 | 
  | 
  | 
                exit (EXIT_FAILURE); | 
| 177 | 
  | 
  | 
              } | 
| 178 | 
  | 
  | 
            args_info->nx_given = 1; | 
| 179 | 
  | 
  | 
            args_info->nx_arg = strtol (optarg,&stop_char,0); | 
| 180 | 
  | 
  | 
            break; | 
| 181 | 
  | 
  | 
          } | 
| 182 | 
  | 
  | 
           | 
| 183 | 
  | 
  | 
          /* number of unit cells in y.  */ | 
| 184 | 
  | 
  | 
          else if (strcmp (long_options[option_index].name, "ny") == 0) | 
| 185 | 
  | 
  | 
          { | 
| 186 | 
  | 
  | 
            if (args_info->ny_given) | 
| 187 | 
  | 
  | 
              { | 
| 188 | 
  | 
  | 
                fprintf (stderr, "%s: `--ny' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 189 | 
  | 
  | 
                clear_args (); | 
| 190 | 
  | 
  | 
                exit (EXIT_FAILURE); | 
| 191 | 
  | 
  | 
              } | 
| 192 | 
  | 
  | 
            args_info->ny_given = 1; | 
| 193 | 
  | 
  | 
            args_info->ny_arg = strtol (optarg,&stop_char,0); | 
| 194 | 
  | 
  | 
            break; | 
| 195 | 
  | 
  | 
          } | 
| 196 | 
  | 
  | 
           | 
| 197 | 
  | 
  | 
          /* number of unit cells in z.  */ | 
| 198 | 
  | 
  | 
          else if (strcmp (long_options[option_index].name, "nz") == 0) | 
| 199 | 
  | 
  | 
          { | 
| 200 | 
  | 
  | 
            if (args_info->nz_given) | 
| 201 | 
  | 
  | 
              { | 
| 202 | 
  | 
  | 
                fprintf (stderr, "%s: `--nz' option given more than once\n", CMDLINE_PARSER_PACKAGE); | 
| 203 | 
  | 
  | 
                clear_args (); | 
| 204 | 
  | 
  | 
                exit (EXIT_FAILURE); | 
| 205 | 
  | 
  | 
              } | 
| 206 | 
  | 
  | 
            args_info->nz_given = 1; | 
| 207 | 
  | 
  | 
            args_info->nz_arg = strtol (optarg,&stop_char,0); | 
| 208 | 
  | 
  | 
            break; | 
| 209 | 
  | 
  | 
          } | 
| 210 | 
  | 
  | 
           | 
| 211 | 
  | 
  | 
 | 
| 212 | 
  | 
  | 
        case '?':       /* Invalid option.  */ | 
| 213 | 
  | 
  | 
          /* `getopt_long' already printed an error message.  */ | 
| 214 | 
  | 
  | 
          exit (EXIT_FAILURE); | 
| 215 | 
  | 
  | 
 | 
| 216 | 
  | 
  | 
        default:        /* bug: option not considered.  */ | 
| 217 | 
  | 
  | 
          fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); | 
| 218 | 
  | 
  | 
          abort (); | 
| 219 | 
  | 
  | 
        } /* switch */ | 
| 220 | 
  | 
  | 
    } /* while */ | 
| 221 | 
  | 
  | 
 | 
| 222 | 
  | 
  | 
 | 
| 223 | 
tim | 
1436 | 
  if (! args_info->density_given) | 
| 224 | 
  | 
  | 
    { | 
| 225 | 
  | 
  | 
      fprintf (stderr, "%s: '--density' option required\n", CMDLINE_PARSER_PACKAGE); | 
| 226 | 
  | 
  | 
      missing_required_options = 1; | 
| 227 | 
  | 
  | 
    } | 
| 228 | 
tim | 
1424 | 
  if (! args_info->nx_given) | 
| 229 | 
  | 
  | 
    { | 
| 230 | 
  | 
  | 
      fprintf (stderr, "%s: '--nx' option required\n", CMDLINE_PARSER_PACKAGE); | 
| 231 | 
  | 
  | 
      missing_required_options = 1; | 
| 232 | 
  | 
  | 
    } | 
| 233 | 
  | 
  | 
  if (! args_info->ny_given) | 
| 234 | 
  | 
  | 
    { | 
| 235 | 
  | 
  | 
      fprintf (stderr, "%s: '--ny' option required\n", CMDLINE_PARSER_PACKAGE); | 
| 236 | 
  | 
  | 
      missing_required_options = 1; | 
| 237 | 
  | 
  | 
    } | 
| 238 | 
  | 
  | 
  if (! args_info->nz_given) | 
| 239 | 
  | 
  | 
    { | 
| 240 | 
  | 
  | 
      fprintf (stderr, "%s: '--nz' option required\n", CMDLINE_PARSER_PACKAGE); | 
| 241 | 
  | 
  | 
      missing_required_options = 1; | 
| 242 | 
  | 
  | 
    } | 
| 243 | 
  | 
  | 
  if ( missing_required_options ) | 
| 244 | 
  | 
  | 
    exit (EXIT_FAILURE); | 
| 245 | 
  | 
  | 
 | 
| 246 | 
  | 
  | 
  if (optind < argc) | 
| 247 | 
  | 
  | 
    { | 
| 248 | 
  | 
  | 
      int i = 0 ; | 
| 249 | 
  | 
  | 
   | 
| 250 | 
  | 
  | 
      args_info->inputs_num = argc - optind ; | 
| 251 | 
  | 
  | 
      args_info->inputs =  | 
| 252 | 
  | 
  | 
        (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; | 
| 253 | 
  | 
  | 
      while (optind < argc) | 
| 254 | 
  | 
  | 
        args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;  | 
| 255 | 
  | 
  | 
    } | 
| 256 | 
  | 
  | 
   | 
| 257 | 
  | 
  | 
  return 0; | 
| 258 | 
  | 
  | 
} |