include/libtu/optparser.h

Sat, 29 Apr 2000 15:35:45 +0200

author
tuomov
date
Sat, 29 Apr 2000 15:35:45 +0200
changeset 9
55e7f2ff6021
parent 8
c1994196683f
child 12
5fd153b29d40
permissions
-rw-r--r--

trunk: changeset 12
Changed the copyright notice in headers

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

mercurial