aboutsummaryrefslogtreecommitdiff
path: root/sys/libbio/newick.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/libbio/newick.c')
-rw-r--r--sys/libbio/newick.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/sys/libbio/newick.c b/sys/libbio/newick.c
index 98d30f2..631596f 100644
--- a/sys/libbio/newick.c
+++ b/sys/libbio/newick.c
@@ -167,10 +167,10 @@ struct Parser
bio·Node *root;
struct Token tok;
- void *fimpl;
+ void *io;
io·Peeker file;
- void *himpl;
- mem·Allocator heap;
+ void *heap;
+ mem·Allocator mem;
};
static
@@ -184,7 +184,7 @@ parse(struct Parser *p)
node = p->root;
for (;;) {
- tok = lex_nospace(p->file, p->fimpl);
+ tok = lex_nospace(p->file, p->io);
switch (tok.kind) {
case tok·lparen:
@@ -193,7 +193,7 @@ parse(struct Parser *p)
goto ERROR;
}
- node = p->heap.alloc(p->himpl, 1, sizeof(*node));
+ node = p->mem.alloc(p->heap, 1, sizeof(*node));
memset(node, 0, sizeof(*node));
if (p->root) {
@@ -231,7 +231,7 @@ parse(struct Parser *p)
}
node->comment = str·make("");
while (tok.kind != tok·rbrak) {
- tok = lex_nospace(p->file, p->fimpl);
+ tok = lex_nospace(p->file, p->io);
if (tok.kind == tok·eof || tok.kind == tok·nil) {
errorf("incorrect format: unmatched comment bracket '['");
goto ERROR;
@@ -246,7 +246,7 @@ parse(struct Parser *p)
break;
case tok·colon:
- tok = lex_nospace(p->file, p->fimpl);
+ tok = lex_nospace(p->file, p->io);
if (tok.kind != tok·number) {
errorf("incorrect format: expected number after colon");
goto ERROR;
@@ -280,7 +280,7 @@ parse(struct Parser *p)
goto ERROR;
}
- node = p->heap.alloc(p->himpl, 1, sizeof(*node));
+ node = p->mem.alloc(p->heap, 1, sizeof(*node));
memset(node, 0, sizeof(*node));
node->name = str·make(tok.lit.s);
@@ -303,7 +303,7 @@ parse(struct Parser *p)
break;
case tok·semi:
- p->file.unget(p->fimpl, ';');
+ p->file.unget(p->io, ';');
if (p->lev) {
errorf("format error: uneven number of parentheses found at ';'");
goto ERROR;
@@ -329,35 +329,30 @@ ERROR:
return 1;
}
-error
+int
bio·readnewick(io·Peeker stream, void *s, bio·Tree *tree)
{
error err;
struct Parser p;
- enum
- {
- error·nil,
- error·notree,
- error·parse,
- };
if (!tree) {
- return error·notree;
+ errorf("tree pointer nil");
+ return 0;
}
p = (struct Parser){
.lev = 0,
.root = nil,
.tok = (struct Token){ 0 },
- .fimpl = s,
+ .io = s,
.file = stream,
- .himpl = tree->h,
+ .mem = tree->mem,
.heap = tree->heap,
};
err = parse(&p);
if (err) {
errorf("parsing failed\n");
- return error·parse;
+ return 0;
}
tree->root = p.root;
@@ -367,7 +362,7 @@ bio·readnewick(io·Peeker stream, void *s, bio·Tree *tree)
phylo·countleafs(tree->root, &tree->nleaf);
phylo·countnodes(tree->root, &tree->root->nnode);
- return error·nil;
+ return 1;
}
// -----------------------------------------------------------------------