4
|
1 /*
|
|
2 lw_cmdline.h
|
|
3
|
|
4 Copyright © 2010 William Astle
|
|
5
|
|
6 This file is part of LWTOOLS.
|
|
7
|
|
8 LWTOOLS is free software: you can redistribute it and/or modify it under the
|
|
9 terms of the GNU General Public License as published by the Free Software
|
|
10 Foundation, either version 3 of the License, or (at your option) any later
|
|
11 version.
|
|
12
|
|
13 This program is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
16 more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License along with
|
|
19 this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20 */
|
|
21
|
|
22 /*
|
|
23
|
|
24 This argument parser is patterned after argp from the gnu C library but
|
|
25 has much of the functionality removed. It is provided here because not
|
|
26 every system has glibc.
|
|
27
|
|
28 Most notably, it does not support option groups or i18n.
|
|
29
|
|
30 */
|
|
31
|
|
32 #ifndef ___lw_cmdline_h_seen___
|
|
33 #define ___lw_cmdline_h_seen___
|
|
34
|
|
35 struct lw_cmdline_options
|
|
36 {
|
|
37 char *name;
|
|
38 int key;
|
|
39 char *arg;
|
|
40 int flags;
|
|
41 char *doc;
|
|
42 };
|
|
43
|
|
44 enum
|
|
45 {
|
|
46 lw_cmdline_opt_optional = 1,
|
192
|
47 lw_cmdline_opt_hidden = 2,
|
5
|
48 /* lw_cmdline_opt_alias = 4,*/
|
|
49 /* lw_cmdline_opt_nousage = 0x10,*/
|
|
50 lw_cmdline_opt_doc = 0x80
|
4
|
51 };
|
|
52
|
|
53 enum
|
|
54 {
|
|
55 lw_cmdline_err_unknown = -1
|
|
56 };
|
|
57
|
|
58 enum
|
|
59 {
|
|
60 lw_cmdline_key_arg = -1,
|
|
61 lw_cmdline_key_end = 0
|
|
62 };
|
|
63
|
|
64 struct lw_cmdline_parser
|
|
65 {
|
|
66 struct lw_cmdline_options *options;
|
|
67 int (*parser)(int key, char *arg, void *input);
|
|
68 char *args_doc;
|
|
69 char *doc;
|
|
70 char *program_version;
|
|
71 };
|
|
72
|
374
|
73 int lw_cmdline_parse(struct lw_cmdline_parser *parser, int argc, char **argv, unsigned flags, int *arg_index, void *input);
|
4
|
74
|
|
75 #endif /* ___lw_cmdline_h_seen___ */
|