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