ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/applications/dynamicProps/DynamicPropsCmd.c
Revision: 2004
Committed: Sun Feb 13 07:14:59 2005 UTC (19 years, 5 months ago) by tim
Content type: text/plain
File size: 7483 byte(s)
Log Message:
adding command line option to DynamicProps

File Contents

# User Rev Content
1 tim 2004 /*
2     File autogenerated by gengetopt version 2.11
3     generated with the following command:
4     /home/maul/gezelter/tim/bin/gengetopt -F DynamicPropsCmd
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 "DynamicPropsCmd.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]...\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(" -i, --input=filename input dump file\n");
41     printf(" -o, --output=filename output file name\n");
42     printf(" --sele1=selection script select first stuntdouble set\n");
43     printf(" --sele2=selection script select second stuntdouble set (if sele2 is not \n set, use script from sele1)\n");
44     printf("\n");
45     printf(" Group: dynamicProps an option of this group is required\n");
46     printf(" -r, --rcorr rmsd\n");
47     printf(" -v, --vcorr velocity correlation function\n");
48     printf(" -d, --dcorr dipole correlation function\n");
49     }
50    
51    
52     static char *gengetopt_strdup (const char *s);
53    
54     /* gengetopt_strdup() */
55     /* strdup.c replacement of strdup, which is not standard */
56     char *
57     gengetopt_strdup (const char *s)
58     {
59     char *result = (char*)malloc(strlen(s) + 1);
60     if (result == (char*)0)
61     return (char*)0;
62     strcpy(result, s);
63     return result;
64     }
65    
66     int
67     cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
68     {
69     int c; /* Character of the parsed option. */
70     int missing_required_options = 0;
71     int dynamicProps_group_counter = 0;
72    
73    
74     args_info->help_given = 0 ;
75     args_info->version_given = 0 ;
76     args_info->input_given = 0 ;
77     args_info->output_given = 0 ;
78     args_info->sele1_given = 0 ;
79     args_info->sele2_given = 0 ;
80     args_info->rcorr_given = 0 ;
81     args_info->vcorr_given = 0 ;
82     args_info->dcorr_given = 0 ;
83     #define clear_args() { \
84     args_info->input_arg = NULL; \
85     args_info->output_arg = NULL; \
86     args_info->sele1_arg = NULL; \
87     args_info->sele2_arg = NULL; \
88     }
89    
90     clear_args();
91    
92     optarg = 0;
93     optind = 1;
94     opterr = 1;
95     optopt = '?';
96    
97     while (1)
98     {
99     int option_index = 0;
100     char *stop_char;
101    
102     static struct option long_options[] = {
103     { "help", 0, NULL, 'h' },
104     { "version", 0, NULL, 'V' },
105     { "input", 1, NULL, 'i' },
106     { "output", 1, NULL, 'o' },
107     { "sele1", 1, NULL, 0 },
108     { "sele2", 1, NULL, 0 },
109     { "rcorr", 0, NULL, 'r' },
110     { "vcorr", 0, NULL, 'v' },
111     { "dcorr", 0, NULL, 'd' },
112     { NULL, 0, NULL, 0 }
113     };
114    
115     stop_char = 0;
116     c = getopt_long (argc, argv, "hVi:o:rvd", long_options, &option_index);
117    
118     if (c == -1) break; /* Exit from `while (1)' loop. */
119    
120     switch (c)
121     {
122     case 'h': /* Print help and exit. */
123     clear_args ();
124     cmdline_parser_print_help ();
125     exit (EXIT_SUCCESS);
126    
127     case 'V': /* Print version and exit. */
128     clear_args ();
129     cmdline_parser_print_version ();
130     exit (EXIT_SUCCESS);
131    
132     case 'i': /* input dump file. */
133     if (args_info->input_given)
134     {
135     fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE);
136     clear_args ();
137     exit (EXIT_FAILURE);
138     }
139     args_info->input_given = 1;
140     args_info->input_arg = gengetopt_strdup (optarg);
141     break;
142    
143     case 'o': /* output file name. */
144     if (args_info->output_given)
145     {
146     fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE);
147     clear_args ();
148     exit (EXIT_FAILURE);
149     }
150     args_info->output_given = 1;
151     args_info->output_arg = gengetopt_strdup (optarg);
152     break;
153    
154     case 'r': /* rmsd. */
155     if (args_info->rcorr_given)
156     {
157     fprintf (stderr, "%s: `--rcorr' (`-r') option given more than once\n", CMDLINE_PARSER_PACKAGE);
158     clear_args ();
159     exit (EXIT_FAILURE);
160     }
161     args_info->rcorr_given = 1;
162     dynamicProps_group_counter += 1;
163     break;
164    
165     case 'v': /* velocity correlation function. */
166     if (args_info->vcorr_given)
167     {
168     fprintf (stderr, "%s: `--vcorr' (`-v') option given more than once\n", CMDLINE_PARSER_PACKAGE);
169     clear_args ();
170     exit (EXIT_FAILURE);
171     }
172     args_info->vcorr_given = 1;
173     dynamicProps_group_counter += 1;
174     break;
175    
176     case 'd': /* dipole correlation function. */
177     if (args_info->dcorr_given)
178     {
179     fprintf (stderr, "%s: `--dcorr' (`-d') option given more than once\n", CMDLINE_PARSER_PACKAGE);
180     clear_args ();
181     exit (EXIT_FAILURE);
182     }
183     args_info->dcorr_given = 1;
184     dynamicProps_group_counter += 1;
185     break;
186    
187    
188     case 0: /* Long option with no short option */
189     /* select first stuntdouble set. */
190     if (strcmp (long_options[option_index].name, "sele1") == 0)
191     {
192     if (args_info->sele1_given)
193     {
194     fprintf (stderr, "%s: `--sele1' option given more than once\n", CMDLINE_PARSER_PACKAGE);
195     clear_args ();
196     exit (EXIT_FAILURE);
197     }
198     args_info->sele1_given = 1;
199     args_info->sele1_arg = gengetopt_strdup (optarg);
200     break;
201     }
202    
203     /* select second stuntdouble set (if sele2 is not set, use script from sele1). */
204     else if (strcmp (long_options[option_index].name, "sele2") == 0)
205     {
206     if (args_info->sele2_given)
207     {
208     fprintf (stderr, "%s: `--sele2' option given more than once\n", CMDLINE_PARSER_PACKAGE);
209     clear_args ();
210     exit (EXIT_FAILURE);
211     }
212     args_info->sele2_given = 1;
213     args_info->sele2_arg = gengetopt_strdup (optarg);
214     break;
215     }
216    
217    
218     case '?': /* Invalid option. */
219     /* `getopt_long' already printed an error message. */
220     exit (EXIT_FAILURE);
221    
222     default: /* bug: option not considered. */
223     fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c);
224     abort ();
225     } /* switch */
226     } /* while */
227    
228     if ( dynamicProps_group_counter != 1)
229     {
230     fprintf (stderr, "%s: %d options of group dynamicProps were given. One is required\n", CMDLINE_PARSER_PACKAGE, dynamicProps_group_counter);
231     missing_required_options = 1;
232     }
233    
234    
235     if (! args_info->input_given)
236     {
237     fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE);
238     missing_required_options = 1;
239     }
240     if ( missing_required_options )
241     exit (EXIT_FAILURE);
242    
243     return 0;
244     }