1 |
tim |
306 |
/* |
2 |
|
|
File autogenerated by gengetopt version 2.11 |
3 |
|
|
generated with the following command: |
4 |
|
|
/home/maul/gezelter/tim/bin/gengetopt -F GofRCmd |
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 "GofRCmd.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(" -n, --frame=INT print every n frame (default=`1')\n"); |
43 |
|
|
printf(" -b, --nbins=INT number of bins (default=`50')\n"); |
44 |
|
|
printf(" -l, --length=DOUBLE maximum length\n"); |
45 |
|
|
printf(" --sele1=selection script select first stuntdouble set\n"); |
46 |
|
|
printf(" --sele2=selection script select second stuntdouble set\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->input_given = 0 ; |
73 |
|
|
args_info->output_given = 0 ; |
74 |
|
|
args_info->frame_given = 0 ; |
75 |
|
|
args_info->nbins_given = 0 ; |
76 |
|
|
args_info->length_given = 0 ; |
77 |
|
|
args_info->sele1_given = 0 ; |
78 |
|
|
args_info->sele2_given = 0 ; |
79 |
|
|
#define clear_args() { \ |
80 |
|
|
args_info->input_arg = NULL; \ |
81 |
|
|
args_info->output_arg = NULL; \ |
82 |
|
|
args_info->frame_arg = 1 ;\ |
83 |
|
|
args_info->nbins_arg = 50 ;\ |
84 |
|
|
args_info->sele1_arg = NULL; \ |
85 |
|
|
args_info->sele2_arg = NULL; \ |
86 |
|
|
} |
87 |
|
|
|
88 |
|
|
clear_args(); |
89 |
|
|
|
90 |
|
|
optarg = 0; |
91 |
|
|
optind = 1; |
92 |
|
|
opterr = 1; |
93 |
|
|
optopt = '?'; |
94 |
|
|
|
95 |
|
|
while (1) |
96 |
|
|
{ |
97 |
|
|
int option_index = 0; |
98 |
|
|
char *stop_char; |
99 |
|
|
|
100 |
|
|
static struct option long_options[] = { |
101 |
|
|
{ "help", 0, NULL, 'h' }, |
102 |
|
|
{ "version", 0, NULL, 'V' }, |
103 |
|
|
{ "input", 1, NULL, 'i' }, |
104 |
|
|
{ "output", 1, NULL, 'o' }, |
105 |
|
|
{ "frame", 1, NULL, 'n' }, |
106 |
|
|
{ "nbins", 1, NULL, 'b' }, |
107 |
|
|
{ "length", 1, NULL, 'l' }, |
108 |
|
|
{ "sele1", 1, NULL, 0 }, |
109 |
|
|
{ "sele2", 1, NULL, 0 }, |
110 |
|
|
{ NULL, 0, NULL, 0 } |
111 |
|
|
}; |
112 |
|
|
|
113 |
|
|
stop_char = 0; |
114 |
|
|
c = getopt_long (argc, argv, "hVi:o:n:b:l:", long_options, &option_index); |
115 |
|
|
|
116 |
|
|
if (c == -1) break; /* Exit from `while (1)' loop. */ |
117 |
|
|
|
118 |
|
|
switch (c) |
119 |
|
|
{ |
120 |
|
|
case 'h': /* Print help and exit. */ |
121 |
|
|
clear_args (); |
122 |
|
|
cmdline_parser_print_help (); |
123 |
|
|
exit (EXIT_SUCCESS); |
124 |
|
|
|
125 |
|
|
case 'V': /* Print version and exit. */ |
126 |
|
|
clear_args (); |
127 |
|
|
cmdline_parser_print_version (); |
128 |
|
|
exit (EXIT_SUCCESS); |
129 |
|
|
|
130 |
|
|
case 'i': /* input dump file. */ |
131 |
|
|
if (args_info->input_given) |
132 |
|
|
{ |
133 |
|
|
fprintf (stderr, "%s: `--input' (`-i') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
134 |
|
|
clear_args (); |
135 |
|
|
exit (EXIT_FAILURE); |
136 |
|
|
} |
137 |
|
|
args_info->input_given = 1; |
138 |
|
|
args_info->input_arg = gengetopt_strdup (optarg); |
139 |
|
|
break; |
140 |
|
|
|
141 |
|
|
case 'o': /* output file name. */ |
142 |
|
|
if (args_info->output_given) |
143 |
|
|
{ |
144 |
|
|
fprintf (stderr, "%s: `--output' (`-o') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
145 |
|
|
clear_args (); |
146 |
|
|
exit (EXIT_FAILURE); |
147 |
|
|
} |
148 |
|
|
args_info->output_given = 1; |
149 |
|
|
args_info->output_arg = gengetopt_strdup (optarg); |
150 |
|
|
break; |
151 |
|
|
|
152 |
|
|
case 'n': /* print every n frame. */ |
153 |
|
|
if (args_info->frame_given) |
154 |
|
|
{ |
155 |
|
|
fprintf (stderr, "%s: `--frame' (`-n') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
156 |
|
|
clear_args (); |
157 |
|
|
exit (EXIT_FAILURE); |
158 |
|
|
} |
159 |
|
|
args_info->frame_given = 1; |
160 |
|
|
args_info->frame_arg = strtol (optarg,&stop_char,0); |
161 |
|
|
break; |
162 |
|
|
|
163 |
|
|
case 'b': /* number of bins. */ |
164 |
|
|
if (args_info->nbins_given) |
165 |
|
|
{ |
166 |
|
|
fprintf (stderr, "%s: `--nbins' (`-b') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
167 |
|
|
clear_args (); |
168 |
|
|
exit (EXIT_FAILURE); |
169 |
|
|
} |
170 |
|
|
args_info->nbins_given = 1; |
171 |
|
|
args_info->nbins_arg = strtol (optarg,&stop_char,0); |
172 |
|
|
break; |
173 |
|
|
|
174 |
|
|
case 'l': /* maximum length. */ |
175 |
|
|
if (args_info->length_given) |
176 |
|
|
{ |
177 |
|
|
fprintf (stderr, "%s: `--length' (`-l') option given more than once\n", CMDLINE_PARSER_PACKAGE); |
178 |
|
|
clear_args (); |
179 |
|
|
exit (EXIT_FAILURE); |
180 |
|
|
} |
181 |
|
|
args_info->length_given = 1; |
182 |
|
|
args_info->length_arg = strtod (optarg, NULL); |
183 |
|
|
break; |
184 |
|
|
|
185 |
|
|
|
186 |
|
|
case 0: /* Long option with no short option */ |
187 |
|
|
/* select first stuntdouble set. */ |
188 |
|
|
if (strcmp (long_options[option_index].name, "sele1") == 0) |
189 |
|
|
{ |
190 |
|
|
if (args_info->sele1_given) |
191 |
|
|
{ |
192 |
|
|
fprintf (stderr, "%s: `--sele1' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
193 |
|
|
clear_args (); |
194 |
|
|
exit (EXIT_FAILURE); |
195 |
|
|
} |
196 |
|
|
args_info->sele1_given = 1; |
197 |
|
|
args_info->sele1_arg = gengetopt_strdup (optarg); |
198 |
|
|
break; |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
/* select second stuntdouble set. */ |
202 |
|
|
else if (strcmp (long_options[option_index].name, "sele2") == 0) |
203 |
|
|
{ |
204 |
|
|
if (args_info->sele2_given) |
205 |
|
|
{ |
206 |
|
|
fprintf (stderr, "%s: `--sele2' option given more than once\n", CMDLINE_PARSER_PACKAGE); |
207 |
|
|
clear_args (); |
208 |
|
|
exit (EXIT_FAILURE); |
209 |
|
|
} |
210 |
|
|
args_info->sele2_given = 1; |
211 |
|
|
args_info->sele2_arg = gengetopt_strdup (optarg); |
212 |
|
|
break; |
213 |
|
|
} |
214 |
|
|
|
215 |
|
|
|
216 |
|
|
case '?': /* Invalid option. */ |
217 |
|
|
/* `getopt_long' already printed an error message. */ |
218 |
|
|
exit (EXIT_FAILURE); |
219 |
|
|
|
220 |
|
|
default: /* bug: option not considered. */ |
221 |
|
|
fprintf (stderr, "%s: option unknown: %c\n", CMDLINE_PARSER_PACKAGE, c); |
222 |
|
|
abort (); |
223 |
|
|
} /* switch */ |
224 |
|
|
} /* while */ |
225 |
|
|
|
226 |
|
|
|
227 |
|
|
if (! args_info->input_given) |
228 |
|
|
{ |
229 |
|
|
fprintf (stderr, "%s: '--input' ('-i') option required\n", CMDLINE_PARSER_PACKAGE); |
230 |
|
|
missing_required_options = 1; |
231 |
|
|
} |
232 |
|
|
if (! args_info->length_given) |
233 |
|
|
{ |
234 |
|
|
fprintf (stderr, "%s: '--length' ('-l') option required\n", CMDLINE_PARSER_PACKAGE); |
235 |
|
|
missing_required_options = 1; |
236 |
|
|
} |
237 |
|
|
if ( missing_required_options ) |
238 |
|
|
exit (EXIT_FAILURE); |
239 |
|
|
|
240 |
|
|
return 0; |
241 |
|
|
} |