diff options
| author | ziejd2 | 2017-09-14 15:39:41 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-14 15:57:50 -0500 |
| commit | c4f926438dcb8abe805e910399940f79ff643c4b (patch) | |
| tree | 3146d05ada5cf4b48d9bdd16c1baa498e8df7192 /sourcecodes/k-best/src/arcs2dot.c | |
| parent | 57ebf49403b75dcf8482d174b59f7fd2a961d98e (diff) | |
| download | BNW-c4f926438dcb8abe805e910399940f79ff643c4b.tar.gz | |
Add files via upload
Diffstat (limited to 'sourcecodes/k-best/src/arcs2dot.c')
| -rw-r--r-- | sourcecodes/k-best/src/arcs2dot.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/sourcecodes/k-best/src/arcs2dot.c b/sourcecodes/k-best/src/arcs2dot.c new file mode 100644 index 00000000..12f48158 --- /dev/null +++ b/sourcecodes/k-best/src/arcs2dot.c @@ -0,0 +1,60 @@ +#include "cfg.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#define BUFSIZE (1024) + +void arcs2dot(char* vdfile, char* arcfile, char* dotfile) +{ + char buffer[BUFSIZE]; + FILE* dotf = strcmp(dotfile,"-") ? fopen(dotfile, "w") : stdout; + + fprintf(dotf, "digraph Bene {\n"); + fprintf(dotf, " /*@@@BEFORE_ALL@@@*/\n"); + + {/* read vdfile to get names of variables */ + + FILE* vdf = fopen(vdfile, "r"); + int v; + fprintf(dotf, " /*@@@BEFORE_NODES@@@*/\n"); + for(v=0; NULL != fgets(buffer, BUFSIZE, vdf); ++v){ + char* token = strtok(buffer, "\t\r\n"); + fprintf(dotf, " V%d [label=\"%s\" /*@@@NODE_ATTS@@@*/];\n", v, token); + } + fprintf(dotf, " /*@@@AFTER_NODES@@@*/\n"); + fclose(vdf); + } + + { + + int from, to; + FILE* arcf = strcmp(arcfile,"-") ? fopen(arcfile, "r") : stdin; + + fprintf(dotf, " /*@@@BEFORE_EDGES@@@*/\n"); + while(2 == fscanf(arcf, "%d %d", &from, &to)){ + fprintf(dotf, " V%d -> V%d /*@@@EDGE_ATTS@@@*/;\n", from, to); + } + fprintf(dotf, " /*@@@AFTER_EDGES@@@*/\n"); + + fclose(arcf); + } + + fprintf(dotf, " /*@@@AFTER_ALL@@@*/\n"); + fprintf(dotf, "}\n"); + fclose(dotf); +} + +int main(int argc, char* argv[]) +{ + + if (argc!=4) { + fprintf(stderr, "Usage: arcs2dot vdfile arcfile dotfile\n"); + return 1; + } + + arcs2dot(argv[1], argv[2], argv[3]); + + return 0; +} |
