Mercurial > hg > th-libs
annotate th_args.h @ 433:0a2f32b8a26e
Improve the build system.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 07 Apr 2017 02:48:31 +0300 |
parents | 4e7e0a74e73e |
children | 1b3472ba7b23 |
rev | line source |
---|---|
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * Simple commandline argument processing function |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
379
f4e182720870
Rename some function arguments and option argument structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
4 * (C) Copyright 2002-2016 Tecnic Software productions (TNSP) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
49
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
8 #ifndef TH_ARGS |
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
9 #define TH_ARGS |
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
10 |
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
11 #include "th_util.h" |
598609fb49b0
Change how "config.h" is included, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
12 #include <stdio.h> |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 #ifdef __cplusplus |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 extern "C" { |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 #endif |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 /* Option flags |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 */ |
140 | 20 #define OPT_NONE (0) // Simple option with no arguments |
21 #define OPT_ARGREQ (1) // Option requires an argument | |
142
0a4fd9cfb929
Revise the argument handling API. Breaks compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
22 #define OPT_ARGMASK (1) // Mask for option argument flags |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
140 | 24 #define OPTH_BAILOUT 0x0001 // Bail out on errors |
25 #define OPTH_ONLY_OPTS 0x0010 // Handle only options | |
26 #define OPTH_ONLY_OTHER 0x0020 // Handle only "non-options" | |
27 #define OPTH_ONLY_MASK 0x00f0 // Mask | |
137
0f43a94516f4
Improve argument handling module.
Matti Hamalainen <ccr@tnsp.org>
parents:
136
diff
changeset
|
28 |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 |
140 | 30 /* Option argument structure |
31 */ | |
136 | 32 typedef struct |
33 { | |
46
5f73c8cd333a
Change some structure member names in optarg_t.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
34 int id; |
381 | 35 char o_short; |
379
f4e182720870
Rename some function arguments and option argument structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
36 char *o_long; |
46
5f73c8cd333a
Change some structure member names in optarg_t.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
37 char *desc; |
5f73c8cd333a
Change some structure member names in optarg_t.
Matti Hamalainen <ccr@tnsp.org>
parents:
45
diff
changeset
|
38 int flags; |
380
ac10155d2b4a
Rename th_optarg_t to t_optarg. API break.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
39 } th_optarg; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 BOOL th_args_process(int argc, char *argv[], |
380
ac10155d2b4a
Rename th_optarg_t to t_optarg. API break.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
43 const th_optarg *opts, const int nopts, |
379
f4e182720870
Rename some function arguments and option argument structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
44 BOOL (*handle_option)(int id, char *, char *), |
f4e182720870
Rename some function arguments and option argument structure members.
Matti Hamalainen <ccr@tnsp.org>
parents:
144
diff
changeset
|
45 BOOL (*handle_other)(char *), const int flags); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
380
ac10155d2b4a
Rename th_optarg_t to t_optarg. API break.
Matti Hamalainen <ccr@tnsp.org>
parents:
379
diff
changeset
|
47 void th_args_help(FILE *, const th_optarg *opts, |
142
0a4fd9cfb929
Revise the argument handling API. Breaks compatibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
140
diff
changeset
|
48 const int nopts, const int flags); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 #ifdef __cplusplus |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 #endif |
129 | 53 #endif // TH_ARGS |