#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tree.h"
#include "mux_tree.h"
Include dependency graph for mux_tree.c:
Go to the source code of this file.
Defines | |
#define | FATAL(msgs...) { fprintf(stderr, ##msgs); exit(1); } |
#define | TREAD(to, len, msg) |
#define | TSAVE(from, len, msg) |
#define | Create(var, typ, count) |
Functions | |
static int | NodeCompare (Node *a, Node *b) |
static void | NodeDelete (Node *a) |
void | AddEntry (Tree *tree, muxkey_t key, dtype_t type, dsize_t size, void *data) |
Node * | FindNode (Tree tree, muxkey_t key) |
void | DeleteEntry (Tree *tree, muxkey_t key) |
static int | NodeSave (Node *n) |
int | SaveTree (FILE *f, Tree tree) |
static void | MyLoadTree (FILE *f, Tree *tree, int(*sizefunc)(int)) |
void | ClearTree (Tree *tree) |
void | LoadTree (FILE *f, Tree *tree, int(*sizefunc)(int)) |
void | UpdateTree (FILE *f, Tree *tree, int(*sizefunc)(int)) |
void | GoThruTree (Tree tree, int(*func)(Node *)) |
Variables | |
static FILE * | tree_file |
static int | nodesave_count |
#define Create | ( | var, | |||
typ, | |||||
count | ) |
Value:
if (!(var = (typ *) calloc(sizeof (typ), count))) \ { fprintf(stderr, "Error mallocating!\n"); exit(1); }
Definition at line 37 of file mux_tree.c.
#define FATAL | ( | msgs... | ) | { fprintf(stderr, ##msgs); exit(1); } |
Definition at line 15 of file mux_tree.c.
#define TREAD | ( | to, | |||
len, | |||||
msg | ) |
Value:
if (feof(f)) FATAL("ERROR READING FILE (%s): EOF.\n", msg); \ if (fread(to,1,len,f) != len) \ FATAL("ERROR READING FILE (%s): NOT ENOUGH READ!\n", msg);
Definition at line 18 of file mux_tree.c.
Referenced by MyLoadTree().
#define TSAVE | ( | from, | |||
len, | |||||
msg | ) |
Value:
if (fwrite(from, 1, len, tree_file) != len) \ FATAL("ERROR WRITING FILE (%s): NOT ENOUGH WRITTEN(?!?)\n", msg);
Definition at line 23 of file mux_tree.c.
Referenced by NodeSave().
Definition at line 55 of file mux_tree.c.
References Create, rbtc_node_type::data, rbtc_node_type::key, NodeCompare(), NodeDelete(), rbtc_node_type::size, tree_add(), and rbtc_node_type::type.
Referenced by MyLoadTree(), and NewSpecialObject().
00057 { 00058 Node *foo; 00059 00060 if (!tree) 00061 return; 00062 Create(foo, Node, 1); 00063 foo->key = key; 00064 foo->data = data; 00065 foo->type = type; 00066 foo->size = size; 00067 tree_add(tree, NodeCompare, foo, NodeDelete); 00068 }
void ClearTree | ( | Tree * | tree | ) |
Definition at line 155 of file mux_tree.c.
References NodeDelete(), and tree_mung().
Referenced by LoadTree().
00156 { 00157 tree_mung(tree, NodeDelete); 00158 }
Definition at line 78 of file mux_tree.c.
References FindNode(), rbtc_node_type::key, NodeCompare(), NodeDelete(), and tree_delete().
Referenced by DisposeSpecialObject(), and zap_unneccessary_hcode().
00079 { 00080 Node foo; 00081 00082 if (FindNode(*tree, key)) { 00083 foo.key = key; 00084 tree_delete(tree, NodeCompare, &foo, NodeDelete); 00085 } 00086 }
Definition at line 70 of file mux_tree.c.
References rbtc_node_type::key, NodeCompare(), and tree_srch().
00071 { 00072 Node foo; 00073 00074 foo.key = key; 00075 return tree_srch(&tree, NodeCompare, &foo); 00076 }
void LoadTree | ( | FILE * | f, | |
Tree * | tree, | |||
int(*)(int) | sizefunc | |||
) |
Definition at line 160 of file mux_tree.c.
References ClearTree(), and MyLoadTree().
00161 { 00162 ClearTree(tree); 00163 MyLoadTree(f, tree, sizefunc); 00164 }
static void MyLoadTree | ( | FILE * | f, | |
Tree * | tree, | |||
int(*)(int) | sizefunc | |||
) | [static] |
Definition at line 115 of file mux_tree.c.
References AddEntry(), and TREAD.
Referenced by LoadTree(), and UpdateTree().
00116 { 00117 muxkey_t key; 00118 dtype_t type; 00119 dsize_t osize; 00120 int nsize, rsize; 00121 void *data; 00122 00123 TREAD(&key, sizeof(key), "first key"); 00124 while (key >= 0 && !feof(f)) { 00125 TREAD(&type, sizeof(type), "type"); 00126 TREAD(&osize, sizeof(osize), "size"); 00127 if (sizefunc && (rsize = sizefunc(type)) >= 0) { 00128 nsize = osize > rsize ? osize : rsize; 00129 } else 00130 nsize = rsize = osize; 00131 if (nsize) { 00132 if (!(data = malloc(nsize))) { 00133 printf("Error malloccing!\n"); 00134 exit(1); 00135 } 00136 if (osize) 00137 TREAD(data, osize, "data"); 00138 00139 if (nsize > osize) 00140 memset(data + osize, 0, nsize - osize); 00141 } else 00142 data = NULL; 00143 00144 /* Set node size to the real type size, rather than the read size, 00145 * so that the object will get 'truncated' to the right size on the 00146 * next dump. 00147 */ 00148 AddEntry(tree, key, type, rsize, data); 00149 TREAD(&key, sizeof(key), "new key"); 00150 } 00151 }
Definition at line 41 of file mux_tree.c.
References rbtc_node_type::key.
Referenced by AddEntry(), DeleteEntry(), and FindNode().
static void NodeDelete | ( | Node * | a | ) | [static] |
Definition at line 48 of file mux_tree.c.
References rbtc_node_type::data.
Referenced by AddEntry(), ClearTree(), and DeleteEntry().
static int NodeSave | ( | Node * | n | ) | [static] |
Definition at line 92 of file mux_tree.c.
References rbtc_node_type::data, rbtc_node_type::key, nodesave_count, rbtc_node_type::size, TSAVE, and rbtc_node_type::type.
Referenced by SaveTree().
00093 { 00094 TSAVE(&n->key, sizeof(n->key), "key"); 00095 TSAVE(&n->type, sizeof(n->type), "type"); 00096 TSAVE(&n->size, sizeof(n->size), "size"); 00097 if (n->size > 0) 00098 TSAVE(n->data, n->size, "data"); 00099 nodesave_count++; 00100 return 1; 00101 }
int SaveTree | ( | FILE * | f, | |
Tree | tree | |||
) |
Definition at line 103 of file mux_tree.c.
References NodeSave(), nodesave_count, tree_file, and tree_trav().
00104 { 00105 muxkey_t key; 00106 00107 nodesave_count = 0; 00108 tree_file = f; 00109 tree_trav(&tree, NodeSave); 00110 key = -1; 00111 fwrite(&key, sizeof(key), 1, tree_file); 00112 return nodesave_count; 00113 }
void UpdateTree | ( | FILE * | f, | |
Tree * | tree, | |||
int(*)(int) | sizefunc | |||
) |
Definition at line 166 of file mux_tree.c.
References MyLoadTree().
Referenced by load_xcode().
00167 { 00168 MyLoadTree(f, tree, sizefunc); 00169 }
int nodesave_count [static] |
FILE* tree_file [static] |