1 |
19 |
jeremybenn |
/*********************************************************************
|
2 |
|
|
This file is part of the argtable2 library.
|
3 |
|
|
Copyright (C) 1998-2001,2003-2008 Stewart Heitmann
|
4 |
|
|
sheitmann@users.sourceforge.net
|
5 |
|
|
|
6 |
|
|
The argtable2 library is free software; you can redistribute it and/or
|
7 |
|
|
modify it under the terms of the GNU Library General Public License as
|
8 |
|
|
published by the Free Software Foundation; either version 2 of the
|
9 |
|
|
License, or (at your option) any later version.
|
10 |
|
|
|
11 |
|
|
This software is distributed in the hope that it will be useful,
|
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
Library General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU Library General Public
|
17 |
|
|
License along with this library; if not, write to the Free Software
|
18 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
19 |
|
|
USA.
|
20 |
|
|
**********************************************************************/
|
21 |
|
|
#ifndef ARGTABLE2
|
22 |
|
|
#define ARGTABLE2
|
23 |
|
|
|
24 |
|
|
#include <stdio.h> /* FILE */
|
25 |
|
|
#include <time.h> /* struct tm */
|
26 |
|
|
#include <sys/types.h>
|
27 |
|
|
|
28 |
|
|
#ifdef __cplusplus
|
29 |
|
|
extern "C" {
|
30 |
|
|
#endif
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/* bit masks for arg_hdr.flag */
|
34 |
|
|
enum
|
35 |
|
|
{
|
36 |
|
|
ARG_TERMINATOR=0x1,
|
37 |
|
|
ARG_HASVALUE=0x2,
|
38 |
|
|
ARG_HASOPTVALUE=0x4
|
39 |
|
|
};
|
40 |
|
|
|
41 |
|
|
typedef void (arg_resetfn)(void *parent);
|
42 |
|
|
typedef int (arg_scanfn)(void *parent, const char *argval);
|
43 |
|
|
typedef int (arg_checkfn)(void *parent);
|
44 |
|
|
typedef void (arg_errorfn)(void *parent, FILE *fp, int error, const char *argval, const char *progname);
|
45 |
|
|
|
46 |
|
|
|
47 |
|
|
/*
|
48 |
|
|
* The arg_hdr struct defines properties that are common to all arg_xxx structs.
|
49 |
|
|
* The argtable library requires each arg_xxx struct to have an arg_hdr
|
50 |
|
|
* struct as its first data member.
|
51 |
|
|
* The argtable library functions then use this data to identify the
|
52 |
|
|
* properties of the command line option, such as its option tags,
|
53 |
|
|
* datatype string, and glossary strings, and so on.
|
54 |
|
|
* Moreover, the arg_hdr struct contains pointers to custom functions that
|
55 |
|
|
* are provided by each arg_xxx struct which perform the tasks of parsing
|
56 |
|
|
* that particular arg_xxx arguments, performing post-parse checks, and
|
57 |
|
|
* reporting errors.
|
58 |
|
|
* These functions are private to the individual arg_xxx source code
|
59 |
|
|
* and are the pointer to them are initiliased by that arg_xxx struct's
|
60 |
|
|
* constructor function. The user could alter them after construction
|
61 |
|
|
* if desired, but the original intention is for them to be set by the
|
62 |
|
|
* constructor and left unaltered.
|
63 |
|
|
*/
|
64 |
|
|
struct arg_hdr
|
65 |
|
|
{
|
66 |
|
|
char flag; /* Modifier flags: ARG_TERMINATOR, ARG_HASVALUE. */
|
67 |
|
|
const char *shortopts; /* String defining the short options */
|
68 |
|
|
const char *longopts; /* String defiing the long options */
|
69 |
|
|
const char *datatype; /* Description of the argument data type */
|
70 |
|
|
const char *glossary; /* Description of the option as shown by arg_print_glossary function */
|
71 |
|
|
int mincount; /* Minimum number of occurences of this option accepted */
|
72 |
|
|
int maxcount; /* Maximum number of occurences if this option accepted */
|
73 |
|
|
void *parent; /* Pointer to parent arg_xxx struct */
|
74 |
|
|
arg_resetfn *resetfn; /* Pointer to parent arg_xxx reset function */
|
75 |
|
|
arg_scanfn *scanfn; /* Pointer to parent arg_xxx scan function */
|
76 |
|
|
arg_checkfn *checkfn; /* Pointer to parent arg_xxx check function */
|
77 |
|
|
arg_errorfn *errorfn; /* Pointer to parent arg_xxx error function */
|
78 |
|
|
void *priv; /* Pointer to private header data for use by arg_xxx functions */
|
79 |
|
|
};
|
80 |
|
|
|
81 |
|
|
struct arg_rem
|
82 |
|
|
{
|
83 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
84 |
|
|
};
|
85 |
|
|
|
86 |
|
|
struct arg_lit
|
87 |
|
|
{
|
88 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
89 |
|
|
int count; /* Number of matching command line args */
|
90 |
|
|
};
|
91 |
|
|
|
92 |
|
|
struct arg_int
|
93 |
|
|
{
|
94 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
95 |
|
|
int count; /* Number of matching command line args */
|
96 |
|
|
int *ival; /* Array of parsed argument values */
|
97 |
|
|
};
|
98 |
|
|
|
99 |
|
|
struct arg_dbl
|
100 |
|
|
{
|
101 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
102 |
|
|
int count; /* Number of matching command line args */
|
103 |
|
|
double *dval; /* Array of parsed argument values */
|
104 |
|
|
};
|
105 |
|
|
|
106 |
|
|
struct arg_str
|
107 |
|
|
{
|
108 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
109 |
|
|
int count; /* Number of matching command line args */
|
110 |
|
|
const char **sval; /* Array of parsed argument values */
|
111 |
|
|
};
|
112 |
|
|
|
113 |
|
|
struct arg_rex
|
114 |
|
|
{
|
115 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
116 |
|
|
int count; /* Number of matching command line args */
|
117 |
|
|
const char **sval; /* Array of parsed argument values */
|
118 |
|
|
};
|
119 |
|
|
|
120 |
|
|
struct arg_file
|
121 |
|
|
{
|
122 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
123 |
|
|
int count; /* Number of matching command line args*/
|
124 |
|
|
const char **filename; /* Array of parsed filenames (eg: /home/foo.bar) */
|
125 |
|
|
const char **basename; /* Array of parsed basenames (eg: foo.bar) */
|
126 |
|
|
const char **extension; /* Array of parsed extensions (eg: bar) */
|
127 |
|
|
};
|
128 |
|
|
|
129 |
|
|
struct arg_date
|
130 |
|
|
{
|
131 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
132 |
|
|
const char *format; /* strptime format string used to parse the date */
|
133 |
|
|
int count; /* Number of matching command line args */
|
134 |
|
|
struct tm *tmval; /* Array of parsed time values */
|
135 |
|
|
};
|
136 |
|
|
|
137 |
|
|
enum {ARG_ELIMIT=1, ARG_EMALLOC, ARG_ENOMATCH, ARG_ELONGOPT, ARG_EMISSARG};
|
138 |
|
|
struct arg_end
|
139 |
|
|
{
|
140 |
|
|
struct arg_hdr hdr; /* The mandatory argtable header struct */
|
141 |
|
|
int count; /* Number of errors encountered */
|
142 |
|
|
int *error; /* Array of error codes */
|
143 |
|
|
void **parent; /* Array of pointers to offending arg_xxx struct */
|
144 |
|
|
const char **argval; /* Array of pointers to offending argv[] string */
|
145 |
|
|
};
|
146 |
|
|
|
147 |
|
|
|
148 |
|
|
/**** arg_xxx constructor functions *********************************/
|
149 |
|
|
|
150 |
|
|
struct arg_rem* arg_rem(const char* datatype, const char* glossary);
|
151 |
|
|
|
152 |
|
|
struct arg_lit* arg_lit0(const char* shortopts,
|
153 |
|
|
const char* longopts,
|
154 |
|
|
const char* glossary);
|
155 |
|
|
struct arg_lit* arg_lit1(const char* shortopts,
|
156 |
|
|
const char* longopts,
|
157 |
|
|
const char *glossary);
|
158 |
|
|
struct arg_lit* arg_litn(const char* shortopts,
|
159 |
|
|
const char* longopts,
|
160 |
|
|
int mincount,
|
161 |
|
|
int maxcount,
|
162 |
|
|
const char *glossary);
|
163 |
|
|
|
164 |
|
|
struct arg_key* arg_key0(const char* keyword,
|
165 |
|
|
int flags,
|
166 |
|
|
const char* glossary);
|
167 |
|
|
struct arg_key* arg_key1(const char* keyword,
|
168 |
|
|
int flags,
|
169 |
|
|
const char* glossary);
|
170 |
|
|
struct arg_key* arg_keyn(const char* keyword,
|
171 |
|
|
int flags,
|
172 |
|
|
int mincount,
|
173 |
|
|
int maxcount,
|
174 |
|
|
const char* glossary);
|
175 |
|
|
|
176 |
|
|
struct arg_int* arg_int0(const char* shortopts,
|
177 |
|
|
const char* longopts,
|
178 |
|
|
const char* datatype,
|
179 |
|
|
const char* glossary);
|
180 |
|
|
struct arg_int* arg_int1(const char* shortopts,
|
181 |
|
|
const char* longopts,
|
182 |
|
|
const char* datatype,
|
183 |
|
|
const char *glossary);
|
184 |
|
|
struct arg_int* arg_intn(const char* shortopts,
|
185 |
|
|
const char* longopts,
|
186 |
|
|
const char *datatype,
|
187 |
|
|
int mincount,
|
188 |
|
|
int maxcount,
|
189 |
|
|
const char *glossary);
|
190 |
|
|
|
191 |
|
|
struct arg_dbl* arg_dbl0(const char* shortopts,
|
192 |
|
|
const char* longopts,
|
193 |
|
|
const char* datatype,
|
194 |
|
|
const char* glossary);
|
195 |
|
|
struct arg_dbl* arg_dbl1(const char* shortopts,
|
196 |
|
|
const char* longopts,
|
197 |
|
|
const char* datatype,
|
198 |
|
|
const char *glossary);
|
199 |
|
|
struct arg_dbl* arg_dbln(const char* shortopts,
|
200 |
|
|
const char* longopts,
|
201 |
|
|
const char *datatype,
|
202 |
|
|
int mincount,
|
203 |
|
|
int maxcount,
|
204 |
|
|
const char *glossary);
|
205 |
|
|
|
206 |
|
|
struct arg_str* arg_str0(const char* shortopts,
|
207 |
|
|
const char* longopts,
|
208 |
|
|
const char* datatype,
|
209 |
|
|
const char* glossary);
|
210 |
|
|
struct arg_str* arg_str1(const char* shortopts,
|
211 |
|
|
const char* longopts,
|
212 |
|
|
const char* datatype,
|
213 |
|
|
const char *glossary);
|
214 |
|
|
struct arg_str* arg_strn(const char* shortopts,
|
215 |
|
|
const char* longopts,
|
216 |
|
|
const char* datatype,
|
217 |
|
|
int mincount,
|
218 |
|
|
int maxcount,
|
219 |
|
|
const char *glossary);
|
220 |
|
|
|
221 |
|
|
struct arg_rex* arg_rex0(const char* shortopts,
|
222 |
|
|
const char* longopts,
|
223 |
|
|
const char* pattern,
|
224 |
|
|
const char* datatype,
|
225 |
|
|
int flags,
|
226 |
|
|
const char* glossary);
|
227 |
|
|
struct arg_rex* arg_rex1(const char* shortopts,
|
228 |
|
|
const char* longopts,
|
229 |
|
|
const char* pattern,
|
230 |
|
|
const char* datatype,
|
231 |
|
|
int flags,
|
232 |
|
|
const char *glossary);
|
233 |
|
|
struct arg_rex* arg_rexn(const char* shortopts,
|
234 |
|
|
const char* longopts,
|
235 |
|
|
const char* pattern,
|
236 |
|
|
const char* datatype,
|
237 |
|
|
int mincount,
|
238 |
|
|
int maxcount,
|
239 |
|
|
int flags,
|
240 |
|
|
const char *glossary);
|
241 |
|
|
|
242 |
|
|
struct arg_file* arg_file0(const char* shortopts,
|
243 |
|
|
const char* longopts,
|
244 |
|
|
const char* datatype,
|
245 |
|
|
const char* glossary);
|
246 |
|
|
struct arg_file* arg_file1(const char* shortopts,
|
247 |
|
|
const char* longopts,
|
248 |
|
|
const char* datatype,
|
249 |
|
|
const char *glossary);
|
250 |
|
|
struct arg_file* arg_filen(const char* shortopts,
|
251 |
|
|
const char* longopts,
|
252 |
|
|
const char* datatype,
|
253 |
|
|
int mincount,
|
254 |
|
|
int maxcount,
|
255 |
|
|
const char *glossary);
|
256 |
|
|
|
257 |
|
|
struct arg_date* arg_date0(const char* shortopts,
|
258 |
|
|
const char* longopts,
|
259 |
|
|
const char* format,
|
260 |
|
|
const char* datatype,
|
261 |
|
|
const char* glossary);
|
262 |
|
|
struct arg_date* arg_date1(const char* shortopts,
|
263 |
|
|
const char* longopts,
|
264 |
|
|
const char* format,
|
265 |
|
|
const char* datatype,
|
266 |
|
|
const char *glossary);
|
267 |
|
|
struct arg_date* arg_daten(const char* shortopts,
|
268 |
|
|
const char* longopts,
|
269 |
|
|
const char* format,
|
270 |
|
|
const char* datatype,
|
271 |
|
|
int mincount,
|
272 |
|
|
int maxcount,
|
273 |
|
|
const char *glossary);
|
274 |
|
|
|
275 |
|
|
struct arg_end* arg_end(int maxerrors);
|
276 |
|
|
|
277 |
|
|
|
278 |
|
|
/**** other functions *******************************************/
|
279 |
|
|
int arg_nullcheck(void **argtable);
|
280 |
|
|
int arg_parse(int argc, char **argv, void **argtable);
|
281 |
|
|
void arg_print_option(FILE *fp, const char *shortopts, const char *longopts, const char *datatype, const char *suffix);
|
282 |
|
|
void arg_print_syntax(FILE *fp, void **argtable, const char *suffix);
|
283 |
|
|
void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix);
|
284 |
|
|
void arg_print_glossary(FILE *fp, void **argtable, const char *format);
|
285 |
|
|
void arg_print_glossary_gnu(FILE *fp, void **argtable);
|
286 |
|
|
void arg_print_errors(FILE* fp, struct arg_end* end, const char* progname);
|
287 |
|
|
void arg_freetable(void **argtable, size_t n);
|
288 |
|
|
|
289 |
|
|
/**** deprecated functions, for back-compatibility only ********/
|
290 |
|
|
void arg_free(void **argtable);
|
291 |
|
|
|
292 |
|
|
#ifdef __cplusplus
|
293 |
|
|
}
|
294 |
|
|
#endif
|
295 |
|
|
#endif
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|