root / qemu-option.h @ e3e87df4
History | View | Annotate | Download (5.7 kB)
1 | d3f24367 | Kevin Wolf | /*
|
---|---|---|---|
2 | d3f24367 | Kevin Wolf | * Commandline option parsing functions
|
3 | d3f24367 | Kevin Wolf | *
|
4 | d3f24367 | Kevin Wolf | * Copyright (c) 2003-2008 Fabrice Bellard
|
5 | d3f24367 | Kevin Wolf | * Copyright (c) 2009 Kevin Wolf <kwolf@redhat.com>
|
6 | d3f24367 | Kevin Wolf | *
|
7 | d3f24367 | Kevin Wolf | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | d3f24367 | Kevin Wolf | * of this software and associated documentation files (the "Software"), to deal
|
9 | d3f24367 | Kevin Wolf | * in the Software without restriction, including without limitation the rights
|
10 | d3f24367 | Kevin Wolf | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | d3f24367 | Kevin Wolf | * copies of the Software, and to permit persons to whom the Software is
|
12 | d3f24367 | Kevin Wolf | * furnished to do so, subject to the following conditions:
|
13 | d3f24367 | Kevin Wolf | *
|
14 | d3f24367 | Kevin Wolf | * The above copyright notice and this permission notice shall be included in
|
15 | d3f24367 | Kevin Wolf | * all copies or substantial portions of the Software.
|
16 | d3f24367 | Kevin Wolf | *
|
17 | d3f24367 | Kevin Wolf | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | d3f24367 | Kevin Wolf | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | d3f24367 | Kevin Wolf | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | d3f24367 | Kevin Wolf | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | d3f24367 | Kevin Wolf | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | d3f24367 | Kevin Wolf | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | d3f24367 | Kevin Wolf | * THE SOFTWARE.
|
24 | d3f24367 | Kevin Wolf | */
|
25 | d3f24367 | Kevin Wolf | |
26 | d3f24367 | Kevin Wolf | #ifndef QEMU_OPTIONS_H
|
27 | d3f24367 | Kevin Wolf | #define QEMU_OPTIONS_H
|
28 | d3f24367 | Kevin Wolf | |
29 | 8756aa72 | Blue Swirl | #include <stdint.h> |
30 | 72cf2d4f | Blue Swirl | #include "qemu-queue.h" |
31 | 8be7e7e4 | Luiz Capitulino | #include "error.h" |
32 | 01e7f188 | Markus Armbruster | #include "qdict.h" |
33 | e27c88fe | Gerd Hoffmann | |
34 | d3f24367 | Kevin Wolf | enum QEMUOptionParType {
|
35 | d3f24367 | Kevin Wolf | OPT_FLAG, |
36 | d3f24367 | Kevin Wolf | OPT_NUMBER, |
37 | d3f24367 | Kevin Wolf | OPT_SIZE, |
38 | d3f24367 | Kevin Wolf | OPT_STRING, |
39 | d3f24367 | Kevin Wolf | }; |
40 | d3f24367 | Kevin Wolf | |
41 | d3f24367 | Kevin Wolf | typedef struct QEMUOptionParameter { |
42 | d3f24367 | Kevin Wolf | const char *name; |
43 | d3f24367 | Kevin Wolf | enum QEMUOptionParType type;
|
44 | d3f24367 | Kevin Wolf | union {
|
45 | d3f24367 | Kevin Wolf | uint64_t n; |
46 | d3f24367 | Kevin Wolf | char* s;
|
47 | d3f24367 | Kevin Wolf | } value; |
48 | db08adf5 | Kevin Wolf | const char *help; |
49 | d3f24367 | Kevin Wolf | } QEMUOptionParameter; |
50 | d3f24367 | Kevin Wolf | |
51 | d3f24367 | Kevin Wolf | |
52 | d3f24367 | Kevin Wolf | const char *get_opt_name(char *buf, int buf_size, const char *p, char delim); |
53 | d3f24367 | Kevin Wolf | const char *get_opt_value(char *buf, int buf_size, const char *p); |
54 | 62c5802e | Gerd Hoffmann | int get_next_param_value(char *buf, int buf_size, |
55 | 62c5802e | Gerd Hoffmann | const char *tag, const char **pstr); |
56 | 62c5802e | Gerd Hoffmann | int get_param_value(char *buf, int buf_size, |
57 | 62c5802e | Gerd Hoffmann | const char *tag, const char *str); |
58 | 62c5802e | Gerd Hoffmann | int check_params(char *buf, int buf_size, |
59 | 62c5802e | Gerd Hoffmann | const char * const *params, const char *str); |
60 | d3f24367 | Kevin Wolf | |
61 | d3f24367 | Kevin Wolf | |
62 | d3f24367 | Kevin Wolf | /*
|
63 | d3f24367 | Kevin Wolf | * The following functions take a parameter list as input. This is a pointer to
|
64 | d3f24367 | Kevin Wolf | * the first element of a QEMUOptionParameter array which is terminated by an
|
65 | d3f24367 | Kevin Wolf | * entry with entry->name == NULL.
|
66 | d3f24367 | Kevin Wolf | */
|
67 | d3f24367 | Kevin Wolf | |
68 | d3f24367 | Kevin Wolf | QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list, |
69 | d3f24367 | Kevin Wolf | const char *name); |
70 | d3f24367 | Kevin Wolf | int set_option_parameter(QEMUOptionParameter *list, const char *name, |
71 | d3f24367 | Kevin Wolf | const char *value); |
72 | d3f24367 | Kevin Wolf | int set_option_parameter_int(QEMUOptionParameter *list, const char *name, |
73 | d3f24367 | Kevin Wolf | uint64_t value); |
74 | b50cbabc | MORITA Kazutaka | QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest, |
75 | b50cbabc | MORITA Kazutaka | QEMUOptionParameter *list); |
76 | d3f24367 | Kevin Wolf | QEMUOptionParameter *parse_option_parameters(const char *param, |
77 | d3f24367 | Kevin Wolf | QEMUOptionParameter *list, QEMUOptionParameter *dest); |
78 | d3f24367 | Kevin Wolf | void free_option_parameters(QEMUOptionParameter *list);
|
79 | d3f24367 | Kevin Wolf | void print_option_parameters(QEMUOptionParameter *list);
|
80 | db08adf5 | Kevin Wolf | void print_option_help(QEMUOptionParameter *list);
|
81 | d3f24367 | Kevin Wolf | |
82 | e27c88fe | Gerd Hoffmann | /* ------------------------------------------------------------------ */
|
83 | e27c88fe | Gerd Hoffmann | |
84 | e27c88fe | Gerd Hoffmann | typedef struct QemuOpt QemuOpt; |
85 | e27c88fe | Gerd Hoffmann | typedef struct QemuOpts QemuOpts; |
86 | e27c88fe | Gerd Hoffmann | typedef struct QemuOptsList QemuOptsList; |
87 | e27c88fe | Gerd Hoffmann | |
88 | e27c88fe | Gerd Hoffmann | enum QemuOptType {
|
89 | e27c88fe | Gerd Hoffmann | QEMU_OPT_STRING = 0, /* no parsing (use string as-is) */ |
90 | e27c88fe | Gerd Hoffmann | QEMU_OPT_BOOL, /* on/off */
|
91 | e27c88fe | Gerd Hoffmann | QEMU_OPT_NUMBER, /* simple number */
|
92 | e27c88fe | Gerd Hoffmann | QEMU_OPT_SIZE, /* size, accepts (K)ilo, (M)ega, (G)iga, (T)era postfix */
|
93 | e27c88fe | Gerd Hoffmann | }; |
94 | e27c88fe | Gerd Hoffmann | |
95 | e27c88fe | Gerd Hoffmann | typedef struct QemuOptDesc { |
96 | e27c88fe | Gerd Hoffmann | const char *name; |
97 | e27c88fe | Gerd Hoffmann | enum QemuOptType type;
|
98 | e27c88fe | Gerd Hoffmann | const char *help; |
99 | e27c88fe | Gerd Hoffmann | } QemuOptDesc; |
100 | e27c88fe | Gerd Hoffmann | |
101 | e27c88fe | Gerd Hoffmann | struct QemuOptsList {
|
102 | e27c88fe | Gerd Hoffmann | const char *name; |
103 | 8212c64f | Markus Armbruster | const char *implied_opt_name; |
104 | da93318a | Peter Maydell | bool merge_lists; /* Merge multiple uses of option into a single list? */ |
105 | 72cf2d4f | Blue Swirl | QTAILQ_HEAD(, QemuOpts) head; |
106 | e27c88fe | Gerd Hoffmann | QemuOptDesc desc[]; |
107 | e27c88fe | Gerd Hoffmann | }; |
108 | e27c88fe | Gerd Hoffmann | |
109 | e27c88fe | Gerd Hoffmann | const char *qemu_opt_get(QemuOpts *opts, const char *name); |
110 | f02b77c9 | M. Mohan Kumar | bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval); |
111 | e27c88fe | Gerd Hoffmann | uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); |
112 | e27c88fe | Gerd Hoffmann | uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); |
113 | e27c88fe | Gerd Hoffmann | int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); |
114 | 384f2139 | Luiz Capitulino | void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, |
115 | 384f2139 | Luiz Capitulino | Error **errp); |
116 | f02b77c9 | M. Mohan Kumar | int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val); |
117 | 48026075 | Gerd Hoffmann | typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque); |
118 | 48026075 | Gerd Hoffmann | int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, |
119 | 48026075 | Gerd Hoffmann | int abort_on_failure);
|
120 | e27c88fe | Gerd Hoffmann | |
121 | e27c88fe | Gerd Hoffmann | QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id); |
122 | 8be7e7e4 | Luiz Capitulino | QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, |
123 | 8be7e7e4 | Luiz Capitulino | int fail_if_exists, Error **errp);
|
124 | bb67ab02 | Markus Armbruster | void qemu_opts_reset(QemuOptsList *list);
|
125 | 94ac7268 | Markus Armbruster | void qemu_opts_loc_restore(QemuOpts *opts);
|
126 | e27c88fe | Gerd Hoffmann | int qemu_opts_set(QemuOptsList *list, const char *id, |
127 | e27c88fe | Gerd Hoffmann | const char *name, const char *value); |
128 | 48026075 | Gerd Hoffmann | const char *qemu_opts_id(QemuOpts *opts); |
129 | e27c88fe | Gerd Hoffmann | void qemu_opts_del(QemuOpts *opts);
|
130 | 29952866 | Luiz Capitulino | void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp); |
131 | 96729cbd | Gerd Hoffmann | int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname); |
132 | 8212c64f | Markus Armbruster | QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev); |
133 | 4f6dd9af | Jan Kiszka | void qemu_opts_set_defaults(QemuOptsList *list, const char *params, |
134 | 4f6dd9af | Jan Kiszka | int permit_abbrev);
|
135 | 4e89978e | Luiz Capitulino | QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
|
136 | 4e89978e | Luiz Capitulino | Error **errp); |
137 | 01e7f188 | Markus Armbruster | QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict); |
138 | e27c88fe | Gerd Hoffmann | |
139 | e27c88fe | Gerd Hoffmann | typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); |
140 | e27c88fe | Gerd Hoffmann | int qemu_opts_print(QemuOpts *opts, void *dummy); |
141 | e27c88fe | Gerd Hoffmann | int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, |
142 | e27c88fe | Gerd Hoffmann | int abort_on_failure);
|
143 | e27c88fe | Gerd Hoffmann | |
144 | d3f24367 | Kevin Wolf | #endif |