Wed, 19 Apr 2000 22:03:38 +0200
trunk: changeset 6
- Simpler optparser
- New Makefile system
0 | 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 | enum{ | |
20 | OPT__IMM_ARG=0x0100, | |
21 | OPT_IMM_ARG=0x0101, /* may have immediate argument (-fblaah) */ | |
22 | OPT_CHAINABLE=0x0200, /* chainable (-xzf) */ | |
23 | OPT_NO_DASH=0x0400, /* dash not necessary (xzf) */ | |
24 | OPT_MIDLONG=0x0800, /* have midlong opt (-help) */ | |
25 | OPT_NO_LONG=0x1000, /* no long opt (--help) */ | |
26 | OPT_ARG=1, /* option has an argument */ | |
27 | OPT_OPT_ARG=3 /* option may have an argument */ | |
28 | }; | |
29 | ||
30 | ||
31 | typedef struct{ | |
32 | int optid; | |
33 | const char *longopt; | |
34 | int flags; | |
35 | } OptParserOpt; | |
36 | ||
37 | ||
38 | enum{ | |
39 | OPT_ID_END=0, | |
40 | OPT_ID_ARGUMENT=1, | |
41 | ||
42 | E_OPT_INVALID_OPTION=-1, | |
43 | E_OPT_INVALID_CHAIN_OPTION=-2, | |
44 | E_OPT_SYNTAX_ERROR=-3, | |
45 | E_OPT_MISSING_ARGUMENT=-4, | |
46 | E_OPT_UNEXPECTED_ARGUMENT=-5 | |
47 | }; | |
48 | ||
49 | ||
50 | extern void optparser_init(int argc, char *const argv[], | |
51 | const OptParserOpt *opts); | |
52 | extern int optparser_get_opt(); | |
53 | extern const char* optparser_get_arg(); | |
54 | extern void optparser_print_error(); | |
55 | ||
56 | #endif /* __LIBTU_OPTPARSER_H */ |