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