aboutsummaryrefslogtreecommitdiff
path: root/sys/libbio/test.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-22 19:51:30 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-22 19:51:30 -0700
commit7f1b6ff70b97e424ce73314809838c7cd94f3ae7 (patch)
tree405e5d2e84b931b7d2ab764db13d295598b16828 /sys/libbio/test.c
parent18383b973877f4c30c878414a51c0b44ea5dafe4 (diff)
feat: interfaces of newick io more general. can now take arbitrary readers/writers
Diffstat (limited to 'sys/libbio/test.c')
-rw-r--r--sys/libbio/test.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/sys/libbio/test.c b/sys/libbio/test.c
index 18bb993..3941290 100644
--- a/sys/libbio/test.c
+++ b/sys/libbio/test.c
@@ -34,6 +34,45 @@ bio·free(void *ptr)
static mem·Allocator arena = {.alloc = &bio·alloc, .realloc = &bio·realloc, .free = &bio·free };
// -----------------------------------------------------------------------
+// Read/writer
+
+static Stream* INPUT;
+
+static
+byte
+get()
+{
+ return io·getbyte(INPUT);
+}
+
+static
+error
+unget(byte c)
+{
+ return io·ungetbyte(INPUT, c);
+}
+
+static io·Peeker peeker = {.get = &get, .unget = &unget};
+
+static Stream* OUTPUT;
+
+static
+error
+put(byte b)
+{
+ return io·putbyte(OUTPUT, b);
+}
+
+static
+int
+putstr(string s)
+{
+ return io·putstring(OUTPUT, s);
+}
+
+static io·Putter putter = {.put = &put, .putstr = &putstr};
+
+// -----------------------------------------------------------------------
// Point of entry for testing
void
@@ -54,11 +93,15 @@ main()
fd[0] = io·open("/home/nolln/root/data/test/example.nwk", "r");
fd[1] = io·open("/home/nolln/root/data/test/example.proc.nwk", "w");
+ INPUT = fd[0];
+ OUTPUT = fd[1];
+
printf("starting\n");
- t = bio·readnewick(fd[0], arena);
- err = bio·writenewick(t, fd[1]);
+ t = bio·readnewick(peeker, arena);
+ err = bio·writenewick(t, putter);
printf("ending\n");
+ io·flush(fd[1]);
io·close(fd[0]); io·close(fd[1]);
return 0;
}