Statistics
| Branch: | Revision:

root / qemu-option.h @ 1a1ea6f0

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