root / qemu-option.h @ 03587182
History | View | Annotate | Download (4.8 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 | e27c88fe | Gerd Hoffmann | |
32 | d3f24367 | Kevin Wolf | enum QEMUOptionParType {
|
33 | d3f24367 | Kevin Wolf | OPT_FLAG, |
34 | d3f24367 | Kevin Wolf | OPT_NUMBER, |
35 | d3f24367 | Kevin Wolf | OPT_SIZE, |
36 | d3f24367 | Kevin Wolf | OPT_STRING, |
37 | d3f24367 | Kevin Wolf | }; |
38 | d3f24367 | Kevin Wolf | |
39 | d3f24367 | Kevin Wolf | typedef struct QEMUOptionParameter { |
40 | d3f24367 | Kevin Wolf | const char *name; |
41 | d3f24367 | Kevin Wolf | enum QEMUOptionParType type;
|
42 | d3f24367 | Kevin Wolf | union {
|
43 | d3f24367 | Kevin Wolf | uint64_t n; |
44 | d3f24367 | Kevin Wolf | char* s;
|
45 | d3f24367 | Kevin Wolf | } value; |
46 | db08adf5 | Kevin Wolf | const char *help; |
47 | d3f24367 | Kevin Wolf | } QEMUOptionParameter; |
48 | d3f24367 | Kevin Wolf | |
49 | d3f24367 | Kevin Wolf | |
50 | d3f24367 | Kevin Wolf | const char *get_opt_name(char *buf, int buf_size, const char *p, char delim); |
51 | d3f24367 | Kevin Wolf | const char *get_opt_value(char *buf, int buf_size, const char *p); |
52 | 62c5802e | Gerd Hoffmann | int get_next_param_value(char *buf, int buf_size, |
53 | 62c5802e | Gerd Hoffmann | const char *tag, const char **pstr); |
54 | 62c5802e | Gerd Hoffmann | int get_param_value(char *buf, int buf_size, |
55 | 62c5802e | Gerd Hoffmann | const char *tag, const char *str); |
56 | 62c5802e | Gerd Hoffmann | int check_params(char *buf, int buf_size, |
57 | 62c5802e | Gerd Hoffmann | const char * const *params, const char *str); |
58 | d3f24367 | Kevin Wolf | |
59 | d3f24367 | Kevin Wolf | |
60 | d3f24367 | Kevin Wolf | /*
|
61 | d3f24367 | Kevin Wolf | * The following functions take a parameter list as input. This is a pointer to
|
62 | d3f24367 | Kevin Wolf | * the first element of a QEMUOptionParameter array which is terminated by an
|
63 | d3f24367 | Kevin Wolf | * entry with entry->name == NULL.
|
64 | d3f24367 | Kevin Wolf | */
|
65 | d3f24367 | Kevin Wolf | |
66 | d3f24367 | Kevin Wolf | QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list, |
67 | d3f24367 | Kevin Wolf | const char *name); |
68 | d3f24367 | Kevin Wolf | int set_option_parameter(QEMUOptionParameter *list, const char *name, |
69 | d3f24367 | Kevin Wolf | const char *value); |
70 | d3f24367 | Kevin Wolf | int set_option_parameter_int(QEMUOptionParameter *list, const char *name, |
71 | d3f24367 | Kevin Wolf | uint64_t value); |
72 | d3f24367 | Kevin Wolf | QEMUOptionParameter *parse_option_parameters(const char *param, |
73 | d3f24367 | Kevin Wolf | QEMUOptionParameter *list, QEMUOptionParameter *dest); |
74 | d3f24367 | Kevin Wolf | void free_option_parameters(QEMUOptionParameter *list);
|
75 | d3f24367 | Kevin Wolf | void print_option_parameters(QEMUOptionParameter *list);
|
76 | db08adf5 | Kevin Wolf | void print_option_help(QEMUOptionParameter *list);
|
77 | d3f24367 | Kevin Wolf | |
78 | e27c88fe | Gerd Hoffmann | /* ------------------------------------------------------------------ */
|
79 | e27c88fe | Gerd Hoffmann | |
80 | e27c88fe | Gerd Hoffmann | typedef struct QemuOpt QemuOpt; |
81 | e27c88fe | Gerd Hoffmann | typedef struct QemuOpts QemuOpts; |
82 | e27c88fe | Gerd Hoffmann | typedef struct QemuOptsList QemuOptsList; |
83 | e27c88fe | Gerd Hoffmann | |
84 | e27c88fe | Gerd Hoffmann | enum QemuOptType {
|
85 | e27c88fe | Gerd Hoffmann | QEMU_OPT_STRING = 0, /* no parsing (use string as-is) */ |
86 | e27c88fe | Gerd Hoffmann | QEMU_OPT_BOOL, /* on/off */
|
87 | e27c88fe | Gerd Hoffmann | QEMU_OPT_NUMBER, /* simple number */
|
88 | e27c88fe | Gerd Hoffmann | QEMU_OPT_SIZE, /* size, accepts (K)ilo, (M)ega, (G)iga, (T)era postfix */
|
89 | e27c88fe | Gerd Hoffmann | }; |
90 | e27c88fe | Gerd Hoffmann | |
91 | e27c88fe | Gerd Hoffmann | typedef struct QemuOptDesc { |
92 | e27c88fe | Gerd Hoffmann | const char *name; |
93 | e27c88fe | Gerd Hoffmann | enum QemuOptType type;
|
94 | e27c88fe | Gerd Hoffmann | const char *help; |
95 | e27c88fe | Gerd Hoffmann | } QemuOptDesc; |
96 | e27c88fe | Gerd Hoffmann | |
97 | e27c88fe | Gerd Hoffmann | struct QemuOptsList {
|
98 | e27c88fe | Gerd Hoffmann | const char *name; |
99 | 72cf2d4f | Blue Swirl | QTAILQ_HEAD(, QemuOpts) head; |
100 | e27c88fe | Gerd Hoffmann | QemuOptDesc desc[]; |
101 | e27c88fe | Gerd Hoffmann | }; |
102 | e27c88fe | Gerd Hoffmann | |
103 | e27c88fe | Gerd Hoffmann | const char *qemu_opt_get(QemuOpts *opts, const char *name); |
104 | e27c88fe | Gerd Hoffmann | int qemu_opt_get_bool(QemuOpts *opts, const char *name, int defval); |
105 | e27c88fe | Gerd Hoffmann | uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval); |
106 | e27c88fe | Gerd Hoffmann | uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval); |
107 | e27c88fe | Gerd Hoffmann | int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); |
108 | 48026075 | Gerd Hoffmann | typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque); |
109 | 48026075 | Gerd Hoffmann | int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, |
110 | 48026075 | Gerd Hoffmann | int abort_on_failure);
|
111 | e27c88fe | Gerd Hoffmann | |
112 | e27c88fe | Gerd Hoffmann | QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id); |
113 | e27c88fe | Gerd Hoffmann | QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists); |
114 | e27c88fe | Gerd Hoffmann | int qemu_opts_set(QemuOptsList *list, const char *id, |
115 | e27c88fe | Gerd Hoffmann | const char *name, const char *value); |
116 | 48026075 | Gerd Hoffmann | const char *qemu_opts_id(QemuOpts *opts); |
117 | e27c88fe | Gerd Hoffmann | void qemu_opts_del(QemuOpts *opts);
|
118 | 96729cbd | Gerd Hoffmann | int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname); |
119 | e27c88fe | Gerd Hoffmann | QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, const char *firstname); |
120 | e27c88fe | Gerd Hoffmann | |
121 | e27c88fe | Gerd Hoffmann | typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque); |
122 | e27c88fe | Gerd Hoffmann | int qemu_opts_print(QemuOpts *opts, void *dummy); |
123 | e27c88fe | Gerd Hoffmann | int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque, |
124 | e27c88fe | Gerd Hoffmann | int abort_on_failure);
|
125 | e27c88fe | Gerd Hoffmann | |
126 | d3f24367 | Kevin Wolf | #endif |