include/libtu/optparser.h

changeset 12
5fd153b29d40
parent 9
55e7f2ff6021
child 34
828f3afd5c76
equal deleted inserted replaced
11:3ea4e7930c5b 12:5fd153b29d40
9 #define LIBTU_OPTPARSER_H 9 #define LIBTU_OPTPARSER_H
10 10
11 #include "types.h" 11 #include "types.h"
12 12
13 13
14 #define OPT_ID(X) ((X)|0x10000) 14 #define OPT_ID_NOSHORT_FLAG 0x10000
15 #define OPT_ID_RESERVED(X) ((X)|0x20000) 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)
16 19
17 /* OPTP_CHAIN is the normal behavior, i.e. single-letter options can be 20 /* OPTP_CHAIN is the normal behavior, i.e. single-letter options can be
18 * "chained" together: 'lr -lR'. Use for normal command line programs. 21 * "chained" together: 'lr -lR'. Use for normal command line programs.
19 * OPTP_MIDLONG allows '-display foo' -like args but disables chaining 22 * OPTP_MIDLONG allows '-display foo' -like args but disables chaining
20 * of single-letter options. X programs should probably use this. 23 * of single-letter options. X programs should probably use this.
25 * Long '--foo=bar' options are supported in all of the modes. 28 * Long '--foo=bar' options are supported in all of the modes.
26 */ 29 */
27 30
28 enum{ 31 enum{
29 OPTP_CHAIN=0, 32 OPTP_CHAIN=0,
33 OPTP_DEFAULT=0,
30 OPTP_MIDLONG=1, 34 OPTP_MIDLONG=1,
31 OPTP_IMMEDIATE=2, 35 OPTP_IMMEDIATE=2,
32 OPTP_NO_DASH=3 36 OPTP_NO_DASH=3
33 }; 37 };
34 38
36 OPT_ARG=1, /* option has an argument */ 40 OPT_ARG=1, /* option has an argument */
37 OPT_OPT_ARG=3 /* option may have an argument */ 41 OPT_OPT_ARG=3 /* option may have an argument */
38 }; 42 };
39 43
40 44
41 typedef struct{ 45 typedef struct _OptParserOpt{
42 int optid; 46 int optid;
43 const char *longopt; 47 const char *longopt;
44 int flags; 48 int flags;
49 const char *argname;
50 const char *descr;
45 } OptParserOpt; 51 } OptParserOpt;
52
53
54 typedef struct _OptParserCommonInfo{
55 const char *version;
56 const char *usage_tmpl;
57 const char *about;
58 } OptParserCommonInfo;
46 59
47 60
48 enum{ 61 enum{
49 OPT_ID_END=0, 62 OPT_ID_END=0,
50 OPT_ID_ARGUMENT=1, 63 OPT_ID_ARGUMENT=1,
56 E_OPT_UNEXPECTED_ARGUMENT=-5 69 E_OPT_UNEXPECTED_ARGUMENT=-5
57 }; 70 };
58 71
59 72
60 extern void optparser_init(int argc, char *const argv[], int mode, 73 extern void optparser_init(int argc, char *const argv[], int mode,
61 const OptParserOpt *opts); 74 const OptParserOpt *opts,
75 const OptParserCommonInfo *cinfo);
76
62 extern int optparser_get_opt(); 77 extern int optparser_get_opt();
63 extern const char* optparser_get_arg(); 78 extern const char* optparser_get_arg();
64 extern void optparser_print_error(); 79 extern void optparser_print_error();
65 80
66 #endif /* LIBTU_OPTPARSER_H */ 81 #endif /* LIBTU_OPTPARSER_H */

mercurial