aboutsummaryrefslogtreecommitdiff
path: root/sys/libbio
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-09-28 13:39:24 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-09-28 13:39:24 -0700
commitbc53100f1ef063e09d77e8670e1796bc67017411 (patch)
treee84b23c3afceb88f75088be2749683b407d1cea2 /sys/libbio
parent83cd586ea304d6f6aa190c65ee796baaba1941a7 (diff)
Checkin: various small changes
Diffstat (limited to 'sys/libbio')
-rw-r--r--sys/libbio/fasta.c4
-rw-r--r--sys/libbio/newick.c37
-rw-r--r--sys/libbio/phylo.c6
3 files changed, 21 insertions, 26 deletions
diff --git a/sys/libbio/fasta.c b/sys/libbio/fasta.c
index 0c47199..2feb0a4 100644
--- a/sys/libbio/fasta.c
+++ b/sys/libbio/fasta.c
@@ -176,7 +176,7 @@ bio·closeseq(bio·SeqReader *rdr)
mem = rdr->seq->mem;
heap = rdr->seq->heap;
-
+
mem.free(heap, rdr->seq);
mem.free(heap, rdr);
@@ -191,7 +191,7 @@ readfasta(bio·SeqReader *rdr, bio·Seq *seq, byte hdr, byte stop)
error err;
byte *beg;
- if (rdr->eof && rdr->b == rdr->bend-1)
+ if(rdr->eof && rdr->b == rdr->bend-1)
return EOF;
reset(rdr->seq);
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;
}
// -----------------------------------------------------------------------
diff --git a/sys/libbio/phylo.c b/sys/libbio/phylo.c
index 920102b..cb5c75c 100644
--- a/sys/libbio/phylo.c
+++ b/sys/libbio/phylo.c
@@ -84,7 +84,7 @@ phylo·countleafs(bio·Node *node, int *n)
{
error err;
bio·Node *child;
-
+
if (!node->nchild) {
*n += 1;
}
@@ -392,7 +392,7 @@ phylo·reroot(bio·Tree *tree, bio·Node *node, double d)
// TODO: should check that node is part of this tree?
// TODO: should we check if node->parent != nil?
-
+
if (fabs(d) < PREC) {
new = node;
rotateparent(node->parent, node);
@@ -402,7 +402,7 @@ phylo·reroot(bio·Tree *tree, bio·Node *node, double d)
rotateparent(new->parent->parent, new->parent);
}
} else {
- new = tree->heap.alloc(tree->h, 1, sizeof(*new));
+ new = tree->mem.alloc(tree->heap, 1, sizeof(*new));
memset(new, 0, sizeof(*new));
phylo·addchild(new, node);