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