ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-4/src/applications/thermalizer/thermalizerCmd.c
Revision: 3059
Committed: Fri Oct 20 14:59:05 2006 UTC (17 years, 8 months ago) by gezelter
Content type: text/plain
File size: 10898 byte(s)
Log Message:
more openbabel updates, also changing velocitizer to thermalizer to
avoid a filename collision on case-insensitve file systems

File Contents

# Content
1 /*
2 File autogenerated by gengetopt version 2.17
3 generated with the following command:
4 gengetopt -F thermalizerCmd --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 #include "getopt.h"
21
22 #include "thermalizerCmd.h"
23
24 const char *gengetopt_args_info_purpose = "Resamples the velocities for all the integrable objects in an OOPSE file from a \nMaxwell-Boltzmann distribution.";
25
26 const char *gengetopt_args_info_usage = "Usage: thermalizer [OPTIONS]... [FILES]...";
27
28 const char *gengetopt_args_info_help[] = {
29 " -h, --help Print help and exit",
30 " -V, --version Print version and exit",
31 " -o, --output=STRING Output file name",
32 " -t, --temperature=DOUBLE temperature (K)",
33 0
34 };
35
36 static
37 void clear_given (struct gengetopt_args_info *args_info);
38 static
39 void clear_args (struct gengetopt_args_info *args_info);
40
41 static int
42 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
43
44 static int
45 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error);
46
47 static char *
48 gengetopt_strdup (const char *s);
49
50 static
51 void clear_given (struct gengetopt_args_info *args_info)
52 {
53 args_info->help_given = 0 ;
54 args_info->version_given = 0 ;
55 args_info->output_given = 0 ;
56 args_info->temperature_given = 0 ;
57 }
58
59 static
60 void clear_args (struct gengetopt_args_info *args_info)
61 {
62 args_info->output_arg = NULL;
63 args_info->output_orig = NULL;
64 args_info->temperature_orig = NULL;
65
66 }
67
68 static
69 void init_args_info(struct gengetopt_args_info *args_info)
70 {
71 args_info->help_help = gengetopt_args_info_help[0] ;
72 args_info->version_help = gengetopt_args_info_help[1] ;
73 args_info->output_help = gengetopt_args_info_help[2] ;
74 args_info->temperature_help = gengetopt_args_info_help[3] ;
75
76 }
77
78 void
79 cmdline_parser_print_version (void)
80 {
81 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
82 }
83
84 void
85 cmdline_parser_print_help (void)
86 {
87 int i = 0;
88 cmdline_parser_print_version ();
89
90 if (strlen(gengetopt_args_info_purpose) > 0)
91 printf("\n%s\n", gengetopt_args_info_purpose);
92
93 printf("\n%s\n\n", gengetopt_args_info_usage);
94 while (gengetopt_args_info_help[i])
95 printf("%s\n", gengetopt_args_info_help[i++]);
96 }
97
98 void
99 cmdline_parser_init (struct gengetopt_args_info *args_info)
100 {
101 clear_given (args_info);
102 clear_args (args_info);
103 init_args_info (args_info);
104
105 args_info->inputs = NULL;
106 args_info->inputs_num = 0;
107 }
108
109 static void
110 cmdline_parser_release (struct gengetopt_args_info *args_info)
111 {
112
113 unsigned int i;
114 if (args_info->output_arg)
115 {
116 free (args_info->output_arg); /* free previous argument */
117 args_info->output_arg = 0;
118 }
119 if (args_info->output_orig)
120 {
121 free (args_info->output_orig); /* free previous argument */
122 args_info->output_orig = 0;
123 }
124 if (args_info->temperature_orig)
125 {
126 free (args_info->temperature_orig); /* free previous argument */
127 args_info->temperature_orig = 0;
128 }
129
130 for (i = 0; i < args_info->inputs_num; ++i)
131 free (args_info->inputs [i]);
132
133 if (args_info->inputs_num)
134 free (args_info->inputs);
135
136 clear_given (args_info);
137 }
138
139 int
140 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
141 {
142 FILE *outfile;
143 int i = 0;
144
145 outfile = fopen(filename, "w");
146
147 if (!outfile)
148 {
149 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
150 return EXIT_FAILURE;
151 }
152
153 if (args_info->help_given) {
154 fprintf(outfile, "%s\n", "help");
155 }
156 if (args_info->version_given) {
157 fprintf(outfile, "%s\n", "version");
158 }
159 if (args_info->output_given) {
160 if (args_info->output_orig) {
161 fprintf(outfile, "%s=\"%s\"\n", "output", args_info->output_orig);
162 } else {
163 fprintf(outfile, "%s\n", "output");
164 }
165 }
166 if (args_info->temperature_given) {
167 if (args_info->temperature_orig) {
168 fprintf(outfile, "%s=\"%s\"\n", "temperature", args_info->temperature_orig);
169 } else {
170 fprintf(outfile, "%s\n", "temperature");
171 }
172 }
173
174 fclose (outfile);
175
176 i = EXIT_SUCCESS;
177 return i;
178 }
179
180 void
181 cmdline_parser_free (struct gengetopt_args_info *args_info)
182 {
183 cmdline_parser_release (args_info);
184 }
185
186
187 /* gengetopt_strdup() */
188 /* strdup.c replacement of strdup, which is not standard */
189 char *
190 gengetopt_strdup (const char *s)
191 {
192 char *result = NULL;
193 if (!s)
194 return result;
195
196 result = (char*)malloc(strlen(s) + 1);
197 if (result == (char*)0)
198 return (char*)0;
199 strcpy(result, s);
200 return result;
201 }
202
203 int
204 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
205 {
206 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
207 }
208
209 int
210 cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
211 {
212 int result;
213
214 result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
215
216 if (result == EXIT_FAILURE)
217 {
218 cmdline_parser_free (args_info);
219 exit (EXIT_FAILURE);
220 }
221
222 return result;
223 }
224
225 int
226 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
227 {
228 int result = EXIT_SUCCESS;
229
230 if (cmdline_parser_required2(args_info, prog_name, NULL) > 0)
231 result = EXIT_FAILURE;
232
233 if (result == EXIT_FAILURE)
234 {
235 cmdline_parser_free (args_info);
236 exit (EXIT_FAILURE);
237 }
238
239 return result;
240 }
241
242 int
243 cmdline_parser_required2 (struct gengetopt_args_info *args_info, const char *prog_name, const char *additional_error)
244 {
245 int error = 0;
246
247 /* checks for required options */
248 if (! args_info->output_given)
249 {
250 fprintf (stderr, "%s: '--output' ('-o') option required%s\n", prog_name, (additional_error ? additional_error : ""));
251 error = 1;
252 }
253
254 if (! args_info->temperature_given)
255 {
256 fprintf (stderr, "%s: '--temperature' ('-t') option required%s\n", prog_name, (additional_error ? additional_error : ""));
257 error = 1;
258 }
259
260
261 /* checks for dependences among options */
262
263 return error;
264 }
265
266 int
267 cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
268 {
269 int c; /* Character of the parsed option. */
270
271 int error = 0;
272 struct gengetopt_args_info local_args_info;
273
274 if (initialize)
275 cmdline_parser_init (args_info);
276
277 cmdline_parser_init (&local_args_info);
278
279 optarg = 0;
280 optind = 0;
281 opterr = 1;
282 optopt = '?';
283
284 while (1)
285 {
286 int option_index = 0;
287 char *stop_char;
288
289 static struct option long_options[] = {
290 { "help", 0, NULL, 'h' },
291 { "version", 0, NULL, 'V' },
292 { "output", 1, NULL, 'o' },
293 { "temperature", 1, NULL, 't' },
294 { NULL, 0, NULL, 0 }
295 };
296
297 stop_char = 0;
298 c = getopt_long (argc, argv, "hVo:t:", long_options, &option_index);
299
300 if (c == -1) break; /* Exit from `while (1)' loop. */
301
302 switch (c)
303 {
304 case 'h': /* Print help and exit. */
305 cmdline_parser_print_help ();
306 cmdline_parser_free (&local_args_info);
307 exit (EXIT_SUCCESS);
308
309 case 'V': /* Print version and exit. */
310 cmdline_parser_print_version ();
311 cmdline_parser_free (&local_args_info);
312 exit (EXIT_SUCCESS);
313
314 case 'o': /* Output file name. */
315 if (local_args_info.output_given)
316 {
317 fprintf (stderr, "%s: `--output' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
318 goto failure;
319 }
320 if (args_info->output_given && ! override)
321 continue;
322 local_args_info.output_given = 1;
323 args_info->output_given = 1;
324 if (args_info->output_arg)
325 free (args_info->output_arg); /* free previous string */
326 args_info->output_arg = gengetopt_strdup (optarg);
327 if (args_info->output_orig)
328 free (args_info->output_orig); /* free previous string */
329 args_info->output_orig = gengetopt_strdup (optarg);
330 break;
331
332 case 't': /* temperature (K). */
333 if (local_args_info.temperature_given)
334 {
335 fprintf (stderr, "%s: `--temperature' (`-t') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
336 goto failure;
337 }
338 if (args_info->temperature_given && ! override)
339 continue;
340 local_args_info.temperature_given = 1;
341 args_info->temperature_given = 1;
342 args_info->temperature_arg = strtod (optarg, &stop_char);
343 if (!(stop_char && *stop_char == '\0')) {
344 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
345 goto failure;
346 }
347 if (args_info->temperature_orig)
348 free (args_info->temperature_orig); /* free previous string */
349 args_info->temperature_orig = gengetopt_strdup (optarg);
350 break;
351
352
353 case 0: /* Long option with no short option */
354 case '?': /* Invalid option. */
355 /* `getopt_long' already printed an error message. */
356 goto failure;
357
358 default: /* bug: option not considered. */
359 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
360 abort ();
361 } /* switch */
362 } /* while */
363
364
365
366 if (check_required)
367 {
368 error += cmdline_parser_required2 (args_info, argv[0], additional_error);
369 }
370
371 cmdline_parser_release (&local_args_info);
372
373 if ( error )
374 return (EXIT_FAILURE);
375
376 if (optind < argc)
377 {
378 int i = 0 ;
379 int found_prog_name = 0;
380 /* whether program name, i.e., argv[0], is in the remaining args
381 (this may happen with some implementations of getopt,
382 but surely not with the one included by gengetopt) */
383
384 i = optind;
385 while (i < argc)
386 if (argv[i++] == argv[0]) {
387 found_prog_name = 1;
388 break;
389 }
390 i = 0;
391
392 args_info->inputs_num = argc - optind - found_prog_name;
393 args_info->inputs =
394 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
395 while (optind < argc)
396 if (argv[optind++] != argv[0])
397 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
398 }
399
400 return 0;
401
402 failure:
403
404 cmdline_parser_release (&local_args_info);
405 return (EXIT_FAILURE);
406 }