1 |
/* |
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 |
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"); |
47 |
} |
48 |
|
49 |
|
50 |
static char *gengetopt_strdup (const char *s); |
51 |
|
52 |
/* gengetopt_strdup() */ |
53 |
/* strdup.c replacement of strdup, which is not standard */ |
54 |
char * |
55 |
gengetopt_strdup (const char *s) |
56 |
{ |
57 |
char *result = (char*)malloc(strlen(s) + 1); |
58 |
if (result == (char*)0) |
59 |
return (char*)0; |
60 |
strcpy(result, s); |
61 |
return result; |
62 |
} |
63 |
|
64 |
int |
65 |
cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) |
66 |
{ |
67 |
int c; /* Character of the parsed option. */ |
68 |
int missing_required_options = 0; |
69 |
|
70 |
args_info->help_given = 0 ; |
71 |
args_info->version_given = 0 ; |
72 |
args_info->output_given = 0 ; |
73 |
args_info->latticetype_given = 0 ; |
74 |
args_info->density_given = 0 ; |
75 |
args_info->ndensity_given = 0 ; |
76 |
args_info->nx_given = 0 ; |
77 |
args_info->ny_given = 0 ; |
78 |
args_info->nz_given = 0 ; |
79 |
#define clear_args() { \ |
80 |
args_info->output_arg = NULL; \ |
81 |
args_info->latticetype_arg = gengetopt_strdup("fcc") ;\ |
82 |
} |
83 |
|
84 |
clear_args(); |
85 |
|
86 |
args_info->inputs = NULL; |
87 |
args_info->inputs_num = 0; |
88 |
|
89 |
optarg = 0; |
90 |
optind = 1; |
91 |
opterr = 1; |
92 |
optopt = '?'; |
93 |
|
94 |
while (1) |
95 |
{ |
96 |
int option_index = 0; |
97 |
char *stop_char; |
98 |
|
99 |
static struct option long_options[] = { |
100 |
{ "help", 0, NULL, 'h' }, |
101 |
{ "version", 0, NULL, 'V' }, |
102 |
{ "output", 1, NULL, 'o' }, |
103 |
{ "latticetype", 1, NULL, 0 }, |
104 |
{ "density", 1, NULL, 0 }, |
105 |
{ "ndensity", 1, NULL, 0 }, |
106 |
{ "nx", 1, NULL, 0 }, |
107 |
{ "ny", 1, NULL, 0 }, |
108 |
{ "nz", 1, NULL, 0 }, |
109 |
{ NULL, 0, NULL, 0 } |
110 |
}; |
111 |
|
112 |
stop_char = 0; |
113 |
c = getopt_long (argc, argv, "hVo:", long_options, &option_index); |
114 |
|
115 |
if (c == -1) break; /* Exit from `while (1)' loop. */ |
116 |
|
117 |
switch (c) |
118 |
{ |
119 |
case 'h': /* Print help and exit. */ |
120 |
clear_args (); |
121 |
cmdline_parser_print_help (); |
122 |
exit (EXIT_SUCCESS); |
123 |
|
124 |
case 'V': /* Print version and exit. */ |
125 |
clear_args (); |
126 |
cmdline_parser_print_version (); |
127 |
exit (EXIT_SUCCESS); |
128 |
|
129 |
case 'o': /* Output file name. */ |
130 |
if (args_info->output_given) |
131 |
{ |
132 |
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
133 |
clear_args (); |
134 |
exit (EXIT_FAILURE); |
135 |
} |
136 |
args_info->output_given = 1; |
137 |
args_info->output_arg = gengetopt_strdup (optarg); |
138 |
break; |
139 |
|
140 |
|
141 |
case 0: /* Long option with no short option */ |
142 |
/* Lattice type string. Valid types are fcc,hcp,bcc and hcp-water.. */ |
143 |
if (strcmp (long_options[option_index].name, "latticetype") == 0) |
144 |
{ |
145 |
if (args_info->latticetype_given) |
146 |
{ |
147 |
fprintf (stderr, "%s: `--latticetype' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
148 |
clear_args (); |
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 |
} |
157 |
|
158 |
/* density g/cm^3. */ |
159 |
else if (strcmp (long_options[option_index].name, "density") == 0) |
160 |
{ |
161 |
if (args_info->density_given) |
162 |
{ |
163 |
fprintf (stderr, "%s: `--density' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
164 |
clear_args (); |
165 |
exit (EXIT_FAILURE); |
166 |
} |
167 |
args_info->density_given = 1; |
168 |
args_info->density_arg = strtod (optarg, NULL); |
169 |
break; |
170 |
} |
171 |
|
172 |
/* number density. */ |
173 |
else if (strcmp (long_options[option_index].name, "ndensity") == 0) |
174 |
{ |
175 |
if (args_info->ndensity_given) |
176 |
{ |
177 |
fprintf (stderr, "%s: `--ndensity' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
178 |
clear_args (); |
179 |
exit (EXIT_FAILURE); |
180 |
} |
181 |
args_info->ndensity_given = 1; |
182 |
args_info->ndensity_arg = strtod (optarg, NULL); |
183 |
break; |
184 |
} |
185 |
|
186 |
/* number of unit cells in x. */ |
187 |
else if (strcmp (long_options[option_index].name, "nx") == 0) |
188 |
{ |
189 |
if (args_info->nx_given) |
190 |
{ |
191 |
fprintf (stderr, "%s: `--nx' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
192 |
clear_args (); |
193 |
exit (EXIT_FAILURE); |
194 |
} |
195 |
args_info->nx_given = 1; |
196 |
args_info->nx_arg = strtol (optarg,&stop_char,0); |
197 |
break; |
198 |
} |
199 |
|
200 |
/* number of unit cells in y. */ |
201 |
else if (strcmp (long_options[option_index].name, "ny") == 0) |
202 |
{ |
203 |
if (args_info->ny_given) |
204 |
{ |
205 |
fprintf (stderr, "%s: `--ny' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
206 |
clear_args (); |
207 |
exit (EXIT_FAILURE); |
208 |
} |
209 |
args_info->ny_given = 1; |
210 |
args_info->ny_arg = strtol (optarg,&stop_char,0); |
211 |
break; |
212 |
} |
213 |
|
214 |
/* number of unit cells in z. */ |
215 |
else if (strcmp (long_options[option_index].name, "nz") == 0) |
216 |
{ |
217 |
if (args_info->nz_given) |
218 |
{ |
219 |
fprintf (stderr, "%s: `--nz' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
220 |
clear_args (); |
221 |
exit (EXIT_FAILURE); |
222 |
} |
223 |
args_info->nz_given = 1; |
224 |
args_info->nz_arg = strtol (optarg,&stop_char,0); |
225 |
break; |
226 |
} |
227 |
|
228 |
|
229 |
case '?': /* Invalid option. */ |
230 |
/* `getopt_long' already printed an error message. */ |
231 |
exit (EXIT_FAILURE); |
232 |
|
233 |
default: /* bug: option not considered. */ |
234 |
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
235 |
abort (); |
236 |
} /* switch */ |
237 |
} /* while */ |
238 |
|
239 |
|
240 |
if (! args_info->nx_given) |
241 |
{ |
242 |
fprintf (stderr, "%s: '--nx' option required\n", CMDLINE_PARSER_PACKAGE); |
243 |
missing_required_options = 1; |
244 |
} |
245 |
if (! args_info->ny_given) |
246 |
{ |
247 |
fprintf (stderr, "%s: '--ny' option required\n", CMDLINE_PARSER_PACKAGE); |
248 |
missing_required_options = 1; |
249 |
} |
250 |
if (! args_info->nz_given) |
251 |
{ |
252 |
fprintf (stderr, "%s: '--nz' option required\n", CMDLINE_PARSER_PACKAGE); |
253 |
missing_required_options = 1; |
254 |
} |
255 |
if ( missing_required_options ) |
256 |
exit (EXIT_FAILURE); |
257 |
|
258 |
if (optind < argc) |
259 |
{ |
260 |
int i = 0 ; |
261 |
|
262 |
args_info->inputs_num = argc - optind ; |
263 |
args_info->inputs = |
264 |
(char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; |
265 |
while (optind < argc) |
266 |
args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; |
267 |
} |
268 |
|
269 |
return 0; |
270 |
} |