include/libtu/optparser.h

Fri, 21 Jul 2000 21:19:37 +0200

author
tuomov
date
Fri, 21 Jul 2000 21:19:37 +0200
changeset 18
afabe75987eb
parent 12
5fd153b29d40
child 34
828f3afd5c76
permissions
-rw-r--r--

trunk: changeset 21
Added 'bool' config file data type

5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
1 /*
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
2 * libtu/optparser.h
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
3 *
9
55e7f2ff6021 trunk: changeset 12
tuomov
parents: 8
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2000.
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
5 * See the included file LICENSE for details.
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
6 */
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
7
8
c1994196683f trunk: changeset 11
tuomov
parents: 5
diff changeset
8 #ifndef LIBTU_OPTPARSER_H
c1994196683f trunk: changeset 11
tuomov
parents: 5
diff changeset
9 #define LIBTU_OPTPARSER_H
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
10
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
11 #include "types.h"
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
12
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
13
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
14 #define OPT_ID_NOSHORT_FLAG 0x10000
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
15 #define OPT_ID_RESERVED_FLAG 0x20000
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
16
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
17 #define OPT_ID(X) ((X)|OPT_ID_NOSHORT_FLAG)
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
18 #define OPT_ID_RESERVED(X) ((X)|OPT_ID_RESERVED_FLAG)
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
19
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
20 /* OPTP_CHAIN is the normal behavior, i.e. single-letter options can be
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
21 * "chained" together: 'lr -lR'. Use for normal command line programs.
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
22 * OPTP_MIDLONG allows '-display foo' -like args but disables chaining
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
23 * of single-letter options. X programs should probably use this.
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
24 * OPTP_IMMEDIATE allows immediate arguments (-I/usr/include) (and disables
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
25 * chaining and midlong options).
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
26 * OPTP_NO_DASH is the same as OPTP_CHAIN but allows the dash to be omitted
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
27 * for 'tar xzf foo' -like behavior.
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
28 * Long '--foo=bar' options are supported in all of the modes.
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
29 */
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
30
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
31 enum{
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
32 OPTP_CHAIN=0,
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
33 OPTP_DEFAULT=0,
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
34 OPTP_MIDLONG=1,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
35 OPTP_IMMEDIATE=2,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
36 OPTP_NO_DASH=3
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
37 };
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
38
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
39 enum{
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
40 OPT_ARG=1, /* option has an argument */
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
41 OPT_OPT_ARG=3 /* option may have an argument */
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
42 };
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
43
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
44
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
45 typedef struct _OptParserOpt{
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
46 int optid;
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
47 const char *longopt;
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
48 int flags;
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
49 const char *argname;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
50 const char *descr;
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
51 } OptParserOpt;
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
52
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
53
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
54 typedef struct _OptParserCommonInfo{
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
55 const char *version;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
56 const char *usage_tmpl;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
57 const char *about;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
58 } OptParserCommonInfo;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
59
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
60
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
61 enum{
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
62 OPT_ID_END=0,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
63 OPT_ID_ARGUMENT=1,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
64
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
65 E_OPT_INVALID_OPTION=-1,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
66 E_OPT_INVALID_CHAIN_OPTION=-2,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
67 E_OPT_SYNTAX_ERROR=-3,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
68 E_OPT_MISSING_ARGUMENT=-4,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
69 E_OPT_UNEXPECTED_ARGUMENT=-5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
70 };
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
71
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
72
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
73 extern void optparser_init(int argc, char *const argv[], int mode,
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
74 const OptParserOpt *opts,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
75 const OptParserCommonInfo *cinfo);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
76
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
77 extern int optparser_get_opt();
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
78 extern const char* optparser_get_arg();
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
79 extern void optparser_print_error();
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
80
8
c1994196683f trunk: changeset 11
tuomov
parents: 5
diff changeset
81 #endif /* LIBTU_OPTPARSER_H */

mercurial