optparser.h

Sun, 07 Mar 2004 22:45:24 +0100

author
tuomov
date
Sun, 07 Mar 2004 22:45:24 +0100
changeset 64
f20d97d852ce
parent 62
aae5facf9fc5
child 79
81e9a32b1c0c
permissions
-rw-r--r--

trunk: changeset 1362
Added libtu_strcasestr.

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 *
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2002.
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
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
58 typedef struct _OptParserCommonInfo{
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
59 const char *version;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
60 const char *usage_tmpl;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
61 const char *about;
58
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
62 } OptParserCommonInfo;
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
63
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
64
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
65 enum{
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
66 OPT_ID_END=0,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
67 OPT_ID_ARGUMENT=1,
58
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
68
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
69 E_OPT_INVALID_OPTION=-1,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
70 E_OPT_INVALID_CHAIN_OPTION=-2,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
71 E_OPT_SYNTAX_ERROR=-3,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
72 E_OPT_MISSING_ARGUMENT=-4,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
73 E_OPT_UNEXPECTED_ARGUMENT=-5
58
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
74 };
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
75
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
76
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
77 extern void optparser_init(int argc, char *const argv[], int mode,
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
78 const OptParserOpt *opts,
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 58
diff changeset
79 const OptParserCommonInfo *cinfo);
58
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
80
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
81 extern int optparser_get_opt();
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
82 extern const char* optparser_get_arg();
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
83 extern void optparser_print_error();
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
84
789df543d0c3 trunk: changeset 1303
tuomov
parents:
diff changeset
85 #endif /* LIBTU_OPTPARSER_H */

mercurial