aboutsummaryrefslogtreecommitdiff
path: root/nodelink.c
diff options
context:
space:
mode:
authorHolden Rohrer <hr@hrhr.dev>2020-05-27 16:21:02 -0400
committerHolden Rohrer <hr@hrhr.dev>2020-05-27 16:21:24 -0400
commit290f2b95ee100735f55fe10af457cc65158af043 (patch)
tree6f72fa5c6312460c04cc78dcd71f370097c3903e /nodelink.c
parent37cd5bb9e3742f4893a14e04d49a4ba9716455c8 (diff)
Initial working commit
There are still some errors when run through valgrind, but it performs as expected for the test file.
Diffstat (limited to 'nodelink.c')
-rw-r--r--nodelink.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/nodelink.c b/nodelink.c
new file mode 100644
index 0000000..ad6beb3
--- /dev/null
+++ b/nodelink.c
@@ -0,0 +1,44 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "nodelink.h"
+#include "strbst.h"
+
+node* newnode(void) {
+ node* new = malloc(sizeof(node));
+ new->links = newbst();
+ return new;
+}
+
+link* newlink(node* to) {
+ link* new = malloc(sizeof(link));
+ new->desc = ""; // preferred to NULL because it can be printed
+ new->to = to;
+ return new;
+}
+
+static void printlink(char* name, link* conn) {
+ if (conn->desc[0])
+ printf("Link to %s: %s", name, conn->desc);
+ else
+ printf("Link to %s", name);
+}
+
+static void printeach(strbstnode* loc, char reprint) {
+ if (loc == NULL) return;
+ // loc->ind is the name of the connection and loc->data the link
+ if (!reprint) printf(" "); // indent on subnode
+ printlink(loc->ind, loc->data); // prints it
+ if (reprint) { // and their subnodes if iterating over root tree
+ printf("subnodes:\n");
+ // prints the link's target's link tree
+ printeach( ( (link*)loc->data)->to->links->head, 0);
+ }
+ printeach(loc->left, reprint);
+ printeach(loc->right, reprint); // recursion
+}
+
+void printnode(node* root) {
+ printf("Root node\n");
+ printeach(root->links->head, 1);
+}