ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/SHAPES/visualizerCmd.c
Revision: 1361
Committed: Tue Jul 20 20:22:43 2004 UTC (19 years, 11 months ago) by gezelter
Content type: text/plain
File size: 6416 byte(s)
Log Message:
using gengetopts --unamed-opts="SHAPEFILE [OUTPUTFILE]"

File Contents

# User Rev Content
1 gezelter 1290 /*
2     File autogenerated by gengetopt version 2.12.1
3     generated with the following command:
4 gezelter 1361 gengetopt --file-name=visualizerCmd --unamed-opts=SHAPEFILE [OUTPUTFILE]
5 gezelter 1290
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 "visualizerCmd.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->grid_given = 0 ;
41 chrisfen 1315 args_info->range_given = 0 ;
42 gezelter 1290 }
43    
44     static
45     void clear_args (struct gengetopt_args_info *args_info)
46     {
47 gezelter 1300 args_info->grid_arg = 101 ;
48 chrisfen 1315 args_info->range_arg = 10 ;
49 gezelter 1290 }
50    
51     void
52     cmdline_parser_print_version (void)
53     {
54     printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
55     }
56    
57     void
58     cmdline_parser_print_help (void)
59     {
60     cmdline_parser_print_version ();
61     printf("\n"
62 gezelter 1361 "Usage: %s [OPTIONS]... [SHAPEFILE [OUTPUTFILE]]...\n", CMDLINE_PARSER_PACKAGE);
63 gezelter 1290 printf("\n");
64 gezelter 1361 printf("%s\n"," -h, --help Print help and exit");
65     printf("%s\n"," -V, --version Print version and exit");
66     printf("%s\n"," -g, --grid=INT number of grid points in each coordinate (default=\n `101')");
67     printf("%s\n"," -r, --range=DOUBLE the sample range for the points in Angstroms (Ex: 10 = \n -10 to 10) (default=`10')");
68 gezelter 1290 }
69    
70     void
71     cmdline_parser_init (struct gengetopt_args_info *args_info)
72     {
73     clear_given (args_info);
74     clear_args (args_info);
75 gezelter 1361
76     args_info->inputs = NULL;
77     args_info->inputs_num = 0;
78 gezelter 1290 }
79    
80     void
81     cmdline_parser_free (struct gengetopt_args_info *args_info)
82     {
83    
84 gezelter 1361 int i;
85 gezelter 1290
86 gezelter 1361 for (i = 0; i < args_info->inputs_num; ++i)
87     free (args_info->inputs [i]);
88    
89     if (args_info->inputs_num)
90     free (args_info->inputs);
91    
92 gezelter 1290 clear_given (args_info);
93     }
94    
95    
96     /* gengetopt_strdup() */
97     /* strdup.c replacement of strdup, which is not standard */
98     char *
99     gengetopt_strdup (const char *s)
100     {
101     char *result = NULL;
102     if (!s)
103     return result;
104    
105     result = (char*)malloc(strlen(s) + 1);
106     if (result == (char*)0)
107     return (char*)0;
108     strcpy(result, s);
109     return result;
110     }
111    
112     int
113     cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
114     {
115     return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
116     }
117    
118     int
119     cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
120     {
121     int result;
122    
123     result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
124    
125     if (result == EXIT_FAILURE)
126     {
127     cmdline_parser_free (args_info);
128     exit (EXIT_FAILURE);
129     }
130    
131     return result;
132     }
133    
134     int
135     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)
136     {
137     int c; /* Character of the parsed option. */
138     int error = 0;
139     struct gengetopt_args_info local_args_info;
140    
141     if (initialize)
142     cmdline_parser_init (args_info);
143    
144     cmdline_parser_init (&local_args_info);
145    
146     optarg = 0;
147     optind = 1;
148     opterr = 1;
149     optopt = '?';
150    
151     while (1)
152     {
153     int option_index = 0;
154     char *stop_char;
155    
156     static struct option long_options[] = {
157     { "help", 0, NULL, 'h' },
158     { "version", 0, NULL, 'V' },
159     { "grid", 1, NULL, 'g' },
160 chrisfen 1315 { "range", 1, NULL, 'r' },
161 gezelter 1290 { NULL, 0, NULL, 0 }
162     };
163    
164     stop_char = 0;
165 gezelter 1361 c = getopt_long (argc, argv, "hVg:r:", long_options, &option_index);
166 gezelter 1290
167     if (c == -1) break; /* Exit from `while (1)' loop. */
168    
169     switch (c)
170     {
171     case 'h': /* Print help and exit. */
172     cmdline_parser_print_help ();
173     exit (EXIT_SUCCESS);
174    
175     case 'V': /* Print version and exit. */
176     cmdline_parser_print_version ();
177     exit (EXIT_SUCCESS);
178    
179     case 'g': /* number of grid points in each coordinate. */
180     if (local_args_info.grid_given)
181     {
182     fprintf (stderr, "%s: `--grid' (`-g') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
183     goto failure;
184     }
185     if (args_info->grid_given && ! override)
186     continue;
187     local_args_info.grid_given = 1;
188     args_info->grid_given = 1;
189     args_info->grid_arg = strtol (optarg,&stop_char,0);
190     break;
191    
192 chrisfen 1315 case 'r': /* the sample range for the points in Angstroms (Ex: 10 = -10 to 10). */
193     if (local_args_info.range_given)
194     {
195     fprintf (stderr, "%s: `--range' (`-r') option given more than once%s\n", CMDLINE_PARSER_PACKAGE, (additional_error ? additional_error : ""));
196     goto failure;
197     }
198     if (args_info->range_given && ! override)
199     continue;
200     local_args_info.range_given = 1;
201     args_info->range_given = 1;
202     args_info->range_arg = strtod (optarg, NULL);
203     break;
204 gezelter 1290
205 chrisfen 1315
206 gezelter 1290 case 0: /* Long option with no short option */
207    
208     case '?': /* Invalid option. */
209     /* `getopt_long' already printed an error message. */
210     goto failure;
211    
212     default: /* bug: option not considered. */
213     fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
214     abort ();
215     } /* switch */
216     } /* while */
217    
218    
219    
220     if (check_required)
221     {
222     }
223    
224     if ( error )
225     return (EXIT_FAILURE);
226    
227 gezelter 1361 if (optind < argc)
228     {
229     int i = 0 ;
230    
231     args_info->inputs_num = argc - optind ;
232     args_info->inputs =
233     (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
234     while (optind < argc)
235     args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ;
236     }
237    
238 gezelter 1290 return 0;
239    
240     failure:
241     cmdline_parser_free (&local_args_info);
242     return (EXIT_FAILURE);
243     }