Lines Matching +full:key +full:- +full:value
2 * Parsing KEY=VALUE,... strings
10 * See the COPYING file in the top-level directory.
14 * KEY=VALUE,... syntax:
16 * key-vals = [ key-val { ',' key-val } [ ',' ] ]
17 * key-val = key '=' val | help
18 * key = key-fragment { '.' key-fragment }
19 * key-fragment = qapi-name | index
20 * qapi-name = '__' / [a-z0-9.-]+ / '_' / [A-Za-z][A-Za-z0-9_-]* /
21 * index = / [0-9]+ /
27 * key-vals specifies a JSON object, i.e. a tree whose root is an
31 * Each key-val = key-fragment '.' ... '=' val specifies a path from
32 * root to a leaf (left of '='), and the leaf's value (right of
36 * L '.' key-fragment is a child of the node denoted by path L
37 * key-fragment is a child of the tree root
38 * If key-fragment is numeric, the parent is an array and the child
39 * is its key-fragment-th member, counting from zero.
41 * key-fragment.
44 * constraints must be satisfiable. Counter-example: a.b=1,a=2 is
52 * If multiple key-val denote the same leaf, the last one determines
53 * the value.
55 * Key-fragments must be valid QAPI names or consist only of decimal
58 * The length of any key-fragment must be between 1 and 127.
60 * If any key-val is help, the object is to be treated as a help
63 * Design flaw: there is no way to denote an empty array or non-root
64 * object. While interpreting "key absent" as empty seems natural
65 * (removing a key-val from the input string removes the member when
67 * "key absent" already means "optional object/array absent", which
80 * Alternative syntax for use with an implied key:
82 * key-vals = [ key-val-1st { ',' key-val } [ ',' ] ]
83 * key-val-1st = val-no-key | key-val
84 * val-no-key = / [^=,]+ / - help
86 * where val-no-key is syntactic sugar for implied-key=val-no-key.
88 * Note that you can't use the sugared form when the value contains
102 * Convert @key to a list index.
103 * Convert all leading decimal digits to a (non-negative) number,
105 * If @end is non-null, assign a pointer to the first character after
109 * On failure, return a negative value.
113 static int key_to_index(const char *key, const char **end) in key_to_index() argument
118 if (*key < '0' || *key > '9') { in key_to_index()
119 return -EINVAL; in key_to_index()
121 ret = qemu_strtoul(key, end, 10, &index); in key_to_index()
123 return ret == -ERANGE ? INT_MAX : ret; in key_to_index()
130 * If @value is null, it needs to map to a QDict, else to this
132 * If @cur doesn't have @key_in_cur, put an empty QDict or @value,
136 * QString, replace it by @value.
139 * In any case, take over the reference to @value, i.e. if the caller
141 * Use @key up to @key_cursor to identify the key in error messages.
142 * On success, return the mapped value.
146 const char *key_in_cur, QString *value, in keyval_parse_put() argument
147 const char *key, const char *key_cursor, in keyval_parse_put() argument
154 if (qobject_type(old) != (value ? QTYPE_QSTRING : QTYPE_QDICT)) { in keyval_parse_put()
156 (int)(key_cursor - key), key); in keyval_parse_put()
157 qobject_unref(value); in keyval_parse_put()
160 if (!value) { in keyval_parse_put()
163 new = QOBJECT(value); /* replacement */ in keyval_parse_put()
165 new = value ? QOBJECT(value) : QOBJECT(qdict_new()); in keyval_parse_put()
174 * If we're looking at KEY=VALUE, store result in @qdict.
175 * The first fragment of KEY applies to @qdict. Subsequent fragments
188 const char *key, *key_end, *val_end, *s, *end; in keyval_parse_one() local
196 key = params; in keyval_parse_one()
199 if (len && key[len] != '=') { in keyval_parse_one()
200 if (starts_with_help_option(key) == len) { in keyval_parse_one()
202 s = key + len; in keyval_parse_one()
209 /* Desugar implied key */ in keyval_parse_one()
210 key = implied_key; in keyval_parse_one()
215 key_end = key + len; in keyval_parse_one()
218 * Loop over key fragments: @s points to current fragment, it in keyval_parse_one()
222 s = key; in keyval_parse_one()
224 /* Want a key index (unless it's first) or a QAPI name */ in keyval_parse_one()
225 if (s != key && key_to_index(s, &end) >= 0) { in keyval_parse_one()
226 len = end - s; in keyval_parse_one()
233 assert(key != implied_key); in keyval_parse_one()
235 (int)(key_end - key), key); in keyval_parse_one()
239 assert(key != implied_key); in keyval_parse_one()
241 s != key || s + len != key_end ? " fragment" : "", in keyval_parse_one()
246 if (s != key) { in keyval_parse_one()
248 key, s - 1, errp); in keyval_parse_one()
266 if (key == implied_key) { in keyval_parse_one()
268 val = g_string_new_len(params, val_end - params); in keyval_parse_one()
276 (int)(s - key), key); in keyval_parse_one()
296 key, key_end, errp)) { in keyval_parse_one()
302 static char *reassemble_key(GSList *key) in reassemble_key() argument
307 for (p = key; p; p = p->next) { in reassemble_key()
309 g_string_prepend(s, (char *)p->data); in reassemble_key()
324 size_t save_len = str->len; in keyval_do_merge()
329 old_value = qdict_get(dest, ent->key); in keyval_do_merge()
331 if (qobject_type(old_value) != qobject_type(ent->value)) { in keyval_do_merge()
333 str->str, ent->key); in keyval_do_merge()
335 } else if (qobject_type(ent->value) == QTYPE_QDICT) { in keyval_do_merge()
336 /* Merge sub-dictionaries. */ in keyval_do_merge()
337 g_string_append(str, ent->key); in keyval_do_merge()
340 qobject_to(QDict, ent->value), in keyval_do_merge()
344 } else if (qobject_type(ent->value) == QTYPE_QLIST) { in keyval_do_merge()
347 QList *new = qobject_to(QList, ent->value); in keyval_do_merge()
350 qobject_ref(item->value); in keyval_do_merge()
351 qlist_append_obj(old, item->value); in keyval_do_merge()
355 assert(qobject_type(ent->value) == QTYPE_QSTRING); in keyval_do_merge()
359 qobject_ref(ent->value); in keyval_do_merge()
360 qdict_put_obj(dest, ent->key, ent->value); in keyval_do_merge()
370 * - lists are concatenated
372 * - dictionaries are merged recursively
374 * - for scalar values, @merged wins
379 * .merge_lists = true case, or to implement -set for options backed by QDicts.
398 * @key_of_cur is the list of key fragments leading up to @cur.
409 char *key; in keyval_listify() local
424 if (key_to_index(ent->key, NULL) >= 0) { in keyval_listify()
430 qdict = qobject_to(QDict, ent->value); in keyval_listify()
435 key_node.data = ent->key; in keyval_listify()
440 if (val != ent->value) { in keyval_listify()
441 qdict_put_obj(cur, ent->key, val); in keyval_listify()
446 key = reassemble_key(key_of_cur); in keyval_listify()
447 error_setg(errp, "Parameters '%s*' used inconsistently", key); in keyval_listify()
448 g_free(key); in keyval_listify()
458 max_index = -1; in keyval_listify()
460 index = key_to_index(ent->key, NULL); in keyval_listify()
470 if ((size_t)index >= nelt - 1) { in keyval_listify()
474 elt[index] = ent->value; in keyval_listify()
484 assert(!elt[nelt-1]); /* need the sentinel to be null */ in keyval_listify()
487 key = reassemble_key(key_of_cur); in keyval_listify()
488 error_setg(errp, "Parameter '%s%d' missing", key, i); in keyval_listify()
489 g_free(key); in keyval_listify()
503 * Parse @params in QEMU's traditional KEY=VALUE,... syntax.
505 * If @implied_key, the first KEY= can be omitted. @implied_key is
506 * implied then, and VALUE can't be empty or contain ',' or '='.
508 * A parameter "help" or "?" without a value isn't added to the
553 * Parse @params in QEMU's traditional KEY=VALUE,... syntax.
555 * If @implied_key, the first KEY= can be omitted. @implied_key is
556 * implied then, and VALUE can't be empty or contain ',' or '='.
558 * A parameter "help" or "?" without a value isn't added to the