diff options
author | Himbeer <himbeer@disroot.org> | 2024-05-11 12:02:21 +0200 |
---|---|---|
committer | Himbeer <himbeer@disroot.org> | 2024-05-11 12:02:21 +0200 |
commit | d3e2b8bb0d14fff92b7337055a8829195cd9b745 (patch) | |
tree | 4b062398e2adfc0dd3c4bd384af046c40ffeb2b5 | |
parent | e2c31f6a194b7f71d8a68e5af193c4008130af51 (diff) |
fdt: Add absolute node path lookup function
-rw-r--r-- | src/fdt.zig | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/fdt.zig b/src/fdt.zig index 67efb53..2139807 100644 --- a/src/fdt.zig +++ b/src/fdt.zig @@ -186,6 +186,22 @@ pub fn findNodeExact(nodes: []const Node, name: []const u8) ?struct { usize, Nod return null; } +pub fn findPath(dt: *const Tree, path: []const u8) ?Node { + if (dt.nodes.items.len < 1) return null; + + path = std.mem.trim(u8, path, "/"); + + var node = dt.nodes.items[0]; + + for (std.mem.tokenizeScalar(u8, path, '/')) |segment| { + if (findNodeExact(node.subnodes.items, segment)) |result| { + node = result; + } else return null; + } + + return node; +} + fn nodeNameFilter(node: Node, name: []const u8) bool { var it = std.mem.splitScalar(u8, node.name, '@'); const trueName = it.first(); |