@@ -47,12 +47,11 @@ static bool path_append(const char **nodes, const char *field)
return true;
}
-static void *find_node(parsertype p, void *root, const char *field,
- struct swupdate_cfg *swcfg)
+static void *find_node_and_path(parsertype p, void *root, const char *field,
+ struct swupdate_cfg *swcfg, const char **nodes)
{
-
struct hw_type *hardware;
- const char **nodes;
+ void *node = NULL;
int i;
if (!field)
@@ -60,8 +59,6 @@ static void *find_node(parsertype p, void *root, const char *field,
hardware = &swcfg->hw;
- nodes = (const char **)calloc(MAX_PARSED_NODES, sizeof(*nodes));
-
for (i = 0; i < 4; i++) {
nodes[0] = NULL;
switch(i) {
@@ -113,21 +110,36 @@ static void *find_node(parsertype p, void *root, const char *field,
* to search for element
*/
if (find_root(p, root, nodes)) {
- void *node = NULL;
if (!path_append(nodes, field))
return NULL;
node = find_root(p, root, nodes);
if (node) {
- free(nodes);
return node;
}
}
}
+ return NULL;
+}
+
+static void *find_node(parsertype p, void *root, const char *field,
+ struct swupdate_cfg *swcfg)
+{
+ const char **nodes;
+ void *node = NULL;
+
+ if (!field)
+ return NULL;
+
+ nodes = (const char **)calloc(MAX_PARSED_NODES, sizeof(*nodes));
+ if (!nodes)
+ return NULL;
+
+ node = find_node_and_path(p, root, field, swcfg, nodes);
free(nodes);
- return NULL;
+ return node;
}
static bool get_common_fields(parsertype p, void *cfg, struct swupdate_cfg *swcfg)
The find_node() function searches for a path inside sw-description, looking at different root start point (selection, board, or initial root.) The caller gets a pointer to the element if found. In case of links, the caller requires the whole path to the element to find a relative path from the found element where the link is set. Split the function in two parts, the core returns also the full path (as ** char array) where the element is found. Signed-off-by: Stefano Babic <sbabic@denx.de> --- parser/parser.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)