| OLD | NEW |
| 1 /* | 1 /* |
| 2 * testHTML.c : a small tester program for HTML input. | 2 * testHTML.c : a small tester program for HTML input. |
| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 * the ENTITY_REF nodes are built in the structure (and the parameter | 172 * the ENTITY_REF nodes are built in the structure (and the parameter |
| 173 * values). | 173 * values). |
| 174 * | 174 * |
| 175 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. | 175 * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. |
| 176 */ | 176 */ |
| 177 static xmlParserInputPtr | 177 static xmlParserInputPtr |
| 178 resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xm
lChar *systemId) | 178 resolveEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *publicId, const xm
lChar *systemId) |
| 179 { | 179 { |
| 180 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ | 180 /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ |
| 181 | 181 |
| 182 | 182 |
| 183 fprintf(stdout, "SAX.resolveEntity("); | 183 fprintf(stdout, "SAX.resolveEntity("); |
| 184 if (publicId != NULL) | 184 if (publicId != NULL) |
| 185 fprintf(stdout, "%s", (char *)publicId); | 185 fprintf(stdout, "%s", (char *)publicId); |
| 186 else | 186 else |
| 187 fprintf(stdout, " "); | 187 fprintf(stdout, " "); |
| 188 if (systemId != NULL) | 188 if (systemId != NULL) |
| 189 fprintf(stdout, ", %s)\n", (char *)systemId); | 189 fprintf(stdout, ", %s)\n", (char *)systemId); |
| 190 else | 190 else |
| 191 fprintf(stdout, ", )\n"); | 191 fprintf(stdout, ", )\n"); |
| 192 /********* | 192 /********* |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) | 226 getParameterEntityDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
| 227 { | 227 { |
| 228 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); | 228 fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); |
| 229 return(NULL); | 229 return(NULL); |
| 230 } | 230 } |
| 231 | 231 |
| 232 | 232 |
| 233 /** | 233 /** |
| 234 * entityDeclDebug: | 234 * entityDeclDebug: |
| 235 * @ctxt: An XML parser context | 235 * @ctxt: An XML parser context |
| 236 * @name: the entity name | 236 * @name: the entity name |
| 237 * @type: the entity type | 237 * @type: the entity type |
| 238 * @publicId: The public ID of the entity | 238 * @publicId: The public ID of the entity |
| 239 * @systemId: The system ID of the entity | 239 * @systemId: The system ID of the entity |
| 240 * @content: the entity value (without processing). | 240 * @content: the entity value (without processing). |
| 241 * | 241 * |
| 242 * An entity definition has been parsed | 242 * An entity definition has been parsed |
| 243 */ | 243 */ |
| 244 static void | 244 static void |
| 245 entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, | 245 entityDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
| 246 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) | 246 const xmlChar *publicId, const xmlChar *systemId, xmlChar *content) |
| 247 { | 247 { |
| 248 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", | 248 fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", |
| 249 name, type, publicId, systemId, content); | 249 name, type, publicId, systemId, content); |
| 250 } | 250 } |
| 251 | 251 |
| 252 /** | 252 /** |
| 253 * attributeDeclDebug: | 253 * attributeDeclDebug: |
| 254 * @ctxt: An XML parser context | 254 * @ctxt: An XML parser context |
| 255 * @name: the attribute name | 255 * @name: the attribute name |
| 256 * @type: the attribute type | 256 * @type: the attribute type |
| 257 * | 257 * |
| 258 * An attribute definition has been parsed | 258 * An attribute definition has been parsed |
| 259 */ | 259 */ |
| 260 static void | 260 static void |
| 261 attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *elem, const xmlCha
r *name, | 261 attributeDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *elem, const xmlCha
r *name, |
| 262 int type, int def, const xmlChar *defaultValue, | 262 int type, int def, const xmlChar *defaultValue, |
| 263 xmlEnumerationPtr tree ATTRIBUTE_UNUSED) | 263 xmlEnumerationPtr tree ATTRIBUTE_UNUSED) |
| 264 { | 264 { |
| 265 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", | 265 fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", |
| 266 elem, name, type, def, defaultValue); | 266 elem, name, type, def, defaultValue); |
| 267 } | 267 } |
| 268 | 268 |
| 269 /** | 269 /** |
| 270 * elementDeclDebug: | 270 * elementDeclDebug: |
| 271 * @ctxt: An XML parser context | 271 * @ctxt: An XML parser context |
| 272 * @name: the element name | 272 * @name: the element name |
| 273 * @type: the element type | 273 * @type: the element type |
| 274 * @content: the element value (without processing). | 274 * @content: the element value (without processing). |
| 275 * | 275 * |
| 276 * An element definition has been parsed | 276 * An element definition has been parsed |
| 277 */ | 277 */ |
| 278 static void | 278 static void |
| 279 elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, | 279 elementDeclDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name, int type, |
| 280 xmlElementContentPtr content ATTRIBUTE_UNUSED) | 280 xmlElementContentPtr content ATTRIBUTE_UNUSED) |
| 281 { | 281 { |
| 282 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n", | 282 fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n", |
| 283 name, type); | 283 name, type); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 output[outlen] = 0; | 446 output[outlen] = 0; |
| 447 | 447 |
| 448 fprintf(stdout, "SAX.cdata(%s, %d)\n", output, len); | 448 fprintf(stdout, "SAX.cdata(%s, %d)\n", output, len); |
| 449 } | 449 } |
| 450 | 450 |
| 451 /** | 451 /** |
| 452 * referenceDebug: | 452 * referenceDebug: |
| 453 * @ctxt: An XML parser context | 453 * @ctxt: An XML parser context |
| 454 * @name: The entity name | 454 * @name: The entity name |
| 455 * | 455 * |
| 456 * called when an entity reference is detected. | 456 * called when an entity reference is detected. |
| 457 */ | 457 */ |
| 458 static void | 458 static void |
| 459 referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) | 459 referenceDebug(void *ctx ATTRIBUTE_UNUSED, const xmlChar *name) |
| 460 { | 460 { |
| 461 fprintf(stdout, "SAX.reference(%s)\n", name); | 461 fprintf(stdout, "SAX.reference(%s)\n", name); |
| 462 } | 462 } |
| 463 | 463 |
| 464 /** | 464 /** |
| 465 * ignorableWhitespaceDebug: | 465 * ignorableWhitespaceDebug: |
| 466 * @ctxt: An XML parser context | 466 * @ctxt: An XML parser context |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 doc = ctxt->myDoc; | 680 doc = ctxt->myDoc; |
| 681 htmlFreeParserCtxt(ctxt); | 681 htmlFreeParserCtxt(ctxt); |
| 682 } | 682 } |
| 683 if (doc != NULL) { | 683 if (doc != NULL) { |
| 684 fprintf(stdout, "htmlSAXParseFile returned non-NULL\n"); | 684 fprintf(stdout, "htmlSAXParseFile returned non-NULL\n"); |
| 685 xmlFreeDoc(doc); | 685 xmlFreeDoc(doc); |
| 686 } | 686 } |
| 687 fclose(f); | 687 fclose(f); |
| 688 } | 688 } |
| 689 } | 689 } |
| 690 } else {» | 690 } else { |
| 691 #endif /* LIBXML_PUSH_ENABLED */ | 691 #endif /* LIBXML_PUSH_ENABLED */ |
| 692 doc = htmlSAXParseFile(filename, NULL, emptySAXHandler, NULL); | 692 doc = htmlSAXParseFile(filename, NULL, emptySAXHandler, NULL); |
| 693 if (doc != NULL) { | 693 if (doc != NULL) { |
| 694 fprintf(stdout, "htmlSAXParseFile returned non-NULL\n"); | 694 fprintf(stdout, "htmlSAXParseFile returned non-NULL\n"); |
| 695 xmlFreeDoc(doc); | 695 xmlFreeDoc(doc); |
| 696 } | 696 } |
| 697 | 697 |
| 698 if (!noout) { | 698 if (!noout) { |
| 699 /* | 699 /* |
| 700 * Debug callback | 700 * Debug callback |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 chars, res, filename, XML_CHAR_ENCODING_NONE); | 739 chars, res, filename, XML_CHAR_ENCODING_NONE); |
| 740 while ((res = fread(chars, 1, size, f)) > 0) { | 740 while ((res = fread(chars, 1, size, f)) > 0) { |
| 741 htmlParseChunk(ctxt, chars, res, 0); | 741 htmlParseChunk(ctxt, chars, res, 0); |
| 742 } | 742 } |
| 743 htmlParseChunk(ctxt, chars, 0, 1); | 743 htmlParseChunk(ctxt, chars, 0, 1); |
| 744 doc = ctxt->myDoc; | 744 doc = ctxt->myDoc; |
| 745 htmlFreeParserCtxt(ctxt); | 745 htmlFreeParserCtxt(ctxt); |
| 746 } | 746 } |
| 747 fclose(f); | 747 fclose(f); |
| 748 } | 748 } |
| 749 } else {» | 749 } else { |
| 750 doc = htmlReadFile(filename, NULL, options); | 750 doc = htmlReadFile(filename, NULL, options); |
| 751 } | 751 } |
| 752 #else | 752 #else |
| 753 doc = htmlReadFile(filename,NULL,options); | 753 doc = htmlReadFile(filename,NULL,options); |
| 754 #endif | 754 #endif |
| 755 if (doc == NULL) { | 755 if (doc == NULL) { |
| 756 xmlGenericError(xmlGenericErrorContext, | 756 xmlGenericError(xmlGenericErrorContext, |
| 757 "Could not parse %s\n", filename); | 757 "Could not parse %s\n", filename); |
| 758 } | 758 } |
| 759 | 759 |
| 760 #ifdef LIBXML_TREE_ENABLED | 760 #ifdef LIBXML_TREE_ENABLED |
| 761 /* | 761 /* |
| 762 * test intermediate copy if needed. | 762 * test intermediate copy if needed. |
| 763 */ | 763 */ |
| 764 if (copy) { | 764 if (copy) { |
| 765 htmlDocPtr tmp; | 765 htmlDocPtr tmp; |
| 766 | 766 |
| 767 tmp = doc; | 767 tmp = doc; |
| 768 doc = xmlCopyDoc(doc, 1); | 768 doc = xmlCopyDoc(doc, 1); |
| 769 xmlFreeDoc(tmp); | 769 xmlFreeDoc(tmp); |
| 770 } | 770 } |
| 771 #endif | 771 #endif |
| 772 | 772 |
| 773 #ifdef LIBXML_OUTPUT_ENABLED | 773 #ifdef LIBXML_OUTPUT_ENABLED |
| 774 /* | 774 /* |
| 775 * print it. | 775 * print it. |
| 776 */ | 776 */ |
| 777 if (!noout) { | 777 if (!noout) { |
| 778 #ifdef LIBXML_DEBUG_ENABLED | 778 #ifdef LIBXML_DEBUG_ENABLED |
| 779 if (!debug) { | 779 if (!debug) { |
| 780 if (encoding) | 780 if (encoding) |
| 781 htmlSaveFileEnc("-", doc, encoding); | 781 htmlSaveFileEnc("-", doc, encoding); |
| 782 else | 782 else |
| 783 htmlDocDump(stdout, doc); | 783 htmlDocDump(stdout, doc); |
| 784 } else | 784 } else |
| 785 xmlDebugDumpDocument(stdout, doc); | 785 xmlDebugDumpDocument(stdout, doc); |
| 786 #else | 786 #else |
| 787 if (encoding) | 787 if (encoding) |
| 788 htmlSaveFileEnc("-", doc, encoding); | 788 htmlSaveFileEnc("-", doc, encoding); |
| 789 else | 789 else |
| 790 htmlDocDump(stdout, doc); | 790 htmlDocDump(stdout, doc); |
| 791 #endif | 791 #endif |
| 792 }» | 792 } |
| 793 #endif /* LIBXML_OUTPUT_ENABLED */ | 793 #endif /* LIBXML_OUTPUT_ENABLED */ |
| 794 | 794 |
| 795 /* | 795 /* |
| 796 * free it. | 796 * free it. |
| 797 */ | 797 */ |
| 798 xmlFreeDoc(doc); | 798 xmlFreeDoc(doc); |
| 799 } | 799 } |
| 800 | 800 |
| 801 int main(int argc, char **argv) { | 801 int main(int argc, char **argv) { |
| 802 int i, count; | 802 int i, count; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 831 if ((!strcmp(argv[i], "-encode")) || | 831 if ((!strcmp(argv[i], "-encode")) || |
| 832 (!strcmp(argv[i], "--encode"))) { | 832 (!strcmp(argv[i], "--encode"))) { |
| 833 i++; | 833 i++; |
| 834 continue; | 834 continue; |
| 835 } | 835 } |
| 836 if (argv[i][0] != '-') { | 836 if (argv[i][0] != '-') { |
| 837 if (repeat) { | 837 if (repeat) { |
| 838 for (count = 0;count < 100 * repeat;count++) { | 838 for (count = 0;count < 100 * repeat;count++) { |
| 839 if (sax) | 839 if (sax) |
| 840 parseSAXFile(argv[i]); | 840 parseSAXFile(argv[i]); |
| 841 » » else | 841 » » else |
| 842 parseAndPrintFile(argv[i]); | 842 parseAndPrintFile(argv[i]); |
| 843 » » } | 843 » » } |
| 844 } else { | 844 } else { |
| 845 if (sax) | 845 if (sax) |
| 846 parseSAXFile(argv[i]); | 846 parseSAXFile(argv[i]); |
| 847 » » else | 847 » » else |
| 848 parseAndPrintFile(argv[i]); | 848 parseAndPrintFile(argv[i]); |
| 849 } | 849 } |
| 850 files ++; | 850 files ++; |
| 851 } | 851 } |
| 852 } | 852 } |
| 853 if (files == 0) { | 853 if (files == 0) { |
| 854 printf("Usage : %s [--debug] [--copy] [--copy] HTMLfiles ...\n", | 854 printf("Usage : %s [--debug] [--copy] [--copy] HTMLfiles ...\n", |
| 855 argv[0]); | 855 argv[0]); |
| 856 printf("\tParse the HTML files and output the result of the parsing\n"); | 856 printf("\tParse the HTML files and output the result of the parsing\n"); |
| 857 #ifdef LIBXML_DEBUG_ENABLED | 857 #ifdef LIBXML_DEBUG_ENABLED |
| (...skipping 13 matching lines...) Expand all Loading... |
| 871 | 871 |
| 872 return(0); | 872 return(0); |
| 873 } | 873 } |
| 874 #else /* !LIBXML_HTML_ENABLED */ | 874 #else /* !LIBXML_HTML_ENABLED */ |
| 875 #include <stdio.h> | 875 #include <stdio.h> |
| 876 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { | 876 int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { |
| 877 printf("%s : HTML support not compiled in\n", argv[0]); | 877 printf("%s : HTML support not compiled in\n", argv[0]); |
| 878 return(0); | 878 return(0); |
| 879 } | 879 } |
| 880 #endif | 880 #endif |
| OLD | NEW |