blob: 80014385728cd41f13975dd90809876666154799 [file] [log] [blame]
Daniel Veillardeae522a2001-04-23 13:41:34 +00001/*
2 * DOCBparser.c : an attempt to parse SGML Docbook documents
3 *
Daniel Veillarde95e2392001-06-06 10:46:28 +00004 * This is extremely hackish. It also adds one extension
5 * <?sgml-declaration encoding="ISO-8859-1"?>
6 * allowing to store the encoding of the document within the instance.
7 *
Daniel Veillardeae522a2001-04-23 13:41:34 +00008 * See Copyright for the status of this software.
9 *
Daniel Veillardc5d64342001-06-24 12:13:24 +000010 * daniel@veillard.com
Daniel Veillardeae522a2001-04-23 13:41:34 +000011 */
12
13#include "libxml.h"
14#ifdef LIBXML_DOCB_ENABLED
15
16#include <string.h>
17#ifdef HAVE_CTYPE_H
18#include <ctype.h>
19#endif
20#ifdef HAVE_STDLIB_H
21#include <stdlib.h>
22#endif
23#ifdef HAVE_SYS_STAT_H
24#include <sys/stat.h>
25#endif
26#ifdef HAVE_FCNTL_H
27#include <fcntl.h>
28#endif
29#ifdef HAVE_UNISTD_H
30#include <unistd.h>
31#endif
32#ifdef HAVE_ZLIB_H
33#include <zlib.h>
34#endif
35
36#include <libxml/xmlmemory.h>
37#include <libxml/tree.h>
38#include <libxml/SAX.h>
39#include <libxml/parser.h>
40#include <libxml/parserInternals.h>
41#include <libxml/xmlerror.h>
42#include <libxml/DOCBparser.h>
43#include <libxml/entities.h>
44#include <libxml/encoding.h>
45#include <libxml/valid.h>
46#include <libxml/xmlIO.h>
47#include <libxml/uri.h>
Daniel Veillard3c01b1d2001-10-17 15:58:35 +000048#include <libxml/globals.h>
Daniel Veillardeae522a2001-04-23 13:41:34 +000049
50/*
Daniel Veillard89cad532001-10-22 09:46:13 +000051 * DocBook XML current versions
52 */
53
54#define XML_DOCBOOK_XML_PUBLIC (const xmlChar *) \
55 "-//OASIS//DTD DocBook XML V4.1.2//EN"
56#define XML_DOCBOOK_XML_SYSTEM (const xmlChar *) \
57 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
58
59/*
Daniel Veillardeae522a2001-04-23 13:41:34 +000060 * Internal description of an SGML entity
61 */
62typedef struct _docbEntityDesc docbEntityDesc;
63typedef docbEntityDesc *docbEntityDescPtr;
64struct _docbEntityDesc {
65 int value; /* the UNICODE value for the character */
66 const char *name; /* The entity name */
67 const char *desc; /* the description */
68};
69
70#if 0
71docbElemDescPtr docbTagLookup (const xmlChar *tag);
72docbEntityDescPtr docbEntityLookup(const xmlChar *name);
73docbEntityDescPtr docbEntityValueLookup(int value);
74
75int docbIsAutoClosed(docbDocPtr doc,
76 docbNodePtr elem);
77int docbAutoCloseTag(docbDocPtr doc,
78 const xmlChar *name,
79 docbNodePtr elem);
80
81#endif
Daniel Veillard61b33d52001-04-24 13:55:12 +000082static int docbParseCharRef(docbParserCtxtPtr ctxt);
83static xmlEntityPtr docbParseEntityRef(docbParserCtxtPtr ctxt,
Daniel Veillardeae522a2001-04-23 13:41:34 +000084 xmlChar **str);
Daniel Veillard61b33d52001-04-24 13:55:12 +000085static void docbParseElement(docbParserCtxtPtr ctxt);
Daniel Veillard1034da22001-04-25 19:06:28 +000086static void docbParseContent(docbParserCtxtPtr ctxt);
Daniel Veillardeae522a2001-04-23 13:41:34 +000087
88/*
89 * Internal description of an SGML element
90 */
91typedef struct _docbElemDesc docbElemDesc;
92typedef docbElemDesc *docbElemDescPtr;
93struct _docbElemDesc {
94 const char *name; /* The tag name */
95 int startTag; /* Whether the start tag can be implied */
96 int endTag; /* Whether the end tag can be implied */
97 int empty; /* Is this an empty element ? */
98 int depr; /* Is this a deprecated element ? */
99 int dtd; /* 1: only in Loose DTD, 2: only Frameset one */
100 const char *desc; /* the description */
101};
102
103
104#define DOCB_MAX_NAMELEN 1000
105#define DOCB_PARSER_BIG_BUFFER_SIZE 1000
106#define DOCB_PARSER_BUFFER_SIZE 100
107
108/* #define DEBUG */
109/* #define DEBUG_PUSH */
110
111/************************************************************************
112 * *
113 * Parser stacks related functions and macros *
114 * *
115 ************************************************************************/
116
117/*
118 * Generic function for accessing stacks in the Parser Context
119 */
120
121#define PUSH_AND_POP(scope, type, name) \
122scope int docb##name##Push(docbParserCtxtPtr ctxt, type value) { \
123 if (ctxt->name##Nr >= ctxt->name##Max) { \
124 ctxt->name##Max *= 2; \
125 ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \
126 ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \
127 if (ctxt->name##Tab == NULL) { \
128 xmlGenericError(xmlGenericErrorContext, "realloc failed !\n"); \
129 return(0); \
130 } \
131 } \
132 ctxt->name##Tab[ctxt->name##Nr] = value; \
133 ctxt->name = value; \
134 return(ctxt->name##Nr++); \
135} \
136scope type docb##name##Pop(docbParserCtxtPtr ctxt) { \
137 type ret; \
138 if (ctxt->name##Nr < 0) return(0); \
139 ctxt->name##Nr--; \
140 if (ctxt->name##Nr < 0) return(0); \
141 if (ctxt->name##Nr > 0) \
142 ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \
143 else \
144 ctxt->name = NULL; \
145 ret = ctxt->name##Tab[ctxt->name##Nr]; \
146 ctxt->name##Tab[ctxt->name##Nr] = 0; \
147 return(ret); \
148} \
149
150/* PUSH_AND_POP(static, xmlNodePtr, node) */
151PUSH_AND_POP(static, xmlChar*, name)
152
153/*
154 * Macros for accessing the content. Those should be used only by the parser,
155 * and not exported.
156 *
157 * Dirty macros, i.e. one need to make assumption on the context to use them
158 *
159 * CUR_PTR return the current pointer to the xmlChar to be parsed.
160 * CUR returns the current xmlChar value, i.e. a 8 bit value if compiled
161 * in ISO-Latin or UTF-8, and the current 16 bit value if compiled
162 * in UNICODE mode. This should be used internally by the parser
163 * only to compare to ASCII values otherwise it would break when
164 * running with UTF-8 encoding.
165 * NXT(n) returns the n'th next xmlChar. Same as CUR is should be used only
166 * to compare on ASCII based substring.
167 * UPP(n) returns the n'th next xmlChar converted to uppercase. Same as CUR
168 * it should be used only to compare on ASCII based substring.
169 * SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined
170 * strings within the parser.
171 *
172 * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding
173 *
174 * CURRENT Returns the current char value, with the full decoding of
175 * UTF-8 if we are using this mode. It returns an int.
176 * NEXT Skip to the next character, this does the proper decoding
177 * in UTF-8 mode. It also pop-up unfinished entities on the fly.
178 * COPY(to) copy one char to *to, increment CUR_PTR and to accordingly
179 */
180
181#define UPPER (toupper(*ctxt->input->cur))
182
183#define SKIP(val) ctxt->nbChars += (val),ctxt->input->cur += (val)
184
185#define NXT(val) ctxt->input->cur[(val)]
186
187#define UPP(val) (toupper(ctxt->input->cur[(val)]))
188
189#define CUR_PTR ctxt->input->cur
190
191#define SHRINK xmlParserInputShrink(ctxt->input)
192
193#define GROW xmlParserInputGrow(ctxt->input, INPUT_CHUNK)
194
195#define CURRENT ((int) (*ctxt->input->cur))
196
197#define SKIP_BLANKS docbSkipBlankChars(ctxt)
198
199/* Imported from XML */
200
201/* #define CUR (ctxt->token ? ctxt->token : (int) (*ctxt->input->cur)) */
202#define CUR ((int) (*ctxt->input->cur))
203#define NEXT xmlNextChar(ctxt),ctxt->nbChars++
204
205#define RAW (ctxt->token ? -1 : (*ctxt->input->cur))
206#define NXT(val) ctxt->input->cur[(val)]
207#define CUR_PTR ctxt->input->cur
208
209
210#define NEXTL(l) do { \
211 if (*(ctxt->input->cur) == '\n') { \
212 ctxt->input->line++; ctxt->input->col = 1; \
213 } else ctxt->input->col++; \
214 ctxt->token = 0; ctxt->input->cur += l; ctxt->nbChars++; \
215 } while (0)
216
217/************
218 \
219 if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \
220 if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt);
221 ************/
222
223#define CUR_CHAR(l) docbCurrentChar(ctxt, &l)
224#define CUR_SCHAR(s, l) xmlStringCurrentChar(ctxt, s, &l)
225
226#define COPY_BUF(l,b,i,v) \
227 if (l == 1) b[i++] = (xmlChar) v; \
228 else i += xmlCopyChar(l,&b[i],v)
229
230/**
231 * docbCurrentChar:
232 * @ctxt: the DocBook SGML parser context
233 * @len: pointer to the length of the char read
234 *
235 * The current char value, if using UTF-8 this may actaully span multiple
236 * bytes in the input buffer. Implement the end of line normalization:
237 * 2.11 End-of-Line Handling
238 * If the encoding is unspecified, in the case we find an ISO-Latin-1
239 * char, then the encoding converter is plugged in automatically.
240 *
Daniel Veillard60087f32001-10-10 09:45:09 +0000241 * Returns the current char value and its length
Daniel Veillardeae522a2001-04-23 13:41:34 +0000242 */
243
244static int
245docbCurrentChar(xmlParserCtxtPtr ctxt, int *len) {
246 if (ctxt->instate == XML_PARSER_EOF)
247 return(0);
248
249 if (ctxt->token != 0) {
250 *len = 0;
251 return(ctxt->token);
252 }
253 if (ctxt->charset == XML_CHAR_ENCODING_UTF8) {
254 /*
255 * We are supposed to handle UTF8, check it's valid
256 * From rfc2044: encoding of the Unicode values on UTF-8:
257 *
258 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
259 * 0000 0000-0000 007F 0xxxxxxx
260 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
261 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
262 *
263 * Check for the 0x110000 limit too
264 */
265 const unsigned char *cur = ctxt->input->cur;
266 unsigned char c;
267 unsigned int val;
268
269 c = *cur;
270 if (c & 0x80) {
271 if (cur[1] == 0)
272 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
273 if ((cur[1] & 0xc0) != 0x80)
274 goto encoding_error;
275 if ((c & 0xe0) == 0xe0) {
276
277 if (cur[2] == 0)
278 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
279 if ((cur[2] & 0xc0) != 0x80)
280 goto encoding_error;
281 if ((c & 0xf0) == 0xf0) {
282 if (cur[3] == 0)
283 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
284 if (((c & 0xf8) != 0xf0) ||
285 ((cur[3] & 0xc0) != 0x80))
286 goto encoding_error;
287 /* 4-byte code */
288 *len = 4;
289 val = (cur[0] & 0x7) << 18;
290 val |= (cur[1] & 0x3f) << 12;
291 val |= (cur[2] & 0x3f) << 6;
292 val |= cur[3] & 0x3f;
293 } else {
294 /* 3-byte code */
295 *len = 3;
296 val = (cur[0] & 0xf) << 12;
297 val |= (cur[1] & 0x3f) << 6;
298 val |= cur[2] & 0x3f;
299 }
300 } else {
301 /* 2-byte code */
302 *len = 2;
303 val = (cur[0] & 0x1f) << 6;
304 val |= cur[1] & 0x3f;
305 }
306 if (!IS_CHAR(val)) {
307 ctxt->errNo = XML_ERR_INVALID_ENCODING;
308 if ((ctxt->sax != NULL) &&
309 (ctxt->sax->error != NULL))
310 ctxt->sax->error(ctxt->userData,
311 "Char 0x%X out of allowed range\n", val);
312 ctxt->wellFormed = 0;
313 ctxt->disableSAX = 1;
314 }
315 return(val);
316 } else {
317 /* 1-byte code */
318 *len = 1;
319 return((int) *ctxt->input->cur);
320 }
321 }
322 /*
Daniel Veillard60087f32001-10-10 09:45:09 +0000323 * Assume it's a fixed length encoding (1) with
Daniel Veillardeae522a2001-04-23 13:41:34 +0000324 * a compatibke encoding for the ASCII set, since
325 * XML constructs only use < 128 chars
326 */
327 *len = 1;
328 if ((int) *ctxt->input->cur < 0x80)
329 return((int) *ctxt->input->cur);
330
331 /*
332 * Humm this is bad, do an automatic flow conversion
333 */
334 xmlSwitchEncoding(ctxt, XML_CHAR_ENCODING_8859_1);
335 ctxt->charset = XML_CHAR_ENCODING_UTF8;
336 return(xmlCurrentChar(ctxt, len));
337
338encoding_error:
339 /*
340 * If we detect an UTF8 error that probably mean that the
341 * input encoding didn't get properly advertized in the
342 * declaration header. Report the error and switch the encoding
343 * to ISO-Latin-1 (if you don't like this policy, just declare the
344 * encoding !)
345 */
346 ctxt->errNo = XML_ERR_INVALID_ENCODING;
347 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL)) {
348 ctxt->sax->error(ctxt->userData,
349 "Input is not proper UTF-8, indicate encoding !\n");
350 ctxt->sax->error(ctxt->userData, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
351 ctxt->input->cur[0], ctxt->input->cur[1],
352 ctxt->input->cur[2], ctxt->input->cur[3]);
353 }
354
355 ctxt->charset = XML_CHAR_ENCODING_8859_1;
356 *len = 1;
357 return((int) *ctxt->input->cur);
358}
359
360#if 0
361/**
362 * sgmlNextChar:
363 * @ctxt: the DocBook SGML parser context
364 *
365 * Skip to the next char input char.
366 */
367
368static void
369sgmlNextChar(docbParserCtxtPtr ctxt) {
370 if (ctxt->instate == XML_PARSER_EOF)
371 return;
372 if ((*ctxt->input->cur == 0) &&
373 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
374 xmlPopInput(ctxt);
375 } else {
376 if (*(ctxt->input->cur) == '\n') {
377 ctxt->input->line++; ctxt->input->col = 1;
378 } else ctxt->input->col++;
379 ctxt->input->cur++;
380 ctxt->nbChars++;
381 if (*ctxt->input->cur == 0)
382 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
383 }
384}
385#endif
386
387/**
388 * docbSkipBlankChars:
389 * @ctxt: the DocBook SGML parser context
390 *
391 * skip all blanks character found at that point in the input streams.
392 *
393 * Returns the number of space chars skipped
394 */
395
396static int
397docbSkipBlankChars(xmlParserCtxtPtr ctxt) {
398 int res = 0;
399
400 while (IS_BLANK(*(ctxt->input->cur))) {
401 if ((*ctxt->input->cur == 0) &&
402 (xmlParserInputGrow(ctxt->input, INPUT_CHUNK) <= 0)) {
403 xmlPopInput(ctxt);
404 } else {
405 if (*(ctxt->input->cur) == '\n') {
406 ctxt->input->line++; ctxt->input->col = 1;
407 } else ctxt->input->col++;
408 ctxt->input->cur++;
409 ctxt->nbChars++;
410 if (*ctxt->input->cur == 0)
411 xmlParserInputGrow(ctxt->input, INPUT_CHUNK);
412 }
413 res++;
414 }
415 return(res);
416}
417
418
419
420/************************************************************************
421 * *
422 * The list of SGML elements and their properties *
423 * *
424 ************************************************************************/
425
426/*
427 * Start Tag: 1 means the start tag can be ommited
428 * End Tag: 1 means the end tag can be ommited
429 * 2 means it's forbidden (empty elements)
430 * Depr: this element is deprecated
431 * DTD: 1 means that this element is valid only in the Loose DTD
432 * 2 means that this element is valid only in the Frameset DTD
433 *
434 * Name,Start Tag,End Tag, Empty, Depr., DTD, Description
435 */
436static docbElemDesc
437docbookElementTable[] = {
438{ "abbrev", 0, 0, 0, 3, 0, "" }, /* word */
439{ "abstract", 0, 0, 0, 9, 0, "" }, /* title */
440{ "accel", 0, 0, 0, 7, 0, "" }, /* smallcptr */
441{ "ackno", 0, 0, 0, 4, 0, "" }, /* docinfo */
442{ "acronym", 0, 0, 0, 3, 0, "" }, /* word */
443{ "action", 0, 0, 0, 7, 0, "" }, /* smallcptr */
444{ "address", 0, 0, 0, 1, 0, "" },
445{ "affiliation",0, 0, 0, 9, 0, "" }, /* shortaffil */
446{ "alt", 0, 0, 0, 1, 0, "" },
447{ "anchor", 0, 2, 1, 0, 0, "" },
448{ "answer", 0, 0, 0, 9, 0, "" }, /* label */
449{ "appendix", 0, 0, 0, 9, 0, "" }, /* appendixinfo */
450{ "appendixinfo",0, 0, 0, 9, 0, "" }, /* graphic */
451{ "application",0, 0, 0, 2, 0, "" }, /* para */
452{ "area", 0, 2, 1, 0, 0, "" },
453{ "areaset", 0, 0, 0, 9, 0, "" }, /* area */
454{ "areaspec", 0, 0, 0, 9, 0, "" }, /* area */
455{ "arg", 0, 0, 0, 1, 0, "" },
Daniel Veillard4ec0b0f2001-04-25 15:53:40 +0000456{ "artheader", 0, 0, 0, 9, 0, "" },
Daniel Veillardeae522a2001-04-23 13:41:34 +0000457{ "article", 0, 0, 0, 9, 0, "" }, /* div.title.content */
458{ "articleinfo",0, 0, 0, 9, 0, "" }, /* graphic */
459{ "artpagenums",0, 0, 0, 4, 0, "" }, /* docinfo */
460{ "attribution",0, 0, 0, 2, 0, "" }, /* para */
461{ "audiodata", 0, 2, 1, 0, 0, "" },
462{ "audioobject",0, 0, 0, 9, 0, "" }, /* objectinfo */
463{ "authorblurb",0, 0, 0, 9, 0, "" }, /* title */
464{ "authorgroup",0, 0, 0, 9, 0, "" }, /* author */
465{ "authorinitials",0, 0, 0, 4, 0, "" }, /* docinfo */
466{ "author", 0, 0, 0, 9, 0, "" }, /* person.ident.mix */
467{ "beginpage", 0, 2, 1, 0, 0, "" },
468{ "bibliodiv", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
469{ "biblioentry",0, 0, 0, 9, 0, "" }, /* articleinfo */
470{ "bibliography",0, 0, 0, 9, 0, "" }, /* bibliographyinfo */
471{ "bibliographyinfo",0, 0, 0, 9, 0, "" }, /* graphic */
472{ "bibliomisc", 0, 0, 0, 2, 0, "" }, /* para */
473{ "bibliomixed",0, 0, 0, 1, 0, "" }, /* %bibliocomponent.mix, bibliomset) */
474{ "bibliomset", 0, 0, 0, 1, 0, "" }, /* %bibliocomponent.mix; | bibliomset) */
475{ "biblioset", 0, 0, 0, 9, 0, "" }, /* bibliocomponent.mix */
476{ "blockquote", 0, 0, 0, 9, 0, "" }, /* title */
477{ "book", 0, 0, 0, 9, 0, "" }, /* div.title.content */
478{ "bookinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
479{ "bridgehead", 0, 0, 0, 8, 0, "" }, /* title */
480{ "callout", 0, 0, 0, 9, 0, "" }, /* component.mix */
481{ "calloutlist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
482{ "caption", 0, 0, 0, 9, 0, "" }, /* textobject.mix */
483{ "caution", 0, 0, 0, 9, 0, "" }, /* title */
484{ "chapter", 0, 0, 0, 9, 0, "" }, /* chapterinfo */
485{ "chapterinfo",0, 0, 0, 9, 0, "" }, /* graphic */
486{ "citation", 0, 0, 0, 2, 0, "" }, /* para */
487{ "citerefentry",0, 0, 0, 9, 0, "" }, /* refentrytitle */
488{ "citetitle", 0, 0, 0, 2, 0, "" }, /* para */
489{ "city", 0, 0, 0, 4, 0, "" }, /* docinfo */
490{ "classname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
491{ "classsynopsisinfo",0,0, 0, 9, 0, "" }, /* cptr */
492{ "classsynopsis",0, 0, 0, 9, 0, "" }, /* ooclass */
493{ "cmdsynopsis",0, 0, 0, 9, 0, "" }, /* command */
494{ "co", 0, 2, 1, 0, 0, "" },
495{ "collab", 0, 0, 0, 9, 0, "" }, /* collabname */
496{ "collabname", 0, 0, 0, 4, 0, "" }, /* docinfo */
497{ "colophon", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
498{ "colspec", 0, 2, 1, 0, 0, "" },
499{ "colspec", 0, 2, 1, 0, 0, "" },
500{ "command", 0, 0, 0, 9, 0, "" }, /* cptr */
501{ "computeroutput",0, 0, 0, 9, 0, "" }, /* cptr */
502{ "confdates", 0, 0, 0, 4, 0, "" }, /* docinfo */
503{ "confgroup", 0, 0, 0, 9, 0, "" }, /* confdates */
504{ "confnum", 0, 0, 0, 4, 0, "" }, /* docinfo */
505{ "confsponsor",0, 0, 0, 4, 0, "" }, /* docinfo */
506{ "conftitle", 0, 0, 0, 4, 0, "" }, /* docinfo */
507{ "constant", 0, 0, 0, 7, 0, "" }, /* smallcptr */
508{ "constructorsynopsis",0,0, 0, 9, 0, "" }, /* modifier */
509{ "contractnum",0, 0, 0, 4, 0, "" }, /* docinfo */
510{ "contractsponsor",0, 0, 0, 4, 0, "" }, /* docinfo */
511{ "contrib", 0, 0, 0, 4, 0, "" }, /* docinfo */
512{ "copyright", 0, 0, 0, 9, 0, "" }, /* year */
513{ "corpauthor", 0, 0, 0, 4, 0, "" }, /* docinfo */
514{ "corpname", 0, 0, 0, 4, 0, "" }, /* docinfo */
515{ "country", 0, 0, 0, 4, 0, "" }, /* docinfo */
516{ "database", 0, 0, 0, 7, 0, "" }, /* smallcptr */
517{ "date", 0, 0, 0, 4, 0, "" }, /* docinfo */
518{ "dedication", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
519{ "destructorsynopsis",0,0, 0, 9, 0, "" }, /* modifier */
Daniel Veillardc057c5d2001-05-02 12:41:24 +0000520{ "docinfo", 0, 0, 0, 9, 0, "" },
Daniel Veillardeae522a2001-04-23 13:41:34 +0000521{ "edition", 0, 0, 0, 4, 0, "" }, /* docinfo */
522{ "editor", 0, 0, 0, 9, 0, "" }, /* person.ident.mix */
523{ "email", 0, 0, 0, 4, 0, "" }, /* docinfo */
524{ "emphasis", 0, 0, 0, 2, 0, "" }, /* para */
525{ "entry", 0, 0, 0, 9, 0, "" }, /* tbl.entry.mdl */
526{ "entrytbl", 0, 0, 0, 9, 0, "" }, /* tbl.entrytbl.mdl */
527{ "envar", 0, 0, 0, 7, 0, "" }, /* smallcptr */
528{ "epigraph", 0, 0, 0, 9, 0, "" }, /* attribution */
529{ "equation", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
530{ "errorcode", 0, 0, 0, 7, 0, "" }, /* smallcptr */
531{ "errorname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
532{ "errortype", 0, 0, 0, 7, 0, "" }, /* smallcptr */
533{ "example", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
534{ "exceptionname",0, 0, 0, 7, 0, "" }, /* smallcptr */
535{ "fax", 0, 0, 0, 4, 0, "" }, /* docinfo */
536{ "fieldsynopsis", 0, 0, 0, 9, 0, "" }, /* modifier */
537{ "figure", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
538{ "filename", 0, 0, 0, 7, 0, "" }, /* smallcptr */
539{ "firstname", 0, 0, 0, 4, 0, "" }, /* docinfo */
540{ "firstterm", 0, 0, 0, 3, 0, "" }, /* word */
541{ "footnote", 0, 0, 0, 9, 0, "" }, /* footnote.mix */
542{ "footnoteref",0, 2, 1, 0, 0, "" },
543{ "foreignphrase",0, 0, 0, 2, 0, "" }, /* para */
544{ "formalpara", 0, 0, 0, 9, 0, "" }, /* title */
545{ "funcdef", 0, 0, 0, 1, 0, "" },
546{ "funcparams", 0, 0, 0, 9, 0, "" }, /* cptr */
547{ "funcprototype",0, 0, 0, 9, 0, "" }, /* funcdef */
548{ "funcsynopsis",0, 0, 0, 9, 0, "" }, /* funcsynopsisinfo */
549{ "funcsynopsisinfo", 0, 0, 0, 9, 0, "" }, /* cptr */
550{ "function", 0, 0, 0, 9, 0, "" }, /* cptr */
551{ "glossary", 0, 0, 0, 9, 0, "" }, /* glossaryinfo */
552{ "glossaryinfo",0, 0, 0, 9, 0, "" }, /* graphic */
553{ "glossdef", 0, 0, 0, 9, 0, "" }, /* glossdef.mix */
554{ "glossdiv", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
555{ "glossentry", 0, 0, 0, 9, 0, "" }, /* glossterm */
556{ "glosslist", 0, 0, 0, 9, 0, "" }, /* glossentry */
Daniel Veillardc057c5d2001-05-02 12:41:24 +0000557{ "glossseealso",0, 0, 1, 2, 0, "" }, /* para */
558{ "glosssee", 0, 0, 1, 2, 0, "" }, /* para */
Daniel Veillardeae522a2001-04-23 13:41:34 +0000559{ "glossterm", 0, 0, 0, 2, 0, "" }, /* para */
Daniel Veillard4ec0b0f2001-04-25 15:53:40 +0000560{ "graphic", 0, 0, 0, 9, 0, "" },
Daniel Veillardeae522a2001-04-23 13:41:34 +0000561{ "graphicco", 0, 0, 0, 9, 0, "" }, /* areaspec */
562{ "group", 0, 0, 0, 9, 0, "" }, /* arg */
563{ "guibutton", 0, 0, 0, 7, 0, "" }, /* smallcptr */
564{ "guiicon", 0, 0, 0, 7, 0, "" }, /* smallcptr */
565{ "guilabel", 0, 0, 0, 7, 0, "" }, /* smallcptr */
566{ "guimenuitem",0, 0, 0, 7, 0, "" }, /* smallcptr */
567{ "guimenu", 0, 0, 0, 7, 0, "" }, /* smallcptr */
568{ "guisubmenu", 0, 0, 0, 7, 0, "" }, /* smallcptr */
569{ "hardware", 0, 0, 0, 7, 0, "" }, /* smallcptr */
570{ "highlights", 0, 0, 0, 9, 0, "" }, /* highlights.mix */
571{ "holder", 0, 0, 0, 4, 0, "" }, /* docinfo */
572{ "honorific", 0, 0, 0, 4, 0, "" }, /* docinfo */
573{ "imagedata", 0, 2, 1, 0, 0, "" },
574{ "imageobjectco",0, 0, 0, 9, 0, "" }, /* areaspec */
575{ "imageobject",0, 0, 0, 9, 0, "" }, /* objectinfo */
576{ "important", 0, 0, 0, 9, 0, "" }, /* title */
577{ "indexdiv", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
578{ "indexentry", 0, 0, 0, 9, 0, "" }, /* primaryie */
579{ "index", 0, 0, 0, 9, 0, "" }, /* indexinfo */
580{ "indexinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
581{ "indexterm", 0, 0, 0, 9, 0, "" }, /* primary */
582{ "informalequation",0, 0, 0, 9, 0, "" }, /* equation.content */
583{ "informalexample",0, 0, 0, 9, 0, "" }, /* example.mix */
584{ "informalfigure",0, 0, 0, 9, 0, "" }, /* figure.mix */
585{ "informaltable",0, 0, 0, 9, 0, "" }, /* graphic */
586{ "initializer",0, 0, 0, 7, 0, "" }, /* smallcptr */
587{ "inlineequation",0, 0, 0, 9, 0, "" }, /* inlineequation.content */
Daniel Veillard02f077a2001-04-26 10:59:11 +0000588{ "inlinegraphic",0, 0, 0, 9, 0, "" },
Daniel Veillardeae522a2001-04-23 13:41:34 +0000589{ "inlinemediaobject",0,0, 0, 9, 0, "" }, /* objectinfo */
590{ "interfacename",0, 0, 0, 7, 0, "" }, /* smallcptr */
591{ "interface", 0, 0, 0, 7, 0, "" }, /* smallcptr */
592{ "invpartnumber",0, 0, 0, 4, 0, "" }, /* docinfo */
593{ "isbn", 0, 0, 0, 4, 0, "" }, /* docinfo */
594{ "issn", 0, 0, 0, 4, 0, "" }, /* docinfo */
595{ "issuenum", 0, 0, 0, 4, 0, "" }, /* docinfo */
596{ "itemizedlist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
597{ "itermset", 0, 0, 0, 9, 0, "" }, /* indexterm */
598{ "jobtitle", 0, 0, 0, 4, 0, "" }, /* docinfo */
599{ "keycap", 0, 0, 0, 7, 0, "" }, /* smallcptr */
600{ "keycode", 0, 0, 0, 7, 0, "" }, /* smallcptr */
601{ "keycombo", 0, 0, 0, 9, 0, "" }, /* keycap */
602{ "keysym", 0, 0, 0, 7, 0, "" }, /* smallcptr */
603{ "keyword", 0, 0, 0, 1, 0, "" },
604{ "keywordset", 0, 0, 0, 9, 0, "" }, /* keyword */
605{ "label", 0, 0, 0, 3, 0, "" }, /* word */
606{ "legalnotice",0, 0, 0, 9, 0, "" }, /* title */
607{ "lineage", 0, 0, 0, 4, 0, "" }, /* docinfo */
608{ "lineannotation",0, 0, 0, 2, 0, "" }, /* para */
609{ "link", 0, 0, 0, 2, 0, "" }, /* para */
610{ "listitem", 0, 0, 0, 9, 0, "" }, /* component.mix */
611{ "literal", 0, 0, 0, 9, 0, "" }, /* cptr */
612{ "literallayout",0, 0, 0, 2, 0, "" }, /* para */
613{ "lot", 0, 0, 0, 9, 0, "" }, /* bookcomponent.title.content */
614{ "lotentry", 0, 0, 0, 2, 0, "" }, /* para */
615{ "manvolnum", 0, 0, 0, 3, 0, "" }, /* word */
616{ "markup", 0, 0, 0, 7, 0, "" }, /* smallcptr */
617{ "medialabel", 0, 0, 0, 7, 0, "" }, /* smallcptr */
618{ "mediaobjectco",0, 0, 0, 9, 0, "" }, /* objectinfo */
619{ "mediaobject",0, 0, 0, 9, 0, "" }, /* objectinfo */
620{ "member", 0, 0, 0, 2, 0, "" }, /* para */
621{ "menuchoice", 0, 0, 0, 9, 0, "" }, /* shortcut */
622{ "methodname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
623{ "methodparam",0, 0, 0, 9, 0, "" }, /* modifier */
624{ "methodsynopsis",0, 0, 0, 9, 0, "" }, /* modifier */
625{ "modespec", 0, 0, 0, 4, 0, "" }, /* docinfo */
626{ "modifier", 0, 0, 0, 7, 0, "" }, /* smallcptr */
627{ "mousebutton",0, 0, 0, 7, 0, "" }, /* smallcptr */
628{ "msgaud", 0, 0, 0, 2, 0, "" }, /* para */
629{ "msgentry", 0, 0, 0, 9, 0, "" }, /* msg */
630{ "msgexplan", 0, 0, 0, 9, 0, "" }, /* title */
631{ "msginfo", 0, 0, 0, 9, 0, "" }, /* msglevel */
632{ "msglevel", 0, 0, 0, 7, 0, "" }, /* smallcptr */
633{ "msgmain", 0, 0, 0, 9, 0, "" }, /* title */
634{ "msgorig", 0, 0, 0, 7, 0, "" }, /* smallcptr */
635{ "msgrel", 0, 0, 0, 9, 0, "" }, /* title */
636{ "msgset", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
637{ "msgsub", 0, 0, 0, 9, 0, "" }, /* title */
638{ "msgtext", 0, 0, 0, 9, 0, "" }, /* component.mix */
639{ "msg", 0, 0, 0, 9, 0, "" }, /* title */
640{ "note", 0, 0, 0, 9, 0, "" }, /* title */
641{ "objectinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
642{ "olink", 0, 0, 0, 2, 0, "" }, /* para */
643{ "ooclass", 0, 0, 0, 9, 0, "" }, /* modifier */
644{ "ooexception",0, 0, 0, 9, 0, "" }, /* modifier */
645{ "oointerface",0, 0, 0, 9, 0, "" }, /* modifier */
646{ "optional", 0, 0, 0, 9, 0, "" }, /* cptr */
647{ "option", 0, 0, 0, 7, 0, "" }, /* smallcptr */
648{ "orderedlist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
649{ "orgdiv", 0, 0, 0, 4, 0, "" }, /* docinfo */
650{ "orgname", 0, 0, 0, 4, 0, "" }, /* docinfo */
651{ "otheraddr", 0, 0, 0, 4, 0, "" }, /* docinfo */
652{ "othercredit",0, 0, 0, 9, 0, "" }, /* person.ident.mix */
653{ "othername", 0, 0, 0, 4, 0, "" }, /* docinfo */
654{ "pagenums", 0, 0, 0, 4, 0, "" }, /* docinfo */
655{ "paramdef", 0, 0, 0, 1, 0, "" },
656{ "parameter", 0, 0, 0, 7, 0, "" }, /* smallcptr */
657{ "para", 0, 0, 0, 2, 0, "" }, /* para */
658{ "partinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
659{ "partintro", 0, 0, 0, 9, 0, "" }, /* div.title.content */
660{ "part", 0, 0, 0, 9, 0, "" }, /* partinfo */
661{ "phone", 0, 0, 0, 4, 0, "" }, /* docinfo */
662{ "phrase", 0, 0, 0, 2, 0, "" }, /* para */
663{ "pob", 0, 0, 0, 4, 0, "" }, /* docinfo */
664{ "postcode", 0, 0, 0, 4, 0, "" }, /* docinfo */
665{ "prefaceinfo",0, 0, 0, 9, 0, "" }, /* graphic */
666{ "preface", 0, 0, 0, 9, 0, "" }, /* prefaceinfo */
667{ "primaryie", 0, 0, 0, 4, 0, "" }, /* ndxterm */
Daniel Veillardc057c5d2001-05-02 12:41:24 +0000668{ "primary", 0, 0, 0, 9, 0, "" }, /* ndxterm */
Daniel Veillardeae522a2001-04-23 13:41:34 +0000669{ "printhistory",0, 0, 0, 9, 0, "" }, /* para.class */
670{ "procedure", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
671{ "productname",0, 0, 0, 2, 0, "" }, /* para */
672{ "productnumber",0, 0, 0, 4, 0, "" }, /* docinfo */
673{ "programlistingco",0, 0, 0, 9, 0, "" }, /* areaspec */
674{ "programlisting",0, 0, 0, 2, 0, "" }, /* para */
675{ "prompt", 0, 0, 0, 7, 0, "" }, /* smallcptr */
676{ "property", 0, 0, 0, 7, 0, "" }, /* smallcptr */
677{ "pubdate", 0, 0, 0, 4, 0, "" }, /* docinfo */
678{ "publishername",0, 0, 0, 4, 0, "" }, /* docinfo */
679{ "publisher", 0, 0, 0, 9, 0, "" }, /* publishername */
680{ "pubsnumber", 0, 0, 0, 4, 0, "" }, /* docinfo */
681{ "qandadiv", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
682{ "qandaentry", 0, 0, 0, 9, 0, "" }, /* revhistory */
683{ "qandaset", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
684{ "question", 0, 0, 0, 9, 0, "" }, /* label */
685{ "quote", 0, 0, 0, 2, 0, "" }, /* para */
686{ "refclass", 0, 0, 0, 9, 0, "" }, /* refclass.char.mix */
687{ "refdescriptor",0, 0, 0, 9, 0, "" }, /* refname.char.mix */
688{ "refentryinfo",0, 0, 0, 9, 0, "" }, /* graphic */
689{ "refentry", 0, 0, 0, 9, 0, "" }, /* ndxterm.class */
690{ "refentrytitle",0, 0, 0, 2, 0, "" }, /* para */
691{ "referenceinfo",0, 0, 0, 9, 0, "" }, /* graphic */
692{ "reference", 0, 0, 0, 9, 0, "" }, /* referenceinfo */
693{ "refmeta", 0, 0, 0, 9, 0, "" }, /* ndxterm.class */
694{ "refmiscinfo",0, 0, 0, 4, 0, "" }, /* docinfo */
695{ "refnamediv", 0, 0, 0, 9, 0, "" }, /* refdescriptor */
696{ "refname", 0, 0, 0, 9, 0, "" }, /* refname.char.mix */
697{ "refpurpose", 0, 0, 0, 9, 0, "" }, /* refinline.char.mix */
698{ "refsect1info",0, 0, 0, 9, 0, "" }, /* graphic */
699{ "refsect1", 0, 0, 0, 9, 0, "" }, /* refsect */
700{ "refsect2info",0, 0, 0, 9, 0, "" }, /* graphic */
701{ "refsect2", 0, 0, 0, 9, 0, "" }, /* refsect */
702{ "refsect3info",0, 0, 0, 9, 0, "" }, /* graphic */
703{ "refsect3", 0, 0, 0, 9, 0, "" }, /* refsect */
704{ "refsynopsisdivinfo",0,0, 0, 9, 0, "" }, /* graphic */
705{ "refsynopsisdiv",0, 0, 0, 9, 0, "" }, /* refsynopsisdivinfo */
706{ "releaseinfo",0, 0, 0, 4, 0, "" }, /* docinfo */
707{ "remark", 0, 0, 0, 2, 0, "" }, /* para */
708{ "replaceable",0, 0, 0, 1, 0, "" },
709{ "returnvalue",0, 0, 0, 7, 0, "" }, /* smallcptr */
710{ "revdescription",0, 0, 0, 9, 0, "" }, /* revdescription.mix */
711{ "revhistory", 0, 0, 0, 9, 0, "" }, /* revision */
712{ "revision", 0, 0, 0, 9, 0, "" }, /* revnumber */
713{ "revnumber", 0, 0, 0, 4, 0, "" }, /* docinfo */
714{ "revremark", 0, 0, 0, 4, 0, "" }, /* docinfo */
715{ "row", 0, 0, 0, 9, 0, "" }, /* tbl.row.mdl */
716{ "row", 0, 0, 0, 9, 0, "" }, /* tbl.row.mdl */
717{ "sbr", 0, 2, 1, 0, 0, "" },
718{ "screenco", 0, 0, 0, 9, 0, "" }, /* areaspec */
719{ "screeninfo", 0, 0, 0, 2, 0, "" }, /* para */
720{ "screen", 0, 0, 0, 2, 0, "" }, /* para */
721{ "screenshot", 0, 0, 0, 9, 0, "" }, /* screeninfo */
722{ "secondaryie",0, 0, 0, 4, 0, "" }, /* ndxterm */
723{ "secondary", 0, 0, 0, 4, 0, "" }, /* ndxterm */
724{ "sect1info", 0, 0, 0, 9, 0, "" }, /* graphic */
725{ "sect1", 0, 0, 0, 9, 0, "" }, /* sect */
726{ "sect2info", 0, 0, 0, 9, 0, "" }, /* graphic */
727{ "sect2", 0, 0, 0, 9, 0, "" }, /* sect */
728{ "sect3info", 0, 0, 0, 9, 0, "" }, /* graphic */
729{ "sect3", 0, 0, 0, 9, 0, "" }, /* sect */
730{ "sect4info", 0, 0, 0, 9, 0, "" }, /* graphic */
731{ "sect4", 0, 0, 0, 9, 0, "" }, /* sect */
732{ "sect5info", 0, 0, 0, 9, 0, "" }, /* graphic */
733{ "sect5", 0, 0, 0, 9, 0, "" }, /* sect */
734{ "sectioninfo",0, 0, 0, 9, 0, "" }, /* graphic */
735{ "section", 0, 0, 0, 9, 0, "" }, /* sectioninfo */
736{ "seealsoie", 0, 0, 0, 4, 0, "" }, /* ndxterm */
737{ "seealso", 0, 0, 0, 4, 0, "" }, /* ndxterm */
738{ "seeie", 0, 0, 0, 4, 0, "" }, /* ndxterm */
739{ "see", 0, 0, 0, 4, 0, "" }, /* ndxterm */
740{ "seglistitem",0, 0, 0, 9, 0, "" }, /* seg */
741{ "segmentedlist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
742{ "seg", 0, 0, 0, 2, 0, "" }, /* para */
743{ "segtitle", 0, 0, 0, 8, 0, "" }, /* title */
744{ "seriesvolnums", 0, 0, 0, 4, 0, "" }, /* docinfo */
745{ "set", 0, 0, 0, 9, 0, "" }, /* div.title.content */
746{ "setindexinfo",0, 0, 0, 9, 0, "" }, /* graphic */
747{ "setindex", 0, 0, 0, 9, 0, "" }, /* setindexinfo */
748{ "setinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
749{ "sgmltag", 0, 0, 0, 7, 0, "" }, /* smallcptr */
750{ "shortaffil", 0, 0, 0, 4, 0, "" }, /* docinfo */
751{ "shortcut", 0, 0, 0, 9, 0, "" }, /* keycap */
752{ "sidebarinfo",0, 0, 0, 9, 0, "" }, /* graphic */
753{ "sidebar", 0, 0, 0, 9, 0, "" }, /* sidebarinfo */
754{ "simpara", 0, 0, 0, 2, 0, "" }, /* para */
755{ "simplelist", 0, 0, 0, 9, 0, "" }, /* member */
756{ "simplemsgentry", 0, 0, 0, 9, 0, "" }, /* msgtext */
757{ "simplesect", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
758{ "spanspec", 0, 2, 1, 0, 0, "" },
759{ "state", 0, 0, 0, 4, 0, "" }, /* docinfo */
760{ "step", 0, 0, 0, 9, 0, "" }, /* title */
761{ "street", 0, 0, 0, 4, 0, "" }, /* docinfo */
762{ "structfield",0, 0, 0, 7, 0, "" }, /* smallcptr */
763{ "structname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
764{ "subjectset", 0, 0, 0, 9, 0, "" }, /* subject */
765{ "subject", 0, 0, 0, 9, 0, "" }, /* subjectterm */
766{ "subjectterm",0, 0, 0, 1, 0, "" },
767{ "subscript", 0, 0, 0, 1, 0, "" },
768{ "substeps", 0, 0, 0, 9, 0, "" }, /* step */
769{ "subtitle", 0, 0, 0, 8, 0, "" }, /* title */
770{ "superscript", 0, 0, 0, 1, 0, "" },
771{ "surname", 0, 0, 0, 4, 0, "" }, /* docinfo */
772{ "symbol", 0, 0, 0, 7, 0, "" }, /* smallcptr */
773{ "synopfragment", 0, 0, 0, 9, 0, "" }, /* arg */
774{ "synopfragmentref", 0, 0, 0, 1, 0, "" },
775{ "synopsis", 0, 0, 0, 2, 0, "" }, /* para */
776{ "systemitem", 0, 0, 0, 7, 0, "" }, /* smallcptr */
777{ "table", 0, 0, 0, 9, 0, "" }, /* tbl.table.mdl */
778/* { "%tbl.table.name;", 0, 0, 0, 9, 0, "" },*/ /* tbl.table.mdl */
779{ "tbody", 0, 0, 0, 9, 0, "" }, /* row */
780{ "tbody", 0, 0, 0, 9, 0, "" }, /* row */
781{ "term", 0, 0, 0, 2, 0, "" }, /* para */
782{ "tertiaryie", 0, 0, 0, 4, 0, "" }, /* ndxterm */
783{ "tertiary ", 0, 0, 0, 4, 0, "" }, /* ndxterm */
784{ "textobject", 0, 0, 0, 9, 0, "" }, /* objectinfo */
785{ "tfoot", 0, 0, 0, 9, 0, "" }, /* tbl.hdft.mdl */
786{ "tgroup", 0, 0, 0, 9, 0, "" }, /* tbl.tgroup.mdl */
787{ "tgroup", 0, 0, 0, 9, 0, "" }, /* tbl.tgroup.mdl */
788{ "thead", 0, 0, 0, 9, 0, "" }, /* row */
789{ "thead", 0, 0, 0, 9, 0, "" }, /* tbl.hdft.mdl */
790{ "tip", 0, 0, 0, 9, 0, "" }, /* title */
791{ "titleabbrev",0, 0, 0, 8, 0, "" }, /* title */
792{ "title", 0, 0, 0, 8, 0, "" }, /* title */
793{ "tocback", 0, 0, 0, 2, 0, "" }, /* para */
794{ "toc", 0, 0, 0, 9, 0, "" }, /* bookcomponent.title.content */
795{ "tocchap", 0, 0, 0, 9, 0, "" }, /* tocentry */
796{ "tocentry", 0, 0, 0, 2, 0, "" }, /* para */
797{ "tocfront", 0, 0, 0, 2, 0, "" }, /* para */
798{ "toclevel1", 0, 0, 0, 9, 0, "" }, /* tocentry */
799{ "toclevel2", 0, 0, 0, 9, 0, "" }, /* tocentry */
800{ "toclevel3", 0, 0, 0, 9, 0, "" }, /* tocentry */
801{ "toclevel4", 0, 0, 0, 9, 0, "" }, /* tocentry */
802{ "toclevel5", 0, 0, 0, 9, 0, "" }, /* tocentry */
803{ "tocpart", 0, 0, 0, 9, 0, "" }, /* tocentry */
804{ "token", 0, 0, 0, 7, 0, "" }, /* smallcptr */
805{ "trademark", 0, 0, 0, 1, 0, "" },
806{ "type", 0, 0, 0, 7, 0, "" }, /* smallcptr */
807{ "ulink", 0, 0, 0, 2, 0, "" }, /* para */
808{ "userinput", 0, 0, 0, 9, 0, "" }, /* cptr */
809{ "varargs", 0, 2, 1, 0, 0, "" },
810{ "variablelist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
811{ "varlistentry",0, 0, 0, 9, 0, "" }, /* term */
812{ "varname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
813{ "videodata", 0, 2, 1, 0, 0, "" },
814{ "videoobject",0, 0, 0, 9, 0, "" }, /* objectinfo */
815{ "void", 0, 2, 1, 0, 0, "" },
816{ "volumenum", 0, 0, 0, 4, 0, "" }, /* docinfo */
817{ "warning", 0, 0, 0, 9, 0, "" }, /* title */
818{ "wordasword", 0, 0, 0, 3, 0, "" }, /* word */
819{ "xref", 0, 2, 1, 0, 0, "" },
820{ "year", 0, 0, 0, 4, 0, "" }, /* docinfo */
821};
822
823#if 0
824/*
825 * start tags that imply the end of a current element
826 * any tag of each line implies the end of the current element if the type of
827 * that element is in the same line
828 */
829static const char *docbEquEnd[] = {
830"dt", "dd", "li", "option", NULL,
831"h1", "h2", "h3", "h4", "h5", "h6", NULL,
832"ol", "menu", "dir", "address", "pre", "listing", "xmp", NULL,
833NULL
834};
835#endif
836
837/*
838 * acording the SGML DTD, HR should be added to the 2nd line above, as it
839 * is not allowed within a H1, H2, H3, etc. But we should tolerate that case
840 * because many documents contain rules in headings...
841 */
842
843/*
844 * start tags that imply the end of current element
845 */
846static const char *docbStartClose[] = {
847NULL
848};
849
850/*
851 * The list of SGML elements which are supposed not to have
852 * CDATA content and where a p element will be implied
853 *
854 * TODO: extend that list by reading the SGML SGML DtD on
855 * implied paragraph
856 */
857static char *docbNoContentElements[] = {
858 NULL
859};
860
861
862static const char** docbStartCloseIndex[100];
863static int docbStartCloseIndexinitialized = 0;
864
865/************************************************************************
866 * *
867 * functions to handle SGML specific data *
868 * *
869 ************************************************************************/
870
871/**
872 * docbInitAutoClose:
873 *
874 * Initialize the docbStartCloseIndex for fast lookup of closing tags names.
875 *
876 */
877static void
878docbInitAutoClose(void) {
879 int indx, i = 0;
880
881 if (docbStartCloseIndexinitialized) return;
882
883 for (indx = 0;indx < 100;indx ++) docbStartCloseIndex[indx] = NULL;
884 indx = 0;
885 while ((docbStartClose[i] != NULL) && (indx < 100 - 1)) {
886 docbStartCloseIndex[indx++] = &docbStartClose[i];
887 while (docbStartClose[i] != NULL) i++;
888 i++;
889 }
890}
891
892/**
893 * docbTagLookup:
894 * @tag: The tag name
895 *
896 * Lookup the SGML tag in the ElementTable
897 *
898 * Returns the related docbElemDescPtr or NULL if not found.
899 */
900static docbElemDescPtr
901docbTagLookup(const xmlChar *tag) {
902 unsigned int i;
903
904 for (i = 0; i < (sizeof(docbookElementTable) /
905 sizeof(docbookElementTable[0]));i++) {
906 if (xmlStrEqual(tag, BAD_CAST docbookElementTable[i].name))
907 return(&docbookElementTable[i]);
908 }
909 return(NULL);
910}
911
912/**
913 * docbCheckAutoClose:
914 * @newtag: The new tag name
915 * @oldtag: The old tag name
916 *
917 * Checks wether the new tag is one of the registered valid tags for closing old.
918 * Initialize the docbStartCloseIndex for fast lookup of closing tags names.
919 *
920 * Returns 0 if no, 1 if yes.
921 */
922static int
923docbCheckAutoClose(const xmlChar *newtag, const xmlChar *oldtag) {
924 int i, indx;
925 const char **closed = NULL;
926
927 if (docbStartCloseIndexinitialized == 0) docbInitAutoClose();
928
929 /* inefficient, but not a big deal */
930 for (indx = 0; indx < 100;indx++) {
931 closed = docbStartCloseIndex[indx];
932 if (closed == NULL) return(0);
933 if (xmlStrEqual(BAD_CAST *closed, newtag)) break;
934 }
935
936 i = closed - docbStartClose;
937 i++;
938 while (docbStartClose[i] != NULL) {
939 if (xmlStrEqual(BAD_CAST docbStartClose[i], oldtag)) {
940 return(1);
941 }
942 i++;
943 }
944 return(0);
945}
946
947/**
948 * docbAutoCloseOnClose:
949 * @ctxt: an SGML parser context
950 * @newtag: The new tag name
951 *
952 * The HTmL DtD allows an ending tag to implicitely close other tags.
953 */
954static void
955docbAutoCloseOnClose(docbParserCtxtPtr ctxt, const xmlChar *newtag) {
956 docbElemDescPtr info;
957 xmlChar *oldname;
958 int i;
959
960 if ((newtag[0] == '/') && (newtag[1] == 0))
961 return;
962
963#ifdef DEBUG
964 xmlGenericError(xmlGenericErrorContext,"Close of %s stack: %d elements\n", newtag, ctxt->nameNr);
965 for (i = 0;i < ctxt->nameNr;i++)
966 xmlGenericError(xmlGenericErrorContext,"%d : %s\n", i, ctxt->nameTab[i]);
967#endif
968
969 for (i = (ctxt->nameNr - 1);i >= 0;i--) {
970 if (xmlStrEqual(newtag, ctxt->nameTab[i])) break;
971 }
972 if (i < 0) return;
973
974 while (!xmlStrEqual(newtag, ctxt->name)) {
975 info = docbTagLookup(ctxt->name);
976 if ((info == NULL) || (info->endTag == 1)) {
977#ifdef DEBUG
978 xmlGenericError(xmlGenericErrorContext,"docbAutoCloseOnClose: %s closes %s\n", newtag, ctxt->name);
979#endif
980 } else {
981 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
982 ctxt->sax->error(ctxt->userData,
983 "Opening and ending tag mismatch: %s and %s\n",
984 newtag, ctxt->name);
985 ctxt->wellFormed = 0;
986 }
987 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
988 ctxt->sax->endElement(ctxt->userData, ctxt->name);
989 oldname = docbnamePop(ctxt);
990 if (oldname != NULL) {
991#ifdef DEBUG
992 xmlGenericError(xmlGenericErrorContext,"docbAutoCloseOnClose: popped %s\n", oldname);
993#endif
994 xmlFree(oldname);
995 }
996 }
997}
998
999/**
1000 * docbAutoClose:
1001 * @ctxt: an SGML parser context
1002 * @newtag: The new tag name or NULL
1003 *
1004 * The HTmL DtD allows a tag to implicitely close other tags.
1005 * The list is kept in docbStartClose array. This function is
1006 * called when a new tag has been detected and generates the
1007 * appropriates closes if possible/needed.
1008 * If newtag is NULL this mean we are at the end of the resource
1009 * and we should check
1010 */
1011static void
1012docbAutoClose(docbParserCtxtPtr ctxt, const xmlChar *newtag) {
1013 xmlChar *oldname;
1014 while ((newtag != NULL) && (ctxt->name != NULL) &&
1015 (docbCheckAutoClose(newtag, ctxt->name))) {
1016#ifdef DEBUG
1017 xmlGenericError(xmlGenericErrorContext,"docbAutoClose: %s closes %s\n", newtag, ctxt->name);
1018#endif
1019 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
1020 ctxt->sax->endElement(ctxt->userData, ctxt->name);
1021 oldname = docbnamePop(ctxt);
1022 if (oldname != NULL) {
1023#ifdef DEBUG
1024 xmlGenericError(xmlGenericErrorContext,"docbAutoClose: popped %s\n", oldname);
1025#endif
1026 xmlFree(oldname);
1027 }
1028 }
1029}
1030
1031/**
1032 * docbAutoCloseTag:
1033 * @doc: the SGML document
1034 * @name: The tag name
1035 * @elem: the SGML element
1036 *
1037 * The HTmL DtD allows a tag to implicitely close other tags.
1038 * The list is kept in docbStartClose array. This function checks
1039 * if the element or one of it's children would autoclose the
1040 * given tag.
1041 *
1042 * Returns 1 if autoclose, 0 otherwise
1043 */
1044static int
1045docbAutoCloseTag(docbDocPtr doc, const xmlChar *name, docbNodePtr elem) {
1046 docbNodePtr child;
1047
1048 if (elem == NULL) return(1);
1049 if (xmlStrEqual(name, elem->name)) return(0);
1050 if (docbCheckAutoClose(elem->name, name)) return(1);
1051 child = elem->children;
1052 while (child != NULL) {
1053 if (docbAutoCloseTag(doc, name, child)) return(1);
1054 child = child->next;
1055 }
1056 return(0);
1057}
1058
1059#if 0
1060/**
1061 * docbIsAutoClosed:
1062 * @doc: the SGML document
1063 * @elem: the SGML element
1064 *
1065 * The list is kept in docbStartClose array. This function checks
1066 * if a tag is autoclosed by one of it's child
1067 *
1068 * Returns 1 if autoclosed, 0 otherwise
1069 */
1070static int
1071docbIsAutoClosed(docbDocPtr doc, docbNodePtr elem) {
1072 docbNodePtr child;
1073
1074 if (elem == NULL) return(1);
1075 child = elem->children;
1076 while (child != NULL) {
1077 if (docbAutoCloseTag(doc, elem->name, child)) return(1);
1078 child = child->next;
1079 }
1080 return(0);
1081}
1082#endif
1083
1084/**
1085 * docbCheckParagraph
1086 * @ctxt: an SGML parser context
1087 *
1088 * Check whether a p element need to be implied before inserting
1089 * characters in the current element.
1090 *
1091 * Returns 1 if a paragraph has been inserted, 0 if not and -1
1092 * in case of error.
1093 */
1094
1095static int
1096docbCheckParagraph(docbParserCtxtPtr ctxt) {
1097 const xmlChar *tag;
1098 int i;
1099
1100 if (ctxt == NULL)
1101 return(-1);
1102 tag = ctxt->name;
1103 if (tag == NULL) {
1104 docbAutoClose(ctxt, BAD_CAST"p");
1105 docbnamePush(ctxt, xmlStrdup(BAD_CAST"p"));
1106 if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL))
1107 ctxt->sax->startElement(ctxt->userData, BAD_CAST"p", NULL);
1108 return(1);
1109 }
1110 for (i = 0; docbNoContentElements[i] != NULL; i++) {
1111 if (xmlStrEqual(tag, BAD_CAST docbNoContentElements[i])) {
1112#ifdef DEBUG
1113 xmlGenericError(xmlGenericErrorContext,"Implied element paragraph\n");
1114#endif
1115 docbAutoClose(ctxt, BAD_CAST"p");
1116 docbnamePush(ctxt, xmlStrdup(BAD_CAST"p"));
1117 if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL))
1118 ctxt->sax->startElement(ctxt->userData, BAD_CAST"p", NULL);
1119 return(1);
1120 }
1121 }
1122 return(0);
1123}
1124
1125/************************************************************************
1126 * *
1127 * The list of SGML predefined entities *
1128 * *
1129 ************************************************************************/
1130
1131
1132static docbEntityDesc
1133docbookEntitiesTable[] = {
1134/*
1135 * the 4 absolute ones, plus apostrophe.
1136 */
1137{ 0x0026, "amp", "AMPERSAND" },
1138{ 0x003C, "lt", "LESS-THAN SIGN" },
1139
1140/*
1141 * Converted with VI macros from docbook ent files
1142 */
1143{ 0x0021, "excl", "EXCLAMATION MARK" },
1144{ 0x0022, "quot", "QUOTATION MARK" },
1145{ 0x0023, "num", "NUMBER SIGN" },
1146{ 0x0024, "dollar", "DOLLAR SIGN" },
1147{ 0x0025, "percnt", "PERCENT SIGN" },
1148{ 0x0027, "apos", "APOSTROPHE" },
1149{ 0x0028, "lpar", "LEFT PARENTHESIS" },
1150{ 0x0029, "rpar", "RIGHT PARENTHESIS" },
1151{ 0x002A, "ast", "ASTERISK OPERATOR" },
1152{ 0x002B, "plus", "PLUS SIGN" },
1153{ 0x002C, "comma", "COMMA" },
1154{ 0x002D, "hyphen", "HYPHEN-MINUS" },
1155{ 0x002E, "period", "FULL STOP" },
1156{ 0x002F, "sol", "SOLIDUS" },
1157{ 0x003A, "colon", "COLON" },
1158{ 0x003B, "semi", "SEMICOLON" },
1159{ 0x003D, "equals", "EQUALS SIGN" },
1160{ 0x003E, "gt", "GREATER-THAN SIGN" },
1161{ 0x003F, "quest", "QUESTION MARK" },
1162{ 0x0040, "commat", "COMMERCIAL AT" },
1163{ 0x005B, "lsqb", "LEFT SQUARE BRACKET" },
1164{ 0x005C, "bsol", "REVERSE SOLIDUS" },
1165{ 0x005D, "rsqb", "RIGHT SQUARE BRACKET" },
1166{ 0x005E, "circ", "RING OPERATOR" },
1167{ 0x005F, "lowbar", "LOW LINE" },
1168{ 0x0060, "grave", "GRAVE ACCENT" },
1169{ 0x007B, "lcub", "LEFT CURLY BRACKET" },
1170{ 0x007C, "verbar", "VERTICAL LINE" },
1171{ 0x007D, "rcub", "RIGHT CURLY BRACKET" },
1172{ 0x00A0, "nbsp", "NO-BREAK SPACE" },
1173{ 0x00A1, "iexcl", "INVERTED EXCLAMATION MARK" },
1174{ 0x00A2, "cent", "CENT SIGN" },
1175{ 0x00A3, "pound", "POUND SIGN" },
1176{ 0x00A4, "curren", "CURRENCY SIGN" },
1177{ 0x00A5, "yen", "YEN SIGN" },
1178{ 0x00A6, "brvbar", "BROKEN BAR" },
1179{ 0x00A7, "sect", "SECTION SIGN" },
1180{ 0x00A8, "die", "" },
1181{ 0x00A8, "Dot", "" },
1182{ 0x00A8, "uml", "" },
1183{ 0x00A9, "copy", "COPYRIGHT SIGN" },
1184{ 0x00AA, "ordf", "FEMININE ORDINAL INDICATOR" },
1185{ 0x00AB, "laquo", "LEFT-POINTING DOUBLE ANGLE QUOTATION MARK" },
1186{ 0x00AC, "not", "NOT SIGN" },
1187{ 0x00AD, "shy", "SOFT HYPHEN" },
1188{ 0x00AE, "reg", "REG TRADE MARK SIGN" },
1189{ 0x00AF, "macr", "MACRON" },
1190{ 0x00B0, "deg", "DEGREE SIGN" },
1191{ 0x00B1, "plusmn", "PLUS-MINUS SIGN" },
1192{ 0x00B2, "sup2", "SUPERSCRIPT TWO" },
1193{ 0x00B3, "sup3", "SUPERSCRIPT THREE" },
1194{ 0x00B4, "acute", "ACUTE ACCENT" },
1195{ 0x00B5, "micro", "MICRO SIGN" },
1196{ 0x00B6, "para", "PILCROW SIGN" },
1197{ 0x00B7, "middot", "MIDDLE DOT" },
1198{ 0x00B8, "cedil", "CEDILLA" },
1199{ 0x00B9, "sup1", "SUPERSCRIPT ONE" },
1200{ 0x00BA, "ordm", "MASCULINE ORDINAL INDICATOR" },
1201{ 0x00BB, "raquo", "RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK" },
1202{ 0x00BC, "frac14", "VULGAR FRACTION ONE QUARTER" },
1203{ 0x00BD, "frac12", "VULGAR FRACTION ONE HALF" },
1204{ 0x00BD, "half", "VULGAR FRACTION ONE HALF" },
1205{ 0x00BE, "frac34", "VULGAR FRACTION THREE QUARTERS" },
1206{ 0x00BF, "iquest", "INVERTED QUESTION MARK" },
1207{ 0x00C0, "Agrave", "LATIN CAPITAL LETTER A WITH GRAVE" },
1208{ 0x00C1, "Aacute", "LATIN CAPITAL LETTER A WITH ACUTE" },
1209{ 0x00C2, "Acirc", "LATIN CAPITAL LETTER A WITH CIRCUMFLEX" },
1210{ 0x00C3, "Atilde", "LATIN CAPITAL LETTER A WITH TILDE" },
1211{ 0x00C4, "Auml", "LATIN CAPITAL LETTER A WITH DIAERESIS" },
1212{ 0x00C5, "Aring", "LATIN CAPITAL LETTER A WITH RING ABOVE" },
1213{ 0x00C6, "AElig", "LATIN CAPITAL LETTER AE" },
1214{ 0x00C7, "Ccedil", "LATIN CAPITAL LETTER C WITH CEDILLA" },
1215{ 0x00C8, "Egrave", "LATIN CAPITAL LETTER E WITH GRAVE" },
1216{ 0x00C9, "Eacute", "LATIN CAPITAL LETTER E WITH ACUTE" },
1217{ 0x00CA, "Ecirc", "LATIN CAPITAL LETTER E WITH CIRCUMFLEX" },
1218{ 0x00CB, "Euml", "LATIN CAPITAL LETTER E WITH DIAERESIS" },
1219{ 0x00CC, "Igrave", "LATIN CAPITAL LETTER I WITH GRAVE" },
1220{ 0x00CD, "Iacute", "LATIN CAPITAL LETTER I WITH ACUTE" },
1221{ 0x00CE, "Icirc", "LATIN CAPITAL LETTER I WITH CIRCUMFLEX" },
1222{ 0x00CF, "Iuml", "LATIN CAPITAL LETTER I WITH DIAERESIS" },
1223{ 0x00D0, "ETH", "LATIN CAPITAL LETTER ETH" },
1224{ 0x00D1, "Ntilde", "LATIN CAPITAL LETTER N WITH TILDE" },
1225{ 0x00D2, "Ograve", "LATIN CAPITAL LETTER O WITH GRAVE" },
1226{ 0x00D3, "Oacute", "LATIN CAPITAL LETTER O WITH ACUTE" },
1227{ 0x00D4, "Ocirc", "LATIN CAPITAL LETTER O WITH CIRCUMFLEX" },
1228{ 0x00D5, "Otilde", "LATIN CAPITAL LETTER O WITH TILDE" },
1229{ 0x00D6, "Ouml", "LATIN CAPITAL LETTER O WITH DIAERESIS" },
1230{ 0x00D7, "times", "MULTIPLICATION SIGN" },
1231{ 0x00D8, "Oslash", "LATIN CAPITAL LETTER O WITH STROKE" },
1232{ 0x00D9, "Ugrave", "LATIN CAPITAL LETTER U WITH GRAVE" },
1233{ 0x00DA, "Uacute", "LATIN CAPITAL LETTER U WITH ACUTE" },
1234{ 0x00DB, "Ucirc", "LATIN CAPITAL LETTER U WITH CIRCUMFLEX" },
1235{ 0x00DC, "Uuml", "LATIN CAPITAL LETTER U WITH DIAERESIS" },
1236{ 0x00DD, "Yacute", "LATIN CAPITAL LETTER Y WITH ACUTE" },
1237{ 0x00DE, "THORN", "LATIN CAPITAL LETTER THORN" },
1238{ 0x00DF, "szlig", "LATIN SMALL LETTER SHARP S" },
1239{ 0x00E0, "agrave", "LATIN SMALL LETTER A WITH GRAVE" },
1240{ 0x00E1, "aacute", "LATIN SMALL LETTER A WITH ACUTE" },
1241{ 0x00E2, "acirc", "LATIN SMALL LETTER A WITH CIRCUMFLEX" },
1242{ 0x00E3, "atilde", "LATIN SMALL LETTER A WITH TILDE" },
1243{ 0x00E4, "auml", "LATIN SMALL LETTER A WITH DIAERESIS" },
1244{ 0x00E5, "aring", "LATIN SMALL LETTER A WITH RING ABOVE" },
1245{ 0x00E6, "aelig", "LATIN SMALL LETTER AE" },
1246{ 0x00E7, "ccedil", "LATIN SMALL LETTER C WITH CEDILLA" },
1247{ 0x00E8, "egrave", "LATIN SMALL LETTER E WITH GRAVE" },
1248{ 0x00E9, "eacute", "LATIN SMALL LETTER E WITH ACUTE" },
1249{ 0x00EA, "ecirc", "LATIN SMALL LETTER E WITH CIRCUMFLEX" },
1250{ 0x00EB, "euml", "LATIN SMALL LETTER E WITH DIAERESIS" },
1251{ 0x00EC, "igrave", "LATIN SMALL LETTER I WITH GRAVE" },
1252{ 0x00ED, "iacute", "LATIN SMALL LETTER I WITH ACUTE" },
1253{ 0x00EE, "icirc", "LATIN SMALL LETTER I WITH CIRCUMFLEX" },
1254{ 0x00EF, "iuml", "LATIN SMALL LETTER I WITH DIAERESIS" },
1255{ 0x00F0, "eth", "LATIN SMALL LETTER ETH" },
1256{ 0x00F1, "ntilde", "LATIN SMALL LETTER N WITH TILDE" },
1257{ 0x00F2, "ograve", "LATIN SMALL LETTER O WITH GRAVE" },
1258{ 0x00F3, "oacute", "LATIN SMALL LETTER O WITH ACUTE" },
1259{ 0x00F4, "ocirc", "LATIN SMALL LETTER O WITH CIRCUMFLEX" },
1260{ 0x00F5, "otilde", "LATIN SMALL LETTER O WITH TILDE" },
1261{ 0x00F6, "ouml", "LATIN SMALL LETTER O WITH DIAERESIS" },
1262{ 0x00F7, "divide", "DIVISION SIGN" },
1263{ 0x00F8, "oslash", "CIRCLED DIVISION SLASH" },
1264{ 0x00F9, "ugrave", "LATIN SMALL LETTER U WITH GRAVE" },
1265{ 0x00FA, "uacute", "LATIN SMALL LETTER U WITH ACUTE" },
1266{ 0x00FB, "ucirc", "LATIN SMALL LETTER U WITH CIRCUMFLEX" },
1267{ 0x00FC, "uuml", "LATIN SMALL LETTER U WITH DIAERESIS" },
1268{ 0x00FD, "yacute", "LATIN SMALL LETTER Y WITH ACUTE" },
1269{ 0x00FE, "thorn", "LATIN SMALL LETTER THORN" },
1270{ 0x00FF, "yuml", "LATIN SMALL LETTER Y WITH DIAERESIS" },
1271{ 0x0100, "Amacr", "LATIN CAPITAL LETTER A WITH MACRON" },
1272{ 0x0101, "amacr", "LATIN SMALL LETTER A WITH MACRON" },
1273{ 0x0102, "Abreve", "LATIN CAPITAL LETTER A WITH BREVE" },
1274{ 0x0103, "abreve", "LATIN SMALL LETTER A WITH BREVE" },
1275{ 0x0104, "Aogon", "LATIN CAPITAL LETTER A WITH OGONEK" },
1276{ 0x0105, "aogon", "LATIN SMALL LETTER A WITH OGONEK" },
1277{ 0x0106, "Cacute", "LATIN CAPITAL LETTER C WITH ACUTE" },
1278{ 0x0107, "cacute", "LATIN SMALL LETTER C WITH ACUTE" },
1279{ 0x0108, "Ccirc", "LATIN CAPITAL LETTER C WITH CIRCUMFLEX" },
1280{ 0x0109, "ccirc", "LATIN SMALL LETTER C WITH CIRCUMFLEX" },
1281{ 0x010A, "Cdot", "LATIN CAPITAL LETTER C WITH DOT ABOVE" },
1282{ 0x010B, "cdot", "DOT OPERATOR" },
1283{ 0x010C, "Ccaron", "LATIN CAPITAL LETTER C WITH CARON" },
1284{ 0x010D, "ccaron", "LATIN SMALL LETTER C WITH CARON" },
1285{ 0x010E, "Dcaron", "LATIN CAPITAL LETTER D WITH CARON" },
1286{ 0x010F, "dcaron", "LATIN SMALL LETTER D WITH CARON" },
1287{ 0x0110, "Dstrok", "LATIN CAPITAL LETTER D WITH STROKE" },
1288{ 0x0111, "dstrok", "LATIN SMALL LETTER D WITH STROKE" },
1289{ 0x0112, "Emacr", "LATIN CAPITAL LETTER E WITH MACRON" },
1290{ 0x0113, "emacr", "LATIN SMALL LETTER E WITH MACRON" },
1291{ 0x0116, "Edot", "LATIN CAPITAL LETTER E WITH DOT ABOVE" },
1292{ 0x0117, "edot", "LATIN SMALL LETTER E WITH DOT ABOVE" },
1293{ 0x0118, "Eogon", "LATIN CAPITAL LETTER E WITH OGONEK" },
1294{ 0x0119, "eogon", "LATIN SMALL LETTER E WITH OGONEK" },
1295{ 0x011A, "Ecaron", "LATIN CAPITAL LETTER E WITH CARON" },
1296{ 0x011B, "ecaron", "LATIN SMALL LETTER E WITH CARON" },
1297{ 0x011C, "Gcirc", "LATIN CAPITAL LETTER G WITH CIRCUMFLEX" },
1298{ 0x011D, "gcirc", "LATIN SMALL LETTER G WITH CIRCUMFLEX" },
1299{ 0x011E, "Gbreve", "LATIN CAPITAL LETTER G WITH BREVE" },
1300{ 0x011F, "gbreve", "LATIN SMALL LETTER G WITH BREVE" },
1301{ 0x0120, "Gdot", "LATIN CAPITAL LETTER G WITH DOT ABOVE" },
1302{ 0x0121, "gdot", "LATIN SMALL LETTER G WITH DOT ABOVE" },
1303{ 0x0122, "Gcedil", "LATIN CAPITAL LETTER G WITH CEDILLA" },
1304{ 0x0124, "Hcirc", "LATIN CAPITAL LETTER H WITH CIRCUMFLEX" },
1305{ 0x0125, "hcirc", "LATIN SMALL LETTER H WITH CIRCUMFLEX" },
1306{ 0x0126, "Hstrok", "LATIN CAPITAL LETTER H WITH STROKE" },
1307{ 0x0127, "hstrok", "LATIN SMALL LETTER H WITH STROKE" },
1308{ 0x0128, "Itilde", "LATIN CAPITAL LETTER I WITH TILDE" },
1309{ 0x0129, "itilde", "LATIN SMALL LETTER I WITH TILDE" },
1310{ 0x012A, "Imacr", "LATIN CAPITAL LETTER I WITH MACRON" },
1311{ 0x012B, "imacr", "LATIN SMALL LETTER I WITH MACRON" },
1312{ 0x012E, "Iogon", "LATIN CAPITAL LETTER I WITH OGONEK" },
1313{ 0x012F, "iogon", "LATIN SMALL LETTER I WITH OGONEK" },
1314{ 0x0130, "Idot", "LATIN CAPITAL LETTER I WITH DOT ABOVE" },
1315{ 0x0131, "inodot", "LATIN SMALL LETTER DOTLESS I" },
1316{ 0x0131, "inodot", "LATIN SMALL LETTER DOTLESS I" },
1317{ 0x0132, "IJlig", "LATIN CAPITAL LIGATURE IJ" },
1318{ 0x0133, "ijlig", "LATIN SMALL LIGATURE IJ" },
1319{ 0x0134, "Jcirc", "LATIN CAPITAL LETTER J WITH CIRCUMFLEX" },
1320{ 0x0135, "jcirc", "LATIN SMALL LETTER J WITH CIRCUMFLEX" },
1321{ 0x0136, "Kcedil", "LATIN CAPITAL LETTER K WITH CEDILLA" },
1322{ 0x0137, "kcedil", "LATIN SMALL LETTER K WITH CEDILLA" },
1323{ 0x0138, "kgreen", "LATIN SMALL LETTER KRA" },
1324{ 0x0139, "Lacute", "LATIN CAPITAL LETTER L WITH ACUTE" },
1325{ 0x013A, "lacute", "LATIN SMALL LETTER L WITH ACUTE" },
1326{ 0x013B, "Lcedil", "LATIN CAPITAL LETTER L WITH CEDILLA" },
1327{ 0x013C, "lcedil", "LATIN SMALL LETTER L WITH CEDILLA" },
1328{ 0x013D, "Lcaron", "LATIN CAPITAL LETTER L WITH CARON" },
1329{ 0x013E, "lcaron", "LATIN SMALL LETTER L WITH CARON" },
1330{ 0x013F, "Lmidot", "LATIN CAPITAL LETTER L WITH MIDDLE DOT" },
1331{ 0x0140, "lmidot", "LATIN SMALL LETTER L WITH MIDDLE DOT" },
1332{ 0x0141, "Lstrok", "LATIN CAPITAL LETTER L WITH STROKE" },
1333{ 0x0142, "lstrok", "LATIN SMALL LETTER L WITH STROKE" },
1334{ 0x0143, "Nacute", "LATIN CAPITAL LETTER N WITH ACUTE" },
1335{ 0x0144, "nacute", "LATIN SMALL LETTER N WITH ACUTE" },
1336{ 0x0145, "Ncedil", "LATIN CAPITAL LETTER N WITH CEDILLA" },
1337{ 0x0146, "ncedil", "LATIN SMALL LETTER N WITH CEDILLA" },
1338{ 0x0147, "Ncaron", "LATIN CAPITAL LETTER N WITH CARON" },
1339{ 0x0148, "ncaron", "LATIN SMALL LETTER N WITH CARON" },
1340{ 0x0149, "napos", "LATIN SMALL LETTER N PRECEDED BY APOSTROPHE" },
1341{ 0x014A, "ENG", "LATIN CAPITAL LETTER ENG" },
1342{ 0x014B, "eng", "LATIN SMALL LETTER ENG" },
1343{ 0x014C, "Omacr", "LATIN CAPITAL LETTER O WITH MACRON" },
1344{ 0x014D, "omacr", "LATIN SMALL LETTER O WITH MACRON" },
1345{ 0x0150, "Odblac", "LATIN CAPITAL LETTER O WITH DOUBLE ACUTE" },
1346{ 0x0151, "odblac", "LATIN SMALL LETTER O WITH DOUBLE ACUTE" },
1347{ 0x0152, "OElig", "LATIN CAPITAL LIGATURE OE" },
1348{ 0x0153, "oelig", "LATIN SMALL LIGATURE OE" },
1349{ 0x0154, "Racute", "LATIN CAPITAL LETTER R WITH ACUTE" },
1350{ 0x0155, "racute", "LATIN SMALL LETTER R WITH ACUTE" },
1351{ 0x0156, "Rcedil", "LATIN CAPITAL LETTER R WITH CEDILLA" },
1352{ 0x0157, "rcedil", "LATIN SMALL LETTER R WITH CEDILLA" },
1353{ 0x0158, "Rcaron", "LATIN CAPITAL LETTER R WITH CARON" },
1354{ 0x0159, "rcaron", "LATIN SMALL LETTER R WITH CARON" },
1355{ 0x015A, "Sacute", "LATIN CAPITAL LETTER S WITH ACUTE" },
1356{ 0x015B, "sacute", "LATIN SMALL LETTER S WITH ACUTE" },
1357{ 0x015C, "Scirc", "LATIN CAPITAL LETTER S WITH CIRCUMFLEX" },
1358{ 0x015D, "scirc", "LATIN SMALL LETTER S WITH CIRCUMFLEX" },
1359{ 0x015E, "Scedil", "LATIN CAPITAL LETTER S WITH CEDILLA" },
1360{ 0x015F, "scedil", "LATIN SMALL LETTER S WITH CEDILLA" },
1361{ 0x0160, "Scaron", "LATIN CAPITAL LETTER S WITH CARON" },
1362{ 0x0161, "scaron", "LATIN SMALL LETTER S WITH CARON" },
1363{ 0x0162, "Tcedil", "LATIN CAPITAL LETTER T WITH CEDILLA" },
1364{ 0x0163, "tcedil", "LATIN SMALL LETTER T WITH CEDILLA" },
1365{ 0x0164, "Tcaron", "LATIN CAPITAL LETTER T WITH CARON" },
1366{ 0x0165, "tcaron", "LATIN SMALL LETTER T WITH CARON" },
1367{ 0x0166, "Tstrok", "LATIN CAPITAL LETTER T WITH STROKE" },
1368{ 0x0167, "tstrok", "LATIN SMALL LETTER T WITH STROKE" },
1369{ 0x0168, "Utilde", "LATIN CAPITAL LETTER U WITH TILDE" },
1370{ 0x0169, "utilde", "LATIN SMALL LETTER U WITH TILDE" },
1371{ 0x016A, "Umacr", "LATIN CAPITAL LETTER U WITH MACRON" },
1372{ 0x016B, "umacr", "LATIN SMALL LETTER U WITH MACRON" },
1373{ 0x016C, "Ubreve", "LATIN CAPITAL LETTER U WITH BREVE" },
1374{ 0x016D, "ubreve", "LATIN SMALL LETTER U WITH BREVE" },
1375{ 0x016E, "Uring", "LATIN CAPITAL LETTER U WITH RING ABOVE" },
1376{ 0x016F, "uring", "LATIN SMALL LETTER U WITH RING ABOVE" },
1377{ 0x0170, "Udblac", "LATIN CAPITAL LETTER U WITH DOUBLE ACUTE" },
1378{ 0x0171, "udblac", "LATIN SMALL LETTER U WITH DOUBLE ACUTE" },
1379{ 0x0172, "Uogon", "LATIN CAPITAL LETTER U WITH OGONEK" },
1380{ 0x0173, "uogon", "LATIN SMALL LETTER U WITH OGONEK" },
1381{ 0x0174, "Wcirc", "LATIN CAPITAL LETTER W WITH CIRCUMFLEX" },
1382{ 0x0175, "wcirc", "LATIN SMALL LETTER W WITH CIRCUMFLEX" },
1383{ 0x0176, "Ycirc", "LATIN CAPITAL LETTER Y WITH CIRCUMFLEX" },
1384{ 0x0177, "ycirc", "LATIN SMALL LETTER Y WITH CIRCUMFLEX" },
1385{ 0x0178, "Yuml", "LATIN CAPITAL LETTER Y WITH DIAERESIS" },
1386{ 0x0179, "Zacute", "LATIN CAPITAL LETTER Z WITH ACUTE" },
1387{ 0x017A, "zacute", "LATIN SMALL LETTER Z WITH ACUTE" },
1388{ 0x017B, "Zdot", "LATIN CAPITAL LETTER Z WITH DOT ABOVE" },
1389{ 0x017C, "zdot", "LATIN SMALL LETTER Z WITH DOT ABOVE" },
1390{ 0x017D, "Zcaron", "LATIN CAPITAL LETTER Z WITH CARON" },
1391{ 0x017E, "zcaron", "LATIN SMALL LETTER Z WITH CARON" },
1392{ 0x0192, "fnof", "LATIN SMALL LETTER F WITH HOOK" },
1393{ 0x01F5, "gacute", "LATIN SMALL LETTER G WITH ACUTE" },
1394{ 0x02C7, "caron", "CARON" },
1395{ 0x02D8, "breve", "BREVE" },
1396{ 0x02D9, "dot", "DOT ABOVE" },
1397{ 0x02DA, "ring", "RING ABOVE" },
1398{ 0x02DB, "ogon", "OGONEK" },
1399{ 0x02DC, "tilde", "TILDE" },
1400{ 0x02DD, "dblac", "DOUBLE ACUTE ACCENT" },
1401{ 0x0386, "Aacgr", "GREEK CAPITAL LETTER ALPHA WITH TONOS" },
1402{ 0x0388, "Eacgr", "GREEK CAPITAL LETTER EPSILON WITH TONOS" },
1403{ 0x0389, "EEacgr", "GREEK CAPITAL LETTER ETA WITH TONOS" },
1404{ 0x038A, "Iacgr", "GREEK CAPITAL LETTER IOTA WITH TONOS" },
1405{ 0x038C, "Oacgr", "GREEK CAPITAL LETTER OMICRON WITH TONOS" },
1406{ 0x038E, "Uacgr", "GREEK CAPITAL LETTER UPSILON WITH TONOS" },
1407{ 0x038F, "OHacgr", "GREEK CAPITAL LETTER OMEGA WITH TONOS" },
1408{ 0x0390, "idiagr", "GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS" },
1409{ 0x0391, "Agr", "GREEK CAPITAL LETTER ALPHA" },
1410{ 0x0392, "Bgr", "GREEK CAPITAL LETTER BETA" },
1411{ 0x0393, "b.Gamma", "GREEK CAPITAL LETTER GAMMA" },
1412{ 0x0393, "Gamma", "GREEK CAPITAL LETTER GAMMA" },
1413{ 0x0393, "Ggr", "GREEK CAPITAL LETTER GAMMA" },
1414{ 0x0394, "b.Delta", "GREEK CAPITAL LETTER DELTA" },
1415{ 0x0394, "Delta", "GREEK CAPITAL LETTER DELTA" },
1416{ 0x0394, "Dgr", "GREEK CAPITAL LETTER DELTA" },
1417{ 0x0395, "Egr", "GREEK CAPITAL LETTER EPSILON" },
1418{ 0x0396, "Zgr", "GREEK CAPITAL LETTER ZETA" },
1419{ 0x0397, "EEgr", "GREEK CAPITAL LETTER ETA" },
1420{ 0x0398, "b.Theta", "GREEK CAPITAL LETTER THETA" },
1421{ 0x0398, "Theta", "GREEK CAPITAL LETTER THETA" },
1422{ 0x0398, "THgr", "GREEK CAPITAL LETTER THETA" },
1423{ 0x0399, "Igr", "GREEK CAPITAL LETTER IOTA" },
1424{ 0x039A, "Kgr", "GREEK CAPITAL LETTER KAPPA" },
1425{ 0x039B, "b.Lambda", "GREEK CAPITAL LETTER LAMDA" },
1426{ 0x039B, "Lambda", "GREEK CAPITAL LETTER LAMDA" },
1427{ 0x039B, "Lgr", "GREEK CAPITAL LETTER LAMDA" },
1428{ 0x039C, "Mgr", "GREEK CAPITAL LETTER MU" },
1429{ 0x039D, "Ngr", "GREEK CAPITAL LETTER NU" },
1430{ 0x039E, "b.Xi", "GREEK CAPITAL LETTER XI" },
1431{ 0x039E, "Xgr", "GREEK CAPITAL LETTER XI" },
1432{ 0x039E, "Xi", "GREEK CAPITAL LETTER XI" },
1433{ 0x039F, "Ogr", "GREEK CAPITAL LETTER OMICRON" },
1434{ 0x03A0, "b.Pi", "GREEK CAPITAL LETTER PI" },
1435{ 0x03A0, "Pgr", "GREEK CAPITAL LETTER PI" },
1436{ 0x03A0, "Pi", "GREEK CAPITAL LETTER PI" },
1437{ 0x03A1, "Rgr", "GREEK CAPITAL LETTER RHO" },
1438{ 0x03A3, "b.Sigma", "GREEK CAPITAL LETTER SIGMA" },
1439{ 0x03A3, "Sgr", "GREEK CAPITAL LETTER SIGMA" },
1440{ 0x03A3, "Sigma", "GREEK CAPITAL LETTER SIGMA" },
1441{ 0x03A4, "Tgr", "GREEK CAPITAL LETTER TAU" },
1442{ 0x03A5, "Ugr", "" },
1443{ 0x03A6, "b.Phi", "GREEK CAPITAL LETTER PHI" },
1444{ 0x03A6, "PHgr", "GREEK CAPITAL LETTER PHI" },
1445{ 0x03A6, "Phi", "GREEK CAPITAL LETTER PHI" },
1446{ 0x03A7, "KHgr", "GREEK CAPITAL LETTER CHI" },
1447{ 0x03A8, "b.Psi", "GREEK CAPITAL LETTER PSI" },
1448{ 0x03A8, "PSgr", "GREEK CAPITAL LETTER PSI" },
1449{ 0x03A8, "Psi", "GREEK CAPITAL LETTER PSI" },
1450{ 0x03A9, "b.Omega", "GREEK CAPITAL LETTER OMEGA" },
1451{ 0x03A9, "OHgr", "GREEK CAPITAL LETTER OMEGA" },
1452{ 0x03A9, "Omega", "GREEK CAPITAL LETTER OMEGA" },
1453{ 0x03AA, "Idigr", "GREEK CAPITAL LETTER IOTA WITH DIALYTIKA" },
1454{ 0x03AB, "Udigr", "GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA" },
1455{ 0x03AC, "aacgr", "GREEK SMALL LETTER ALPHA WITH TONOS" },
1456{ 0x03AD, "eacgr", "GREEK SMALL LETTER EPSILON WITH TONOS" },
1457{ 0x03AE, "eeacgr", "GREEK SMALL LETTER ETA WITH TONOS" },
1458{ 0x03AF, "iacgr", "GREEK SMALL LETTER IOTA WITH TONOS" },
1459{ 0x03B0, "udiagr", "GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS" },
1460{ 0x03B1, "agr", "" },
1461{ 0x03B1, "alpha", "" },
1462{ 0x03B1, "b.alpha", "" },
1463{ 0x03B2, "b.beta", "GREEK SMALL LETTER BETA" },
1464{ 0x03B2, "beta", "GREEK SMALL LETTER BETA" },
1465{ 0x03B2, "bgr", "GREEK SMALL LETTER BETA" },
1466{ 0x03B3, "b.gamma", "GREEK SMALL LETTER GAMMA" },
1467{ 0x03B3, "gamma", "GREEK SMALL LETTER GAMMA" },
1468{ 0x03B3, "ggr", "GREEK SMALL LETTER GAMMA" },
1469{ 0x03B4, "b.delta", "GREEK SMALL LETTER DELTA" },
1470{ 0x03B4, "delta", "GREEK SMALL LETTER DELTA" },
1471{ 0x03B4, "dgr", "GREEK SMALL LETTER DELTA" },
1472{ 0x03B5, "b.epsi", "" },
1473{ 0x03B5, "b.epsis", "" },
1474{ 0x03B5, "b.epsiv", "" },
1475{ 0x03B5, "egr", "" },
1476{ 0x03B5, "epsiv", "" },
1477{ 0x03B6, "b.zeta", "GREEK SMALL LETTER ZETA" },
1478{ 0x03B6, "zeta", "GREEK SMALL LETTER ZETA" },
1479{ 0x03B6, "zgr", "GREEK SMALL LETTER ZETA" },
1480{ 0x03B7, "b.eta", "GREEK SMALL LETTER ETA" },
1481{ 0x03B7, "eegr", "GREEK SMALL LETTER ETA" },
1482{ 0x03B7, "eta", "GREEK SMALL LETTER ETA" },
1483{ 0x03B8, "b.thetas", "" },
1484{ 0x03B8, "thetas", "" },
1485{ 0x03B8, "thgr", "" },
1486{ 0x03B9, "b.iota", "GREEK SMALL LETTER IOTA" },
1487{ 0x03B9, "igr", "GREEK SMALL LETTER IOTA" },
1488{ 0x03B9, "iota", "GREEK SMALL LETTER IOTA" },
1489{ 0x03BA, "b.kappa", "GREEK SMALL LETTER KAPPA" },
1490{ 0x03BA, "kappa", "GREEK SMALL LETTER KAPPA" },
1491{ 0x03BA, "kgr", "GREEK SMALL LETTER KAPPA" },
1492{ 0x03BB, "b.lambda", "GREEK SMALL LETTER LAMDA" },
1493{ 0x03BB, "lambda", "GREEK SMALL LETTER LAMDA" },
1494{ 0x03BB, "lgr", "GREEK SMALL LETTER LAMDA" },
1495{ 0x03BC, "b.mu", "GREEK SMALL LETTER MU" },
1496{ 0x03BC, "mgr", "GREEK SMALL LETTER MU" },
1497{ 0x03BC, "mu", "GREEK SMALL LETTER MU" },
1498{ 0x03BD, "b.nu", "GREEK SMALL LETTER NU" },
1499{ 0x03BD, "ngr", "GREEK SMALL LETTER NU" },
1500{ 0x03BD, "nu", "GREEK SMALL LETTER NU" },
1501{ 0x03BE, "b.xi", "GREEK SMALL LETTER XI" },
1502{ 0x03BE, "xgr", "GREEK SMALL LETTER XI" },
1503{ 0x03BE, "xi", "GREEK SMALL LETTER XI" },
1504{ 0x03BF, "ogr", "GREEK SMALL LETTER OMICRON" },
1505{ 0x03C0, "b.pi", "GREEK SMALL LETTER PI" },
1506{ 0x03C0, "pgr", "GREEK SMALL LETTER PI" },
1507{ 0x03C0, "pi", "GREEK SMALL LETTER PI" },
1508{ 0x03C1, "b.rho", "GREEK SMALL LETTER RHO" },
1509{ 0x03C1, "rgr", "GREEK SMALL LETTER RHO" },
1510{ 0x03C1, "rho", "GREEK SMALL LETTER RHO" },
1511{ 0x03C2, "b.sigmav", "" },
1512{ 0x03C2, "sfgr", "" },
1513{ 0x03C2, "sigmav", "" },
1514{ 0x03C3, "b.sigma", "GREEK SMALL LETTER SIGMA" },
1515{ 0x03C3, "sgr", "GREEK SMALL LETTER SIGMA" },
1516{ 0x03C3, "sigma", "GREEK SMALL LETTER SIGMA" },
1517{ 0x03C4, "b.tau", "GREEK SMALL LETTER TAU" },
1518{ 0x03C4, "tau", "GREEK SMALL LETTER TAU" },
1519{ 0x03C4, "tgr", "GREEK SMALL LETTER TAU" },
1520{ 0x03C5, "b.upsi", "GREEK SMALL LETTER UPSILON" },
1521{ 0x03C5, "ugr", "GREEK SMALL LETTER UPSILON" },
1522{ 0x03C5, "upsi", "GREEK SMALL LETTER UPSILON" },
1523{ 0x03C6, "b.phis", "GREEK SMALL LETTER PHI" },
1524{ 0x03C6, "phgr", "GREEK SMALL LETTER PHI" },
1525{ 0x03C6, "phis", "GREEK SMALL LETTER PHI" },
1526{ 0x03C7, "b.chi", "GREEK SMALL LETTER CHI" },
1527{ 0x03C7, "chi", "GREEK SMALL LETTER CHI" },
1528{ 0x03C7, "khgr", "GREEK SMALL LETTER CHI" },
1529{ 0x03C8, "b.psi", "GREEK SMALL LETTER PSI" },
1530{ 0x03C8, "psgr", "GREEK SMALL LETTER PSI" },
1531{ 0x03C8, "psi", "GREEK SMALL LETTER PSI" },
1532{ 0x03C9, "b.omega", "GREEK SMALL LETTER OMEGA" },
1533{ 0x03C9, "ohgr", "GREEK SMALL LETTER OMEGA" },
1534{ 0x03C9, "omega", "GREEK SMALL LETTER OMEGA" },
1535{ 0x03CA, "idigr", "GREEK SMALL LETTER IOTA WITH DIALYTIKA" },
1536{ 0x03CB, "udigr", "GREEK SMALL LETTER UPSILON WITH DIALYTIKA" },
1537{ 0x03CC, "oacgr", "GREEK SMALL LETTER OMICRON WITH TONOS" },
1538{ 0x03CD, "uacgr", "GREEK SMALL LETTER UPSILON WITH TONOS" },
1539{ 0x03CE, "ohacgr", "GREEK SMALL LETTER OMEGA WITH TONOS" },
1540{ 0x03D1, "b.thetav", "" },
1541{ 0x03D1, "thetav", "" },
1542{ 0x03D2, "b.Upsi", "" },
1543{ 0x03D2, "Upsi", "" },
1544{ 0x03D5, "b.phiv", "GREEK PHI SYMBOL" },
1545{ 0x03D5, "phiv", "GREEK PHI SYMBOL" },
1546{ 0x03D6, "b.piv", "GREEK PI SYMBOL" },
1547{ 0x03D6, "piv", "GREEK PI SYMBOL" },
1548{ 0x03DC, "b.gammad", "GREEK LETTER DIGAMMA" },
1549{ 0x03DC, "gammad", "GREEK LETTER DIGAMMA" },
1550{ 0x03F0, "b.kappav", "GREEK KAPPA SYMBOL" },
1551{ 0x03F0, "kappav", "GREEK KAPPA SYMBOL" },
1552{ 0x03F1, "b.rhov", "GREEK RHO SYMBOL" },
1553{ 0x03F1, "rhov", "GREEK RHO SYMBOL" },
1554{ 0x0401, "IOcy", "CYRILLIC CAPITAL LETTER IO" },
1555{ 0x0402, "DJcy", "CYRILLIC CAPITAL LETTER DJE" },
1556{ 0x0403, "GJcy", "CYRILLIC CAPITAL LETTER GJE" },
1557{ 0x0404, "Jukcy", "CYRILLIC CAPITAL LETTER UKRAINIAN IE" },
1558{ 0x0405, "DScy", "CYRILLIC CAPITAL LETTER DZE" },
1559{ 0x0406, "Iukcy", "CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I" },
1560{ 0x0407, "YIcy", "CYRILLIC CAPITAL LETTER YI" },
1561{ 0x0408, "Jsercy", "CYRILLIC CAPITAL LETTER JE" },
1562{ 0x0409, "LJcy", "CYRILLIC CAPITAL LETTER LJE" },
1563{ 0x040A, "NJcy", "CYRILLIC CAPITAL LETTER NJE" },
1564{ 0x040B, "TSHcy", "CYRILLIC CAPITAL LETTER TSHE" },
1565{ 0x040C, "KJcy", "CYRILLIC CAPITAL LETTER KJE" },
1566{ 0x040E, "Ubrcy", "CYRILLIC CAPITAL LETTER SHORT U" },
1567{ 0x040F, "DZcy", "CYRILLIC CAPITAL LETTER DZHE" },
1568{ 0x0410, "Acy", "CYRILLIC CAPITAL LETTER A" },
1569{ 0x0411, "Bcy", "CYRILLIC CAPITAL LETTER BE" },
1570{ 0x0412, "Vcy", "CYRILLIC CAPITAL LETTER VE" },
1571{ 0x0413, "Gcy", "CYRILLIC CAPITAL LETTER GHE" },
1572{ 0x0414, "Dcy", "CYRILLIC CAPITAL LETTER DE" },
1573{ 0x0415, "IEcy", "CYRILLIC CAPITAL LETTER IE" },
1574{ 0x0416, "ZHcy", "CYRILLIC CAPITAL LETTER ZHE" },
1575{ 0x0417, "Zcy", "CYRILLIC CAPITAL LETTER ZE" },
1576{ 0x0418, "Icy", "CYRILLIC CAPITAL LETTER I" },
1577{ 0x0419, "Jcy", "CYRILLIC CAPITAL LETTER SHORT I" },
1578{ 0x041A, "Kcy", "CYRILLIC CAPITAL LETTER KA" },
1579{ 0x041B, "Lcy", "CYRILLIC CAPITAL LETTER EL" },
1580{ 0x041C, "Mcy", "CYRILLIC CAPITAL LETTER EM" },
1581{ 0x041D, "Ncy", "CYRILLIC CAPITAL LETTER EN" },
1582{ 0x041E, "Ocy", "CYRILLIC CAPITAL LETTER O" },
1583{ 0x041F, "Pcy", "CYRILLIC CAPITAL LETTER PE" },
1584{ 0x0420, "Rcy", "CYRILLIC CAPITAL LETTER ER" },
1585{ 0x0421, "Scy", "CYRILLIC CAPITAL LETTER ES" },
1586{ 0x0422, "Tcy", "CYRILLIC CAPITAL LETTER TE" },
1587{ 0x0423, "Ucy", "CYRILLIC CAPITAL LETTER U" },
1588{ 0x0424, "Fcy", "CYRILLIC CAPITAL LETTER EF" },
1589{ 0x0425, "KHcy", "CYRILLIC CAPITAL LETTER HA" },
1590{ 0x0426, "TScy", "CYRILLIC CAPITAL LETTER TSE" },
1591{ 0x0427, "CHcy", "CYRILLIC CAPITAL LETTER CHE" },
1592{ 0x0428, "SHcy", "CYRILLIC CAPITAL LETTER SHA" },
1593{ 0x0429, "SHCHcy", "CYRILLIC CAPITAL LETTER SHCHA" },
1594{ 0x042A, "HARDcy", "CYRILLIC CAPITAL LETTER HARD SIGN" },
1595{ 0x042B, "Ycy", "CYRILLIC CAPITAL LETTER YERU" },
1596{ 0x042C, "SOFTcy", "CYRILLIC CAPITAL LETTER SOFT SIGN" },
1597{ 0x042D, "Ecy", "CYRILLIC CAPITAL LETTER E" },
1598{ 0x042E, "YUcy", "CYRILLIC CAPITAL LETTER YU" },
1599{ 0x042F, "YAcy", "CYRILLIC CAPITAL LETTER YA" },
1600{ 0x0430, "acy", "CYRILLIC SMALL LETTER A" },
1601{ 0x0431, "bcy", "CYRILLIC SMALL LETTER BE" },
1602{ 0x0432, "vcy", "CYRILLIC SMALL LETTER VE" },
1603{ 0x0433, "gcy", "CYRILLIC SMALL LETTER GHE" },
1604{ 0x0434, "dcy", "CYRILLIC SMALL LETTER DE" },
1605{ 0x0435, "iecy", "CYRILLIC SMALL LETTER IE" },
1606{ 0x0436, "zhcy", "CYRILLIC SMALL LETTER ZHE" },
1607{ 0x0437, "zcy", "CYRILLIC SMALL LETTER ZE" },
1608{ 0x0438, "icy", "CYRILLIC SMALL LETTER I" },
1609{ 0x0439, "jcy", "CYRILLIC SMALL LETTER SHORT I" },
1610{ 0x043A, "kcy", "CYRILLIC SMALL LETTER KA" },
1611{ 0x043B, "lcy", "CYRILLIC SMALL LETTER EL" },
1612{ 0x043C, "mcy", "CYRILLIC SMALL LETTER EM" },
1613{ 0x043D, "ncy", "CYRILLIC SMALL LETTER EN" },
1614{ 0x043E, "ocy", "CYRILLIC SMALL LETTER O" },
1615{ 0x043F, "pcy", "CYRILLIC SMALL LETTER PE" },
1616{ 0x0440, "rcy", "CYRILLIC SMALL LETTER ER" },
1617{ 0x0441, "scy", "CYRILLIC SMALL LETTER ES" },
1618{ 0x0442, "tcy", "CYRILLIC SMALL LETTER TE" },
1619{ 0x0443, "ucy", "CYRILLIC SMALL LETTER U" },
1620{ 0x0444, "fcy", "CYRILLIC SMALL LETTER EF" },
1621{ 0x0445, "khcy", "CYRILLIC SMALL LETTER HA" },
1622{ 0x0446, "tscy", "CYRILLIC SMALL LETTER TSE" },
1623{ 0x0447, "chcy", "CYRILLIC SMALL LETTER CHE" },
1624{ 0x0448, "shcy", "CYRILLIC SMALL LETTER SHA" },
1625{ 0x0449, "shchcy", "CYRILLIC SMALL LETTER SHCHA" },
1626{ 0x044A, "hardcy", "CYRILLIC SMALL LETTER HARD SIGN" },
1627{ 0x044B, "ycy", "CYRILLIC SMALL LETTER YERU" },
1628{ 0x044C, "softcy", "CYRILLIC SMALL LETTER SOFT SIGN" },
1629{ 0x044D, "ecy", "CYRILLIC SMALL LETTER E" },
1630{ 0x044E, "yucy", "CYRILLIC SMALL LETTER YU" },
1631{ 0x044F, "yacy", "CYRILLIC SMALL LETTER YA" },
1632{ 0x0451, "iocy", "CYRILLIC SMALL LETTER IO" },
1633{ 0x0452, "djcy", "CYRILLIC SMALL LETTER DJE" },
1634{ 0x0453, "gjcy", "CYRILLIC SMALL LETTER GJE" },
1635{ 0x0454, "jukcy", "CYRILLIC SMALL LETTER UKRAINIAN IE" },
1636{ 0x0455, "dscy", "CYRILLIC SMALL LETTER DZE" },
1637{ 0x0456, "iukcy", "CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I" },
1638{ 0x0457, "yicy", "CYRILLIC SMALL LETTER YI" },
1639{ 0x0458, "jsercy", "CYRILLIC SMALL LETTER JE" },
1640{ 0x0459, "ljcy", "CYRILLIC SMALL LETTER LJE" },
1641{ 0x045A, "njcy", "CYRILLIC SMALL LETTER NJE" },
1642{ 0x045B, "tshcy", "CYRILLIC SMALL LETTER TSHE" },
1643{ 0x045C, "kjcy", "CYRILLIC SMALL LETTER KJE" },
1644{ 0x045E, "ubrcy", "CYRILLIC SMALL LETTER SHORT U" },
1645{ 0x045F, "dzcy", "CYRILLIC SMALL LETTER DZHE" },
1646{ 0x2002, "ensp", "EN SPACE" },
1647{ 0x2003, "emsp", "EM SPACE" },
1648{ 0x2004, "emsp13", "THREE-PER-EM SPACE" },
1649{ 0x2005, "emsp14", "FOUR-PER-EM SPACE" },
1650{ 0x2007, "numsp", "FIGURE SPACE" },
1651{ 0x2008, "puncsp", "PUNCTUATION SPACE" },
1652{ 0x2009, "thinsp", "THIN SPACE" },
1653{ 0x200A, "hairsp", "HAIR SPACE" },
1654{ 0x2010, "dash", "HYPHEN" },
1655{ 0x2013, "ndash", "EN DASH" },
1656{ 0x2014, "mdash", "EM DASH" },
1657{ 0x2015, "horbar", "HORIZONTAL BAR" },
1658{ 0x2016, "Verbar", "DOUBLE VERTICAL LINE" },
1659{ 0x2018, "lsquo", "" },
1660{ 0x2018, "rsquor", "" },
1661{ 0x2019, "rsquo", "RIGHT SINGLE QUOTATION MARK" },
1662{ 0x201A, "lsquor", "SINGLE LOW-9 QUOTATION MARK" },
1663{ 0x201C, "ldquo", "" },
1664{ 0x201C, "rdquor", "" },
1665{ 0x201D, "rdquo", "RIGHT DOUBLE QUOTATION MARK" },
1666{ 0x201E, "ldquor", "DOUBLE LOW-9 QUOTATION MARK" },
1667{ 0x2020, "dagger", "DAGGER" },
1668{ 0x2021, "Dagger", "DOUBLE DAGGER" },
1669{ 0x2022, "bull", "BULLET" },
1670{ 0x2025, "nldr", "TWO DOT LEADER" },
1671{ 0x2026, "hellip", "HORIZONTAL ELLIPSIS" },
1672{ 0x2026, "mldr", "HORIZONTAL ELLIPSIS" },
1673{ 0x2030, "permil", "PER MILLE SIGN" },
1674{ 0x2032, "prime", "PRIME" },
1675{ 0x2032, "vprime", "PRIME" },
1676{ 0x2033, "Prime", "DOUBLE PRIME" },
1677{ 0x2034, "tprime", "TRIPLE PRIME" },
1678{ 0x2035, "bprime", "REVERSED PRIME" },
1679{ 0x2041, "caret", "CARET" },
1680{ 0x2043, "hybull", "HYPHEN BULLET" },
1681{ 0x20DB, "tdot", "COMBINING THREE DOTS ABOVE" },
1682{ 0x20DC, "DotDot", "COMBINING FOUR DOTS ABOVE" },
1683{ 0x2105, "incare", "CARE OF" },
1684{ 0x210B, "hamilt", "SCRIPT CAPITAL H" },
1685{ 0x210F, "planck", "PLANCK CONSTANT OVER TWO PI" },
1686{ 0x2111, "image", "BLACK-LETTER CAPITAL I" },
1687{ 0x2112, "lagran", "SCRIPT CAPITAL L" },
1688{ 0x2113, "ell", "SCRIPT SMALL L" },
1689{ 0x2116, "numero", "NUMERO SIGN" },
1690{ 0x2117, "copysr", "SOUND RECORDING COPYRIGHT" },
1691{ 0x2118, "weierp", "SCRIPT CAPITAL P" },
1692{ 0x211C, "real", "BLACK-LETTER CAPITAL R" },
1693{ 0x211E, "rx", "PRESCRIPTION TAKE" },
1694{ 0x2122, "trade", "TRADE MARK SIGN" },
1695{ 0x2126, "ohm", "OHM SIGN" },
1696{ 0x212B, "angst", "ANGSTROM SIGN" },
1697{ 0x212C, "bernou", "SCRIPT CAPITAL B" },
1698{ 0x2133, "phmmat", "SCRIPT CAPITAL M" },
1699{ 0x2134, "order", "SCRIPT SMALL O" },
1700{ 0x2135, "aleph", "ALEF SYMBOL" },
1701{ 0x2136, "beth", "BET SYMBOL" },
1702{ 0x2137, "gimel", "GIMEL SYMBOL" },
1703{ 0x2138, "daleth", "DALET SYMBOL" },
1704{ 0x2153, "frac13", "VULGAR FRACTION ONE THIRD" },
1705{ 0x2154, "frac23", "VULGAR FRACTION TWO THIRDS" },
1706{ 0x2155, "frac15", "VULGAR FRACTION ONE FIFTH" },
1707{ 0x2156, "frac25", "VULGAR FRACTION TWO FIFTHS" },
1708{ 0x2157, "frac35", "VULGAR FRACTION THREE FIFTHS" },
1709{ 0x2158, "frac45", "VULGAR FRACTION FOUR FIFTHS" },
1710{ 0x2159, "frac16", "VULGAR FRACTION ONE SIXTH" },
1711{ 0x215A, "frac56", "VULGAR FRACTION FIVE SIXTHS" },
1712{ 0x215B, "frac18", "" },
1713{ 0x215C, "frac38", "" },
1714{ 0x215D, "frac58", "" },
1715{ 0x215E, "frac78", "" },
1716{ 0x2190, "larr", "LEFTWARDS DOUBLE ARROW" },
1717{ 0x2191, "uarr", "UPWARDS ARROW" },
1718{ 0x2192, "rarr", "RIGHTWARDS DOUBLE ARROW" },
1719{ 0x2193, "darr", "DOWNWARDS ARROW" },
1720{ 0x2194, "harr", "LEFT RIGHT ARROW" },
1721{ 0x2194, "xhArr", "LEFT RIGHT ARROW" },
1722{ 0x2194, "xharr", "LEFT RIGHT ARROW" },
1723{ 0x2195, "varr", "UP DOWN ARROW" },
1724{ 0x2196, "nwarr", "NORTH WEST ARROW" },
1725{ 0x2197, "nearr", "NORTH EAST ARROW" },
1726{ 0x2198, "drarr", "SOUTH EAST ARROW" },
1727{ 0x2199, "dlarr", "SOUTH WEST ARROW" },
1728{ 0x219A, "nlarr", "LEFTWARDS ARROW WITH STROKE" },
1729{ 0x219B, "nrarr", "RIGHTWARDS ARROW WITH STROKE" },
1730{ 0x219D, "rarrw", "RIGHTWARDS SQUIGGLE ARROW" },
1731{ 0x219E, "Larr", "LEFTWARDS TWO HEADED ARROW" },
1732{ 0x21A0, "Rarr", "RIGHTWARDS TWO HEADED ARROW" },
1733{ 0x21A2, "larrtl", "LEFTWARDS ARROW WITH TAIL" },
1734{ 0x21A3, "rarrtl", "RIGHTWARDS ARROW WITH TAIL" },
1735{ 0x21A6, "map", "RIGHTWARDS ARROW FROM BAR" },
1736{ 0x21A9, "larrhk", "LEFTWARDS ARROW WITH HOOK" },
1737{ 0x21AA, "rarrhk", "RIGHTWARDS ARROW WITH HOOK" },
1738{ 0x21AB, "larrlp", "LEFTWARDS ARROW WITH LOOP" },
1739{ 0x21AC, "rarrlp", "RIGHTWARDS ARROW WITH LOOP" },
1740{ 0x21AD, "harrw", "LEFT RIGHT WAVE ARROW" },
1741{ 0x21AE, "nharr", "LEFT RIGHT ARROW WITH STROKE" },
1742{ 0x21B0, "lsh", "UPWARDS ARROW WITH TIP LEFTWARDS" },
1743{ 0x21B1, "rsh", "UPWARDS ARROW WITH TIP RIGHTWARDS" },
1744{ 0x21B6, "cularr", "ANTICLOCKWISE TOP SEMICIRCLE ARROW" },
1745{ 0x21B7, "curarr", "CLOCKWISE TOP SEMICIRCLE ARROW" },
1746{ 0x21BA, "olarr", "ANTICLOCKWISE OPEN CIRCLE ARROW" },
1747{ 0x21BB, "orarr", "CLOCKWISE OPEN CIRCLE ARROW" },
1748{ 0x21BC, "lharu", "LEFTWARDS HARPOON WITH BARB UPWARDS" },
1749{ 0x21BD, "lhard", "LEFTWARDS HARPOON WITH BARB DOWNWARDS" },
1750{ 0x21BE, "uharr", "UPWARDS HARPOON WITH BARB RIGHTWARDS" },
1751{ 0x21BF, "uharl", "UPWARDS HARPOON WITH BARB LEFTWARDS" },
1752{ 0x21C0, "rharu", "RIGHTWARDS HARPOON WITH BARB UPWARDS" },
1753{ 0x21C1, "rhard", "RIGHTWARDS HARPOON WITH BARB DOWNWARDS" },
1754{ 0x21C2, "dharr", "DOWNWARDS HARPOON WITH BARB RIGHTWARDS" },
1755{ 0x21C3, "dharl", "DOWNWARDS HARPOON WITH BARB LEFTWARDS" },
1756{ 0x21C4, "rlarr2", "RIGHTWARDS ARROW OVER LEFTWARDS ARROW" },
1757{ 0x21C6, "lrarr2", "LEFTWARDS ARROW OVER RIGHTWARDS ARROW" },
1758{ 0x21C7, "larr2", "LEFTWARDS PAIRED ARROWS" },
1759{ 0x21C8, "uarr2", "UPWARDS PAIRED ARROWS" },
1760{ 0x21C9, "rarr2", "RIGHTWARDS PAIRED ARROWS" },
1761{ 0x21CA, "darr2", "DOWNWARDS PAIRED ARROWS" },
1762{ 0x21CB, "lrhar2", "LEFTWARDS HARPOON OVER RIGHTWARDS HARPOON" },
1763{ 0x21CC, "rlhar2", "RIGHTWARDS HARPOON OVER LEFTWARDS HARPOON" },
1764{ 0x21CD, "nlArr", "LEFTWARDS DOUBLE ARROW WITH STROKE" },
1765{ 0x21CE, "nhArr", "LEFT RIGHT DOUBLE ARROW WITH STROKE" },
1766{ 0x21CF, "nrArr", "RIGHTWARDS DOUBLE ARROW WITH STROKE" },
1767{ 0x21D0, "lArr", "LEFTWARDS ARROW" },
1768{ 0x21D0, "xlArr", "LEFTWARDS DOUBLE ARROW" },
1769{ 0x21D1, "uArr", "UPWARDS DOUBLE ARROW" },
1770{ 0x21D2, "rArr", "RIGHTWARDS ARROW" },
1771{ 0x21D2, "xrArr", "RIGHTWARDS DOUBLE ARROW" },
1772{ 0x21D3, "dArr", "DOWNWARDS DOUBLE ARROW" },
1773{ 0x21D4, "hArr", "" },
1774{ 0x21D4, "iff", "LEFT RIGHT DOUBLE ARROW" },
1775{ 0x21D5, "vArr", "UP DOWN DOUBLE ARROW" },
1776{ 0x21DA, "lAarr", "LEFTWARDS TRIPLE ARROW" },
1777{ 0x21DB, "rAarr", "RIGHTWARDS TRIPLE ARROW" },
1778{ 0x2200, "forall", "" },
1779{ 0x2201, "comp", "COMPLEMENT" },
1780{ 0x2202, "part", "" },
1781{ 0x2203, "exist", "" },
1782{ 0x2204, "nexist", "THERE DOES NOT EXIST" },
1783{ 0x2205, "empty", "" },
1784{ 0x2207, "nabla", "NABLA" },
1785{ 0x2209, "notin", "" },
1786{ 0x220A, "epsi", "" },
1787{ 0x220A, "epsis", "" },
1788{ 0x220A, "isin", "" },
1789{ 0x220D, "bepsi", "SMALL CONTAINS AS MEMBER" },
1790{ 0x220D, "ni", "" },
1791{ 0x220F, "prod", "N-ARY PRODUCT" },
1792{ 0x2210, "amalg", "N-ARY COPRODUCT" },
1793{ 0x2210, "coprod", "N-ARY COPRODUCT" },
1794{ 0x2210, "samalg", "" },
1795{ 0x2211, "sum", "N-ARY SUMMATION" },
1796{ 0x2212, "minus", "MINUS SIGN" },
1797{ 0x2213, "mnplus", "" },
1798{ 0x2214, "plusdo", "DOT PLUS" },
1799{ 0x2216, "setmn", "SET MINUS" },
1800{ 0x2216, "ssetmn", "SET MINUS" },
1801{ 0x2217, "lowast", "ASTERISK OPERATOR" },
1802{ 0x2218, "compfn", "RING OPERATOR" },
1803{ 0x221A, "radic", "" },
1804{ 0x221D, "prop", "" },
1805{ 0x221D, "vprop", "" },
1806{ 0x221E, "infin", "" },
1807{ 0x221F, "ang90", "RIGHT ANGLE" },
1808{ 0x2220, "ang", "ANGLE" },
1809{ 0x2221, "angmsd", "MEASURED ANGLE" },
1810{ 0x2222, "angsph", "" },
1811{ 0x2223, "mid", "" },
1812{ 0x2224, "nmid", "DOES NOT DIVIDE" },
1813{ 0x2225, "par", "PARALLEL TO" },
1814{ 0x2225, "spar", "PARALLEL TO" },
1815{ 0x2226, "npar", "NOT PARALLEL TO" },
1816{ 0x2226, "nspar", "NOT PARALLEL TO" },
1817{ 0x2227, "and", "" },
1818{ 0x2228, "or", "" },
1819{ 0x2229, "cap", "" },
1820{ 0x222A, "cup", "" },
1821{ 0x222B, "int", "" },
1822{ 0x222E, "conint", "" },
1823{ 0x2234, "there4", "" },
1824{ 0x2235, "becaus", "BECAUSE" },
1825{ 0x223C, "sim", "" },
1826{ 0x223C, "thksim", "TILDE OPERATOR" },
1827{ 0x223D, "bsim", "" },
1828{ 0x2240, "wreath", "WREATH PRODUCT" },
1829{ 0x2241, "nsim", "" },
1830{ 0x2243, "sime", "" },
1831{ 0x2244, "nsime", "" },
1832{ 0x2245, "cong", "" },
1833{ 0x2247, "ncong", "NEITHER APPROXIMATELY NOR ACTUALLY EQUAL TO" },
1834{ 0x2248, "ap", "" },
1835{ 0x2248, "thkap", "ALMOST EQUAL TO" },
1836{ 0x2249, "nap", "NOT ALMOST EQUAL TO" },
1837{ 0x224A, "ape", "" },
1838{ 0x224C, "bcong", "ALL EQUAL TO" },
1839{ 0x224D, "asymp", "EQUIVALENT TO" },
1840{ 0x224E, "bump", "" },
1841{ 0x224F, "bumpe", "" },
1842{ 0x2250, "esdot", "" },
1843{ 0x2251, "eDot", "" },
1844{ 0x2252, "efDot", "" },
1845{ 0x2253, "erDot", "" },
1846{ 0x2254, "colone", "" },
1847{ 0x2255, "ecolon", "" },
1848{ 0x2256, "ecir", "" },
1849{ 0x2257, "cire", "" },
1850{ 0x2259, "wedgeq", "ESTIMATES" },
1851{ 0x225C, "trie", "" },
1852{ 0x2260, "ne", "" },
1853{ 0x2261, "equiv", "" },
1854{ 0x2262, "nequiv", "NOT IDENTICAL TO" },
1855{ 0x2264, "le", "" },
1856{ 0x2264, "les", "LESS-THAN OR EQUAL TO" },
1857{ 0x2265, "ge", "GREATER-THAN OR EQUAL TO" },
1858{ 0x2265, "ges", "GREATER-THAN OR EQUAL TO" },
1859{ 0x2266, "lE", "" },
1860{ 0x2267, "gE", "" },
1861{ 0x2268, "lnE", "" },
1862{ 0x2268, "lne", "" },
1863{ 0x2268, "lvnE", "LESS-THAN BUT NOT EQUAL TO" },
1864{ 0x2269, "gnE", "" },
1865{ 0x2269, "gne", "" },
1866{ 0x2269, "gvnE", "GREATER-THAN BUT NOT EQUAL TO" },
1867{ 0x226A, "Lt", "MUCH LESS-THAN" },
1868{ 0x226B, "Gt", "MUCH GREATER-THAN" },
1869{ 0x226C, "twixt", "BETWEEN" },
1870{ 0x226E, "nlt", "NOT LESS-THAN" },
1871{ 0x226F, "ngt", "NOT GREATER-THAN" },
1872{ 0x2270, "nlE", "" },
1873{ 0x2270, "nle", "NEITHER LESS-THAN NOR EQUAL TO" },
1874{ 0x2270, "nles", "" },
1875{ 0x2271, "ngE", "" },
1876{ 0x2271, "nge", "NEITHER GREATER-THAN NOR EQUAL TO" },
1877{ 0x2271, "nges", "" },
1878{ 0x2272, "lap", "LESS-THAN OR EQUIVALENT TO" },
1879{ 0x2272, "lsim", "LESS-THAN OR EQUIVALENT TO" },
1880{ 0x2273, "gap", "GREATER-THAN OR EQUIVALENT TO" },
1881{ 0x2273, "gsim", "GREATER-THAN OR EQUIVALENT TO" },
1882{ 0x2276, "lg", "LESS-THAN OR GREATER-THAN" },
1883{ 0x2277, "gl", "" },
1884{ 0x227A, "pr", "" },
1885{ 0x227B, "sc", "" },
1886{ 0x227C, "cupre", "" },
1887{ 0x227C, "pre", "" },
1888{ 0x227D, "sccue", "" },
1889{ 0x227D, "sce", "" },
1890{ 0x227E, "prap", "" },
1891{ 0x227E, "prsim", "" },
1892{ 0x227F, "scap", "" },
1893{ 0x227F, "scsim", "" },
1894{ 0x2280, "npr", "DOES NOT PRECEDE" },
1895{ 0x2281, "nsc", "DOES NOT SUCCEED" },
1896{ 0x2282, "sub", "" },
1897{ 0x2283, "sup", "" },
1898{ 0x2284, "nsub", "NOT A SUBSET OF" },
1899{ 0x2285, "nsup", "NOT A SUPERSET OF" },
1900{ 0x2286, "subE", "" },
1901{ 0x2286, "sube", "" },
1902{ 0x2287, "supE", "" },
1903{ 0x2287, "supe", "" },
1904{ 0x2288, "nsubE", "" },
1905{ 0x2288, "nsube", "" },
1906{ 0x2289, "nsupE", "" },
1907{ 0x2289, "nsupe", "" },
1908{ 0x228A, "subne", "" },
1909{ 0x228A, "subnE", "SUBSET OF WITH NOT EQUAL TO" },
1910{ 0x228A, "vsubne", "SUBSET OF WITH NOT EQUAL TO" },
1911{ 0x228B, "supnE", "" },
1912{ 0x228B, "supne", "" },
1913{ 0x228B, "vsupnE", "SUPERSET OF WITH NOT EQUAL TO" },
1914{ 0x228B, "vsupne", "SUPERSET OF WITH NOT EQUAL TO" },
1915{ 0x228E, "uplus", "MULTISET UNION" },
1916{ 0x228F, "sqsub", "" },
1917{ 0x2290, "sqsup", "" },
1918{ 0x2291, "sqsube", "" },
1919{ 0x2292, "sqsupe", "" },
1920{ 0x2293, "sqcap", "SQUARE CAP" },
1921{ 0x2294, "sqcup", "SQUARE CUP" },
1922{ 0x2295, "oplus", "CIRCLED PLUS" },
1923{ 0x2296, "ominus", "CIRCLED MINUS" },
1924{ 0x2297, "otimes", "CIRCLED TIMES" },
1925{ 0x2298, "osol", "CIRCLED DIVISION SLASH" },
1926{ 0x2299, "odot", "CIRCLED DOT OPERATOR" },
1927{ 0x229A, "ocir", "CIRCLED RING OPERATOR" },
1928{ 0x229B, "oast", "CIRCLED ASTERISK OPERATOR" },
1929{ 0x229D, "odash", "CIRCLED DASH" },
1930{ 0x229E, "plusb", "SQUARED PLUS" },
1931{ 0x229F, "minusb", "SQUARED MINUS" },
1932{ 0x22A0, "timesb", "SQUARED TIMES" },
1933{ 0x22A1, "sdotb", "SQUARED DOT OPERATOR" },
1934{ 0x22A2, "vdash", "" },
1935{ 0x22A3, "dashv", "" },
1936{ 0x22A4, "top", "DOWN TACK" },
1937{ 0x22A5, "bottom", "" },
1938{ 0x22A5, "perp", "" },
1939{ 0x22A7, "models", "MODELS" },
1940{ 0x22A8, "vDash", "" },
1941{ 0x22A9, "Vdash", "" },
1942{ 0x22AA, "Vvdash", "" },
1943{ 0x22AC, "nvdash", "DOES NOT PROVE" },
1944{ 0x22AD, "nvDash", "NOT TRUE" },
1945{ 0x22AE, "nVdash", "DOES NOT FORCE" },
1946{ 0x22AF, "nVDash", "NEGATED DOUBLE VERTICAL BAR DOUBLE RIGHT TURNSTILE" },
1947{ 0x22B2, "vltri", "" },
1948{ 0x22B3, "vrtri", "" },
1949{ 0x22B4, "ltrie", "" },
1950{ 0x22B5, "rtrie", "" },
1951{ 0x22B8, "mumap", "MULTIMAP" },
1952{ 0x22BA, "intcal", "INTERCALATE" },
1953{ 0x22BB, "veebar", "" },
1954{ 0x22BC, "barwed", "NAND" },
1955{ 0x22C4, "diam", "DIAMOND OPERATOR" },
1956{ 0x22C5, "sdot", "DOT OPERATOR" },
1957{ 0x22C6, "sstarf", "STAR OPERATOR" },
1958{ 0x22C6, "star", "STAR OPERATOR" },
1959{ 0x22C7, "divonx", "DIVISION TIMES" },
1960{ 0x22C8, "bowtie", "" },
1961{ 0x22C9, "ltimes", "LEFT NORMAL FACTOR SEMIDIRECT PRODUCT" },
1962{ 0x22CA, "rtimes", "RIGHT NORMAL FACTOR SEMIDIRECT PRODUCT" },
1963{ 0x22CB, "lthree", "LEFT SEMIDIRECT PRODUCT" },
1964{ 0x22CC, "rthree", "RIGHT SEMIDIRECT PRODUCT" },
1965{ 0x22CD, "bsime", "" },
1966{ 0x22CE, "cuvee", "CURLY LOGICAL OR" },
1967{ 0x22CF, "cuwed", "CURLY LOGICAL AND" },
1968{ 0x22D0, "Sub", "" },
1969{ 0x22D1, "Sup", "" },
1970{ 0x22D2, "Cap", "DOUBLE INTERSECTION" },
1971{ 0x22D3, "Cup", "DOUBLE UNION" },
1972{ 0x22D4, "fork", "" },
1973{ 0x22D6, "ldot", "" },
1974{ 0x22D7, "gsdot", "" },
1975{ 0x22D8, "Ll", "" },
1976{ 0x22D9, "Gg", "VERY MUCH GREATER-THAN" },
1977{ 0x22DA, "lEg", "" },
1978{ 0x22DA, "leg", "" },
1979{ 0x22DB, "gEl", "" },
1980{ 0x22DB, "gel", "" },
1981{ 0x22DC, "els", "" },
1982{ 0x22DD, "egs", "" },
1983{ 0x22DE, "cuepr", "" },
1984{ 0x22DF, "cuesc", "" },
1985{ 0x22E0, "npre", "DOES NOT PRECEDE OR EQUAL" },
1986{ 0x22E1, "nsce", "DOES NOT SUCCEED OR EQUAL" },
1987{ 0x22E6, "lnsim", "" },
1988{ 0x22E7, "gnsim", "GREATER-THAN BUT NOT EQUIVALENT TO" },
1989{ 0x22E8, "prnap", "" },
1990{ 0x22E8, "prnsim", "" },
1991{ 0x22E9, "scnap", "" },
1992{ 0x22E9, "scnsim", "" },
1993{ 0x22EA, "nltri", "NOT NORMAL SUBGROUP OF" },
1994{ 0x22EB, "nrtri", "DOES NOT CONTAIN AS NORMAL SUBGROUP" },
1995{ 0x22EC, "nltrie", "NOT NORMAL SUBGROUP OF OR EQUAL TO" },
1996{ 0x22ED, "nrtrie", "DOES NOT CONTAIN AS NORMAL SUBGROUP OR EQUAL" },
1997{ 0x22EE, "vellip", "" },
1998{ 0x2306, "Barwed", "PERSPECTIVE" },
1999{ 0x2308, "lceil", "LEFT CEILING" },
2000{ 0x2309, "rceil", "RIGHT CEILING" },
2001{ 0x230A, "lfloor", "LEFT FLOOR" },
2002{ 0x230B, "rfloor", "RIGHT FLOOR" },
2003{ 0x230C, "drcrop", "BOTTOM RIGHT CROP" },
2004{ 0x230D, "dlcrop", "BOTTOM LEFT CROP" },
2005{ 0x230E, "urcrop", "TOP RIGHT CROP" },
2006{ 0x230F, "ulcrop", "TOP LEFT CROP" },
2007{ 0x2315, "telrec", "TELEPHONE RECORDER" },
2008{ 0x2316, "target", "POSITION INDICATOR" },
2009{ 0x231C, "ulcorn", "TOP LEFT CORNER" },
2010{ 0x231D, "urcorn", "TOP RIGHT CORNER" },
2011{ 0x231E, "dlcorn", "BOTTOM LEFT CORNER" },
2012{ 0x231F, "drcorn", "BOTTOM RIGHT CORNER" },
2013{ 0x2322, "frown", "" },
2014{ 0x2322, "sfrown", "FROWN" },
2015{ 0x2323, "smile", "" },
2016{ 0x2323, "ssmile", "SMILE" },
2017{ 0x2423, "blank", "OPEN BOX" },
2018{ 0x24C8, "oS", "CIRCLED LATIN CAPITAL LETTER S" },
2019{ 0x2500, "boxh", "BOX DRAWINGS LIGHT HORIZONTAL" },
2020{ 0x2502, "boxv", "BOX DRAWINGS LIGHT VERTICAL" },
2021{ 0x250C, "boxdr", "BOX DRAWINGS LIGHT DOWN AND RIGHT" },
2022{ 0x2510, "boxdl", "BOX DRAWINGS LIGHT DOWN AND LEFT" },
2023{ 0x2514, "boxur", "BOX DRAWINGS LIGHT UP AND RIGHT" },
2024{ 0x2518, "boxul", "BOX DRAWINGS LIGHT UP AND LEFT" },
2025{ 0x251C, "boxvr", "BOX DRAWINGS LIGHT VERTICAL AND RIGHT" },
2026{ 0x2524, "boxvl", "BOX DRAWINGS LIGHT VERTICAL AND LEFT" },
2027{ 0x252C, "boxhd", "BOX DRAWINGS LIGHT DOWN AND HORIZONTAL" },
2028{ 0x2534, "boxhu", "BOX DRAWINGS LIGHT UP AND HORIZONTAL" },
2029{ 0x253C, "boxvh", "BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL" },
2030{ 0x2550, "boxH", "BOX DRAWINGS DOUBLE HORIZONTAL" },
2031{ 0x2551, "boxV", "BOX DRAWINGS DOUBLE VERTICAL" },
2032{ 0x2552, "boxDR", "BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE" },
2033{ 0x2553, "boxDr", "BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE" },
2034{ 0x2554, "boxdR", "BOX DRAWINGS DOUBLE DOWN AND RIGHT" },
2035{ 0x2555, "boxDL", "BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE" },
2036{ 0x2556, "boxdL", "BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE" },
2037{ 0x2557, "boxDl", "BOX DRAWINGS DOUBLE DOWN AND LEFT" },
2038{ 0x2558, "boxUR", "BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE" },
2039{ 0x2559, "boxuR", "BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE" },
2040{ 0x255A, "boxUr", "BOX DRAWINGS DOUBLE UP AND RIGHT" },
2041{ 0x255B, "boxUL", "BOX DRAWINGS UP SINGLE AND LEFT DOUBLE" },
2042{ 0x255C, "boxUl", "BOX DRAWINGS UP DOUBLE AND LEFT SINGLE" },
2043{ 0x255D, "boxuL", "BOX DRAWINGS DOUBLE UP AND LEFT" },
2044{ 0x255E, "boxvR", "BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE" },
2045{ 0x255F, "boxVR", "BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE" },
2046{ 0x2560, "boxVr", "BOX DRAWINGS DOUBLE VERTICAL AND RIGHT" },
2047{ 0x2561, "boxvL", "BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE" },
2048{ 0x2562, "boxVL", "BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE" },
2049{ 0x2563, "boxVl", "BOX DRAWINGS DOUBLE VERTICAL AND LEFT" },
2050{ 0x2564, "boxhD", "BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE" },
2051{ 0x2565, "boxHD", "BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE" },
2052{ 0x2566, "boxHd", "BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL" },
2053{ 0x2567, "boxhU", "BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE" },
2054{ 0x2568, "boxHU", "BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE" },
2055{ 0x2569, "boxHu", "BOX DRAWINGS DOUBLE UP AND HORIZONTAL" },
2056{ 0x256A, "boxvH", "BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE" },
2057{ 0x256B, "boxVH", "BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE" },
2058{ 0x256C, "boxVh", "BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL" },
2059{ 0x2580, "uhblk", "UPPER HALF BLOCK" },
2060{ 0x2584, "lhblk", "LOWER HALF BLOCK" },
2061{ 0x2588, "block", "FULL BLOCK" },
2062{ 0x2591, "blk14", "LIGHT SHADE" },
2063{ 0x2592, "blk12", "MEDIUM SHADE" },
2064{ 0x2593, "blk34", "DARK SHADE" },
2065{ 0x25A1, "square", "WHITE SQUARE" },
2066{ 0x25A1, "squ", "WHITE SQUARE" },
2067{ 0x25AA, "squf", "" },
2068{ 0x25AD, "rect", "WHITE RECTANGLE" },
2069{ 0x25AE, "marker", "BLACK VERTICAL RECTANGLE" },
2070{ 0x25B3, "xutri", "WHITE UP-POINTING TRIANGLE" },
2071{ 0x25B4, "utrif", "BLACK UP-POINTING TRIANGLE" },
2072{ 0x25B5, "utri", "WHITE UP-POINTING TRIANGLE" },
2073{ 0x25B8, "rtrif", "BLACK RIGHT-POINTING TRIANGLE" },
2074{ 0x25B9, "rtri", "WHITE RIGHT-POINTING TRIANGLE" },
2075{ 0x25BD, "xdtri", "WHITE DOWN-POINTING TRIANGLE" },
2076{ 0x25BE, "dtrif", "BLACK DOWN-POINTING TRIANGLE" },
2077{ 0x25BF, "dtri", "WHITE DOWN-POINTING TRIANGLE" },
2078{ 0x25C2, "ltrif", "BLACK LEFT-POINTING TRIANGLE" },
2079{ 0x25C3, "ltri", "WHITE LEFT-POINTING TRIANGLE" },
2080{ 0x25CA, "loz", "LOZENGE" },
2081{ 0x25CB, "cir", "WHITE CIRCLE" },
2082{ 0x25CB, "xcirc", "WHITE CIRCLE" },
2083{ 0x2605, "starf", "BLACK STAR" },
2084{ 0x260E, "phone", "TELEPHONE SIGN" },
2085{ 0x2640, "female", "" },
2086{ 0x2642, "male", "MALE SIGN" },
2087{ 0x2660, "spades", "BLACK SPADE SUIT" },
2088{ 0x2663, "clubs", "BLACK CLUB SUIT" },
2089{ 0x2665, "hearts", "BLACK HEART SUIT" },
2090{ 0x2666, "diams", "BLACK DIAMOND SUIT" },
2091{ 0x2669, "sung", "" },
2092{ 0x266D, "flat", "MUSIC FLAT SIGN" },
2093{ 0x266E, "natur", "MUSIC NATURAL SIGN" },
2094{ 0x266F, "sharp", "MUSIC SHARP SIGN" },
2095{ 0x2713, "check", "CHECK MARK" },
2096{ 0x2717, "cross", "BALLOT X" },
2097{ 0x2720, "malt", "MALTESE CROSS" },
2098{ 0x2726, "lozf", "" },
2099{ 0x2736, "sext", "SIX POINTED BLACK STAR" },
2100{ 0x3008, "lang", "" },
2101{ 0x3009, "rang", "" },
2102{ 0xE291, "rpargt", "" },
2103{ 0xE2A2, "lnap", "" },
2104{ 0xE2AA, "nsmid", "" },
2105{ 0xE2B3, "prnE", "" },
2106{ 0xE2B5, "scnE", "" },
2107{ 0xE2B8, "vsubnE", "" },
2108{ 0xE301, "smid", "" },
2109{ 0xE411, "gnap", "" },
2110{ 0xFB00, "fflig", "" },
2111{ 0xFB01, "filig", "" },
2112{ 0xFB02, "fllig", "" },
2113{ 0xFB03, "ffilig", "" },
2114{ 0xFB04, "ffllig", "" },
2115{ 0xFE68, "sbsol", "SMALL REVERSE SOLIDUS" },
2116};
2117
2118/************************************************************************
2119 * *
2120 * Commodity functions to handle entities *
2121 * *
2122 ************************************************************************/
2123
2124/*
2125 * Macro used to grow the current buffer.
2126 */
2127#define growBuffer(buffer) { \
2128 buffer##_size *= 2; \
2129 buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \
2130 if (buffer == NULL) { \
2131 perror("realloc failed"); \
2132 return(NULL); \
2133 } \
2134}
2135
2136/**
2137 * docbEntityLookup:
2138 * @name: the entity name
2139 *
2140 * Lookup the given entity in EntitiesTable
2141 *
2142 * TODO: the linear scan is really ugly, an hash table is really needed.
2143 *
2144 * Returns the associated docbEntityDescPtr if found, NULL otherwise.
2145 */
2146static docbEntityDescPtr
2147docbEntityLookup(const xmlChar *name) {
2148 unsigned int i;
2149
2150 for (i = 0;i < (sizeof(docbookEntitiesTable)/
2151 sizeof(docbookEntitiesTable[0]));i++) {
2152 if (xmlStrEqual(name, BAD_CAST docbookEntitiesTable[i].name)) {
2153#ifdef DEBUG
2154 xmlGenericError(xmlGenericErrorContext,"Found entity %s\n", name);
2155#endif
2156 return(&docbookEntitiesTable[i]);
2157 }
2158 }
2159 return(NULL);
2160}
2161
2162/**
2163 * docbEntityValueLookup:
2164 * @value: the entity's unicode value
2165 *
2166 * Lookup the given entity in EntitiesTable
2167 *
2168 * TODO: the linear scan is really ugly, an hash table is really needed.
2169 *
2170 * Returns the associated docbEntityDescPtr if found, NULL otherwise.
2171 */
2172static docbEntityDescPtr
2173docbEntityValueLookup(int value) {
2174 unsigned int i;
2175#ifdef DEBUG
2176 int lv = 0;
2177#endif
2178
2179 for (i = 0;i < (sizeof(docbookEntitiesTable)/
2180 sizeof(docbookEntitiesTable[0]));i++) {
2181 if (docbookEntitiesTable[i].value >= value) {
2182 if (docbookEntitiesTable[i].value > value)
2183 break;
2184#ifdef DEBUG
2185 xmlGenericError(xmlGenericErrorContext,"Found entity %s\n", docbookEntitiesTable[i].name);
2186#endif
2187 return(&docbookEntitiesTable[i]);
2188 }
2189#ifdef DEBUG
2190 if (lv > docbookEntitiesTable[i].value) {
2191 xmlGenericError(xmlGenericErrorContext,
2192 "docbookEntitiesTable[] is not sorted (%d > %d)!\n",
2193 lv, docbookEntitiesTable[i].value);
2194 }
2195 lv = docbookEntitiesTable[i].value;
2196#endif
2197 }
2198 return(NULL);
2199}
2200
2201#if 0
2202/**
2203 * UTF8ToSgml:
2204 * @out: a pointer to an array of bytes to store the result
2205 * @outlen: the length of @out
2206 * @in: a pointer to an array of UTF-8 chars
2207 * @inlen: the length of @in
2208 *
2209 * Take a block of UTF-8 chars in and try to convert it to an ASCII
2210 * plus SGML entities block of chars out.
2211 *
2212 * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise
2213 * The value of @inlen after return is the number of octets consumed
2214 * as the return value is positive, else unpredictiable.
2215 * The value of @outlen after return is the number of octets consumed.
2216 */
2217int
2218UTF8ToSgml(unsigned char* out, int *outlen,
2219 const unsigned char* in, int *inlen) {
2220 const unsigned char* processed = in;
2221 const unsigned char* outend;
2222 const unsigned char* outstart = out;
2223 const unsigned char* instart = in;
2224 const unsigned char* inend;
2225 unsigned int c, d;
2226 int trailing;
2227
2228 if (in == NULL) {
2229 /*
2230 * initialization nothing to do
2231 */
2232 *outlen = 0;
2233 *inlen = 0;
2234 return(0);
2235 }
2236 inend = in + (*inlen);
2237 outend = out + (*outlen);
2238 while (in < inend) {
2239 d = *in++;
2240 if (d < 0x80) { c= d; trailing= 0; }
2241 else if (d < 0xC0) {
2242 /* trailing byte in leading position */
2243 *outlen = out - outstart;
2244 *inlen = processed - instart;
2245 return(-2);
2246 } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; }
2247 else if (d < 0xF0) { c= d & 0x0F; trailing= 2; }
2248 else if (d < 0xF8) { c= d & 0x07; trailing= 3; }
2249 else {
2250 /* no chance for this in Ascii */
2251 *outlen = out - outstart;
2252 *inlen = processed - instart;
2253 return(-2);
2254 }
2255
2256 if (inend - in < trailing) {
2257 break;
2258 }
2259
2260 for ( ; trailing; trailing--) {
2261 if ((in >= inend) || (((d= *in++) & 0xC0) != 0x80))
2262 break;
2263 c <<= 6;
2264 c |= d & 0x3F;
2265 }
2266
2267 /* assertion: c is a single UTF-4 value */
2268 if (c < 0x80) {
2269 if (out + 1 >= outend)
2270 break;
2271 *out++ = c;
2272 } else {
2273 int len;
2274 docbEntityDescPtr ent;
2275
2276 /*
2277 * Try to lookup a predefined SGML entity for it
2278 */
2279
2280 ent = docbEntityValueLookup(c);
2281 if (ent == NULL) {
2282 /* no chance for this in Ascii */
2283 *outlen = out - outstart;
2284 *inlen = processed - instart;
2285 return(-2);
2286 }
2287 len = strlen(ent->name);
2288 if (out + 2 + len >= outend)
2289 break;
2290 *out++ = '&';
2291 memcpy(out, ent->name, len);
2292 out += len;
2293 *out++ = ';';
2294 }
2295 processed = in;
2296 }
2297 *outlen = out - outstart;
2298 *inlen = processed - instart;
2299 return(0);
2300}
2301#endif
2302
2303/**
2304 * docbEncodeEntities:
2305 * @out: a pointer to an array of bytes to store the result
2306 * @outlen: the length of @out
2307 * @in: a pointer to an array of UTF-8 chars
2308 * @inlen: the length of @in
2309 * @quoteChar: the quote character to escape (' or ") or zero.
2310 *
2311 * Take a block of UTF-8 chars in and try to convert it to an ASCII
2312 * plus SGML entities block of chars out.
2313 *
2314 * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise
2315 * The value of @inlen after return is the number of octets consumed
2316 * as the return value is positive, else unpredictiable.
2317 * The value of @outlen after return is the number of octets consumed.
2318 */
2319int
2320docbEncodeEntities(unsigned char* out, int *outlen,
2321 const unsigned char* in, int *inlen, int quoteChar) {
2322 const unsigned char* processed = in;
2323 const unsigned char* outend = out + (*outlen);
2324 const unsigned char* outstart = out;
2325 const unsigned char* instart = in;
2326 const unsigned char* inend = in + (*inlen);
2327 unsigned int c, d;
2328 int trailing;
2329
2330 while (in < inend) {
2331 d = *in++;
2332 if (d < 0x80) { c= d; trailing= 0; }
2333 else if (d < 0xC0) {
2334 /* trailing byte in leading position */
2335 *outlen = out - outstart;
2336 *inlen = processed - instart;
2337 return(-2);
2338 } else if (d < 0xE0) { c= d & 0x1F; trailing= 1; }
2339 else if (d < 0xF0) { c= d & 0x0F; trailing= 2; }
2340 else if (d < 0xF8) { c= d & 0x07; trailing= 3; }
2341 else {
2342 /* no chance for this in Ascii */
2343 *outlen = out - outstart;
2344 *inlen = processed - instart;
2345 return(-2);
2346 }
2347
2348 if (inend - in < trailing)
2349 break;
2350
2351 while (trailing--) {
2352 if (((d= *in++) & 0xC0) != 0x80) {
2353 *outlen = out - outstart;
2354 *inlen = processed - instart;
2355 return(-2);
2356 }
2357 c <<= 6;
2358 c |= d & 0x3F;
2359 }
2360
2361 /* assertion: c is a single UTF-4 value */
2362 if (c < 0x80 && c != (unsigned int) quoteChar && c != '&' && c != '<' && c != '>') {
2363 if (out >= outend)
2364 break;
2365 *out++ = c;
2366 } else {
2367 docbEntityDescPtr ent;
2368 const char *cp;
2369 char nbuf[16];
2370 int len;
2371
2372 /*
2373 * Try to lookup a predefined SGML entity for it
2374 */
2375 ent = docbEntityValueLookup(c);
2376 if (ent == NULL) {
2377 sprintf(nbuf, "#%u", c);
2378 cp = nbuf;
2379 }
2380 else
2381 cp = ent->name;
2382 len = strlen(cp);
2383 if (out + 2 + len > outend)
2384 break;
2385 *out++ = '&';
2386 memcpy(out, cp, len);
2387 out += len;
2388 *out++ = ';';
2389 }
2390 processed = in;
2391 }
2392 *outlen = out - outstart;
2393 *inlen = processed - instart;
2394 return(0);
2395}
2396
2397
2398/************************************************************************
2399 * *
2400 * Commodity functions to handle streams *
2401 * *
2402 ************************************************************************/
2403
2404/**
2405 * docbNewInputStream:
2406 * @ctxt: an SGML parser context
2407 *
2408 * Create a new input stream structure
2409 * Returns the new input stream or NULL
2410 */
2411static docbParserInputPtr
2412docbNewInputStream(docbParserCtxtPtr ctxt) {
2413 docbParserInputPtr input;
2414
2415 input = (xmlParserInputPtr) xmlMalloc(sizeof(docbParserInput));
2416 if (input == NULL) {
2417 ctxt->errNo = XML_ERR_NO_MEMORY;
2418 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2419 ctxt->sax->error(ctxt->userData,
2420 "malloc: couldn't allocate a new input stream\n");
2421 return(NULL);
2422 }
2423 memset(input, 0, sizeof(docbParserInput));
2424 input->filename = NULL;
2425 input->directory = NULL;
2426 input->base = NULL;
2427 input->cur = NULL;
2428 input->buf = NULL;
2429 input->line = 1;
2430 input->col = 1;
2431 input->buf = NULL;
2432 input->free = NULL;
2433 input->version = NULL;
2434 input->consumed = 0;
2435 input->length = 0;
2436 return(input);
2437}
2438
2439
2440/************************************************************************
2441 * *
2442 * Commodity functions, cleanup needed ? *
2443 * *
2444 ************************************************************************/
2445
2446/**
2447 * areBlanks:
2448 * @ctxt: an SGML parser context
2449 * @str: a xmlChar *
2450 * @len: the size of @str
2451 *
2452 * Is this a sequence of blank chars that one can ignore ?
2453 *
2454 * Returns 1 if ignorable 0 otherwise.
2455 */
2456
2457static int areBlanks(docbParserCtxtPtr ctxt, const xmlChar *str, int len) {
2458 int i;
2459 xmlNodePtr lastChild;
2460
2461 for (i = 0;i < len;i++)
2462 if (!(IS_BLANK(str[i]))) return(0);
2463
2464 if (CUR == 0) return(1);
2465 if (CUR != '<') return(0);
2466 if (ctxt->name == NULL)
2467 return(1);
2468 if (ctxt->node == NULL) return(0);
2469 lastChild = xmlGetLastChild(ctxt->node);
2470 if (lastChild == NULL) {
Daniel Veillard7db37732001-07-12 01:20:08 +00002471 if ((ctxt->node->type != XML_ELEMENT_NODE) &&
2472 (ctxt->node->content != NULL)) return(0);
Daniel Veillardeae522a2001-04-23 13:41:34 +00002473 } else if (xmlNodeIsText(lastChild))
2474 return(0);
2475 return(1);
2476}
2477
2478/************************************************************************
Daniel Veillard61b33d52001-04-24 13:55:12 +00002479 * *
2480 * External entities support *
2481 * *
2482 ************************************************************************/
2483
2484/**
2485 * docbParseCtxtExternalEntity:
2486 * @ctx: the existing parsing context
2487 * @URL: the URL for the entity to load
2488 * @ID: the System ID for the entity to load
2489 * @list: the return value for the set of parsed nodes
2490 *
2491 * Parse an external general entity within an existing parsing context
2492 *
2493 * Returns 0 if the entity is well formed, -1 in case of args problem and
2494 * the parser error code otherwise
2495 */
2496
2497static int
2498docbParseCtxtExternalEntity(xmlParserCtxtPtr ctx, const xmlChar *URL,
2499 const xmlChar *ID, xmlNodePtr *list) {
2500 xmlParserCtxtPtr ctxt;
2501 xmlDocPtr newDoc;
2502 xmlSAXHandlerPtr oldsax = NULL;
2503 int ret = 0;
2504
2505 if (ctx->depth > 40) {
2506 return(XML_ERR_ENTITY_LOOP);
2507 }
2508
2509 if (list != NULL)
2510 *list = NULL;
2511 if ((URL == NULL) && (ID == NULL))
2512 return(-1);
2513 if (ctx->myDoc == NULL) /* @@ relax but check for dereferences */
2514 return(-1);
2515
2516
2517 ctxt = xmlCreateEntityParserCtxt(URL, ID, ctx->myDoc->URL);
2518 if (ctxt == NULL) return(-1);
2519 ctxt->userData = ctxt;
2520 oldsax = ctxt->sax;
2521 ctxt->sax = ctx->sax;
2522 newDoc = xmlNewDoc(BAD_CAST "1.0");
2523 if (newDoc == NULL) {
2524 xmlFreeParserCtxt(ctxt);
2525 return(-1);
2526 }
2527 if (ctx->myDoc != NULL) {
2528 newDoc->intSubset = ctx->myDoc->intSubset;
2529 newDoc->extSubset = ctx->myDoc->extSubset;
2530 }
2531 if (ctx->myDoc->URL != NULL) {
2532 newDoc->URL = xmlStrdup(ctx->myDoc->URL);
2533 }
2534 newDoc->children = xmlNewDocNode(newDoc, NULL, BAD_CAST "pseudoroot", NULL);
2535 if (newDoc->children == NULL) {
2536 ctxt->sax = oldsax;
2537 xmlFreeParserCtxt(ctxt);
2538 newDoc->intSubset = NULL;
2539 newDoc->extSubset = NULL;
2540 xmlFreeDoc(newDoc);
2541 return(-1);
2542 }
2543 nodePush(ctxt, newDoc->children);
2544 if (ctx->myDoc == NULL) {
2545 ctxt->myDoc = newDoc;
2546 } else {
2547 ctxt->myDoc = ctx->myDoc;
2548 newDoc->children->doc = ctx->myDoc;
2549 }
2550
2551 /*
2552 * Parse a possible text declaration first
2553 */
2554 GROW;
2555 if ((RAW == '<') && (NXT(1) == '?') &&
2556 (NXT(2) == 'x') && (NXT(3) == 'm') &&
2557 (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
2558 xmlParseTextDecl(ctxt);
2559 }
2560
2561 /*
2562 * Doing validity checking on chunk doesn't make sense
2563 */
2564 ctxt->instate = XML_PARSER_CONTENT;
2565 ctxt->validate = ctx->validate;
2566 ctxt->loadsubset = ctx->loadsubset;
2567 ctxt->depth = ctx->depth + 1;
2568 ctxt->replaceEntities = ctx->replaceEntities;
2569 if (ctxt->validate) {
2570 ctxt->vctxt.error = ctx->vctxt.error;
2571 ctxt->vctxt.warning = ctx->vctxt.warning;
2572 /* Allocate the Node stack */
2573 ctxt->vctxt.nodeTab = (xmlNodePtr *) xmlMalloc(4 * sizeof(xmlNodePtr));
2574 if (ctxt->vctxt.nodeTab == NULL) {
2575 xmlGenericError(xmlGenericErrorContext,
2576 "docbParseCtxtExternalEntity: out of memory\n");
2577 ctxt->validate = 0;
2578 ctxt->vctxt.error = NULL;
2579 ctxt->vctxt.warning = NULL;
2580 } else {
2581 ctxt->vctxt.nodeNr = 0;
2582 ctxt->vctxt.nodeMax = 4;
2583 ctxt->vctxt.node = NULL;
2584 }
2585 } else {
2586 ctxt->vctxt.error = NULL;
2587 ctxt->vctxt.warning = NULL;
2588 }
2589
2590 docbParseContent(ctxt);
2591
2592 if ((RAW == '<') && (NXT(1) == '/')) {
2593 ctxt->errNo = XML_ERR_NOT_WELL_BALANCED;
2594 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2595 ctxt->sax->error(ctxt->userData,
2596 "chunk is not well balanced\n");
2597 ctxt->wellFormed = 0;
2598 ctxt->disableSAX = 1;
2599 } else if (RAW != 0) {
2600 ctxt->errNo = XML_ERR_EXTRA_CONTENT;
2601 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2602 ctxt->sax->error(ctxt->userData,
2603 "extra content at the end of well balanced chunk\n");
2604 ctxt->wellFormed = 0;
2605 ctxt->disableSAX = 1;
2606 }
2607 if (ctxt->node != newDoc->children) {
2608 ctxt->errNo = XML_ERR_NOT_WELL_BALANCED;
2609 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2610 ctxt->sax->error(ctxt->userData,
2611 "chunk is not well balanced\n");
2612 ctxt->wellFormed = 0;
2613 ctxt->disableSAX = 1;
2614 }
2615
2616 if (!ctxt->wellFormed) {
2617 if (ctxt->errNo == 0)
2618 ret = 1;
2619 else
2620 ret = ctxt->errNo;
2621 } else {
2622 if (list != NULL) {
2623 xmlNodePtr cur;
2624
2625 /*
2626 * Return the newly created nodeset after unlinking it from
2627 * they pseudo parent.
2628 */
2629 cur = newDoc->children->children;
2630 *list = cur;
2631 while (cur != NULL) {
2632 cur->parent = NULL;
2633 cur = cur->next;
2634 }
2635 newDoc->children->children = NULL;
2636 }
2637 ret = 0;
2638 }
2639 ctxt->sax = oldsax;
2640 xmlFreeParserCtxt(ctxt);
2641 newDoc->intSubset = NULL;
2642 newDoc->extSubset = NULL;
2643 xmlFreeDoc(newDoc);
2644
2645 return(ret);
2646}
2647
2648/************************************************************************
2649 * *
2650 * The parser itself *
2651 * *
Daniel Veillardeae522a2001-04-23 13:41:34 +00002652 ************************************************************************/
2653
2654/**
2655 * docbParseSGMLName:
2656 * @ctxt: an SGML parser context
2657 *
2658 * parse an SGML tag or attribute name, note that we convert it to lowercase
2659 * since SGML names are not case-sensitive.
2660 *
2661 * Returns the Tag Name parsed or NULL
2662 */
2663
2664static xmlChar *
2665docbParseSGMLName(docbParserCtxtPtr ctxt) {
2666 xmlChar *ret = NULL;
2667 int i = 0;
2668 xmlChar loc[DOCB_PARSER_BUFFER_SIZE];
2669
2670 if (!IS_LETTER(CUR) && (CUR != '_') &&
2671 (CUR != ':')) return(NULL);
2672
2673 while ((i < DOCB_PARSER_BUFFER_SIZE) &&
2674 ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) ||
2675 (CUR == ':') || (CUR == '_'))) {
2676 if ((CUR >= 'A') && (CUR <= 'Z')) loc[i] = CUR + 0x20;
2677 else loc[i] = CUR;
2678 i++;
2679
2680 NEXT;
2681 }
2682
2683 ret = xmlStrndup(loc, i);
2684
2685 return(ret);
2686}
2687
2688/**
2689 * docbParseName:
2690 * @ctxt: an SGML parser context
2691 *
2692 * parse an SGML name, this routine is case sensistive.
2693 *
2694 * Returns the Name parsed or NULL
2695 */
2696
2697static xmlChar *
2698docbParseName(docbParserCtxtPtr ctxt) {
2699 xmlChar buf[DOCB_MAX_NAMELEN];
2700 int len = 0;
2701
2702 GROW;
2703 if (!IS_LETTER(CUR) && (CUR != '_')) {
2704 return(NULL);
2705 }
2706
2707 while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) ||
2708 (CUR == '.') || (CUR == '-') ||
2709 (CUR == '_') || (CUR == ':') ||
2710 (IS_COMBINING(CUR)) ||
2711 (IS_EXTENDER(CUR))) {
2712 buf[len++] = CUR;
2713 NEXT;
2714 if (len >= DOCB_MAX_NAMELEN) {
2715 xmlGenericError(xmlGenericErrorContext,
2716 "docbParseName: reached DOCB_MAX_NAMELEN limit\n");
2717 while ((IS_LETTER(CUR)) || (IS_DIGIT(CUR)) ||
2718 (CUR == '.') || (CUR == '-') ||
2719 (CUR == '_') || (CUR == ':') ||
2720 (IS_COMBINING(CUR)) ||
2721 (IS_EXTENDER(CUR)))
2722 NEXT;
2723 break;
2724 }
2725 }
2726 return(xmlStrndup(buf, len));
2727}
2728
2729/**
2730 * docbParseSGMLAttribute:
2731 * @ctxt: an SGML parser context
2732 * @stop: a char stop value
2733 *
2734 * parse an SGML attribute value till the stop (quote), if
2735 * stop is 0 then it stops at the first space
2736 *
2737 * Returns the attribute parsed or NULL
2738 */
2739
2740static xmlChar *
2741docbParseSGMLAttribute(docbParserCtxtPtr ctxt, const xmlChar stop) {
2742 xmlChar *buffer = NULL;
2743 int buffer_size = 0;
2744 xmlChar *out = NULL;
2745 xmlChar *name = NULL;
2746
2747 xmlChar *cur = NULL;
Daniel Veillard61b33d52001-04-24 13:55:12 +00002748 xmlEntityPtr xent;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002749 docbEntityDescPtr ent;
2750
2751 /*
2752 * allocate a translation buffer.
2753 */
2754 buffer_size = DOCB_PARSER_BIG_BUFFER_SIZE;
2755 buffer = (xmlChar *) xmlMalloc(buffer_size * sizeof(xmlChar));
2756 if (buffer == NULL) {
2757 perror("docbParseSGMLAttribute: malloc failed");
2758 return(NULL);
2759 }
2760 out = buffer;
2761
2762 /*
2763 * Ok loop until we reach one of the ending chars
2764 */
2765 while ((CUR != 0) && (CUR != stop) && (CUR != '>')) {
2766 if ((stop == 0) && (IS_BLANK(CUR))) break;
2767 if (CUR == '&') {
2768 if (NXT(1) == '#') {
2769 unsigned int c;
2770 int bits;
2771
2772 c = docbParseCharRef(ctxt);
2773 if (c < 0x80)
2774 { *out++ = c; bits= -6; }
2775 else if (c < 0x800)
2776 { *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
2777 else if (c < 0x10000)
2778 { *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
2779 else
2780 { *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
2781
2782 for ( ; bits >= 0; bits-= 6) {
2783 *out++ = ((c >> bits) & 0x3F) | 0x80;
2784 }
2785 } else {
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002786 xent = docbParseEntityRef(ctxt, &name);
Daniel Veillardeae522a2001-04-23 13:41:34 +00002787 if (name == NULL) {
2788 *out++ = '&';
2789 if (out - buffer > buffer_size - 100) {
2790 int indx = out - buffer;
2791
2792 growBuffer(buffer);
2793 out = &buffer[indx];
2794 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002795 *out++ = '&';
Daniel Veillardeae522a2001-04-23 13:41:34 +00002796 } else {
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002797 ent = docbEntityLookup(name);
2798 if (ent == NULL) {
2799 *out++ = '&';
2800 cur = name;
2801 while (*cur != 0) {
2802 if (out - buffer > buffer_size - 100) {
2803 int indx = out - buffer;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002804
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002805 growBuffer(buffer);
2806 out = &buffer[indx];
2807 }
2808 *out++ = *cur++;
2809 }
2810 xmlFree(name);
2811 } else {
2812 unsigned int c;
2813 int bits;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002814
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002815 if (out - buffer > buffer_size - 100) {
2816 int indx = out - buffer;
2817
2818 growBuffer(buffer);
2819 out = &buffer[indx];
2820 }
2821 c = (xmlChar)ent->value;
2822 if (c < 0x80)
2823 { *out++ = c; bits= -6; }
2824 else if (c < 0x800)
2825 { *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
2826 else if (c < 0x10000)
2827 { *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
2828 else
2829 { *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
2830
2831 for ( ; bits >= 0; bits-= 6) {
2832 *out++ = ((c >> bits) & 0x3F) | 0x80;
2833 }
2834 xmlFree(name);
2835 }
2836 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002837 }
2838 } else {
2839 unsigned int c;
2840 int bits;
2841
2842 if (out - buffer > buffer_size - 100) {
2843 int indx = out - buffer;
2844
2845 growBuffer(buffer);
2846 out = &buffer[indx];
2847 }
2848 c = CUR;
2849 if (c < 0x80)
2850 { *out++ = c; bits= -6; }
2851 else if (c < 0x800)
2852 { *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
2853 else if (c < 0x10000)
2854 { *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
2855 else
2856 { *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
2857
2858 for ( ; bits >= 0; bits-= 6) {
2859 *out++ = ((c >> bits) & 0x3F) | 0x80;
2860 }
2861 NEXT;
2862 }
2863 }
2864 *out++ = 0;
2865 return(buffer);
2866}
2867
2868
2869/**
2870 * docbParseEntityRef:
2871 * @ctxt: an SGML parser context
2872 * @str: location to store the entity name
2873 *
2874 * parse an SGML ENTITY references
2875 *
2876 * [68] EntityRef ::= '&' Name ';'
2877 *
Daniel Veillard61b33d52001-04-24 13:55:12 +00002878 * Returns the associated xmlEntityPtr if found, or NULL otherwise,
Daniel Veillardeae522a2001-04-23 13:41:34 +00002879 * if non-NULL *str will have to be freed by the caller.
2880 */
Daniel Veillard61b33d52001-04-24 13:55:12 +00002881static xmlEntityPtr
Daniel Veillardeae522a2001-04-23 13:41:34 +00002882docbParseEntityRef(docbParserCtxtPtr ctxt, xmlChar **str) {
2883 xmlChar *name;
Daniel Veillard61b33d52001-04-24 13:55:12 +00002884 xmlEntityPtr ent = NULL;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002885 *str = NULL;
2886
2887 if (CUR == '&') {
2888 NEXT;
2889 name = docbParseName(ctxt);
Daniel Veillard61b33d52001-04-24 13:55:12 +00002890 if (name == NULL) {
2891 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2892 ctxt->sax->error(ctxt->userData,
2893 "docbParseEntityRef: no name\n");
2894 ctxt->wellFormed = 0;
2895 } else {
Daniel Veillardeae522a2001-04-23 13:41:34 +00002896 GROW;
Daniel Veillard61b33d52001-04-24 13:55:12 +00002897 if (CUR == ';') {
2898 *str = name;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002899
Daniel Veillard61b33d52001-04-24 13:55:12 +00002900 /*
2901 * Ask first SAX for entity resolution, otherwise try the
2902 * predefined set.
2903 */
2904 if (ctxt->sax != NULL) {
2905 if (ctxt->sax->getEntity != NULL)
2906 ent = ctxt->sax->getEntity(ctxt->userData, name);
2907 if (ent == NULL)
2908 ent = xmlGetPredefinedEntity(name);
2909 }
2910 NEXT;
2911 } else {
2912 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2913 ctxt->sax->error(ctxt->userData,
Daniel Veillardeae522a2001-04-23 13:41:34 +00002914 "docbParseEntityRef: expecting ';'\n");
Daniel Veillard61b33d52001-04-24 13:55:12 +00002915 *str = name;
2916 }
2917 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002918 }
2919 return(ent);
2920}
2921
2922/**
2923 * docbParseAttValue:
2924 * @ctxt: an SGML parser context
2925 *
2926 * parse a value for an attribute
2927 * Note: the parser won't do substitution of entities here, this
2928 * will be handled later in xmlStringGetNodeList, unless it was
2929 * asked for ctxt->replaceEntities != 0
2930 *
2931 * Returns the AttValue parsed or NULL.
2932 */
2933
2934static xmlChar *
2935docbParseAttValue(docbParserCtxtPtr ctxt) {
2936 xmlChar *ret = NULL;
2937
2938 if (CUR == '"') {
2939 NEXT;
2940 ret = docbParseSGMLAttribute(ctxt, '"');
2941 if (CUR != '"') {
2942 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2943 ctxt->sax->error(ctxt->userData, "AttValue: ' expected\n");
2944 ctxt->wellFormed = 0;
2945 } else
2946 NEXT;
2947 } else if (CUR == '\'') {
2948 NEXT;
2949 ret = docbParseSGMLAttribute(ctxt, '\'');
2950 if (CUR != '\'') {
2951 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2952 ctxt->sax->error(ctxt->userData, "AttValue: ' expected\n");
2953 ctxt->wellFormed = 0;
2954 } else
2955 NEXT;
2956 } else {
2957 /*
2958 * That's an SGMLism, the attribute value may not be quoted
2959 */
2960 ret = docbParseSGMLAttribute(ctxt, 0);
2961 if (ret == NULL) {
2962 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2963 ctxt->sax->error(ctxt->userData, "AttValue: no value found\n");
2964 ctxt->wellFormed = 0;
2965 }
2966 }
2967 return(ret);
2968}
2969
2970/**
2971 * docbParseSystemLiteral:
2972 * @ctxt: an SGML parser context
2973 *
2974 * parse an SGML Literal
2975 *
2976 * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
2977 *
2978 * Returns the SystemLiteral parsed or NULL
2979 */
2980
2981static xmlChar *
2982docbParseSystemLiteral(docbParserCtxtPtr ctxt) {
2983 const xmlChar *q;
2984 xmlChar *ret = NULL;
2985
2986 if (CUR == '"') {
2987 NEXT;
2988 q = CUR_PTR;
2989 while ((IS_CHAR(CUR)) && (CUR != '"'))
2990 NEXT;
2991 if (!IS_CHAR(CUR)) {
2992 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2993 ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n");
2994 ctxt->wellFormed = 0;
2995 } else {
2996 ret = xmlStrndup(q, CUR_PTR - q);
2997 NEXT;
2998 }
2999 } else if (CUR == '\'') {
3000 NEXT;
3001 q = CUR_PTR;
3002 while ((IS_CHAR(CUR)) && (CUR != '\''))
3003 NEXT;
3004 if (!IS_CHAR(CUR)) {
3005 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3006 ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n");
3007 ctxt->wellFormed = 0;
3008 } else {
3009 ret = xmlStrndup(q, CUR_PTR - q);
3010 NEXT;
3011 }
3012 } else {
3013 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3014 ctxt->sax->error(ctxt->userData,
3015 "SystemLiteral \" or ' expected\n");
3016 ctxt->wellFormed = 0;
3017 }
3018
3019 return(ret);
3020}
3021
3022/**
3023 * docbParsePubidLiteral:
3024 * @ctxt: an SGML parser context
3025 *
3026 * parse an SGML public literal
3027 *
3028 * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
3029 *
3030 * Returns the PubidLiteral parsed or NULL.
3031 */
3032
3033static xmlChar *
3034docbParsePubidLiteral(docbParserCtxtPtr ctxt) {
3035 const xmlChar *q;
3036 xmlChar *ret = NULL;
3037 /*
3038 * Name ::= (Letter | '_') (NameChar)*
3039 */
3040 if (CUR == '"') {
3041 NEXT;
3042 q = CUR_PTR;
3043 while (IS_PUBIDCHAR(CUR)) NEXT;
3044 if (CUR != '"') {
3045 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3046 ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n");
3047 ctxt->wellFormed = 0;
3048 } else {
3049 ret = xmlStrndup(q, CUR_PTR - q);
3050 NEXT;
3051 }
3052 } else if (CUR == '\'') {
3053 NEXT;
3054 q = CUR_PTR;
3055 while ((IS_LETTER(CUR)) && (CUR != '\''))
3056 NEXT;
3057 if (!IS_LETTER(CUR)) {
3058 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3059 ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n");
3060 ctxt->wellFormed = 0;
3061 } else {
3062 ret = xmlStrndup(q, CUR_PTR - q);
3063 NEXT;
3064 }
3065 } else {
3066 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3067 ctxt->sax->error(ctxt->userData, "SystemLiteral \" or ' expected\n");
3068 ctxt->wellFormed = 0;
3069 }
3070
3071 return(ret);
3072}
3073
3074/**
3075 * docbParseCharData:
3076 * @ctxt: an SGML parser context
3077 * @cdata: int indicating whether we are within a CDATA section
3078 *
3079 * parse a CharData section.
3080 * if we are within a CDATA section ']]>' marks an end of section.
3081 *
3082 * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
3083 */
3084
3085static void
3086docbParseCharData(docbParserCtxtPtr ctxt) {
3087 xmlChar buf[DOCB_PARSER_BIG_BUFFER_SIZE + 5];
3088 int nbchar = 0;
3089 int cur, l;
3090
3091 SHRINK;
3092 cur = CUR_CHAR(l);
3093 while (((cur != '<') || (ctxt->token == '<')) &&
3094 ((cur != '&') || (ctxt->token == '&')) &&
3095 (IS_CHAR(cur))) {
3096 COPY_BUF(l,buf,nbchar,cur);
3097 if (nbchar >= DOCB_PARSER_BIG_BUFFER_SIZE) {
3098 /*
3099 * Ok the segment is to be consumed as chars.
3100 */
3101 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
3102 if (areBlanks(ctxt, buf, nbchar)) {
3103 if (ctxt->sax->ignorableWhitespace != NULL)
3104 ctxt->sax->ignorableWhitespace(ctxt->userData,
3105 buf, nbchar);
3106 } else {
3107 docbCheckParagraph(ctxt);
3108 if (ctxt->sax->characters != NULL)
3109 ctxt->sax->characters(ctxt->userData, buf, nbchar);
3110 }
3111 }
3112 nbchar = 0;
3113 }
3114 NEXTL(l);
3115 cur = CUR_CHAR(l);
3116 }
3117 if (nbchar != 0) {
3118 /*
3119 * Ok the segment is to be consumed as chars.
3120 */
3121 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
3122 if (areBlanks(ctxt, buf, nbchar)) {
3123 if (ctxt->sax->ignorableWhitespace != NULL)
3124 ctxt->sax->ignorableWhitespace(ctxt->userData, buf, nbchar);
3125 } else {
3126 docbCheckParagraph(ctxt);
3127 if (ctxt->sax->characters != NULL)
3128 ctxt->sax->characters(ctxt->userData, buf, nbchar);
3129 }
3130 }
3131 }
3132}
3133
3134/**
3135 * docbParseExternalID:
3136 * @ctxt: an SGML parser context
3137 * @publicID: a xmlChar** receiving PubidLiteral
3138 *
3139 * Parse an External ID or a Public ID
3140 *
3141 * Returns the function returns SystemLiteral and in the second
3142 * case publicID receives PubidLiteral,
3143 * it is possible to return NULL and have publicID set.
3144 */
3145
3146static xmlChar *
3147docbParseExternalID(docbParserCtxtPtr ctxt, xmlChar **publicID) {
3148 xmlChar *URI = NULL;
3149
3150 if ((UPPER == 'S') && (UPP(1) == 'Y') &&
3151 (UPP(2) == 'S') && (UPP(3) == 'T') &&
3152 (UPP(4) == 'E') && (UPP(5) == 'M')) {
3153 SKIP(6);
3154 if (!IS_BLANK(CUR)) {
3155 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3156 ctxt->sax->error(ctxt->userData,
3157 "Space required after 'SYSTEM'\n");
3158 ctxt->wellFormed = 0;
3159 }
3160 SKIP_BLANKS;
3161 URI = docbParseSystemLiteral(ctxt);
3162 if (URI == NULL) {
3163 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3164 ctxt->sax->error(ctxt->userData,
3165 "docbParseExternalID: SYSTEM, no URI\n");
3166 ctxt->wellFormed = 0;
3167 }
3168 } else if ((UPPER == 'P') && (UPP(1) == 'U') &&
3169 (UPP(2) == 'B') && (UPP(3) == 'L') &&
3170 (UPP(4) == 'I') && (UPP(5) == 'C')) {
3171 SKIP(6);
3172 if (!IS_BLANK(CUR)) {
3173 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3174 ctxt->sax->error(ctxt->userData,
3175 "Space required after 'PUBLIC'\n");
3176 ctxt->wellFormed = 0;
3177 }
3178 SKIP_BLANKS;
3179 *publicID = docbParsePubidLiteral(ctxt);
3180 if (*publicID == NULL) {
3181 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3182 ctxt->sax->error(ctxt->userData,
3183 "docbParseExternalID: PUBLIC, no Public Identifier\n");
3184 ctxt->wellFormed = 0;
3185 }
3186 SKIP_BLANKS;
3187 if ((CUR == '"') || (CUR == '\'')) {
3188 URI = docbParseSystemLiteral(ctxt);
3189 }
3190 }
3191 return(URI);
3192}
3193
3194/**
Daniel Veillarde95e2392001-06-06 10:46:28 +00003195 * docbParsePI:
3196 * @ctxt: an XML parser context
3197 *
3198 * parse an XML Processing Instruction.
3199 *
3200 * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
3201 *
3202 * The processing is transfered to SAX once parsed.
3203 */
3204
3205static void
3206docbParsePI(xmlParserCtxtPtr ctxt) {
3207 xmlChar *buf = NULL;
3208 int len = 0;
3209 int size = DOCB_PARSER_BUFFER_SIZE;
3210 int cur, l;
3211 xmlChar *target;
3212 xmlParserInputState state;
3213 int count = 0;
3214
3215 if ((RAW == '<') && (NXT(1) == '?')) {
3216 xmlParserInputPtr input = ctxt->input;
3217 state = ctxt->instate;
3218 ctxt->instate = XML_PARSER_PI;
3219 /*
3220 * this is a Processing Instruction.
3221 */
3222 SKIP(2);
3223 SHRINK;
3224
3225 /*
3226 * Parse the target name and check for special support like
3227 * namespace.
3228 */
3229 target = xmlParseName(ctxt);
3230 if (target != NULL) {
3231 xmlChar *encoding = NULL;
3232
3233 if ((RAW == '?') && (NXT(1) == '>')) {
3234 if (input != ctxt->input) {
3235 ctxt->errNo = XML_ERR_ENTITY_BOUNDARY;
3236 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3237 ctxt->sax->error(ctxt->userData,
3238 "PI declaration doesn't start and stop in the same entity\n");
3239 ctxt->wellFormed = 0;
3240 ctxt->disableSAX = 1;
3241 }
3242 SKIP(2);
3243
3244 /*
3245 * SAX: PI detected.
3246 */
3247 if ((ctxt->sax) && (!ctxt->disableSAX) &&
3248 (ctxt->sax->processingInstruction != NULL))
3249 ctxt->sax->processingInstruction(ctxt->userData,
3250 target, NULL);
3251 ctxt->instate = state;
3252 xmlFree(target);
3253 return;
3254 }
3255 if (xmlStrEqual(target, BAD_CAST "sgml-declaration")) {
3256
3257 encoding = xmlParseEncodingDecl(ctxt);
3258 if (encoding == NULL) {
3259 xmlGenericError(xmlGenericErrorContext,
3260 "sgml-declaration: failed to find/handle encoding\n");
3261#ifdef DEBUG
3262 } else {
3263 xmlGenericError(xmlGenericErrorContext,
3264 "switched to encoding %s\n", encoding);
3265#endif
3266 }
3267
3268 }
3269 buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar));
3270 if (buf == NULL) {
3271 xmlGenericError(xmlGenericErrorContext,
3272 "malloc of %d byte failed\n", size);
3273 ctxt->instate = state;
3274 return;
3275 }
3276 cur = CUR;
3277 if (encoding != NULL) {
3278 len = snprintf((char *) buf, size - 1,
3279 " encoding = \"%s\"", encoding);
3280 if (len < 0)
3281 len = size;
3282 } else {
3283 if (!IS_BLANK(cur)) {
3284 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
3285 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3286 ctxt->sax->error(ctxt->userData,
3287 "docbParsePI: PI %s space expected\n", target);
3288 ctxt->wellFormed = 0;
3289 ctxt->disableSAX = 1;
3290 }
3291 SKIP_BLANKS;
3292 }
3293 cur = CUR_CHAR(l);
3294 while (IS_CHAR(cur) && /* checked */
3295 ((cur != '?') || (NXT(1) != '>'))) {
3296 if (len + 5 >= size) {
3297 size *= 2;
3298 buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
3299 if (buf == NULL) {
3300 xmlGenericError(xmlGenericErrorContext,
3301 "realloc of %d byte failed\n", size);
3302 ctxt->instate = state;
3303 return;
3304 }
3305 }
3306 count++;
3307 if (count > 50) {
3308 GROW;
3309 count = 0;
3310 }
3311 COPY_BUF(l,buf,len,cur);
3312 NEXTL(l);
3313 cur = CUR_CHAR(l);
3314 if (cur == 0) {
3315 SHRINK;
3316 GROW;
3317 cur = CUR_CHAR(l);
3318 }
3319 }
3320 buf[len] = 0;
3321 if (cur != '?') {
3322 ctxt->errNo = XML_ERR_PI_NOT_FINISHED;
3323 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3324 ctxt->sax->error(ctxt->userData,
3325 "docbParsePI: PI %s never end ...\n", target);
3326 ctxt->wellFormed = 0;
3327 ctxt->disableSAX = 1;
3328 } else {
3329 if (input != ctxt->input) {
3330 ctxt->errNo = XML_ERR_ENTITY_BOUNDARY;
3331 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3332 ctxt->sax->error(ctxt->userData,
3333 "PI declaration doesn't start and stop in the same entity\n");
3334 ctxt->wellFormed = 0;
3335 ctxt->disableSAX = 1;
3336 }
3337 SKIP(2);
3338
3339 /*
3340 * SAX: PI detected.
3341 */
3342 if ((ctxt->sax) && (!ctxt->disableSAX) &&
3343 (ctxt->sax->processingInstruction != NULL))
3344 ctxt->sax->processingInstruction(ctxt->userData,
3345 target, buf);
3346 }
3347 xmlFree(buf);
3348 xmlFree(target);
3349 } else {
3350 ctxt->errNo = XML_ERR_PI_NOT_STARTED;
3351 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3352 ctxt->sax->error(ctxt->userData,
3353 "docbParsePI : no target name\n");
3354 ctxt->wellFormed = 0;
3355 ctxt->disableSAX = 1;
3356 }
3357 ctxt->instate = state;
3358 }
3359}
3360
3361/**
Daniel Veillardeae522a2001-04-23 13:41:34 +00003362 * docbParseComment:
3363 * @ctxt: an SGML parser context
3364 *
3365 * Parse an XML (SGML) comment <!-- .... -->
3366 *
3367 * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
3368 */
3369static void
3370docbParseComment(docbParserCtxtPtr ctxt) {
3371 xmlChar *buf = NULL;
3372 int len;
3373 int size = DOCB_PARSER_BUFFER_SIZE;
3374 int q, ql;
3375 int r, rl;
3376 int cur, l;
3377 xmlParserInputState state;
3378
3379 /*
3380 * Check that there is a comment right here.
3381 */
3382 if ((RAW != '<') || (NXT(1) != '!') ||
3383 (NXT(2) != '-') || (NXT(3) != '-')) return;
3384
3385 state = ctxt->instate;
3386 ctxt->instate = XML_PARSER_COMMENT;
3387 SHRINK;
3388 SKIP(4);
3389 buf = (xmlChar *) xmlMalloc(size * sizeof(xmlChar));
3390 if (buf == NULL) {
3391 xmlGenericError(xmlGenericErrorContext,
3392 "malloc of %d byte failed\n", size);
3393 ctxt->instate = state;
3394 return;
3395 }
3396 q = CUR_CHAR(ql);
3397 NEXTL(ql);
3398 r = CUR_CHAR(rl);
3399 NEXTL(rl);
3400 cur = CUR_CHAR(l);
3401 len = 0;
3402 while (IS_CHAR(cur) &&
3403 ((cur != '>') ||
3404 (r != '-') || (q != '-'))) {
3405 if (len + 5 >= size) {
3406 size *= 2;
3407 buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
3408 if (buf == NULL) {
3409 xmlGenericError(xmlGenericErrorContext,
3410 "realloc of %d byte failed\n", size);
3411 ctxt->instate = state;
3412 return;
3413 }
3414 }
3415 COPY_BUF(ql,buf,len,q);
3416 q = r;
3417 ql = rl;
3418 r = cur;
3419 rl = l;
3420 NEXTL(l);
3421 cur = CUR_CHAR(l);
3422 if (cur == 0) {
3423 SHRINK;
3424 GROW;
3425 cur = CUR_CHAR(l);
3426 }
3427 }
3428 buf[len] = 0;
3429 if (!IS_CHAR(cur)) {
3430 ctxt->errNo = XML_ERR_COMMENT_NOT_FINISHED;
3431 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3432 ctxt->sax->error(ctxt->userData,
3433 "Comment not terminated \n<!--%.50s\n", buf);
3434 ctxt->wellFormed = 0;
3435 xmlFree(buf);
3436 } else {
3437 NEXT;
3438 if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) &&
3439 (!ctxt->disableSAX))
3440 ctxt->sax->comment(ctxt->userData, buf);
3441 xmlFree(buf);
3442 }
3443 ctxt->instate = state;
3444}
3445
3446/**
3447 * docbParseCharRef:
3448 * @ctxt: an SGML parser context
3449 *
3450 * parse Reference declarations
3451 *
3452 * [66] CharRef ::= '&#' [0-9]+ ';' |
3453 * '&#x' [0-9a-fA-F]+ ';'
3454 *
3455 * Returns the value parsed (as an int)
3456 */
3457static int
3458docbParseCharRef(docbParserCtxtPtr ctxt) {
3459 int val = 0;
3460
3461 if ((CUR == '&') && (NXT(1) == '#') &&
3462 (NXT(2) == 'x')) {
3463 SKIP(3);
3464 while (CUR != ';') {
3465 if ((CUR >= '0') && (CUR <= '9'))
3466 val = val * 16 + (CUR - '0');
3467 else if ((CUR >= 'a') && (CUR <= 'f'))
3468 val = val * 16 + (CUR - 'a') + 10;
3469 else if ((CUR >= 'A') && (CUR <= 'F'))
3470 val = val * 16 + (CUR - 'A') + 10;
3471 else {
3472 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3473 ctxt->sax->error(ctxt->userData,
3474 "docbParseCharRef: invalid hexadecimal value\n");
3475 ctxt->wellFormed = 0;
3476 val = 0;
3477 break;
3478 }
3479 NEXT;
3480 }
3481 if (CUR == ';')
3482 NEXT;
3483 } else if ((CUR == '&') && (NXT(1) == '#')) {
3484 SKIP(2);
3485 while (CUR != ';') {
3486 if ((CUR >= '0') && (CUR <= '9'))
3487 val = val * 10 + (CUR - '0');
3488 else {
3489 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3490 ctxt->sax->error(ctxt->userData,
3491 "docbParseCharRef: invalid decimal value\n");
3492 ctxt->wellFormed = 0;
3493 val = 0;
3494 break;
3495 }
3496 NEXT;
3497 }
3498 if (CUR == ';')
3499 NEXT;
3500 } else {
3501 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3502 ctxt->sax->error(ctxt->userData, "docbParseCharRef: invalid value\n");
3503 ctxt->wellFormed = 0;
3504 }
3505 /*
3506 * Check the value IS_CHAR ...
3507 */
3508 if (IS_CHAR(val)) {
3509 return(val);
3510 } else {
3511 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3512 ctxt->sax->error(ctxt->userData, "docbParseCharRef: invalid xmlChar value %d\n",
3513 val);
3514 ctxt->wellFormed = 0;
3515 }
3516 return(0);
3517}
3518
3519
3520/**
3521 * docbParseDocTypeDecl :
3522 * @ctxt: an SGML parser context
3523 *
3524 * parse a DOCTYPE declaration
3525 *
3526 * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
3527 * ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
3528 */
3529
3530static void
3531docbParseDocTypeDecl(docbParserCtxtPtr ctxt) {
3532 xmlChar *name;
3533 xmlChar *ExternalID = NULL;
3534 xmlChar *URI = NULL;
3535
3536 /*
3537 * We know that '<!DOCTYPE' has been detected.
3538 */
3539 SKIP(9);
3540
3541 SKIP_BLANKS;
3542
3543 /*
3544 * Parse the DOCTYPE name.
3545 */
3546 name = docbParseName(ctxt);
3547 if (name == NULL) {
3548 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3549 ctxt->sax->error(ctxt->userData, "docbParseDocTypeDecl : no DOCTYPE name !\n");
3550 ctxt->wellFormed = 0;
3551 }
3552 /*
3553 * Check that upper(name) == "SGML" !!!!!!!!!!!!!
3554 */
3555
3556 SKIP_BLANKS;
3557
3558 /*
3559 * Check for SystemID and ExternalID
3560 */
3561 URI = docbParseExternalID(ctxt, &ExternalID);
3562 SKIP_BLANKS;
3563
3564 /*
3565 * Create or update the document accordingly to the DOCTYPE
Daniel Veillard89cad532001-10-22 09:46:13 +00003566 * But use the predefined PUBLIC and SYSTEM ID of DocBook XML
Daniel Veillardeae522a2001-04-23 13:41:34 +00003567 */
3568 if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) &&
3569 (!ctxt->disableSAX))
Daniel Veillard89cad532001-10-22 09:46:13 +00003570 ctxt->sax->internalSubset(ctxt->userData, name,
3571 XML_DOCBOOK_XML_PUBLIC,
3572 XML_DOCBOOK_XML_SYSTEM);
Daniel Veillardeae522a2001-04-23 13:41:34 +00003573
Daniel Veillard89cad532001-10-22 09:46:13 +00003574 if (RAW != '>') {
3575 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3576 ctxt->sax->error(ctxt->userData,
3577 "docbParseDocTypeDecl : internal subset not handled\n");
3578 } else {
3579 NEXT;
Daniel Veillardeae522a2001-04-23 13:41:34 +00003580 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00003581
3582 /*
3583 * Cleanup, since we don't use all those identifiers
3584 */
3585 if (URI != NULL) xmlFree(URI);
3586 if (ExternalID != NULL) xmlFree(ExternalID);
3587 if (name != NULL) xmlFree(name);
3588}
3589
3590/**
3591 * docbParseAttribute:
3592 * @ctxt: an SGML parser context
3593 * @value: a xmlChar ** used to store the value of the attribute
3594 *
3595 * parse an attribute
3596 *
3597 * [41] Attribute ::= Name Eq AttValue
3598 *
3599 * [25] Eq ::= S? '=' S?
3600 *
3601 * With namespace:
3602 *
3603 * [NS 11] Attribute ::= QName Eq AttValue
3604 *
3605 * Also the case QName == xmlns:??? is handled independently as a namespace
3606 * definition.
3607 *
3608 * Returns the attribute name, and the value in *value.
3609 */
3610
3611static xmlChar *
3612docbParseAttribute(docbParserCtxtPtr ctxt, xmlChar **value) {
3613 xmlChar *name, *val = NULL;
3614
3615 *value = NULL;
3616 name = docbParseName(ctxt);
3617 if (name == NULL) {
3618 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3619 ctxt->sax->error(ctxt->userData, "error parsing attribute name\n");
3620 ctxt->wellFormed = 0;
3621 return(NULL);
3622 }
3623
3624 /*
3625 * read the value
3626 */
3627 SKIP_BLANKS;
3628 if (CUR == '=') {
3629 NEXT;
3630 SKIP_BLANKS;
3631 val = docbParseAttValue(ctxt);
3632 /******
3633 } else {
3634 * TODO : some attribute must have values, some may not
3635 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3636 ctxt->sax->warning(ctxt->userData,
3637 "No value for attribute %s\n", name); */
3638 }
3639
3640 *value = val;
3641 return(name);
3642}
3643
3644/**
3645 * docbCheckEncoding:
3646 * @ctxt: an SGML parser context
3647 * @attvalue: the attribute value
3648 *
3649 * Checks an http-equiv attribute from a Meta tag to detect
3650 * the encoding
3651 * If a new encoding is detected the parser is switched to decode
3652 * it and pass UTF8
3653 */
3654static void
3655docbCheckEncoding(docbParserCtxtPtr ctxt, const xmlChar *attvalue) {
3656 const xmlChar *encoding;
3657
3658 if ((ctxt == NULL) || (attvalue == NULL))
3659 return;
3660
3661 encoding = xmlStrstr(attvalue, BAD_CAST"charset=");
3662 if (encoding == NULL)
3663 encoding = xmlStrstr(attvalue, BAD_CAST"Charset=");
3664 if (encoding == NULL)
3665 encoding = xmlStrstr(attvalue, BAD_CAST"CHARSET=");
3666 if (encoding != NULL) {
3667 encoding += 8;
3668 } else {
3669 encoding = xmlStrstr(attvalue, BAD_CAST"charset =");
3670 if (encoding == NULL)
3671 encoding = xmlStrstr(attvalue, BAD_CAST"Charset =");
3672 if (encoding == NULL)
3673 encoding = xmlStrstr(attvalue, BAD_CAST"CHARSET =");
3674 if (encoding != NULL)
3675 encoding += 9;
3676 }
3677 /*
3678 * Restricted from 2.3.5 */
3679 if (encoding != NULL) {
3680 xmlCharEncoding enc;
3681
3682 if (ctxt->input->encoding != NULL)
3683 xmlFree((xmlChar *) ctxt->input->encoding);
3684 ctxt->input->encoding = encoding;
3685
3686 enc = xmlParseCharEncoding((const char *) encoding);
3687 if (enc == XML_CHAR_ENCODING_8859_1) {
3688 ctxt->charset = XML_CHAR_ENCODING_8859_1;
3689 } else if (enc != XML_CHAR_ENCODING_UTF8) {
3690 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3691 ctxt->sax->error(ctxt->userData,
3692 "Unsupported encoding %s\n", encoding);
3693 /* xmlFree(encoding); */
3694 ctxt->wellFormed = 0;
3695 ctxt->disableSAX = 1;
3696 ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;
3697 }
3698 }
3699}
3700
3701/**
3702 * docbCheckMeta:
3703 * @ctxt: an SGML parser context
3704 * @atts: the attributes values
3705 *
3706 * Checks an attributes from a Meta tag
3707 */
3708static void
3709docbCheckMeta(docbParserCtxtPtr ctxt, const xmlChar **atts) {
3710 int i;
3711 const xmlChar *att, *value;
3712 int http = 0;
3713 const xmlChar *content = NULL;
3714
3715 if ((ctxt == NULL) || (atts == NULL))
3716 return;
3717
3718 i = 0;
3719 att = atts[i++];
3720 while (att != NULL) {
3721 value = atts[i++];
3722 if ((value != NULL) &&
3723 ((xmlStrEqual(att, BAD_CAST"http-equiv")) ||
3724 (xmlStrEqual(att, BAD_CAST"Http-Equiv")) ||
3725 (xmlStrEqual(att, BAD_CAST"HTTP-EQUIV"))) &&
3726 ((xmlStrEqual(value, BAD_CAST"Content-Type")) ||
3727 (xmlStrEqual(value, BAD_CAST"content-type")) ||
3728 (xmlStrEqual(value, BAD_CAST"CONTENT-TYPE"))))
3729 http = 1;
3730 else if ((value != NULL) &&
3731 ((xmlStrEqual(att, BAD_CAST"content")) ||
3732 (xmlStrEqual(att, BAD_CAST"Content")) ||
3733 (xmlStrEqual(att, BAD_CAST"CONTENT"))))
3734 content = value;
3735 att = atts[i++];
3736 }
3737 if ((http) && (content != NULL))
3738 docbCheckEncoding(ctxt, content);
3739
3740}
3741
3742/**
3743 * docbParseStartTag:
3744 * @ctxt: an SGML parser context
3745 *
3746 * parse a start of tag either for rule element or
3747 * EmptyElement. In both case we don't parse the tag closing chars.
3748 *
3749 * [40] STag ::= '<' Name (S Attribute)* S? '>'
3750 *
3751 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
3752 *
3753 * With namespace:
3754 *
3755 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>'
3756 *
3757 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
3758 *
3759 */
3760
3761static void
3762docbParseStartTag(docbParserCtxtPtr ctxt) {
3763 xmlChar *name;
3764 xmlChar *attname;
3765 xmlChar *attvalue;
3766 const xmlChar **atts = NULL;
3767 int nbatts = 0;
3768 int maxatts = 0;
3769 int meta = 0;
3770 int i;
3771
3772 if (CUR != '<') return;
3773 NEXT;
3774
3775 GROW;
3776 name = docbParseSGMLName(ctxt);
3777 if (name == NULL) {
3778 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3779 ctxt->sax->error(ctxt->userData,
3780 "docbParseStartTag: invalid element name\n");
3781 ctxt->wellFormed = 0;
3782 return;
3783 }
3784 if (xmlStrEqual(name, BAD_CAST"meta"))
3785 meta = 1;
3786
3787 /*
3788 * Check for auto-closure of SGML elements.
3789 */
3790 docbAutoClose(ctxt, name);
3791
3792 /*
3793 * Now parse the attributes, it ends up with the ending
3794 *
3795 * (S Attribute)* S?
3796 */
3797 SKIP_BLANKS;
3798 while ((IS_CHAR(CUR)) &&
3799 (CUR != '>') &&
3800 ((CUR != '/') || (NXT(1) != '>'))) {
3801 long cons = ctxt->nbChars;
3802
3803 GROW;
3804 attname = docbParseAttribute(ctxt, &attvalue);
3805 if (attname != NULL) {
3806
3807 /*
3808 * Well formedness requires at most one declaration of an attribute
3809 */
3810 for (i = 0; i < nbatts;i += 2) {
3811 if (xmlStrEqual(atts[i], attname)) {
3812 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3813 ctxt->sax->error(ctxt->userData,
3814 "Attribute %s redefined\n",
3815 attname);
3816 ctxt->wellFormed = 0;
3817 xmlFree(attname);
3818 if (attvalue != NULL)
3819 xmlFree(attvalue);
3820 goto failed;
3821 }
3822 }
3823
3824 /*
3825 * Add the pair to atts
3826 */
3827 if (atts == NULL) {
3828 maxatts = 10;
3829 atts = (const xmlChar **) xmlMalloc(maxatts * sizeof(xmlChar *));
3830 if (atts == NULL) {
3831 xmlGenericError(xmlGenericErrorContext,
3832 "malloc of %ld byte failed\n",
3833 maxatts * (long)sizeof(xmlChar *));
3834 if (name != NULL) xmlFree(name);
3835 return;
3836 }
3837 } else if (nbatts + 4 > maxatts) {
3838 maxatts *= 2;
Daniel Veillard50f34372001-08-03 12:06:36 +00003839 atts = (const xmlChar **) xmlRealloc((void *)atts, maxatts * sizeof(xmlChar *));
Daniel Veillardeae522a2001-04-23 13:41:34 +00003840 if (atts == NULL) {
3841 xmlGenericError(xmlGenericErrorContext,
3842 "realloc of %ld byte failed\n",
3843 maxatts * (long)sizeof(xmlChar *));
3844 if (name != NULL) xmlFree(name);
3845 return;
3846 }
3847 }
3848 atts[nbatts++] = attname;
3849 atts[nbatts++] = attvalue;
3850 atts[nbatts] = NULL;
3851 atts[nbatts + 1] = NULL;
3852 }
3853
3854failed:
3855 SKIP_BLANKS;
3856 if (cons == ctxt->nbChars) {
3857 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3858 ctxt->sax->error(ctxt->userData,
3859 "docbParseStartTag: problem parsing attributes\n");
3860 ctxt->wellFormed = 0;
3861 break;
3862 }
3863 }
3864
3865 /*
3866 * Handle specific association to the META tag
3867 */
3868 if (meta)
3869 docbCheckMeta(ctxt, atts);
3870
3871 /*
3872 * SAX: Start of Element !
3873 */
3874 docbnamePush(ctxt, xmlStrdup(name));
3875#ifdef DEBUG
3876 xmlGenericError(xmlGenericErrorContext,"Start of element %s: pushed %s\n", name, ctxt->name);
3877#endif
3878 if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL))
3879 ctxt->sax->startElement(ctxt->userData, name, atts);
3880
3881 if (atts != NULL) {
3882 for (i = 0;i < nbatts;i++) {
3883 if (atts[i] != NULL)
3884 xmlFree((xmlChar *) atts[i]);
3885 }
3886 xmlFree((void *) atts);
3887 }
3888 if (name != NULL) xmlFree(name);
3889}
3890
3891/**
3892 * docbParseEndTag:
3893 * @ctxt: an SGML parser context
3894 *
3895 * parse an end of tag
3896 *
3897 * [42] ETag ::= '</' Name S? '>'
3898 *
3899 * With namespace
3900 *
3901 * [NS 9] ETag ::= '</' QName S? '>'
3902 */
3903
3904static void
3905docbParseEndTag(docbParserCtxtPtr ctxt) {
3906 xmlChar *name;
3907 xmlChar *oldname;
3908 int i;
3909
3910 if ((CUR != '<') || (NXT(1) != '/')) {
3911 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3912 ctxt->sax->error(ctxt->userData, "docbParseEndTag: '</' not found\n");
3913 ctxt->wellFormed = 0;
3914 return;
3915 }
3916 SKIP(2);
3917
3918 name = docbParseSGMLName(ctxt);
3919 if (name == NULL) {
3920 if (CUR == '>') {
3921 NEXT;
3922 oldname = docbnamePop(ctxt);
3923 if (oldname != NULL) {
3924 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
3925 ctxt->sax->endElement(ctxt->userData, name);
3926#ifdef DEBUG
3927 xmlGenericError(xmlGenericErrorContext,"End of tag </>: popping out %s\n", oldname);
3928#endif
3929 xmlFree(oldname);
3930#ifdef DEBUG
3931 } else {
3932 xmlGenericError(xmlGenericErrorContext,"End of tag </>: stack empty !!!\n");
3933#endif
3934 }
3935 return;
3936 } else
3937 return;
3938 }
3939
3940 /*
3941 * We should definitely be at the ending "S? '>'" part
3942 */
3943 SKIP_BLANKS;
3944 if ((!IS_CHAR(CUR)) || (CUR != '>')) {
3945 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3946 ctxt->sax->error(ctxt->userData, "End tag : expected '>'\n");
3947 ctxt->wellFormed = 0;
3948 } else
3949 NEXT;
3950
3951 /*
3952 * If the name read is not one of the element in the parsing stack
3953 * then return, it's just an error.
3954 */
3955 for (i = (ctxt->nameNr - 1);i >= 0;i--) {
3956 if (xmlStrEqual(name, ctxt->nameTab[i])) break;
3957 }
3958 if (i < 0) {
3959 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3960 ctxt->sax->error(ctxt->userData,
3961 "Unexpected end tag : %s\n", name);
3962 xmlFree(name);
3963 ctxt->wellFormed = 0;
3964 return;
3965 }
3966
3967
3968 /*
3969 * Check for auto-closure of SGML elements.
3970 */
3971
3972 docbAutoCloseOnClose(ctxt, name);
3973
3974 /*
3975 * Well formedness constraints, opening and closing must match.
3976 * With the exception that the autoclose may have popped stuff out
3977 * of the stack.
3978 */
3979 if (((name[0] != '/') || (name[1] != 0)) &&
3980 (!xmlStrEqual(name, ctxt->name))) {
3981#ifdef DEBUG
3982 xmlGenericError(xmlGenericErrorContext,"End of tag %s: expecting %s\n", name, ctxt->name);
3983#endif
3984 if ((ctxt->name != NULL) &&
3985 (!xmlStrEqual(ctxt->name, name))) {
3986 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3987 ctxt->sax->error(ctxt->userData,
3988 "Opening and ending tag mismatch: %s and %s\n",
3989 name, ctxt->name);
3990 ctxt->wellFormed = 0;
3991 }
3992 }
3993
3994 /*
3995 * SAX: End of Tag
3996 */
3997 oldname = ctxt->name;
3998 if (((name[0] == '/') && (name[1] == 0)) ||
3999 ((oldname != NULL) && (xmlStrEqual(oldname, name)))) {
4000 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
4001 ctxt->sax->endElement(ctxt->userData, name);
4002 oldname = docbnamePop(ctxt);
4003 if (oldname != NULL) {
4004#ifdef DEBUG
4005 xmlGenericError(xmlGenericErrorContext,"End of tag %s: popping out %s\n", name, oldname);
4006#endif
4007 xmlFree(oldname);
4008#ifdef DEBUG
4009 } else {
4010 xmlGenericError(xmlGenericErrorContext,"End of tag %s: stack empty !!!\n", name);
4011#endif
4012 }
4013 }
4014
4015 if (name != NULL)
4016 xmlFree(name);
4017
4018 return;
4019}
4020
4021
4022/**
4023 * docbParseReference:
4024 * @ctxt: an SGML parser context
4025 *
4026 * parse and handle entity references in content,
4027 * this will end-up in a call to character() since this is either a
4028 * CharRef, or a predefined entity.
4029 */
4030static void
4031docbParseReference(docbParserCtxtPtr ctxt) {
4032 docbEntityDescPtr ent;
Daniel Veillard61b33d52001-04-24 13:55:12 +00004033 xmlEntityPtr xent;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004034 xmlChar out[6];
4035 xmlChar *name;
4036 if (CUR != '&') return;
4037
4038 if (NXT(1) == '#') {
4039 unsigned int c;
4040 int bits, i = 0;
4041
4042 c = docbParseCharRef(ctxt);
4043 if (c < 0x80) { out[i++]= c; bits= -6; }
4044 else if (c < 0x800) { out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }
4045 else if (c < 0x10000) { out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }
4046 else { out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }
4047
4048 for ( ; bits >= 0; bits-= 6) {
4049 out[i++]= ((c >> bits) & 0x3F) | 0x80;
4050 }
4051 out[i] = 0;
4052
4053 docbCheckParagraph(ctxt);
4054 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
4055 ctxt->sax->characters(ctxt->userData, out, i);
4056 } else {
Daniel Veillard61b33d52001-04-24 13:55:12 +00004057 /*
4058 * Lookup the entity in the table.
4059 */
4060 xent = docbParseEntityRef(ctxt, &name);
4061 if (xent != NULL) {
Daniel Veillard1034da22001-04-25 19:06:28 +00004062 if (((ctxt->replaceEntities) || (ctxt->loadsubset)) &&
4063 ((xent->children == NULL) &&
4064 (xent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))) {
Daniel Veillard61b33d52001-04-24 13:55:12 +00004065 /*
4066 * we really need to fetch and parse the external entity
4067 */
4068 int parse;
4069 xmlNodePtr children = NULL;
4070
4071 parse = docbParseCtxtExternalEntity(ctxt,
4072 xent->SystemID, xent->ExternalID, &children);
4073 xmlAddChildList((xmlNodePtr) xent, children);
Daniel Veillard1034da22001-04-25 19:06:28 +00004074 }
4075 if (ctxt->replaceEntities) {
Daniel Veillard61b33d52001-04-24 13:55:12 +00004076 if ((ctxt->node != NULL) && (xent->children != NULL)) {
4077 /*
4078 * Seems we are generating the DOM content, do
4079 * a simple tree copy
4080 */
4081 xmlNodePtr new;
4082 new = xmlCopyNodeList(xent->children);
4083
4084 xmlAddChildList(ctxt->node, new);
4085 /*
4086 * This is to avoid a nasty side effect, see
4087 * characters() in SAX.c
4088 */
4089 ctxt->nodemem = 0;
4090 ctxt->nodelen = 0;
4091 }
Daniel Veillard1034da22001-04-25 19:06:28 +00004092 } else {
4093 if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) &&
4094 (ctxt->replaceEntities == 0) && (!ctxt->disableSAX)) {
4095 /*
4096 * Create a node.
4097 */
4098 ctxt->sax->reference(ctxt->userData, xent->name);
4099 }
Daniel Veillard61b33d52001-04-24 13:55:12 +00004100 }
4101 } else if (name != NULL) {
4102 ent = docbEntityLookup(name);
4103 if ((ent == NULL) || (ent->value <= 0)) {
4104 docbCheckParagraph(ctxt);
4105 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) {
4106 ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1);
4107 ctxt->sax->characters(ctxt->userData, name, xmlStrlen(name));
4108 /* ctxt->sax->characters(ctxt->userData, BAD_CAST ";", 1); */
4109 }
4110 } else {
4111 unsigned int c;
4112 int bits, i = 0;
4113
4114 c = ent->value;
4115 if (c < 0x80)
4116 { out[i++]= c; bits= -6; }
4117 else if (c < 0x800)
4118 { out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }
4119 else if (c < 0x10000)
4120 { out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }
4121 else
4122 { out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }
4123
4124 for ( ; bits >= 0; bits-= 6) {
4125 out[i++]= ((c >> bits) & 0x3F) | 0x80;
4126 }
4127 out[i] = 0;
4128
4129 docbCheckParagraph(ctxt);
4130 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
4131 ctxt->sax->characters(ctxt->userData, out, i);
4132 }
4133 } else {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004134 docbCheckParagraph(ctxt);
4135 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
4136 ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1);
4137 return;
4138 }
Daniel Veillard61b33d52001-04-24 13:55:12 +00004139 if (name != NULL)
4140 xmlFree(name);
Daniel Veillardeae522a2001-04-23 13:41:34 +00004141 }
4142}
4143
4144/**
4145 * docbParseContent:
4146 * @ctxt: an SGML parser context
4147 * @name: the node name
4148 *
4149 * Parse a content: comment, sub-element, reference or text.
4150 *
4151 */
Daniel Veillardeae522a2001-04-23 13:41:34 +00004152static void
Daniel Veillard84666b32001-06-11 17:31:08 +00004153docbParseContent(docbParserCtxtPtr ctxt)
4154{
Daniel Veillardeae522a2001-04-23 13:41:34 +00004155 xmlChar *currentNode;
4156 int depth;
4157
4158 currentNode = xmlStrdup(ctxt->name);
4159 depth = ctxt->nameNr;
4160 while (1) {
Daniel Veillard84666b32001-06-11 17:31:08 +00004161 long cons = ctxt->nbChars;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004162
4163 GROW;
Daniel Veillard84666b32001-06-11 17:31:08 +00004164 /*
4165 * Our tag or one of it's parent or children is ending.
4166 */
Daniel Veillardeae522a2001-04-23 13:41:34 +00004167 if ((CUR == '<') && (NXT(1) == '/')) {
Daniel Veillard84666b32001-06-11 17:31:08 +00004168 docbParseEndTag(ctxt);
4169 if (currentNode != NULL)
4170 xmlFree(currentNode);
4171 return;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004172 }
4173
Daniel Veillard84666b32001-06-11 17:31:08 +00004174 /*
4175 * Has this node been popped out during parsing of
4176 * the next element
4177 */
Daniel Veillardeae522a2001-04-23 13:41:34 +00004178 if ((!xmlStrEqual(currentNode, ctxt->name)) &&
Daniel Veillard84666b32001-06-11 17:31:08 +00004179 (depth >= ctxt->nameNr)) {
4180 if (currentNode != NULL)
4181 xmlFree(currentNode);
4182 return;
4183 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004184
Daniel Veillard84666b32001-06-11 17:31:08 +00004185 /*
4186 * Sometimes DOCTYPE arrives in the middle of the document
4187 */
4188 if ((CUR == '<') && (NXT(1) == '!') &&
4189 (UPP(2) == 'D') && (UPP(3) == 'O') &&
4190 (UPP(4) == 'C') && (UPP(5) == 'T') &&
4191 (UPP(6) == 'Y') && (UPP(7) == 'P') && (UPP(8) == 'E')) {
4192 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4193 ctxt->sax->error(ctxt->userData,
4194 "Misplaced DOCTYPE declaration\n");
4195 ctxt->wellFormed = 0;
4196 docbParseDocTypeDecl(ctxt);
4197 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004198
Daniel Veillard84666b32001-06-11 17:31:08 +00004199 /*
4200 * First case : a comment
4201 */
4202 if ((CUR == '<') && (NXT(1) == '!') &&
4203 (NXT(2) == '-') && (NXT(3) == '-')) {
4204 docbParseComment(ctxt);
4205 }
4206
4207 /*
4208 * Second case : a PI
4209 */
4210 else if ((RAW == '<') && (NXT(1) == '?')) {
4211 docbParsePI(ctxt);
4212 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004213
Daniel Veillard84666b32001-06-11 17:31:08 +00004214 /*
4215 * Third case : a sub-element.
4216 */
4217 else if (CUR == '<') {
4218 docbParseElement(ctxt);
4219 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004220
Daniel Veillard84666b32001-06-11 17:31:08 +00004221 /*
4222 * Fourth case : a reference. If if has not been resolved,
4223 * parsing returns it's Name, create the node
4224 */
4225 else if (CUR == '&') {
4226 docbParseReference(ctxt);
4227 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004228
Daniel Veillard84666b32001-06-11 17:31:08 +00004229 /*
4230 * Fifth : end of the resource
4231 */
4232 else if (CUR == 0) {
4233 docbAutoClose(ctxt, NULL);
4234 if (ctxt->nameNr == 0)
4235 break;
4236 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004237
Daniel Veillard84666b32001-06-11 17:31:08 +00004238 /*
4239 * Last case, text. Note that References are handled directly.
4240 */
4241 else {
4242 docbParseCharData(ctxt);
4243 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004244
Daniel Veillard84666b32001-06-11 17:31:08 +00004245 if (cons == ctxt->nbChars) {
4246 if (ctxt->node != NULL) {
4247 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4248 ctxt->sax->error(ctxt->userData,
4249 "detected an error in element content\n");
4250 ctxt->wellFormed = 0;
4251 }
4252 break;
4253 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004254
4255 GROW;
4256 }
Daniel Veillard84666b32001-06-11 17:31:08 +00004257 if (currentNode != NULL)
4258 xmlFree(currentNode);
Daniel Veillardeae522a2001-04-23 13:41:34 +00004259}
4260
4261/**
4262 * docbParseElement:
4263 * @ctxt: an SGML parser context
4264 *
4265 * parse an SGML element, this is highly recursive
4266 *
4267 * [39] element ::= EmptyElemTag | STag content ETag
4268 *
4269 * [41] Attribute ::= Name Eq AttValue
4270 */
4271
4272static void
4273docbParseElement(docbParserCtxtPtr ctxt) {
4274 xmlChar *name;
4275 xmlChar *currentNode = NULL;
4276 docbElemDescPtr info;
4277 docbParserNodeInfo node_info;
4278 xmlChar *oldname;
4279 int depth = ctxt->nameNr;
4280
4281 /* Capture start position */
4282 if (ctxt->record_info) {
4283 node_info.begin_pos = ctxt->input->consumed +
4284 (CUR_PTR - ctxt->input->base);
4285 node_info.begin_line = ctxt->input->line;
4286 }
4287
4288 oldname = xmlStrdup(ctxt->name);
4289 docbParseStartTag(ctxt);
4290 name = ctxt->name;
4291#ifdef DEBUG
4292 if (oldname == NULL)
4293 xmlGenericError(xmlGenericErrorContext,
4294 "Start of element %s\n", name);
4295 else if (name == NULL)
4296 xmlGenericError(xmlGenericErrorContext,
4297 "Start of element failed, was %s\n", oldname);
4298 else
4299 xmlGenericError(xmlGenericErrorContext,
4300 "Start of element %s, was %s\n", name, oldname);
4301#endif
4302 if (((depth == ctxt->nameNr) && (xmlStrEqual(oldname, ctxt->name))) ||
4303 (name == NULL)) {
4304 if (CUR == '>')
4305 NEXT;
4306 if (oldname != NULL)
4307 xmlFree(oldname);
4308 return;
4309 }
4310 if (oldname != NULL)
4311 xmlFree(oldname);
4312
4313 /*
4314 * Lookup the info for that element.
4315 */
4316 info = docbTagLookup(name);
4317 if (info == NULL) {
4318 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4319 ctxt->sax->error(ctxt->userData, "Tag %s unknown\n",
4320 name);
4321 ctxt->wellFormed = 0;
4322 } else if (info->depr) {
4323/***************************
4324 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
4325 ctxt->sax->warning(ctxt->userData, "Tag %s is deprecated\n",
4326 name);
4327 ***************************/
4328 }
4329
4330 /*
4331 * Check for an Empty Element labelled the XML/SGML way
4332 */
4333 if ((CUR == '/') && (NXT(1) == '>')) {
4334 SKIP(2);
4335 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
4336 ctxt->sax->endElement(ctxt->userData, name);
4337 oldname = docbnamePop(ctxt);
4338#ifdef DEBUG
4339 xmlGenericError(xmlGenericErrorContext,"End of tag the XML way: popping out %s\n", oldname);
4340#endif
4341 if (oldname != NULL)
4342 xmlFree(oldname);
4343 return;
4344 }
4345
4346 if (CUR == '>') {
4347 NEXT;
4348 } else {
4349 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4350 ctxt->sax->error(ctxt->userData,
4351 "Couldn't find end of Start Tag %s\n",
4352 name);
4353 ctxt->wellFormed = 0;
4354
4355 /*
4356 * end of parsing of this node.
4357 */
4358 if (xmlStrEqual(name, ctxt->name)) {
4359 nodePop(ctxt);
4360 oldname = docbnamePop(ctxt);
4361#ifdef DEBUG
4362 xmlGenericError(xmlGenericErrorContext,"End of start tag problem: popping out %s\n", oldname);
4363#endif
4364 if (oldname != NULL)
4365 xmlFree(oldname);
4366 }
4367
4368 /*
4369 * Capture end position and add node
4370 */
4371 if ( currentNode != NULL && ctxt->record_info ) {
4372 node_info.end_pos = ctxt->input->consumed +
4373 (CUR_PTR - ctxt->input->base);
4374 node_info.end_line = ctxt->input->line;
4375 node_info.node = ctxt->node;
4376 xmlParserAddNodeInfo(ctxt, &node_info);
4377 }
4378 return;
4379 }
4380
4381 /*
4382 * Check for an Empty Element from DTD definition
4383 */
4384 if ((info != NULL) && (info->empty)) {
4385 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
4386 ctxt->sax->endElement(ctxt->userData, name);
4387 oldname = docbnamePop(ctxt);
4388#ifdef DEBUG
4389 xmlGenericError(xmlGenericErrorContext,"End of empty tag %s : popping out %s\n", name, oldname);
4390#endif
4391 if (oldname != NULL)
4392 xmlFree(oldname);
4393 return;
4394 }
4395
4396 /*
4397 * Parse the content of the element:
4398 */
4399 currentNode = xmlStrdup(ctxt->name);
4400 depth = ctxt->nameNr;
4401 while (IS_CHAR(CUR)) {
4402 docbParseContent(ctxt);
4403 if (ctxt->nameNr < depth) break;
4404 }
4405
4406 if (!IS_CHAR(CUR)) {
4407 /************
4408 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4409 ctxt->sax->error(ctxt->userData,
4410 "Premature end of data in tag %s\n", currentNode);
4411 ctxt->wellFormed = 0;
4412 *************/
4413
4414 /*
4415 * end of parsing of this node.
4416 */
4417 nodePop(ctxt);
4418 oldname = docbnamePop(ctxt);
4419#ifdef DEBUG
4420 xmlGenericError(xmlGenericErrorContext,"Premature end of tag %s : popping out %s\n", name, oldname);
4421#endif
4422 if (oldname != NULL)
4423 xmlFree(oldname);
4424 if (currentNode != NULL)
4425 xmlFree(currentNode);
4426 return;
4427 }
4428
4429 /*
4430 * Capture end position and add node
4431 */
4432 if ( currentNode != NULL && ctxt->record_info ) {
4433 node_info.end_pos = ctxt->input->consumed +
4434 (CUR_PTR - ctxt->input->base);
4435 node_info.end_line = ctxt->input->line;
4436 node_info.node = ctxt->node;
4437 xmlParserAddNodeInfo(ctxt, &node_info);
4438 }
4439 if (currentNode != NULL)
4440 xmlFree(currentNode);
4441}
4442
4443/**
4444 * docbParseEntityDecl:
4445 * @ctxt: an SGML parser context
4446 *
4447 * parse <!ENTITY declarations
4448 *
4449 */
4450
4451static void
4452docbParseEntityDecl(xmlParserCtxtPtr ctxt) {
4453 xmlChar *name = NULL;
4454 xmlChar *value = NULL;
4455 xmlChar *URI = NULL, *literal = NULL;
4456 xmlChar *ndata = NULL;
4457 int isParameter = 0;
4458 xmlChar *orig = NULL;
4459
4460 GROW;
4461 if ((RAW == '<') && (NXT(1) == '!') &&
Daniel Veillard61b33d52001-04-24 13:55:12 +00004462 (UPP(2) == 'E') && (UPP(3) == 'N') &&
4463 (UPP(4) == 'T') && (UPP(5) == 'I') &&
4464 (UPP(6) == 'T') && (UPP(7) == 'Y')) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004465 xmlParserInputPtr input = ctxt->input;
4466 ctxt->instate = XML_PARSER_ENTITY_DECL;
4467 SHRINK;
4468 SKIP(8);
4469 if (!IS_BLANK(CUR)) {
4470 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4471 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4472 ctxt->sax->error(ctxt->userData,
4473 "Space required after '<!ENTITY'\n");
4474 ctxt->wellFormed = 0;
4475 ctxt->disableSAX = 1;
4476 }
4477 SKIP_BLANKS;
4478
4479 if (RAW == '%') {
4480 NEXT;
4481 if (!IS_BLANK(CUR)) {
4482 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4483 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4484 ctxt->sax->error(ctxt->userData,
4485 "Space required after '%'\n");
4486 ctxt->wellFormed = 0;
4487 ctxt->disableSAX = 1;
4488 }
4489 SKIP_BLANKS;
4490 isParameter = 1;
4491 }
4492
4493 name = xmlParseName(ctxt);
4494 if (name == NULL) {
4495 ctxt->errNo = XML_ERR_NAME_REQUIRED;
4496 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4497 ctxt->sax->error(ctxt->userData, "sgmlarseEntityDecl: no name\n");
4498 ctxt->wellFormed = 0;
4499 ctxt->disableSAX = 1;
4500 return;
4501 }
4502 if (!IS_BLANK(CUR)) {
4503 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4504 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4505 ctxt->sax->error(ctxt->userData,
4506 "Space required after the entity name\n");
4507 ctxt->wellFormed = 0;
4508 ctxt->disableSAX = 1;
4509 }
4510 SKIP_BLANKS;
4511
4512 /*
4513 * handle the various case of definitions...
4514 */
4515 if (isParameter) {
4516 if ((RAW == '"') || (RAW == '\'')) {
4517 value = xmlParseEntityValue(ctxt, &orig);
4518 if (value) {
4519 if ((ctxt->sax != NULL) &&
4520 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4521 ctxt->sax->entityDecl(ctxt->userData, name,
4522 XML_INTERNAL_PARAMETER_ENTITY,
4523 NULL, NULL, value);
4524 }
4525 } else {
4526 URI = xmlParseExternalID(ctxt, &literal, 1);
4527 if ((URI == NULL) && (literal == NULL)) {
4528 ctxt->errNo = XML_ERR_VALUE_REQUIRED;
4529 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4530 ctxt->sax->error(ctxt->userData,
4531 "Entity value required\n");
4532 ctxt->wellFormed = 0;
4533 ctxt->disableSAX = 1;
4534 }
4535 if (URI) {
4536 xmlURIPtr uri;
4537
4538 uri = xmlParseURI((const char *) URI);
4539 if (uri == NULL) {
4540 ctxt->errNo = XML_ERR_INVALID_URI;
4541 if ((ctxt->sax != NULL) &&
4542 (!ctxt->disableSAX) &&
4543 (ctxt->sax->error != NULL))
4544 ctxt->sax->error(ctxt->userData,
4545 "Invalid URI: %s\n", URI);
4546 ctxt->wellFormed = 0;
4547 } else {
4548 if (uri->fragment != NULL) {
4549 ctxt->errNo = XML_ERR_URI_FRAGMENT;
4550 if ((ctxt->sax != NULL) &&
4551 (!ctxt->disableSAX) &&
4552 (ctxt->sax->error != NULL))
4553 ctxt->sax->error(ctxt->userData,
4554 "Fragment not allowed: %s\n", URI);
4555 ctxt->wellFormed = 0;
4556 } else {
4557 if ((ctxt->sax != NULL) &&
4558 (!ctxt->disableSAX) &&
4559 (ctxt->sax->entityDecl != NULL))
4560 ctxt->sax->entityDecl(ctxt->userData, name,
4561 XML_EXTERNAL_PARAMETER_ENTITY,
4562 literal, URI, NULL);
4563 }
4564 xmlFreeURI(uri);
4565 }
4566 }
4567 }
4568 } else {
4569 if ((RAW == '"') || (RAW == '\'')) {
4570 value = xmlParseEntityValue(ctxt, &orig);
4571 if ((ctxt->sax != NULL) &&
4572 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4573 ctxt->sax->entityDecl(ctxt->userData, name,
4574 XML_INTERNAL_GENERAL_ENTITY,
4575 NULL, NULL, value);
4576 } else {
4577 URI = xmlParseExternalID(ctxt, &literal, 1);
4578 if ((URI == NULL) && (literal == NULL)) {
4579 ctxt->errNo = XML_ERR_VALUE_REQUIRED;
4580 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4581 ctxt->sax->error(ctxt->userData,
4582 "Entity value required\n");
4583 ctxt->wellFormed = 0;
4584 ctxt->disableSAX = 1;
4585 }
4586 if (URI) {
4587 xmlURIPtr uri;
4588
4589 uri = xmlParseURI((const char *)URI);
4590 if (uri == NULL) {
4591 ctxt->errNo = XML_ERR_INVALID_URI;
4592 if ((ctxt->sax != NULL) &&
4593 (!ctxt->disableSAX) &&
4594 (ctxt->sax->error != NULL))
4595 ctxt->sax->error(ctxt->userData,
4596 "Invalid URI: %s\n", URI);
4597 ctxt->wellFormed = 0;
4598 } else {
4599 if (uri->fragment != NULL) {
4600 ctxt->errNo = XML_ERR_URI_FRAGMENT;
4601 if ((ctxt->sax != NULL) &&
4602 (!ctxt->disableSAX) &&
4603 (ctxt->sax->error != NULL))
4604 ctxt->sax->error(ctxt->userData,
4605 "Fragment not allowed: %s\n", URI);
4606 ctxt->wellFormed = 0;
4607 }
4608 xmlFreeURI(uri);
4609 }
4610 }
4611 if ((RAW != '>') && (!IS_BLANK(CUR))) {
4612 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4613 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4614 ctxt->sax->error(ctxt->userData,
4615 "Space required before content model\n");
4616 ctxt->wellFormed = 0;
4617 ctxt->disableSAX = 1;
4618 }
4619 SKIP_BLANKS;
4620
4621 /*
4622 * SGML specific: here we can get the content model
4623 */
4624 if (RAW != '>') {
4625 xmlChar *contmod;
4626
4627 contmod = xmlParseName(ctxt);
4628
4629 if (contmod == NULL) {
4630 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4631 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4632 ctxt->sax->error(ctxt->userData,
4633 "Could not parse entity content model\n");
4634 ctxt->wellFormed = 0;
4635 ctxt->disableSAX = 1;
4636 } else {
4637 if (xmlStrEqual(contmod, BAD_CAST"NDATA")) {
4638 if (!IS_BLANK(CUR)) {
4639 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4640 if ((ctxt->sax != NULL) &&
4641 (ctxt->sax->error != NULL))
4642 ctxt->sax->error(ctxt->userData,
4643 "Space required after 'NDATA'\n");
4644 ctxt->wellFormed = 0;
4645 ctxt->disableSAX = 1;
4646 }
4647 SKIP_BLANKS;
4648 ndata = xmlParseName(ctxt);
4649 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
4650 (ctxt->sax->unparsedEntityDecl != NULL)) {
4651 ctxt->sax->unparsedEntityDecl(ctxt->userData,
4652 name, literal, URI, ndata);
4653 }
4654 } else if (xmlStrEqual(contmod, BAD_CAST"SUBDOC")) {
4655 if ((ctxt->sax != NULL) &&
4656 (ctxt->sax->warning != NULL))
4657 ctxt->sax->warning(ctxt->userData,
4658 "SUBDOC entities are not supported\n");
4659 SKIP_BLANKS;
4660 ndata = xmlParseName(ctxt);
4661 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
4662 (ctxt->sax->unparsedEntityDecl != NULL)) {
4663 ctxt->sax->unparsedEntityDecl(ctxt->userData,
4664 name, literal, URI, ndata);
4665 }
4666 } else if (xmlStrEqual(contmod, BAD_CAST"CDATA")) {
4667 if ((ctxt->sax != NULL) &&
4668 (ctxt->sax->warning != NULL))
4669 ctxt->sax->warning(ctxt->userData,
4670 "CDATA entities are not supported\n");
4671 SKIP_BLANKS;
4672 ndata = xmlParseName(ctxt);
4673 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
4674 (ctxt->sax->unparsedEntityDecl != NULL)) {
4675 ctxt->sax->unparsedEntityDecl(ctxt->userData,
4676 name, literal, URI, ndata);
4677 }
4678 }
4679 xmlFree(contmod);
4680 }
4681 } else {
4682 if ((ctxt->sax != NULL) &&
4683 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4684 ctxt->sax->entityDecl(ctxt->userData, name,
4685 XML_EXTERNAL_GENERAL_PARSED_ENTITY,
4686 literal, URI, NULL);
4687 }
4688 }
4689 }
4690 SKIP_BLANKS;
4691 if (RAW != '>') {
4692 ctxt->errNo = XML_ERR_ENTITY_NOT_FINISHED;
4693 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4694 ctxt->sax->error(ctxt->userData,
4695 "docbParseEntityDecl: entity %s not terminated\n", name);
4696 ctxt->wellFormed = 0;
4697 ctxt->disableSAX = 1;
4698 } else {
4699 if (input != ctxt->input) {
4700 ctxt->errNo = XML_ERR_ENTITY_BOUNDARY;
4701 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4702 ctxt->sax->error(ctxt->userData,
4703"Entity declaration doesn't start and stop in the same entity\n");
4704 ctxt->wellFormed = 0;
4705 ctxt->disableSAX = 1;
4706 }
4707 NEXT;
4708 }
4709 if (orig != NULL) {
4710 /*
4711 * Ugly mechanism to save the raw entity value.
4712 */
4713 xmlEntityPtr cur = NULL;
4714
4715 if (isParameter) {
4716 if ((ctxt->sax != NULL) &&
4717 (ctxt->sax->getParameterEntity != NULL))
4718 cur = ctxt->sax->getParameterEntity(ctxt->userData, name);
4719 } else {
4720 if ((ctxt->sax != NULL) &&
4721 (ctxt->sax->getEntity != NULL))
4722 cur = ctxt->sax->getEntity(ctxt->userData, name);
4723 }
4724 if (cur != NULL) {
4725 if (cur->orig != NULL)
4726 xmlFree(orig);
4727 else
4728 cur->orig = orig;
4729 } else
4730 xmlFree(orig);
4731 }
4732 if (name != NULL) xmlFree(name);
4733 if (value != NULL) xmlFree(value);
4734 if (URI != NULL) xmlFree(URI);
4735 if (literal != NULL) xmlFree(literal);
4736 if (ndata != NULL) xmlFree(ndata);
4737 }
4738}
4739
4740/**
4741 * docbParseMarkupDecl:
4742 * @ctxt: an SGML parser context
4743 *
4744 * parse Markup declarations
4745 *
4746 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
4747 * NotationDecl | PI | Comment
4748 */
4749static void
4750docbParseMarkupDecl(xmlParserCtxtPtr ctxt) {
4751 GROW;
4752 xmlParseElementDecl(ctxt);
4753 xmlParseAttributeListDecl(ctxt);
4754 docbParseEntityDecl(ctxt);
4755 xmlParseNotationDecl(ctxt);
Daniel Veillarde95e2392001-06-06 10:46:28 +00004756 docbParsePI(ctxt);
Daniel Veillardeae522a2001-04-23 13:41:34 +00004757 xmlParseComment(ctxt);
4758 /*
4759 * This is only for internal subset. On external entities,
4760 * the replacement is done before parsing stage
4761 */
4762 if ((ctxt->external == 0) && (ctxt->inputNr == 1))
4763 xmlParsePEReference(ctxt);
4764 ctxt->instate = XML_PARSER_DTD;
4765}
4766
4767/**
4768 * docbParseInternalsubset:
4769 * @ctxt: an SGML parser context
4770 *
4771 * parse the internal subset declaration
4772 *
4773 * [28 end] ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
4774 */
4775
4776static void
4777docbParseInternalSubset(xmlParserCtxtPtr ctxt) {
4778 /*
4779 * Is there any DTD definition ?
4780 */
4781 if (RAW == '[') {
4782 ctxt->instate = XML_PARSER_DTD;
4783 NEXT;
4784 /*
4785 * Parse the succession of Markup declarations and
4786 * PEReferences.
4787 * Subsequence (markupdecl | PEReference | S)*
4788 */
4789 while (RAW != ']') {
4790 const xmlChar *check = CUR_PTR;
4791 int cons = ctxt->input->consumed;
4792
4793 SKIP_BLANKS;
4794 docbParseMarkupDecl(ctxt);
4795 xmlParsePEReference(ctxt);
4796
4797 /*
4798 * Pop-up of finished entities.
4799 */
4800 while ((RAW == 0) && (ctxt->inputNr > 1))
4801 xmlPopInput(ctxt);
4802
4803 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
4804 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
4805 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4806 ctxt->sax->error(ctxt->userData,
4807 "docbParseInternalSubset: error detected in Markup declaration\n");
4808 ctxt->wellFormed = 0;
4809 ctxt->disableSAX = 1;
4810 break;
4811 }
4812 }
4813 if (RAW == ']') {
4814 NEXT;
4815 SKIP_BLANKS;
4816 }
4817 }
4818
4819 /*
4820 * We should be at the end of the DOCTYPE declaration.
4821 */
4822 if (RAW != '>') {
4823 ctxt->errNo = XML_ERR_DOCTYPE_NOT_FINISHED;
4824 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
Daniel Veillardf6ed8bc2001-10-02 09:22:47 +00004825 ctxt->sax->error(ctxt->userData, "DOCTYPE improperly terminated\n");
Daniel Veillardeae522a2001-04-23 13:41:34 +00004826 ctxt->wellFormed = 0;
4827 ctxt->disableSAX = 1;
4828 }
4829 NEXT;
4830}
4831
4832/**
4833 * docbParseMisc:
4834 * @ctxt: an XML parser context
4835 *
4836 * parse an XML Misc* optionnal field.
4837 *
4838 * [27] Misc ::= Comment | PI | S
4839 */
4840
4841static void
4842docbParseMisc(xmlParserCtxtPtr ctxt) {
4843 while (((RAW == '<') && (NXT(1) == '?')) ||
4844 ((RAW == '<') && (NXT(1) == '!') &&
4845 (NXT(2) == '-') && (NXT(3) == '-')) ||
4846 IS_BLANK(CUR)) {
4847 if ((RAW == '<') && (NXT(1) == '?')) {
Daniel Veillard84666b32001-06-11 17:31:08 +00004848 docbParsePI(ctxt);
4849 } else if (IS_BLANK(CUR)) {
4850 NEXT;
4851 } else
4852 xmlParseComment(ctxt);
Daniel Veillardeae522a2001-04-23 13:41:34 +00004853 }
4854}
4855
4856/**
4857 * docbParseDocument :
4858 * @ctxt: an SGML parser context
4859 *
4860 * parse an SGML document (and build a tree if using the standard SAX
4861 * interface).
4862 *
4863 * Returns 0, -1 in case of error. the parser context is augmented
4864 * as a result of the parsing.
4865 */
4866
4867int
4868docbParseDocument(docbParserCtxtPtr ctxt) {
4869 xmlChar start[4];
4870 xmlCharEncoding enc;
4871 xmlDtdPtr dtd;
4872
4873 docbDefaultSAXHandlerInit();
4874 ctxt->html = 2;
4875
4876 GROW;
4877 /*
4878 * SAX: beginning of the document processing.
4879 */
4880 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
4881 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
4882
4883 /*
4884 * Get the 4 first bytes and decode the charset
4885 * if enc != XML_CHAR_ENCODING_NONE
4886 * plug some encoding conversion routines.
4887 */
4888 start[0] = RAW;
4889 start[1] = NXT(1);
4890 start[2] = NXT(2);
4891 start[3] = NXT(3);
4892 enc = xmlDetectCharEncoding(start, 4);
4893 if (enc != XML_CHAR_ENCODING_NONE) {
4894 xmlSwitchEncoding(ctxt, enc);
4895 }
4896
4897 /*
4898 * Wipe out everything which is before the first '<'
4899 */
4900 SKIP_BLANKS;
4901 if (CUR == 0) {
4902 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4903 ctxt->sax->error(ctxt->userData, "Document is empty\n");
4904 ctxt->wellFormed = 0;
4905 }
4906
4907 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
4908 ctxt->sax->startDocument(ctxt->userData);
4909
4910
4911 /*
4912 * The Misc part of the Prolog
4913 */
4914 GROW;
4915 docbParseMisc(ctxt);
4916
4917 /*
4918 * Then possibly doc type declaration(s) and more Misc
4919 * (doctypedecl Misc*)?
4920 */
4921 GROW;
4922 if ((RAW == '<') && (NXT(1) == '!') &&
Daniel Veillard61b33d52001-04-24 13:55:12 +00004923 (UPP(2) == 'D') && (UPP(3) == 'O') &&
4924 (UPP(4) == 'C') && (UPP(5) == 'T') &&
4925 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
4926 (UPP(8) == 'E')) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004927
4928 ctxt->inSubset = 1;
4929 docbParseDocTypeDecl(ctxt);
4930 if (RAW == '[') {
4931 ctxt->instate = XML_PARSER_DTD;
4932 docbParseInternalSubset(ctxt);
4933 }
4934
4935 /*
4936 * Create and update the external subset.
4937 */
4938 ctxt->inSubset = 2;
4939 if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) &&
4940 (!ctxt->disableSAX))
4941 ctxt->sax->internalSubset(ctxt->userData, ctxt->intSubName,
4942 ctxt->extSubSystem, ctxt->extSubURI);
4943 ctxt->inSubset = 0;
4944
4945
4946 ctxt->instate = XML_PARSER_PROLOG;
4947 docbParseMisc(ctxt);
4948 }
4949
4950 /*
4951 * Time to start parsing the tree itself
4952 */
4953 docbParseContent(ctxt);
4954
4955 /*
4956 * autoclose
4957 */
4958 if (CUR == 0)
4959 docbAutoClose(ctxt, NULL);
4960
4961
4962 /*
4963 * SAX: end of the document processing.
4964 */
4965 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
4966 ctxt->sax->endDocument(ctxt->userData);
4967
4968 if (ctxt->myDoc != NULL) {
4969 dtd = ctxt->myDoc->intSubset;
Daniel Veillarde95e2392001-06-06 10:46:28 +00004970 ctxt->myDoc->standalone = -1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004971 if (dtd == NULL)
4972 ctxt->myDoc->intSubset =
4973 xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "SGML",
4974 BAD_CAST "-//W3C//DTD SGML 4.0 Transitional//EN",
4975 BAD_CAST "http://www.w3.org/TR/REC-docbook/loose.dtd");
4976 }
4977 if (! ctxt->wellFormed) return(-1);
4978 return(0);
4979}
4980
4981
4982/************************************************************************
4983 * *
4984 * Parser contexts handling *
4985 * *
4986 ************************************************************************/
4987
4988/**
Daniel Veillard1034da22001-04-25 19:06:28 +00004989 * docbInitParserCtxt:
Daniel Veillardeae522a2001-04-23 13:41:34 +00004990 * @ctxt: an SGML parser context
4991 *
4992 * Initialize a parser context
4993 */
4994
4995static void
4996docbInitParserCtxt(docbParserCtxtPtr ctxt)
4997{
4998 docbSAXHandler *sax;
4999
5000 if (ctxt == NULL) return;
5001 memset(ctxt, 0, sizeof(docbParserCtxt));
5002
5003 sax = (docbSAXHandler *) xmlMalloc(sizeof(docbSAXHandler));
5004 if (sax == NULL) {
5005 xmlGenericError(xmlGenericErrorContext,
5006 "docbInitParserCtxt: out of memory\n");
5007 }
5008 memset(sax, 0, sizeof(docbSAXHandler));
5009
5010 /* Allocate the Input stack */
5011 ctxt->inputTab = (docbParserInputPtr *)
5012 xmlMalloc(5 * sizeof(docbParserInputPtr));
5013 if (ctxt->inputTab == NULL) {
5014 xmlGenericError(xmlGenericErrorContext,
5015 "docbInitParserCtxt: out of memory\n");
5016 }
5017 ctxt->inputNr = 0;
5018 ctxt->inputMax = 5;
5019 ctxt->input = NULL;
5020 ctxt->version = NULL;
5021 ctxt->encoding = NULL;
5022 ctxt->standalone = -1;
5023 ctxt->instate = XML_PARSER_START;
5024
5025 /* Allocate the Node stack */
5026 ctxt->nodeTab = (docbNodePtr *) xmlMalloc(10 * sizeof(docbNodePtr));
5027 ctxt->nodeNr = 0;
5028 ctxt->nodeMax = 10;
5029 ctxt->node = NULL;
5030
5031 /* Allocate the Name stack */
5032 ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
5033 ctxt->nameNr = 0;
5034 ctxt->nameMax = 10;
5035 ctxt->name = NULL;
5036
5037 if (sax == NULL) ctxt->sax = &docbDefaultSAXHandler;
5038 else {
5039 ctxt->sax = sax;
5040 memcpy(sax, &docbDefaultSAXHandler, sizeof(docbSAXHandler));
5041 }
5042 ctxt->userData = ctxt;
5043 ctxt->myDoc = NULL;
5044 ctxt->wellFormed = 1;
Daniel Veillard635ef722001-10-29 11:48:19 +00005045 ctxt->linenumbers = xmlLineNumbersDefaultValue;
Daniel Veillard61b33d52001-04-24 13:55:12 +00005046 ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue;
Daniel Veillardeae522a2001-04-23 13:41:34 +00005047 ctxt->html = 2;
5048 ctxt->record_info = 0;
5049 ctxt->validate = 0;
5050 ctxt->nbChars = 0;
5051 ctxt->checkIndex = 0;
5052 xmlInitNodeInfoSeq(&ctxt->node_seq);
5053}
5054
5055/**
5056 * docbFreeParserCtxt:
5057 * @ctxt: an SGML parser context
5058 *
5059 * Free all the memory used by a parser context. However the parsed
5060 * document in ctxt->myDoc is not freed.
5061 */
5062
5063void
5064docbFreeParserCtxt(docbParserCtxtPtr ctxt)
5065{
5066 xmlFreeParserCtxt(ctxt);
5067}
5068
5069/**
5070 * docbCreateDocParserCtxt :
5071 * @cur: a pointer to an array of xmlChar
Daniel Veillard1034da22001-04-25 19:06:28 +00005072 * @encoding: the SGML document encoding, or NULL
Daniel Veillardeae522a2001-04-23 13:41:34 +00005073 *
5074 * Create a parser context for an SGML document.
5075 *
5076 * Returns the new parser context or NULL
5077 */
5078static docbParserCtxtPtr
Daniel Veillard1034da22001-04-25 19:06:28 +00005079docbCreateDocParserCtxt(xmlChar *cur, const char *encoding ATTRIBUTE_UNUSED) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00005080 docbParserCtxtPtr ctxt;
5081 docbParserInputPtr input;
5082 /* sgmlCharEncoding enc; */
5083
5084 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
5085 if (ctxt == NULL) {
5086 perror("malloc");
5087 return(NULL);
5088 }
5089 docbInitParserCtxt(ctxt);
5090 input = (docbParserInputPtr) xmlMalloc(sizeof(docbParserInput));
5091 if (input == NULL) {
5092 perror("malloc");
5093 xmlFree(ctxt);
5094 return(NULL);
5095 }
5096 memset(input, 0, sizeof(docbParserInput));
5097
5098 input->line = 1;
5099 input->col = 1;
5100 input->base = cur;
5101 input->cur = cur;
5102
5103 inputPush(ctxt, input);
5104 return(ctxt);
5105}
5106
5107/************************************************************************
5108 * *
5109 * Progressive parsing interfaces *
5110 * *
5111 ************************************************************************/
5112
5113/**
5114 * docbParseLookupSequence:
5115 * @ctxt: an SGML parser context
5116 * @first: the first char to lookup
5117 * @next: the next char to lookup or zero
5118 * @third: the next char to lookup or zero
5119 *
5120 * Try to find if a sequence (first, next, third) or just (first next) or
5121 * (first) is available in the input stream.
5122 * This function has a side effect of (possibly) incrementing ctxt->checkIndex
5123 * to avoid rescanning sequences of bytes, it DOES change the state of the
5124 * parser, do not use liberally.
5125 * This is basically similar to xmlParseLookupSequence()
5126 *
5127 * Returns the index to the current parsing point if the full sequence
5128 * is available, -1 otherwise.
5129 */
5130static int
5131docbParseLookupSequence(docbParserCtxtPtr ctxt, xmlChar first,
5132 xmlChar next, xmlChar third) {
5133 int base, len;
5134 docbParserInputPtr in;
5135 const xmlChar *buf;
5136
5137 in = ctxt->input;
5138 if (in == NULL) return(-1);
5139 base = in->cur - in->base;
5140 if (base < 0) return(-1);
5141 if (ctxt->checkIndex > base)
5142 base = ctxt->checkIndex;
5143 if (in->buf == NULL) {
5144 buf = in->base;
5145 len = in->length;
5146 } else {
5147 buf = in->buf->buffer->content;
5148 len = in->buf->buffer->use;
5149 }
5150 /* take into account the sequence length */
5151 if (third) len -= 2;
5152 else if (next) len --;
5153 for (;base < len;base++) {
5154 if (buf[base] == first) {
5155 if (third != 0) {
5156 if ((buf[base + 1] != next) ||
5157 (buf[base + 2] != third)) continue;
5158 } else if (next != 0) {
5159 if (buf[base + 1] != next) continue;
5160 }
5161 ctxt->checkIndex = 0;
5162#ifdef DEBUG_PUSH
5163 if (next == 0)
5164 xmlGenericError(xmlGenericErrorContext,
5165 "HPP: lookup '%c' found at %d\n",
5166 first, base);
5167 else if (third == 0)
5168 xmlGenericError(xmlGenericErrorContext,
5169 "HPP: lookup '%c%c' found at %d\n",
5170 first, next, base);
5171 else
5172 xmlGenericError(xmlGenericErrorContext,
5173 "HPP: lookup '%c%c%c' found at %d\n",
5174 first, next, third, base);
5175#endif
5176 return(base - (in->cur - in->base));
5177 }
5178 }
5179 ctxt->checkIndex = base;
5180#ifdef DEBUG_PUSH
5181 if (next == 0)
5182 xmlGenericError(xmlGenericErrorContext,
5183 "HPP: lookup '%c' failed\n", first);
5184 else if (third == 0)
5185 xmlGenericError(xmlGenericErrorContext,
5186 "HPP: lookup '%c%c' failed\n", first, next);
5187 else
5188 xmlGenericError(xmlGenericErrorContext,
5189 "HPP: lookup '%c%c%c' failed\n", first, next, third);
5190#endif
5191 return(-1);
5192}
5193
5194/**
5195 * docbParseTryOrFinish:
5196 * @ctxt: an SGML parser context
5197 * @terminate: last chunk indicator
5198 *
5199 * Try to progress on parsing
5200 *
5201 * Returns zero if no parsing was possible
5202 */
5203static int
5204docbParseTryOrFinish(docbParserCtxtPtr ctxt, int terminate) {
5205 int ret = 0;
5206 docbParserInputPtr in;
5207 int avail = 0;
5208 xmlChar cur, next;
5209
5210#ifdef DEBUG_PUSH
5211 switch (ctxt->instate) {
5212 case XML_PARSER_EOF:
5213 xmlGenericError(xmlGenericErrorContext,
5214 "HPP: try EOF\n"); break;
5215 case XML_PARSER_START:
5216 xmlGenericError(xmlGenericErrorContext,
5217 "HPP: try START\n"); break;
5218 case XML_PARSER_MISC:
5219 xmlGenericError(xmlGenericErrorContext,
5220 "HPP: try MISC\n");break;
5221 case XML_PARSER_COMMENT:
5222 xmlGenericError(xmlGenericErrorContext,
5223 "HPP: try COMMENT\n");break;
5224 case XML_PARSER_PROLOG:
5225 xmlGenericError(xmlGenericErrorContext,
5226 "HPP: try PROLOG\n");break;
5227 case XML_PARSER_START_TAG:
5228 xmlGenericError(xmlGenericErrorContext,
5229 "HPP: try START_TAG\n");break;
5230 case XML_PARSER_CONTENT:
5231 xmlGenericError(xmlGenericErrorContext,
5232 "HPP: try CONTENT\n");break;
5233 case XML_PARSER_CDATA_SECTION:
5234 xmlGenericError(xmlGenericErrorContext,
5235 "HPP: try CDATA_SECTION\n");break;
5236 case XML_PARSER_END_TAG:
5237 xmlGenericError(xmlGenericErrorContext,
5238 "HPP: try END_TAG\n");break;
5239 case XML_PARSER_ENTITY_DECL:
5240 xmlGenericError(xmlGenericErrorContext,
5241 "HPP: try ENTITY_DECL\n");break;
5242 case XML_PARSER_ENTITY_VALUE:
5243 xmlGenericError(xmlGenericErrorContext,
5244 "HPP: try ENTITY_VALUE\n");break;
5245 case XML_PARSER_ATTRIBUTE_VALUE:
5246 xmlGenericError(xmlGenericErrorContext,
5247 "HPP: try ATTRIBUTE_VALUE\n");break;
5248 case XML_PARSER_DTD:
5249 xmlGenericError(xmlGenericErrorContext,
5250 "HPP: try DTD\n");break;
5251 case XML_PARSER_EPILOG:
5252 xmlGenericError(xmlGenericErrorContext,
5253 "HPP: try EPILOG\n");break;
5254 case XML_PARSER_PI:
5255 xmlGenericError(xmlGenericErrorContext,
5256 "HPP: try PI\n");break;
5257 }
5258#endif
5259
5260 while (1) {
5261
5262 in = ctxt->input;
5263 if (in == NULL) break;
5264 if (in->buf == NULL)
5265 avail = in->length - (in->cur - in->base);
5266 else
5267 avail = in->buf->buffer->use - (in->cur - in->base);
5268 if ((avail == 0) && (terminate)) {
5269 docbAutoClose(ctxt, NULL);
5270 if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
5271 /*
5272 * SAX: end of the document processing.
5273 */
5274 ctxt->instate = XML_PARSER_EOF;
5275 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5276 ctxt->sax->endDocument(ctxt->userData);
5277 }
5278 }
5279 if (avail < 1)
5280 goto done;
5281 switch (ctxt->instate) {
5282 case XML_PARSER_EOF:
5283 /*
5284 * Document parsing is done !
5285 */
5286 goto done;
5287 case XML_PARSER_START:
5288 /*
5289 * Very first chars read from the document flow.
5290 */
5291 cur = in->cur[0];
5292 if (IS_BLANK(cur)) {
5293 SKIP_BLANKS;
5294 if (in->buf == NULL)
5295 avail = in->length - (in->cur - in->base);
5296 else
5297 avail = in->buf->buffer->use - (in->cur - in->base);
5298 }
5299 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
5300 ctxt->sax->setDocumentLocator(ctxt->userData,
5301 &xmlDefaultSAXLocator);
5302 if ((ctxt->sax) && (ctxt->sax->startDocument) &&
5303 (!ctxt->disableSAX))
5304 ctxt->sax->startDocument(ctxt->userData);
5305
5306 cur = in->cur[0];
5307 next = in->cur[1];
5308 if ((cur == '<') && (next == '!') &&
5309 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5310 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5311 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5312 (UPP(8) == 'E')) {
5313 if ((!terminate) &&
5314 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5315 goto done;
5316#ifdef DEBUG_PUSH
5317 xmlGenericError(xmlGenericErrorContext,
5318 "HPP: Parsing internal subset\n");
5319#endif
5320 docbParseDocTypeDecl(ctxt);
5321 ctxt->instate = XML_PARSER_PROLOG;
5322#ifdef DEBUG_PUSH
5323 xmlGenericError(xmlGenericErrorContext,
5324 "HPP: entering PROLOG\n");
5325#endif
5326 } else {
5327 ctxt->instate = XML_PARSER_MISC;
5328 }
5329#ifdef DEBUG_PUSH
5330 xmlGenericError(xmlGenericErrorContext,
5331 "HPP: entering MISC\n");
5332#endif
5333 break;
5334 case XML_PARSER_MISC:
5335 SKIP_BLANKS;
5336 if (in->buf == NULL)
5337 avail = in->length - (in->cur - in->base);
5338 else
5339 avail = in->buf->buffer->use - (in->cur - in->base);
5340 if (avail < 2)
5341 goto done;
5342 cur = in->cur[0];
5343 next = in->cur[1];
5344 if ((cur == '<') && (next == '!') &&
5345 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5346 if ((!terminate) &&
5347 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5348 goto done;
5349#ifdef DEBUG_PUSH
5350 xmlGenericError(xmlGenericErrorContext,
5351 "HPP: Parsing Comment\n");
5352#endif
5353 docbParseComment(ctxt);
5354 ctxt->instate = XML_PARSER_MISC;
5355 } else if ((cur == '<') && (next == '!') &&
5356 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5357 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5358 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5359 (UPP(8) == 'E')) {
5360 if ((!terminate) &&
5361 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5362 goto done;
5363#ifdef DEBUG_PUSH
5364 xmlGenericError(xmlGenericErrorContext,
5365 "HPP: Parsing internal subset\n");
5366#endif
5367 docbParseDocTypeDecl(ctxt);
5368 ctxt->instate = XML_PARSER_PROLOG;
5369#ifdef DEBUG_PUSH
5370 xmlGenericError(xmlGenericErrorContext,
5371 "HPP: entering PROLOG\n");
5372#endif
5373 } else if ((cur == '<') && (next == '!') &&
5374 (avail < 9)) {
5375 goto done;
5376 } else {
5377 ctxt->instate = XML_PARSER_START_TAG;
5378#ifdef DEBUG_PUSH
5379 xmlGenericError(xmlGenericErrorContext,
5380 "HPP: entering START_TAG\n");
5381#endif
5382 }
5383 break;
5384 case XML_PARSER_PROLOG:
5385 SKIP_BLANKS;
5386 if (in->buf == NULL)
5387 avail = in->length - (in->cur - in->base);
5388 else
5389 avail = in->buf->buffer->use - (in->cur - in->base);
5390 if (avail < 2)
5391 goto done;
5392 cur = in->cur[0];
5393 next = in->cur[1];
5394 if ((cur == '<') && (next == '!') &&
5395 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5396 if ((!terminate) &&
5397 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5398 goto done;
5399#ifdef DEBUG_PUSH
5400 xmlGenericError(xmlGenericErrorContext,
5401 "HPP: Parsing Comment\n");
5402#endif
5403 docbParseComment(ctxt);
5404 ctxt->instate = XML_PARSER_PROLOG;
5405 } else if ((cur == '<') && (next == '!') &&
5406 (avail < 4)) {
5407 goto done;
5408 } else {
5409 ctxt->instate = XML_PARSER_START_TAG;
5410#ifdef DEBUG_PUSH
5411 xmlGenericError(xmlGenericErrorContext,
5412 "HPP: entering START_TAG\n");
5413#endif
5414 }
5415 break;
5416 case XML_PARSER_EPILOG:
5417 if (in->buf == NULL)
5418 avail = in->length - (in->cur - in->base);
5419 else
5420 avail = in->buf->buffer->use - (in->cur - in->base);
5421 if (avail < 1)
5422 goto done;
5423 cur = in->cur[0];
5424 if (IS_BLANK(cur)) {
5425 docbParseCharData(ctxt);
5426 goto done;
5427 }
5428 if (avail < 2)
5429 goto done;
5430 next = in->cur[1];
5431 if ((cur == '<') && (next == '!') &&
5432 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5433 if ((!terminate) &&
5434 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5435 goto done;
5436#ifdef DEBUG_PUSH
5437 xmlGenericError(xmlGenericErrorContext,
5438 "HPP: Parsing Comment\n");
5439#endif
5440 docbParseComment(ctxt);
5441 ctxt->instate = XML_PARSER_EPILOG;
5442 } else if ((cur == '<') && (next == '!') &&
5443 (avail < 4)) {
5444 goto done;
5445 } else {
5446 ctxt->errNo = XML_ERR_DOCUMENT_END;
5447 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5448 ctxt->sax->error(ctxt->userData,
5449 "Extra content at the end of the document\n");
5450 ctxt->wellFormed = 0;
5451 ctxt->instate = XML_PARSER_EOF;
5452#ifdef DEBUG_PUSH
5453 xmlGenericError(xmlGenericErrorContext,
5454 "HPP: entering EOF\n");
5455#endif
5456 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5457 ctxt->sax->endDocument(ctxt->userData);
5458 goto done;
5459 }
5460 break;
5461 case XML_PARSER_START_TAG: {
5462 xmlChar *name, *oldname;
5463 int depth = ctxt->nameNr;
5464 docbElemDescPtr info;
5465
5466 if (avail < 2)
5467 goto done;
5468 cur = in->cur[0];
5469 if (cur != '<') {
5470 ctxt->instate = XML_PARSER_CONTENT;
5471#ifdef DEBUG_PUSH
5472 xmlGenericError(xmlGenericErrorContext,
5473 "HPP: entering CONTENT\n");
5474#endif
5475 break;
5476 }
5477 if ((!terminate) &&
5478 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5479 goto done;
5480
5481 oldname = xmlStrdup(ctxt->name);
5482 docbParseStartTag(ctxt);
5483 name = ctxt->name;
5484#ifdef DEBUG
5485 if (oldname == NULL)
5486 xmlGenericError(xmlGenericErrorContext,
5487 "Start of element %s\n", name);
5488 else if (name == NULL)
5489 xmlGenericError(xmlGenericErrorContext,
5490 "Start of element failed, was %s\n",
5491 oldname);
5492 else
5493 xmlGenericError(xmlGenericErrorContext,
5494 "Start of element %s, was %s\n",
5495 name, oldname);
5496#endif
5497 if (((depth == ctxt->nameNr) &&
5498 (xmlStrEqual(oldname, ctxt->name))) ||
5499 (name == NULL)) {
5500 if (CUR == '>')
5501 NEXT;
5502 if (oldname != NULL)
5503 xmlFree(oldname);
5504 break;
5505 }
5506 if (oldname != NULL)
5507 xmlFree(oldname);
5508
5509 /*
5510 * Lookup the info for that element.
5511 */
5512 info = docbTagLookup(name);
5513 if (info == NULL) {
5514 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5515 ctxt->sax->error(ctxt->userData, "Tag %s unknown\n",
5516 name);
5517 ctxt->wellFormed = 0;
5518 } else if (info->depr) {
5519 /***************************
5520 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
5521 ctxt->sax->warning(ctxt->userData,
5522 "Tag %s is deprecated\n",
5523 name);
5524 ***************************/
5525 }
5526
5527 /*
5528 * Check for an Empty Element labelled the XML/SGML way
5529 */
5530 if ((CUR == '/') && (NXT(1) == '>')) {
5531 SKIP(2);
5532 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
5533 ctxt->sax->endElement(ctxt->userData, name);
5534 oldname = docbnamePop(ctxt);
5535#ifdef DEBUG
5536 xmlGenericError(xmlGenericErrorContext,"End of tag the XML way: popping out %s\n",
5537 oldname);
5538#endif
5539 if (oldname != NULL)
5540 xmlFree(oldname);
5541 ctxt->instate = XML_PARSER_CONTENT;
5542#ifdef DEBUG_PUSH
5543 xmlGenericError(xmlGenericErrorContext,
5544 "HPP: entering CONTENT\n");
5545#endif
5546 break;
5547 }
5548
5549 if (CUR == '>') {
5550 NEXT;
5551 } else {
5552 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5553 ctxt->sax->error(ctxt->userData,
5554 "Couldn't find end of Start Tag %s\n",
5555 name);
5556 ctxt->wellFormed = 0;
5557
5558 /*
5559 * end of parsing of this node.
5560 */
5561 if (xmlStrEqual(name, ctxt->name)) {
5562 nodePop(ctxt);
5563 oldname = docbnamePop(ctxt);
5564#ifdef DEBUG
5565 xmlGenericError(xmlGenericErrorContext,
5566 "End of start tag problem: popping out %s\n", oldname);
5567#endif
5568 if (oldname != NULL)
5569 xmlFree(oldname);
5570 }
5571
5572 ctxt->instate = XML_PARSER_CONTENT;
5573#ifdef DEBUG_PUSH
5574 xmlGenericError(xmlGenericErrorContext,
5575 "HPP: entering CONTENT\n");
5576#endif
5577 break;
5578 }
5579
5580 /*
5581 * Check for an Empty Element from DTD definition
5582 */
5583 if ((info != NULL) && (info->empty)) {
5584 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
5585 ctxt->sax->endElement(ctxt->userData, name);
5586 oldname = docbnamePop(ctxt);
5587#ifdef DEBUG
5588 xmlGenericError(xmlGenericErrorContext,"End of empty tag %s : popping out %s\n", name, oldname);
5589#endif
5590 if (oldname != NULL)
5591 xmlFree(oldname);
5592 }
5593 ctxt->instate = XML_PARSER_CONTENT;
5594#ifdef DEBUG_PUSH
5595 xmlGenericError(xmlGenericErrorContext,
5596 "HPP: entering CONTENT\n");
5597#endif
5598 break;
5599 }
5600 case XML_PARSER_CONTENT: {
5601 long cons;
5602 /*
5603 * Handle preparsed entities and charRef
5604 */
5605 if (ctxt->token != 0) {
5606 xmlChar chr[2] = { 0 , 0 } ;
5607
5608 chr[0] = (xmlChar) ctxt->token;
5609 docbCheckParagraph(ctxt);
5610 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
5611 ctxt->sax->characters(ctxt->userData, chr, 1);
5612 ctxt->token = 0;
5613 ctxt->checkIndex = 0;
5614 }
5615 if ((avail == 1) && (terminate)) {
5616 cur = in->cur[0];
5617 if ((cur != '<') && (cur != '&')) {
5618 if (ctxt->sax != NULL) {
5619 if (IS_BLANK(cur)) {
5620 if (ctxt->sax->ignorableWhitespace != NULL)
5621 ctxt->sax->ignorableWhitespace(
5622 ctxt->userData, &cur, 1);
5623 } else {
5624 docbCheckParagraph(ctxt);
5625 if (ctxt->sax->characters != NULL)
5626 ctxt->sax->characters(
5627 ctxt->userData, &cur, 1);
5628 }
5629 }
5630 ctxt->token = 0;
5631 ctxt->checkIndex = 0;
5632 NEXT;
5633 }
5634 break;
5635 }
5636 if (avail < 2)
5637 goto done;
5638 cur = in->cur[0];
5639 next = in->cur[1];
5640 cons = ctxt->nbChars;
5641 /*
5642 * Sometimes DOCTYPE arrives in the middle of the document
5643 */
5644 if ((cur == '<') && (next == '!') &&
5645 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5646 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5647 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5648 (UPP(8) == 'E')) {
5649 if ((!terminate) &&
5650 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5651 goto done;
5652 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5653 ctxt->sax->error(ctxt->userData,
5654 "Misplaced DOCTYPE declaration\n");
5655 ctxt->wellFormed = 0;
5656 docbParseDocTypeDecl(ctxt);
5657 } else if ((cur == '<') && (next == '!') &&
5658 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5659 if ((!terminate) &&
5660 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5661 goto done;
5662#ifdef DEBUG_PUSH
5663 xmlGenericError(xmlGenericErrorContext,
5664 "HPP: Parsing Comment\n");
5665#endif
5666 docbParseComment(ctxt);
5667 ctxt->instate = XML_PARSER_CONTENT;
5668 } else if ((cur == '<') && (next == '!') && (avail < 4)) {
5669 goto done;
5670 } else if ((cur == '<') && (next == '/')) {
5671 ctxt->instate = XML_PARSER_END_TAG;
5672 ctxt->checkIndex = 0;
5673#ifdef DEBUG_PUSH
5674 xmlGenericError(xmlGenericErrorContext,
5675 "HPP: entering END_TAG\n");
5676#endif
5677 break;
5678 } else if (cur == '<') {
5679 ctxt->instate = XML_PARSER_START_TAG;
5680 ctxt->checkIndex = 0;
5681#ifdef DEBUG_PUSH
5682 xmlGenericError(xmlGenericErrorContext,
5683 "HPP: entering START_TAG\n");
5684#endif
5685 break;
5686 } else if (cur == '&') {
5687 if ((!terminate) &&
5688 (docbParseLookupSequence(ctxt, ';', 0, 0) < 0))
5689 goto done;
5690#ifdef DEBUG_PUSH
5691 xmlGenericError(xmlGenericErrorContext,
5692 "HPP: Parsing Reference\n");
5693#endif
5694 /* TODO: check generation of subtrees if noent !!! */
5695 docbParseReference(ctxt);
5696 } else {
5697 /* TODO Avoid the extra copy, handle directly !!!!!! */
5698 /*
5699 * Goal of the following test is :
5700 * - minimize calls to the SAX 'character' callback
5701 * when they are mergeable
5702 */
5703 if ((ctxt->inputNr == 1) &&
5704 (avail < DOCB_PARSER_BIG_BUFFER_SIZE)) {
5705 if ((!terminate) &&
5706 (docbParseLookupSequence(ctxt, '<', 0, 0) < 0))
5707 goto done;
5708 }
5709 ctxt->checkIndex = 0;
5710#ifdef DEBUG_PUSH
5711 xmlGenericError(xmlGenericErrorContext,
5712 "HPP: Parsing char data\n");
5713#endif
5714 docbParseCharData(ctxt);
5715 }
5716 if (cons == ctxt->nbChars) {
5717 if (ctxt->node != NULL) {
5718 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5719 ctxt->sax->error(ctxt->userData,
5720 "detected an error in element content\n");
5721 ctxt->wellFormed = 0;
5722 NEXT;
5723 }
5724 break;
5725 }
5726
5727 break;
5728 }
5729 case XML_PARSER_END_TAG:
5730 if (avail < 2)
5731 goto done;
5732 if ((!terminate) &&
5733 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5734 goto done;
5735 docbParseEndTag(ctxt);
5736 if (ctxt->nameNr == 0) {
5737 ctxt->instate = XML_PARSER_EPILOG;
5738 } else {
5739 ctxt->instate = XML_PARSER_CONTENT;
5740 }
5741 ctxt->checkIndex = 0;
5742#ifdef DEBUG_PUSH
5743 xmlGenericError(xmlGenericErrorContext,
5744 "HPP: entering CONTENT\n");
5745#endif
5746 break;
5747 case XML_PARSER_CDATA_SECTION:
5748 xmlGenericError(xmlGenericErrorContext,
5749 "HPP: internal error, state == CDATA\n");
5750 ctxt->instate = XML_PARSER_CONTENT;
5751 ctxt->checkIndex = 0;
5752#ifdef DEBUG_PUSH
5753 xmlGenericError(xmlGenericErrorContext,
5754 "HPP: entering CONTENT\n");
5755#endif
5756 break;
5757 case XML_PARSER_DTD:
5758 xmlGenericError(xmlGenericErrorContext,
5759 "HPP: internal error, state == DTD\n");
5760 ctxt->instate = XML_PARSER_CONTENT;
5761 ctxt->checkIndex = 0;
5762#ifdef DEBUG_PUSH
5763 xmlGenericError(xmlGenericErrorContext,
5764 "HPP: entering CONTENT\n");
5765#endif
5766 break;
5767 case XML_PARSER_COMMENT:
5768 xmlGenericError(xmlGenericErrorContext,
5769 "HPP: internal error, state == COMMENT\n");
5770 ctxt->instate = XML_PARSER_CONTENT;
5771 ctxt->checkIndex = 0;
5772#ifdef DEBUG_PUSH
5773 xmlGenericError(xmlGenericErrorContext,
5774 "HPP: entering CONTENT\n");
5775#endif
5776 break;
5777 case XML_PARSER_PI:
5778 xmlGenericError(xmlGenericErrorContext,
5779 "HPP: internal error, state == PI\n");
5780 ctxt->instate = XML_PARSER_CONTENT;
5781 ctxt->checkIndex = 0;
5782#ifdef DEBUG_PUSH
5783 xmlGenericError(xmlGenericErrorContext,
5784 "HPP: entering CONTENT\n");
5785#endif
5786 break;
5787 case XML_PARSER_ENTITY_DECL:
5788 xmlGenericError(xmlGenericErrorContext,
5789 "HPP: internal error, state == ENTITY_DECL\n");
5790 ctxt->instate = XML_PARSER_CONTENT;
5791 ctxt->checkIndex = 0;
5792#ifdef DEBUG_PUSH
5793 xmlGenericError(xmlGenericErrorContext,
5794 "HPP: entering CONTENT\n");
5795#endif
5796 break;
5797 case XML_PARSER_ENTITY_VALUE:
5798 xmlGenericError(xmlGenericErrorContext,
5799 "HPP: internal error, state == ENTITY_VALUE\n");
5800 ctxt->instate = XML_PARSER_CONTENT;
5801 ctxt->checkIndex = 0;
5802#ifdef DEBUG_PUSH
5803 xmlGenericError(xmlGenericErrorContext,
5804 "HPP: entering DTD\n");
5805#endif
5806 break;
5807 case XML_PARSER_ATTRIBUTE_VALUE:
5808 xmlGenericError(xmlGenericErrorContext,
5809 "HPP: internal error, state == ATTRIBUTE_VALUE\n");
5810 ctxt->instate = XML_PARSER_START_TAG;
5811 ctxt->checkIndex = 0;
5812#ifdef DEBUG_PUSH
5813 xmlGenericError(xmlGenericErrorContext,
5814 "HPP: entering START_TAG\n");
5815#endif
5816 break;
5817 case XML_PARSER_SYSTEM_LITERAL:
5818 xmlGenericError(xmlGenericErrorContext,
5819 "HPP: internal error, state == XML_PARSER_SYSTEM_LITERAL\n");
5820 ctxt->instate = XML_PARSER_CONTENT;
5821 ctxt->checkIndex = 0;
5822#ifdef DEBUG_PUSH
5823 xmlGenericError(xmlGenericErrorContext,
5824 "HPP: entering CONTENT\n");
5825#endif
5826 break;
5827
5828 case XML_PARSER_IGNORE:
5829 xmlGenericError(xmlGenericErrorContext,
5830 "HPP: internal error, state == XML_PARSER_IGNORE\n");
5831 ctxt->instate = XML_PARSER_CONTENT;
5832 ctxt->checkIndex = 0;
5833#ifdef DEBUG_PUSH
5834 xmlGenericError(xmlGenericErrorContext,
5835 "HPP: entering CONTENT\n");
5836#endif
5837 break;
5838 }
5839 }
5840done:
5841 if ((avail == 0) && (terminate)) {
5842 docbAutoClose(ctxt, NULL);
5843 if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
5844 /*
5845 * SAX: end of the document processing.
5846 */
5847 ctxt->instate = XML_PARSER_EOF;
5848 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5849 ctxt->sax->endDocument(ctxt->userData);
5850 }
5851 }
5852 if ((ctxt->myDoc != NULL) &&
5853 ((terminate) || (ctxt->instate == XML_PARSER_EOF) ||
5854 (ctxt->instate == XML_PARSER_EPILOG))) {
5855 xmlDtdPtr dtd;
5856 dtd = ctxt->myDoc->intSubset;
5857 if (dtd == NULL)
5858 ctxt->myDoc->intSubset =
5859 xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "SGML",
5860 BAD_CAST "-//W3C//DTD SGML 4.0 Transitional//EN",
5861 BAD_CAST "http://www.w3.org/TR/REC-docbook/loose.dtd");
5862 }
5863#ifdef DEBUG_PUSH
5864 xmlGenericError(xmlGenericErrorContext, "HPP: done %d\n", ret);
5865#endif
5866 return(ret);
5867}
5868
5869/**
5870 * docbParseChunk:
5871 * @ctxt: an XML parser context
5872 * @chunk: an char array
5873 * @size: the size in byte of the chunk
5874 * @terminate: last chunk indicator
5875 *
5876 * Parse a Chunk of memory
5877 *
5878 * Returns zero if no error, the xmlParserErrors otherwise.
5879 */
5880int
5881docbParseChunk(docbParserCtxtPtr ctxt, const char *chunk, int size,
5882 int terminate) {
5883 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
5884 (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) {
5885 int base = ctxt->input->base - ctxt->input->buf->buffer->content;
5886 int cur = ctxt->input->cur - ctxt->input->base;
5887
5888 xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
5889 ctxt->input->base = ctxt->input->buf->buffer->content + base;
5890 ctxt->input->cur = ctxt->input->base + cur;
5891#ifdef DEBUG_PUSH
5892 xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
5893#endif
5894
5895 if ((terminate) || (ctxt->input->buf->buffer->use > 80))
5896 docbParseTryOrFinish(ctxt, terminate);
5897 } else if (ctxt->instate != XML_PARSER_EOF) {
5898 xmlParserInputBufferPush(ctxt->input->buf, 0, "");
5899 docbParseTryOrFinish(ctxt, terminate);
5900 }
5901 if (terminate) {
5902 if ((ctxt->instate != XML_PARSER_EOF) &&
5903 (ctxt->instate != XML_PARSER_EPILOG) &&
5904 (ctxt->instate != XML_PARSER_MISC)) {
5905 ctxt->errNo = XML_ERR_DOCUMENT_END;
5906 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5907 ctxt->sax->error(ctxt->userData,
5908 "Extra content at the end of the document\n");
5909 ctxt->wellFormed = 0;
5910 }
5911 if (ctxt->instate != XML_PARSER_EOF) {
5912 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5913 ctxt->sax->endDocument(ctxt->userData);
5914 }
5915 ctxt->instate = XML_PARSER_EOF;
5916 }
5917 return((xmlParserErrors) ctxt->errNo);
5918}
5919
5920/************************************************************************
5921 * *
5922 * User entry points *
5923 * *
5924 ************************************************************************/
5925
5926/**
5927 * docbCreatePushParserCtxt :
5928 * @sax: a SAX handler
5929 * @user_data: The user data returned on SAX callbacks
5930 * @chunk: a pointer to an array of chars
5931 * @size: number of chars in the array
5932 * @filename: an optional file name or URI
5933 * @enc: an optional encoding
5934 *
5935 * Create a parser context for using the DocBook SGML parser in push mode
5936 * To allow content encoding detection, @size should be >= 4
5937 * The value of @filename is used for fetching external entities
5938 * and error/warning reports.
5939 *
5940 * Returns the new parser context or NULL
5941 */
5942docbParserCtxtPtr
5943docbCreatePushParserCtxt(docbSAXHandlerPtr sax, void *user_data,
5944 const char *chunk, int size, const char *filename,
5945 xmlCharEncoding enc) {
5946 docbParserCtxtPtr ctxt;
5947 docbParserInputPtr inputStream;
5948 xmlParserInputBufferPtr buf;
5949
5950 buf = xmlAllocParserInputBuffer(enc);
5951 if (buf == NULL) return(NULL);
5952
5953 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
5954 if (ctxt == NULL) {
5955 xmlFree(buf);
5956 return(NULL);
5957 }
5958 memset(ctxt, 0, sizeof(docbParserCtxt));
5959 docbInitParserCtxt(ctxt);
5960 if (sax != NULL) {
5961 if (ctxt->sax != &docbDefaultSAXHandler)
5962 xmlFree(ctxt->sax);
5963 ctxt->sax = (docbSAXHandlerPtr) xmlMalloc(sizeof(docbSAXHandler));
5964 if (ctxt->sax == NULL) {
5965 xmlFree(buf);
5966 xmlFree(ctxt);
5967 return(NULL);
5968 }
5969 memcpy(ctxt->sax, sax, sizeof(docbSAXHandler));
5970 if (user_data != NULL)
5971 ctxt->userData = user_data;
5972 }
5973 if (filename == NULL) {
5974 ctxt->directory = NULL;
5975 } else {
5976 ctxt->directory = xmlParserGetDirectory(filename);
5977 }
5978
5979 inputStream = docbNewInputStream(ctxt);
5980 if (inputStream == NULL) {
5981 xmlFreeParserCtxt(ctxt);
5982 return(NULL);
5983 }
5984
5985 if (filename == NULL)
5986 inputStream->filename = NULL;
5987 else
5988 inputStream->filename = xmlMemStrdup(filename);
5989 inputStream->buf = buf;
5990 inputStream->base = inputStream->buf->buffer->content;
5991 inputStream->cur = inputStream->buf->buffer->content;
5992
5993 inputPush(ctxt, inputStream);
5994
5995 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
5996 (ctxt->input->buf != NULL)) {
5997 xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
5998#ifdef DEBUG_PUSH
5999 xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
6000#endif
6001 }
6002
6003 return(ctxt);
6004}
6005
6006/**
6007 * docbSAXParseDoc :
6008 * @cur: a pointer to an array of xmlChar
6009 * @encoding: a free form C string describing the SGML document encoding, or NULL
6010 * @sax: the SAX handler block
6011 * @userData: if using SAX, this pointer will be provided on callbacks.
6012 *
6013 * parse an SGML in-memory document and build a tree.
6014 * It use the given SAX function block to handle the parsing callback.
6015 * If sax is NULL, fallback to the default DOM tree building routines.
6016 *
6017 * Returns the resulting document tree
6018 */
6019
6020docbDocPtr
6021docbSAXParseDoc(xmlChar *cur, const char *encoding, docbSAXHandlerPtr sax, void *userData) {
6022 docbDocPtr ret;
6023 docbParserCtxtPtr ctxt;
6024
6025 if (cur == NULL) return(NULL);
6026
6027
6028 ctxt = docbCreateDocParserCtxt(cur, encoding);
6029 if (ctxt == NULL) return(NULL);
6030 if (sax != NULL) {
6031 ctxt->sax = sax;
6032 ctxt->userData = userData;
6033 }
6034
6035 docbParseDocument(ctxt);
6036 ret = ctxt->myDoc;
6037 if (sax != NULL) {
6038 ctxt->sax = NULL;
6039 ctxt->userData = NULL;
6040 }
6041 docbFreeParserCtxt(ctxt);
6042
6043 return(ret);
6044}
6045
6046/**
6047 * docbParseDoc :
6048 * @cur: a pointer to an array of xmlChar
6049 * @encoding: a free form C string describing the SGML document encoding, or NULL
6050 *
6051 * parse an SGML in-memory document and build a tree.
6052 *
6053 * Returns the resulting document tree
6054 */
6055
6056docbDocPtr
6057docbParseDoc(xmlChar *cur, const char *encoding) {
6058 return(docbSAXParseDoc(cur, encoding, NULL, NULL));
6059}
6060
6061
6062/**
6063 * docbCreateFileParserCtxt :
6064 * @filename: the filename
Daniel Veillard1034da22001-04-25 19:06:28 +00006065 * @encoding: the SGML document encoding, or NULL
Daniel Veillardeae522a2001-04-23 13:41:34 +00006066 *
6067 * Create a parser context for a file content.
6068 * Automatic support for ZLIB/Compress compressed document is provided
6069 * by default if found at compile-time.
6070 *
6071 * Returns the new parser context or NULL
6072 */
6073docbParserCtxtPtr
Daniel Veillard1034da22001-04-25 19:06:28 +00006074docbCreateFileParserCtxt(const char *filename,
6075 const char *encoding ATTRIBUTE_UNUSED)
Daniel Veillardeae522a2001-04-23 13:41:34 +00006076{
6077 docbParserCtxtPtr ctxt;
6078 docbParserInputPtr inputStream;
6079 xmlParserInputBufferPtr buf;
6080 /* sgmlCharEncoding enc; */
6081
6082 buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
6083 if (buf == NULL) return(NULL);
6084
6085 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
6086 if (ctxt == NULL) {
6087 perror("malloc");
6088 return(NULL);
6089 }
6090 memset(ctxt, 0, sizeof(docbParserCtxt));
6091 docbInitParserCtxt(ctxt);
6092 inputStream = (docbParserInputPtr) xmlMalloc(sizeof(docbParserInput));
6093 if (inputStream == NULL) {
6094 perror("malloc");
6095 xmlFree(ctxt);
6096 return(NULL);
6097 }
6098 memset(inputStream, 0, sizeof(docbParserInput));
6099
6100 inputStream->filename = xmlMemStrdup(filename);
6101 inputStream->line = 1;
6102 inputStream->col = 1;
6103 inputStream->buf = buf;
6104 inputStream->directory = NULL;
6105
6106 inputStream->base = inputStream->buf->buffer->content;
6107 inputStream->cur = inputStream->buf->buffer->content;
6108 inputStream->free = NULL;
6109
6110 inputPush(ctxt, inputStream);
6111 return(ctxt);
6112}
6113
6114/**
6115 * docbSAXParseFile :
6116 * @filename: the filename
6117 * @encoding: a free form C string describing the SGML document encoding, or NULL
6118 * @sax: the SAX handler block
6119 * @userData: if using SAX, this pointer will be provided on callbacks.
6120 *
6121 * parse an SGML file and build a tree. Automatic support for ZLIB/Compress
6122 * compressed document is provided by default if found at compile-time.
6123 * It use the given SAX function block to handle the parsing callback.
6124 * If sax is NULL, fallback to the default DOM tree building routines.
6125 *
6126 * Returns the resulting document tree
6127 */
6128
6129docbDocPtr
6130docbSAXParseFile(const char *filename, const char *encoding, docbSAXHandlerPtr sax,
6131 void *userData) {
6132 docbDocPtr ret;
6133 docbParserCtxtPtr ctxt;
6134 docbSAXHandlerPtr oldsax = NULL;
6135
6136 ctxt = docbCreateFileParserCtxt(filename, encoding);
6137 if (ctxt == NULL) return(NULL);
6138 if (sax != NULL) {
6139 oldsax = ctxt->sax;
6140 ctxt->sax = sax;
6141 ctxt->userData = userData;
6142 }
6143
6144 docbParseDocument(ctxt);
6145
6146 ret = ctxt->myDoc;
6147 if (sax != NULL) {
6148 ctxt->sax = oldsax;
6149 ctxt->userData = NULL;
6150 }
6151 docbFreeParserCtxt(ctxt);
6152
6153 return(ret);
6154}
6155
6156/**
6157 * docbParseFile :
6158 * @filename: the filename
6159 * @encoding: a free form C string describing document encoding, or NULL
6160 *
6161 * parse a Docbook SGML file and build a tree. Automatic support for
6162 * ZLIB/Compress compressed document is provided by default if found
6163 * at compile-time.
6164 *
6165 * Returns the resulting document tree
6166 */
6167
6168docbDocPtr
6169docbParseFile(const char *filename, const char *encoding) {
6170 return(docbSAXParseFile(filename, encoding, NULL, NULL));
6171}
6172
6173#endif /* LIBXML_DOCB_ENABLED */