From: kim Date: Wed, 28 Apr 2010 01:49:51 +0000 (+0000) Subject: More fixing in the printing code X-Git-Url: http://git.nguyen.vg/gitweb/?p=SXSI%2FXMLTree.git;a=commitdiff_plain;h=b9205dab05e219c2ac3ce7cf5fe0107267d60535 More fixing in the printing code git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@796 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- diff --git a/XMLTree.cpp b/XMLTree.cpp index 06aaba0..9be500e 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -107,6 +107,7 @@ XMLTree::XMLTree( pb * const par, uint npar, vector * const TN, TagIdM uint *empty_texts_bmp, TagType *tags, TextCollection * const TC, bool dis_tc) { + buffer = 0; // creates the data structure for the tree topology Par = (bp *)umalloc(sizeof(bp)); STARTTIMER(); @@ -248,6 +249,7 @@ void XMLTree::Save(int fd) // a pointer to the loaded data structure XMLTree *XMLTree::Load(int fd, bool load_tc,int sample_factor) { + FILE *fp; char buffer[1024]; XMLTree *XML_Tree; @@ -947,7 +949,8 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ int newfd = dup(fd); stream = fdopen(newfd,"wa"); - + if (buffer == 0) + buffer = new string(); FILE* fp = stream; treeNode fin = fast_find_close(Par,x); @@ -970,8 +973,7 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ if (first_idx != NULLT) current_text = GetText(MyText(first_idx)); int read = 0; - - std::stack st; + std::vector st; while (n <= fin){ if (fast_inspect(Par,n)){ if (tag == PCDATA_TAG_ID ) { @@ -987,13 +989,12 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ } else { - myfputc('<',fp); tagstr = (uchar*) GetTagNameByRef(tag); myfputs((const char*) tagstr ,fp); n++; if (fast_inspect(Par,n)) { - st.push(tagstr); + st.push_back(tagstr); tag = Tag(n); if (tag == ATTRIBUTE_TAG_ID){ n++; @@ -1001,10 +1002,11 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ while (fast_inspect(Par,n)){ if (no_text) { myfputc('<',fp); - myfputs((const char*) &(GetTagNameByRef(Tag(n))[3]),fp); + const uchar * tmp = &(GetTagNameByRef(Tag(n))[3]); + myfputs((const char*) tmp,fp); myfputc('>',fp); myfputs("<$@/>',fp); n+= 4; } @@ -1040,14 +1042,14 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ else do { myfputs("', fp); - st.pop(); + st.pop_back(); n++; }while (!fast_inspect(Par,n) && !st.empty()); tag=Tag(n); }; - myfputc('\n',fp); + //myfputc('\n',fp); mybufferflush(fp); fflush(fp); fclose(fp); diff --git a/XMLTree.h b/XMLTree.h index c2a0210..d0a5c73 100644 --- a/XMLTree.h +++ b/XMLTree.h @@ -142,28 +142,28 @@ class XMLTree { FILE* stream; int stream_fd; - string buffer; + string * buffer; void myfputs(const char* s, FILE * fp){ - buffer.append(s); - if (buffer.size() >= 1000000){ - fputs(buffer.c_str(),fp); - buffer.clear(); + buffer->append(s); + if (buffer->size() >= 100000){ + fputs(buffer->c_str(),fp); + buffer->clear(); }; } void myfputc(const char c, FILE*fp){ - buffer.append(1,c); - if (buffer.size() >= 1000000){ - fputs(buffer.c_str(),fp); - buffer.clear(); + buffer->append(1,c); + if (buffer->size() >= 100000){ + fputs(buffer->c_str(),fp); + buffer->clear(); }; } void mybufferflush(FILE* fp){ - fputs(buffer.c_str(), fp); - buffer.clear(); + fputs(buffer->c_str(), fp); + buffer->clear(); } /** Data structure constructors */ - XMLTree(){;}; + XMLTree(){ buffer = 0;}; // non const pointer are freed by this method. XMLTree( pb * const par, uint npar, vector * const TN, TagIdMap * const tim, uint *empty_texts_bmp, TagType *tags,