biomcmc-lib  0.1
low level library for phylogenetic analysis
argtable3.h
1 /*******************************************************************************
2  * This file is part of the argtable3 library.
3  *
4  * Copyright (C) 1998-2001,2003-2011,2013 Stewart Heitmann
5  * <sheitmann@users.sourceforge.net>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of STEWART HEITMANN nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
23  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  ******************************************************************************/
30 
31 #ifndef ARGTABLE3
32 #define ARGTABLE3
33 
34 #include "lowlevel.h"
35 #include <getopt.h>
36 #include <errno.h>
37 #include <err.h>
38 #include <setjmp.h>
39 
40 // On Windows isspace crashes app in case of using Unicode character set and string to be above ASCII
41 // so you have to use _istspace instead of space
42 #ifdef UNICODE
43 #include <tchar.h>
44  #define ISSPACE _istspace
45 #else
46  #define ISSPACE isspace
47 #endif
48 
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 #define ARG_REX_ICASE 1
55 
56 /* bit masks for arg_hdr.flag */
57 enum
58 {
59  ARG_TERMINATOR=0x1,
60  ARG_HASVALUE=0x2,
61  ARG_HASOPTVALUE=0x4
62 };
63 
64 typedef void (arg_resetfn)(void *parent);
65 typedef int (arg_scanfn)(void *parent, const char *argval);
66 typedef int (arg_checkfn)(void *parent);
67 typedef void (arg_errorfn)(void *parent, FILE *fp, int error, const char *argval, const char *progname);
68 
69 
70 /*
71 * The arg_hdr struct defines properties that are common to all arg_xxx structs.
72 * The argtable library requires each arg_xxx struct to have an arg_hdr
73 * struct as its first data member.
74 * The argtable library functions then use this data to identify the
75 * properties of the command line option, such as its option tags,
76 * datatype string, and glossary strings, and so on.
77 * Moreover, the arg_hdr struct contains pointers to custom functions that
78 * are provided by each arg_xxx struct which perform the tasks of parsing
79 * that particular arg_xxx arguments, performing post-parse checks, and
80 * reporting errors.
81 * These functions are private to the individual arg_xxx source code
82 * and are the pointer to them are initiliased by that arg_xxx struct's
83 * constructor function. The user could alter them after construction
84 * if desired, but the original intention is for them to be set by the
85 * constructor and left unaltered.
86 */
87 struct arg_hdr
88 {
89  char flag; /* Modifier flags: ARG_TERMINATOR, ARG_HASVALUE. */
90  const char *shortopts; /* String defining the short options */
91  const char *longopts; /* String defiing the long options */
92  const char *datatype; /* Description of the argument data type */
93  const char *glossary; /* Description of the option as shown by arg_print_glossary function */
94  int mincount; /* Minimum number of occurences of this option accepted */
95  int maxcount; /* Maximum number of occurences if this option accepted */
96  void *parent; /* Pointer to parent arg_xxx struct */
97  arg_resetfn *resetfn; /* Pointer to parent arg_xxx reset function */
98  arg_scanfn *scanfn; /* Pointer to parent arg_xxx scan function */
99  arg_checkfn *checkfn; /* Pointer to parent arg_xxx check function */
100  arg_errorfn *errorfn; /* Pointer to parent arg_xxx error function */
101  void *priv; /* Pointer to private header data for use by arg_xxx functions */
102 };
103 
104 struct arg_rem
105 {
106  struct arg_hdr hdr; /* The mandatory argtable header struct */
107 };
108 
109 struct arg_lit
110 {
111  struct arg_hdr hdr; /* The mandatory argtable header struct */
112  int count; /* Number of matching command line args */
113 };
114 
115 struct arg_int
116 {
117  struct arg_hdr hdr; /* The mandatory argtable header struct */
118  int count; /* Number of matching command line args */
119  int *ival; /* Array of parsed argument values */
120 };
121 
122 struct arg_dbl
123 {
124  struct arg_hdr hdr; /* The mandatory argtable header struct */
125  int count; /* Number of matching command line args */
126  double *dval; /* Array of parsed argument values */
127 };
128 
129 struct arg_str
130 {
131  struct arg_hdr hdr; /* The mandatory argtable header struct */
132  int count; /* Number of matching command line args */
133  const char **sval; /* Array of parsed argument values */
134 };
135 
136 struct arg_rex
137 {
138  struct arg_hdr hdr; /* The mandatory argtable header struct */
139  int count; /* Number of matching command line args */
140  const char **sval; /* Array of parsed argument values */
141 };
142 
143 struct arg_file
144 {
145  struct arg_hdr hdr; /* The mandatory argtable header struct */
146  int count; /* Number of matching command line args*/
147  const char **filename; /* Array of parsed filenames (eg: /home/foo.bar) */
148  const char **basename; /* Array of parsed basenames (eg: foo.bar) */
149  const char **extension; /* Array of parsed extensions (eg: .bar) */
150 };
151 
152 struct arg_date
153 {
154  struct arg_hdr hdr; /* The mandatory argtable header struct */
155  const char *format; /* strptime format string used to parse the date */
156  int count; /* Number of matching command line args */
157  struct tm *tmval; /* Array of parsed time values */
158 };
159 
160 enum {ARG_ELIMIT=1, ARG_EMALLOC, ARG_ENOMATCH, ARG_ELONGOPT, ARG_EMISSARG};
161 struct arg_end
162 {
163  struct arg_hdr hdr; /* The mandatory argtable header struct */
164  int count; /* Number of errors encountered */
165  int *error; /* Array of error codes */
166  void **parent; /* Array of pointers to offending arg_xxx struct */
167  const char **argval; /* Array of pointers to offending argv[] string */
168 };
169 
170 
171 /**** arg_xxx constructor functions *********************************/
172 
173 struct arg_rem* arg_rem(const char* datatype, const char* glossary);
174 
175 struct arg_lit* arg_lit0(const char* shortopts,
176  const char* longopts,
177  const char* glossary);
178 struct arg_lit* arg_lit1(const char* shortopts,
179  const char* longopts,
180  const char *glossary);
181 struct arg_lit* arg_litn(const char* shortopts,
182  const char* longopts,
183  int mincount,
184  int maxcount,
185  const char *glossary);
186 
187 struct arg_key* arg_key0(const char* keyword,
188  int flags,
189  const char* glossary);
190 struct arg_key* arg_key1(const char* keyword,
191  int flags,
192  const char* glossary);
193 struct arg_key* arg_keyn(const char* keyword,
194  int flags,
195  int mincount,
196  int maxcount,
197  const char* glossary);
198 
199 struct arg_int* arg_int0(const char* shortopts,
200  const char* longopts,
201  const char* datatype,
202  const char* glossary);
203 struct arg_int* arg_int1(const char* shortopts,
204  const char* longopts,
205  const char* datatype,
206  const char *glossary);
207 struct arg_int* arg_intn(const char* shortopts,
208  const char* longopts,
209  const char *datatype,
210  int mincount,
211  int maxcount,
212  const char *glossary);
213 
214 struct arg_dbl* arg_dbl0(const char* shortopts,
215  const char* longopts,
216  const char* datatype,
217  const char* glossary);
218 struct arg_dbl* arg_dbl1(const char* shortopts,
219  const char* longopts,
220  const char* datatype,
221  const char *glossary);
222 struct arg_dbl* arg_dbln(const char* shortopts,
223  const char* longopts,
224  const char *datatype,
225  int mincount,
226  int maxcount,
227  const char *glossary);
228 
229 struct arg_str* arg_str0(const char* shortopts,
230  const char* longopts,
231  const char* datatype,
232  const char* glossary);
233 struct arg_str* arg_str1(const char* shortopts,
234  const char* longopts,
235  const char* datatype,
236  const char *glossary);
237 struct arg_str* arg_strn(const char* shortopts,
238  const char* longopts,
239  const char* datatype,
240  int mincount,
241  int maxcount,
242  const char *glossary);
243 
244 struct arg_rex* arg_rex0(const char* shortopts,
245  const char* longopts,
246  const char* pattern,
247  const char* datatype,
248  int flags,
249  const char* glossary);
250 struct arg_rex* arg_rex1(const char* shortopts,
251  const char* longopts,
252  const char* pattern,
253  const char* datatype,
254  int flags,
255  const char *glossary);
256 struct arg_rex* arg_rexn(const char* shortopts,
257  const char* longopts,
258  const char* pattern,
259  const char* datatype,
260  int mincount,
261  int maxcount,
262  int flags,
263  const char *glossary);
264 
265 struct arg_file* arg_file0(const char* shortopts,
266  const char* longopts,
267  const char* datatype,
268  const char* glossary);
269 struct arg_file* arg_file1(const char* shortopts,
270  const char* longopts,
271  const char* datatype,
272  const char *glossary);
273 struct arg_file* arg_filen(const char* shortopts,
274  const char* longopts,
275  const char* datatype,
276  int mincount,
277  int maxcount,
278  const char *glossary);
279 
280 struct arg_date* arg_date0(const char* shortopts,
281  const char* longopts,
282  const char* format,
283  const char* datatype,
284  const char* glossary);
285 struct arg_date* arg_date1(const char* shortopts,
286  const char* longopts,
287  const char* format,
288  const char* datatype,
289  const char *glossary);
290 struct arg_date* arg_daten(const char* shortopts,
291  const char* longopts,
292  const char* format,
293  const char* datatype,
294  int mincount,
295  int maxcount,
296  const char *glossary);
297 
298 struct arg_end* arg_end(int maxerrors);
299 
300 /**** other functions *******************************************/
301 int arg_nullcheck(void **argtable);
302 int arg_parse(int argc, char **argv, void **argtable);
303 void arg_print_option(FILE *fp, const char *shortopts, const char *longopts, const char *datatype, const char *suffix);
304 void arg_print_syntax(FILE *fp, void **argtable, const char *suffix);
305 void arg_print_syntaxv(FILE *fp, void **argtable, const char *suffix);
306 void arg_print_glossary(FILE *fp, void **argtable, const char *format);
307 void arg_print_glossary_gnu(FILE *fp, void **argtable);
308 void arg_print_errors(FILE* fp, struct arg_end* end, const char* progname);
309 void arg_freetable(void **argtable, size_t n);
310 void arg_print_formatted(FILE *fp, const unsigned lmargin, const unsigned rmargin, const char *text);
311 
312 /**** deprecated functions, for back-compatibility only ********/
313 void arg_free(void **argtable);
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 #endif
Definition: argtable3.h:152
Definition: argtable3.h:87
Definition: argtable3.h:129
Definition: argtable3.h:161
Lowest level header file. Header file for lowlevel.c.
Definition: argtable3.h:104
Definition: argtable3.h:143
Definition: argtable3.h:122
Definition: argtable3.h:115
Definition: argtable3.h:136
Definition: argtable3.h:109