include/libtu/optparser.h

Wed, 19 Apr 2000 22:10:28 +0200

author
tuomov
date
Wed, 19 Apr 2000 22:10:28 +0200
changeset 5
f878a9ffa3e0
child 8
c1994196683f
permissions
-rw-r--r--

trunk: changeset 8
Moved include/*.h to include/libtu/

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

mercurial