added first test for the patterns a few fixes Daniel

* Makefile.am configure.in result/pattern/simple
  test/pattern/simple.*: added first test for the patterns
* pattern.c xmllint.c: a few fixes
Daniel
diff --git a/ChangeLog b/ChangeLog
index 23d96d2..d875ab5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Sun Jan 30 23:35:19 CET 2005 Daniel Veillard <daniel@veillard.com>
+
+	* Makefile.am configure.in result/pattern/simple 
+	  test/pattern/simple.*: added first test for the patterns
+	* pattern.c xmllint.c: a few fixes
+
 Sun Jan 30 19:27:23 CET 2005 Daniel Veillard <daniel@veillard.com>
 
 	* pattern.c include/libxml/pattern.h xmllint.c: added a 
diff --git a/Makefile.am b/Makefile.am
index 20fcec9..d354404 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -148,7 +148,7 @@
 
 testall : tests SVGtests SAXtests
 
-tests: XMLtests XMLenttests NStests IDtests Errtests APItests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@  @TEST_VALID@ URItests @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@ @TEST_MODULES@
+tests: XMLtests XMLenttests NStests IDtests Errtests APItests @READER_TEST@ @TEST_SAX@ @TEST_PUSH@ @TEST_HTML@ @TEST_PHTML@  @TEST_VALID@ URItests @TEST_PATTERN@ @TEST_XPATH@ @TEST_XPTR@ @TEST_XINCLUDE@ @TEST_C14N@ @TEST_DEBUG@ @TEST_CATALOG@ @TEST_REGEXPS@ @TEST_SCHEMAS@ @TEST_THREADS@ Timingtests @TEST_VTIME@ @PYTHON_TESTS@ @TEST_MODULES@
 	@(if [ "@PYTHON_SUBDIR@" != "" ] ; then cd python ; \
 	    $(MAKE) MAKEFLAGS+=--silent tests ; fi)
 	@(cd doc/examples ; $(MAKE) MAKEFLAGS+=--silent tests)
@@ -1001,6 +1001,30 @@
 	  fi)
 	@(if [ -x $(PYTHON) -a -d xstc ] ; then cd xstc ; $(MAKE) CHECKER="$(CHECKER)" MAKEFLAGS+=--silent pytests ; fi)
 
+Patterntests: xmllint$(EXEEXT)
+	@(echo > .memdump)
+	@echo "## Pattern regression tests"
+	-@(for i in $(srcdir)/test/pattern/*.pat ; do \
+	  name=`basename $$i .pat`; \
+	  if [ -f $(srcdir)/test/pattern/$$name.xml ] ; then \
+	  if [ ! -f $(srcdir)/result/pattern/$$name ] ; then \
+	      rm -f result.$$name ; \
+	      echo New test file $$name ; \
+	      for pat in `cat $$i` ; do \
+	      $(CHECKER) $(top_builddir)/xmllint --stream --pattern $$pat $(srcdir)/test/pattern/$$name.xml >> $(srcdir)/result/pattern/$$name ; \
+	      grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0";\
+	      done ;\
+	  else \
+	      rm -f result.$$name ; \
+	      lst=`cat $$i` ; \
+	      log=`for pat in $$lst ; do $(CHECKER) $(top_builddir)/xmllint --stream --pattern $$pat $(srcdir)/test/pattern/$$name.xml 2>&1 >> result.$$name ; \
+	      grep "MORY ALLO" .memdump  | grep -v "MEMORY ALLOCATED : 0";\
+	      done ;\
+	      diff $(srcdir)/result/pattern/$$name result.$$name` ; \
+	      if [ -n "$$log" ] ; then echo $$name result ; echo $$log ; fi ; \
+	      rm result.$$name ; \
+	  fi ; fi ; done ;)
+
 ModuleTests: testModule$(EXEEXT) testdso.la
 	@echo "## Module tests"
 	@(./testModule$(EXEEXT))
diff --git a/configure.in b/configure.in
index b3cd424..61a8eb0 100644
--- a/configure.in
+++ b/configure.in
@@ -866,13 +866,13 @@
 if test "$with_pattern" = "no" ; then
     echo Disabling the xmlPattern parsing interface
     WITH_PATTERN=0
-    PATTERN_TEST=
+    TEST_PATTERN=
 else    
     WITH_PATTERN=1
-    PATTERN_TEST=Patterntests
+    TEST_PATTERN=Patterntests
 fi
 AC_SUBST(WITH_PATTERN)
-AC_SUBST(PATTERN_TEST)
+AC_SUBST(TEST_PATTERN)
 
 if test "$with_sax1" = "no" ; then
     echo Disabling the older SAX1 interface
diff --git a/pattern.c b/pattern.c
index fb6466b..3ad56a1 100644
--- a/pattern.c
+++ b/pattern.c
@@ -11,6 +11,20 @@
  * daniel@veillard.com
  */
 
+/*
+ * TODO:
+ * - compilation flags to check for specific syntaxes
+ *   using flags of xmlPatterncompile()
+ * - making clear how pattern starting with / or . need to be handled,
+ *   currently push(NULL, NULL) means a reset of the streaming context
+ *   and indicating we are on / (the document node), probably need
+ *   something similar for .
+ * - xmlPatterncompile support of namespaces arguments, I'm not sure
+ *   it's implemented and definitely not tested
+ * - handling of disjunction "pattern1 | pattern2" mean needed to build
+ *   and check a list internally
+ */
+
 #define IN_LIBXML
 #include "libxml.h"
 
@@ -1348,7 +1362,6 @@
 	    }
 	} else if (!(comp->steps[step].flags & XML_STREAM_STEP_DESC)) {
 	    /* didn't match, discard */
-	    printf("discard %d\n", i); 
 	    stream->states[2 * i] = -1;
 	}
     }
diff --git a/result/pattern/simple b/result/pattern/simple
new file mode 100644
index 0000000..5710b5c
--- /dev/null
+++ b/result/pattern/simple
@@ -0,0 +1,12 @@
+Node /a matches pattern a
+Node /a/b matches pattern b
+Node /a/b matches pattern b
+Node /a matches pattern /a
+Node /a/b matches pattern a/b
+Node /a/b/c matches pattern a/b/c
+Node /a matches pattern //a
+Node /a/b matches pattern //b
+Node /a/b/c matches pattern //c
+Node /a/b matches pattern a//b
+Node /a/b/c matches pattern a//c
+Node /a/b/c matches pattern b//c
diff --git a/test/pattern/simple.pat b/test/pattern/simple.pat
new file mode 100644
index 0000000..1b298ae
--- /dev/null
+++ b/test/pattern/simple.pat
@@ -0,0 +1,15 @@
+a
+b
+b
+/a
+/b
+/c
+a/b
+a/b/c
+//a
+//b
+//c
+a//b
+a//c
+b//c
+
diff --git a/test/pattern/simple.xml b/test/pattern/simple.xml
new file mode 100644
index 0000000..16ac6c2
--- /dev/null
+++ b/test/pattern/simple.xml
@@ -0,0 +1,5 @@
+<a>
+  <b>
+    <c d="attr">text</c>
+  </b>
+</a>
diff --git a/xmllint.c b/xmllint.c
index 993c881..52e05eb 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -865,8 +865,6 @@
 		    fprintf(stderr,
 		            "  pattern %s node %s\n",
 			    pattern, path);
-		    if (path != NULL)
-		        xmlFree(path);
 		}
 		
 
@@ -879,6 +877,8 @@
 		}
 	    }
 	}
+	if (path != NULL)
+	    xmlFree(path);
     }
 #endif
 }