Lines Matching refs:node

40  * xbc_parse() parses the text to build a simple tree. Each tree node is
41 * simply a key word or a value. A key node may have a next key node or/and
42 * a child node (both key and value). A value node may have a next value
43 * node (for array).
112 * xbc_root_node() - Get the root node of extended boot config
114 * Return the address of root node of extended boot config. If the
126 * xbc_node_index() - Get the index of XBC node
127 * @node: A target node of getting index.
129 * Return the index number of @node in XBC node list.
131 int __init xbc_node_index(struct xbc_node *node)
133 return node - &xbc_nodes[0];
137 * xbc_node_get_parent() - Get the parent XBC node
138 * @node: An XBC node.
140 * Return the parent node of @node. If the node is top node of the tree,
143 struct xbc_node * __init xbc_node_get_parent(struct xbc_node *node)
145 return node->parent == XBC_NODE_MAX ? NULL : &xbc_nodes[node->parent];
149 * xbc_node_get_child() - Get the child XBC node
150 * @node: An XBC node.
152 * Return the first child node of @node. If the node has no child, return
155 struct xbc_node * __init xbc_node_get_child(struct xbc_node *node)
157 return node->child ? &xbc_nodes[node->child] : NULL;
161 * xbc_node_get_next() - Get the next sibling XBC node
162 * @node: An XBC node.
164 * Return the NEXT sibling node of @node. If the node has no next sibling,
165 * return NULL. Note that even if this returns NULL, it doesn't mean @node
166 * has no siblings. (You also has to check whether the parent's child node
167 * is @node or not.)
169 struct xbc_node * __init xbc_node_get_next(struct xbc_node *node)
171 return node->next ? &xbc_nodes[node->next] : NULL;
175 * xbc_node_get_data() - Get the data of XBC node
176 * @node: An XBC node.
178 * Return the data (which is always a null terminated string) of @node.
179 * If the node has invalid data, warn and return NULL.
181 const char * __init xbc_node_get_data(struct xbc_node *node)
183 int offset = node->data & ~XBC_VALUE;
192 xbc_node_match_prefix(struct xbc_node *node, const char **prefix)
194 const char *p = xbc_node_get_data(node);
211 * xbc_node_find_subkey() - Find a subkey node which matches given key
212 * @parent: An XBC node.
215 * Search a key node under @parent which matches @key. The @key can contain
217 * node from whole tree. Return NULL if no node is matched.
222 struct xbc_node *node;
225 node = xbc_node_get_subkey(parent);
227 node = xbc_root_node();
229 while (node && xbc_node_is_key(node)) {
230 if (!xbc_node_match_prefix(node, &key))
231 node = xbc_node_get_next(node);
233 node = xbc_node_get_subkey(node);
238 return node;
242 * xbc_node_find_value() - Find a value node which matches given key
243 * @parent: An XBC node.
245 * @vnode: A container pointer of found XBC node.
247 * Search a value node under @parent whose (parent) key node matches @key,
250 * this searches the node from whole tree. Return the value string if a
251 * matched key found, return NULL if no node is matched.
260 struct xbc_node *node = xbc_node_find_subkey(parent, key);
262 if (!node || !xbc_node_is_key(node))
265 node = xbc_node_get_child(node);
266 if (node && !xbc_node_is_value(node))
270 *vnode = node;
272 return node ? xbc_node_get_data(node) : "";
276 * xbc_node_compose_key_after() - Compose partial key string of the XBC node
277 * @root: Root XBC node
278 * @node: Target XBC node.
282 * Compose the partial key of the @node into @buf, which is starting right
284 * key words of @node.
286 * if @node is NULL or @root is not the ancestor of @node or @root is @node,
292 struct xbc_node *node,
298 if (!node || node == root)
301 if (xbc_node_is_value(node))
302 node = xbc_node_get_parent(node);
304 while (node && node != root) {
305 keys[depth++] = xbc_node_index(node);
308 node = xbc_node_get_parent(node);
310 if (!node && root)
314 node = xbc_nodes + keys[depth];
315 ret = snprintf(buf, size, "%s%s", xbc_node_get_data(node),
332 * xbc_node_find_next_leaf() - Find the next leaf node under given node
333 * @root: An XBC root node
334 * @node: An XBC node which starts from.
336 * Search the next leaf node (which means the terminal key node) of @node
337 * under @root node (including @root node itself).
338 * Return the next node or NULL if next leaf node is not found.
341 struct xbc_node *node)
348 if (!node) { /* First try */
349 node = root;
350 if (!node)
351 node = xbc_nodes;
353 /* Leaf node may have a subkey */
354 next = xbc_node_get_subkey(node);
356 node = next;
360 if (node == root) /* @root was a leaf, no child node. */
363 while (!node->next) {
364 node = xbc_node_get_parent(node);
365 if (node == root)
367 /* User passed a node which is not uder parent */
368 if (WARN_ON(!node))
371 node = xbc_node_get_next(node);
375 while (node && !xbc_node_is_leaf(node))
376 node = xbc_node_get_child(node);
378 return node;
383 * @root: An XBC root node
384 * @leaf: A container pointer of XBC node which starts from.
386 * Search the next leaf node (which means the terminal key node) of *@leaf
387 * under @root node. Returns the value and update *@leaf if next leaf node
388 * is found, or NULL if no next leaf node is found.
410 static int __init xbc_init_node(struct xbc_node *node, char *data, uint32_t flag)
417 node->data = (uint16_t)offset | flag;
418 node->child = 0;
419 node->next = 0;
426 struct xbc_node *node;
431 node = &xbc_nodes[xbc_node_num++];
432 if (xbc_init_node(node, data, flag) < 0)
435 return node;
438 static inline __init struct xbc_node *xbc_last_sibling(struct xbc_node *node)
440 while (node->next)
441 node = xbc_node_get_next(node);
443 return node;
446 static inline __init struct xbc_node *xbc_last_child(struct xbc_node *node)
448 while (node->child)
449 node = xbc_node_get_child(node);
451 return node;
456 struct xbc_node *sib, *node = xbc_add_node(data, flag);
458 if (node) {
461 node->parent = XBC_NODE_MAX;
463 sib->next = xbc_node_index(node);
465 node->parent = xbc_node_index(last_parent);
467 node->next = last_parent->child;
468 last_parent->child = xbc_node_index(node);
472 sib->next = xbc_node_index(node);
478 return node;
493 struct xbc_node *node = xbc_add_sibling(data, flag);
495 if (node)
496 last_parent = node;
498 return node;
558 * Return delimiter or error, no node added. As same as lib/cmdline.c,
608 struct xbc_node *node;
627 node = xbc_add_child(*__v, XBC_VALUE);
628 if (!node)
632 node->child = 0;
638 struct xbc_node *find_match_node(struct xbc_node *node, char *k)
640 while (node) {
641 if (!strcmp(xbc_node_get_data(node), k))
643 node = xbc_node_get_next(node);
645 return node;
650 struct xbc_node *node, *child;
659 node = find_match_node(xbc_nodes, k);
662 /* Since the value node is the first child, skip it. */
665 node = find_match_node(child, k);
668 if (node)
669 last_parent = node;
672 node = xbc_add_child(k, XBC_KEY);
673 if (!node)
733 /* The value node should always be the first child */