about summary refs log tree commit diff
path: root/sourcecodes/k-best/src/parents2arcs.c
diff options
context:
space:
mode:
authorziejd22017-09-14 15:39:41 -0500
committerziejd22017-09-14 15:57:50 -0500
commitc4f926438dcb8abe805e910399940f79ff643c4b (patch)
tree3146d05ada5cf4b48d9bdd16c1baa498e8df7192 /sourcecodes/k-best/src/parents2arcs.c
parent57ebf49403b75dcf8482d174b59f7fd2a961d98e (diff)
downloadBNW-c4f926438dcb8abe805e910399940f79ff643c4b.tar.gz
Add files via upload
Diffstat (limited to 'sourcecodes/k-best/src/parents2arcs.c')
-rw-r--r--sourcecodes/k-best/src/parents2arcs.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/sourcecodes/k-best/src/parents2arcs.c b/sourcecodes/k-best/src/parents2arcs.c
new file mode 100644
index 00000000..81e8b3b1
--- /dev/null
+++ b/sourcecodes/k-best/src/parents2arcs.c
@@ -0,0 +1,37 @@
+#include "cfg.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#define BUFSIZE (1024)
+
+void parents2arcs(char* parfile, char* arcfile)
+{
+  char buffer[BUFSIZE];
+  int v;
+  FILE* parf = strcmp(parfile,"-") ? fopen(parfile, "r") : stdin;
+  FILE* arcf = strcmp(arcfile,"-") ? fopen(arcfile, "w") : stdout;
+  for(v=0; NULL != fgets(buffer, BUFSIZE, parf); ++v){
+    /* could check that the last character in buffer is newline */
+    char* token;
+    for(token=strtok(buffer, " \t\r\n"); token; token=strtok(NULL, " \t\r\n")){
+      fprintf(arcf, "%d %d\n", atoi(token), v);
+    }
+  }
+  fclose(arcf);
+  fclose(parf);
+}
+
+int main(int argc, char* argv[])
+{
+
+  if (argc!=3) {
+    fprintf(stderr, "Usage: parents2arcs parentfile arcfile\n");
+    return 1;
+  }
+
+  parents2arcs(argv[1], argv[2]);
+
+  return 0;
+}