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