Introduce get_next_param_value
In order to parse multiple instances of the same param=value pair, introduce get_next_param_value which can pass back to string parsing position after reading a parameter value. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
e15f4a992c
commit
5db4af8bc8
2
sysemu.h
2
sysemu.h
|
@ -275,6 +275,8 @@ void usb_info(Monitor *mon);
|
||||||
|
|
||||||
int get_param_value(char *buf, int buf_size,
|
int get_param_value(char *buf, int buf_size,
|
||||||
const char *tag, const char *str);
|
const char *tag, const char *str);
|
||||||
|
int get_next_param_value(char *buf, int buf_size,
|
||||||
|
const char *tag, const char **pstr);
|
||||||
int check_params(char *buf, int buf_size,
|
int check_params(char *buf, int buf_size,
|
||||||
const char * const *params, const char *str);
|
const char * const *params, const char *str);
|
||||||
|
|
||||||
|
|
17
vl.c
17
vl.c
|
@ -1812,20 +1812,23 @@ static int socket_init(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int get_param_value(char *buf, int buf_size,
|
int get_next_param_value(char *buf, int buf_size,
|
||||||
const char *tag, const char *str)
|
const char *tag, const char **pstr)
|
||||||
{
|
{
|
||||||
const char *p;
|
const char *p;
|
||||||
char option[128];
|
char option[128];
|
||||||
|
|
||||||
p = str;
|
p = *pstr;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
p = get_opt_name(option, sizeof(option), p, '=');
|
p = get_opt_name(option, sizeof(option), p, '=');
|
||||||
if (*p != '=')
|
if (*p != '=')
|
||||||
break;
|
break;
|
||||||
p++;
|
p++;
|
||||||
if (!strcmp(tag, option)) {
|
if (!strcmp(tag, option)) {
|
||||||
(void)get_opt_value(buf, buf_size, p);
|
*pstr = get_opt_value(buf, buf_size, p);
|
||||||
|
if (**pstr == ',') {
|
||||||
|
(*pstr)++;
|
||||||
|
}
|
||||||
return strlen(buf);
|
return strlen(buf);
|
||||||
} else {
|
} else {
|
||||||
p = get_opt_value(NULL, 0, p);
|
p = get_opt_value(NULL, 0, p);
|
||||||
|
@ -1837,6 +1840,12 @@ int get_param_value(char *buf, int buf_size,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_param_value(char *buf, int buf_size,
|
||||||
|
const char *tag, const char *str)
|
||||||
|
{
|
||||||
|
return get_next_param_value(buf, buf_size, tag, &str);
|
||||||
|
}
|
||||||
|
|
||||||
int check_params(char *buf, int buf_size,
|
int check_params(char *buf, int buf_size,
|
||||||
const char * const *params, const char *str)
|
const char * const *params, const char *str)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue