Subversion Repositories HelenOS

Rev

Rev 1895 | Rev 1899 | Go to most recent revision | Show entire file | Regard 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
/** Return value of the 'name' property.
54
/** Get OpenFirmware node property.
55
 *
55
 *
-
 
56
 * @param node Node in which to lookup the property.
56
 * @param node Node of interest.
57
 * @param name Name of the property.
57
 *
58
 *
58
 * @return Value of the 'name' property belonging to the node.
59
 * @return Pointer to the property structure or NULL if no such property.
59
 */
60
 */
60
const char *ofw_tree_node_name(const ofw_tree_node_t *node)
61
ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *node, const char *name)
61
{
62
{
62
    int i;
63
    int i;
63
   
64
   
64
    for (i = 0; i < node->properties; i++) {
65
    for (i = 0; i < node->properties; i++) {
65
        if (strncmp(node->property[i].name, "name", strlen("name")) == 0) {
66
        if (strcmp(node->property[i].name, name) == 0)
66
            if (node->property[i].size < 2)
-
 
67
                panic("Invalid name property.\n");
-
 
68
            return node->property[i].value;
67
            return &node->property[i];
69
        }
68
    }
-
 
69
 
-
 
70
    return NULL;
70
    }
71
}
71
   
72
 
-
 
73
/** Return value of the 'name' property.
-
 
74
 *
-
 
75
 * @param node Node of interest.
-
 
76
 *
-
 
77
 * @return Value of the 'name' property belonging to the node.
-
 
78
 */
-
 
79
const char *ofw_tree_node_name(const ofw_tree_node_t *node)
-
 
80
{
-
 
81
    ofw_tree_property_t *prop;
-
 
82
   
-
 
83
    prop = ofw_tree_getprop(node, "name");
-
 
84
    if (!prop)
72
    panic("Node without name property.\n");
85
        panic("Node without name property.\n");
-
 
86
       
-
 
87
    if (prop->size < 2)
-
 
88
        panic("Invalid name property.\n");
-
 
89
   
-
 
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
     */
-
 
107
    for (cur = node->child; cur; cur = cur->peer) {
-
 
108
        if (strcmp(cur->da_name, name) == 0)
-
 
109
            return cur;
-
 
110
    }
-
 
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
     */
86
    for (cur = node->child; cur; cur = cur->peer) {
119
    for (cur = node->child; cur; cur = cur->peer) {
87
        if (strncmp(cur->da_name, da_name, strlen(da_name)) == 0)
120
        if (strcmp(ofw_tree_node_name(cur), name) == 0)
88
            return cur;
121
            return cur;
89
    }
122
    }
90
   
123
       
91
    return NULL;
124
    return NULL;
92
}
125
}