| 84 | } |
| 85 | |
| 86 | static struct node *read_nodes(FILE *f) |
| 87 | { |
| 88 | char line[4096]; |
| 89 | unsigned int curr_indent = 0, indent; |
| 90 | struct node *n, *curr = new_node(); |
| 91 | |
| 92 | /* Ignore first line */ |
| 93 | fgets(line, 4096, f); |
| 94 | |
| 95 | while (fgets(line, 4096, f)) { |
| 96 | bool is_name; |
| 97 | |
| 98 | indent = strspn(line, " "); |
| 99 | |
| 100 | /* Ignore references for now. */ |
| 101 | if (strstarts(line + indent, "reference to: ")) |
| 102 | continue; |
| 103 | |
| 104 | /* Blank name? Use offset of 'contains' to guess indent! */ |
| 105 | if (strstarts(line + indent, "contains ")) |
| 106 | indent -= 31; |
| 107 | |
| 108 | is_name = strstarts(line + indent, ".name "); |
| 109 | |
| 110 | n = parse(line + indent); |
| 111 | if (is_name) { |
| 112 | curr->name = namelen(n->len); |
| 113 | free(n); |
| 114 | } else { |
| 115 | if (indent > curr_indent) { |
| 116 | assert(indent == curr_indent + 4); |
| 117 | curr_indent += 4; |
| 118 | } else { |
| 119 | /* Go back up to parent. */ |
| 120 | for (curr_indent += 4; |
| 121 | curr_indent != indent; |
| 122 | curr_indent -= 4) |
| 123 | curr = curr->parent; |
| 124 | } |
| 125 | add_child(curr, n); |
| 126 | curr = n; |
| 127 | } |
| 128 | } |
| 129 | while (curr->parent) { |
| 130 | curr = curr->parent; |
| 131 | curr_indent -= 4; |
| 132 | } |
| 133 | assert(curr_indent == 0); |
| 134 | return curr; |
| 135 | } |
| 136 | |
| 137 | static int unused_talloc_destructor(void *p) |
| 138 | { |