blob: e1d352b34ce7154d9288f73b5527583acdee8edd [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;
2678 docbEntityDescPtr ent;
2679
2680 /*
2681 * allocate a translation buffer.
2682 */
2683 buffer_size = DOCB_PARSER_BIG_BUFFER_SIZE;
Daniel Veillard3c908dc2003-04-19 00:07:51 +00002684 buffer = (xmlChar *) xmlMallocAtomic(buffer_size * sizeof(xmlChar));
Daniel Veillardeae522a2001-04-23 13:41:34 +00002685 if (buffer == NULL) {
Daniel Veillard3487c8d2002-09-05 11:33:25 +00002686 xmlGenericError(xmlGenericErrorContext,
2687 "docbParseSGMLAttribute: malloc failed");
Daniel Veillardeae522a2001-04-23 13:41:34 +00002688 return(NULL);
2689 }
2690 out = buffer;
2691
2692 /*
2693 * Ok loop until we reach one of the ending chars
2694 */
2695 while ((CUR != 0) && (CUR != stop) && (CUR != '>')) {
2696 if ((stop == 0) && (IS_BLANK(CUR))) break;
2697 if (CUR == '&') {
2698 if (NXT(1) == '#') {
2699 unsigned int c;
2700 int bits;
2701
2702 c = docbParseCharRef(ctxt);
2703 if (c < 0x80)
2704 { *out++ = c; bits= -6; }
2705 else if (c < 0x800)
2706 { *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
2707 else if (c < 0x10000)
2708 { *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
2709 else
2710 { *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
2711
2712 for ( ; bits >= 0; bits-= 6) {
2713 *out++ = ((c >> bits) & 0x3F) | 0x80;
2714 }
2715 } else {
William M. Brack779af002003-08-01 15:55:39 +00002716 docbParseEntityRef(ctxt, &name);
Daniel Veillardeae522a2001-04-23 13:41:34 +00002717 if (name == NULL) {
2718 *out++ = '&';
2719 if (out - buffer > buffer_size - 100) {
2720 int indx = out - buffer;
2721
2722 growBuffer(buffer);
2723 out = &buffer[indx];
2724 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002725 *out++ = '&';
Daniel Veillardeae522a2001-04-23 13:41:34 +00002726 } else {
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002727 ent = docbEntityLookup(name);
2728 if (ent == NULL) {
2729 *out++ = '&';
2730 cur = name;
2731 while (*cur != 0) {
2732 if (out - buffer > buffer_size - 100) {
2733 int indx = out - buffer;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002734
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002735 growBuffer(buffer);
2736 out = &buffer[indx];
2737 }
2738 *out++ = *cur++;
2739 }
2740 xmlFree(name);
2741 } else {
2742 unsigned int c;
2743 int bits;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002744
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002745 if (out - buffer > buffer_size - 100) {
2746 int indx = out - buffer;
2747
2748 growBuffer(buffer);
2749 out = &buffer[indx];
2750 }
2751 c = (xmlChar)ent->value;
2752 if (c < 0x80)
2753 { *out++ = c; bits= -6; }
2754 else if (c < 0x800)
2755 { *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
2756 else if (c < 0x10000)
2757 { *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
2758 else
2759 { *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
2760
2761 for ( ; bits >= 0; bits-= 6) {
2762 *out++ = ((c >> bits) & 0x3F) | 0x80;
2763 }
2764 xmlFree(name);
2765 }
2766 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002767 }
2768 } else {
2769 unsigned int c;
2770 int bits;
2771
2772 if (out - buffer > buffer_size - 100) {
2773 int indx = out - buffer;
2774
2775 growBuffer(buffer);
2776 out = &buffer[indx];
2777 }
2778 c = CUR;
2779 if (c < 0x80)
2780 { *out++ = c; bits= -6; }
2781 else if (c < 0x800)
2782 { *out++ =((c >> 6) & 0x1F) | 0xC0; bits= 0; }
2783 else if (c < 0x10000)
2784 { *out++ =((c >> 12) & 0x0F) | 0xE0; bits= 6; }
2785 else
2786 { *out++ =((c >> 18) & 0x07) | 0xF0; bits= 12; }
2787
2788 for ( ; bits >= 0; bits-= 6) {
2789 *out++ = ((c >> bits) & 0x3F) | 0x80;
2790 }
2791 NEXT;
2792 }
2793 }
2794 *out++ = 0;
2795 return(buffer);
2796}
2797
2798
2799/**
2800 * docbParseEntityRef:
2801 * @ctxt: an SGML parser context
2802 * @str: location to store the entity name
2803 *
2804 * parse an SGML ENTITY references
2805 *
2806 * [68] EntityRef ::= '&' Name ';'
2807 *
Daniel Veillard61b33d52001-04-24 13:55:12 +00002808 * Returns the associated xmlEntityPtr if found, or NULL otherwise,
Daniel Veillardeae522a2001-04-23 13:41:34 +00002809 * if non-NULL *str will have to be freed by the caller.
2810 */
Daniel Veillard61b33d52001-04-24 13:55:12 +00002811static xmlEntityPtr
Daniel Veillardeae522a2001-04-23 13:41:34 +00002812docbParseEntityRef(docbParserCtxtPtr ctxt, xmlChar **str) {
2813 xmlChar *name;
Daniel Veillard61b33d52001-04-24 13:55:12 +00002814 xmlEntityPtr ent = NULL;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002815 *str = NULL;
2816
2817 if (CUR == '&') {
2818 NEXT;
2819 name = docbParseName(ctxt);
Daniel Veillard61b33d52001-04-24 13:55:12 +00002820 if (name == NULL) {
2821 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2822 ctxt->sax->error(ctxt->userData,
2823 "docbParseEntityRef: no name\n");
2824 ctxt->wellFormed = 0;
2825 } else {
Daniel Veillardeae522a2001-04-23 13:41:34 +00002826 GROW;
Daniel Veillard61b33d52001-04-24 13:55:12 +00002827 if (CUR == ';') {
2828 *str = name;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002829
Daniel Veillard61b33d52001-04-24 13:55:12 +00002830 /*
2831 * Ask first SAX for entity resolution, otherwise try the
2832 * predefined set.
2833 */
2834 if (ctxt->sax != NULL) {
2835 if (ctxt->sax->getEntity != NULL)
2836 ent = ctxt->sax->getEntity(ctxt->userData, name);
2837 if (ent == NULL)
2838 ent = xmlGetPredefinedEntity(name);
2839 }
2840 NEXT;
2841 } else {
2842 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2843 ctxt->sax->error(ctxt->userData,
Daniel Veillardeae522a2001-04-23 13:41:34 +00002844 "docbParseEntityRef: expecting ';'\n");
Daniel Veillard61b33d52001-04-24 13:55:12 +00002845 *str = name;
2846 }
2847 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002848 }
2849 return(ent);
2850}
2851
2852/**
2853 * docbParseAttValue:
2854 * @ctxt: an SGML parser context
2855 *
2856 * parse a value for an attribute
2857 * Note: the parser won't do substitution of entities here, this
2858 * will be handled later in xmlStringGetNodeList, unless it was
2859 * asked for ctxt->replaceEntities != 0
2860 *
2861 * Returns the AttValue parsed or NULL.
2862 */
2863
2864static xmlChar *
2865docbParseAttValue(docbParserCtxtPtr ctxt) {
2866 xmlChar *ret = NULL;
2867
2868 if (CUR == '"') {
2869 NEXT;
2870 ret = docbParseSGMLAttribute(ctxt, '"');
2871 if (CUR != '"') {
2872 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2873 ctxt->sax->error(ctxt->userData, "AttValue: ' expected\n");
2874 ctxt->wellFormed = 0;
2875 } else
2876 NEXT;
2877 } else if (CUR == '\'') {
2878 NEXT;
2879 ret = docbParseSGMLAttribute(ctxt, '\'');
2880 if (CUR != '\'') {
2881 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2882 ctxt->sax->error(ctxt->userData, "AttValue: ' expected\n");
2883 ctxt->wellFormed = 0;
2884 } else
2885 NEXT;
2886 } else {
2887 /*
2888 * That's an SGMLism, the attribute value may not be quoted
2889 */
2890 ret = docbParseSGMLAttribute(ctxt, 0);
2891 if (ret == NULL) {
2892 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2893 ctxt->sax->error(ctxt->userData, "AttValue: no value found\n");
2894 ctxt->wellFormed = 0;
2895 }
2896 }
2897 return(ret);
2898}
2899
2900/**
2901 * docbParseSystemLiteral:
2902 * @ctxt: an SGML parser context
2903 *
2904 * parse an SGML Literal
2905 *
2906 * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
2907 *
2908 * Returns the SystemLiteral parsed or NULL
2909 */
2910
2911static xmlChar *
2912docbParseSystemLiteral(docbParserCtxtPtr ctxt) {
2913 const xmlChar *q;
2914 xmlChar *ret = NULL;
2915
2916 if (CUR == '"') {
2917 NEXT;
2918 q = CUR_PTR;
Daniel Veillard34ba3872003-07-15 13:34:05 +00002919 while ((IS_CHAR((unsigned int) CUR)) && (CUR != '"'))
Daniel Veillardeae522a2001-04-23 13:41:34 +00002920 NEXT;
Daniel Veillard34ba3872003-07-15 13:34:05 +00002921 if (!IS_CHAR((unsigned int) CUR)) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00002922 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2923 ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n");
2924 ctxt->wellFormed = 0;
2925 } else {
2926 ret = xmlStrndup(q, CUR_PTR - q);
2927 NEXT;
2928 }
2929 } else if (CUR == '\'') {
2930 NEXT;
2931 q = CUR_PTR;
Daniel Veillard34ba3872003-07-15 13:34:05 +00002932 while ((IS_CHAR((unsigned int) CUR)) && (CUR != '\''))
Daniel Veillardeae522a2001-04-23 13:41:34 +00002933 NEXT;
Daniel Veillard34ba3872003-07-15 13:34:05 +00002934 if (!IS_CHAR((unsigned int) CUR)) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00002935 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2936 ctxt->sax->error(ctxt->userData, "Unfinished SystemLiteral\n");
2937 ctxt->wellFormed = 0;
2938 } else {
2939 ret = xmlStrndup(q, CUR_PTR - q);
2940 NEXT;
2941 }
2942 } else {
2943 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2944 ctxt->sax->error(ctxt->userData,
2945 "SystemLiteral \" or ' expected\n");
2946 ctxt->wellFormed = 0;
2947 }
2948
2949 return(ret);
2950}
2951
2952/**
2953 * docbParsePubidLiteral:
2954 * @ctxt: an SGML parser context
2955 *
2956 * parse an SGML public literal
2957 *
2958 * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
2959 *
2960 * Returns the PubidLiteral parsed or NULL.
2961 */
2962
2963static xmlChar *
2964docbParsePubidLiteral(docbParserCtxtPtr ctxt) {
2965 const xmlChar *q;
2966 xmlChar *ret = NULL;
2967 /*
2968 * Name ::= (Letter | '_') (NameChar)*
2969 */
2970 if (CUR == '"') {
2971 NEXT;
2972 q = CUR_PTR;
2973 while (IS_PUBIDCHAR(CUR)) NEXT;
2974 if (CUR != '"') {
2975 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2976 ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n");
2977 ctxt->wellFormed = 0;
2978 } else {
2979 ret = xmlStrndup(q, CUR_PTR - q);
2980 NEXT;
2981 }
2982 } else if (CUR == '\'') {
2983 NEXT;
2984 q = CUR_PTR;
2985 while ((IS_LETTER(CUR)) && (CUR != '\''))
2986 NEXT;
2987 if (!IS_LETTER(CUR)) {
2988 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2989 ctxt->sax->error(ctxt->userData, "Unfinished PubidLiteral\n");
2990 ctxt->wellFormed = 0;
2991 } else {
2992 ret = xmlStrndup(q, CUR_PTR - q);
2993 NEXT;
2994 }
2995 } else {
2996 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
2997 ctxt->sax->error(ctxt->userData, "SystemLiteral \" or ' expected\n");
2998 ctxt->wellFormed = 0;
2999 }
3000
3001 return(ret);
3002}
3003
3004/**
3005 * docbParseCharData:
3006 * @ctxt: an SGML parser context
3007 * @cdata: int indicating whether we are within a CDATA section
3008 *
3009 * parse a CharData section.
3010 * if we are within a CDATA section ']]>' marks an end of section.
3011 *
3012 * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
3013 */
3014
3015static void
3016docbParseCharData(docbParserCtxtPtr ctxt) {
3017 xmlChar buf[DOCB_PARSER_BIG_BUFFER_SIZE + 5];
3018 int nbchar = 0;
3019 int cur, l;
3020
3021 SHRINK;
3022 cur = CUR_CHAR(l);
3023 while (((cur != '<') || (ctxt->token == '<')) &&
3024 ((cur != '&') || (ctxt->token == '&')) &&
3025 (IS_CHAR(cur))) {
3026 COPY_BUF(l,buf,nbchar,cur);
3027 if (nbchar >= DOCB_PARSER_BIG_BUFFER_SIZE) {
3028 /*
3029 * Ok the segment is to be consumed as chars.
3030 */
3031 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
3032 if (areBlanks(ctxt, buf, nbchar)) {
3033 if (ctxt->sax->ignorableWhitespace != NULL)
3034 ctxt->sax->ignorableWhitespace(ctxt->userData,
3035 buf, nbchar);
3036 } else {
Daniel Veillardeae522a2001-04-23 13:41:34 +00003037 if (ctxt->sax->characters != NULL)
3038 ctxt->sax->characters(ctxt->userData, buf, nbchar);
3039 }
3040 }
3041 nbchar = 0;
3042 }
3043 NEXTL(l);
3044 cur = CUR_CHAR(l);
3045 }
3046 if (nbchar != 0) {
3047 /*
3048 * Ok the segment is to be consumed as chars.
3049 */
3050 if ((ctxt->sax != NULL) && (!ctxt->disableSAX)) {
3051 if (areBlanks(ctxt, buf, nbchar)) {
3052 if (ctxt->sax->ignorableWhitespace != NULL)
3053 ctxt->sax->ignorableWhitespace(ctxt->userData, buf, nbchar);
3054 } else {
Daniel Veillardeae522a2001-04-23 13:41:34 +00003055 if (ctxt->sax->characters != NULL)
3056 ctxt->sax->characters(ctxt->userData, buf, nbchar);
3057 }
3058 }
3059 }
3060}
3061
3062/**
3063 * docbParseExternalID:
3064 * @ctxt: an SGML parser context
3065 * @publicID: a xmlChar** receiving PubidLiteral
3066 *
3067 * Parse an External ID or a Public ID
3068 *
3069 * Returns the function returns SystemLiteral and in the second
3070 * case publicID receives PubidLiteral,
3071 * it is possible to return NULL and have publicID set.
3072 */
3073
3074static xmlChar *
3075docbParseExternalID(docbParserCtxtPtr ctxt, xmlChar **publicID) {
3076 xmlChar *URI = NULL;
3077
3078 if ((UPPER == 'S') && (UPP(1) == 'Y') &&
3079 (UPP(2) == 'S') && (UPP(3) == 'T') &&
3080 (UPP(4) == 'E') && (UPP(5) == 'M')) {
3081 SKIP(6);
3082 if (!IS_BLANK(CUR)) {
3083 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3084 ctxt->sax->error(ctxt->userData,
3085 "Space required after 'SYSTEM'\n");
3086 ctxt->wellFormed = 0;
3087 }
3088 SKIP_BLANKS;
3089 URI = docbParseSystemLiteral(ctxt);
3090 if (URI == NULL) {
3091 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3092 ctxt->sax->error(ctxt->userData,
3093 "docbParseExternalID: SYSTEM, no URI\n");
3094 ctxt->wellFormed = 0;
3095 }
3096 } else if ((UPPER == 'P') && (UPP(1) == 'U') &&
3097 (UPP(2) == 'B') && (UPP(3) == 'L') &&
3098 (UPP(4) == 'I') && (UPP(5) == 'C')) {
3099 SKIP(6);
3100 if (!IS_BLANK(CUR)) {
3101 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3102 ctxt->sax->error(ctxt->userData,
3103 "Space required after 'PUBLIC'\n");
3104 ctxt->wellFormed = 0;
3105 }
3106 SKIP_BLANKS;
3107 *publicID = docbParsePubidLiteral(ctxt);
3108 if (*publicID == NULL) {
3109 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3110 ctxt->sax->error(ctxt->userData,
3111 "docbParseExternalID: PUBLIC, no Public Identifier\n");
3112 ctxt->wellFormed = 0;
3113 }
3114 SKIP_BLANKS;
3115 if ((CUR == '"') || (CUR == '\'')) {
3116 URI = docbParseSystemLiteral(ctxt);
3117 }
3118 }
3119 return(URI);
3120}
3121
3122/**
Daniel Veillarde95e2392001-06-06 10:46:28 +00003123 * docbParsePI:
3124 * @ctxt: an XML parser context
3125 *
3126 * parse an XML Processing Instruction.
3127 *
3128 * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
3129 *
3130 * The processing is transfered to SAX once parsed.
3131 */
3132
3133static void
3134docbParsePI(xmlParserCtxtPtr ctxt) {
3135 xmlChar *buf = NULL;
3136 int len = 0;
3137 int size = DOCB_PARSER_BUFFER_SIZE;
3138 int cur, l;
3139 xmlChar *target;
3140 xmlParserInputState state;
3141 int count = 0;
3142
3143 if ((RAW == '<') && (NXT(1) == '?')) {
3144 xmlParserInputPtr input = ctxt->input;
3145 state = ctxt->instate;
3146 ctxt->instate = XML_PARSER_PI;
3147 /*
3148 * this is a Processing Instruction.
3149 */
3150 SKIP(2);
3151 SHRINK;
3152
3153 /*
3154 * Parse the target name and check for special support like
3155 * namespace.
3156 */
3157 target = xmlParseName(ctxt);
3158 if (target != NULL) {
3159 xmlChar *encoding = NULL;
3160
3161 if ((RAW == '?') && (NXT(1) == '>')) {
3162 if (input != ctxt->input) {
3163 ctxt->errNo = XML_ERR_ENTITY_BOUNDARY;
3164 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3165 ctxt->sax->error(ctxt->userData,
3166 "PI declaration doesn't start and stop in the same entity\n");
3167 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00003168 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillarde95e2392001-06-06 10:46:28 +00003169 }
3170 SKIP(2);
3171
3172 /*
3173 * SAX: PI detected.
3174 */
3175 if ((ctxt->sax) && (!ctxt->disableSAX) &&
3176 (ctxt->sax->processingInstruction != NULL))
3177 ctxt->sax->processingInstruction(ctxt->userData,
3178 target, NULL);
3179 ctxt->instate = state;
3180 xmlFree(target);
3181 return;
3182 }
3183 if (xmlStrEqual(target, BAD_CAST "sgml-declaration")) {
3184
3185 encoding = xmlParseEncodingDecl(ctxt);
3186 if (encoding == NULL) {
3187 xmlGenericError(xmlGenericErrorContext,
3188 "sgml-declaration: failed to find/handle encoding\n");
3189#ifdef DEBUG
3190 } else {
3191 xmlGenericError(xmlGenericErrorContext,
3192 "switched to encoding %s\n", encoding);
3193#endif
3194 }
3195
3196 }
Daniel Veillard3c908dc2003-04-19 00:07:51 +00003197 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
Daniel Veillarde95e2392001-06-06 10:46:28 +00003198 if (buf == NULL) {
3199 xmlGenericError(xmlGenericErrorContext,
3200 "malloc of %d byte failed\n", size);
3201 ctxt->instate = state;
3202 return;
3203 }
3204 cur = CUR;
3205 if (encoding != NULL) {
3206 len = snprintf((char *) buf, size - 1,
3207 " encoding = \"%s\"", encoding);
3208 if (len < 0)
3209 len = size;
3210 } else {
3211 if (!IS_BLANK(cur)) {
3212 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
3213 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3214 ctxt->sax->error(ctxt->userData,
3215 "docbParsePI: PI %s space expected\n", target);
3216 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00003217 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillarde95e2392001-06-06 10:46:28 +00003218 }
3219 SKIP_BLANKS;
3220 }
3221 cur = CUR_CHAR(l);
3222 while (IS_CHAR(cur) && /* checked */
3223 ((cur != '?') || (NXT(1) != '>'))) {
3224 if (len + 5 >= size) {
3225 size *= 2;
3226 buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
3227 if (buf == NULL) {
3228 xmlGenericError(xmlGenericErrorContext,
3229 "realloc of %d byte failed\n", size);
3230 ctxt->instate = state;
3231 return;
3232 }
3233 }
3234 count++;
3235 if (count > 50) {
3236 GROW;
3237 count = 0;
3238 }
3239 COPY_BUF(l,buf,len,cur);
3240 NEXTL(l);
3241 cur = CUR_CHAR(l);
3242 if (cur == 0) {
3243 SHRINK;
3244 GROW;
3245 cur = CUR_CHAR(l);
3246 }
3247 }
3248 buf[len] = 0;
3249 if (cur != '?') {
3250 ctxt->errNo = XML_ERR_PI_NOT_FINISHED;
3251 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3252 ctxt->sax->error(ctxt->userData,
3253 "docbParsePI: PI %s never end ...\n", target);
3254 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00003255 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillarde95e2392001-06-06 10:46:28 +00003256 } else {
3257 if (input != ctxt->input) {
3258 ctxt->errNo = XML_ERR_ENTITY_BOUNDARY;
3259 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3260 ctxt->sax->error(ctxt->userData,
3261 "PI declaration doesn't start and stop in the same entity\n");
3262 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00003263 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillarde95e2392001-06-06 10:46:28 +00003264 }
3265 SKIP(2);
3266
3267 /*
3268 * SAX: PI detected.
3269 */
3270 if ((ctxt->sax) && (!ctxt->disableSAX) &&
3271 (ctxt->sax->processingInstruction != NULL))
3272 ctxt->sax->processingInstruction(ctxt->userData,
3273 target, buf);
3274 }
3275 xmlFree(buf);
3276 xmlFree(target);
3277 } else {
3278 ctxt->errNo = XML_ERR_PI_NOT_STARTED;
3279 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3280 ctxt->sax->error(ctxt->userData,
3281 "docbParsePI : no target name\n");
3282 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00003283 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillarde95e2392001-06-06 10:46:28 +00003284 }
3285 ctxt->instate = state;
3286 }
3287}
3288
3289/**
Daniel Veillardeae522a2001-04-23 13:41:34 +00003290 * docbParseComment:
3291 * @ctxt: an SGML parser context
3292 *
3293 * Parse an XML (SGML) comment <!-- .... -->
3294 *
3295 * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
3296 */
3297static void
3298docbParseComment(docbParserCtxtPtr ctxt) {
3299 xmlChar *buf = NULL;
3300 int len;
3301 int size = DOCB_PARSER_BUFFER_SIZE;
3302 int q, ql;
3303 int r, rl;
3304 int cur, l;
3305 xmlParserInputState state;
3306
3307 /*
3308 * Check that there is a comment right here.
3309 */
3310 if ((RAW != '<') || (NXT(1) != '!') ||
3311 (NXT(2) != '-') || (NXT(3) != '-')) return;
3312
3313 state = ctxt->instate;
3314 ctxt->instate = XML_PARSER_COMMENT;
3315 SHRINK;
3316 SKIP(4);
Daniel Veillard3c908dc2003-04-19 00:07:51 +00003317 buf = (xmlChar *) xmlMallocAtomic(size * sizeof(xmlChar));
Daniel Veillardeae522a2001-04-23 13:41:34 +00003318 if (buf == NULL) {
3319 xmlGenericError(xmlGenericErrorContext,
3320 "malloc of %d byte failed\n", size);
3321 ctxt->instate = state;
3322 return;
3323 }
3324 q = CUR_CHAR(ql);
3325 NEXTL(ql);
3326 r = CUR_CHAR(rl);
3327 NEXTL(rl);
3328 cur = CUR_CHAR(l);
3329 len = 0;
3330 while (IS_CHAR(cur) &&
3331 ((cur != '>') ||
3332 (r != '-') || (q != '-'))) {
3333 if (len + 5 >= size) {
3334 size *= 2;
3335 buf = (xmlChar *) xmlRealloc(buf, size * sizeof(xmlChar));
3336 if (buf == NULL) {
3337 xmlGenericError(xmlGenericErrorContext,
3338 "realloc of %d byte failed\n", size);
3339 ctxt->instate = state;
3340 return;
3341 }
3342 }
3343 COPY_BUF(ql,buf,len,q);
3344 q = r;
3345 ql = rl;
3346 r = cur;
3347 rl = l;
3348 NEXTL(l);
3349 cur = CUR_CHAR(l);
3350 if (cur == 0) {
3351 SHRINK;
3352 GROW;
3353 cur = CUR_CHAR(l);
3354 }
3355 }
3356 buf[len] = 0;
3357 if (!IS_CHAR(cur)) {
3358 ctxt->errNo = XML_ERR_COMMENT_NOT_FINISHED;
3359 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3360 ctxt->sax->error(ctxt->userData,
3361 "Comment not terminated \n<!--%.50s\n", buf);
3362 ctxt->wellFormed = 0;
3363 xmlFree(buf);
3364 } else {
3365 NEXT;
3366 if ((ctxt->sax != NULL) && (ctxt->sax->comment != NULL) &&
3367 (!ctxt->disableSAX))
3368 ctxt->sax->comment(ctxt->userData, buf);
3369 xmlFree(buf);
3370 }
3371 ctxt->instate = state;
3372}
3373
3374/**
3375 * docbParseCharRef:
3376 * @ctxt: an SGML parser context
3377 *
3378 * parse Reference declarations
3379 *
3380 * [66] CharRef ::= '&#' [0-9]+ ';' |
3381 * '&#x' [0-9a-fA-F]+ ';'
3382 *
3383 * Returns the value parsed (as an int)
3384 */
3385static int
3386docbParseCharRef(docbParserCtxtPtr ctxt) {
3387 int val = 0;
3388
3389 if ((CUR == '&') && (NXT(1) == '#') &&
3390 (NXT(2) == 'x')) {
3391 SKIP(3);
3392 while (CUR != ';') {
3393 if ((CUR >= '0') && (CUR <= '9'))
3394 val = val * 16 + (CUR - '0');
3395 else if ((CUR >= 'a') && (CUR <= 'f'))
3396 val = val * 16 + (CUR - 'a') + 10;
3397 else if ((CUR >= 'A') && (CUR <= 'F'))
3398 val = val * 16 + (CUR - 'A') + 10;
3399 else {
3400 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3401 ctxt->sax->error(ctxt->userData,
3402 "docbParseCharRef: invalid hexadecimal value\n");
3403 ctxt->wellFormed = 0;
3404 val = 0;
3405 break;
3406 }
3407 NEXT;
3408 }
3409 if (CUR == ';')
3410 NEXT;
3411 } else if ((CUR == '&') && (NXT(1) == '#')) {
3412 SKIP(2);
3413 while (CUR != ';') {
3414 if ((CUR >= '0') && (CUR <= '9'))
3415 val = val * 10 + (CUR - '0');
3416 else {
3417 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3418 ctxt->sax->error(ctxt->userData,
3419 "docbParseCharRef: invalid decimal value\n");
3420 ctxt->wellFormed = 0;
3421 val = 0;
3422 break;
3423 }
3424 NEXT;
3425 }
3426 if (CUR == ';')
3427 NEXT;
3428 } else {
3429 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3430 ctxt->sax->error(ctxt->userData, "docbParseCharRef: invalid value\n");
3431 ctxt->wellFormed = 0;
3432 }
3433 /*
3434 * Check the value IS_CHAR ...
3435 */
3436 if (IS_CHAR(val)) {
3437 return(val);
3438 } else {
3439 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3440 ctxt->sax->error(ctxt->userData, "docbParseCharRef: invalid xmlChar value %d\n",
3441 val);
3442 ctxt->wellFormed = 0;
3443 }
3444 return(0);
3445}
3446
3447
3448/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00003449 * docbParseDocTypeDecl:
Daniel Veillardeae522a2001-04-23 13:41:34 +00003450 * @ctxt: an SGML parser context
3451 *
3452 * parse a DOCTYPE declaration
3453 *
3454 * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
3455 * ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
3456 */
3457
3458static void
3459docbParseDocTypeDecl(docbParserCtxtPtr ctxt) {
3460 xmlChar *name;
3461 xmlChar *ExternalID = NULL;
3462 xmlChar *URI = NULL;
3463
3464 /*
3465 * We know that '<!DOCTYPE' has been detected.
3466 */
3467 SKIP(9);
3468
3469 SKIP_BLANKS;
3470
3471 /*
3472 * Parse the DOCTYPE name.
3473 */
3474 name = docbParseName(ctxt);
3475 if (name == NULL) {
3476 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3477 ctxt->sax->error(ctxt->userData, "docbParseDocTypeDecl : no DOCTYPE name !\n");
3478 ctxt->wellFormed = 0;
3479 }
3480 /*
3481 * Check that upper(name) == "SGML" !!!!!!!!!!!!!
3482 */
3483
3484 SKIP_BLANKS;
3485
3486 /*
3487 * Check for SystemID and ExternalID
3488 */
3489 URI = docbParseExternalID(ctxt, &ExternalID);
3490 SKIP_BLANKS;
3491
3492 /*
3493 * Create or update the document accordingly to the DOCTYPE
Daniel Veillard89cad532001-10-22 09:46:13 +00003494 * But use the predefined PUBLIC and SYSTEM ID of DocBook XML
Daniel Veillardeae522a2001-04-23 13:41:34 +00003495 */
3496 if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) &&
3497 (!ctxt->disableSAX))
Daniel Veillard89cad532001-10-22 09:46:13 +00003498 ctxt->sax->internalSubset(ctxt->userData, name,
3499 XML_DOCBOOK_XML_PUBLIC,
3500 XML_DOCBOOK_XML_SYSTEM);
Daniel Veillardeae522a2001-04-23 13:41:34 +00003501
Daniel Veillard89cad532001-10-22 09:46:13 +00003502 if (RAW != '>') {
3503 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3504 ctxt->sax->error(ctxt->userData,
3505 "docbParseDocTypeDecl : internal subset not handled\n");
3506 } else {
3507 NEXT;
Daniel Veillardeae522a2001-04-23 13:41:34 +00003508 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00003509
3510 /*
3511 * Cleanup, since we don't use all those identifiers
3512 */
3513 if (URI != NULL) xmlFree(URI);
3514 if (ExternalID != NULL) xmlFree(ExternalID);
3515 if (name != NULL) xmlFree(name);
3516}
3517
3518/**
3519 * docbParseAttribute:
3520 * @ctxt: an SGML parser context
3521 * @value: a xmlChar ** used to store the value of the attribute
3522 *
3523 * parse an attribute
3524 *
3525 * [41] Attribute ::= Name Eq AttValue
3526 *
3527 * [25] Eq ::= S? '=' S?
3528 *
3529 * With namespace:
3530 *
3531 * [NS 11] Attribute ::= QName Eq AttValue
3532 *
3533 * Also the case QName == xmlns:??? is handled independently as a namespace
3534 * definition.
3535 *
3536 * Returns the attribute name, and the value in *value.
3537 */
3538
3539static xmlChar *
3540docbParseAttribute(docbParserCtxtPtr ctxt, xmlChar **value) {
3541 xmlChar *name, *val = NULL;
3542
3543 *value = NULL;
3544 name = docbParseName(ctxt);
3545 if (name == NULL) {
3546 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3547 ctxt->sax->error(ctxt->userData, "error parsing attribute name\n");
3548 ctxt->wellFormed = 0;
3549 return(NULL);
3550 }
3551
3552 /*
3553 * read the value
3554 */
3555 SKIP_BLANKS;
3556 if (CUR == '=') {
3557 NEXT;
3558 SKIP_BLANKS;
3559 val = docbParseAttValue(ctxt);
3560 /******
3561 } else {
3562 * TODO : some attribute must have values, some may not
3563 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3564 ctxt->sax->warning(ctxt->userData,
3565 "No value for attribute %s\n", name); */
3566 }
3567
3568 *value = val;
3569 return(name);
3570}
3571
3572/**
3573 * docbCheckEncoding:
3574 * @ctxt: an SGML parser context
3575 * @attvalue: the attribute value
3576 *
3577 * Checks an http-equiv attribute from a Meta tag to detect
3578 * the encoding
3579 * If a new encoding is detected the parser is switched to decode
3580 * it and pass UTF8
3581 */
3582static void
3583docbCheckEncoding(docbParserCtxtPtr ctxt, const xmlChar *attvalue) {
3584 const xmlChar *encoding;
3585
3586 if ((ctxt == NULL) || (attvalue == NULL))
3587 return;
3588
3589 encoding = xmlStrstr(attvalue, BAD_CAST"charset=");
3590 if (encoding == NULL)
3591 encoding = xmlStrstr(attvalue, BAD_CAST"Charset=");
3592 if (encoding == NULL)
3593 encoding = xmlStrstr(attvalue, BAD_CAST"CHARSET=");
3594 if (encoding != NULL) {
3595 encoding += 8;
3596 } else {
3597 encoding = xmlStrstr(attvalue, BAD_CAST"charset =");
3598 if (encoding == NULL)
3599 encoding = xmlStrstr(attvalue, BAD_CAST"Charset =");
3600 if (encoding == NULL)
3601 encoding = xmlStrstr(attvalue, BAD_CAST"CHARSET =");
3602 if (encoding != NULL)
3603 encoding += 9;
3604 }
3605 /*
3606 * Restricted from 2.3.5 */
3607 if (encoding != NULL) {
3608 xmlCharEncoding enc;
3609
3610 if (ctxt->input->encoding != NULL)
3611 xmlFree((xmlChar *) ctxt->input->encoding);
3612 ctxt->input->encoding = encoding;
3613
3614 enc = xmlParseCharEncoding((const char *) encoding);
3615 if (enc == XML_CHAR_ENCODING_8859_1) {
3616 ctxt->charset = XML_CHAR_ENCODING_8859_1;
3617 } else if (enc != XML_CHAR_ENCODING_UTF8) {
3618 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3619 ctxt->sax->error(ctxt->userData,
3620 "Unsupported encoding %s\n", encoding);
3621 /* xmlFree(encoding); */
3622 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00003623 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00003624 ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;
3625 }
3626 }
3627}
3628
3629/**
3630 * docbCheckMeta:
3631 * @ctxt: an SGML parser context
3632 * @atts: the attributes values
3633 *
3634 * Checks an attributes from a Meta tag
3635 */
3636static void
3637docbCheckMeta(docbParserCtxtPtr ctxt, const xmlChar **atts) {
3638 int i;
3639 const xmlChar *att, *value;
3640 int http = 0;
3641 const xmlChar *content = NULL;
3642
3643 if ((ctxt == NULL) || (atts == NULL))
3644 return;
3645
3646 i = 0;
3647 att = atts[i++];
3648 while (att != NULL) {
3649 value = atts[i++];
3650 if ((value != NULL) &&
3651 ((xmlStrEqual(att, BAD_CAST"http-equiv")) ||
3652 (xmlStrEqual(att, BAD_CAST"Http-Equiv")) ||
3653 (xmlStrEqual(att, BAD_CAST"HTTP-EQUIV"))) &&
3654 ((xmlStrEqual(value, BAD_CAST"Content-Type")) ||
3655 (xmlStrEqual(value, BAD_CAST"content-type")) ||
3656 (xmlStrEqual(value, BAD_CAST"CONTENT-TYPE"))))
3657 http = 1;
3658 else if ((value != NULL) &&
3659 ((xmlStrEqual(att, BAD_CAST"content")) ||
3660 (xmlStrEqual(att, BAD_CAST"Content")) ||
3661 (xmlStrEqual(att, BAD_CAST"CONTENT"))))
3662 content = value;
3663 att = atts[i++];
3664 }
3665 if ((http) && (content != NULL))
3666 docbCheckEncoding(ctxt, content);
3667
3668}
3669
3670/**
3671 * docbParseStartTag:
3672 * @ctxt: an SGML parser context
3673 *
3674 * parse a start of tag either for rule element or
3675 * EmptyElement. In both case we don't parse the tag closing chars.
3676 *
3677 * [40] STag ::= '<' Name (S Attribute)* S? '>'
3678 *
3679 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
3680 *
3681 * With namespace:
3682 *
3683 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>'
3684 *
3685 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
3686 *
3687 */
3688
3689static void
3690docbParseStartTag(docbParserCtxtPtr ctxt) {
3691 xmlChar *name;
3692 xmlChar *attname;
3693 xmlChar *attvalue;
3694 const xmlChar **atts = NULL;
3695 int nbatts = 0;
3696 int maxatts = 0;
3697 int meta = 0;
3698 int i;
3699
3700 if (CUR != '<') return;
3701 NEXT;
3702
3703 GROW;
3704 name = docbParseSGMLName(ctxt);
3705 if (name == NULL) {
3706 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3707 ctxt->sax->error(ctxt->userData,
3708 "docbParseStartTag: invalid element name\n");
3709 ctxt->wellFormed = 0;
3710 return;
3711 }
3712 if (xmlStrEqual(name, BAD_CAST"meta"))
3713 meta = 1;
3714
3715 /*
3716 * Check for auto-closure of SGML elements.
3717 */
3718 docbAutoClose(ctxt, name);
3719
3720 /*
3721 * Now parse the attributes, it ends up with the ending
3722 *
3723 * (S Attribute)* S?
3724 */
3725 SKIP_BLANKS;
Daniel Veillard34ba3872003-07-15 13:34:05 +00003726 while ((IS_CHAR((unsigned int) CUR)) &&
Daniel Veillardeae522a2001-04-23 13:41:34 +00003727 (CUR != '>') &&
3728 ((CUR != '/') || (NXT(1) != '>'))) {
3729 long cons = ctxt->nbChars;
3730
3731 GROW;
3732 attname = docbParseAttribute(ctxt, &attvalue);
3733 if (attname != NULL) {
3734
3735 /*
3736 * Well formedness requires at most one declaration of an attribute
3737 */
3738 for (i = 0; i < nbatts;i += 2) {
3739 if (xmlStrEqual(atts[i], attname)) {
3740 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3741 ctxt->sax->error(ctxt->userData,
3742 "Attribute %s redefined\n",
3743 attname);
3744 ctxt->wellFormed = 0;
3745 xmlFree(attname);
3746 if (attvalue != NULL)
3747 xmlFree(attvalue);
3748 goto failed;
3749 }
3750 }
3751
3752 /*
3753 * Add the pair to atts
3754 */
3755 if (atts == NULL) {
3756 maxatts = 10;
3757 atts = (const xmlChar **) xmlMalloc(maxatts * sizeof(xmlChar *));
3758 if (atts == NULL) {
3759 xmlGenericError(xmlGenericErrorContext,
3760 "malloc of %ld byte failed\n",
3761 maxatts * (long)sizeof(xmlChar *));
3762 if (name != NULL) xmlFree(name);
3763 return;
3764 }
3765 } else if (nbatts + 4 > maxatts) {
3766 maxatts *= 2;
Daniel Veillard50f34372001-08-03 12:06:36 +00003767 atts = (const xmlChar **) xmlRealloc((void *)atts, maxatts * sizeof(xmlChar *));
Daniel Veillardeae522a2001-04-23 13:41:34 +00003768 if (atts == NULL) {
3769 xmlGenericError(xmlGenericErrorContext,
3770 "realloc of %ld byte failed\n",
3771 maxatts * (long)sizeof(xmlChar *));
3772 if (name != NULL) xmlFree(name);
3773 return;
3774 }
3775 }
3776 atts[nbatts++] = attname;
3777 atts[nbatts++] = attvalue;
3778 atts[nbatts] = NULL;
3779 atts[nbatts + 1] = NULL;
3780 }
3781
3782failed:
3783 SKIP_BLANKS;
3784 if (cons == ctxt->nbChars) {
3785 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3786 ctxt->sax->error(ctxt->userData,
3787 "docbParseStartTag: problem parsing attributes\n");
3788 ctxt->wellFormed = 0;
3789 break;
3790 }
3791 }
3792
3793 /*
3794 * Handle specific association to the META tag
3795 */
3796 if (meta)
3797 docbCheckMeta(ctxt, atts);
3798
3799 /*
3800 * SAX: Start of Element !
3801 */
3802 docbnamePush(ctxt, xmlStrdup(name));
3803#ifdef DEBUG
3804 xmlGenericError(xmlGenericErrorContext,"Start of element %s: pushed %s\n", name, ctxt->name);
3805#endif
3806 if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL))
3807 ctxt->sax->startElement(ctxt->userData, name, atts);
3808
3809 if (atts != NULL) {
3810 for (i = 0;i < nbatts;i++) {
3811 if (atts[i] != NULL)
3812 xmlFree((xmlChar *) atts[i]);
3813 }
3814 xmlFree((void *) atts);
3815 }
3816 if (name != NULL) xmlFree(name);
3817}
3818
3819/**
3820 * docbParseEndTag:
3821 * @ctxt: an SGML parser context
3822 *
3823 * parse an end of tag
3824 *
3825 * [42] ETag ::= '</' Name S? '>'
3826 *
3827 * With namespace
3828 *
3829 * [NS 9] ETag ::= '</' QName S? '>'
3830 */
3831
3832static void
3833docbParseEndTag(docbParserCtxtPtr ctxt) {
3834 xmlChar *name;
3835 xmlChar *oldname;
3836 int i;
3837
3838 if ((CUR != '<') || (NXT(1) != '/')) {
3839 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3840 ctxt->sax->error(ctxt->userData, "docbParseEndTag: '</' not found\n");
3841 ctxt->wellFormed = 0;
3842 return;
3843 }
3844 SKIP(2);
3845
3846 name = docbParseSGMLName(ctxt);
3847 if (name == NULL) {
3848 if (CUR == '>') {
3849 NEXT;
3850 oldname = docbnamePop(ctxt);
3851 if (oldname != NULL) {
3852 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
3853 ctxt->sax->endElement(ctxt->userData, name);
3854#ifdef DEBUG
3855 xmlGenericError(xmlGenericErrorContext,"End of tag </>: popping out %s\n", oldname);
3856#endif
3857 xmlFree(oldname);
3858#ifdef DEBUG
3859 } else {
3860 xmlGenericError(xmlGenericErrorContext,"End of tag </>: stack empty !!!\n");
3861#endif
3862 }
3863 return;
3864 } else
3865 return;
3866 }
3867
3868 /*
3869 * We should definitely be at the ending "S? '>'" part
3870 */
3871 SKIP_BLANKS;
Daniel Veillard34ba3872003-07-15 13:34:05 +00003872 if ((!IS_CHAR((unsigned int) CUR)) || (CUR != '>')) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00003873 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3874 ctxt->sax->error(ctxt->userData, "End tag : expected '>'\n");
3875 ctxt->wellFormed = 0;
3876 } else
3877 NEXT;
3878
3879 /*
3880 * If the name read is not one of the element in the parsing stack
3881 * then return, it's just an error.
3882 */
3883 for (i = (ctxt->nameNr - 1);i >= 0;i--) {
3884 if (xmlStrEqual(name, ctxt->nameTab[i])) break;
3885 }
3886 if (i < 0) {
3887 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3888 ctxt->sax->error(ctxt->userData,
3889 "Unexpected end tag : %s\n", name);
3890 xmlFree(name);
3891 ctxt->wellFormed = 0;
3892 return;
3893 }
3894
3895
3896 /*
3897 * Check for auto-closure of SGML elements.
3898 */
3899
3900 docbAutoCloseOnClose(ctxt, name);
3901
3902 /*
3903 * Well formedness constraints, opening and closing must match.
3904 * With the exception that the autoclose may have popped stuff out
3905 * of the stack.
3906 */
3907 if (((name[0] != '/') || (name[1] != 0)) &&
3908 (!xmlStrEqual(name, ctxt->name))) {
3909#ifdef DEBUG
3910 xmlGenericError(xmlGenericErrorContext,"End of tag %s: expecting %s\n", name, ctxt->name);
3911#endif
3912 if ((ctxt->name != NULL) &&
3913 (!xmlStrEqual(ctxt->name, name))) {
3914 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3915 ctxt->sax->error(ctxt->userData,
3916 "Opening and ending tag mismatch: %s and %s\n",
3917 name, ctxt->name);
3918 ctxt->wellFormed = 0;
3919 }
3920 }
3921
3922 /*
3923 * SAX: End of Tag
3924 */
3925 oldname = ctxt->name;
3926 if (((name[0] == '/') && (name[1] == 0)) ||
3927 ((oldname != NULL) && (xmlStrEqual(oldname, name)))) {
3928 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
3929 ctxt->sax->endElement(ctxt->userData, name);
3930 oldname = docbnamePop(ctxt);
3931 if (oldname != NULL) {
3932#ifdef DEBUG
3933 xmlGenericError(xmlGenericErrorContext,"End of tag %s: popping out %s\n", name, oldname);
3934#endif
3935 xmlFree(oldname);
3936#ifdef DEBUG
3937 } else {
3938 xmlGenericError(xmlGenericErrorContext,"End of tag %s: stack empty !!!\n", name);
3939#endif
3940 }
3941 }
3942
3943 if (name != NULL)
3944 xmlFree(name);
3945
3946 return;
3947}
3948
3949
3950/**
3951 * docbParseReference:
3952 * @ctxt: an SGML parser context
3953 *
3954 * parse and handle entity references in content,
3955 * this will end-up in a call to character() since this is either a
3956 * CharRef, or a predefined entity.
3957 */
3958static void
3959docbParseReference(docbParserCtxtPtr ctxt) {
3960 docbEntityDescPtr ent;
Daniel Veillard61b33d52001-04-24 13:55:12 +00003961 xmlEntityPtr xent;
Daniel Veillardeae522a2001-04-23 13:41:34 +00003962 xmlChar out[6];
3963 xmlChar *name;
3964 if (CUR != '&') return;
3965
3966 if (NXT(1) == '#') {
3967 unsigned int c;
3968 int bits, i = 0;
3969
3970 c = docbParseCharRef(ctxt);
3971 if (c < 0x80) { out[i++]= c; bits= -6; }
3972 else if (c < 0x800) { out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }
3973 else if (c < 0x10000) { out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }
3974 else { out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }
3975
3976 for ( ; bits >= 0; bits-= 6) {
3977 out[i++]= ((c >> bits) & 0x3F) | 0x80;
3978 }
3979 out[i] = 0;
3980
Daniel Veillardeae522a2001-04-23 13:41:34 +00003981 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
3982 ctxt->sax->characters(ctxt->userData, out, i);
3983 } else {
Daniel Veillard61b33d52001-04-24 13:55:12 +00003984 /*
3985 * Lookup the entity in the table.
3986 */
3987 xent = docbParseEntityRef(ctxt, &name);
3988 if (xent != NULL) {
Daniel Veillard1034da22001-04-25 19:06:28 +00003989 if (((ctxt->replaceEntities) || (ctxt->loadsubset)) &&
3990 ((xent->children == NULL) &&
3991 (xent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))) {
Daniel Veillard61b33d52001-04-24 13:55:12 +00003992 /*
3993 * we really need to fetch and parse the external entity
3994 */
Daniel Veillard61b33d52001-04-24 13:55:12 +00003995 xmlNodePtr children = NULL;
3996
William M. Brack779af002003-08-01 15:55:39 +00003997 docbParseCtxtExternalEntity(ctxt,
Daniel Veillard61b33d52001-04-24 13:55:12 +00003998 xent->SystemID, xent->ExternalID, &children);
3999 xmlAddChildList((xmlNodePtr) xent, children);
Daniel Veillard1034da22001-04-25 19:06:28 +00004000 }
4001 if (ctxt->replaceEntities) {
Daniel Veillard61b33d52001-04-24 13:55:12 +00004002 if ((ctxt->node != NULL) && (xent->children != NULL)) {
4003 /*
4004 * Seems we are generating the DOM content, do
4005 * a simple tree copy
4006 */
4007 xmlNodePtr new;
4008 new = xmlCopyNodeList(xent->children);
4009
4010 xmlAddChildList(ctxt->node, new);
4011 /*
4012 * This is to avoid a nasty side effect, see
4013 * characters() in SAX.c
4014 */
4015 ctxt->nodemem = 0;
4016 ctxt->nodelen = 0;
4017 }
Daniel Veillard1034da22001-04-25 19:06:28 +00004018 } else {
4019 if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) &&
4020 (ctxt->replaceEntities == 0) && (!ctxt->disableSAX)) {
4021 /*
4022 * Create a node.
4023 */
4024 ctxt->sax->reference(ctxt->userData, xent->name);
4025 }
Daniel Veillard61b33d52001-04-24 13:55:12 +00004026 }
4027 } else if (name != NULL) {
4028 ent = docbEntityLookup(name);
4029 if ((ent == NULL) || (ent->value <= 0)) {
Daniel Veillard61b33d52001-04-24 13:55:12 +00004030 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) {
4031 ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1);
4032 ctxt->sax->characters(ctxt->userData, name, xmlStrlen(name));
4033 /* ctxt->sax->characters(ctxt->userData, BAD_CAST ";", 1); */
4034 }
4035 } else {
4036 unsigned int c;
4037 int bits, i = 0;
4038
4039 c = ent->value;
4040 if (c < 0x80)
4041 { out[i++]= c; bits= -6; }
4042 else if (c < 0x800)
4043 { out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }
4044 else if (c < 0x10000)
4045 { out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }
4046 else
4047 { out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }
4048
4049 for ( ; bits >= 0; bits-= 6) {
4050 out[i++]= ((c >> bits) & 0x3F) | 0x80;
4051 }
4052 out[i] = 0;
4053
Daniel Veillard61b33d52001-04-24 13:55:12 +00004054 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
4055 ctxt->sax->characters(ctxt->userData, out, i);
4056 }
4057 } else {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004058 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
4059 ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1);
4060 return;
4061 }
Daniel Veillard61b33d52001-04-24 13:55:12 +00004062 if (name != NULL)
4063 xmlFree(name);
Daniel Veillardeae522a2001-04-23 13:41:34 +00004064 }
4065}
4066
4067/**
4068 * docbParseContent:
4069 * @ctxt: an SGML parser context
4070 * @name: the node name
4071 *
4072 * Parse a content: comment, sub-element, reference or text.
4073 *
4074 */
Daniel Veillardeae522a2001-04-23 13:41:34 +00004075static void
Daniel Veillard84666b32001-06-11 17:31:08 +00004076docbParseContent(docbParserCtxtPtr ctxt)
4077{
Daniel Veillardeae522a2001-04-23 13:41:34 +00004078 xmlChar *currentNode;
4079 int depth;
4080
4081 currentNode = xmlStrdup(ctxt->name);
4082 depth = ctxt->nameNr;
4083 while (1) {
Daniel Veillard84666b32001-06-11 17:31:08 +00004084 long cons = ctxt->nbChars;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004085
4086 GROW;
Daniel Veillard84666b32001-06-11 17:31:08 +00004087 /*
4088 * Our tag or one of it's parent or children is ending.
4089 */
Daniel Veillardeae522a2001-04-23 13:41:34 +00004090 if ((CUR == '<') && (NXT(1) == '/')) {
Daniel Veillard84666b32001-06-11 17:31:08 +00004091 docbParseEndTag(ctxt);
4092 if (currentNode != NULL)
4093 xmlFree(currentNode);
4094 return;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004095 }
4096
Daniel Veillard84666b32001-06-11 17:31:08 +00004097 /*
4098 * Has this node been popped out during parsing of
4099 * the next element
4100 */
Daniel Veillardeae522a2001-04-23 13:41:34 +00004101 if ((!xmlStrEqual(currentNode, ctxt->name)) &&
Daniel Veillard84666b32001-06-11 17:31:08 +00004102 (depth >= ctxt->nameNr)) {
4103 if (currentNode != NULL)
4104 xmlFree(currentNode);
4105 return;
4106 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004107
Daniel Veillard84666b32001-06-11 17:31:08 +00004108 /*
4109 * Sometimes DOCTYPE arrives in the middle of the document
4110 */
4111 if ((CUR == '<') && (NXT(1) == '!') &&
4112 (UPP(2) == 'D') && (UPP(3) == 'O') &&
4113 (UPP(4) == 'C') && (UPP(5) == 'T') &&
4114 (UPP(6) == 'Y') && (UPP(7) == 'P') && (UPP(8) == 'E')) {
4115 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4116 ctxt->sax->error(ctxt->userData,
4117 "Misplaced DOCTYPE declaration\n");
4118 ctxt->wellFormed = 0;
4119 docbParseDocTypeDecl(ctxt);
4120 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004121
Daniel Veillard84666b32001-06-11 17:31:08 +00004122 /*
4123 * First case : a comment
4124 */
4125 if ((CUR == '<') && (NXT(1) == '!') &&
4126 (NXT(2) == '-') && (NXT(3) == '-')) {
4127 docbParseComment(ctxt);
4128 }
4129
4130 /*
4131 * Second case : a PI
4132 */
4133 else if ((RAW == '<') && (NXT(1) == '?')) {
4134 docbParsePI(ctxt);
4135 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004136
Daniel Veillard84666b32001-06-11 17:31:08 +00004137 /*
4138 * Third case : a sub-element.
4139 */
4140 else if (CUR == '<') {
4141 docbParseElement(ctxt);
4142 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004143
Daniel Veillard84666b32001-06-11 17:31:08 +00004144 /*
4145 * Fourth case : a reference. If if has not been resolved,
4146 * parsing returns it's Name, create the node
4147 */
4148 else if (CUR == '&') {
4149 docbParseReference(ctxt);
4150 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004151
Daniel Veillard84666b32001-06-11 17:31:08 +00004152 /*
4153 * Fifth : end of the resource
4154 */
4155 else if (CUR == 0) {
4156 docbAutoClose(ctxt, NULL);
4157 if (ctxt->nameNr == 0)
4158 break;
4159 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004160
Daniel Veillard84666b32001-06-11 17:31:08 +00004161 /*
4162 * Last case, text. Note that References are handled directly.
4163 */
4164 else {
4165 docbParseCharData(ctxt);
4166 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004167
Daniel Veillard84666b32001-06-11 17:31:08 +00004168 if (cons == ctxt->nbChars) {
4169 if (ctxt->node != NULL) {
4170 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4171 ctxt->sax->error(ctxt->userData,
4172 "detected an error in element content\n");
4173 ctxt->wellFormed = 0;
4174 }
4175 break;
4176 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00004177
4178 GROW;
4179 }
Daniel Veillard84666b32001-06-11 17:31:08 +00004180 if (currentNode != NULL)
4181 xmlFree(currentNode);
Daniel Veillardeae522a2001-04-23 13:41:34 +00004182}
4183
4184/**
4185 * docbParseElement:
4186 * @ctxt: an SGML parser context
4187 *
4188 * parse an SGML element, this is highly recursive
4189 *
4190 * [39] element ::= EmptyElemTag | STag content ETag
4191 *
4192 * [41] Attribute ::= Name Eq AttValue
4193 */
4194
4195static void
4196docbParseElement(docbParserCtxtPtr ctxt) {
4197 xmlChar *name;
4198 xmlChar *currentNode = NULL;
4199 docbElemDescPtr info;
4200 docbParserNodeInfo node_info;
4201 xmlChar *oldname;
4202 int depth = ctxt->nameNr;
4203
4204 /* Capture start position */
4205 if (ctxt->record_info) {
4206 node_info.begin_pos = ctxt->input->consumed +
4207 (CUR_PTR - ctxt->input->base);
4208 node_info.begin_line = ctxt->input->line;
4209 }
4210
4211 oldname = xmlStrdup(ctxt->name);
4212 docbParseStartTag(ctxt);
4213 name = ctxt->name;
4214#ifdef DEBUG
4215 if (oldname == NULL)
4216 xmlGenericError(xmlGenericErrorContext,
4217 "Start of element %s\n", name);
4218 else if (name == NULL)
4219 xmlGenericError(xmlGenericErrorContext,
4220 "Start of element failed, was %s\n", oldname);
4221 else
4222 xmlGenericError(xmlGenericErrorContext,
4223 "Start of element %s, was %s\n", name, oldname);
4224#endif
4225 if (((depth == ctxt->nameNr) && (xmlStrEqual(oldname, ctxt->name))) ||
4226 (name == NULL)) {
4227 if (CUR == '>')
4228 NEXT;
4229 if (oldname != NULL)
4230 xmlFree(oldname);
4231 return;
4232 }
4233 if (oldname != NULL)
4234 xmlFree(oldname);
4235
4236 /*
4237 * Lookup the info for that element.
4238 */
4239 info = docbTagLookup(name);
4240 if (info == NULL) {
4241 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4242 ctxt->sax->error(ctxt->userData, "Tag %s unknown\n",
4243 name);
4244 ctxt->wellFormed = 0;
4245 } else if (info->depr) {
4246/***************************
4247 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
4248 ctxt->sax->warning(ctxt->userData, "Tag %s is deprecated\n",
4249 name);
4250 ***************************/
4251 }
4252
4253 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00004254 * Check for an Empty Element labeled the XML/SGML way
Daniel Veillardeae522a2001-04-23 13:41:34 +00004255 */
4256 if ((CUR == '/') && (NXT(1) == '>')) {
4257 SKIP(2);
4258 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
4259 ctxt->sax->endElement(ctxt->userData, name);
4260 oldname = docbnamePop(ctxt);
4261#ifdef DEBUG
4262 xmlGenericError(xmlGenericErrorContext,"End of tag the XML way: popping out %s\n", oldname);
4263#endif
4264 if (oldname != NULL)
4265 xmlFree(oldname);
4266 return;
4267 }
4268
4269 if (CUR == '>') {
4270 NEXT;
4271 } else {
4272 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4273 ctxt->sax->error(ctxt->userData,
4274 "Couldn't find end of Start Tag %s\n",
4275 name);
4276 ctxt->wellFormed = 0;
4277
4278 /*
4279 * end of parsing of this node.
4280 */
4281 if (xmlStrEqual(name, ctxt->name)) {
4282 nodePop(ctxt);
4283 oldname = docbnamePop(ctxt);
4284#ifdef DEBUG
4285 xmlGenericError(xmlGenericErrorContext,"End of start tag problem: popping out %s\n", oldname);
4286#endif
4287 if (oldname != NULL)
4288 xmlFree(oldname);
4289 }
4290
4291 /*
4292 * Capture end position and add node
4293 */
4294 if ( currentNode != NULL && ctxt->record_info ) {
4295 node_info.end_pos = ctxt->input->consumed +
4296 (CUR_PTR - ctxt->input->base);
4297 node_info.end_line = ctxt->input->line;
4298 node_info.node = ctxt->node;
4299 xmlParserAddNodeInfo(ctxt, &node_info);
4300 }
4301 return;
4302 }
4303
4304 /*
4305 * Check for an Empty Element from DTD definition
4306 */
4307 if ((info != NULL) && (info->empty)) {
4308 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
4309 ctxt->sax->endElement(ctxt->userData, name);
4310 oldname = docbnamePop(ctxt);
4311#ifdef DEBUG
4312 xmlGenericError(xmlGenericErrorContext,"End of empty tag %s : popping out %s\n", name, oldname);
4313#endif
4314 if (oldname != NULL)
4315 xmlFree(oldname);
4316 return;
4317 }
4318
4319 /*
4320 * Parse the content of the element:
4321 */
4322 currentNode = xmlStrdup(ctxt->name);
4323 depth = ctxt->nameNr;
Daniel Veillard34ba3872003-07-15 13:34:05 +00004324 while (IS_CHAR((unsigned int) CUR)) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004325 docbParseContent(ctxt);
4326 if (ctxt->nameNr < depth) break;
4327 }
4328
Daniel Veillard34ba3872003-07-15 13:34:05 +00004329 if (!IS_CHAR((unsigned int) CUR)) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004330 /************
4331 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4332 ctxt->sax->error(ctxt->userData,
4333 "Premature end of data in tag %s\n", currentNode);
4334 ctxt->wellFormed = 0;
4335 *************/
4336
4337 /*
4338 * end of parsing of this node.
4339 */
4340 nodePop(ctxt);
4341 oldname = docbnamePop(ctxt);
4342#ifdef DEBUG
4343 xmlGenericError(xmlGenericErrorContext,"Premature end of tag %s : popping out %s\n", name, oldname);
4344#endif
4345 if (oldname != NULL)
4346 xmlFree(oldname);
4347 if (currentNode != NULL)
4348 xmlFree(currentNode);
4349 return;
4350 }
4351
4352 /*
4353 * Capture end position and add node
4354 */
4355 if ( currentNode != NULL && ctxt->record_info ) {
4356 node_info.end_pos = ctxt->input->consumed +
4357 (CUR_PTR - ctxt->input->base);
4358 node_info.end_line = ctxt->input->line;
4359 node_info.node = ctxt->node;
4360 xmlParserAddNodeInfo(ctxt, &node_info);
4361 }
4362 if (currentNode != NULL)
4363 xmlFree(currentNode);
4364}
4365
4366/**
4367 * docbParseEntityDecl:
4368 * @ctxt: an SGML parser context
4369 *
4370 * parse <!ENTITY declarations
4371 *
4372 */
4373
4374static void
4375docbParseEntityDecl(xmlParserCtxtPtr ctxt) {
4376 xmlChar *name = NULL;
4377 xmlChar *value = NULL;
4378 xmlChar *URI = NULL, *literal = NULL;
4379 xmlChar *ndata = NULL;
4380 int isParameter = 0;
4381 xmlChar *orig = NULL;
4382
4383 GROW;
4384 if ((RAW == '<') && (NXT(1) == '!') &&
Daniel Veillard61b33d52001-04-24 13:55:12 +00004385 (UPP(2) == 'E') && (UPP(3) == 'N') &&
4386 (UPP(4) == 'T') && (UPP(5) == 'I') &&
4387 (UPP(6) == 'T') && (UPP(7) == 'Y')) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004388 xmlParserInputPtr input = ctxt->input;
4389 ctxt->instate = XML_PARSER_ENTITY_DECL;
4390 SHRINK;
4391 SKIP(8);
4392 if (!IS_BLANK(CUR)) {
4393 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4394 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4395 ctxt->sax->error(ctxt->userData,
4396 "Space required after '<!ENTITY'\n");
4397 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004398 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004399 }
4400 SKIP_BLANKS;
4401
4402 if (RAW == '%') {
4403 NEXT;
4404 if (!IS_BLANK(CUR)) {
4405 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4406 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4407 ctxt->sax->error(ctxt->userData,
4408 "Space required after '%'\n");
4409 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004410 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004411 }
4412 SKIP_BLANKS;
4413 isParameter = 1;
4414 }
4415
4416 name = xmlParseName(ctxt);
4417 if (name == NULL) {
4418 ctxt->errNo = XML_ERR_NAME_REQUIRED;
4419 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4420 ctxt->sax->error(ctxt->userData, "sgmlarseEntityDecl: no name\n");
4421 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004422 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004423 return;
4424 }
4425 if (!IS_BLANK(CUR)) {
4426 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4427 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4428 ctxt->sax->error(ctxt->userData,
4429 "Space required after the entity name\n");
4430 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004431 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004432 }
4433 SKIP_BLANKS;
4434
4435 /*
4436 * handle the various case of definitions...
4437 */
4438 if (isParameter) {
4439 if ((RAW == '"') || (RAW == '\'')) {
4440 value = xmlParseEntityValue(ctxt, &orig);
4441 if (value) {
4442 if ((ctxt->sax != NULL) &&
4443 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4444 ctxt->sax->entityDecl(ctxt->userData, name,
4445 XML_INTERNAL_PARAMETER_ENTITY,
4446 NULL, NULL, value);
4447 }
4448 } else {
4449 URI = xmlParseExternalID(ctxt, &literal, 1);
4450 if ((URI == NULL) && (literal == NULL)) {
4451 ctxt->errNo = XML_ERR_VALUE_REQUIRED;
4452 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4453 ctxt->sax->error(ctxt->userData,
4454 "Entity value required\n");
4455 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004456 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004457 }
4458 if (URI) {
4459 xmlURIPtr uri;
4460
4461 uri = xmlParseURI((const char *) URI);
4462 if (uri == NULL) {
4463 ctxt->errNo = XML_ERR_INVALID_URI;
4464 if ((ctxt->sax != NULL) &&
4465 (!ctxt->disableSAX) &&
4466 (ctxt->sax->error != NULL))
4467 ctxt->sax->error(ctxt->userData,
4468 "Invalid URI: %s\n", URI);
4469 ctxt->wellFormed = 0;
4470 } else {
4471 if (uri->fragment != NULL) {
4472 ctxt->errNo = XML_ERR_URI_FRAGMENT;
4473 if ((ctxt->sax != NULL) &&
4474 (!ctxt->disableSAX) &&
4475 (ctxt->sax->error != NULL))
4476 ctxt->sax->error(ctxt->userData,
4477 "Fragment not allowed: %s\n", URI);
4478 ctxt->wellFormed = 0;
4479 } else {
4480 if ((ctxt->sax != NULL) &&
4481 (!ctxt->disableSAX) &&
4482 (ctxt->sax->entityDecl != NULL))
4483 ctxt->sax->entityDecl(ctxt->userData, name,
4484 XML_EXTERNAL_PARAMETER_ENTITY,
4485 literal, URI, NULL);
4486 }
4487 xmlFreeURI(uri);
4488 }
4489 }
4490 }
4491 } else {
4492 if ((RAW == '"') || (RAW == '\'')) {
4493 value = xmlParseEntityValue(ctxt, &orig);
4494 if ((ctxt->sax != NULL) &&
4495 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4496 ctxt->sax->entityDecl(ctxt->userData, name,
4497 XML_INTERNAL_GENERAL_ENTITY,
4498 NULL, NULL, value);
4499 } else {
4500 URI = xmlParseExternalID(ctxt, &literal, 1);
4501 if ((URI == NULL) && (literal == NULL)) {
4502 ctxt->errNo = XML_ERR_VALUE_REQUIRED;
4503 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4504 ctxt->sax->error(ctxt->userData,
4505 "Entity value required\n");
4506 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004507 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004508 }
4509 if (URI) {
4510 xmlURIPtr uri;
4511
4512 uri = xmlParseURI((const char *)URI);
4513 if (uri == NULL) {
4514 ctxt->errNo = XML_ERR_INVALID_URI;
4515 if ((ctxt->sax != NULL) &&
4516 (!ctxt->disableSAX) &&
4517 (ctxt->sax->error != NULL))
4518 ctxt->sax->error(ctxt->userData,
4519 "Invalid URI: %s\n", URI);
4520 ctxt->wellFormed = 0;
4521 } else {
4522 if (uri->fragment != NULL) {
4523 ctxt->errNo = XML_ERR_URI_FRAGMENT;
4524 if ((ctxt->sax != NULL) &&
4525 (!ctxt->disableSAX) &&
4526 (ctxt->sax->error != NULL))
4527 ctxt->sax->error(ctxt->userData,
4528 "Fragment not allowed: %s\n", URI);
4529 ctxt->wellFormed = 0;
4530 }
4531 xmlFreeURI(uri);
4532 }
4533 }
4534 if ((RAW != '>') && (!IS_BLANK(CUR))) {
4535 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4536 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4537 ctxt->sax->error(ctxt->userData,
4538 "Space required before content model\n");
4539 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004540 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004541 }
4542 SKIP_BLANKS;
4543
4544 /*
4545 * SGML specific: here we can get the content model
4546 */
4547 if (RAW != '>') {
4548 xmlChar *contmod;
4549
4550 contmod = xmlParseName(ctxt);
4551
4552 if (contmod == NULL) {
4553 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4554 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4555 ctxt->sax->error(ctxt->userData,
4556 "Could not parse entity content model\n");
4557 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004558 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004559 } else {
4560 if (xmlStrEqual(contmod, BAD_CAST"NDATA")) {
4561 if (!IS_BLANK(CUR)) {
4562 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4563 if ((ctxt->sax != NULL) &&
4564 (ctxt->sax->error != NULL))
4565 ctxt->sax->error(ctxt->userData,
4566 "Space required after 'NDATA'\n");
4567 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004568 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004569 }
4570 SKIP_BLANKS;
4571 ndata = xmlParseName(ctxt);
4572 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
4573 (ctxt->sax->unparsedEntityDecl != NULL)) {
4574 ctxt->sax->unparsedEntityDecl(ctxt->userData,
4575 name, literal, URI, ndata);
4576 }
4577 } else if (xmlStrEqual(contmod, BAD_CAST"SUBDOC")) {
4578 if ((ctxt->sax != NULL) &&
4579 (ctxt->sax->warning != NULL))
4580 ctxt->sax->warning(ctxt->userData,
4581 "SUBDOC entities are not supported\n");
4582 SKIP_BLANKS;
4583 ndata = xmlParseName(ctxt);
4584 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
4585 (ctxt->sax->unparsedEntityDecl != NULL)) {
4586 ctxt->sax->unparsedEntityDecl(ctxt->userData,
4587 name, literal, URI, ndata);
4588 }
4589 } else if (xmlStrEqual(contmod, BAD_CAST"CDATA")) {
4590 if ((ctxt->sax != NULL) &&
4591 (ctxt->sax->warning != NULL))
4592 ctxt->sax->warning(ctxt->userData,
4593 "CDATA entities are not supported\n");
4594 SKIP_BLANKS;
4595 ndata = xmlParseName(ctxt);
4596 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
4597 (ctxt->sax->unparsedEntityDecl != NULL)) {
4598 ctxt->sax->unparsedEntityDecl(ctxt->userData,
4599 name, literal, URI, ndata);
4600 }
4601 }
4602 xmlFree(contmod);
4603 }
4604 } else {
4605 if ((ctxt->sax != NULL) &&
4606 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4607 ctxt->sax->entityDecl(ctxt->userData, name,
4608 XML_EXTERNAL_GENERAL_PARSED_ENTITY,
4609 literal, URI, NULL);
4610 }
4611 }
4612 }
4613 SKIP_BLANKS;
4614 if (RAW != '>') {
4615 ctxt->errNo = XML_ERR_ENTITY_NOT_FINISHED;
4616 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4617 ctxt->sax->error(ctxt->userData,
4618 "docbParseEntityDecl: entity %s not terminated\n", name);
4619 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004620 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004621 } else {
4622 if (input != ctxt->input) {
4623 ctxt->errNo = XML_ERR_ENTITY_BOUNDARY;
4624 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4625 ctxt->sax->error(ctxt->userData,
4626"Entity declaration doesn't start and stop in the same entity\n");
4627 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004628 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004629 }
4630 NEXT;
4631 }
4632 if (orig != NULL) {
4633 /*
4634 * Ugly mechanism to save the raw entity value.
4635 */
4636 xmlEntityPtr cur = NULL;
4637
4638 if (isParameter) {
4639 if ((ctxt->sax != NULL) &&
4640 (ctxt->sax->getParameterEntity != NULL))
4641 cur = ctxt->sax->getParameterEntity(ctxt->userData, name);
4642 } else {
4643 if ((ctxt->sax != NULL) &&
4644 (ctxt->sax->getEntity != NULL))
4645 cur = ctxt->sax->getEntity(ctxt->userData, name);
4646 }
4647 if (cur != NULL) {
4648 if (cur->orig != NULL)
4649 xmlFree(orig);
4650 else
4651 cur->orig = orig;
4652 } else
4653 xmlFree(orig);
4654 }
4655 if (name != NULL) xmlFree(name);
4656 if (value != NULL) xmlFree(value);
4657 if (URI != NULL) xmlFree(URI);
4658 if (literal != NULL) xmlFree(literal);
4659 if (ndata != NULL) xmlFree(ndata);
4660 }
4661}
4662
4663/**
4664 * docbParseMarkupDecl:
4665 * @ctxt: an SGML parser context
4666 *
4667 * parse Markup declarations
4668 *
4669 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
4670 * NotationDecl | PI | Comment
4671 */
4672static void
4673docbParseMarkupDecl(xmlParserCtxtPtr ctxt) {
4674 GROW;
4675 xmlParseElementDecl(ctxt);
4676 xmlParseAttributeListDecl(ctxt);
4677 docbParseEntityDecl(ctxt);
4678 xmlParseNotationDecl(ctxt);
Daniel Veillarde95e2392001-06-06 10:46:28 +00004679 docbParsePI(ctxt);
Daniel Veillardeae522a2001-04-23 13:41:34 +00004680 xmlParseComment(ctxt);
4681 /*
4682 * This is only for internal subset. On external entities,
4683 * the replacement is done before parsing stage
4684 */
4685 if ((ctxt->external == 0) && (ctxt->inputNr == 1))
4686 xmlParsePEReference(ctxt);
4687 ctxt->instate = XML_PARSER_DTD;
4688}
4689
4690/**
Daniel Veillardcbaf3992001-12-31 16:16:02 +00004691 * docbParseInternalSubset:
Daniel Veillardeae522a2001-04-23 13:41:34 +00004692 * @ctxt: an SGML parser context
4693 *
4694 * parse the internal subset declaration
4695 *
4696 * [28 end] ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
4697 */
4698
4699static void
4700docbParseInternalSubset(xmlParserCtxtPtr ctxt) {
4701 /*
4702 * Is there any DTD definition ?
4703 */
4704 if (RAW == '[') {
4705 ctxt->instate = XML_PARSER_DTD;
4706 NEXT;
4707 /*
4708 * Parse the succession of Markup declarations and
4709 * PEReferences.
4710 * Subsequence (markupdecl | PEReference | S)*
4711 */
4712 while (RAW != ']') {
4713 const xmlChar *check = CUR_PTR;
Daniel Veillard3e59fc52003-04-18 12:34:58 +00004714 unsigned int cons = ctxt->input->consumed;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004715
4716 SKIP_BLANKS;
4717 docbParseMarkupDecl(ctxt);
4718 xmlParsePEReference(ctxt);
4719
4720 /*
4721 * Pop-up of finished entities.
4722 */
4723 while ((RAW == 0) && (ctxt->inputNr > 1))
4724 xmlPopInput(ctxt);
4725
4726 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
4727 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
4728 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4729 ctxt->sax->error(ctxt->userData,
4730 "docbParseInternalSubset: error detected in Markup declaration\n");
4731 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004732 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004733 break;
4734 }
4735 }
4736 if (RAW == ']') {
4737 NEXT;
4738 SKIP_BLANKS;
4739 }
4740 }
4741
4742 /*
4743 * We should be at the end of the DOCTYPE declaration.
4744 */
4745 if (RAW != '>') {
4746 ctxt->errNo = XML_ERR_DOCTYPE_NOT_FINISHED;
4747 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
Daniel Veillardf6ed8bc2001-10-02 09:22:47 +00004748 ctxt->sax->error(ctxt->userData, "DOCTYPE improperly terminated\n");
Daniel Veillardeae522a2001-04-23 13:41:34 +00004749 ctxt->wellFormed = 0;
Daniel Veillarddad3f682002-11-17 16:47:27 +00004750 if (ctxt->recovery == 0) ctxt->disableSAX = 1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004751 }
4752 NEXT;
4753}
4754
4755/**
4756 * docbParseMisc:
4757 * @ctxt: an XML parser context
4758 *
Daniel Veillardcbaf3992001-12-31 16:16:02 +00004759 * parse an XML Misc* optional field.
Daniel Veillardeae522a2001-04-23 13:41:34 +00004760 *
4761 * [27] Misc ::= Comment | PI | S
4762 */
4763
4764static void
4765docbParseMisc(xmlParserCtxtPtr ctxt) {
4766 while (((RAW == '<') && (NXT(1) == '?')) ||
4767 ((RAW == '<') && (NXT(1) == '!') &&
4768 (NXT(2) == '-') && (NXT(3) == '-')) ||
4769 IS_BLANK(CUR)) {
4770 if ((RAW == '<') && (NXT(1) == '?')) {
Daniel Veillard84666b32001-06-11 17:31:08 +00004771 docbParsePI(ctxt);
4772 } else if (IS_BLANK(CUR)) {
4773 NEXT;
4774 } else
4775 xmlParseComment(ctxt);
Daniel Veillardeae522a2001-04-23 13:41:34 +00004776 }
4777}
4778
4779/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00004780 * docbParseDocument:
Daniel Veillardeae522a2001-04-23 13:41:34 +00004781 * @ctxt: an SGML parser context
4782 *
4783 * parse an SGML document (and build a tree if using the standard SAX
4784 * interface).
4785 *
4786 * Returns 0, -1 in case of error. the parser context is augmented
4787 * as a result of the parsing.
4788 */
4789
4790int
4791docbParseDocument(docbParserCtxtPtr ctxt) {
4792 xmlChar start[4];
4793 xmlCharEncoding enc;
4794 xmlDtdPtr dtd;
4795
4796 docbDefaultSAXHandlerInit();
4797 ctxt->html = 2;
4798
4799 GROW;
4800 /*
4801 * SAX: beginning of the document processing.
4802 */
4803 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
4804 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
4805
4806 /*
4807 * Get the 4 first bytes and decode the charset
4808 * if enc != XML_CHAR_ENCODING_NONE
4809 * plug some encoding conversion routines.
4810 */
4811 start[0] = RAW;
4812 start[1] = NXT(1);
4813 start[2] = NXT(2);
4814 start[3] = NXT(3);
4815 enc = xmlDetectCharEncoding(start, 4);
4816 if (enc != XML_CHAR_ENCODING_NONE) {
4817 xmlSwitchEncoding(ctxt, enc);
4818 }
4819
4820 /*
4821 * Wipe out everything which is before the first '<'
4822 */
4823 SKIP_BLANKS;
4824 if (CUR == 0) {
4825 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4826 ctxt->sax->error(ctxt->userData, "Document is empty\n");
4827 ctxt->wellFormed = 0;
4828 }
4829
4830 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
4831 ctxt->sax->startDocument(ctxt->userData);
4832
4833
4834 /*
4835 * The Misc part of the Prolog
4836 */
4837 GROW;
4838 docbParseMisc(ctxt);
4839
4840 /*
4841 * Then possibly doc type declaration(s) and more Misc
4842 * (doctypedecl Misc*)?
4843 */
4844 GROW;
4845 if ((RAW == '<') && (NXT(1) == '!') &&
Daniel Veillard61b33d52001-04-24 13:55:12 +00004846 (UPP(2) == 'D') && (UPP(3) == 'O') &&
4847 (UPP(4) == 'C') && (UPP(5) == 'T') &&
4848 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
4849 (UPP(8) == 'E')) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004850
4851 ctxt->inSubset = 1;
4852 docbParseDocTypeDecl(ctxt);
4853 if (RAW == '[') {
4854 ctxt->instate = XML_PARSER_DTD;
4855 docbParseInternalSubset(ctxt);
4856 }
4857
4858 /*
4859 * Create and update the external subset.
4860 */
4861 ctxt->inSubset = 2;
4862 if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) &&
4863 (!ctxt->disableSAX))
4864 ctxt->sax->internalSubset(ctxt->userData, ctxt->intSubName,
4865 ctxt->extSubSystem, ctxt->extSubURI);
4866 ctxt->inSubset = 0;
4867
4868
4869 ctxt->instate = XML_PARSER_PROLOG;
4870 docbParseMisc(ctxt);
4871 }
4872
4873 /*
4874 * Time to start parsing the tree itself
4875 */
4876 docbParseContent(ctxt);
4877
4878 /*
4879 * autoclose
4880 */
4881 if (CUR == 0)
4882 docbAutoClose(ctxt, NULL);
4883
4884
4885 /*
4886 * SAX: end of the document processing.
4887 */
4888 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
4889 ctxt->sax->endDocument(ctxt->userData);
4890
4891 if (ctxt->myDoc != NULL) {
4892 dtd = ctxt->myDoc->intSubset;
Daniel Veillarde95e2392001-06-06 10:46:28 +00004893 ctxt->myDoc->standalone = -1;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004894 if (dtd == NULL)
4895 ctxt->myDoc->intSubset =
4896 xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "SGML",
4897 BAD_CAST "-//W3C//DTD SGML 4.0 Transitional//EN",
4898 BAD_CAST "http://www.w3.org/TR/REC-docbook/loose.dtd");
4899 }
4900 if (! ctxt->wellFormed) return(-1);
4901 return(0);
4902}
4903
4904
4905/************************************************************************
4906 * *
4907 * Parser contexts handling *
4908 * *
4909 ************************************************************************/
4910
4911/**
Daniel Veillard1034da22001-04-25 19:06:28 +00004912 * docbInitParserCtxt:
Daniel Veillardeae522a2001-04-23 13:41:34 +00004913 * @ctxt: an SGML parser context
4914 *
4915 * Initialize a parser context
4916 */
4917
4918static void
4919docbInitParserCtxt(docbParserCtxtPtr ctxt)
4920{
4921 docbSAXHandler *sax;
4922
4923 if (ctxt == NULL) return;
4924 memset(ctxt, 0, sizeof(docbParserCtxt));
4925
4926 sax = (docbSAXHandler *) xmlMalloc(sizeof(docbSAXHandler));
4927 if (sax == NULL) {
4928 xmlGenericError(xmlGenericErrorContext,
4929 "docbInitParserCtxt: out of memory\n");
4930 }
4931 memset(sax, 0, sizeof(docbSAXHandler));
4932
4933 /* Allocate the Input stack */
4934 ctxt->inputTab = (docbParserInputPtr *)
4935 xmlMalloc(5 * sizeof(docbParserInputPtr));
4936 if (ctxt->inputTab == NULL) {
4937 xmlGenericError(xmlGenericErrorContext,
4938 "docbInitParserCtxt: out of memory\n");
4939 }
4940 ctxt->inputNr = 0;
4941 ctxt->inputMax = 5;
4942 ctxt->input = NULL;
4943 ctxt->version = NULL;
4944 ctxt->encoding = NULL;
4945 ctxt->standalone = -1;
4946 ctxt->instate = XML_PARSER_START;
4947
4948 /* Allocate the Node stack */
4949 ctxt->nodeTab = (docbNodePtr *) xmlMalloc(10 * sizeof(docbNodePtr));
4950 ctxt->nodeNr = 0;
4951 ctxt->nodeMax = 10;
4952 ctxt->node = NULL;
4953
4954 /* Allocate the Name stack */
4955 ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
4956 ctxt->nameNr = 0;
4957 ctxt->nameMax = 10;
4958 ctxt->name = NULL;
4959
4960 if (sax == NULL) ctxt->sax = &docbDefaultSAXHandler;
4961 else {
4962 ctxt->sax = sax;
4963 memcpy(sax, &docbDefaultSAXHandler, sizeof(docbSAXHandler));
4964 }
4965 ctxt->userData = ctxt;
4966 ctxt->myDoc = NULL;
4967 ctxt->wellFormed = 1;
Daniel Veillard635ef722001-10-29 11:48:19 +00004968 ctxt->linenumbers = xmlLineNumbersDefaultValue;
Daniel Veillard61b33d52001-04-24 13:55:12 +00004969 ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004970 ctxt->html = 2;
4971 ctxt->record_info = 0;
4972 ctxt->validate = 0;
4973 ctxt->nbChars = 0;
4974 ctxt->checkIndex = 0;
4975 xmlInitNodeInfoSeq(&ctxt->node_seq);
4976}
4977
4978/**
4979 * docbFreeParserCtxt:
4980 * @ctxt: an SGML parser context
4981 *
4982 * Free all the memory used by a parser context. However the parsed
4983 * document in ctxt->myDoc is not freed.
4984 */
4985
4986void
4987docbFreeParserCtxt(docbParserCtxtPtr ctxt)
4988{
4989 xmlFreeParserCtxt(ctxt);
4990}
4991
4992/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00004993 * docbCreateDocParserCtxt:
Daniel Veillardeae522a2001-04-23 13:41:34 +00004994 * @cur: a pointer to an array of xmlChar
Daniel Veillard1034da22001-04-25 19:06:28 +00004995 * @encoding: the SGML document encoding, or NULL
Daniel Veillardeae522a2001-04-23 13:41:34 +00004996 *
4997 * Create a parser context for an SGML document.
4998 *
4999 * Returns the new parser context or NULL
5000 */
5001static docbParserCtxtPtr
Daniel Veillard1034da22001-04-25 19:06:28 +00005002docbCreateDocParserCtxt(xmlChar *cur, const char *encoding ATTRIBUTE_UNUSED) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00005003 docbParserCtxtPtr ctxt;
5004 docbParserInputPtr input;
5005 /* sgmlCharEncoding enc; */
5006
5007 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
5008 if (ctxt == NULL) {
Daniel Veillard3487c8d2002-09-05 11:33:25 +00005009 xmlGenericError(xmlGenericErrorContext, "malloc failed");
5010 return(NULL);
Daniel Veillardeae522a2001-04-23 13:41:34 +00005011 }
5012 docbInitParserCtxt(ctxt);
5013 input = (docbParserInputPtr) xmlMalloc(sizeof(docbParserInput));
5014 if (input == NULL) {
Daniel Veillard3487c8d2002-09-05 11:33:25 +00005015 xmlGenericError(xmlGenericErrorContext, "malloc failed");
5016 xmlFree(ctxt);
5017 return(NULL);
Daniel Veillardeae522a2001-04-23 13:41:34 +00005018 }
5019 memset(input, 0, sizeof(docbParserInput));
5020
5021 input->line = 1;
5022 input->col = 1;
5023 input->base = cur;
5024 input->cur = cur;
5025
5026 inputPush(ctxt, input);
5027 return(ctxt);
5028}
5029
5030/************************************************************************
5031 * *
5032 * Progressive parsing interfaces *
5033 * *
5034 ************************************************************************/
5035
5036/**
5037 * docbParseLookupSequence:
5038 * @ctxt: an SGML parser context
5039 * @first: the first char to lookup
5040 * @next: the next char to lookup or zero
5041 * @third: the next char to lookup or zero
5042 *
5043 * Try to find if a sequence (first, next, third) or just (first next) or
5044 * (first) is available in the input stream.
5045 * This function has a side effect of (possibly) incrementing ctxt->checkIndex
5046 * to avoid rescanning sequences of bytes, it DOES change the state of the
5047 * parser, do not use liberally.
5048 * This is basically similar to xmlParseLookupSequence()
5049 *
5050 * Returns the index to the current parsing point if the full sequence
5051 * is available, -1 otherwise.
5052 */
5053static int
5054docbParseLookupSequence(docbParserCtxtPtr ctxt, xmlChar first,
5055 xmlChar next, xmlChar third) {
5056 int base, len;
5057 docbParserInputPtr in;
5058 const xmlChar *buf;
5059
5060 in = ctxt->input;
5061 if (in == NULL) return(-1);
5062 base = in->cur - in->base;
5063 if (base < 0) return(-1);
5064 if (ctxt->checkIndex > base)
5065 base = ctxt->checkIndex;
5066 if (in->buf == NULL) {
5067 buf = in->base;
5068 len = in->length;
5069 } else {
5070 buf = in->buf->buffer->content;
5071 len = in->buf->buffer->use;
5072 }
5073 /* take into account the sequence length */
5074 if (third) len -= 2;
5075 else if (next) len --;
5076 for (;base < len;base++) {
5077 if (buf[base] == first) {
5078 if (third != 0) {
5079 if ((buf[base + 1] != next) ||
5080 (buf[base + 2] != third)) continue;
5081 } else if (next != 0) {
5082 if (buf[base + 1] != next) continue;
5083 }
5084 ctxt->checkIndex = 0;
5085#ifdef DEBUG_PUSH
5086 if (next == 0)
5087 xmlGenericError(xmlGenericErrorContext,
5088 "HPP: lookup '%c' found at %d\n",
5089 first, base);
5090 else if (third == 0)
5091 xmlGenericError(xmlGenericErrorContext,
5092 "HPP: lookup '%c%c' found at %d\n",
5093 first, next, base);
5094 else
5095 xmlGenericError(xmlGenericErrorContext,
5096 "HPP: lookup '%c%c%c' found at %d\n",
5097 first, next, third, base);
5098#endif
5099 return(base - (in->cur - in->base));
5100 }
5101 }
5102 ctxt->checkIndex = base;
5103#ifdef DEBUG_PUSH
5104 if (next == 0)
5105 xmlGenericError(xmlGenericErrorContext,
5106 "HPP: lookup '%c' failed\n", first);
5107 else if (third == 0)
5108 xmlGenericError(xmlGenericErrorContext,
5109 "HPP: lookup '%c%c' failed\n", first, next);
5110 else
5111 xmlGenericError(xmlGenericErrorContext,
5112 "HPP: lookup '%c%c%c' failed\n", first, next, third);
5113#endif
5114 return(-1);
5115}
5116
5117/**
5118 * docbParseTryOrFinish:
5119 * @ctxt: an SGML parser context
5120 * @terminate: last chunk indicator
5121 *
5122 * Try to progress on parsing
5123 *
5124 * Returns zero if no parsing was possible
5125 */
5126static int
5127docbParseTryOrFinish(docbParserCtxtPtr ctxt, int terminate) {
5128 int ret = 0;
5129 docbParserInputPtr in;
5130 int avail = 0;
5131 xmlChar cur, next;
5132
5133#ifdef DEBUG_PUSH
5134 switch (ctxt->instate) {
5135 case XML_PARSER_EOF:
5136 xmlGenericError(xmlGenericErrorContext,
5137 "HPP: try EOF\n"); break;
5138 case XML_PARSER_START:
5139 xmlGenericError(xmlGenericErrorContext,
5140 "HPP: try START\n"); break;
5141 case XML_PARSER_MISC:
5142 xmlGenericError(xmlGenericErrorContext,
5143 "HPP: try MISC\n");break;
5144 case XML_PARSER_COMMENT:
5145 xmlGenericError(xmlGenericErrorContext,
5146 "HPP: try COMMENT\n");break;
5147 case XML_PARSER_PROLOG:
5148 xmlGenericError(xmlGenericErrorContext,
5149 "HPP: try PROLOG\n");break;
5150 case XML_PARSER_START_TAG:
5151 xmlGenericError(xmlGenericErrorContext,
5152 "HPP: try START_TAG\n");break;
5153 case XML_PARSER_CONTENT:
5154 xmlGenericError(xmlGenericErrorContext,
5155 "HPP: try CONTENT\n");break;
5156 case XML_PARSER_CDATA_SECTION:
5157 xmlGenericError(xmlGenericErrorContext,
5158 "HPP: try CDATA_SECTION\n");break;
5159 case XML_PARSER_END_TAG:
5160 xmlGenericError(xmlGenericErrorContext,
5161 "HPP: try END_TAG\n");break;
5162 case XML_PARSER_ENTITY_DECL:
5163 xmlGenericError(xmlGenericErrorContext,
5164 "HPP: try ENTITY_DECL\n");break;
5165 case XML_PARSER_ENTITY_VALUE:
5166 xmlGenericError(xmlGenericErrorContext,
5167 "HPP: try ENTITY_VALUE\n");break;
5168 case XML_PARSER_ATTRIBUTE_VALUE:
5169 xmlGenericError(xmlGenericErrorContext,
5170 "HPP: try ATTRIBUTE_VALUE\n");break;
5171 case XML_PARSER_DTD:
5172 xmlGenericError(xmlGenericErrorContext,
5173 "HPP: try DTD\n");break;
5174 case XML_PARSER_EPILOG:
5175 xmlGenericError(xmlGenericErrorContext,
5176 "HPP: try EPILOG\n");break;
5177 case XML_PARSER_PI:
5178 xmlGenericError(xmlGenericErrorContext,
5179 "HPP: try PI\n");break;
5180 }
5181#endif
5182
5183 while (1) {
5184
5185 in = ctxt->input;
5186 if (in == NULL) break;
5187 if (in->buf == NULL)
5188 avail = in->length - (in->cur - in->base);
5189 else
5190 avail = in->buf->buffer->use - (in->cur - in->base);
5191 if ((avail == 0) && (terminate)) {
5192 docbAutoClose(ctxt, NULL);
5193 if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
5194 /*
5195 * SAX: end of the document processing.
5196 */
5197 ctxt->instate = XML_PARSER_EOF;
5198 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5199 ctxt->sax->endDocument(ctxt->userData);
5200 }
5201 }
5202 if (avail < 1)
5203 goto done;
5204 switch (ctxt->instate) {
5205 case XML_PARSER_EOF:
5206 /*
5207 * Document parsing is done !
5208 */
5209 goto done;
5210 case XML_PARSER_START:
5211 /*
5212 * Very first chars read from the document flow.
5213 */
5214 cur = in->cur[0];
5215 if (IS_BLANK(cur)) {
5216 SKIP_BLANKS;
5217 if (in->buf == NULL)
5218 avail = in->length - (in->cur - in->base);
5219 else
5220 avail = in->buf->buffer->use - (in->cur - in->base);
5221 }
5222 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
5223 ctxt->sax->setDocumentLocator(ctxt->userData,
5224 &xmlDefaultSAXLocator);
5225 if ((ctxt->sax) && (ctxt->sax->startDocument) &&
5226 (!ctxt->disableSAX))
5227 ctxt->sax->startDocument(ctxt->userData);
5228
5229 cur = in->cur[0];
5230 next = in->cur[1];
5231 if ((cur == '<') && (next == '!') &&
5232 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5233 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5234 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5235 (UPP(8) == 'E')) {
5236 if ((!terminate) &&
5237 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5238 goto done;
5239#ifdef DEBUG_PUSH
5240 xmlGenericError(xmlGenericErrorContext,
5241 "HPP: Parsing internal subset\n");
5242#endif
5243 docbParseDocTypeDecl(ctxt);
5244 ctxt->instate = XML_PARSER_PROLOG;
5245#ifdef DEBUG_PUSH
5246 xmlGenericError(xmlGenericErrorContext,
5247 "HPP: entering PROLOG\n");
5248#endif
5249 } else {
5250 ctxt->instate = XML_PARSER_MISC;
5251 }
5252#ifdef DEBUG_PUSH
5253 xmlGenericError(xmlGenericErrorContext,
5254 "HPP: entering MISC\n");
5255#endif
5256 break;
5257 case XML_PARSER_MISC:
5258 SKIP_BLANKS;
5259 if (in->buf == NULL)
5260 avail = in->length - (in->cur - in->base);
5261 else
5262 avail = in->buf->buffer->use - (in->cur - in->base);
5263 if (avail < 2)
5264 goto done;
5265 cur = in->cur[0];
5266 next = in->cur[1];
5267 if ((cur == '<') && (next == '!') &&
5268 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5269 if ((!terminate) &&
5270 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5271 goto done;
5272#ifdef DEBUG_PUSH
5273 xmlGenericError(xmlGenericErrorContext,
5274 "HPP: Parsing Comment\n");
5275#endif
5276 docbParseComment(ctxt);
5277 ctxt->instate = XML_PARSER_MISC;
5278 } else if ((cur == '<') && (next == '!') &&
5279 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5280 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5281 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5282 (UPP(8) == 'E')) {
5283 if ((!terminate) &&
5284 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5285 goto done;
5286#ifdef DEBUG_PUSH
5287 xmlGenericError(xmlGenericErrorContext,
5288 "HPP: Parsing internal subset\n");
5289#endif
5290 docbParseDocTypeDecl(ctxt);
5291 ctxt->instate = XML_PARSER_PROLOG;
5292#ifdef DEBUG_PUSH
5293 xmlGenericError(xmlGenericErrorContext,
5294 "HPP: entering PROLOG\n");
5295#endif
5296 } else if ((cur == '<') && (next == '!') &&
5297 (avail < 9)) {
5298 goto done;
5299 } else {
5300 ctxt->instate = XML_PARSER_START_TAG;
5301#ifdef DEBUG_PUSH
5302 xmlGenericError(xmlGenericErrorContext,
5303 "HPP: entering START_TAG\n");
5304#endif
5305 }
5306 break;
5307 case XML_PARSER_PROLOG:
5308 SKIP_BLANKS;
5309 if (in->buf == NULL)
5310 avail = in->length - (in->cur - in->base);
5311 else
5312 avail = in->buf->buffer->use - (in->cur - in->base);
5313 if (avail < 2)
5314 goto done;
5315 cur = in->cur[0];
5316 next = in->cur[1];
5317 if ((cur == '<') && (next == '!') &&
5318 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5319 if ((!terminate) &&
5320 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5321 goto done;
5322#ifdef DEBUG_PUSH
5323 xmlGenericError(xmlGenericErrorContext,
5324 "HPP: Parsing Comment\n");
5325#endif
5326 docbParseComment(ctxt);
5327 ctxt->instate = XML_PARSER_PROLOG;
5328 } else if ((cur == '<') && (next == '!') &&
5329 (avail < 4)) {
5330 goto done;
5331 } else {
5332 ctxt->instate = XML_PARSER_START_TAG;
5333#ifdef DEBUG_PUSH
5334 xmlGenericError(xmlGenericErrorContext,
5335 "HPP: entering START_TAG\n");
5336#endif
5337 }
5338 break;
5339 case XML_PARSER_EPILOG:
5340 if (in->buf == NULL)
5341 avail = in->length - (in->cur - in->base);
5342 else
5343 avail = in->buf->buffer->use - (in->cur - in->base);
5344 if (avail < 1)
5345 goto done;
5346 cur = in->cur[0];
5347 if (IS_BLANK(cur)) {
5348 docbParseCharData(ctxt);
5349 goto done;
5350 }
5351 if (avail < 2)
5352 goto done;
5353 next = in->cur[1];
5354 if ((cur == '<') && (next == '!') &&
5355 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5356 if ((!terminate) &&
5357 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5358 goto done;
5359#ifdef DEBUG_PUSH
5360 xmlGenericError(xmlGenericErrorContext,
5361 "HPP: Parsing Comment\n");
5362#endif
5363 docbParseComment(ctxt);
5364 ctxt->instate = XML_PARSER_EPILOG;
5365 } else if ((cur == '<') && (next == '!') &&
5366 (avail < 4)) {
5367 goto done;
5368 } else {
5369 ctxt->errNo = XML_ERR_DOCUMENT_END;
5370 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5371 ctxt->sax->error(ctxt->userData,
5372 "Extra content at the end of the document\n");
5373 ctxt->wellFormed = 0;
5374 ctxt->instate = XML_PARSER_EOF;
5375#ifdef DEBUG_PUSH
5376 xmlGenericError(xmlGenericErrorContext,
5377 "HPP: entering EOF\n");
5378#endif
5379 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5380 ctxt->sax->endDocument(ctxt->userData);
5381 goto done;
5382 }
5383 break;
5384 case XML_PARSER_START_TAG: {
5385 xmlChar *name, *oldname;
5386 int depth = ctxt->nameNr;
5387 docbElemDescPtr info;
5388
5389 if (avail < 2)
5390 goto done;
5391 cur = in->cur[0];
5392 if (cur != '<') {
5393 ctxt->instate = XML_PARSER_CONTENT;
5394#ifdef DEBUG_PUSH
5395 xmlGenericError(xmlGenericErrorContext,
5396 "HPP: entering CONTENT\n");
5397#endif
5398 break;
5399 }
5400 if ((!terminate) &&
5401 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5402 goto done;
5403
5404 oldname = xmlStrdup(ctxt->name);
5405 docbParseStartTag(ctxt);
5406 name = ctxt->name;
5407#ifdef DEBUG
5408 if (oldname == NULL)
5409 xmlGenericError(xmlGenericErrorContext,
5410 "Start of element %s\n", name);
5411 else if (name == NULL)
5412 xmlGenericError(xmlGenericErrorContext,
5413 "Start of element failed, was %s\n",
5414 oldname);
5415 else
5416 xmlGenericError(xmlGenericErrorContext,
5417 "Start of element %s, was %s\n",
5418 name, oldname);
5419#endif
5420 if (((depth == ctxt->nameNr) &&
5421 (xmlStrEqual(oldname, ctxt->name))) ||
5422 (name == NULL)) {
5423 if (CUR == '>')
5424 NEXT;
5425 if (oldname != NULL)
5426 xmlFree(oldname);
5427 break;
5428 }
5429 if (oldname != NULL)
5430 xmlFree(oldname);
5431
5432 /*
5433 * Lookup the info for that element.
5434 */
5435 info = docbTagLookup(name);
5436 if (info == NULL) {
5437 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5438 ctxt->sax->error(ctxt->userData, "Tag %s unknown\n",
5439 name);
5440 ctxt->wellFormed = 0;
5441 } else if (info->depr) {
5442 /***************************
5443 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
5444 ctxt->sax->warning(ctxt->userData,
5445 "Tag %s is deprecated\n",
5446 name);
5447 ***************************/
5448 }
5449
5450 /*
Daniel Veillardcbaf3992001-12-31 16:16:02 +00005451 * Check for an Empty Element labeled the XML/SGML way
Daniel Veillardeae522a2001-04-23 13:41:34 +00005452 */
5453 if ((CUR == '/') && (NXT(1) == '>')) {
5454 SKIP(2);
5455 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
5456 ctxt->sax->endElement(ctxt->userData, name);
5457 oldname = docbnamePop(ctxt);
5458#ifdef DEBUG
5459 xmlGenericError(xmlGenericErrorContext,"End of tag the XML way: popping out %s\n",
5460 oldname);
5461#endif
5462 if (oldname != NULL)
5463 xmlFree(oldname);
5464 ctxt->instate = XML_PARSER_CONTENT;
5465#ifdef DEBUG_PUSH
5466 xmlGenericError(xmlGenericErrorContext,
5467 "HPP: entering CONTENT\n");
5468#endif
5469 break;
5470 }
5471
5472 if (CUR == '>') {
5473 NEXT;
5474 } else {
5475 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5476 ctxt->sax->error(ctxt->userData,
5477 "Couldn't find end of Start Tag %s\n",
5478 name);
5479 ctxt->wellFormed = 0;
5480
5481 /*
5482 * end of parsing of this node.
5483 */
5484 if (xmlStrEqual(name, ctxt->name)) {
5485 nodePop(ctxt);
5486 oldname = docbnamePop(ctxt);
5487#ifdef DEBUG
5488 xmlGenericError(xmlGenericErrorContext,
5489 "End of start tag problem: popping out %s\n", oldname);
5490#endif
5491 if (oldname != NULL)
5492 xmlFree(oldname);
5493 }
5494
5495 ctxt->instate = XML_PARSER_CONTENT;
5496#ifdef DEBUG_PUSH
5497 xmlGenericError(xmlGenericErrorContext,
5498 "HPP: entering CONTENT\n");
5499#endif
5500 break;
5501 }
5502
5503 /*
5504 * Check for an Empty Element from DTD definition
5505 */
5506 if ((info != NULL) && (info->empty)) {
5507 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
5508 ctxt->sax->endElement(ctxt->userData, name);
5509 oldname = docbnamePop(ctxt);
5510#ifdef DEBUG
5511 xmlGenericError(xmlGenericErrorContext,"End of empty tag %s : popping out %s\n", name, oldname);
5512#endif
5513 if (oldname != NULL)
5514 xmlFree(oldname);
5515 }
5516 ctxt->instate = XML_PARSER_CONTENT;
5517#ifdef DEBUG_PUSH
5518 xmlGenericError(xmlGenericErrorContext,
5519 "HPP: entering CONTENT\n");
5520#endif
5521 break;
5522 }
5523 case XML_PARSER_CONTENT: {
5524 long cons;
5525 /*
5526 * Handle preparsed entities and charRef
5527 */
5528 if (ctxt->token != 0) {
5529 xmlChar chr[2] = { 0 , 0 } ;
5530
5531 chr[0] = (xmlChar) ctxt->token;
Daniel Veillardeae522a2001-04-23 13:41:34 +00005532 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
5533 ctxt->sax->characters(ctxt->userData, chr, 1);
5534 ctxt->token = 0;
5535 ctxt->checkIndex = 0;
5536 }
5537 if ((avail == 1) && (terminate)) {
5538 cur = in->cur[0];
5539 if ((cur != '<') && (cur != '&')) {
5540 if (ctxt->sax != NULL) {
5541 if (IS_BLANK(cur)) {
5542 if (ctxt->sax->ignorableWhitespace != NULL)
5543 ctxt->sax->ignorableWhitespace(
5544 ctxt->userData, &cur, 1);
5545 } else {
Daniel Veillardeae522a2001-04-23 13:41:34 +00005546 if (ctxt->sax->characters != NULL)
5547 ctxt->sax->characters(
5548 ctxt->userData, &cur, 1);
5549 }
5550 }
5551 ctxt->token = 0;
5552 ctxt->checkIndex = 0;
5553 NEXT;
5554 }
5555 break;
5556 }
5557 if (avail < 2)
5558 goto done;
5559 cur = in->cur[0];
5560 next = in->cur[1];
5561 cons = ctxt->nbChars;
5562 /*
5563 * Sometimes DOCTYPE arrives in the middle of the document
5564 */
5565 if ((cur == '<') && (next == '!') &&
5566 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5567 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5568 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5569 (UPP(8) == 'E')) {
5570 if ((!terminate) &&
5571 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5572 goto done;
5573 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5574 ctxt->sax->error(ctxt->userData,
5575 "Misplaced DOCTYPE declaration\n");
5576 ctxt->wellFormed = 0;
5577 docbParseDocTypeDecl(ctxt);
5578 } else if ((cur == '<') && (next == '!') &&
5579 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5580 if ((!terminate) &&
5581 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5582 goto done;
5583#ifdef DEBUG_PUSH
5584 xmlGenericError(xmlGenericErrorContext,
5585 "HPP: Parsing Comment\n");
5586#endif
5587 docbParseComment(ctxt);
5588 ctxt->instate = XML_PARSER_CONTENT;
5589 } else if ((cur == '<') && (next == '!') && (avail < 4)) {
5590 goto done;
5591 } else if ((cur == '<') && (next == '/')) {
5592 ctxt->instate = XML_PARSER_END_TAG;
5593 ctxt->checkIndex = 0;
5594#ifdef DEBUG_PUSH
5595 xmlGenericError(xmlGenericErrorContext,
5596 "HPP: entering END_TAG\n");
5597#endif
5598 break;
5599 } else if (cur == '<') {
5600 ctxt->instate = XML_PARSER_START_TAG;
5601 ctxt->checkIndex = 0;
5602#ifdef DEBUG_PUSH
5603 xmlGenericError(xmlGenericErrorContext,
5604 "HPP: entering START_TAG\n");
5605#endif
5606 break;
5607 } else if (cur == '&') {
5608 if ((!terminate) &&
5609 (docbParseLookupSequence(ctxt, ';', 0, 0) < 0))
5610 goto done;
5611#ifdef DEBUG_PUSH
5612 xmlGenericError(xmlGenericErrorContext,
5613 "HPP: Parsing Reference\n");
5614#endif
5615 /* TODO: check generation of subtrees if noent !!! */
5616 docbParseReference(ctxt);
5617 } else {
5618 /* TODO Avoid the extra copy, handle directly !!!!!! */
5619 /*
Daniel Veillard01c13b52002-12-10 15:19:08 +00005620 * Goal of the following test is:
Daniel Veillardeae522a2001-04-23 13:41:34 +00005621 * - minimize calls to the SAX 'character' callback
5622 * when they are mergeable
5623 */
5624 if ((ctxt->inputNr == 1) &&
5625 (avail < DOCB_PARSER_BIG_BUFFER_SIZE)) {
5626 if ((!terminate) &&
5627 (docbParseLookupSequence(ctxt, '<', 0, 0) < 0))
5628 goto done;
5629 }
5630 ctxt->checkIndex = 0;
5631#ifdef DEBUG_PUSH
5632 xmlGenericError(xmlGenericErrorContext,
5633 "HPP: Parsing char data\n");
5634#endif
5635 docbParseCharData(ctxt);
5636 }
5637 if (cons == ctxt->nbChars) {
5638 if (ctxt->node != NULL) {
5639 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5640 ctxt->sax->error(ctxt->userData,
5641 "detected an error in element content\n");
5642 ctxt->wellFormed = 0;
5643 NEXT;
5644 }
5645 break;
5646 }
5647
5648 break;
5649 }
5650 case XML_PARSER_END_TAG:
5651 if (avail < 2)
5652 goto done;
5653 if ((!terminate) &&
5654 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5655 goto done;
5656 docbParseEndTag(ctxt);
5657 if (ctxt->nameNr == 0) {
5658 ctxt->instate = XML_PARSER_EPILOG;
5659 } else {
5660 ctxt->instate = XML_PARSER_CONTENT;
5661 }
5662 ctxt->checkIndex = 0;
5663#ifdef DEBUG_PUSH
5664 xmlGenericError(xmlGenericErrorContext,
5665 "HPP: entering CONTENT\n");
5666#endif
5667 break;
5668 case XML_PARSER_CDATA_SECTION:
5669 xmlGenericError(xmlGenericErrorContext,
5670 "HPP: internal error, state == CDATA\n");
5671 ctxt->instate = XML_PARSER_CONTENT;
5672 ctxt->checkIndex = 0;
5673#ifdef DEBUG_PUSH
5674 xmlGenericError(xmlGenericErrorContext,
5675 "HPP: entering CONTENT\n");
5676#endif
5677 break;
5678 case XML_PARSER_DTD:
5679 xmlGenericError(xmlGenericErrorContext,
5680 "HPP: internal error, state == DTD\n");
5681 ctxt->instate = XML_PARSER_CONTENT;
5682 ctxt->checkIndex = 0;
5683#ifdef DEBUG_PUSH
5684 xmlGenericError(xmlGenericErrorContext,
5685 "HPP: entering CONTENT\n");
5686#endif
5687 break;
5688 case XML_PARSER_COMMENT:
5689 xmlGenericError(xmlGenericErrorContext,
5690 "HPP: internal error, state == COMMENT\n");
5691 ctxt->instate = XML_PARSER_CONTENT;
5692 ctxt->checkIndex = 0;
5693#ifdef DEBUG_PUSH
5694 xmlGenericError(xmlGenericErrorContext,
5695 "HPP: entering CONTENT\n");
5696#endif
5697 break;
5698 case XML_PARSER_PI:
5699 xmlGenericError(xmlGenericErrorContext,
5700 "HPP: internal error, state == PI\n");
5701 ctxt->instate = XML_PARSER_CONTENT;
5702 ctxt->checkIndex = 0;
5703#ifdef DEBUG_PUSH
5704 xmlGenericError(xmlGenericErrorContext,
5705 "HPP: entering CONTENT\n");
5706#endif
5707 break;
5708 case XML_PARSER_ENTITY_DECL:
5709 xmlGenericError(xmlGenericErrorContext,
5710 "HPP: internal error, state == ENTITY_DECL\n");
5711 ctxt->instate = XML_PARSER_CONTENT;
5712 ctxt->checkIndex = 0;
5713#ifdef DEBUG_PUSH
5714 xmlGenericError(xmlGenericErrorContext,
5715 "HPP: entering CONTENT\n");
5716#endif
5717 break;
5718 case XML_PARSER_ENTITY_VALUE:
5719 xmlGenericError(xmlGenericErrorContext,
5720 "HPP: internal error, state == ENTITY_VALUE\n");
5721 ctxt->instate = XML_PARSER_CONTENT;
5722 ctxt->checkIndex = 0;
5723#ifdef DEBUG_PUSH
5724 xmlGenericError(xmlGenericErrorContext,
5725 "HPP: entering DTD\n");
5726#endif
5727 break;
5728 case XML_PARSER_ATTRIBUTE_VALUE:
5729 xmlGenericError(xmlGenericErrorContext,
5730 "HPP: internal error, state == ATTRIBUTE_VALUE\n");
5731 ctxt->instate = XML_PARSER_START_TAG;
5732 ctxt->checkIndex = 0;
5733#ifdef DEBUG_PUSH
5734 xmlGenericError(xmlGenericErrorContext,
5735 "HPP: entering START_TAG\n");
5736#endif
5737 break;
5738 case XML_PARSER_SYSTEM_LITERAL:
5739 xmlGenericError(xmlGenericErrorContext,
5740 "HPP: internal error, state == XML_PARSER_SYSTEM_LITERAL\n");
5741 ctxt->instate = XML_PARSER_CONTENT;
5742 ctxt->checkIndex = 0;
5743#ifdef DEBUG_PUSH
5744 xmlGenericError(xmlGenericErrorContext,
5745 "HPP: entering CONTENT\n");
5746#endif
5747 break;
5748
5749 case XML_PARSER_IGNORE:
5750 xmlGenericError(xmlGenericErrorContext,
5751 "HPP: internal error, state == XML_PARSER_IGNORE\n");
5752 ctxt->instate = XML_PARSER_CONTENT;
5753 ctxt->checkIndex = 0;
5754#ifdef DEBUG_PUSH
5755 xmlGenericError(xmlGenericErrorContext,
5756 "HPP: entering CONTENT\n");
5757#endif
5758 break;
Daniel Veillard044fc6b2002-03-04 17:09:44 +00005759 case XML_PARSER_PUBLIC_LITERAL:
5760 xmlGenericError(xmlGenericErrorContext,
5761 "HPP: internal error, state == XML_PARSER_LITERAL\n");
5762 ctxt->instate = XML_PARSER_CONTENT;
5763 ctxt->checkIndex = 0;
5764#ifdef DEBUG_PUSH
5765 xmlGenericError(xmlGenericErrorContext,
5766 "HPP: entering CONTENT\n");
5767#endif
5768 break;
Daniel Veillardeae522a2001-04-23 13:41:34 +00005769 }
5770 }
5771done:
5772 if ((avail == 0) && (terminate)) {
5773 docbAutoClose(ctxt, NULL);
5774 if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
5775 /*
5776 * SAX: end of the document processing.
5777 */
5778 ctxt->instate = XML_PARSER_EOF;
5779 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5780 ctxt->sax->endDocument(ctxt->userData);
5781 }
5782 }
5783 if ((ctxt->myDoc != NULL) &&
5784 ((terminate) || (ctxt->instate == XML_PARSER_EOF) ||
5785 (ctxt->instate == XML_PARSER_EPILOG))) {
5786 xmlDtdPtr dtd;
5787 dtd = ctxt->myDoc->intSubset;
5788 if (dtd == NULL)
5789 ctxt->myDoc->intSubset =
5790 xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "SGML",
5791 BAD_CAST "-//W3C//DTD SGML 4.0 Transitional//EN",
5792 BAD_CAST "http://www.w3.org/TR/REC-docbook/loose.dtd");
5793 }
5794#ifdef DEBUG_PUSH
5795 xmlGenericError(xmlGenericErrorContext, "HPP: done %d\n", ret);
5796#endif
5797 return(ret);
5798}
5799
5800/**
5801 * docbParseChunk:
5802 * @ctxt: an XML parser context
5803 * @chunk: an char array
5804 * @size: the size in byte of the chunk
5805 * @terminate: last chunk indicator
5806 *
5807 * Parse a Chunk of memory
5808 *
5809 * Returns zero if no error, the xmlParserErrors otherwise.
5810 */
5811int
5812docbParseChunk(docbParserCtxtPtr ctxt, const char *chunk, int size,
5813 int terminate) {
5814 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
5815 (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) {
5816 int base = ctxt->input->base - ctxt->input->buf->buffer->content;
5817 int cur = ctxt->input->cur - ctxt->input->base;
5818
5819 xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
5820 ctxt->input->base = ctxt->input->buf->buffer->content + base;
5821 ctxt->input->cur = ctxt->input->base + cur;
5822#ifdef DEBUG_PUSH
5823 xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
5824#endif
5825
5826 if ((terminate) || (ctxt->input->buf->buffer->use > 80))
5827 docbParseTryOrFinish(ctxt, terminate);
5828 } else if (ctxt->instate != XML_PARSER_EOF) {
5829 xmlParserInputBufferPush(ctxt->input->buf, 0, "");
5830 docbParseTryOrFinish(ctxt, terminate);
5831 }
5832 if (terminate) {
5833 if ((ctxt->instate != XML_PARSER_EOF) &&
5834 (ctxt->instate != XML_PARSER_EPILOG) &&
5835 (ctxt->instate != XML_PARSER_MISC)) {
5836 ctxt->errNo = XML_ERR_DOCUMENT_END;
5837 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5838 ctxt->sax->error(ctxt->userData,
5839 "Extra content at the end of the document\n");
5840 ctxt->wellFormed = 0;
5841 }
5842 if (ctxt->instate != XML_PARSER_EOF) {
5843 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5844 ctxt->sax->endDocument(ctxt->userData);
5845 }
5846 ctxt->instate = XML_PARSER_EOF;
5847 }
5848 return((xmlParserErrors) ctxt->errNo);
5849}
5850
5851/************************************************************************
5852 * *
5853 * User entry points *
5854 * *
5855 ************************************************************************/
5856
5857/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00005858 * docbCreatePushParserCtxt:
Daniel Veillardeae522a2001-04-23 13:41:34 +00005859 * @sax: a SAX handler
5860 * @user_data: The user data returned on SAX callbacks
5861 * @chunk: a pointer to an array of chars
5862 * @size: number of chars in the array
5863 * @filename: an optional file name or URI
5864 * @enc: an optional encoding
5865 *
5866 * Create a parser context for using the DocBook SGML parser in push mode
5867 * To allow content encoding detection, @size should be >= 4
5868 * The value of @filename is used for fetching external entities
5869 * and error/warning reports.
5870 *
5871 * Returns the new parser context or NULL
5872 */
5873docbParserCtxtPtr
5874docbCreatePushParserCtxt(docbSAXHandlerPtr sax, void *user_data,
5875 const char *chunk, int size, const char *filename,
5876 xmlCharEncoding enc) {
5877 docbParserCtxtPtr ctxt;
5878 docbParserInputPtr inputStream;
5879 xmlParserInputBufferPtr buf;
5880
5881 buf = xmlAllocParserInputBuffer(enc);
5882 if (buf == NULL) return(NULL);
5883
5884 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
5885 if (ctxt == NULL) {
5886 xmlFree(buf);
5887 return(NULL);
5888 }
5889 memset(ctxt, 0, sizeof(docbParserCtxt));
5890 docbInitParserCtxt(ctxt);
5891 if (sax != NULL) {
5892 if (ctxt->sax != &docbDefaultSAXHandler)
5893 xmlFree(ctxt->sax);
5894 ctxt->sax = (docbSAXHandlerPtr) xmlMalloc(sizeof(docbSAXHandler));
5895 if (ctxt->sax == NULL) {
5896 xmlFree(buf);
5897 xmlFree(ctxt);
5898 return(NULL);
5899 }
5900 memcpy(ctxt->sax, sax, sizeof(docbSAXHandler));
5901 if (user_data != NULL)
5902 ctxt->userData = user_data;
5903 }
5904 if (filename == NULL) {
5905 ctxt->directory = NULL;
5906 } else {
5907 ctxt->directory = xmlParserGetDirectory(filename);
5908 }
5909
5910 inputStream = docbNewInputStream(ctxt);
5911 if (inputStream == NULL) {
5912 xmlFreeParserCtxt(ctxt);
5913 return(NULL);
5914 }
5915
5916 if (filename == NULL)
5917 inputStream->filename = NULL;
5918 else
Daniel Veillardc3ca5ba2003-05-09 22:26:28 +00005919 inputStream->filename = (char *)
5920 xmlCanonicPath((const xmlChar *)filename);
Daniel Veillardeae522a2001-04-23 13:41:34 +00005921 inputStream->buf = buf;
5922 inputStream->base = inputStream->buf->buffer->content;
5923 inputStream->cur = inputStream->buf->buffer->content;
5924
5925 inputPush(ctxt, inputStream);
5926
5927 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
5928 (ctxt->input->buf != NULL)) {
5929 xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
5930#ifdef DEBUG_PUSH
5931 xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
5932#endif
5933 }
5934
5935 return(ctxt);
5936}
5937
5938/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00005939 * docbSAXParseDoc:
Daniel Veillardeae522a2001-04-23 13:41:34 +00005940 * @cur: a pointer to an array of xmlChar
5941 * @encoding: a free form C string describing the SGML document encoding, or NULL
5942 * @sax: the SAX handler block
5943 * @userData: if using SAX, this pointer will be provided on callbacks.
5944 *
5945 * parse an SGML in-memory document and build a tree.
5946 * It use the given SAX function block to handle the parsing callback.
5947 * If sax is NULL, fallback to the default DOM tree building routines.
5948 *
5949 * Returns the resulting document tree
5950 */
5951
5952docbDocPtr
5953docbSAXParseDoc(xmlChar *cur, const char *encoding, docbSAXHandlerPtr sax, void *userData) {
5954 docbDocPtr ret;
5955 docbParserCtxtPtr ctxt;
5956
5957 if (cur == NULL) return(NULL);
5958
5959
5960 ctxt = docbCreateDocParserCtxt(cur, encoding);
5961 if (ctxt == NULL) return(NULL);
5962 if (sax != NULL) {
5963 ctxt->sax = sax;
5964 ctxt->userData = userData;
5965 }
5966
5967 docbParseDocument(ctxt);
5968 ret = ctxt->myDoc;
5969 if (sax != NULL) {
5970 ctxt->sax = NULL;
5971 ctxt->userData = NULL;
5972 }
5973 docbFreeParserCtxt(ctxt);
5974
5975 return(ret);
5976}
5977
5978/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00005979 * docbParseDoc:
Daniel Veillardeae522a2001-04-23 13:41:34 +00005980 * @cur: a pointer to an array of xmlChar
5981 * @encoding: a free form C string describing the SGML document encoding, or NULL
5982 *
5983 * parse an SGML in-memory document and build a tree.
5984 *
5985 * Returns the resulting document tree
5986 */
5987
5988docbDocPtr
5989docbParseDoc(xmlChar *cur, const char *encoding) {
5990 return(docbSAXParseDoc(cur, encoding, NULL, NULL));
5991}
5992
5993
5994/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00005995 * docbCreateFileParserCtxt:
Daniel Veillardeae522a2001-04-23 13:41:34 +00005996 * @filename: the filename
Daniel Veillard1034da22001-04-25 19:06:28 +00005997 * @encoding: the SGML document encoding, or NULL
Daniel Veillardeae522a2001-04-23 13:41:34 +00005998 *
5999 * Create a parser context for a file content.
6000 * Automatic support for ZLIB/Compress compressed document is provided
6001 * by default if found at compile-time.
6002 *
6003 * Returns the new parser context or NULL
6004 */
6005docbParserCtxtPtr
Daniel Veillard1034da22001-04-25 19:06:28 +00006006docbCreateFileParserCtxt(const char *filename,
6007 const char *encoding ATTRIBUTE_UNUSED)
Daniel Veillardeae522a2001-04-23 13:41:34 +00006008{
6009 docbParserCtxtPtr ctxt;
6010 docbParserInputPtr inputStream;
6011 xmlParserInputBufferPtr buf;
6012 /* sgmlCharEncoding enc; */
6013
6014 buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
6015 if (buf == NULL) return(NULL);
6016
6017 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
6018 if (ctxt == NULL) {
Daniel Veillard3487c8d2002-09-05 11:33:25 +00006019 xmlGenericError(xmlGenericErrorContext, "malloc failed");
6020 return(NULL);
Daniel Veillardeae522a2001-04-23 13:41:34 +00006021 }
6022 memset(ctxt, 0, sizeof(docbParserCtxt));
6023 docbInitParserCtxt(ctxt);
6024 inputStream = (docbParserInputPtr) xmlMalloc(sizeof(docbParserInput));
6025 if (inputStream == NULL) {
Daniel Veillard3487c8d2002-09-05 11:33:25 +00006026 xmlGenericError(xmlGenericErrorContext, "malloc failed");
6027 xmlFree(ctxt);
6028 return(NULL);
Daniel Veillardeae522a2001-04-23 13:41:34 +00006029 }
6030 memset(inputStream, 0, sizeof(docbParserInput));
6031
Daniel Veillard85095e22003-04-23 13:56:44 +00006032 inputStream->filename = (char *) xmlCanonicPath((const xmlChar *)filename);
Daniel Veillardeae522a2001-04-23 13:41:34 +00006033 inputStream->line = 1;
6034 inputStream->col = 1;
6035 inputStream->buf = buf;
6036 inputStream->directory = NULL;
6037
6038 inputStream->base = inputStream->buf->buffer->content;
6039 inputStream->cur = inputStream->buf->buffer->content;
6040 inputStream->free = NULL;
6041
6042 inputPush(ctxt, inputStream);
6043 return(ctxt);
6044}
6045
6046/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00006047 * docbSAXParseFile:
Daniel Veillardeae522a2001-04-23 13:41:34 +00006048 * @filename: the filename
6049 * @encoding: a free form C string describing the SGML document encoding, or NULL
6050 * @sax: the SAX handler block
6051 * @userData: if using SAX, this pointer will be provided on callbacks.
6052 *
6053 * parse an SGML file and build a tree. Automatic support for ZLIB/Compress
6054 * compressed document is provided by default if found at compile-time.
6055 * It use the given SAX function block to handle the parsing callback.
6056 * If sax is NULL, fallback to the default DOM tree building routines.
6057 *
6058 * Returns the resulting document tree
6059 */
6060
6061docbDocPtr
6062docbSAXParseFile(const char *filename, const char *encoding, docbSAXHandlerPtr sax,
6063 void *userData) {
6064 docbDocPtr ret;
6065 docbParserCtxtPtr ctxt;
6066 docbSAXHandlerPtr oldsax = NULL;
6067
6068 ctxt = docbCreateFileParserCtxt(filename, encoding);
6069 if (ctxt == NULL) return(NULL);
6070 if (sax != NULL) {
6071 oldsax = ctxt->sax;
6072 ctxt->sax = sax;
6073 ctxt->userData = userData;
6074 }
6075
6076 docbParseDocument(ctxt);
6077
6078 ret = ctxt->myDoc;
6079 if (sax != NULL) {
6080 ctxt->sax = oldsax;
6081 ctxt->userData = NULL;
6082 }
6083 docbFreeParserCtxt(ctxt);
6084
6085 return(ret);
6086}
6087
6088/**
Daniel Veillard01c13b52002-12-10 15:19:08 +00006089 * docbParseFile:
Daniel Veillardeae522a2001-04-23 13:41:34 +00006090 * @filename: the filename
6091 * @encoding: a free form C string describing document encoding, or NULL
6092 *
6093 * parse a Docbook SGML file and build a tree. Automatic support for
6094 * ZLIB/Compress compressed document is provided by default if found
6095 * at compile-time.
6096 *
6097 * Returns the resulting document tree
6098 */
6099
6100docbDocPtr
6101docbParseFile(const char *filename, const char *encoding) {
6102 return(docbSAXParseFile(filename, encoding, NULL, NULL));
6103}
6104
6105#endif /* LIBXML_DOCB_ENABLED */