From 3ef0e73864d21e2cb96c1c03b09324a665de070e Mon Sep 17 00:00:00 2001 From: Holden Rohrer Date: Sun, 14 Jun 2020 20:53:17 -0400 Subject: moved print statement to main.c --- main.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 6c3a617..1a797aa 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,33 @@ #include +#include #include "read.h" +#include "nodelink.h" + +static void printlink(char* name, link* conn) { + if (conn->desc[0]) + printf("%s: %s", name, conn->desc); + else + printf("%s\n", 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 + // and subnodes if iterating over root tree (except root link) + if (reprint && strcmp(loc->ind,"")) { + // 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) { + printeach(root->links->head, 1); +} int main() { node* root = readfile("template"); -- cgit