aboutsummaryrefslogtreecommitdiff
path: root/sys/libbio/test.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-23 21:09:30 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-23 21:09:30 -0700
commit4c7870c21b9e645b349ddb77b091543b72c46bf5 (patch)
treef53a77257b62c7ef0729f176daa4c49c5bf57587 /sys/libbio/test.c
parent1a6c99600617f069d6d167fb3d33142a07fe0936 (diff)
feat: made calling signature of interface accepting functions more reliable
Diffstat (limited to 'sys/libbio/test.c')
-rw-r--r--sys/libbio/test.c102
1 files changed, 15 insertions, 87 deletions
diff --git a/sys/libbio/test.c b/sys/libbio/test.c
index fb79302..115ee46 100644
--- a/sys/libbio/test.c
+++ b/sys/libbio/test.c
@@ -3,108 +3,36 @@
#include <libbio.h>
// -----------------------------------------------------------------------
-// Arena allocator
-
-static mem·Arena* ARENA;
-
-static
-void*
-bio·alloc(ulong size)
-{
- return mem·arenaalloc(ARENA, size);
-}
-
-static
-void*
-bio·realloc(void *ptr, ulong size)
-{
- void* new = mem·arenaalloc(ARENA, size);
- memcpy(new, ptr, size);
-
- return new;
-}
-
-static
-void
-bio·free(void *ptr)
-{
- /* stub */
-}
-
-static mem·Allocator arena = {.alloc = &bio·alloc, .realloc = &bio·realloc, .free = &bio·free };
-
-// -----------------------------------------------------------------------
-// Read/writer
-
-/* Static reader thunk */
-static Stream* INPUT;
-
-static
-byte
-get()
-{
- return io·getbyte(INPUT);
-}
-
-static
-error
-unget(byte c)
-{
- return io·ungetbyte(INPUT, c);
-}
-
-static io·Peeker rdr = {.get = &get, .unget = &unget};
-
-/* Static writer thunk */
-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 wtr = {.put = &put, .putstr = &putstr};
-
-// -----------------------------------------------------------------------
// Point of entry for testing
-void
-init()
-{
- ARENA = mem·newarena(mem·sys);
-}
int
main()
{
- init();
-
error err;
bio·Tree t;
- Stream *fd[2];
+ mem·Arena *mem;
+ Stream *fd[2];
+
+ io·Peeker rdr;
+ io·Putter wtr;
+ mem·Allocator al;
+
+ mem = mem·newarena(mem·sys, nil);
+ rdr = (io·Peeker){.get = &io·getbyte, .unget = &io·ungetbyte};
+ wtr = (io·Putter){.put = &io·putbyte, .putstr = &io·putstring};
+ al = (mem·Allocator) { .alloc = &mem·arenaalloc, .free = nil, };
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];
-
- t = bio·readnewick(rdr, arena);
- err = bio·writenewick(t, wtr);
+ t = bio·readnewick(rdr, fd[0], al, mem);
+ err = bio·writenewick(t, wtr, fd[1]);
io·flush(fd[1]);
- io·close(fd[0]); io·close(fd[1]);
+ io·close(fd[0]);
+ io·close(fd[1]);
- mem·freearena(ARENA);
return 0;
}