More fixing in the printing code
[SXSI/XMLTree.git] / XMLTree.cpp
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