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