Annotation of XML/testHTML.c, revision 1.6
1.1 daniel 1: /*
2: * testHTML.c : a small tester program for HTML input.
3: *
4: * See Copyright for the status of this software.
5: *
6: * Daniel.Veillard@w3.org
7: */
8:
9: #ifdef WIN32
10: #define HAVE_FCNTL_H
11: #include <io.h>
12: #else
1.4 daniel 13: #include "config.h"
1.1 daniel 14: #endif
1.3 daniel 15:
16: #include <stdio.h>
17: #include <string.h>
18:
19: #ifdef HAVE_SYS_TYPES_H
1.1 daniel 20: #include <sys/types.h>
1.3 daniel 21: #endif
1.1 daniel 22: #ifdef HAVE_SYS_STAT_H
23: #include <sys/stat.h>
24: #endif
25: #ifdef HAVE_FCNTL_H
26: #include <fcntl.h>
27: #endif
28: #ifdef HAVE_UNISTD_H
29: #include <unistd.h>
30: #endif
1.3 daniel 31: #ifdef HAVE_STDLIB_H
1.1 daniel 32: #include <stdlib.h>
1.3 daniel 33: #endif
1.1 daniel 34:
1.6 ! daniel 35: #include "xmlmemory.h"
1.1 daniel 36: #include "HTMLparser.h"
37: #include "HTMLtree.h"
38: #include "debugXML.h"
39:
40: static int debug = 0;
41: static int copy = 0;
42:
43: /*
44: * Note: this is perfectly clean HTML, i.e. not a useful test.
1.5 daniel 45: static xmlChar buffer[] =
1.1 daniel 46: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"\n\
47: \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n\
48: <html>\n\
49: <head>\n\
50: <title>This service is temporary down</title>\n\
51: </head>\n\
52: \n\
53: <body bgcolor=\"#FFFFFF\">\n\
54: <h1 align=\"center\">Sorry, this service is temporary down</h1>\n\
55: We are doing our best to get it back on-line,\n\
56: \n\
57: <p>The W3C system administrators</p>\n\
58: </body>\n\
59: </html>\n\
60: ";
1.2 daniel 61: */
1.1 daniel 62:
63: /************************************************************************
64: * *
65: * Debug *
66: * *
67: ************************************************************************/
68:
69: void parseAndPrintFile(char *filename) {
70: htmlDocPtr doc, tmp;
71:
72: /*
73: * build an HTML tree from a string;
74: */
75: doc = htmlParseFile(filename, NULL);
76:
77: /*
78: * test intermediate copy if needed.
79: */
80: if (copy) {
81: tmp = doc;
82: doc = xmlCopyDoc(doc, 1);
83: xmlFreeDoc(tmp);
84: }
85:
86: /*
87: * print it.
88: */
89: if (!debug)
90: htmlDocDump(stdout, doc);
91: else
92: xmlDebugDumpDocument(stdout, doc);
93:
94: /*
95: * free it.
96: */
97: xmlFreeDoc(doc);
98: }
99:
1.5 daniel 100: void parseAndPrintBuffer(xmlChar *buf) {
1.1 daniel 101: htmlDocPtr doc, tmp;
102:
103: /*
104: * build an HTML tree from a string;
105: */
106: doc = htmlParseDoc(buf, NULL);
107:
108: /*
109: * test intermediate copy if needed.
110: */
111: if (copy) {
112: tmp = doc;
113: doc = xmlCopyDoc(doc, 1);
114: xmlFreeDoc(tmp);
115: }
116:
117: /*
118: * print it.
119: */
120: if (!debug)
121: htmlDocDump(stdout, doc);
122: else
123: xmlDebugDumpDocument(stdout, doc);
124:
125: /*
126: * free it.
127: */
128: xmlFreeDoc(doc);
129: }
130:
131: int main(int argc, char **argv) {
132: int i;
133: int files = 0;
134:
135: for (i = 1; i < argc ; i++) {
136: if ((!strcmp(argv[i], "-debug")) || (!strcmp(argv[i], "--debug")))
137: debug++;
138: else if ((!strcmp(argv[i], "-copy")) || (!strcmp(argv[i], "--copy")))
139: copy++;
140: }
141: for (i = 1; i < argc ; i++) {
142: if (argv[i][0] != '-') {
143: parseAndPrintFile(argv[i]);
144: files ++;
145: }
146: }
147: if (files == 0) {
148: printf("Usage : %s [--debug] [--copy] HTMLfiles ...\n",
149: argv[0]);
150: printf("\tParse the HTML files and output the result of the parsing\n");
151: printf("\t--debug : dump a debug tree of the in-memory document\n");
152: printf("\t--copy : used to test the internal copy implementation\n");
153: }
1.6 ! daniel 154: xmlMemoryDump();
1.1 daniel 155:
156: return(0);
157: }
Webmaster