fixed implementation for | added a specific regression test Daniel

* pattern.c xmllint.c: fixed implementation for |
* test/pattern/conj.* result/pattern/conj: added a specific regression
  test
Daniel
diff --git a/ChangeLog b/ChangeLog
index 866b057..1f2a9e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Feb  6 00:17:57 CET 2005 Daniel Veillard <daniel@veillard.com>
+
+	* pattern.c xmllint.c: fixed implementation for |
+	* test/pattern/conj.* result/pattern/conj: added a specific regression
+	  test
+
 Sat Feb  5 18:36:56 CET 2005 Daniel Veillard <daniel@veillard.com>
 
 	* pattern.c: first implementation for | support
diff --git a/pattern.c b/pattern.c
index c28bf29..c0ad59c 100644
--- a/pattern.c
+++ b/pattern.c
@@ -19,8 +19,6 @@
  *   currently push(NULL, NULL) means a reset of the streaming context
  *   and indicating we are on / (the document node), probably need
  *   something similar for .
- * - handling of disjunction "pattern1 | pattern2" mean needed to build
- *   and check a list internally
  * - get rid of the "compile" starting with lowercase
  * - get rid of the Strdup/Strndup in case of dictionary
  */
@@ -1303,10 +1301,14 @@
  */
 void
 xmlFreeStreamCtxt(xmlStreamCtxtPtr stream) {
-    if (stream != NULL) {
+    xmlStreamCtxtPtr next;
+
+    while (stream != NULL) {
+        next = stream->next;
         if (stream->states != NULL)
 	    xmlFree(stream->states);
         xmlFree(stream);
+	stream = next;
     }
 }
 
@@ -1367,6 +1369,9 @@
               const xmlChar *name, const xmlChar *ns) {
     int ret = 0, err = 0, tmp, i, m, match, step, desc, final;
     xmlStreamCompPtr comp;
+#ifdef DEBUG_STREAMING
+    xmlStreamCtxtPtr orig = stream;
+#endif
 
     if ((stream == NULL) || (stream->nbState < 0))
         return(-1);
@@ -1382,8 +1387,10 @@
 		    err++;
 		if (comp->steps[tmp].flags & XML_STREAM_STEP_FINAL)
 		    ret = 1;
+		stream = stream->next;
 		continue; /* while */
 	    }
+	    stream = stream->next;
 	    continue; /* while */
 	}
 	/*
@@ -1486,11 +1493,11 @@
         stream = stream->next;
     } /* while stream != NULL */
     
-#ifdef DEBUG_STREAMING
-    xmlDebugStreamCtxt(stream, ret);
-#endif
     if (err > 0)
         ret = -1;
+#ifdef DEBUG_STREAMING
+    xmlDebugStreamCtxt(orig, ret);
+#endif
     return(ret);
 }
 
@@ -1560,8 +1567,8 @@
         return(NULL);
 
     start = pattern;
+    or = start;
     while (*or != 0) {
-	or = start;
 	tmp = NULL;
 	while ((*or != 0) && (*or != '|')) or++;
         if (*or == 0)
@@ -1591,11 +1598,11 @@
 	xmlStreamCompile(cur);
 	if (xmlReversePattern(cur) < 0)
 	    goto error;
-	start = or;
 	if (tmp != NULL) {
 	    xmlFree(tmp);
 	    tmp = NULL;
 	}
+	start = or;
     }
     return(ret);
 error:
