diff options
-rw-r--r-- | graphs.c | 85 | ||||
-rw-r--r-- | graphs.h | 3 | ||||
-rw-r--r-- | trie.h | 11 | ||||
-rw-r--r-- | trie.inc.h | 49 |
4 files changed, 87 insertions, 61 deletions
@@ -5,11 +5,16 @@ #include <string.h> #include "err.h" +// #define TYPE strbuf +// #include "linked_list.h" +// #include "linked_list.inc.h" +// #undef TYPE + int create_graph_trie (vcomponent* ev, char* filename) { FILE* f = fopen(filename, "w"); fputs("digraph {\n rankdir=LR;", f); - TRIE_DOT(content_line)(&ev->clines, f); + trie_to_dot(&ev->clines, f); fputs("}", f); fclose(f); @@ -35,7 +40,7 @@ int helper_vcomponent (vcomponent* root, FILE* f) { (void*) n); fprintf(f, "subgraph \"cluster_%c_%p\" {\ncolor=red; \n", n->c, root); - TRIE_DOT_HELP(content_line) ( n, f ); + trie_to_dot_helper( n, f ); fputs("}", f); @@ -67,3 +72,79 @@ int create_graph_vcomponent (vcomponent* root, char* outfile) { fclose(f); return 0; } + +#define T content_line + +int trie_to_dot ( TRIE(T)* trie, FILE* f ) { + TRIE_NODE(T)* n = trie->root->child; + fprintf(f, "\"%p\" [label=root fontcolor=gray, color=gray];", trie); + while (n != NULL) { + fprintf(f, "\"%p\" -> \"%p\" [color=gray]\n", + (void*) trie, + (void*) n); + fprintf(f, "subgraph \"cluster_%c\" {\n", + n->c); + trie_to_dot_helper( n, f ); + fputs("}", f); + n = n->next; + } + return 0; +} + +int trie_to_dot_helper ( TRIE_NODE(T)* root, FILE* f ) { + if (root->value == NULL) { + fprintf(f, "\"%p\"[label = \"%c\" style=filled fillcolor=white];\n", + (void*) root, root->c); + } else { + fprintf(f, "\"%p\"[label = \"%c [%i]\" style=filled fillcolor=green];\n", + (void*) root, root->c, + SIZE(LLIST(strbuf))(&root->value->vals)); + } + TRIE_NODE(T)* child = root->child; + + // ---------------------------------------- + if (root->value != NULL) { + + FOR(LLIST(strbuf), link, &root->value->vals) { + char buf[0x100]; + FMT(strbuf)(link->value, buf); + fprintf(f, "\"%p\" [label=\"%s\" shape=rectangle color=darkgreen];\n", + link->value, buf); + fprintf(f, "\"%p\" -> \"%p\";\n", root, link->value); + } + + + /* Parameters */ + if (! EMPTY(LLIST(key_val))(&root->value->params)) { + fprintf(f, "subgraph \"cluster_param_%p\"{\n color=blue;\n", root); + FOR(LLIST(key_val), link, &root->value->params) { + fprintf(f, "\"%p\" [shape=rectangle, label=\"%s := %s\"];", link, + link->value->key.mem, + link->value->val.mem); + } + fputs("}", f); + + /* + * TODO + * Params should actually belong to each value. Not to + * each content_line (since a content line is a collection + * of lines in the original file). This is a temporary + * hack. + */ + fprintf(f, "\"link_%p\" [label=params style=filled fillcolor=lightblue];\n", root); + fprintf(f, "\"%p\" -> \"link_%p\";\n", root, root); + FOR(LLIST(key_val), link, &root->value->params) { + fprintf(f, "\"link_%p\" -> \"%p\";\n", root, link); + } + } + } + // ---------------------------------------- + + while (child != NULL) { + fprintf(f, "\"%p\" -> \"%p\";\n", + (void*) root, (void*) child); + trie_to_dot_helper(child, f); + child = child->next; + } + return 0; +} @@ -9,4 +9,7 @@ int create_graph_vcomponent (vcomponent* root, char* outfile); int helper_vcomponent (vcomponent* root, FILE* f); +int trie_to_dot ( TRIE(content_line)*, FILE* ); +int trie_to_dot_helper ( TRIE_NODE(content_line)*, FILE* ); + #endif /* GRAPHS_H */ @@ -8,14 +8,6 @@ #define TRIE(T) TEMPL(trie, T) #define TRIE_NODE(T) TEMPL(trie_node, T) -/* - * TODO - * The DOT functions are for generating graphviz framgments. They - * realy should be moved away from here. - */ -#define TRIE_DOT(T) TP(trie_to_dot__, T) -#define TRIE_DOT_HELP(T) TP(trie_to_dot_helper__, T) - #endif /* TRIE_H */ #ifdef TYPE @@ -46,9 +38,6 @@ FREE_F(TRIE_NODE(TYPE)); FREE_F(TRIE(TYPE)); -int TRIE_DOT(TYPE) ( TRIE(TYPE)*, FILE* ); -int TRIE_DOT_HELP(TYPE) ( TRIE_NODE(TYPE)*, FILE* ); - int EMPTY(TRIE(TYPE))(TRIE(TYPE)*); FMT_F(TRIE_NODE(TYPE)); @@ -5,6 +5,7 @@ #include <stdarg.h> #include "err.h" +#include "macro.h" INIT_F ( TRIE(TYPE) ) { NEW(TRIE_NODE(TYPE), t, '\0'); @@ -119,54 +120,6 @@ int EMPTY(TRIE(TYPE))(TRIE(TYPE)* this) { return this->root->child == NULL; } -int TRIE_DOT(TYPE) ( TRIE(TYPE)* trie, FILE* f ) { - TRIE_NODE(TYPE)* n = trie->root->child; - fprintf(f, "\"%p\" [label=root fontcolor=gray, color=gray];", trie); - while (n != NULL) { - fprintf(f, "\"%p\" -> \"%p\" [color=gray]\n", - (void*) trie, - (void*) n); - fprintf(f, "subgraph \"cluster_%c\" {\n", - n->c); - TRIE_DOT_HELP(TYPE) ( n, f ); - fputs("}", f); - n = n->next; - } - return 0; -} - -int TRIE_DOT_HELP(TYPE) ( TRIE_NODE(TYPE)* root, FILE* f ) { - fprintf(f, "\"%p\"[label = \"%c\" style=filled fillcolor=\"%s\"];\n", - (void*) root, root->c, - root->value == NULL ? "white" : "green"); - TRIE_NODE(TYPE)* child = root->child; - - // ---------------------------------------- - if (root->value != NULL) { - if (! EMPTY(LLIST(key_val))(&root->value->params)) { - fprintf(f, "subgraph \"cluster_param_%p\"{\n color=blue;\n", root); - FOR(LLIST(key_val), link, &root->value->params) { - fprintf(f, "\"%p\" [shape=rectangle, label=\"%s := %s\"];", link, - link->value->key.mem, - link->value->val.mem); - } - fputs("}", f); - FOR(LLIST(key_val), link, &root->value->params) { - fprintf(f, "\"%p\" -> \"%p\";\n", root, link); - } - } - } - // ---------------------------------------- - - while (child != NULL) { - fprintf(f, "\"%p\" -> \"%p\";\n", - (void*) root, (void*) child); - TRIE_DOT_HELP(TYPE)(child, f); - child = child->next; - } - return 0; -} - FMT_F(TRIE_NODE(TYPE)) { va_list ap; |