From b443dd155b926655d84a3eadef5be09907d6c5eb Mon Sep 17 00:00:00 2001 From: kim Date: Tue, 27 Apr 2010 08:05:27 +0000 Subject: [PATCH] Fix printing git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@789 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- XMLTree.cpp | 59 ++++++++++++++++++++++++++++++++--------------------- XMLTree.h | 21 ++++++++++++++++++- 2 files changed, 56 insertions(+), 24 deletions(-) diff --git a/XMLTree.cpp b/XMLTree.cpp index e23a06a..06aaba0 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -941,6 +941,8 @@ bool XMLTree::IsOpen(treeNode x) { return fast_inspect(Par,x); } //WARNING this uses directly the underlying implementation for plain text + + void XMLTree::Print(int fd,treeNode x, bool no_text){ int newfd = dup(fd); @@ -973,9 +975,9 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ while (n <= fin){ if (fast_inspect(Par,n)){ if (tag == PCDATA_TAG_ID ) { - // fputs((const char*) (GetText(MyTextUnsafe(n))),fp); + // myfputs((const char*) (GetText(MyTextUnsafe(n))),fp); if (no_text) - fputs("<$/>",fp); + myfputs("<$/>",fp); else{ read = fprintf(fp,"%s",(const char*) current_text); current_text += (read + 1); @@ -986,40 +988,50 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ } else { - fputc('<',fp); + myfputc('<',fp); tagstr = (uchar*) GetTagNameByRef(tag); - fputs((const char*) tagstr ,fp); + myfputs((const char*) tagstr ,fp); n++; if (fast_inspect(Par,n)) { st.push(tagstr); tag = Tag(n); if (tag == ATTRIBUTE_TAG_ID){ n++; + if (no_text) myfputs("><@@>",fp); while (fast_inspect(Par,n)){ - fputc(' ',fp); - fputs((const char*) &(GetTagNameByRef(Tag(n))[3]),fp); - fputs("=\"",fp); - n++; - if (no_text) - fputs("<$@/>",fp); - else{ - read = fprintf(fp,"%s",(const char*) current_text); - current_text += (read + 1); - //fputs((const char*) GetText(MyTextUnsafe(n)),fp); - fputc('"',fp); + if (no_text) { + myfputc('<',fp); + myfputs((const char*) &(GetTagNameByRef(Tag(n))[3]),fp); + myfputc('>',fp); + myfputs("<$@/>',fp); + n+= 4; + } + else { + myfputc(' ',fp); + myfputs((const char*) &(GetTagNameByRef(Tag(n))[3]),fp); + n++; + myfputs("=\"",fp); + read = fprintf(fp,"%s",(const char*) current_text); + current_text += (read + 1); + //myfputs((const char*) GetText(MyTextUnsafe(n)),fp); + myfputc('"',fp); + n+=3; } - n+=3; //close @$ @@ }; - fputc('>',fp); + if (no_text) + myfputs("",fp); + else myfputc('>',fp); n++; tag=Tag(n); } else { - fputc('>',fp); + myfputc('>',fp); }; } else {// tag - fputs("/>",fp); + myfputs("/>",fp); n++; tag=Tag(n); }; @@ -1027,15 +1039,16 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){ } else do { - fputs("', fp); + myfputs("', fp); st.pop(); n++; }while (!fast_inspect(Par,n) && !st.empty()); tag=Tag(n); }; - fputc('\n',fp); + myfputc('\n',fp); + mybufferflush(fp); fflush(fp); fclose(fp); } diff --git a/XMLTree.h b/XMLTree.h index 00ad143..c2a0210 100644 --- a/XMLTree.h +++ b/XMLTree.h @@ -141,8 +141,27 @@ class XMLTree { bool disable_tc; FILE* stream; - int stream_fd; + int stream_fd; + string buffer; + void myfputs(const char* s, FILE * fp){ + buffer.append(s); + if (buffer.size() >= 1000000){ + 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(); + }; + } + void mybufferflush(FILE* fp){ + fputs(buffer.c_str(), fp); + buffer.clear(); + } /** Data structure constructors */ XMLTree(){;}; -- 2.17.1