diff --git a/result/pattern/conj b/result/pattern/conj
new file mode 100644
index 0000000..616450b
--- /dev/null
+++ b/result/pattern/conj
@@ -0,0 +1,47 @@
+Node /a matches pattern a|b
+Node /a/b matches pattern a|b
+Node /a/b/c[1]/b matches pattern a|b
+Node /a/b/c[2]/b matches pattern a|b
+Node /a/b/c[2]/c/b matches pattern a|b
+Node /a/c/b matches pattern a|b
+Node /a matches pattern a|c
+Node /a/b/c[1] matches pattern a|c
+Node /a/b/c[2] matches pattern a|c
+Node /a/b/c[2]/c matches pattern a|c
+Node /a/c matches pattern a|c
+Node /a/b matches pattern b|c
+Node /a/b/c[1] matches pattern b|c
+Node /a/b/c[1]/b matches pattern b|c
+Node /a/b/c[2] matches pattern b|c
+Node /a/b/c[2]/b matches pattern b|c
+Node /a/b/c[2]/c matches pattern b|c
+Node /a/b/c[2]/c/b matches pattern b|c
+Node /a/c matches pattern b|c
+Node /a/c/b matches pattern b|c
+Node /a matches pattern a|b|c
+Node /a/b matches pattern a|b|c
+Node /a/b/c[1] matches pattern a|b|c
+Node /a/b/c[1]/b matches pattern a|b|c
+Node /a/b/c[2] matches pattern a|b|c
+Node /a/b/c[2]/b matches pattern a|b|c
+Node /a/b/c[2]/c matches pattern a|b|c
+Node /a/b/c[2]/c/b matches pattern a|b|c
+Node /a/c matches pattern a|b|c
+Node /a/c/b matches pattern a|b|c
+Node /a matches pattern /a|b
+Node /a/b matches pattern /a|b
+Node /a/b/c[1]/b matches pattern /a|b
+Node /a/b/c[2]/b matches pattern /a|b
+Node /a/b/c[2]/c/b matches pattern /a|b
+Node /a/c/b matches pattern /a|b
+Node /a matches pattern b|/a
+Node /a/b matches pattern b|/a
+Node /a/b/c[1]/b matches pattern b|/a
+Node /a/b/c[2]/b matches pattern b|/a
+Node /a/b/c[2]/c/b matches pattern b|/a
+Node /a/c/b matches pattern b|/a
+Node /a/b/c[1] matches pattern a//c|b//c
+Node /a/b/c[2] matches pattern a//c|b//c
+Node /a/b/c[2]/c matches pattern a//c|b//c
+Node /a/c matches pattern a//c|b//c
+Node /a matches pattern d|e|f|g|h|a
diff --git a/test/pattern/conj.pat b/test/pattern/conj.pat
new file mode 100644
index 0000000..ca80a06
--- /dev/null
+++ b/test/pattern/conj.pat
@@ -0,0 +1,8 @@
+a|b
+a|c
+b|c
+a|b|c
+/a|b
+b|/a
+a//c|b//c
+d|e|f|g|h|a
diff --git a/test/pattern/conj.xml b/test/pattern/conj.xml
new file mode 100644
index 0000000..c1c770e
--- /dev/null
+++ b/test/pattern/conj.xml
@@ -0,0 +1,13 @@
+<a>
+  <b>
+    <c><b/></c>
+    <c>
+      <b/>
+      <c><b/></c>
+    </c>
+  </b>
+  <c>
+     <b>
+     </b>
+  </c>
+</a>
diff --git a/xmllint.c b/xmllint.c
index 94c66f7..dea8d5b 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -1062,6 +1062,17 @@
 	    pattern = NULL;
 	}
     }
+    if (patternc != NULL) {
+        patstream = xmlPatternGetStreamCtxt(patternc);
+	if (patstream != NULL) {
+	    ret = xmlStreamPush(patstream, NULL, NULL);
+	    if (ret < 0) {
+		fprintf(stderr, "xmlStreamPush() failure\n");
+		xmlFreeStreamCtxt(patstream);
+		patstream = NULL;
+            }
+	}
+    }
 #endif /* LIBXML_PATTERN_ENABLED */
     reader = xmlReaderWalker(doc);
     if (reader != NULL) {
@@ -1090,6 +1101,12 @@
 	fprintf(stderr, "Failed to crate a reader from the document\n");
 	progresult = XMLLINT_ERR_UNCLASS;
     }
+#ifdef LIBXML_PATTERN_ENABLED
+    if (patstream != NULL) {
+	xmlFreeStreamCtxt(patstream);
+	patstream = NULL;
+    }
+#endif
 }
 #endif /* LIBXML_READER_ENABLED */