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