1 /********************************************************************
3 name-table.c - the functions used for name table handling. The
4 name table is a binary tree. The node's left child has the name
5 alphabetically before the name in the node, and the right child
6 has the name which is alphabetically after the name in the node.
8 Niksa Orlic, 2004-04-25
10 ********************************************************************/
14 //#include "../util/message.h"
25 #include <string.h>
26 #include <stdlib.h>
29 /*
30 Create an empty name table.
31 */
33 {
49 }
52 /*
53 Destroy an allocated name table and free all memory.
54 */
56 {
71 }
73 /*
74 name_table *name_table_duplicate(name_table *item)
75 {
76 name_table *new_item = mem_alloc(sizeof(name_table));
78 new_item->descriptor = identifier_duplicate(item->descriptor);
79 new_item->name = string_duplicate(item->name);
81 if (item->left_child != NULL)
82 new_item->left_child = name_table_duplicate(item->left_child);
83 else
84 new_item->left_child = NULL;
86 if (item->right_child != NULL)
87 new_item->right_child = name_table_duplicate(item->right_child);
88 else
89 new_item->right_child = NULL;
91 return new_item;
92 }*/
95 /*
96 Inserts an entry into the name table. The string and the descriptor are
97 not copied, only pointers to the string and descriptor are copied.
98 */
101 {
109 {
110 /* the root item is empty, insert the value
111 into the root item */
116 }
119 /* go through the tree to the first free element */
122 do
123 {
127 {
128 /* an error occured, just return */
130 }
133 {
138 }
141 {
146 }
163 }
166 /*
167 Searches name table for an element with a given name.
168 Return the identifier descriptor if found or NULL if
169 not found.
170 */
172 {
176 {
188 }
191 }
194 {
198 {
210 }
213 }