annotate th_args.h @ 380:ac10155d2b4a

Rename th_optarg_t to t_optarg. API break.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 01 Mar 2016 17:21:22 +0200
parents f4e182720870
children 4e7e0a74e73e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
20 #define OPT_NONE (0) // Simple option with no arguments
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
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
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
24 #define OPTH_BAILOUT 0x0001 // Bail out on errors
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
25 #define OPTH_ONLY_OPTS 0x0010 // Handle only options
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
26 #define OPTH_ONLY_OTHER 0x0020 // Handle only "non-options"
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
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
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
30 /* Option argument structure
f81c6dc7bd0f Cosmetics, comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 137
diff changeset
31 */
136
286b2249c5d2 Clean up th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
32 typedef struct
286b2249c5d2 Clean up th_args API.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
33 {
46
5f73c8cd333a Change some structure member names in optarg_t.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
34 int id;
379
f4e182720870 Rename some function arguments and option argument structure members.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
35 char o_hort;
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
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 66
diff changeset
53 #endif // TH_ARGS