optparser.h

Mon, 17 Jan 2005 22:02:09 +0100

author
tuomov
date
Mon, 17 Jan 2005 22:02:09 +0100
changeset 85
9f94b2e96e3b
parent 79
81e9a32b1c0c
permissions
-rw-r--r--

trunk: changeset 1934
Fixed everything that requires locale stuff to check CF_NO_LOCALE.

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

mercurial