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