Fix bug in xml_tree::print (which would pop the printing stack one time
authorKim Nguyễn <kn@lri.fr>
Thu, 12 Apr 2012 14:31:05 +0000 (16:31 +0200)
committerKim Nguyễn <kn@lri.fr>
Thu, 12 Apr 2012 14:31:05 +0000 (16:31 +0200)
too many).

xml-tree.cpp
xml-tree.hpp

index 3e32ffd..df7efe2 100644 (file)
@@ -238,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,
@@ -409,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());
@@ -421,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);
@@ -492,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<std::string>();
     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);
@@ -578,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);
index 950f0ef..debabe9 100644 (file)
@@ -111,7 +111,7 @@ public:
   //I/O functions
   void save(int, char*);
   static xml_tree* load(int, char*, bool, int);
-  void print(int, node_t, bool no_text=false);
+  void print(node_t, int, bool no_text=false);
   void flush(int);
 
 private: