X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=buffer_tree.c;h=c826e8fa26a97c9036595ddf188bb984a7b4ec4e;hb=03683166610b241183b3cdb311069c96144fa53e;hp=cd3a3c78a45db3babb73c34a3b860b55c2d99bd7;hpb=81f6ec36f467795d7f17fcc669395f8a5d1223bb;p=paraslash.git diff --git a/buffer_tree.c b/buffer_tree.c index cd3a3c78..c826e8fa 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -119,6 +119,11 @@ void btr_add_output(char *buf, size_t size, struct btr_node *btrn) { struct btr_buffer *btrb; + assert(size != 0); + if (list_empty(&btrn->children)) { + free(buf); + return; + } btrb = new_btrb(buf, size); add_btrb_to_children(btrb, btrn, 0); } @@ -137,6 +142,17 @@ void btr_pushdown(struct btr_node *btrn) btr_pushdown_br(br, btrn); } +int btr_pushdown_one(struct btr_node *btrn) +{ + struct btr_buffer_reference *br; + + if (list_empty(&btrn->input_queue)) + return 0; + br = list_first_entry(&btrn->input_queue, struct btr_buffer_reference, node); + btr_pushdown_br(br, btrn); + return 1; +} + /* Return true if this node has no children. */ bool btr_no_children(struct btr_node *btrn) { @@ -371,3 +387,20 @@ bool btr_eof(struct btr_node *btrn) return (len == 0 && btr_no_parent(btrn)); } + +void log_tree_recursively(struct btr_node *btrn, int loglevel, int depth) +{ + struct btr_node *ch; + const char spaces[] = " ", *space = spaces + 16 - depth; + + if (depth > 16) + return; + para_log(loglevel, "%s%s\n", space, btrn->name); + FOR_EACH_CHILD(ch, btrn) + log_tree_recursively(ch, loglevel, depth + 1); +} + +void btr_log_tree(struct btr_node *btrn, int loglevel) +{ + return log_tree_recursively(btrn, loglevel, 0); +}