X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=xml-tree.cpp;h=df7efe234fbacc745639e34e22bcecd48a6e3f47;hb=115c103a05a3143ccea9e6a725fc6ee3fa206061;hp=758c1b4d9b5ffce3bbdb2022ca57a9a642b58ca5;hpb=429f734c9f9241dfb9c587e8b333777f3540625f;p=SXSI%2FXMLTree.git diff --git a/xml-tree.cpp b/xml-tree.cpp index 758c1b4..df7efe2 100644 --- a/xml-tree.cpp +++ b/xml-tree.cpp @@ -121,11 +121,7 @@ xml_tree::xml_tree(std::vector *tags, delete textbitmap; this->text_index_type = idx_type; - fprintf(stderr, "Before!\n"); - fflush(stderr); text_collection = tc_builder->InitTextCollection(); - fprintf(stderr, "After!\n"); - fflush(stderr); delete tc_builder; }; @@ -242,8 +238,7 @@ void xml_tree::save(int fd, char* s) bool disable_tc = text_collection == 0 || text_positions == 0; ufwrite(&disable_tc, sizeof(bool),1,fp); - fprintf(stderr, "whoot\n"); - fflush(stderr); + if (!disable_tc) { text_positions->save(fp); ufwrite(&text_index_type, @@ -413,6 +408,7 @@ void xml_tree::uflush(int fd) if (size < BUFFER_SIZE) return; uflush_r(fd, size); } + void xml_tree::flush(int fd) { uflush_r(fd, print_buffer->size()); @@ -425,12 +421,14 @@ void xml_tree::uflush_r(int fd, size_t s) size_t written; while (1) { written = write(fd, print_buffer->data(), s); - if ((written < 0) && (errno == EAGAIN || errno == EINTR)) + if ((written < 0) && (errno == EAGAIN || errno == EINTR)){ continue; + }; break; }; print_buffer->clear(); } + void xml_tree::uput_str(std::string s, int fd) { print_buffer->append(s); @@ -496,14 +494,16 @@ size_t xml_tree::uprintf(const char*s, int fd) return i; } -void xml_tree::print(int fd, xml_tree::node_t x, bool no_text) +void xml_tree::print(xml_tree::node_t x, int fd, bool no_text) { + if (print_buffer == 0) { print_buffer = new std::string(BUFFER_SIZE, 0); print_buffer->clear(); print_stack = new std::vector(); print_stack->reserve(256); }; + xml_tree::node_t fin = bp_find_close(par, x); xml_tree::node_t n = x; xml_tree::tag_t label = tag(n); @@ -582,7 +582,7 @@ void xml_tree::print(int fd, xml_tree::node_t x, bool no_text) uputc('>', fd); print_stack->pop_back(); n++; - } while (!bp_inspect(par, n) || print_stack->empty()); + } while (!bp_inspect(par, n) && !print_stack->empty()); label = tag(n); }; uputc('\n', fd);