aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2019-02-09 01:19:43 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2019-02-09 01:19:43 +0100
commiteba7f0e2713a55b2516df97999a3995476a7c166 (patch)
tree0a798f752b57be021006ae405412453ac26a0512
parentFix main loop. (diff)
downloadcalp-eba7f0e2713a55b2516df97999a3995476a7c166.tar.gz
calp-eba7f0e2713a55b2516df97999a3995476a7c166.tar.xz
Add support for full tree printing.
-rw-r--r--graphs.c50
-rw-r--r--graphs.h6
-rw-r--r--main.c8
-rw-r--r--trie.h2
-rw-r--r--trie.inc.h9
5 files changed, 69 insertions, 6 deletions
diff --git a/graphs.c b/graphs.c
index ab49f4f1..f1c8ed75 100644
--- a/graphs.c
+++ b/graphs.c
@@ -1,8 +1,9 @@
#include "graphs.h"
#include <stdio.h>
+#include <errno.h>
-int create_graph (vcomponent* ev, char* filename) {
+int create_graph_trie (vcomponent* ev, char* filename) {
FILE* f = fopen(filename, "w");
fputs("digraph {\n rankdir=LR;", f);
@@ -15,3 +16,50 @@ int create_graph (vcomponent* ev, char* filename) {
return 0;
}
+
+int helper_vcomponent (vcomponent* root, FILE* f) {
+ fprintf(f, "subgraph \"cluster_root\" { label=File; \"%p\" [label=%s] }\n", root, root->type);
+
+ TRIE(content_line)* trie = &root->clines;
+ TRIE_NODE(content_line)* n = trie->root->child;
+
+ if (! EMPTY(TRIE(content_line))(trie)) {
+ fprintf(f, "subgraph \"cluster_%p\" {\n", root);
+ fprintf(f, "\"%p\" [label=trie fontcolor=gray, color=gray];", trie);
+ fprintf(f, "\"%p\" -> \"%p\" [color=red]\n", root, trie);
+ while (n != NULL) {
+ fprintf(f, "\"%p\" -> \"%p\" [color=gray]\n",
+ (void*) trie,
+ (void*) n);
+ fprintf(f, "subgraph \"cluster_%c_%p\" {\ncolor=red; \n",
+ n->c, root);
+ TRIE_DOT_HELP(content_line) ( n, f );
+ fputs("}", f);
+ n = n->next;
+ }
+ fputs("}", f);
+ }
+
+ vcomponent* child;
+ for (size_t i = 0; i < root->components.length; i++) {
+ child = GET(VECT(vcomponent))(&root->components, i);
+ if (child == NULL) continue;
+ fprintf(f, "\"%p\" -> \"%p\"\n", root, child);
+ helper_vcomponent(child, f);
+ }
+ return 0;
+}
+
+int create_graph_vcomponent (vcomponent* root, char* outfile) {
+ FILE* f = fopen(outfile, "w");
+ if (f == NULL) {
+ printf("Error opening file %s, errno = %i\n", outfile, errno);
+ return 1;
+ }
+ vcomponent* c = root;
+ fputs("digraph {", f);
+ helper_vcomponent(c, f);
+ fputs("}", f);
+ fclose(f);
+ return 0;
+}
diff --git a/graphs.h b/graphs.h
index 45c461af..6baa1ffa 100644
--- a/graphs.h
+++ b/graphs.h
@@ -3,6 +3,10 @@
#include "vcal.h"
-int create_graph (vcomponent* ev, char* filename);
+int create_graph_trie (vcomponent* ev, char* filename);
+
+int create_graph_vcomponent (vcomponent* root, char* outfile);
+
+int helper_vcomponent (vcomponent* root, FILE* f);
#endif /* GRAPHS_H */
diff --git a/main.c b/main.c
index 47d69e4d..6b312ec1 100644
--- a/main.c
+++ b/main.c
@@ -56,6 +56,7 @@ int main (int argc, char* argv[argc]) {
}
}
} else if (strcmp(args.argv[0], "-g") == 0) {
+ /* TODO this might be broken */
if (arg_shift(&args) == 0) {
for (size_t i = 0; i < root.components.length; i++) {
vcomponent* cal = GET(VECT(vcomponent))(&root.components, i);
@@ -68,10 +69,13 @@ int main (int argc, char* argv[argc]) {
strcat(target, "/tmp/dot/");
strcat(target, ev->filename);
strcat(target, ".dot");
- create_graph(ev, target);
+ // create_graph(ev, target);
}
} else {
- create_graph(FCHILD(FCHILD(&root)), args.argv[0]);
+ // create_graph(FCHILD(FCHILD(&root)), args.argv[0]);
+ puts("Creating graph for single file");
+ printf("output = %s\n", args.argv[0]);
+ create_graph_vcomponent(&root, args.argv[0]);
}
}
diff --git a/trie.h b/trie.h
index 77d0020f..9acbe300 100644
--- a/trie.h
+++ b/trie.h
@@ -49,4 +49,6 @@ 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)*);
+
#endif /* TYPE */
diff --git a/trie.inc.h b/trie.inc.h
index 5fa047db..3bc19895 100644
--- a/trie.inc.h
+++ b/trie.inc.h
@@ -113,11 +113,16 @@ FREE_F(TRIE(TYPE)) {
return FREE(TRIE_NODE(TYPE))(this->root);
}
+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;
- fputs("root [fontcolor=gray, color=gray];", f);
+ fprintf(f, "\"%p\" [label=root fontcolor=gray, color=gray];", trie);
while (n != NULL) {
- fprintf(f, "root -> \"%p\" [color=gray]\n",
+ fprintf(f, "\"%p\" -> \"%p\" [color=gray]\n",
+ (void*) trie,
(void*) n);
fprintf(f, "subgraph \"cluster_%c\" {\n",
n->c);