Statistics
| Branch: | Revision:

root / qemu-option.h @ 45724d6d

History | View | Annotate | Download (6.1 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 c8057f95 Peter Maydell
/**
111 c8057f95 Peter Maydell
 * qemu_opt_has_help_opt:
112 c8057f95 Peter Maydell
 * @opts: options to search for a help request
113 c8057f95 Peter Maydell
 *
114 c8057f95 Peter Maydell
 * Check whether the options specified by @opts include one of the
115 c8057f95 Peter Maydell
 * standard strings which indicate that the user is asking for a
116 c8057f95 Peter Maydell
 * list of the valid values for a command line option (as defined
117 c8057f95 Peter Maydell
 * by is_help_option()).
118 c8057f95 Peter Maydell
 *
119 c8057f95 Peter Maydell
 * Returns: true if @opts includes 'help' or equivalent.
120 c8057f95 Peter Maydell
 */
121 c8057f95 Peter Maydell
bool qemu_opt_has_help_opt(QemuOpts *opts);
122 f02b77c9 M. Mohan Kumar
bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
123 e27c88fe Gerd Hoffmann
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);
124 e27c88fe Gerd Hoffmann
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
125 e27c88fe Gerd Hoffmann
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
126 384f2139 Luiz Capitulino
void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value,
127 384f2139 Luiz Capitulino
                      Error **errp);
128 f02b77c9 M. Mohan Kumar
int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val);
129 48026075 Gerd Hoffmann
typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque);
130 48026075 Gerd Hoffmann
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
131 48026075 Gerd Hoffmann
                     int abort_on_failure);
132 e27c88fe Gerd Hoffmann
133 e27c88fe Gerd Hoffmann
QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
134 8be7e7e4 Luiz Capitulino
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
135 8be7e7e4 Luiz Capitulino
                           int fail_if_exists, Error **errp);
136 bb67ab02 Markus Armbruster
void qemu_opts_reset(QemuOptsList *list);
137 94ac7268 Markus Armbruster
void qemu_opts_loc_restore(QemuOpts *opts);
138 e27c88fe Gerd Hoffmann
int qemu_opts_set(QemuOptsList *list, const char *id,
139 e27c88fe Gerd Hoffmann
                  const char *name, const char *value);
140 48026075 Gerd Hoffmann
const char *qemu_opts_id(QemuOpts *opts);
141 e27c88fe Gerd Hoffmann
void qemu_opts_del(QemuOpts *opts);
142 29952866 Luiz Capitulino
void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp);
143 96729cbd Gerd Hoffmann
int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
144 8212c64f Markus Armbruster
QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev);
145 4f6dd9af Jan Kiszka
void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
146 4f6dd9af Jan Kiszka
                            int permit_abbrev);
147 4e89978e Luiz Capitulino
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
148 4e89978e Luiz Capitulino
                               Error **errp);
149 01e7f188 Markus Armbruster
QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
150 e27c88fe Gerd Hoffmann
151 e27c88fe Gerd Hoffmann
typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
152 e27c88fe Gerd Hoffmann
int qemu_opts_print(QemuOpts *opts, void *dummy);
153 e27c88fe Gerd Hoffmann
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
154 e27c88fe Gerd Hoffmann
                      int abort_on_failure);
155 e27c88fe Gerd Hoffmann
156 d3f24367 Kevin Wolf
#endif