| OLD | NEW |
| 1 /* | 1 /* |
| 2 * testSAX.c : a small tester program for parsing using the SAX API. | 2 * testSAX.c : a small tester program for parsing using the SAX API. |
| 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.com | 6 * daniel@veillard.com |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "libxml.h" | 9 #include "libxml.h" |
| 10 | 10 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 static int timing = 0; | 64 static int timing = 0; |
| 65 | 65 |
| 66 /* | 66 /* |
| 67 * Timing routines. | 67 * Timing routines. |
| 68 */ | 68 */ |
| 69 /* | 69 /* |
| 70 * Internal timing routines to remove the necessity to have unix-specific | 70 * Internal timing routines to remove the necessity to have unix-specific |
| 71 * function calls | 71 * function calls |
| 72 */ | 72 */ |
| 73 | 73 |
| 74 #ifndef HAVE_GETTIMEOFDAY | 74 #ifndef HAVE_GETTIMEOFDAY |
| 75 #ifdef HAVE_SYS_TIMEB_H | 75 #ifdef HAVE_SYS_TIMEB_H |
| 76 #ifdef HAVE_SYS_TIME_H | 76 #ifdef HAVE_SYS_TIME_H |
| 77 #ifdef HAVE_FTIME | 77 #ifdef HAVE_FTIME |
| 78 | 78 |
| 79 static int | 79 static int |
| 80 my_gettimeofday(struct timeval *tvp, void *tzp) | 80 my_gettimeofday(struct timeval *tvp, void *tzp) |
| 81 { | 81 { |
| 82 struct timeb timebuffer; | 82 struct timeb timebuffer; |
| 83 | 83 |
| 84 ftime(&timebuffer); | 84 ftime(&timebuffer); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. | 361 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. |
| 362 */ | 362 */ |
| 363 static xmlParserInputPtr | 363 static xmlParserInputPtr |
| 364 resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xm
lChar *systemId) | 364 resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xm
lChar *systemId) |
| 365 { | 365 { |
| 366 callbacks++; | 366 callbacks++; |
| 367 if (quiet) | 367 if (quiet) |
| 368 return(NULL); | 368 return(NULL); |
| 369 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ | 369 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
| 370 | 370 |
| 371 | 371 |
| 372 fprintf(stdout, "SAX.resolveEntity("); | 372 fprintf(stdout, "SAX.resolveEntity("); |
| 373 if (publicId != NULL) | 373 if (publicId != NULL) |
| 374 fprintf(stdout, "%s", (char *)publicId); | 374 fprintf(stdout, "%s", (char *)publicId); |
| 375 else | 375 else |
| 376 fprintf(stdout, " "); | 376 fprintf(stdout, " "); |
| 377 if (systemId != NULL) | 377 if (systemId != NULL) |
| 378 fprintf(stdout, ", %s)\n", (char *)systemId); | 378 fprintf(stdout, ", %s)\n", (char *)systemId); |
| 379 else | 379 else |
| 380 fprintf(stdout, ", )\n"); | 380 fprintf(stdout, ", )\n"); |
| 381 /********* | 381 /********* |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 if (quiet) | 421 if (quiet) |
| 422 return(NULL); | 422 return(NULL); |
| 423 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); | 423 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); |
| 424 return(NULL); | 424 return(NULL); |
| 425 } | 425 } |
| 426 | 426 |
| 427 | 427 |
| 428 /** | 428 /** |
| 429 * entityDeclDebug: | 429 * entityDeclDebug: |
| 430 * @ctxt: An XML parser context | 430 * @ctxt: An XML parser context |
| 431 * @name: the entity name | 431 * @name: the entity name |
| 432 * @type: the entity type | 432 * @type: the entity type |
| 433 * @publicId: The public ID of the entity | 433 * @publicId: The public ID of the entity |
| 434 * @systemId: The system ID of the entity | 434 * @systemId: The system ID of the entity |
| 435 * @content: the entity value (without processing). | 435 * @content: the entity value (without processing). |
| 436 * | 436 * |
| 437 * An entity definition has been parsed | 437 * An entity definition has been parsed |
| 438 */ | 438 */ |
| 439 static void | 439 static void |
| 440 entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, | 440 entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
| 441 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) | 441 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
| 442 { | 442 { |
| 443 const xmlChar *nullstr = BAD_CAST "(null)"; | 443 const xmlChar *nullstr = BAD_CAST "(null)"; |
| 444 /* not all libraries handle printing null pointers nicely */ | 444 /* not all libraries handle printing null pointers nicely */ |
| 445 if (publicId == NULL) | 445 if (publicId == NULL) |
| 446 publicId = nullstr; | 446 publicId = nullstr; |
| 447 if (systemId == NULL) | 447 if (systemId == NULL) |
| 448 systemId = nullstr; | 448 systemId = nullstr; |
| 449 if (content == NULL) | 449 if (content == NULL) |
| 450 content = (xmlChar *)nullstr; | 450 content = (xmlChar *)nullstr; |
| 451 callbacks++; | 451 callbacks++; |
| 452 if (quiet) | 452 if (quiet) |
| 453 return; | 453 return; |
| 454 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", | 454 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", |
| 455 name, type, publicId, systemId, content); | 455 name, type, publicId, systemId, content); |
| 456 } | 456 } |
| 457 | 457 |
| 458 /** | 458 /** |
| 459 * attributeDeclDebug: | 459 * attributeDeclDebug: |
| 460 * @ctxt: An XML parser context | 460 * @ctxt: An XML parser context |
| 461 * @name: the attribute name | 461 * @name: the attribute name |
| 462 * @type: the attribute type | 462 * @type: the attribute type |
| 463 * | 463 * |
| 464 * An attribute definition has been parsed | 464 * An attribute definition has been parsed |
| 465 */ | 465 */ |
| 466 static void | 466 static void |
| 467 attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem, | 467 attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar * elem, |
| 468 const xmlChar * name, int type, int def, | 468 const xmlChar * name, int type, int def, |
| 469 const xmlChar * defaultValue, xmlEnumerationPtr tree) | 469 const xmlChar * defaultValue, xmlEnumerationPtr tree) |
| 470 { | 470 { |
| 471 callbacks++; | 471 callbacks++; |
| 472 if (quiet) | 472 if (quiet) |
| 473 return; | 473 return; |
| 474 if (defaultValue == NULL) | 474 if (defaultValue == NULL) |
| 475 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n", | 475 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, NULL, ...)\n", |
| 476 elem, name, type, def); | 476 elem, name, type, def); |
| 477 else | 477 else |
| 478 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", | 478 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", |
| 479 elem, name, type, def, defaultValue); | 479 elem, name, type, def, defaultValue); |
| 480 xmlFreeEnumeration(tree); | 480 xmlFreeEnumeration(tree); |
| 481 } | 481 } |
| 482 | 482 |
| 483 /** | 483 /** |
| 484 * elementDeclDebug: | 484 * elementDeclDebug: |
| 485 * @ctxt: An XML parser context | 485 * @ctxt: An XML parser context |
| 486 * @name: the element name | 486 * @name: the element name |
| 487 * @type: the element type | 487 * @type: the element type |
| 488 * @content: the element value (without processing). | 488 * @content: the element value (without processing). |
| 489 * | 489 * |
| 490 * An element definition has been parsed | 490 * An element definition has been parsed |
| 491 */ | 491 */ |
| 492 static void | 492 static void |
| 493 elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, | 493 elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
| 494 xmlElementContentPtr content ATTRIBUTE_UNUSED) | 494 xmlElementContentPtr content ATTRIBUTE_UNUSED) |
| 495 { | 495 { |
| 496 callbacks++; | 496 callbacks++; |
| 497 if (quiet) | 497 if (quiet) |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 output[i] = 0; | 663 output[i] = 0; |
| 664 | 664 |
| 665 fprintf(stdout, "SAX.characters(%s, %d)\n", output, len); | 665 fprintf(stdout, "SAX.characters(%s, %d)\n", output, len); |
| 666 } | 666 } |
| 667 | 667 |
| 668 /** | 668 /** |
| 669 * referenceDebug: | 669 * referenceDebug: |
| 670 * @ctxt: An XML parser context | 670 * @ctxt: An XML parser context |
| 671 * @name: The entity name | 671 * @name: The entity name |
| 672 * | 672 * |
| 673 * called when an entity reference is detected. | 673 * called when an entity reference is detected. |
| 674 */ | 674 */ |
| 675 static void | 675 static void |
| 676 referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) | 676 referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
| 677 { | 677 { |
| 678 callbacks++; | 678 callbacks++; |
| 679 if (quiet) | 679 if (quiet) |
| 680 return; | 680 return; |
| 681 fprintf(stdout, "SAX.reference(%s)\n", name); | 681 fprintf(stdout, "SAX.reference(%s)\n", name); |
| 682 } | 682 } |
| 683 | 683 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 fprintf(stdout, "SAX.startElementNs(%s", (char *) localname); | 899 fprintf(stdout, "SAX.startElementNs(%s", (char *) localname); |
| 900 if (prefix == NULL) | 900 if (prefix == NULL) |
| 901 fprintf(stdout, ", NULL"); | 901 fprintf(stdout, ", NULL"); |
| 902 else | 902 else |
| 903 fprintf(stdout, ", %s", (char *) prefix); | 903 fprintf(stdout, ", %s", (char *) prefix); |
| 904 if (URI == NULL) | 904 if (URI == NULL) |
| 905 fprintf(stdout, ", NULL"); | 905 fprintf(stdout, ", NULL"); |
| 906 else | 906 else |
| 907 fprintf(stdout, ", '%s'", (char *) URI); | 907 fprintf(stdout, ", '%s'", (char *) URI); |
| 908 fprintf(stdout, ", %d", nb_namespaces); | 908 fprintf(stdout, ", %d", nb_namespaces); |
| 909 | 909 |
| 910 if (namespaces != NULL) { | 910 if (namespaces != NULL) { |
| 911 for (i = 0;i < nb_namespaces * 2;i++) { | 911 for (i = 0;i < nb_namespaces * 2;i++) { |
| 912 fprintf(stdout, ", xmlns"); | 912 fprintf(stdout, ", xmlns"); |
| 913 if (namespaces[i] != NULL) | 913 if (namespaces[i] != NULL) |
| 914 fprintf(stdout, ":%s", namespaces[i]); | 914 fprintf(stdout, ":%s", namespaces[i]); |
| 915 i++; | 915 i++; |
| 916 fprintf(stdout, "='%s'", namespaces[i]); | 916 fprintf(stdout, "='%s'", namespaces[i]); |
| 917 } | 917 } |
| 918 } | 918 } |
| 919 fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted); | 919 fprintf(stdout, ", %d, %d", nb_attributes, nb_defaulted); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 } | 1124 } |
| 1125 #endif | 1125 #endif |
| 1126 } | 1126 } |
| 1127 | 1127 |
| 1128 | 1128 |
| 1129 int main(int argc, char **argv) { | 1129 int main(int argc, char **argv) { |
| 1130 int i; | 1130 int i; |
| 1131 int files = 0; | 1131 int files = 0; |
| 1132 | 1132 |
| 1133 LIBXML_TEST_VERSION /* be safe, plus calls xmlInitParser */ | 1133 LIBXML_TEST_VERSION /* be safe, plus calls xmlInitParser */ |
| 1134 | 1134 |
| 1135 for (i = 1; i < argc ; i++) { | 1135 for (i = 1; i < argc ; i++) { |
| 1136 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) | 1136 if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug"))) |
| 1137 debug++; | 1137 debug++; |
| 1138 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) | 1138 else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy"))) |
| 1139 copy++; | 1139 copy++; |
| 1140 else if ((!strcmp(argv[i], "-recover")) || | 1140 else if ((!strcmp(argv[i], "-recover")) || |
| 1141 (!strcmp(argv[i], "--recover"))) | 1141 (!strcmp(argv[i], "--recover"))) |
| 1142 recovery++; | 1142 recovery++; |
| 1143 else if ((!strcmp(argv[i], "-push")) || | 1143 else if ((!strcmp(argv[i], "-push")) || |
| 1144 (!strcmp(argv[i], "--push"))) | 1144 (!strcmp(argv[i], "--push"))) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 xmlMemoryDump(); | 1189 xmlMemoryDump(); |
| 1190 | 1190 |
| 1191 return(0); | 1191 return(0); |
| 1192 } | 1192 } |
| 1193 #else | 1193 #else |
| 1194 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { | 1194 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
| 1195 printf("%s : SAX1 parsing support not compiled in\n", argv[0]); | 1195 printf("%s : SAX1 parsing support not compiled in\n", argv[0]); |
| 1196 return(0); | 1196 return(0); |
| 1197 } | 1197 } |
| 1198 #endif /* LIBXML_SAX1_ENABLED */ | 1198 #endif /* LIBXML_SAX1_ENABLED */ |
| OLD | NEW |