Sun, 14 May 2000 18:58:42 +0200
trunk: changeset 13
Use $(ANSI_SOURCE)
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 | ||
14 | #define OPT_ID(X) ((X)|0x10000) | |
15 | #define OPT_ID_RESERVED(X) ((X)|0x20000) | |
16 | ||
17 | /* OPTP_CHAIN is the normal behavior, i.e. single-letter options can be | |
18 | * "chained" together: 'lr -lR'. Use for normal command line programs. | |
19 | * OPTP_MIDLONG allows '-display foo' -like args but disables chaining | |
20 | * of single-letter options. X programs should probably use this. | |
21 | * OPTP_IMMEDIATE allows immediate arguments (-I/usr/include) (and disables | |
22 | * chaining and midlong options). | |
23 | * OPTP_NO_DASH is the same as OPTP_CHAIN but allows the dash to be omitted | |
24 | * for 'tar xzf foo' -like behavior. | |
25 | * Long '--foo=bar' options are supported in all of the modes. | |
26 | */ | |
27 | ||
28 | enum{ | |
29 | OPTP_CHAIN=0, | |
30 | OPTP_MIDLONG=1, | |
31 | OPTP_IMMEDIATE=2, | |
32 | OPTP_NO_DASH=3 | |
33 | }; | |
34 | ||
35 | enum{ | |
36 | OPT_ARG=1, /* option has an argument */ | |
37 | OPT_OPT_ARG=3 /* option may have an argument */ | |
38 | }; | |
39 | ||
40 | ||
41 | typedef struct{ | |
42 | int optid; | |
43 | const char *longopt; | |
44 | int flags; | |
45 | } OptParserOpt; | |
46 | ||
47 | ||
48 | enum{ | |
49 | OPT_ID_END=0, | |
50 | OPT_ID_ARGUMENT=1, | |
51 | ||
52 | E_OPT_INVALID_OPTION=-1, | |
53 | E_OPT_INVALID_CHAIN_OPTION=-2, | |
54 | E_OPT_SYNTAX_ERROR=-3, | |
55 | E_OPT_MISSING_ARGUMENT=-4, | |
56 | E_OPT_UNEXPECTED_ARGUMENT=-5 | |
57 | }; | |
58 | ||
59 | ||
60 | extern void optparser_init(int argc, char *const argv[], int mode, | |
61 | const OptParserOpt *opts); | |
62 | extern int optparser_get_opt(); | |
63 | extern const char* optparser_get_arg(); | |
64 | extern void optparser_print_error(); | |
65 | ||
8 | 66 | #endif /* LIBTU_OPTPARSER_H */ |