Lines Matching refs:node
42 * xbc_parse() parses the text to build a simple tree. Each tree node is
43 * simply a key word or a value. A key node may have a next key node or/and
44 * a child node (both key and value). A value node may have a next value
45 * node (for array).
111 * xbc_root_node() - Get the root node of extended boot config
113 * Return the address of root node of extended boot config. If the
125 * xbc_node_index() - Get the index of XBC node
126 * @node: A target node of getting index.
128 * Return the index number of @node in XBC node list.
130 int __init xbc_node_index(struct xbc_node *node)
132 return node - &xbc_nodes[0];
136 * xbc_node_get_parent() - Get the parent XBC node
137 * @node: An XBC node.
139 * Return the parent node of @node. If the node is top node of the tree,
142 struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node)
144 return node->parent == XBC_NODE_MAX ? NULL : &xbc_nodes[node->parent];
148 * xbc_node_get_child() - Get the child XBC node
149 * @node: An XBC node.
151 * Return the first child node of @node. If the node has no child, return
154 struct xbc_node * __init xbc_node_get_child(struct xbc_node *node)
156 return node->child ? &xbc_nodes[node->child] : NULL;
160 * xbc_node_get_next() - Get the next sibling XBC node
161 * @node: An XBC node.
163 * Return the NEXT sibling node of @node. If the node has no next sibling,
164 * return NULL. Note that even if this returns NULL, it doesn't mean @node
165 * has no siblings. (You also has to check whether the parent's child node
166 * is @node or not.)
168 struct xbc_node * __init xbc_node_get_next(struct xbc_node *node)
170 return node->next ? &xbc_nodes[node->next] : NULL;
174 * xbc_node_get_data() - Get the data of XBC node
175 * @node: An XBC node.
177 * Return the data (which is always a null terminated string) of @node.
178 * If the node has invalid data, warn and return NULL.
180 const char * __init xbc_node_get_data(struct xbc_node *node)
182 int offset = node->data & ~XBC_VALUE;
191 xbc_node_match_prefix(struct xbc_node *node, const char **prefix)
193 const char *p = xbc_node_get_data(node);
210 * xbc_node_find_subkey() - Find a subkey node which matches given key
211 * @parent: An XBC node.
214 * Search a key node under @parent which matches @key. The @key can contain
216 * node from whole tree. Return NULL if no node is matched.
221 struct xbc_node *node;
224 node = xbc_node_get_subkey(parent);
226 node = xbc_root_node();
228 while (node && xbc_node_is_key(node)) {
229 if (!xbc_node_match_prefix(node, &key))
230 node = xbc_node_get_next(node);
232 node = xbc_node_get_subkey(node);
237 return node;
241 * xbc_node_find_value() - Find a value node which matches given key
242 * @parent: An XBC node.
244 * @vnode: A container pointer of found XBC node.
246 * Search a value node under @parent whose (parent) key node matches @key,
249 * this searches the node from whole tree. Return the value string if a
250 * matched key found, return NULL if no node is matched.
259 struct xbc_node *node = xbc_node_find_subkey(parent, key);
261 if (!node || !xbc_node_is_key(node))
264 node = xbc_node_get_child(node);
265 if (node && !xbc_node_is_value(node))
269 *vnode = node;
271 return node ? xbc_node_get_data(node) : "";
275 * xbc_node_compose_key_after() - Compose partial key string of the XBC node
276 * @root: Root XBC node
277 * @node: Target XBC node.
281 * Compose the partial key of the @node into @buf, which is starting right
283 * key words of @node.
285 * if @node is NULL or @root is not the ancestor of @node or @root is @node,
291 struct xbc_node *node,
297 if (!node || node == root)
300 if (xbc_node_is_value(node))
301 node = xbc_node_get_parent(node);
303 while (node && node != root) {
304 keys[depth++] = xbc_node_index(node);
307 node = xbc_node_get_parent(node);
309 if (!node && root)
313 node = xbc_nodes + keys[depth];
314 ret = snprintf(buf, size, "%s%s", xbc_node_get_data(node),
331 * xbc_node_find_next_leaf() - Find the next leaf node under given node
332 * @root: An XBC root node
333 * @node: An XBC node which starts from.
335 * Search the next leaf node (which means the terminal key node) of @node
336 * under @root node (including @root node itself).
337 * Return the next node or NULL if next leaf node is not found.
340 struct xbc_node *node)
347 if (!node) { /* First try */
348 node = root;
349 if (!node)
350 node = xbc_nodes;
352 /* Leaf node may have a subkey */
353 next = xbc_node_get_subkey(node);
355 node = next;
359 if (node == root) /* @root was a leaf, no child node. */
362 while (!node->next) {
363 node = xbc_node_get_parent(node);
364 if (node == root)
366 /* User passed a node which is not uder parent */
367 if (WARN_ON(!node))
370 node = xbc_node_get_next(node);
374 while (node && !xbc_node_is_leaf(node))
375 node = xbc_node_get_child(node);
377 return node;
382 * @root: An XBC root node
383 * @leaf: A container pointer of XBC node which starts from.
385 * Search the next leaf node (which means the terminal key node) of *@leaf
386 * under @root node. Returns the value and update *@leaf if next leaf node
387 * is found, or NULL if no next leaf node is found.
409 static int __init xbc_init_node(struct xbc_node *node, char *data, uint32_t flag)
416 node->data = (uint16_t)offset | flag;
417 node->child = 0;
418 node->next = 0;
425 struct xbc_node *node;
430 node = &xbc_nodes[xbc_node_num++];
431 if (xbc_init_node(node, data, flag) < 0)
434 return node;
437 static inline __init struct xbc_node *xbc_last_sibling(struct xbc_node *node)
439 while (node->next)
440 node = xbc_node_get_next(node);
442 return node;
445 static inline __init struct xbc_node *xbc_last_child(struct xbc_node *node)
447 while (node->child)
448 node = xbc_node_get_child(node);
450 return node;
455 struct xbc_node *sib, *node = xbc_add_node(data, flag);
457 if (node) {
460 node->parent = XBC_NODE_MAX;
462 sib->next = xbc_node_index(node);
464 node->parent = xbc_node_index(last_parent);
466 node->next = last_parent->child;
467 last_parent->child = xbc_node_index(node);
471 sib->next = xbc_node_index(node);
477 return node;
492 struct xbc_node *node = xbc_add_sibling(data, flag);
494 if (node)
495 last_parent = node;
497 return node;
557 * Return delimiter or error, no node added. As same as lib/cmdline.c,
611 struct xbc_node *node;
623 node = xbc_add_child(*__v, XBC_VALUE);
624 if (!node)
628 node->child = 0;
634 struct xbc_node *find_match_node(struct xbc_node *node, char *k)
636 while (node) {
637 if (!strcmp(xbc_node_get_data(node), k))
639 node = xbc_node_get_next(node);
641 return node;
646 struct xbc_node *node, *child;
655 node = find_match_node(xbc_nodes, k);
658 /* Since the value node is the first child, skip it. */
661 node = find_match_node(child, k);
664 if (node)
665 last_parent = node;
668 node = xbc_add_child(k, XBC_KEY);
669 if (!node)
721 /* The value node should always be the first child */