1 #ifndef TREE_H 2 #define TREE_H 3 4 #include "node.h" 5 6 /*flag (attribute) definitions*/ 7 enum { 8 F_hidden = 1 << 0, 9 F_readonly = 1 << 1, 10 F_temp = 1 << 2, 11 F_expanded = 1 << 3, 12 F_visible = 1 << 12 13 }; 14 15 /* creates a new tree and returns a node pointing to it don't store this node 16 for reference, keep updating your pointer into the tree with the pointers 17 returned from other functions. 18 19 Returns: new tree 20 */ 21 Node *tree_new (); 22 23 24 /* Given a node in a tree, this function returns a pointer to the root 25 of the tree 26 27 Returns: tree root 28 */ 29 Node *node_root (Node *node); 30 31 /* frees a whole tree from memory, by reference to one of it's nodes 32 */ 33 void tree_free (Node *node); 34 35 /*returns the topmost of the siblings on the level of node 36 37 Returns: level top 38 */ 39 Node *node_top (Node *node); 40 41 /*returns the bottommost of the sibling on the lvel of node 42 43 Returns: level bottom 44 */ 45 Node *node_bottom (Node *node); 46 47 /* inserts a new node above node, returns the new node 48 49 Returns: new node 50 */ 51 Node *node_insert_up (Node *node); 52 53 /* inserts a new node below node, returns the new node 54 55 Returns: new node 56 */ 57 Node *node_insert_down (Node *node); 58 59 /*inserts a child for node, if there already is a child, 0 is returned 60 61 Returns: new node 62 */ 63 Node *node_insert_right (Node *node); 64 65 /* the number of nodes above 66 67 Returns: number of nodes 68 */ 69 unsigned int nodes_up (Node *node); 70 71 /* the number of nodes below 72 73 Returns: number of nodes 74 */ 75 unsigned int nodes_down (Node *node); 76 77 /* the number of nodes to the left (level of node) 78 79 Returns: number of nodes 80 */ 81 unsigned int nodes_left (Node *node); 82 unsigned int nodes_right (Node *node); 83 84 /* removes node and it's children, returns: the 'nearest' still existing node 85 (up or down or left of specified node) 86 87 Returns: nearby node 88 */ 89 Node *node_remove (Node *node); 90 91 /* finds a node starting with match amongst the siblings of where 92 returns 0 if no match found or no match string given 93 94 Returns: matching node or NULL 95 */ 96 Node *node_match (char *match, Node *where); 97 98 /* same as above, but must match whole node 99 100 Returns: matching node or NULL 101 */ 102 Node *node_exact_match (char *match, Node *where); 103 104 /* returns the next node with a case insensitive substring match from where. 105 106 Returns: matching node or NULL 107 */ 108 Node *node_recursive_match (char *match, Node *where); 109 110 /* returns the next node with a case insensitive substring match from where. 111 112 Returns: matching node or NULL 113 */ 114 Node *node_backrecursive_match (char *match, Node *where); 115 116 117 /* swaps the contents of two nodes 118 */ 119 void node_swap (Node *nodeA, Node *nodeB); 120 121 /* returns the next node, doing a recursive traversal of the tree 122 123 Returns: next recursive node or 0 if none 124 */ 125 Node *node_recurse (Node *node); 126 127 /* returns the previous node, doing a recursive traversal of the tree backwards 128 129 Returns: next back recursive node or 0 if none 130 */ 131 Node *node_backrecurse (Node *node); 132 133 /* returns the number of this node in the database 134 */ 135 int node_no (Node *node); 136 137 /* included from node.h 138 139 (most of these are actually macros but can be used as if functions) 140 141 determines if there is a node immedietly next to the specified 142 node in given direction, returns the node if there is 0 otherwise 143 144 Node *node_up(node); 145 Node *node_down(node); 146 Node *node_left(node); 147 Node *node_right(node); 148 149 sets all the flags of a node, if it exists 150 Returns: New flags, or 0 if node didn't exist 151 152 int node_setflags(node,flags); 153 154 gets all the flags of a node, if it exists 155 Returns: flags, or 0 if node didn't exist 156 int node_getflags(node); 157 158 returns the state of the specified flag 159 Returns: 1 if flag is set 0 if not 160 int node_getflag(node,flag); 161 162 sets the specified flag if state is 1, turns of the flag if state is 0 163 Returns: new flags 164 int node_setflag(node,flag); 165 166 toggles the specified flag, 167 Returns: 1 if flag were set 0 if flag were turned of 168 int node_toggleflag(node,flag); 169 170 gets priority of node 171 Returns: priority, or 0 if node didn't exist 172 int node_getpriority(node); 173 174 sets priority of a node, if it exists 175 Returns: New priority, or 0 if node didn't exist 176 int node_setpriority(node,priority); 177 178 179 sets and gets the data for a node, does neccesary allocating 180 and freeing as well. 181 char *node_setdata(Node *node,char *data); 182 183 Returns: pointer to data 184 char *node_getdata(Node *node); 185 */ 186 187 Node *tree_duplicate (Node *source, Node *target); 188 189 extern char TEXT[5]; 190 191 192 #define fixnullstring(str) ((str)?(str):"") 193 194 195 #endif /* TREE_H */ 196