aboutsummaryrefslogtreecommitdiff
path: root/sys/libbio/test.c
blob: 18bb993f41e9a69dd10a3c3398ad353f3fb10eb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <u.h>
#include <libn.h>
#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 };

// -----------------------------------------------------------------------
// 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");

    printf("starting\n");
    t   = bio·readnewick(fd[0], arena);
    err = bio·writenewick(t, fd[1]);
    printf("ending\n");

    io·close(fd[0]); io·close(fd[1]);
    return 0;
}