Commit | Line | Data |
---|---|---|
1479465f GJ |
1 | /* |
2 | * libdpkg - Debian packaging suite library routines | |
3 | * options.h - option parsing functions | |
4 | * | |
5 | * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk> | |
6 | * Copyright © 2008-2014 Guillem Jover <guillem@debian.org> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #ifndef LIBDPKG_OPTIONS_H | |
23 | #define LIBDPKG_OPTIONS_H | |
24 | ||
25 | #include <dpkg/macros.h> | |
26 | #include <dpkg/dpkg-db.h> | |
27 | ||
28 | DPKG_BEGIN_DECLS | |
29 | ||
30 | /** | |
31 | * @defgroup options Option parsing | |
32 | * @ingroup dpkg-internal | |
33 | * @{ | |
34 | */ | |
35 | ||
36 | typedef int action_func(const char *const *argv); | |
37 | ||
38 | struct cmdinfo { | |
39 | const char *olong; | |
40 | char oshort; | |
41 | ||
42 | /* | |
43 | * 0 = Normal (-o, --option) | |
44 | * 1 = Standard value (-o=value, --option=value or | |
45 | * -o value, --option value) | |
46 | * 2 = Option string continued (--option-value) | |
47 | */ | |
48 | int takesvalue; | |
49 | int *iassignto; | |
50 | const char **sassignto; | |
51 | void (*call)(const struct cmdinfo*, const char *value); | |
52 | ||
53 | int arg_int; | |
54 | void *arg_ptr; | |
55 | ||
56 | action_func *action; | |
57 | }; | |
58 | ||
59 | void badusage(const char *fmt, ...) DPKG_ATTR_NORET DPKG_ATTR_PRINTF(1); | |
60 | ||
61 | #define MAX_CONFIG_LINE 1024 | |
62 | ||
63 | void dpkg_options_load(const char *prog, const struct cmdinfo *cmdinfos); | |
64 | void dpkg_options_parse(const char *const **argvp, | |
65 | const struct cmdinfo *cmdinfos, const char *help_str); | |
66 | ||
67 | long dpkg_options_parse_arg_int(const struct cmdinfo *cmd, const char *str); | |
68 | ||
69 | struct pkginfo * | |
70 | dpkg_options_parse_pkgname(const struct cmdinfo *cmd, const char *name); | |
71 | ||
72 | /** | |
73 | * Current cmdinfo action. | |
74 | */ | |
75 | extern const struct cmdinfo *cipaction; | |
76 | ||
77 | void setaction(const struct cmdinfo *cip, const char *value); | |
78 | void setobsolete(const struct cmdinfo *cip, const char *value); | |
79 | ||
80 | #define ACTION(longopt, shortopt, code, func) \ | |
81 | { longopt, shortopt, 0, NULL, NULL, setaction, code, NULL, func } | |
82 | #define OBSOLETE(longopt, shortopt) \ | |
83 | { longopt, shortopt, 0, NULL, NULL, setobsolete, 0, NULL, NULL } | |
84 | ||
85 | /** @} */ | |
86 | ||
87 | DPKG_END_DECLS | |
88 | ||
89 | #endif /* LIBDPKG_OPTIONS_H */ |