ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/SHAPES/forcerCmd.c
Revision: 1240
Committed: Fri Jun 4 16:11:27 2004 UTC (20 years, 1 month ago) by gezelter
Content type: text/plain
File size: 10053 byte(s)
Log Message:
Initial import of SHAPES code

File Contents

# User Rev Content
1 gezelter 1240 /*
2     File autogenerated by gengetopt version 2.12.1
3     generated with the following command:
4     gengetopt --file-name=forcerCmd
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 "forcerCmd.h"
23    
24     static
25     void clear_given (struct gengetopt_args_info *args_info);
26     static
27     void clear_args (struct gengetopt_args_info *args_info);
28    
29     static int
30     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);
31    
32     static char *
33     gengetopt_strdup (const char *s);
34    
35     static
36     void clear_given (struct gengetopt_args_info *args_info)
37     {
38     args_info->help_given = 0 ;
39     args_info->version_given = 0 ;
40     args_info->input_given = 0 ;
41     args_info->charmm_given = 0 ;
42     args_info->amber_given = 0 ;
43     args_info->lj_given = 0 ;
44     args_info->gaff_given = 0 ;
45     args_info->opls_given = 0 ;
46     args_info->ForceField_group_counter = 0 ;
47     }
48    
49     static
50     void clear_args (struct gengetopt_args_info *args_info)
51     {
52     args_info->input_arg = NULL;
53     }
54    
55     void
56     cmdline_parser_print_version (void)
57     {
58     printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
59     }
60    
61     void
62     cmdline_parser_print_help (void)
63     {
64     cmdline_parser_print_version ();
65     printf("\n"
66     "Usage: %s [OPTIONS]...\n", CMDLINE_PARSER_PACKAGE);
67     printf("\n");
68     printf("%s\n"," -h, --help Print help and exit");
69     printf("%s\n"," -V, --version Print version and exit");
70     printf("%s\n"," -i, --input=filename input file name");
71     printf("\n");
72     printf(" Group: ForceField A Force Field must be specified\n");
73     printf("%s\n"," -c, --charmm Use CHARMM 27 parameters");
74     printf("%s\n"," -a, --amber Use Amber99 parameters");
75     printf("%s\n"," -l, --lj Use Lennard-Jones parameters");
76     printf("%s\n"," -g, --gaff Use GAFF parameters");
77     printf("%s\n"," -o, --opls Use OPLS/AA parameters");
78     }
79    
80     void
81     cmdline_parser_init (struct gengetopt_args_info *args_info)
82     {
83     clear_given (args_info);
84     clear_args (args_info);
85     }
86    
87     void
88     cmdline_parser_free (struct gengetopt_args_info *args_info)
89     {
90    
91     if (args_info->input_arg)
92     {
93     free (args_info->input_arg); /* free previous argument */
94     args_info->input_arg = 0;
95     }
96    
97     clear_given (args_info);
98     }
99    
100    
101     /* gengetopt_strdup() */
102     /* strdup.c replacement of strdup, which is not standard */
103     char *
104     gengetopt_strdup (const char *s)
105     {
106     char *result = NULL;
107     if (!s)
108     return result;
109    
110     result = (char*)malloc(strlen(s) + 1);
111     if (result == (char*)0)
112     return (char*)0;
113     strcpy(result, s);
114     return result;
115     }
116    
117     static void
118     reset_group_ForceField(struct gengetopt_args_info *args_info);
119    
120     static void
121     reset_group_ForceField(struct gengetopt_args_info *args_info)
122     {
123     if (! args_info->ForceField_group_counter)
124     return;
125    
126     args_info->charmm_given = 0 ;
127     args_info->amber_given = 0 ;
128     args_info->lj_given = 0 ;
129     args_info->gaff_given = 0 ;
130     args_info->opls_given = 0 ;
131    
132     args_info->ForceField_group_counter = 0;
133     }
134    
135     int
136     cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
137     {
138     return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
139     }
140    
141     int
142     cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
143     {
144     int result;
145    
146     result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
147    
148     if (result == EXIT_FAILURE)
149     {
150     cmdline_parser_free (args_info);
151     exit (EXIT_FAILURE);
152     }
153    
154     return result;
155     }
156    
157     int
158     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)
159     {
160     int c; /* Character of the parsed option. */
161     int error = 0;
162     struct gengetopt_args_info local_args_info;
163    
164     if (initialize)
165     cmdline_parser_init (args_info);
166    
167     cmdline_parser_init (&local_args_info);
168    
169     optarg = 0;
170     optind = 1;
171     opterr = 1;
172     optopt = '?';
173    
174     while (1)
175     {
176     int option_index = 0;
177     char *stop_char;
178    
179     static struct option long_options[] = {
180     { "help", 0, NULL, 'h' },
181     { "version", 0, NULL, 'V' },
182     { "input", 1, NULL, 'i' },
183     { "charmm", 0, NULL, 'c' },
184     { "amber", 0, NULL, 'a' },
185     { "lj", 0, NULL, 'l' },
186     { "gaff", 0, NULL, 'g' },
187     { "opls", 0, NULL, 'o' },
188     { NULL, 0, NULL, 0 }
189     };
190    
191     stop_char = 0;
192     c = getopt_long (argc, argv, "hVi:calgo", long_options, &option_index);
193    
194     if (c == -1) break; /* Exit from `while (1)' loop. */
195    
196     switch (c)
197     {
198     case 'h': /* Print help and exit. */
199     cmdline_parser_print_help ();
200     exit (EXIT_SUCCESS);
201    
202     case 'V': /* Print version and exit. */
203     cmdline_parser_print_version ();
204     exit (EXIT_SUCCESS);
205    
206     case 'i': /* input file name. */
207     if (local_args_info.input_given)
208     {
209     fprintf (stderr, "%s: `--input' (`-i') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
210     goto failure;
211     }
212     if (args_info->input_given && ! override)
213     continue;
214     local_args_info.input_given = 1;
215     args_info->input_given = 1;
216     if (args_info->input_arg)
217     free (args_info->input_arg); /* free previous string */
218     args_info->input_arg = gengetopt_strdup (optarg);
219     break;
220    
221     case 'c': /* Use CHARMM 27 parameters. */
222     if (local_args_info.charmm_given)
223     {
224     fprintf (stderr, "%s: `--charmm' (`-c') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
225     goto failure;
226     }
227     if (args_info->charmm_given && ! override)
228     continue;
229     local_args_info.charmm_given = 1;
230     args_info->charmm_given = 1;
231     if (args_info->ForceField_group_counter && override)
232     reset_group_ForceField (args_info);
233     args_info->ForceField_group_counter += 1;
234     break;
235    
236     case 'a': /* Use Amber99 parameters. */
237     if (local_args_info.amber_given)
238     {
239     fprintf (stderr, "%s: `--amber' (`-a') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
240     goto failure;
241     }
242     if (args_info->amber_given && ! override)
243     continue;
244     local_args_info.amber_given = 1;
245     args_info->amber_given = 1;
246     if (args_info->ForceField_group_counter && override)
247     reset_group_ForceField (args_info);
248     args_info->ForceField_group_counter += 1;
249     break;
250    
251     case 'l': /* Use Lennard-Jones parameters. */
252     if (local_args_info.lj_given)
253     {
254     fprintf (stderr, "%s: `--lj' (`-l') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
255     goto failure;
256     }
257     if (args_info->lj_given && ! override)
258     continue;
259     local_args_info.lj_given = 1;
260     args_info->lj_given = 1;
261     if (args_info->ForceField_group_counter && override)
262     reset_group_ForceField (args_info);
263     args_info->ForceField_group_counter += 1;
264     break;
265    
266     case 'g': /* Use GAFF parameters. */
267     if (local_args_info.gaff_given)
268     {
269     fprintf (stderr, "%s: `--gaff' (`-g') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
270     goto failure;
271     }
272     if (args_info->gaff_given && ! override)
273     continue;
274     local_args_info.gaff_given = 1;
275     args_info->gaff_given = 1;
276     if (args_info->ForceField_group_counter && override)
277     reset_group_ForceField (args_info);
278     args_info->ForceField_group_counter += 1;
279     break;
280    
281     case 'o': /* Use OPLS/AA parameters. */
282     if (local_args_info.opls_given)
283     {
284     fprintf (stderr, "%s: `--opls' (`-o') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
285     goto failure;
286     }
287     if (args_info->opls_given && ! override)
288     continue;
289     local_args_info.opls_given = 1;
290     args_info->opls_given = 1;
291     if (args_info->ForceField_group_counter && override)
292     reset_group_ForceField (args_info);
293     args_info->ForceField_group_counter += 1;
294     break;
295    
296    
297     case 0: /* Long option with no short option */
298    
299     case '?': /* Invalid option. */
300     /* `getopt_long' already printed an error message. */
301     goto failure;
302    
303     default: /* bug: option not considered. */
304     fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
305     abort ();
306     } /* switch */
307     } /* while */
308    
309     if ( args_info->ForceField_group_counter != 1)
310     {
311     fprintf (stderr, "%s: %d options of group ForceField were given. One is required.%s\n", CMDLINE_PARSER_PACKAGE, args_info->ForceField_group_counter, (additional_error ? additional_error : ""));
312     error = 1;
313     }
314    
315    
316    
317     if (check_required)
318     {
319     if (! args_info->input_given)
320     {
321     fprintf (stderr, "%s: '--input' ('-i') option required%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
322     error = 1;
323     }
324     }
325    
326     if ( error )
327     return (EXIT_FAILURE);
328    
329     return 0;
330    
331     failure:
332     cmdline_parser_free (&local_args_info);
333     return (EXIT_FAILURE);
334     }