aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--read.c21
-rw-r--r--template2
2 files changed, 15 insertions, 8 deletions
diff --git a/read.c b/read.c
index e739bb0..ec7c6c8 100644
--- a/read.c
+++ b/read.c
@@ -59,19 +59,24 @@ static char* line(FILE* file, bool nl) { // gets a line from file
}
}
-static link* insorget(strbst* tgt, char* name) {
+static link* insorget(strbst* tgt, char* name, bool tofree) {
link* get = query(tgt, name);
if (!get) {
get = newlink(newnode());
insbst(tgt, name, get);
- } else {
+ } else if (tofree) {
free(name);
}
return get;
}
-static link* addbstlink(strbst* tree, char* name, node* to) {
- link* l = newlink(to);
+static link* addbstlink(strbst* tree, char* name, node* to, bool f) {
+ link* l = query(tree, name);
+ if (l && f) {
+ free(name);
+ return l;
+ }
+ l = newlink(to);
insbst(tree, name, l);
return l;
}
@@ -102,7 +107,7 @@ node* readfile(char* name) {
FILE* read = fopen(name, "r");
node *root, *cur;
cur = root = newnode();
- link* curl = addbstlink(root->links, "", root);
+ link* curl = addbstlink(root->links, "", root, false);
llnode start;
start.next = NULL; // empty desc isn't undefined
@@ -121,14 +126,14 @@ node* readfile(char* name) {
}
switch (c) {
case ':':
- curl = insorget(root->links, line(read, false));
+ curl = insorget(root->links, line(read, false), true);
cur = curl->to;
break;
case '-': ;
char* lname = line(read, false);
- node* at = insorget(root->links, lname)->to;
- curl = addbstlink(cur->links, lname, at);
+ node* at = insorget(root->links, lname, false)->to;
+ curl = addbstlink(cur->links, lname, at, true);
break;
default:
diff --git a/template b/template
index 912188a..381044a 100644
--- a/template
+++ b/template
@@ -19,6 +19,8 @@ Civilians are being killed by chemicals outlawed by Geneva Convention.
- Chemical Warfare
The United Nations has attempted, in ceasefires to get gov't to agree to
stop chemical warfare in exchange for enemies'
+- Chemical Warfare
+Append because I rememmberd more
:
should append