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