include/libtu/optparser.h

Mon, 17 Feb 2003 23:24:47 +0100

author
tuomov
date
Mon, 17 Feb 2003 23:24:47 +0100
changeset 43
aad48c3d4966
parent 39
ebea551c80dc
child 53
f8f9366b359c
permissions
-rw-r--r--

trunk: changeset 46
UNLINK_ITEM fixed to reset next/previous pointers to NULL

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 *
36
63cd573ffbcf trunk: changeset 39
tuomov
parents: 35
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2002.
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
39
ebea551c80dc trunk: changeset 42
tuomov
parents: 37
diff changeset
45 #define END_OPTPARSEROPTS {0, NULL, 0, NULL, NULL}
37
3cf58eae0df6 trunk: changeset 40
tuomov
parents: 36
diff changeset
46
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
47 typedef struct _OptParserOpt{
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
48 int optid;
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
49 const char *longopt;
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
50 int flags;
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
51 const char *argname;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
52 const char *descr;
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
53 } OptParserOpt;
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
54
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
55
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
56 typedef struct _OptParserCommonInfo{
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
57 const char *version;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
58 const char *usage_tmpl;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
59 const char *about;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
60 } OptParserCommonInfo;
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
61
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
62
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
63 enum{
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
64 OPT_ID_END=0,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
65 OPT_ID_ARGUMENT=1,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
66
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
67 E_OPT_INVALID_OPTION=-1,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
68 E_OPT_INVALID_CHAIN_OPTION=-2,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
69 E_OPT_SYNTAX_ERROR=-3,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
70 E_OPT_MISSING_ARGUMENT=-4,
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
71 E_OPT_UNEXPECTED_ARGUMENT=-5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
72 };
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
73
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
74
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
75 extern void optparser_init(int argc, char *const argv[], int mode,
12
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
76 const OptParserOpt *opts,
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
77 const OptParserCommonInfo *cinfo);
5fd153b29d40 trunk: changeset 15
tuomov
parents: 9
diff changeset
78
5
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
79 extern int optparser_get_opt();
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
80 extern const char* optparser_get_arg();
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
81 extern void optparser_print_error();
f878a9ffa3e0 trunk: changeset 8
tuomov
parents:
diff changeset
82
8
c1994196683f trunk: changeset 11
tuomov
parents: 5
diff changeset
83 #endif /* LIBTU_OPTPARSER_H */

mercurial