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