ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-1.0/utils/sysbuilder/cmdline.c
Revision: 1334
Committed: Fri Jul 16 18:58:03 2004 UTC (19 years, 11 months ago) by gezelter
Content type: text/plain
File size: 12280 byte(s)
Log Message:
Initial import of OOPSE-1.0 source tree

File Contents

# Content
1 /*
2 File autogenerated by gengetopt version 2.10
3 generated with the following command:
4 gengetopt --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
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 "cmdline.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(" -h --help Print help and exit\n");
38 printf(" -V --version Print version and exit\n");
39 printf(" -n --nanoparticle Build nanoparticle model (default=off)\n");
40 printf(" -vDOUBLE --vacancies=DOUBLE Build nanoparticle with vacancies %.\n");
41 printf(" --vacancyradius=DOUBLE Radius(A) between core-shell interface to build vacancies.\n");
42 printf(" --core=STRING Core model name. For a single component particle, the model for the particle.\n");
43 printf(" --shell=STRING Shell model name.\n");
44 printf(" --randomparticle=DOUBLE Create an random configuration mole fraction %.\n");
45 printf(" --bilayer Tries to build a basic bilayer with the specified number of lipids in the input bass file. The bilayer will be surrounded by the number of solvent molecules specified in the bass file. -note: combined with -r the simulation will start the lipids randomly oriented in a sea of water. (default=off)\n");
46 printf(" --lipid=STRING Lipid model in BASS file\n");
47 printf(" --water=STRING Water model in BASS file\n");
48 printf(" -r --random Build randomly oriented lipids in a sea of water (default=off)\n");
49 printf(" -ISTRING --include=STRING File name that should be included at the top of the output bass file.\n");
50 printf(" -oSTRING --output=STRING Output file name\n");
51 }
52
53
54 static char *gengetopt_strdup (const char *s);
55
56 /* gengetopt_strdup() */
57 /* strdup.c replacement of strdup, which is not standard */
58 char *
59 gengetopt_strdup (const char *s)
60 {
61 char *result = (char*)malloc(strlen(s) + 1);
62 if (result == (char*)0)
63 return (char*)0;
64 strcpy(result, s);
65 return result;
66 }
67
68 int
69 cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
70 {
71 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
80 int missing_required_options = 0;
81
82 args_info->help_given = 0 ;
83 args_info->version_given = 0 ;
84 args_info->nanoparticle_given = 0 ;
85 args_info->vacancies_given = 0 ;
86 args_info->vacancyradius_given = 0 ;
87 args_info->core_given = 0 ;
88 args_info->shell_given = 0 ;
89 args_info->randomparticle_given = 0 ;
90 args_info->bilayer_given = 0 ;
91 args_info->lipid_given = 0 ;
92 args_info->water_given = 0 ;
93 args_info->random_given = 0 ;
94 args_info->include_given = 0 ;
95 args_info->output_given = 0 ;
96 #define clear_args() { \
97 args_info->nanoparticle_flag = 0;\
98 args_info->core_arg = NULL; \
99 args_info->shell_arg = NULL; \
100 args_info->bilayer_flag = 0;\
101 args_info->lipid_arg = NULL; \
102 args_info->water_arg = NULL; \
103 args_info->random_flag = 0;\
104 args_info->include_arg = NULL; \
105 args_info->output_arg = NULL; \
106 }
107
108 clear_args();
109
110 args_info->inputs = NULL;
111 args_info->inputs_num = 0;
112
113 optarg = 0;
114 optind = 1;
115 opterr = 1;
116 optopt = '?';
117
118 while (1)
119 {
120 int option_index = 0;
121 char *stop_char;
122
123 static struct option long_options[] = {
124 { "help", 0, NULL, 'h' },
125 { "version", 0, NULL, 'V' },
126 { "nanoparticle", 0, NULL, 'n' },
127 { "vacancies", 1, NULL, 'v' },
128 { "vacancyradius", 1, NULL, 0 },
129 { "core", 1, NULL, 0 },
130 { "shell", 1, NULL, 0 },
131 { "randomparticle", 1, NULL, 0 },
132 { "bilayer", 0, NULL, 0 },
133 { "lipid", 1, NULL, 0 },
134 { "water", 1, NULL, 0 },
135 { "random", 0, NULL, 'r' },
136 { "include", 1, NULL, 'I' },
137 { "output", 1, NULL, 'o' },
138 { NULL, 0, NULL, 0 }
139 };
140
141 stop_char = 0;
142 c = getopt_long (argc, argv, "hVnv:rI:o:", long_options, &option_index);
143
144 if (c == -1) break; /* Exit from `while (1)' loop. */
145
146 switch (c)
147 {
148 case 'h': /* Print help and exit. */
149 clear_args ();
150 cmdline_parser_print_help ();
151 exit (EXIT_SUCCESS);
152
153 case 'V': /* Print version and exit. */
154 clear_args ();
155 cmdline_parser_print_version ();
156 exit (EXIT_SUCCESS);
157
158 case 'n': /* Build nanoparticle model. */
159 if (args_info->nanoparticle_given)
160 {
161 fprintf (stderr, "%s: `--nanoparticle' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE);
162 clear_args ();
163 exit (EXIT_FAILURE);
164 }
165 args_info->nanoparticle_given = 1;
166 args_info->nanoparticle_flag = !(args_info->nanoparticle_flag);
167 break;
168
169 case 'v': /* Build nanoparticle with vacancies %.. */
170 if (args_info->vacancies_given)
171 {
172 fprintf (stderr, "%s: `--vacancies' (`-v') option given more than once\n", CMDLINE_PARSER_PACKAGE);
173 clear_args ();
174 exit (EXIT_FAILURE);
175 }
176 args_info->vacancies_given = 1;
177 args_info->vacancies_arg = strtod (optarg, NULL);
178 break;
179
180 case 'r': /* Build randomly oriented lipids in a sea of water. */
181 if (args_info->random_given)
182 {
183 fprintf (stderr, "%s: `--random' (`-r') option given more than once\n", CMDLINE_PARSER_PACKAGE);
184 clear_args ();
185 exit (EXIT_FAILURE);
186 }
187 args_info->random_given = 1;
188 args_info->random_flag = !(args_info->random_flag);
189 break;
190
191 case 'I': /* File name that should be included at the top of the output bass file.. */
192 args_info->include_given++;
193 include_new = (struct include_list *) malloc (sizeof (struct include_list));
194 include_new->next = include_list;
195 include_list = include_new;
196
197
198 include_new->include_arg = gengetopt_strdup (optarg);
199 break;
200
201 case 'o': /* Output file name. */
202 if (args_info->output_given)
203 {
204 fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
205 clear_args ();
206 exit (EXIT_FAILURE);
207 }
208 args_info->output_given = 1;
209 args_info->output_arg = gengetopt_strdup (optarg);
210 break;
211
212
213 case 0: /* Long option with no short option */
214 /* Radius(A) between core-shell interface to build vacancies.. */
215 if (strcmp (long_options[option_index].name, "vacancyradius") == 0)
216 {
217 if (args_info->vacancyradius_given)
218 {
219 fprintf (stderr, "%s: `--vacancyradius' option given more than once\n", CMDLINE_PARSER_PACKAGE);
220 clear_args ();
221 exit (EXIT_FAILURE);
222 }
223 args_info->vacancyradius_given = 1;
224 args_info->vacancyradius_arg = strtod (optarg, NULL);
225 break;
226 }
227
228 /* Core model name. For a single component particle, the model for the particle.. */
229 else if (strcmp (long_options[option_index].name, "core") == 0)
230 {
231 if (args_info->core_given)
232 {
233 fprintf (stderr, "%s: `--core' option given more than once\n", CMDLINE_PARSER_PACKAGE);
234 clear_args ();
235 exit (EXIT_FAILURE);
236 }
237 args_info->core_given = 1;
238 args_info->core_arg = gengetopt_strdup (optarg);
239 break;
240 }
241
242 /* Shell model name.. */
243 else if (strcmp (long_options[option_index].name, "shell") == 0)
244 {
245 if (args_info->shell_given)
246 {
247 fprintf (stderr, "%s: `--shell' option given more than once\n", CMDLINE_PARSER_PACKAGE);
248 clear_args ();
249 exit (EXIT_FAILURE);
250 }
251 args_info->shell_given = 1;
252 args_info->shell_arg = gengetopt_strdup (optarg);
253 break;
254 }
255
256 /* Create an random configuration mole fraction %.. */
257 else if (strcmp (long_options[option_index].name, "randomparticle") == 0)
258 {
259 if (args_info->randomparticle_given)
260 {
261 fprintf (stderr, "%s: `--randomparticle' option given more than once\n", CMDLINE_PARSER_PACKAGE);
262 clear_args ();
263 exit (EXIT_FAILURE);
264 }
265 args_info->randomparticle_given = 1;
266 args_info->randomparticle_arg = strtod (optarg, NULL);
267 break;
268 }
269
270 /* Tries to build a basic bilayer with the specified number of lipids in the input bass file. The bilayer will be surrounded by the number of solvent molecules specified in the bass file. -note: combined with -r the simulation will start the lipids randomly oriented in a sea of water.. */
271 else if (strcmp (long_options[option_index].name, "bilayer") == 0)
272 {
273 if (args_info->bilayer_given)
274 {
275 fprintf (stderr, "%s: `--bilayer' option given more than once\n", CMDLINE_PARSER_PACKAGE);
276 clear_args ();
277 exit (EXIT_FAILURE);
278 }
279 args_info->bilayer_given = 1;
280 args_info->bilayer_flag = !(args_info->bilayer_flag);
281 break;
282 }
283
284 /* Lipid model in BASS file. */
285 else if (strcmp (long_options[option_index].name, "lipid") == 0)
286 {
287 if (args_info->lipid_given)
288 {
289 fprintf (stderr, "%s: `--lipid' option given more than once\n", CMDLINE_PARSER_PACKAGE);
290 clear_args ();
291 exit (EXIT_FAILURE);
292 }
293 args_info->lipid_given = 1;
294 args_info->lipid_arg = gengetopt_strdup (optarg);
295 break;
296 }
297
298 /* Water model in BASS file. */
299 else if (strcmp (long_options[option_index].name, "water") == 0)
300 {
301 if (args_info->water_given)
302 {
303 fprintf (stderr, "%s: `--water' option given more than once\n", CMDLINE_PARSER_PACKAGE);
304 clear_args ();
305 exit (EXIT_FAILURE);
306 }
307 args_info->water_given = 1;
308 args_info->water_arg = gengetopt_strdup (optarg);
309 break;
310 }
311
312
313 case '?': /* Invalid option. */
314 /* `getopt_long' already printed an error message. */
315 exit (EXIT_FAILURE);
316
317 default: /* bug: option not considered. */
318 fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
319 abort ();
320 } /* switch */
321 } /* while */
322
323
324 if ( missing_required_options )
325 exit (EXIT_FAILURE);
326
327 args_info->include_arg = (char * *) malloc (args_info->include_given * sizeof (char *));
328 for (i = 0; i < args_info->include_given; i++)
329 {
330 args_info->include_arg [i] = include_list->include_arg;
331 include_list = include_list->next;
332 }
333
334 if (optind < argc)
335 {
336 int i = 0 ;
337
338 args_info->inputs_num = argc - optind ;
339 args_info->inputs =
340 (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
341 while (optind < argc)
342 args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
343 }
344
345 return 0;
346 }