| OLD | NEW |
| 1 /* | 1 /* |
| 2 * testRegexp.c: simple module for testing regular expressions | 2 * testRegexp.c: simple module for testing regular expressions |
| 3 * | 3 * |
| 4 * See Copyright for the status of this software. | 4 * See Copyright for the status of this software. |
| 5 * | 5 * |
| 6 * Daniel Veillard <veillard@redhat.com> | 6 * Daniel Veillard <veillard@redhat.com> |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "libxml.h" | 9 #include "libxml.h" |
| 10 #ifdef LIBXML_REGEXP_ENABLED | 10 #ifdef LIBXML_REGEXP_ENABLED |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 input = fopen(filename, "r"); | 43 input = fopen(filename, "r"); |
| 44 if (input == NULL) { | 44 if (input == NULL) { |
| 45 xmlGenericError(xmlGenericErrorContext, | 45 xmlGenericError(xmlGenericErrorContext, |
| 46 "Cannot open %s for reading\n", filename); | 46 "Cannot open %s for reading\n", filename); |
| 47 return; | 47 return; |
| 48 } | 48 } |
| 49 while (fgets(expression, 4500, input) != NULL) { | 49 while (fgets(expression, 4500, input) != NULL) { |
| 50 len = strlen(expression); | 50 len = strlen(expression); |
| 51 len--; | 51 len--; |
| 52 » while ((len >= 0) && | 52 » while ((len >= 0) && |
| 53 ((expression[len] == '\n') || (expression[len] == '\t') || | 53 ((expression[len] == '\n') || (expression[len] == '\t') || |
| 54 (expression[len] == '\r') || (expression[len] == ' '))) len--; | 54 (expression[len] == '\r') || (expression[len] == ' '))) len--; |
| 55 » expression[len + 1] = 0; | 55 » expression[len + 1] = 0; |
| 56 if (len >= 0) { | 56 if (len >= 0) { |
| 57 if (expression[0] == '#') | 57 if (expression[0] == '#') |
| 58 continue; | 58 continue; |
| 59 if ((expression[0] == '=') && (expression[1] == '>')) { | 59 if ((expression[0] == '=') && (expression[1] == '>')) { |
| 60 char *pattern = &expression[2]; | 60 char *pattern = &expression[2]; |
| 61 | 61 |
| 62 if (comp != NULL) { | 62 if (comp != NULL) { |
| 63 xmlRegFreeRegexp(comp); | 63 xmlRegFreeRegexp(comp); |
| 64 comp = NULL; | 64 comp = NULL; |
| 65 } | 65 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 | 96 |
| 97 input = fopen(filename, "r"); | 97 input = fopen(filename, "r"); |
| 98 if (input == NULL) { | 98 if (input == NULL) { |
| 99 xmlGenericError(xmlGenericErrorContext, | 99 xmlGenericError(xmlGenericErrorContext, |
| 100 "Cannot open %s for reading\n", filename); | 100 "Cannot open %s for reading\n", filename); |
| 101 return; | 101 return; |
| 102 } | 102 } |
| 103 while (fgets(expression, 4500, input) != NULL) { | 103 while (fgets(expression, 4500, input) != NULL) { |
| 104 len = strlen(expression); | 104 len = strlen(expression); |
| 105 len--; | 105 len--; |
| 106 » while ((len >= 0) && | 106 » while ((len >= 0) && |
| 107 ((expression[len] == '\n') || (expression[len] == '\t') || | 107 ((expression[len] == '\n') || (expression[len] == '\t') || |
| 108 (expression[len] == '\r') || (expression[len] == ' '))) len--; | 108 (expression[len] == '\r') || (expression[len] == ' '))) len--; |
| 109 » expression[len + 1] = 0; | 109 » expression[len + 1] = 0; |
| 110 if (len >= 0) { | 110 if (len >= 0) { |
| 111 if (expression[0] == '#') | 111 if (expression[0] == '#') |
| 112 continue; | 112 continue; |
| 113 if ((expression[0] == '=') && (expression[1] == '>')) { | 113 if ((expression[0] == '=') && (expression[1] == '>')) { |
| 114 char *str = &expression[2]; | 114 char *str = &expression[2]; |
| 115 | 115 |
| 116 if (expr != NULL) { | 116 if (expr != NULL) { |
| 117 xmlExpFree(ctxt, expr); | 117 xmlExpFree(ctxt, expr); |
| 118 » » if (xmlExpCtxtNbNodes(ctxt) != 0) | 118 » » if (xmlExpCtxtNbNodes(ctxt) != 0) |
| 119 printf(" Parse/free of Expression leaked %d\n", | 119 printf(" Parse/free of Expression leaked %d\n", |
| 120 xmlExpCtxtNbNodes(ctxt)); | 120 xmlExpCtxtNbNodes(ctxt)); |
| 121 expr = NULL; | 121 expr = NULL; |
| 122 } | 122 } |
| 123 printf("Expression: %s\n", str) ; | 123 printf("Expression: %s\n", str) ; |
| 124 expr = xmlExpParse(ctxt, str); | 124 expr = xmlExpParse(ctxt, str); |
| 125 if (expr == NULL) { | 125 if (expr == NULL) { |
| 126 printf(" parsing Failed\n"); | 126 printf(" parsing Failed\n"); |
| 127 break; | 127 break; |
| 128 } | 128 } |
| 129 } else if (expr != NULL) { | 129 } else if (expr != NULL) { |
| 130 int expect = -1; | 130 int expect = -1; |
| 131 int nodes1, nodes2; | 131 int nodes1, nodes2; |
| 132 | 132 |
| 133 if (expression[0] == '0') | 133 if (expression[0] == '0') |
| 134 expect = 0; | 134 expect = 0; |
| 135 if (expression[0] == '1') | 135 if (expression[0] == '1') |
| 136 expect = 1; | 136 expect = 1; |
| 137 printf("Subexp: %s", expression + 2) ; | 137 printf("Subexp: %s", expression + 2) ; |
| 138 nodes1 = xmlExpCtxtNbNodes(ctxt); | 138 nodes1 = xmlExpCtxtNbNodes(ctxt); |
| 139 sub = xmlExpParse(ctxt, expression + 2); | 139 sub = xmlExpParse(ctxt, expression + 2); |
| 140 if (sub == NULL) { | 140 if (sub == NULL) { |
| 141 printf(" parsing Failed\n"); | 141 printf(" parsing Failed\n"); |
| 142 break; | 142 break; |
| 143 } else { | 143 } else { |
| 144 int ret; | 144 int ret; |
| 145 » » | 145 |
| 146 nodes2 = xmlExpCtxtNbNodes(ctxt); | 146 nodes2 = xmlExpCtxtNbNodes(ctxt); |
| 147 ret = xmlExpSubsume(ctxt, expr, sub); | 147 ret = xmlExpSubsume(ctxt, expr, sub); |
| 148 | 148 |
| 149 if ((expect == 1) && (ret == 1)) { | 149 if ((expect == 1) && (ret == 1)) { |
| 150 printf(" => accept, Ok\n"); | 150 printf(" => accept, Ok\n"); |
| 151 } else if ((expect == 0) && (ret == 0)) { | 151 } else if ((expect == 0) && (ret == 0)) { |
| 152 printf(" => reject, Ok\n"); | 152 printf(" => reject, Ok\n"); |
| 153 } else if ((expect == 1) && (ret == 0)) { | 153 } else if ((expect == 1) && (ret == 0)) { |
| 154 printf(" => reject, Failed\n"); | 154 printf(" => reject, Failed\n"); |
| 155 } else if ((expect == 0) && (ret == 1)) { | 155 } else if ((expect == 0) && (ret == 1)) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 167 printf(" Parse/free leaked %d\n", | 167 printf(" Parse/free leaked %d\n", |
| 168 xmlExpCtxtNbNodes(ctxt) - nodes1); | 168 xmlExpCtxtNbNodes(ctxt) - nodes1); |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 | 171 |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 } | 174 } |
| 175 if (expr != NULL) { | 175 if (expr != NULL) { |
| 176 xmlExpFree(ctxt, expr); | 176 xmlExpFree(ctxt, expr); |
| 177 » if (xmlExpCtxtNbNodes(ctxt) != 0) | 177 » if (xmlExpCtxtNbNodes(ctxt) != 0) |
| 178 printf(" Parse/free of Expression leaked %d\n", | 178 printf(" Parse/free of Expression leaked %d\n", |
| 179 xmlExpCtxtNbNodes(ctxt)); | 179 xmlExpCtxtNbNodes(ctxt)); |
| 180 } | 180 } |
| 181 fclose(input); | 181 fclose(input); |
| 182 } | 182 } |
| 183 | 183 |
| 184 static void | 184 static void |
| 185 testReduce(xmlExpCtxtPtr ctxt, xmlExpNodePtr expr, const char *tst) { | 185 testReduce(xmlExpCtxtPtr ctxt, xmlExpNodePtr expr, const char *tst) { |
| 186 xmlBufferPtr xmlExpBuf; | 186 xmlBufferPtr xmlExpBuf; |
| 187 xmlExpNodePtr sub, deriv; | 187 xmlExpNodePtr sub, deriv; |
| 188 xmlExpBuf = xmlBufferCreate(); | 188 xmlExpBuf = xmlBufferCreate(); |
| 189 | 189 |
| 190 sub = xmlExpParse(ctxt, tst); | 190 sub = xmlExpParse(ctxt, tst); |
| 191 if (sub == NULL) { | 191 if (sub == NULL) { |
| 192 printf("Subset %s failed to parse\n", tst); | 192 printf("Subset %s failed to parse\n", tst); |
| 193 return; | 193 return; |
| 194 } | 194 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 206 printf("Resulting nillable derivation: %s\n", | 206 printf("Resulting nillable derivation: %s\n", |
| 207 (const char *) xmlBufferContent(xmlExpBuf)); | 207 (const char *) xmlBufferContent(xmlExpBuf)); |
| 208 else | 208 else |
| 209 printf("Resulting derivation: %s\n", | 209 printf("Resulting derivation: %s\n", |
| 210 (const char *) xmlBufferContent(xmlExpBuf)); | 210 (const char *) xmlBufferContent(xmlExpBuf)); |
| 211 xmlExpFree(ctxt, deriv); | 211 xmlExpFree(ctxt, deriv); |
| 212 } | 212 } |
| 213 xmlExpFree(ctxt, sub); | 213 xmlExpFree(ctxt, sub); |
| 214 } | 214 } |
| 215 | 215 |
| 216 static void | 216 static void |
| 217 exprDebug(xmlExpCtxtPtr ctxt, xmlExpNodePtr expr) { | 217 exprDebug(xmlExpCtxtPtr ctxt, xmlExpNodePtr expr) { |
| 218 xmlBufferPtr xmlExpBuf; | 218 xmlBufferPtr xmlExpBuf; |
| 219 xmlExpNodePtr deriv; | 219 xmlExpNodePtr deriv; |
| 220 const char *list[40]; | 220 const char *list[40]; |
| 221 int ret; | 221 int ret; |
| 222 | 222 |
| 223 xmlExpBuf = xmlBufferCreate(); | 223 xmlExpBuf = xmlBufferCreate(); |
| 224 | 224 |
| 225 if (expr == NULL) { | 225 if (expr == NULL) { |
| 226 printf("Failed to parse\n"); | 226 printf("Failed to parse\n"); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 return(0); | 393 return(0); |
| 394 } | 394 } |
| 395 | 395 |
| 396 #else | 396 #else |
| 397 #include <stdio.h> | 397 #include <stdio.h> |
| 398 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { | 398 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
| 399 printf("%s : Regexp support not compiled in\n", argv[0]); | 399 printf("%s : Regexp support not compiled in\n", argv[0]); |
| 400 return(0); | 400 return(0); |
| 401 } | 401 } |
| 402 #endif /* LIBXML_REGEXP_ENABLED */ | 402 #endif /* LIBXML_REGEXP_ENABLED */ |
| OLD | NEW |