diff options
-rw-r--r-- | nodelink.c | 8 | ||||
-rw-r--r-- | read.c | 12 |
2 files changed, 17 insertions, 3 deletions
@@ -11,9 +11,15 @@ node* newnode(void) { return new; } +static char* empty(void) { + char* out = malloc(sizeof(char)); + *out = 0; + return out; +} + link* newlink(node* to) { link* new = malloc(sizeof(link)); - new->desc = ""; // preferred to NULL because it can be printed + new->desc = empty(); // preferred to NULL because it can be printed new->to = to; return new; } @@ -88,6 +88,14 @@ static char* resolvell(llnode* tail, size_t sz) { return out; } +static void stradd(char** orig, char* new) { // new is freed + size_t nsz = strlen(new)+1; + size_t olen = strlen(*orig); + *orig = realloc(*orig,olen+nsz); + memcpy(*orig+olen,new,nsz); + free(new); +} + node* readfile(char* name) { FILE* read = fopen(name, "r"); node *root, *cur; @@ -103,7 +111,7 @@ node* readfile(char* name) { int c; while ( ( c = fgetc(read) ) != EOF ) { if (c == ':' || c == '-') { - curl->desc = resolvell(head->next, sz); + stradd(&(curl->desc),resolvell(head->next, sz)); head->next = NULL; tail = head; sz = 0; @@ -117,7 +125,6 @@ node* readfile(char* name) { case '-': ; char* lname = line(read, false); - printf("%s.\n",lname); node* at = insorget(root->links, lname)->to; curl = addbstlink(cur->links, lname, at); break; @@ -130,6 +137,7 @@ node* readfile(char* name) { break; } } + stradd(&(curl->desc),resolvell(head->next, sz)); fclose(read); return root; } |