include/libtu/optparser.h

Mon, 17 Nov 2003 22:04:25 +0100

author
tuomov
date
Mon, 17 Nov 2003 22:04:25 +0100
changeset 56
af2c6d224f9d
parent 53
f8f9366b359c
permissions
-rw-r--r--

trunk: changeset 60
Check that PREV!=NULL when unlinking item from a list. (PREV must
point to something if on list.)

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

mercurial