Permalink
Browse files

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
  • Loading branch information...
1 parent f1f08cf commit 2b2e02d6bb15ae7c4dc14c1a468158f0b8c3f367 Daniel Veillard committed Feb 5, 2005
Showing with 106 additions and 8 deletions.
  1. +6 −0 ChangeLog
  2. +15 −8 pattern.c
  3. +47 −0 result/pattern/conj
  4. +8 −0 test/pattern/conj.pat
  5. +13 −0 test/pattern/conj.xml
  6. +17 −0 xmllint.c
View
@@ -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
View
@@ -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 @@ xmlNewStreamCtxt(xmlStreamCompPtr stream) {
*/
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 @@ xmlStreamPush(xmlStreamCtxtPtr stream,
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 @@ xmlStreamPush(xmlStreamCtxtPtr stream,
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 @@ xmlStreamPush(xmlStreamCtxtPtr stream,
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 @@ xmlPatterncompile(const xmlChar *pattern, xmlDict *dict,
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 @@ xmlPatterncompile(const xmlChar *pattern, xmlDict *dict,
xmlStreamCompile(cur);
if (xmlReversePattern(cur) < 0)
goto error;
- start = or;
if (tmp != NULL) {
xmlFree(tmp);
tmp = NULL;
}
+ start = or;
}
return(ret);
error:
View
@@ -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
View
@@ -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
View
@@ -0,0 +1,13 @@
+<a>
+ <b>
+ <c><b/></c>
+ <c>
+ <b/>
+ <c><b/></c>
+ </c>
+ </b>
+ <c>
+ <b>
+ </b>
+ </c>
+</a>
View
@@ -1062,6 +1062,17 @@ static void walkDoc(xmlDocPtr doc) {
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 @@ static void walkDoc(xmlDocPtr doc) {
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 */

0 comments on commit 2b2e02d

Please sign in to comment.