2009-05-18 18:42:09 +04:00
|
|
|
/*
|
|
|
|
* Commandline option parsing functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003-2008 Fabrice Bellard
|
|
|
|
* Copyright (c) 2009 Kevin Wolf <kwolf@redhat.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_OPTIONS_H
|
|
|
|
#define QEMU_OPTIONS_H
|
|
|
|
|
2009-09-20 11:51:06 +04:00
|
|
|
#include <stdint.h>
|
2009-09-12 11:36:22 +04:00
|
|
|
#include "qemu-queue.h"
|
2010-02-10 22:15:29 +03:00
|
|
|
#include "qdict.h"
|
2009-07-22 18:43:03 +04:00
|
|
|
|
2009-05-18 18:42:09 +04:00
|
|
|
enum QEMUOptionParType {
|
|
|
|
OPT_FLAG,
|
|
|
|
OPT_NUMBER,
|
|
|
|
OPT_SIZE,
|
|
|
|
OPT_STRING,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct QEMUOptionParameter {
|
|
|
|
const char *name;
|
|
|
|
enum QEMUOptionParType type;
|
|
|
|
union {
|
|
|
|
uint64_t n;
|
|
|
|
char* s;
|
|
|
|
} value;
|
2009-06-04 17:39:38 +04:00
|
|
|
const char *help;
|
2009-05-18 18:42:09 +04:00
|
|
|
} QEMUOptionParameter;
|
|
|
|
|
|
|
|
|
|
|
|
const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);
|
|
|
|
const char *get_opt_value(char *buf, int buf_size, const char *p);
|
2009-07-22 18:43:00 +04:00
|
|
|
int get_next_param_value(char *buf, int buf_size,
|
|
|
|
const char *tag, const char **pstr);
|
|
|
|
int get_param_value(char *buf, int buf_size,
|
|
|
|
const char *tag, const char *str);
|
|
|
|
int check_params(char *buf, int buf_size,
|
|
|
|
const char * const *params, const char *str);
|
2009-05-18 18:42:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following functions take a parameter list as input. This is a pointer to
|
|
|
|
* the first element of a QEMUOptionParameter array which is terminated by an
|
|
|
|
* entry with entry->name == NULL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
QEMUOptionParameter *get_option_parameter(QEMUOptionParameter *list,
|
|
|
|
const char *name);
|
|
|
|
int set_option_parameter(QEMUOptionParameter *list, const char *name,
|
|
|
|
const char *value);
|
|
|
|
int set_option_parameter_int(QEMUOptionParameter *list, const char *name,
|
|
|
|
uint64_t value);
|
2010-05-26 06:35:36 +04:00
|
|
|
QEMUOptionParameter *append_option_parameters(QEMUOptionParameter *dest,
|
|
|
|
QEMUOptionParameter *list);
|
2009-05-18 18:42:09 +04:00
|
|
|
QEMUOptionParameter *parse_option_parameters(const char *param,
|
|
|
|
QEMUOptionParameter *list, QEMUOptionParameter *dest);
|
|
|
|
void free_option_parameters(QEMUOptionParameter *list);
|
|
|
|
void print_option_parameters(QEMUOptionParameter *list);
|
2009-06-04 17:39:38 +04:00
|
|
|
void print_option_help(QEMUOptionParameter *list);
|
2009-05-18 18:42:09 +04:00
|
|
|
|
2009-07-22 18:43:03 +04:00
|
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
typedef struct QemuOpt QemuOpt;
|
|
|
|
typedef struct QemuOpts QemuOpts;
|
|
|
|
typedef struct QemuOptsList QemuOptsList;
|
|
|
|
|
|
|
|
enum QemuOptType {
|
|
|
|
QEMU_OPT_STRING = 0, /* no parsing (use string as-is) */
|
|
|
|
QEMU_OPT_BOOL, /* on/off */
|
|
|
|
QEMU_OPT_NUMBER, /* simple number */
|
|
|
|
QEMU_OPT_SIZE, /* size, accepts (K)ilo, (M)ega, (G)iga, (T)era postfix */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct QemuOptDesc {
|
|
|
|
const char *name;
|
|
|
|
enum QemuOptType type;
|
|
|
|
const char *help;
|
|
|
|
} QemuOptDesc;
|
|
|
|
|
|
|
|
struct QemuOptsList {
|
|
|
|
const char *name;
|
2010-02-10 21:52:18 +03:00
|
|
|
const char *implied_opt_name;
|
2009-09-12 11:36:22 +04:00
|
|
|
QTAILQ_HEAD(, QemuOpts) head;
|
2009-07-22 18:43:03 +04:00
|
|
|
QemuOptDesc desc[];
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *qemu_opt_get(QemuOpts *opts, const char *name);
|
2011-10-25 10:40:39 +04:00
|
|
|
bool qemu_opt_get_bool(QemuOpts *opts, const char *name, bool defval);
|
2009-07-22 18:43:03 +04:00
|
|
|
uint64_t qemu_opt_get_number(QemuOpts *opts, const char *name, uint64_t defval);
|
|
|
|
uint64_t qemu_opt_get_size(QemuOpts *opts, const char *name, uint64_t defval);
|
|
|
|
int qemu_opt_set(QemuOpts *opts, const char *name, const char *value);
|
2011-10-25 10:40:39 +04:00
|
|
|
int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val);
|
2009-07-31 14:25:32 +04:00
|
|
|
typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque);
|
|
|
|
int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque,
|
|
|
|
int abort_on_failure);
|
2009-07-22 18:43:03 +04:00
|
|
|
|
|
|
|
QemuOpts *qemu_opts_find(QemuOptsList *list, const char *id);
|
|
|
|
QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists);
|
2010-06-01 12:47:34 +04:00
|
|
|
void qemu_opts_reset(QemuOptsList *list);
|
2010-05-27 23:06:04 +04:00
|
|
|
void qemu_opts_loc_restore(QemuOpts *opts);
|
2009-07-22 18:43:03 +04:00
|
|
|
int qemu_opts_set(QemuOptsList *list, const char *id,
|
|
|
|
const char *name, const char *value);
|
2009-07-31 14:25:32 +04:00
|
|
|
const char *qemu_opts_id(QemuOpts *opts);
|
2009-07-22 18:43:03 +04:00
|
|
|
void qemu_opts_del(QemuOpts *opts);
|
2010-02-21 19:01:30 +03:00
|
|
|
int qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc);
|
2009-09-10 12:58:33 +04:00
|
|
|
int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname);
|
2010-02-10 21:52:18 +03:00
|
|
|
QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev);
|
2012-01-27 22:54:54 +04:00
|
|
|
void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
|
|
|
|
int permit_abbrev);
|
2010-02-10 22:15:29 +03:00
|
|
|
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict);
|
|
|
|
QDict *qemu_opts_to_qdict(QemuOpts *opts, QDict *qdict);
|
2009-07-22 18:43:03 +04:00
|
|
|
|
|
|
|
typedef int (*qemu_opts_loopfunc)(QemuOpts *opts, void *opaque);
|
|
|
|
int qemu_opts_print(QemuOpts *opts, void *dummy);
|
|
|
|
int qemu_opts_foreach(QemuOptsList *list, qemu_opts_loopfunc func, void *opaque,
|
|
|
|
int abort_on_failure);
|
|
|
|
|
2009-05-18 18:42:09 +04:00
|
|
|
#endif
|