#include #include #include // ----------------------------------------------------------------------- // 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 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 init() { ARENA = mem·newarena(mem·sys); } int main() { init(); error err; bio·Tree t; Stream *fd[2]; 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(peeker, arena); err = bio·writenewick(t, putter); printf("ending\n"); io·flush(fd[1]); io·close(fd[0]); io·close(fd[1]); return 0; }