qemu-option.h 5.3 KB

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