More fixing in the printing code
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Wed, 28 Apr 2010 01:49:51 +0000 (01:49 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Wed, 28 Apr 2010 01:49:51 +0000 (01:49 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@796 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp
XMLTree.h

index 06aaba0..9be500e 100644 (file)
@@ -107,6 +107,7 @@ XMLTree::XMLTree( pb * const par, uint npar,  vector<string> * const TN,  TagIdM
                  uint *empty_texts_bmp, TagType *tags,\r
                  TextCollection * const TC, bool dis_tc)\r
  {\r
+   buffer = 0;\r
     // creates the data structure for the tree topology\r
     Par = (bp *)umalloc(sizeof(bp));\r
     STARTTIMER();\r
@@ -248,6 +249,7 @@ void XMLTree::Save(int fd)
 // a pointer to the loaded data structure\r
 XMLTree *XMLTree::Load(int fd, bool load_tc,int sample_factor) \r
  {\r
+\r
     FILE *fp;\r
     char buffer[1024];\r
     XMLTree *XML_Tree;\r
@@ -947,7 +949,8 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){
   \r
   int newfd = dup(fd);\r
   stream = fdopen(newfd,"wa");\r
-\r
+  if (buffer == 0)\r
+    buffer = new string();\r
 \r
   FILE* fp = stream;\r
   treeNode fin = fast_find_close(Par,x);\r
@@ -970,8 +973,7 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){
    if (first_idx != NULLT)\r
    current_text = GetText(MyText(first_idx));\r
    int read = 0;\r
-\r
- std::stack<uchar*> st;\r
+   std::vector<uchar*> st;\r
  while (n <= fin){\r
    if (fast_inspect(Par,n)){\r
      if (tag == PCDATA_TAG_ID  ) {       \r
@@ -987,13 +989,12 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){
       \r
      }\r
      else {\r
-\r
        myfputc('<',fp);\r
        tagstr = (uchar*) GetTagNameByRef(tag);\r
        myfputs((const char*) tagstr ,fp);\r
        n++;\r
        if (fast_inspect(Par,n)) {\r
-        st.push(tagstr);\r
+        st.push_back(tagstr);\r
         tag = Tag(n);\r
         if (tag == ATTRIBUTE_TAG_ID){\r
           n++;\r
@@ -1001,10 +1002,11 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){
           while (fast_inspect(Par,n)){\r
             if (no_text) {\r
               myfputc('<',fp);\r
-              myfputs((const char*) &(GetTagNameByRef(Tag(n))[3]),fp);\r
+              const uchar * tmp = &(GetTagNameByRef(Tag(n))[3]);\r
+              myfputs((const char*) tmp,fp);\r
               myfputc('>',fp);\r
               myfputs("<$@/></",fp);\r
-              myfputs((const char*) &(GetTagNameByRef(Tag(n))[3]),fp);\r
+              myfputs((const char*) tmp,fp);\r
               myfputc('>',fp);\r
               n+= 4;\r
             }\r
@@ -1040,14 +1042,14 @@ void XMLTree::Print(int fd,treeNode x, bool no_text){
    else\r
      do {\r
        myfputs("</",fp);\r
-       myfputs((const char*)st.top(),fp);\r
+       myfputs((const char*)st.back(),fp);\r
        myfputc('>', fp);\r
-       st.pop();\r
+       st.pop_back();\r
        n++;\r
      }while (!fast_inspect(Par,n) && !st.empty());\r
    tag=Tag(n);\r
  };\r
- myfputc('\n',fp);\r
//myfputc('\n',fp);\r
  mybufferflush(fp);\r
  fflush(fp);\r
  fclose(fp);\r
index c2a0210..d0a5c73 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -142,28 +142,28 @@ class XMLTree {
    \r
    FILE* stream;\r
    int   stream_fd; \r
-   string buffer;\r
+   string buffer;\r
    void myfputs(const char* s, FILE * fp){\r
-     buffer.append(s);\r
-     if (buffer.size() >= 1000000){\r
-       fputs(buffer.c_str(),fp);\r
-       buffer.clear();\r
+     buffer->append(s);\r
+     if (buffer->size() >= 100000){\r
+       fputs(buffer->c_str(),fp);\r
+       buffer->clear();\r
      };\r
 \r
    }\r
    void myfputc(const char c, FILE*fp){\r
-     buffer.append(1,c);\r
-     if (buffer.size() >= 1000000){\r
-       fputs(buffer.c_str(),fp);\r
-       buffer.clear();\r
+     buffer->append(1,c);\r
+     if (buffer->size() >= 100000){\r
+       fputs(buffer->c_str(),fp);\r
+       buffer->clear();\r
      };\r
    }\r
    void mybufferflush(FILE* fp){\r
-     fputs(buffer.c_str(), fp);\r
-     buffer.clear();\r
+     fputs(buffer->c_str(), fp);\r
+     buffer->clear();\r
    }\r
    /** Data structure constructors */\r
-   XMLTree(){;};\r
+   XMLTree(){ buffer = 0;};\r
 \r
    // non const pointer are freed by this method.\r
   XMLTree( pb * const par, uint npar,  vector<string> * const TN,  TagIdMap * const tim, uint *empty_texts_bmp, TagType *tags,\r