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