Rev 1895 | Rev 1899 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1895 | Rev 1896 | ||
|---|---|---|---|
| Line 49... | Line 49... | ||
| 49 | void ofw_tree_init(ofw_tree_node_t *root) |
49 | void ofw_tree_init(ofw_tree_node_t *root) |
| 50 | { |
50 | { |
| 51 | ofw_root = root; |
51 | ofw_root = root; |
| 52 | } |
52 | } |
| 53 | 53 | ||
| - | 54 | /** Get OpenFirmware node property. |
|
| - | 55 | * |
|
| - | 56 | * @param node Node in which to lookup the property. |
|
| - | 57 | * @param name Name of the property. |
|
| - | 58 | * |
|
| - | 59 | * @return Pointer to the property structure or NULL if no such property. |
|
| - | 60 | */ |
|
| - | 61 | ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *node, const char *name) |
|
| - | 62 | { |
|
| - | 63 | int i; |
|
| - | 64 | ||
| - | 65 | for (i = 0; i < node->properties; i++) { |
|
| - | 66 | if (strcmp(node->property[i].name, name) == 0) |
|
| - | 67 | return &node->property[i]; |
|
| - | 68 | } |
|
| - | 69 | ||
| - | 70 | return NULL; |
|
| - | 71 | } |
|
| - | 72 | ||
| 54 | /** Return value of the 'name' property. |
73 | /** Return value of the 'name' property. |
| 55 | * |
74 | * |
| 56 | * @param node Node of interest. |
75 | * @param node Node of interest. |
| 57 | * |
76 | * |
| 58 | * @return Value of the 'name' property belonging to the node. |
77 | * @return Value of the 'name' property belonging to the node. |
| 59 | */ |
78 | */ |
| 60 | const char *ofw_tree_node_name(const ofw_tree_node_t *node) |
79 | const char *ofw_tree_node_name(const ofw_tree_node_t *node) |
| 61 | { |
80 | { |
| 62 | int i; |
81 | ofw_tree_property_t *prop; |
| 63 | 82 | ||
| 64 | for (i = 0; i < node->properties; i++) { |
83 | prop = ofw_tree_getprop(node, "name"); |
| 65 | if (strncmp(node->property[i].name, "name", strlen("name")) == 0) { |
- | |
| 66 | if (node->property[i].size < 2) |
84 | if (!prop) |
| 67 | panic("Invalid name property.\n"); |
85 | panic("Node without name property.\n"); |
| 68 | return node->property[i].value; |
- | |
| 69 | } |
86 | |
| 70 | } |
87 | if (prop->size < 2) |
| - | 88 | panic("Invalid name property.\n"); |
|
| 71 | 89 | ||
| 72 | panic("Node without name property.\n"); |
90 | return prop->value; |
| 73 | } |
91 | } |
| 74 | 92 | ||
| 75 | /** Lookup child of given name. |
93 | /** Lookup child of given name. |
| 76 | * |
94 | * |
| 77 | * @param node Node whose child is being looked up. |
95 | * @param node Node whose child is being looked up. |
| 78 | * @param da_name Disambigued name of the child being looked up. |
96 | * @param name Name of the child being looked up. |
| 79 | * |
97 | * |
| 80 | * @return NULL if there is no such child or pointer to the matching child node. |
98 | * @return NULL if there is no such child or pointer to the matching child node. |
| 81 | */ |
99 | */ |
| 82 | static ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *da_name) |
100 | static ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *name) |
| 83 | { |
101 | { |
| 84 | ofw_tree_node_t *cur; |
102 | ofw_tree_node_t *cur; |
| 85 | 103 | ||
| - | 104 | /* |
|
| - | 105 | * Try to find the disambigued name. |
|
| - | 106 | */ |
|
| 86 | for (cur = node->child; cur; cur = cur->peer) { |
107 | for (cur = node->child; cur; cur = cur->peer) { |
| 87 | if (strncmp(cur->da_name, da_name, strlen(da_name)) == 0) |
108 | if (strcmp(cur->da_name, name) == 0) |
| 88 | return cur; |
109 | return cur; |
| 89 | } |
110 | } |
| 90 | 111 | ||
| - | 112 | /* |
|
| - | 113 | * Disambigued name not found. |
|
| - | 114 | * Lets try our luck with possibly ambiguous "name" property. |
|
| - | 115 | * |
|
| - | 116 | * We need to do this because paths stored in "/aliases" |
|
| - | 117 | * are not always fully-qualified. |
|
| - | 118 | */ |
|
| - | 119 | for (cur = node->child; cur; cur = cur->peer) { |
|
| - | 120 | if (strcmp(ofw_tree_node_name(cur), name) == 0) |
|
| - | 121 | return cur; |
|
| - | 122 | } |
|
| - | 123 | ||
| 91 | return NULL; |
124 | return NULL; |
| 92 | } |
125 | } |
| 93 | 126 | ||
| 94 | /** Lookup OpenFirmware node by its path. |
127 | /** Lookup OpenFirmware node by its path. |
| 95 | * |
128 | * |