2 * DOCBparser.c : an attempt to parse SGML Docbook documents
4 * This is extremely hackish. It also adds one extension
5 * <?sgml-declaration encoding="ISO-8859-1"?>
6 * allowing to store the encoding of the document within the instance.
8 * See Copyright for the status of this software.
15 #ifdef LIBXML_DOCB_ENABLED
24 #ifdef HAVE_SYS_STAT_H
37 #include <libxml/xmlmemory.h>
38 #include <libxml/tree.h>
39 #include <libxml/SAX.h>
40 #include <libxml/parser.h>
41 #include <libxml/parserInternals.h>
42 #include <libxml/xmlerror.h>
43 #include <libxml/DOCBparser.h>
44 #include <libxml/entities.h>
45 #include <libxml/encoding.h>
46 #include <libxml/valid.h>
47 #include <libxml/xmlIO.h>
48 #include <libxml/uri.h>
49 #include <libxml/globals.h>
52 * DocBook XML current versions
55 #define XML_DOCBOOK_XML_PUBLIC (const xmlChar *) \
56 "-//OASIS//DTD DocBook XML V4.1.2//EN"
57 #define XML_DOCBOOK_XML_SYSTEM (const xmlChar *) \
58 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
61 * Internal description of an SGML entity
63 typedef struct _docbEntityDesc docbEntityDesc
;
64 typedef docbEntityDesc
*docbEntityDescPtr
;
65 struct _docbEntityDesc
{
66 int value
; /* the UNICODE value for the character */
67 const char *name
; /* The entity name */
68 const char *desc
; /* the description */
72 docbElemDescPtr
docbTagLookup (const xmlChar
*tag
);
73 docbEntityDescPtr
docbEntityLookup(const xmlChar
*name
);
74 docbEntityDescPtr
docbEntityValueLookup(int value
);
76 int docbIsAutoClosed(docbDocPtr doc
,
78 int docbAutoCloseTag(docbDocPtr doc
,
83 static int docbParseCharRef(docbParserCtxtPtr ctxt
);
84 static xmlEntityPtr
docbParseEntityRef(docbParserCtxtPtr ctxt
,
86 static void docbParseElement(docbParserCtxtPtr ctxt
);
87 static void docbParseContent(docbParserCtxtPtr ctxt
);
90 * Internal description of an SGML element
92 typedef struct _docbElemDesc docbElemDesc
;
93 typedef docbElemDesc
*docbElemDescPtr
;
94 struct _docbElemDesc
{
95 const char *name
; /* The tag name */
96 int startTag
; /* Whether the start tag can be implied */
97 int endTag
; /* Whether the end tag can be implied */
98 int empty
; /* Is this an empty element ? */
99 int depr
; /* Is this a deprecated element ? */
100 int dtd
; /* 1: only in Loose DTD, 2: only Frameset one */
101 const char *desc
; /* the description */
105 #define DOCB_MAX_NAMELEN 1000
106 #define DOCB_PARSER_BIG_BUFFER_SIZE 1000
107 #define DOCB_PARSER_BUFFER_SIZE 100
110 /* #define DEBUG_PUSH */
112 /************************************************************************
114 * Parser stacks related functions and macros *
116 ************************************************************************/
119 * Generic function for accessing stacks in the Parser Context
122 #define PUSH_AND_POP(scope, type, name) \
123 scope int docb##name##Push(docbParserCtxtPtr ctxt, type value) { \
124 if (ctxt->name##Nr >= ctxt->name##Max) { \
125 ctxt->name##Max *= 2; \
126 ctxt->name##Tab = (type *) xmlRealloc(ctxt->name##Tab, \
127 ctxt->name##Max * sizeof(ctxt->name##Tab[0])); \
128 if (ctxt->name##Tab == NULL) { \
129 xmlGenericError(xmlGenericErrorContext, \
130 "realloc failed !\n"); \
134 ctxt->name##Tab[ctxt->name##Nr] = value; \
135 ctxt->name = value; \
136 return(ctxt->name##Nr++); \
138 scope type docb##name##Pop(docbParserCtxtPtr ctxt) { \
140 if (ctxt->name##Nr < 0) return(0); \
142 if (ctxt->name##Nr < 0) return(0); \
143 if (ctxt->name##Nr > 0) \
144 ctxt->name = ctxt->name##Tab[ctxt->name##Nr - 1]; \
147 ret = ctxt->name##Tab[ctxt->name##Nr]; \
148 ctxt->name##Tab[ctxt->name##Nr] = 0; \
152 /* PUSH_AND_POP(static, xmlNodePtr, node) */
153 PUSH_AND_POP(static, xmlChar
*, name
)
156 * Macros for accessing the content. Those should be used only by the parser,
159 * Dirty macros, i.e. one need to make assumption on the context to use them
161 * CUR_PTR return the current pointer to the xmlChar to be parsed.
162 * CUR returns the current xmlChar value, i.e. a 8 bit value if compiled
163 * in ISO-Latin or UTF-8, and the current 16 bit value if compiled
164 * in UNICODE mode. This should be used internally by the parser
165 * only to compare to ASCII values otherwise it would break when
166 * running with UTF-8 encoding.
167 * NXT(n) returns the n'th next xmlChar. Same as CUR is should be used only
168 * to compare on ASCII based substring.
169 * UPP(n) returns the n'th next xmlChar converted to uppercase. Same as CUR
170 * it should be used only to compare on ASCII based substring.
171 * SKIP(n) Skip n xmlChar, and must also be used only to skip ASCII defined
172 * strings within the parser.
174 * Clean macros, not dependent of an ASCII context, expect UTF-8 encoding
176 * CURRENT Returns the current char value, with the full decoding of
177 * UTF-8 if we are using this mode. It returns an int.
178 * NEXT Skip to the next character, this does the proper decoding
179 * in UTF-8 mode. It also pop-up unfinished entities on the fly.
180 * COPY(to) copy one char to *to, increment CUR_PTR and to accordingly
183 #define UPPER (toupper(*ctxt->input->cur))
185 #define SKIP(val) ctxt->nbChars += (val),ctxt->input->cur += (val)
187 #define NXT(val) ctxt->input->cur[(val)]
189 #define UPP(val) (toupper(ctxt->input->cur[(val)]))
191 #define CUR_PTR ctxt->input->cur
193 #define SHRINK xmlParserInputShrink(ctxt->input)
195 #define GROW xmlParserInputGrow(ctxt->input, INPUT_CHUNK)
197 #define CURRENT ((int) (*ctxt->input->cur))
199 #define SKIP_BLANKS docbSkipBlankChars(ctxt)
201 /* Imported from XML */
203 /* #define CUR (ctxt->token ? ctxt->token : (int) (*ctxt->input->cur)) */
204 #define CUR ((int) (*ctxt->input->cur))
205 #define NEXT xmlNextChar(ctxt),ctxt->nbChars++
207 #define RAW (ctxt->token ? -1 : (*ctxt->input->cur))
208 #define NXT(val) ctxt->input->cur[(val)]
209 #define CUR_PTR ctxt->input->cur
212 #define NEXTL(l) do { \
213 if (*(ctxt->input->cur) == '\n') { \
214 ctxt->input->line++; ctxt->input->col = 1; \
215 } else ctxt->input->col++; \
216 ctxt->token = 0; ctxt->input->cur += l; ctxt->nbChars++; \
221 if (*ctxt->input->cur == '%') xmlParserHandlePEReference(ctxt); \
222 if (*ctxt->input->cur == '&') xmlParserHandleReference(ctxt);
225 #define CUR_CHAR(l) docbCurrentChar(ctxt, &l)
226 #define CUR_SCHAR(s, l) xmlStringCurrentChar(ctxt, s, &l)
228 #define COPY_BUF(l,b,i,v) \
229 if (l == 1) b[i++] = (xmlChar) v; \
230 else i += xmlCopyChar(l,&b[i],v)
234 * @ctxt: the DocBook SGML parser context
235 * @len: pointer to the length of the char read
237 * The current char value, if using UTF-8 this may actually span multiple
238 * bytes in the input buffer. Implement the end of line normalization:
239 * 2.11 End-of-Line Handling
240 * If the encoding is unspecified, in the case we find an ISO-Latin-1
241 * char, then the encoding converter is plugged in automatically.
243 * Returns the current char value and its length
247 docbCurrentChar(xmlParserCtxtPtr ctxt
, int *len
) {
248 if (ctxt
->instate
== XML_PARSER_EOF
)
251 if (ctxt
->token
!= 0) {
255 if (ctxt
->charset
== XML_CHAR_ENCODING_UTF8
) {
257 * We are supposed to handle UTF8, check it's valid
258 * From rfc2044: encoding of the Unicode values on UTF-8:
260 * UCS-4 range (hex.) UTF-8 octet sequence (binary)
261 * 0000 0000-0000 007F 0xxxxxxx
262 * 0000 0080-0000 07FF 110xxxxx 10xxxxxx
263 * 0000 0800-0000 FFFF 1110xxxx 10xxxxxx 10xxxxxx
265 * Check for the 0x110000 limit too
267 const unsigned char *cur
= ctxt
->input
->cur
;
274 xmlParserInputGrow(ctxt
->input
, INPUT_CHUNK
);
275 if ((cur
[1] & 0xc0) != 0x80)
277 if ((c
& 0xe0) == 0xe0) {
280 xmlParserInputGrow(ctxt
->input
, INPUT_CHUNK
);
281 if ((cur
[2] & 0xc0) != 0x80)
283 if ((c
& 0xf0) == 0xf0) {
285 xmlParserInputGrow(ctxt
->input
, INPUT_CHUNK
);
286 if (((c
& 0xf8) != 0xf0) ||
287 ((cur
[3] & 0xc0) != 0x80))
291 val
= (cur
[0] & 0x7) << 18;
292 val
|= (cur
[1] & 0x3f) << 12;
293 val
|= (cur
[2] & 0x3f) << 6;
294 val
|= cur
[3] & 0x3f;
298 val
= (cur
[0] & 0xf) << 12;
299 val
|= (cur
[1] & 0x3f) << 6;
300 val
|= cur
[2] & 0x3f;
305 val
= (cur
[0] & 0x1f) << 6;
306 val
|= cur
[1] & 0x3f;
309 ctxt
->errNo
= XML_ERR_INVALID_ENCODING
;
310 if ((ctxt
->sax
!= NULL
) &&
311 (ctxt
->sax
->error
!= NULL
))
312 ctxt
->sax
->error(ctxt
->userData
,
313 "Char 0x%X out of allowed range\n", val
);
314 ctxt
->wellFormed
= 0;
315 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
321 return((int) *ctxt
->input
->cur
);
325 * Assume it's a fixed length encoding (1) with
326 * a compatible encoding for the ASCII set, since
327 * XML constructs only use < 128 chars
330 if ((int) *ctxt
->input
->cur
< 0x80)
331 return((int) *ctxt
->input
->cur
);
334 * Humm this is bad, do an automatic flow conversion
336 xmlSwitchEncoding(ctxt
, XML_CHAR_ENCODING_8859_1
);
337 ctxt
->charset
= XML_CHAR_ENCODING_UTF8
;
338 return(xmlCurrentChar(ctxt
, len
));
342 * If we detect an UTF8 error that probably mean that the
343 * input encoding didn't get properly advertized in the
344 * declaration header. Report the error and switch the encoding
345 * to ISO-Latin-1 (if you don't like this policy, just declare the
348 ctxt
->errNo
= XML_ERR_INVALID_ENCODING
;
349 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
)) {
350 ctxt
->sax
->error(ctxt
->userData
,
351 "Input is not proper UTF-8, indicate encoding !\n");
352 ctxt
->sax
->error(ctxt
->userData
, "Bytes: 0x%02X 0x%02X 0x%02X 0x%02X\n",
353 ctxt
->input
->cur
[0], ctxt
->input
->cur
[1],
354 ctxt
->input
->cur
[2], ctxt
->input
->cur
[3]);
357 ctxt
->charset
= XML_CHAR_ENCODING_8859_1
;
359 return((int) *ctxt
->input
->cur
);
365 * @ctxt: the DocBook SGML parser context
367 * Skip to the next char input char.
371 sgmlNextChar(docbParserCtxtPtr ctxt
) {
372 if (ctxt
->instate
== XML_PARSER_EOF
)
374 if ((*ctxt
->input
->cur
== 0) &&
375 (xmlParserInputGrow(ctxt
->input
, INPUT_CHUNK
) <= 0)) {
378 if (*(ctxt
->input
->cur
) == '\n') {
379 ctxt
->input
->line
++; ctxt
->input
->col
= 1;
380 } else ctxt
->input
->col
++;
383 if (*ctxt
->input
->cur
== 0)
384 xmlParserInputGrow(ctxt
->input
, INPUT_CHUNK
);
390 * docbSkipBlankChars:
391 * @ctxt: the DocBook SGML parser context
393 * skip all blanks character found at that point in the input streams.
395 * Returns the number of space chars skipped
399 docbSkipBlankChars(xmlParserCtxtPtr ctxt
) {
402 while (IS_BLANK(*(ctxt
->input
->cur
))) {
403 if ((*ctxt
->input
->cur
== 0) &&
404 (xmlParserInputGrow(ctxt
->input
, INPUT_CHUNK
) <= 0)) {
407 if (*(ctxt
->input
->cur
) == '\n') {
408 ctxt
->input
->line
++; ctxt
->input
->col
= 1;
409 } else ctxt
->input
->col
++;
412 if (*ctxt
->input
->cur
== 0)
413 xmlParserInputGrow(ctxt
->input
, INPUT_CHUNK
);
422 /************************************************************************
424 * The list of SGML elements and their properties *
426 ************************************************************************/
429 * Start Tag: 1 means the start tag can be ommited
430 * End Tag: 1 means the end tag can be ommited
431 * 2 means it's forbidden (empty elements)
432 * Depr: this element is deprecated
433 * DTD: 1 means that this element is valid only in the Loose DTD
434 * 2 means that this element is valid only in the Frameset DTD
436 * Name,Start Tag,End Tag, Empty, Depr., DTD, Description
439 docbookElementTable
[] = {
440 { "abbrev", 0, 0, 0, 3, 0, "" }, /* word */
441 { "abstract", 0, 0, 0, 9, 0, "" }, /* title */
442 { "accel", 0, 0, 0, 7, 0, "" }, /* smallcptr */
443 { "ackno", 0, 0, 0, 4, 0, "" }, /* docinfo */
444 { "acronym", 0, 0, 0, 3, 0, "" }, /* word */
445 { "action", 0, 0, 0, 7, 0, "" }, /* smallcptr */
446 { "address", 0, 0, 0, 1, 0, "" },
447 { "affiliation",0, 0, 0, 9, 0, "" }, /* shortaffil */
448 { "alt", 0, 0, 0, 1, 0, "" },
449 { "anchor", 0, 2, 1, 0, 0, "" },
450 { "answer", 0, 0, 0, 9, 0, "" }, /* label */
451 { "appendix", 0, 0, 0, 9, 0, "" }, /* appendixinfo */
452 { "appendixinfo",0, 0, 0, 9, 0, "" }, /* graphic */
453 { "application",0, 0, 0, 2, 0, "" }, /* para */
454 { "area", 0, 2, 1, 0, 0, "" },
455 { "areaset", 0, 0, 0, 9, 0, "" }, /* area */
456 { "areaspec", 0, 0, 0, 9, 0, "" }, /* area */
457 { "arg", 0, 0, 0, 1, 0, "" },
458 { "artheader", 0, 0, 0, 9, 0, "" },
459 { "article", 0, 0, 0, 9, 0, "" }, /* div.title.content */
460 { "articleinfo",0, 0, 0, 9, 0, "" }, /* graphic */
461 { "artpagenums",0, 0, 0, 4, 0, "" }, /* docinfo */
462 { "attribution",0, 0, 0, 2, 0, "" }, /* para */
463 { "audiodata", 0, 2, 1, 0, 0, "" },
464 { "audioobject",0, 0, 0, 9, 0, "" }, /* objectinfo */
465 { "authorblurb",0, 0, 0, 9, 0, "" }, /* title */
466 { "authorgroup",0, 0, 0, 9, 0, "" }, /* author */
467 { "authorinitials",0, 0, 0, 4, 0, "" }, /* docinfo */
468 { "author", 0, 0, 0, 9, 0, "" }, /* person.ident.mix */
469 { "beginpage", 0, 2, 1, 0, 0, "" },
470 { "bibliodiv", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
471 { "biblioentry",0, 0, 0, 9, 0, "" }, /* articleinfo */
472 { "bibliography",0, 0, 0, 9, 0, "" }, /* bibliographyinfo */
473 { "bibliographyinfo",0, 0, 0, 9, 0, "" }, /* graphic */
474 { "bibliomisc", 0, 0, 0, 2, 0, "" }, /* para */
475 { "bibliomixed",0, 0, 0, 1, 0, "" }, /* %bibliocomponent.mix, bibliomset) */
476 { "bibliomset", 0, 0, 0, 1, 0, "" }, /* %bibliocomponent.mix; | bibliomset) */
477 { "biblioset", 0, 0, 0, 9, 0, "" }, /* bibliocomponent.mix */
478 { "blockquote", 0, 0, 0, 9, 0, "" }, /* title */
479 { "book", 0, 0, 0, 9, 0, "" }, /* div.title.content */
480 { "bookinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
481 { "bridgehead", 0, 0, 0, 8, 0, "" }, /* title */
482 { "callout", 0, 0, 0, 9, 0, "" }, /* component.mix */
483 { "calloutlist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
484 { "caption", 0, 0, 0, 9, 0, "" }, /* textobject.mix */
485 { "caution", 0, 0, 0, 9, 0, "" }, /* title */
486 { "chapter", 0, 0, 0, 9, 0, "" }, /* chapterinfo */
487 { "chapterinfo",0, 0, 0, 9, 0, "" }, /* graphic */
488 { "citation", 0, 0, 0, 2, 0, "" }, /* para */
489 { "citerefentry",0, 0, 0, 9, 0, "" }, /* refentrytitle */
490 { "citetitle", 0, 0, 0, 2, 0, "" }, /* para */
491 { "city", 0, 0, 0, 4, 0, "" }, /* docinfo */
492 { "classname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
493 { "classsynopsisinfo",0,0, 0, 9, 0, "" }, /* cptr */
494 { "classsynopsis",0, 0, 0, 9, 0, "" }, /* ooclass */
495 { "cmdsynopsis",0, 0, 0, 9, 0, "" }, /* command */
496 { "co", 0, 2, 1, 0, 0, "" },
497 { "collab", 0, 0, 0, 9, 0, "" }, /* collabname */
498 { "collabname", 0, 0, 0, 4, 0, "" }, /* docinfo */
499 { "colophon", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
500 { "colspec", 0, 2, 1, 0, 0, "" },
501 { "colspec", 0, 2, 1, 0, 0, "" },
502 { "command", 0, 0, 0, 9, 0, "" }, /* cptr */
503 { "computeroutput",0, 0, 0, 9, 0, "" }, /* cptr */
504 { "confdates", 0, 0, 0, 4, 0, "" }, /* docinfo */
505 { "confgroup", 0, 0, 0, 9, 0, "" }, /* confdates */
506 { "confnum", 0, 0, 0, 4, 0, "" }, /* docinfo */
507 { "confsponsor",0, 0, 0, 4, 0, "" }, /* docinfo */
508 { "conftitle", 0, 0, 0, 4, 0, "" }, /* docinfo */
509 { "constant", 0, 0, 0, 7, 0, "" }, /* smallcptr */
510 { "constructorsynopsis",0,0, 0, 9, 0, "" }, /* modifier */
511 { "contractnum",0, 0, 0, 4, 0, "" }, /* docinfo */
512 { "contractsponsor",0, 0, 0, 4, 0, "" }, /* docinfo */
513 { "contrib", 0, 0, 0, 4, 0, "" }, /* docinfo */
514 { "copyright", 0, 0, 0, 9, 0, "" }, /* year */
515 { "corpauthor", 0, 0, 0, 4, 0, "" }, /* docinfo */
516 { "corpname", 0, 0, 0, 4, 0, "" }, /* docinfo */
517 { "country", 0, 0, 0, 4, 0, "" }, /* docinfo */
518 { "database", 0, 0, 0, 7, 0, "" }, /* smallcptr */
519 { "date", 0, 0, 0, 4, 0, "" }, /* docinfo */
520 { "dedication", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
521 { "destructorsynopsis",0,0, 0, 9, 0, "" }, /* modifier */
522 { "docinfo", 0, 0, 0, 9, 0, "" },
523 { "edition", 0, 0, 0, 4, 0, "" }, /* docinfo */
524 { "editor", 0, 0, 0, 9, 0, "" }, /* person.ident.mix */
525 { "email", 0, 0, 0, 4, 0, "" }, /* docinfo */
526 { "emphasis", 0, 0, 0, 2, 0, "" }, /* para */
527 { "entry", 0, 0, 0, 9, 0, "" }, /* tbl.entry.mdl */
528 { "entrytbl", 0, 0, 0, 9, 0, "" }, /* tbl.entrytbl.mdl */
529 { "envar", 0, 0, 0, 7, 0, "" }, /* smallcptr */
530 { "epigraph", 0, 0, 0, 9, 0, "" }, /* attribution */
531 { "equation", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
532 { "errorcode", 0, 0, 0, 7, 0, "" }, /* smallcptr */
533 { "errorname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
534 { "errortype", 0, 0, 0, 7, 0, "" }, /* smallcptr */
535 { "example", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
536 { "exceptionname",0, 0, 0, 7, 0, "" }, /* smallcptr */
537 { "fax", 0, 0, 0, 4, 0, "" }, /* docinfo */
538 { "fieldsynopsis", 0, 0, 0, 9, 0, "" }, /* modifier */
539 { "figure", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
540 { "filename", 0, 0, 0, 7, 0, "" }, /* smallcptr */
541 { "firstname", 0, 0, 0, 4, 0, "" }, /* docinfo */
542 { "firstterm", 0, 0, 0, 3, 0, "" }, /* word */
543 { "footnote", 0, 0, 0, 9, 0, "" }, /* footnote.mix */
544 { "footnoteref",0, 2, 1, 0, 0, "" },
545 { "foreignphrase",0, 0, 0, 2, 0, "" }, /* para */
546 { "formalpara", 0, 0, 0, 9, 0, "" }, /* title */
547 { "funcdef", 0, 0, 0, 1, 0, "" },
548 { "funcparams", 0, 0, 0, 9, 0, "" }, /* cptr */
549 { "funcprototype",0, 0, 0, 9, 0, "" }, /* funcdef */
550 { "funcsynopsis",0, 0, 0, 9, 0, "" }, /* funcsynopsisinfo */
551 { "funcsynopsisinfo", 0, 0, 0, 9, 0, "" }, /* cptr */
552 { "function", 0, 0, 0, 9, 0, "" }, /* cptr */
553 { "glossary", 0, 0, 0, 9, 0, "" }, /* glossaryinfo */
554 { "glossaryinfo",0, 0, 0, 9, 0, "" }, /* graphic */
555 { "glossdef", 0, 0, 0, 9, 0, "" }, /* glossdef.mix */
556 { "glossdiv", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
557 { "glossentry", 0, 0, 0, 9, 0, "" }, /* glossterm */
558 { "glosslist", 0, 0, 0, 9, 0, "" }, /* glossentry */
559 { "glossseealso",0, 0, 1, 2, 0, "" }, /* para */
560 { "glosssee", 0, 0, 1, 2, 0, "" }, /* para */
561 { "glossterm", 0, 0, 0, 2, 0, "" }, /* para */
562 { "graphic", 0, 0, 0, 9, 0, "" },
563 { "graphicco", 0, 0, 0, 9, 0, "" }, /* areaspec */
564 { "group", 0, 0, 0, 9, 0, "" }, /* arg */
565 { "guibutton", 0, 0, 0, 7, 0, "" }, /* smallcptr */
566 { "guiicon", 0, 0, 0, 7, 0, "" }, /* smallcptr */
567 { "guilabel", 0, 0, 0, 7, 0, "" }, /* smallcptr */
568 { "guimenuitem",0, 0, 0, 7, 0, "" }, /* smallcptr */
569 { "guimenu", 0, 0, 0, 7, 0, "" }, /* smallcptr */
570 { "guisubmenu", 0, 0, 0, 7, 0, "" }, /* smallcptr */
571 { "hardware", 0, 0, 0, 7, 0, "" }, /* smallcptr */
572 { "highlights", 0, 0, 0, 9, 0, "" }, /* highlights.mix */
573 { "holder", 0, 0, 0, 4, 0, "" }, /* docinfo */
574 { "honorific", 0, 0, 0, 4, 0, "" }, /* docinfo */
575 { "imagedata", 0, 2, 1, 0, 0, "" },
576 { "imageobjectco",0, 0, 0, 9, 0, "" }, /* areaspec */
577 { "imageobject",0, 0, 0, 9, 0, "" }, /* objectinfo */
578 { "important", 0, 0, 0, 9, 0, "" }, /* title */
579 { "indexdiv", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
580 { "indexentry", 0, 0, 0, 9, 0, "" }, /* primaryie */
581 { "index", 0, 0, 0, 9, 0, "" }, /* indexinfo */
582 { "indexinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
583 { "indexterm", 0, 0, 0, 9, 0, "" }, /* primary */
584 { "informalequation",0, 0, 0, 9, 0, "" }, /* equation.content */
585 { "informalexample",0, 0, 0, 9, 0, "" }, /* example.mix */
586 { "informalfigure",0, 0, 0, 9, 0, "" }, /* figure.mix */
587 { "informaltable",0, 0, 0, 9, 0, "" }, /* graphic */
588 { "initializer",0, 0, 0, 7, 0, "" }, /* smallcptr */
589 { "inlineequation",0, 0, 0, 9, 0, "" }, /* inlineequation.content */
590 { "inlinegraphic",0, 0, 0, 9, 0, "" },
591 { "inlinemediaobject",0,0, 0, 9, 0, "" }, /* objectinfo */
592 { "interfacename",0, 0, 0, 7, 0, "" }, /* smallcptr */
593 { "interface", 0, 0, 0, 7, 0, "" }, /* smallcptr */
594 { "invpartnumber",0, 0, 0, 4, 0, "" }, /* docinfo */
595 { "isbn", 0, 0, 0, 4, 0, "" }, /* docinfo */
596 { "issn", 0, 0, 0, 4, 0, "" }, /* docinfo */
597 { "issuenum", 0, 0, 0, 4, 0, "" }, /* docinfo */
598 { "itemizedlist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
599 { "itermset", 0, 0, 0, 9, 0, "" }, /* indexterm */
600 { "jobtitle", 0, 0, 0, 4, 0, "" }, /* docinfo */
601 { "keycap", 0, 0, 0, 7, 0, "" }, /* smallcptr */
602 { "keycode", 0, 0, 0, 7, 0, "" }, /* smallcptr */
603 { "keycombo", 0, 0, 0, 9, 0, "" }, /* keycap */
604 { "keysym", 0, 0, 0, 7, 0, "" }, /* smallcptr */
605 { "keyword", 0, 0, 0, 1, 0, "" },
606 { "keywordset", 0, 0, 0, 9, 0, "" }, /* keyword */
607 { "label", 0, 0, 0, 3, 0, "" }, /* word */
608 { "legalnotice",0, 0, 0, 9, 0, "" }, /* title */
609 { "lineage", 0, 0, 0, 4, 0, "" }, /* docinfo */
610 { "lineannotation",0, 0, 0, 2, 0, "" }, /* para */
611 { "link", 0, 0, 0, 2, 0, "" }, /* para */
612 { "listitem", 0, 0, 0, 9, 0, "" }, /* component.mix */
613 { "literal", 0, 0, 0, 9, 0, "" }, /* cptr */
614 { "literallayout",0, 0, 0, 2, 0, "" }, /* para */
615 { "lot", 0, 0, 0, 9, 0, "" }, /* bookcomponent.title.content */
616 { "lotentry", 0, 0, 0, 2, 0, "" }, /* para */
617 { "manvolnum", 0, 0, 0, 3, 0, "" }, /* word */
618 { "markup", 0, 0, 0, 7, 0, "" }, /* smallcptr */
619 { "medialabel", 0, 0, 0, 7, 0, "" }, /* smallcptr */
620 { "mediaobjectco",0, 0, 0, 9, 0, "" }, /* objectinfo */
621 { "mediaobject",0, 0, 0, 9, 0, "" }, /* objectinfo */
622 { "member", 0, 0, 0, 2, 0, "" }, /* para */
623 { "menuchoice", 0, 0, 0, 9, 0, "" }, /* shortcut */
624 { "methodname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
625 { "methodparam",0, 0, 0, 9, 0, "" }, /* modifier */
626 { "methodsynopsis",0, 0, 0, 9, 0, "" }, /* modifier */
627 { "modespec", 0, 0, 0, 4, 0, "" }, /* docinfo */
628 { "modifier", 0, 0, 0, 7, 0, "" }, /* smallcptr */
629 { "mousebutton",0, 0, 0, 7, 0, "" }, /* smallcptr */
630 { "msgaud", 0, 0, 0, 2, 0, "" }, /* para */
631 { "msgentry", 0, 0, 0, 9, 0, "" }, /* msg */
632 { "msgexplan", 0, 0, 0, 9, 0, "" }, /* title */
633 { "msginfo", 0, 0, 0, 9, 0, "" }, /* msglevel */
634 { "msglevel", 0, 0, 0, 7, 0, "" }, /* smallcptr */
635 { "msgmain", 0, 0, 0, 9, 0, "" }, /* title */
636 { "msgorig", 0, 0, 0, 7, 0, "" }, /* smallcptr */
637 { "msgrel", 0, 0, 0, 9, 0, "" }, /* title */
638 { "msgset", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
639 { "msgsub", 0, 0, 0, 9, 0, "" }, /* title */
640 { "msgtext", 0, 0, 0, 9, 0, "" }, /* component.mix */
641 { "msg", 0, 0, 0, 9, 0, "" }, /* title */
642 { "note", 0, 0, 0, 9, 0, "" }, /* title */
643 { "objectinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
644 { "olink", 0, 0, 0, 2, 0, "" }, /* para */
645 { "ooclass", 0, 0, 0, 9, 0, "" }, /* modifier */
646 { "ooexception",0, 0, 0, 9, 0, "" }, /* modifier */
647 { "oointerface",0, 0, 0, 9, 0, "" }, /* modifier */
648 { "optional", 0, 0, 0, 9, 0, "" }, /* cptr */
649 { "option", 0, 0, 0, 7, 0, "" }, /* smallcptr */
650 { "orderedlist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
651 { "orgdiv", 0, 0, 0, 4, 0, "" }, /* docinfo */
652 { "orgname", 0, 0, 0, 4, 0, "" }, /* docinfo */
653 { "otheraddr", 0, 0, 0, 4, 0, "" }, /* docinfo */
654 { "othercredit",0, 0, 0, 9, 0, "" }, /* person.ident.mix */
655 { "othername", 0, 0, 0, 4, 0, "" }, /* docinfo */
656 { "pagenums", 0, 0, 0, 4, 0, "" }, /* docinfo */
657 { "paramdef", 0, 0, 0, 1, 0, "" },
658 { "parameter", 0, 0, 0, 7, 0, "" }, /* smallcptr */
659 { "para", 0, 0, 0, 2, 0, "" }, /* para */
660 { "partinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
661 { "partintro", 0, 0, 0, 9, 0, "" }, /* div.title.content */
662 { "part", 0, 0, 0, 9, 0, "" }, /* partinfo */
663 { "phone", 0, 0, 0, 4, 0, "" }, /* docinfo */
664 { "phrase", 0, 0, 0, 2, 0, "" }, /* para */
665 { "pob", 0, 0, 0, 4, 0, "" }, /* docinfo */
666 { "postcode", 0, 0, 0, 4, 0, "" }, /* docinfo */
667 { "prefaceinfo",0, 0, 0, 9, 0, "" }, /* graphic */
668 { "preface", 0, 0, 0, 9, 0, "" }, /* prefaceinfo */
669 { "primaryie", 0, 0, 0, 4, 0, "" }, /* ndxterm */
670 { "primary", 0, 0, 0, 9, 0, "" }, /* ndxterm */
671 { "printhistory",0, 0, 0, 9, 0, "" }, /* para.class */
672 { "procedure", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
673 { "productname",0, 0, 0, 2, 0, "" }, /* para */
674 { "productnumber",0, 0, 0, 4, 0, "" }, /* docinfo */
675 { "programlistingco",0, 0, 0, 9, 0, "" }, /* areaspec */
676 { "programlisting",0, 0, 0, 2, 0, "" }, /* para */
677 { "prompt", 0, 0, 0, 7, 0, "" }, /* smallcptr */
678 { "property", 0, 0, 0, 7, 0, "" }, /* smallcptr */
679 { "pubdate", 0, 0, 0, 4, 0, "" }, /* docinfo */
680 { "publishername",0, 0, 0, 4, 0, "" }, /* docinfo */
681 { "publisher", 0, 0, 0, 9, 0, "" }, /* publishername */
682 { "pubsnumber", 0, 0, 0, 4, 0, "" }, /* docinfo */
683 { "qandadiv", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
684 { "qandaentry", 0, 0, 0, 9, 0, "" }, /* revhistory */
685 { "qandaset", 0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
686 { "question", 0, 0, 0, 9, 0, "" }, /* label */
687 { "quote", 0, 0, 0, 2, 0, "" }, /* para */
688 { "refclass", 0, 0, 0, 9, 0, "" }, /* refclass.char.mix */
689 { "refdescriptor",0, 0, 0, 9, 0, "" }, /* refname.char.mix */
690 { "refentryinfo",0, 0, 0, 9, 0, "" }, /* graphic */
691 { "refentry", 0, 0, 0, 9, 0, "" }, /* ndxterm.class */
692 { "refentrytitle",0, 0, 0, 2, 0, "" }, /* para */
693 { "referenceinfo",0, 0, 0, 9, 0, "" }, /* graphic */
694 { "reference", 0, 0, 0, 9, 0, "" }, /* referenceinfo */
695 { "refmeta", 0, 0, 0, 9, 0, "" }, /* ndxterm.class */
696 { "refmiscinfo",0, 0, 0, 4, 0, "" }, /* docinfo */
697 { "refnamediv", 0, 0, 0, 9, 0, "" }, /* refdescriptor */
698 { "refname", 0, 0, 0, 9, 0, "" }, /* refname.char.mix */
699 { "refpurpose", 0, 0, 0, 9, 0, "" }, /* refinline.char.mix */
700 { "refsect1info",0, 0, 0, 9, 0, "" }, /* graphic */
701 { "refsect1", 0, 0, 0, 9, 0, "" }, /* refsect */
702 { "refsect2info",0, 0, 0, 9, 0, "" }, /* graphic */
703 { "refsect2", 0, 0, 0, 9, 0, "" }, /* refsect */
704 { "refsect3info",0, 0, 0, 9, 0, "" }, /* graphic */
705 { "refsect3", 0, 0, 0, 9, 0, "" }, /* refsect */
706 { "refsynopsisdivinfo",0,0, 0, 9, 0, "" }, /* graphic */
707 { "refsynopsisdiv",0, 0, 0, 9, 0, "" }, /* refsynopsisdivinfo */
708 { "releaseinfo",0, 0, 0, 4, 0, "" }, /* docinfo */
709 { "remark", 0, 0, 0, 2, 0, "" }, /* para */
710 { "replaceable",0, 0, 0, 1, 0, "" },
711 { "returnvalue",0, 0, 0, 7, 0, "" }, /* smallcptr */
712 { "revdescription",0, 0, 0, 9, 0, "" }, /* revdescription.mix */
713 { "revhistory", 0, 0, 0, 9, 0, "" }, /* revision */
714 { "revision", 0, 0, 0, 9, 0, "" }, /* revnumber */
715 { "revnumber", 0, 0, 0, 4, 0, "" }, /* docinfo */
716 { "revremark", 0, 0, 0, 4, 0, "" }, /* docinfo */
717 { "row", 0, 0, 0, 9, 0, "" }, /* tbl.row.mdl */
718 { "row", 0, 0, 0, 9, 0, "" }, /* tbl.row.mdl */
719 { "sbr", 0, 2, 1, 0, 0, "" },
720 { "screenco", 0, 0, 0, 9, 0, "" }, /* areaspec */
721 { "screeninfo", 0, 0, 0, 2, 0, "" }, /* para */
722 { "screen", 0, 0, 0, 2, 0, "" }, /* para */
723 { "screenshot", 0, 0, 0, 9, 0, "" }, /* screeninfo */
724 { "secondaryie",0, 0, 0, 4, 0, "" }, /* ndxterm */
725 { "secondary", 0, 0, 0, 4, 0, "" }, /* ndxterm */
726 { "sect1info", 0, 0, 0, 9, 0, "" }, /* graphic */
727 { "sect1", 0, 0, 0, 9, 0, "" }, /* sect */
728 { "sect2info", 0, 0, 0, 9, 0, "" }, /* graphic */
729 { "sect2", 0, 0, 0, 9, 0, "" }, /* sect */
730 { "sect3info", 0, 0, 0, 9, 0, "" }, /* graphic */
731 { "sect3", 0, 0, 0, 9, 0, "" }, /* sect */
732 { "sect4info", 0, 0, 0, 9, 0, "" }, /* graphic */
733 { "sect4", 0, 0, 0, 9, 0, "" }, /* sect */
734 { "sect5info", 0, 0, 0, 9, 0, "" }, /* graphic */
735 { "sect5", 0, 0, 0, 9, 0, "" }, /* sect */
736 { "sectioninfo",0, 0, 0, 9, 0, "" }, /* graphic */
737 { "section", 0, 0, 0, 9, 0, "" }, /* sectioninfo */
738 { "seealsoie", 0, 0, 0, 4, 0, "" }, /* ndxterm */
739 { "seealso", 0, 0, 0, 4, 0, "" }, /* ndxterm */
740 { "seeie", 0, 0, 0, 4, 0, "" }, /* ndxterm */
741 { "see", 0, 0, 0, 4, 0, "" }, /* ndxterm */
742 { "seglistitem",0, 0, 0, 9, 0, "" }, /* seg */
743 { "segmentedlist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
744 { "seg", 0, 0, 0, 2, 0, "" }, /* para */
745 { "segtitle", 0, 0, 0, 8, 0, "" }, /* title */
746 { "seriesvolnums", 0, 0, 0, 4, 0, "" }, /* docinfo */
747 { "set", 0, 0, 0, 9, 0, "" }, /* div.title.content */
748 { "setindexinfo",0, 0, 0, 9, 0, "" }, /* graphic */
749 { "setindex", 0, 0, 0, 9, 0, "" }, /* setindexinfo */
750 { "setinfo", 0, 0, 0, 9, 0, "" }, /* graphic */
751 { "sgmltag", 0, 0, 0, 7, 0, "" }, /* smallcptr */
752 { "shortaffil", 0, 0, 0, 4, 0, "" }, /* docinfo */
753 { "shortcut", 0, 0, 0, 9, 0, "" }, /* keycap */
754 { "sidebarinfo",0, 0, 0, 9, 0, "" }, /* graphic */
755 { "sidebar", 0, 0, 0, 9, 0, "" }, /* sidebarinfo */
756 { "simpara", 0, 0, 0, 2, 0, "" }, /* para */
757 { "simplelist", 0, 0, 0, 9, 0, "" }, /* member */
758 { "simplemsgentry", 0, 0, 0, 9, 0, "" }, /* msgtext */
759 { "simplesect", 0, 0, 0, 9, 0, "" }, /* sect.title.content */
760 { "spanspec", 0, 2, 1, 0, 0, "" },
761 { "state", 0, 0, 0, 4, 0, "" }, /* docinfo */
762 { "step", 0, 0, 0, 9, 0, "" }, /* title */
763 { "street", 0, 0, 0, 4, 0, "" }, /* docinfo */
764 { "structfield",0, 0, 0, 7, 0, "" }, /* smallcptr */
765 { "structname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
766 { "subjectset", 0, 0, 0, 9, 0, "" }, /* subject */
767 { "subject", 0, 0, 0, 9, 0, "" }, /* subjectterm */
768 { "subjectterm",0, 0, 0, 1, 0, "" },
769 { "subscript", 0, 0, 0, 1, 0, "" },
770 { "substeps", 0, 0, 0, 9, 0, "" }, /* step */
771 { "subtitle", 0, 0, 0, 8, 0, "" }, /* title */
772 { "superscript", 0, 0, 0, 1, 0, "" },
773 { "surname", 0, 0, 0, 4, 0, "" }, /* docinfo */
774 { "symbol", 0, 0, 0, 7, 0, "" }, /* smallcptr */
775 { "synopfragment", 0, 0, 0, 9, 0, "" }, /* arg */
776 { "synopfragmentref", 0, 0, 0, 1, 0, "" },
777 { "synopsis", 0, 0, 0, 2, 0, "" }, /* para */
778 { "systemitem", 0, 0, 0, 7, 0, "" }, /* smallcptr */
779 { "table", 0, 0, 0, 9, 0, "" }, /* tbl.table.mdl */
780 /* { "%tbl.table.name;", 0, 0, 0, 9, 0, "" },*/ /* tbl.table.mdl */
781 { "tbody", 0, 0, 0, 9, 0, "" }, /* row */
782 { "tbody", 0, 0, 0, 9, 0, "" }, /* row */
783 { "term", 0, 0, 0, 2, 0, "" }, /* para */
784 { "tertiaryie", 0, 0, 0, 4, 0, "" }, /* ndxterm */
785 { "tertiary ", 0, 0, 0, 4, 0, "" }, /* ndxterm */
786 { "textobject", 0, 0, 0, 9, 0, "" }, /* objectinfo */
787 { "tfoot", 0, 0, 0, 9, 0, "" }, /* tbl.hdft.mdl */
788 { "tgroup", 0, 0, 0, 9, 0, "" }, /* tbl.tgroup.mdl */
789 { "tgroup", 0, 0, 0, 9, 0, "" }, /* tbl.tgroup.mdl */
790 { "thead", 0, 0, 0, 9, 0, "" }, /* row */
791 { "thead", 0, 0, 0, 9, 0, "" }, /* tbl.hdft.mdl */
792 { "tip", 0, 0, 0, 9, 0, "" }, /* title */
793 { "titleabbrev",0, 0, 0, 8, 0, "" }, /* title */
794 { "title", 0, 0, 0, 8, 0, "" }, /* title */
795 { "tocback", 0, 0, 0, 2, 0, "" }, /* para */
796 { "toc", 0, 0, 0, 9, 0, "" }, /* bookcomponent.title.content */
797 { "tocchap", 0, 0, 0, 9, 0, "" }, /* tocentry */
798 { "tocentry", 0, 0, 0, 2, 0, "" }, /* para */
799 { "tocfront", 0, 0, 0, 2, 0, "" }, /* para */
800 { "toclevel1", 0, 0, 0, 9, 0, "" }, /* tocentry */
801 { "toclevel2", 0, 0, 0, 9, 0, "" }, /* tocentry */
802 { "toclevel3", 0, 0, 0, 9, 0, "" }, /* tocentry */
803 { "toclevel4", 0, 0, 0, 9, 0, "" }, /* tocentry */
804 { "toclevel5", 0, 0, 0, 9, 0, "" }, /* tocentry */
805 { "tocpart", 0, 0, 0, 9, 0, "" }, /* tocentry */
806 { "token", 0, 0, 0, 7, 0, "" }, /* smallcptr */
807 { "trademark", 0, 0, 0, 1, 0, "" },
808 { "type", 0, 0, 0, 7, 0, "" }, /* smallcptr */
809 { "ulink", 0, 0, 0, 2, 0, "" }, /* para */
810 { "userinput", 0, 0, 0, 9, 0, "" }, /* cptr */
811 { "varargs", 0, 2, 1, 0, 0, "" },
812 { "variablelist",0, 0, 0, 9, 0, "" }, /* formalobject.title.content */
813 { "varlistentry",0, 0, 0, 9, 0, "" }, /* term */
814 { "varname", 0, 0, 0, 7, 0, "" }, /* smallcptr */
815 { "videodata", 0, 2, 1, 0, 0, "" },
816 { "videoobject",0, 0, 0, 9, 0, "" }, /* objectinfo */
817 { "void", 0, 2, 1, 0, 0, "" },
818 { "volumenum", 0, 0, 0, 4, 0, "" }, /* docinfo */
819 { "warning", 0, 0, 0, 9, 0, "" }, /* title */
820 { "wordasword", 0, 0, 0, 3, 0, "" }, /* word */
821 { "xref", 0, 2, 1, 0, 0, "" },
822 { "year", 0, 0, 0, 4, 0, "" }, /* docinfo */
827 * start tags that imply the end of a current element
828 * any tag of each line implies the end of the current element if the type of
829 * that element is in the same line
831 static const char *docbEquEnd
[] = {
832 "dt", "dd", "li", "option", NULL
,
833 "h1", "h2", "h3", "h4", "h5", "h6", NULL
,
834 "ol", "menu", "dir", "address", "pre", "listing", "xmp", NULL
,
840 * according the SGML DTD, HR should be added to the 2nd line above, as it
841 * is not allowed within a H1, H2, H3, etc. But we should tolerate that case
842 * because many documents contain rules in headings...
846 * start tags that imply the end of current element
848 static const char *docbStartClose
[] = {
852 static const char** docbStartCloseIndex
[100];
853 static int docbStartCloseIndexinitialized
= 0;
855 /************************************************************************
857 * functions to handle SGML specific data *
859 ************************************************************************/
864 * Initialize the docbStartCloseIndex for fast lookup of closing tags names.
868 docbInitAutoClose(void) {
871 if (docbStartCloseIndexinitialized
) return;
873 for (indx
= 0;indx
< 100;indx
++) docbStartCloseIndex
[indx
] = NULL
;
875 while ((docbStartClose
[i
] != NULL
) && (indx
< 100 - 1)) {
876 docbStartCloseIndex
[indx
++] = &docbStartClose
[i
];
877 while (docbStartClose
[i
] != NULL
) i
++;
886 * Lookup the SGML tag in the ElementTable
888 * Returns the related docbElemDescPtr or NULL if not found.
890 static docbElemDescPtr
891 docbTagLookup(const xmlChar
*tag
) {
894 for (i
= 0; i
< (sizeof(docbookElementTable
) /
895 sizeof(docbookElementTable
[0]));i
++) {
896 if (xmlStrEqual(tag
, BAD_CAST docbookElementTable
[i
].name
))
897 return(&docbookElementTable
[i
]);
903 * docbCheckAutoClose:
904 * @newtag: The new tag name
905 * @oldtag: The old tag name
907 * Checks whether the new tag is one of the registered valid tags for
909 * Initialize the docbStartCloseIndex for fast lookup of closing tags names.
911 * Returns 0 if no, 1 if yes.
914 docbCheckAutoClose(const xmlChar
*newtag
, const xmlChar
*oldtag
) {
916 const char **closed
= NULL
;
918 if (docbStartCloseIndexinitialized
== 0) docbInitAutoClose();
920 /* inefficient, but not a big deal */
921 for (indx
= 0; indx
< 100;indx
++) {
922 closed
= docbStartCloseIndex
[indx
];
923 if (closed
== NULL
) return(0);
924 if (xmlStrEqual(BAD_CAST
*closed
, newtag
)) break;
927 i
= closed
- docbStartClose
;
929 while (docbStartClose
[i
] != NULL
) {
930 if (xmlStrEqual(BAD_CAST docbStartClose
[i
], oldtag
)) {
939 * docbAutoCloseOnClose:
940 * @ctxt: an SGML parser context
941 * @newtag: The new tag name
943 * The DocBook DTD allows an ending tag to implicitly close other tags.
946 docbAutoCloseOnClose(docbParserCtxtPtr ctxt
, const xmlChar
*newtag
) {
947 docbElemDescPtr info
;
951 if ((newtag
[0] == '/') && (newtag
[1] == 0))
955 xmlGenericError(xmlGenericErrorContext
,"Close of %s stack: %d elements\n", newtag
, ctxt
->nameNr
);
956 for (i
= 0;i
< ctxt
->nameNr
;i
++)
957 xmlGenericError(xmlGenericErrorContext
,"%d : %s\n", i
, ctxt
->nameTab
[i
]);
960 for (i
= (ctxt
->nameNr
- 1);i
>= 0;i
--) {
961 if (xmlStrEqual(newtag
, ctxt
->nameTab
[i
])) break;
965 while (!xmlStrEqual(newtag
, ctxt
->name
)) {
966 info
= docbTagLookup(ctxt
->name
);
967 if ((info
== NULL
) || (info
->endTag
== 1)) {
969 xmlGenericError(xmlGenericErrorContext
,"docbAutoCloseOnClose: %s closes %s\n", newtag
, ctxt
->name
);
972 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
973 ctxt
->sax
->error(ctxt
->userData
,
974 "Opening and ending tag mismatch: %s and %s\n",
976 ctxt
->wellFormed
= 0;
978 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->endElement
!= NULL
))
979 ctxt
->sax
->endElement(ctxt
->userData
, ctxt
->name
);
980 oldname
= docbnamePop(ctxt
);
981 if (oldname
!= NULL
) {
983 xmlGenericError(xmlGenericErrorContext
,"docbAutoCloseOnClose: popped %s\n", oldname
);
992 * @ctxt: an SGML parser context
993 * @newtag: The new tag name or NULL
995 * The DocBook DTD allows a tag to implicitly close other tags.
996 * The list is kept in docbStartClose array. This function is
997 * called when a new tag has been detected and generates the
998 * appropriates closes if possible/needed.
999 * If newtag is NULL this mean we are at the end of the resource
1000 * and we should check
1003 docbAutoClose(docbParserCtxtPtr ctxt
, const xmlChar
*newtag
) {
1005 while ((newtag
!= NULL
) && (ctxt
->name
!= NULL
) &&
1006 (docbCheckAutoClose(newtag
, ctxt
->name
))) {
1008 xmlGenericError(xmlGenericErrorContext
,"docbAutoClose: %s closes %s\n", newtag
, ctxt
->name
);
1010 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->endElement
!= NULL
))
1011 ctxt
->sax
->endElement(ctxt
->userData
, ctxt
->name
);
1012 oldname
= docbnamePop(ctxt
);
1013 if (oldname
!= NULL
) {
1015 xmlGenericError(xmlGenericErrorContext
,"docbAutoClose: popped %s\n", oldname
);
1024 * @doc: the SGML document
1025 * @name: The tag name
1026 * @elem: the SGML element
1028 * The DocBook DTD allows a tag to implicitly close other tags.
1029 * The list is kept in docbStartClose array. This function checks
1030 * if the element or one of it's children would autoclose the
1033 * Returns 1 if autoclose, 0 otherwise
1036 docbAutoCloseTag(docbDocPtr doc
, const xmlChar
*name
, docbNodePtr elem
) {
1039 if (elem
== NULL
) return(1);
1040 if (xmlStrEqual(name
, elem
->name
)) return(0);
1041 if (docbCheckAutoClose(elem
->name
, name
)) return(1);
1042 child
= elem
->children
;
1043 while (child
!= NULL
) {
1044 if (docbAutoCloseTag(doc
, name
, child
)) return(1);
1045 child
= child
->next
;
1050 /************************************************************************
1052 * The list of SGML predefined entities *
1054 ************************************************************************/
1057 static docbEntityDesc
1058 docbookEntitiesTable
[] = {
1060 * the 4 absolute ones, plus apostrophe.
1062 { 0x0026, "amp", "AMPERSAND" },
1063 { 0x003C, "lt", "LESS-THAN SIGN" },
1066 * Converted with VI macros from docbook ent files
1068 { 0x0021, "excl", "EXCLAMATION MARK" },
1069 { 0x0022, "quot", "QUOTATION MARK" },
1070 { 0x0023, "num", "NUMBER SIGN" },
1071 { 0x0024, "dollar", "DOLLAR SIGN" },
1072 { 0x0025, "percnt", "PERCENT SIGN" },
1073 { 0x0027, "apos", "APOSTROPHE" },
1074 { 0x0028, "lpar", "LEFT PARENTHESIS" },
1075 { 0x0029, "rpar", "RIGHT PARENTHESIS" },
1076 { 0x002A, "ast", "ASTERISK OPERATOR" },
1077 { 0x002B, "plus", "PLUS SIGN" },
1078 { 0x002C, "comma", "COMMA" },
1079 { 0x002D, "hyphen", "HYPHEN-MINUS" },
1080 { 0x002E, "period", "FULL STOP" },
1081 { 0x002F, "sol", "SOLIDUS" },
1082 { 0x003A, "colon", "COLON" },
1083 { 0x003B, "semi", "SEMICOLON" },
1084 { 0x003D, "equals", "EQUALS SIGN" },
1085 { 0x003E, "gt", "GREATER-THAN SIGN" },
1086 { 0x003F, "quest", "QUESTION MARK" },
1087 { 0x0040, "commat", "COMMERCIAL AT" },
1088 { 0x005B, "lsqb", "LEFT SQUARE BRACKET" },
1089 { 0x005C, "bsol", "REVERSE SOLIDUS" },
1090 { 0x005D, "rsqb", "RIGHT SQUARE BRACKET" },
1091 { 0x005E, "circ", "RING OPERATOR" },
1092 { 0x005F, "lowbar", "LOW LINE" },
1093 { 0x0060, "grave", "GRAVE ACCENT" },
1094 { 0x007B, "lcub", "LEFT CURLY BRACKET" },
1095 { 0x007C, "verbar", "VERTICAL LINE" },
1096 { 0x007D, "rcub", "RIGHT CURLY BRACKET" },
1097 { 0x00A0, "nbsp", "NO-BREAK SPACE" },
1098 { 0x00A1, "iexcl", "INVERTED EXCLAMATION MARK" },
1099 { 0x00A2, "cent", "CENT SIGN" },
1100 { 0x00A3, "pound", "POUND SIGN" },
1101 { 0x00A4, "curren", "CURRENCY SIGN" },
1102 { 0x00A5, "yen", "YEN SIGN" },
1103 { 0x00A6, "brvbar", "BROKEN BAR" },
1104 { 0x00A7, "sect", "SECTION SIGN" },
1105 { 0x00A8, "die", "" },
1106 { 0x00A8, "Dot", "" },
1107 { 0x00A8, "uml", "" },
1108 { 0x00A9, "copy", "COPYRIGHT SIGN" },
1109 { 0x00AA, "ordf", "FEMININE ORDINAL INDICATOR" },
1110 { 0x00AB, "laquo", "LEFT-POINTING DOUBLE ANGLE QUOTATION MARK" },
1111 { 0x00AC, "not", "NOT SIGN" },
1112 { 0x00AD, "shy", "SOFT HYPHEN" },
1113 { 0x00AE, "reg", "REG TRADE MARK SIGN" },
1114 { 0x00AF, "macr", "MACRON" },
1115 { 0x00B0, "deg", "DEGREE SIGN" },
1116 { 0x00B1, "plusmn", "PLUS-MINUS SIGN" },
1117 { 0x00B2, "sup2", "SUPERSCRIPT TWO" },
1118 { 0x00B3, "sup3", "SUPERSCRIPT THREE" },
1119 { 0x00B4, "acute", "ACUTE ACCENT" },
1120 { 0x00B5, "micro", "MICRO SIGN" },
1121 { 0x00B6, "para", "PILCROW SIGN" },
1122 { 0x00B7, "middot", "MIDDLE DOT" },
1123 { 0x00B8, "cedil", "CEDILLA" },
1124 { 0x00B9, "sup1", "SUPERSCRIPT ONE" },
1125 { 0x00BA, "ordm", "MASCULINE ORDINAL INDICATOR" },
1126 { 0x00BB, "raquo", "RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK" },
1127 { 0x00BC, "frac14", "VULGAR FRACTION ONE QUARTER" },
1128 { 0x00BD, "frac12", "VULGAR FRACTION ONE HALF" },
1129 { 0x00BD, "half", "VULGAR FRACTION ONE HALF" },
1130 { 0x00BE, "frac34", "VULGAR FRACTION THREE QUARTERS" },
1131 { 0x00BF, "iquest", "INVERTED QUESTION MARK" },
1132 { 0x00C0, "Agrave", "LATIN CAPITAL LETTER A WITH GRAVE" },
1133 { 0x00C1, "Aacute", "LATIN CAPITAL LETTER A WITH ACUTE" },
1134 { 0x00C2, "Acirc", "LATIN CAPITAL LETTER A WITH CIRCUMFLEX" },
1135 { 0x00C3, "Atilde", "LATIN CAPITAL LETTER A WITH TILDE" },
1136 { 0x00C4, "Auml", "LATIN CAPITAL LETTER A WITH DIAERESIS" },
1137 { 0x00C5, "Aring", "LATIN CAPITAL LETTER A WITH RING ABOVE" },
1138 { 0x00C6, "AElig", "LATIN CAPITAL LETTER AE" },
1139 { 0x00C7, "Ccedil", "LATIN CAPITAL LETTER C WITH CEDILLA" },
1140 { 0x00C8, "Egrave", "LATIN CAPITAL LETTER E WITH GRAVE" },
1141 { 0x00C9, "Eacute", "LATIN CAPITAL LETTER E WITH ACUTE" },
1142 { 0x00CA, "Ecirc", "LATIN CAPITAL LETTER E WITH CIRCUMFLEX" },
1143 { 0x00CB, "Euml", "LATIN CAPITAL LETTER E WITH DIAERESIS" },
1144 { 0x00CC, "Igrave", "LATIN CAPITAL LETTER I WITH GRAVE" },
1145 { 0x00CD, "Iacute", "LATIN CAPITAL LETTER I WITH ACUTE" },
1146 { 0x00CE, "Icirc", "LATIN CAPITAL LETTER I WITH CIRCUMFLEX" },
1147 { 0x00CF, "Iuml", "LATIN CAPITAL LETTER I WITH DIAERESIS" },
1148 { 0x00D0, "ETH", "LATIN CAPITAL LETTER ETH" },
1149 { 0x00D1, "Ntilde", "LATIN CAPITAL LETTER N WITH TILDE" },
1150 { 0x00D2, "Ograve", "LATIN CAPITAL LETTER O WITH GRAVE" },
1151 { 0x00D3, "Oacute", "LATIN CAPITAL LETTER O WITH ACUTE" },
1152 { 0x00D4, "Ocirc", "LATIN CAPITAL LETTER O WITH CIRCUMFLEX" },
1153 { 0x00D5, "Otilde", "LATIN CAPITAL LETTER O WITH TILDE" },
1154 { 0x00D6, "Ouml", "LATIN CAPITAL LETTER O WITH DIAERESIS" },
1155 { 0x00D7, "times", "MULTIPLICATION SIGN" },
1156 { 0x00D8, "Oslash", "LATIN CAPITAL LETTER O WITH STROKE" },
1157 { 0x00D9, "Ugrave", "LATIN CAPITAL LETTER U WITH GRAVE" },
1158 { 0x00DA, "Uacute", "LATIN CAPITAL LETTER U WITH ACUTE" },
1159 { 0x00DB, "Ucirc", "LATIN CAPITAL LETTER U WITH CIRCUMFLEX" },
1160 { 0x00DC, "Uuml", "LATIN CAPITAL LETTER U WITH DIAERESIS" },
1161 { 0x00DD, "Yacute", "LATIN CAPITAL LETTER Y WITH ACUTE" },
1162 { 0x00DE, "THORN", "LATIN CAPITAL LETTER THORN" },
1163 { 0x00DF, "szlig", "LATIN SMALL LETTER SHARP S" },
1164 { 0x00E0, "agrave", "LATIN SMALL LETTER A WITH GRAVE" },
1165 { 0x00E1, "aacute", "LATIN SMALL LETTER A WITH ACUTE" },
1166 { 0x00E2, "acirc", "LATIN SMALL LETTER A WITH CIRCUMFLEX" },
1167 { 0x00E3, "atilde", "LATIN SMALL LETTER A WITH TILDE" },
1168 { 0x00E4, "auml", "LATIN SMALL LETTER A WITH DIAERESIS" },
1169 { 0x00E5, "aring", "LATIN SMALL LETTER A WITH RING ABOVE" },
1170 { 0x00E6, "aelig", "LATIN SMALL LETTER AE" },
1171 { 0x00E7, "ccedil", "LATIN SMALL LETTER C WITH CEDILLA" },
1172 { 0x00E8, "egrave", "LATIN SMALL LETTER E WITH GRAVE" },
1173 { 0x00E9, "eacute", "LATIN SMALL LETTER E WITH ACUTE" },
1174 { 0x00EA, "ecirc", "LATIN SMALL LETTER E WITH CIRCUMFLEX" },
1175 { 0x00EB, "euml", "LATIN SMALL LETTER E WITH DIAERESIS" },
1176 { 0x00EC, "igrave", "LATIN SMALL LETTER I WITH GRAVE" },
1177 { 0x00ED, "iacute", "LATIN SMALL LETTER I WITH ACUTE" },
1178 { 0x00EE, "icirc", "LATIN SMALL LETTER I WITH CIRCUMFLEX" },
1179 { 0x00EF, "iuml", "LATIN SMALL LETTER I WITH DIAERESIS" },
1180 { 0x00F0, "eth", "LATIN SMALL LETTER ETH" },
1181 { 0x00F1, "ntilde", "LATIN SMALL LETTER N WITH TILDE" },
1182 { 0x00F2, "ograve", "LATIN SMALL LETTER O WITH GRAVE" },
1183 { 0x00F3, "oacute", "LATIN SMALL LETTER O WITH ACUTE" },
1184 { 0x00F4, "ocirc", "LATIN SMALL LETTER O WITH CIRCUMFLEX" },
1185 { 0x00F5, "otilde", "LATIN SMALL LETTER O WITH TILDE" },
1186 { 0x00F6, "ouml", "LATIN SMALL LETTER O WITH DIAERESIS" },
1187 { 0x00F7, "divide", "DIVISION SIGN" },
1188 { 0x00F8, "oslash", "CIRCLED DIVISION SLASH" },
1189 { 0x00F9, "ugrave", "LATIN SMALL LETTER U WITH GRAVE" },
1190 { 0x00FA, "uacute", "LATIN SMALL LETTER U WITH ACUTE" },
1191 { 0x00FB, "ucirc", "LATIN SMALL LETTER U WITH CIRCUMFLEX" },
1192 { 0x00FC, "uuml", "LATIN SMALL LETTER U WITH DIAERESIS" },
1193 { 0x00FD, "yacute", "LATIN SMALL LETTER Y WITH ACUTE" },
1194 { 0x00FE, "thorn", "LATIN SMALL LETTER THORN" },
1195 { 0x00FF, "yuml", "LATIN SMALL LETTER Y WITH DIAERESIS" },
1196 { 0x0100, "Amacr", "LATIN CAPITAL LETTER A WITH MACRON" },
1197 { 0x0101, "amacr", "LATIN SMALL LETTER A WITH MACRON" },
1198 { 0x0102, "Abreve", "LATIN CAPITAL LETTER A WITH BREVE" },
1199 { 0x0103, "abreve", "LATIN SMALL LETTER A WITH BREVE" },
1200 { 0x0104, "Aogon", "LATIN CAPITAL LETTER A WITH OGONEK" },
1201 { 0x0105, "aogon", "LATIN SMALL LETTER A WITH OGONEK" },
1202 { 0x0106, "Cacute", "LATIN CAPITAL LETTER C WITH ACUTE" },
1203 { 0x0107, "cacute", "LATIN SMALL LETTER C WITH ACUTE" },
1204 { 0x0108, "Ccirc", "LATIN CAPITAL LETTER C WITH CIRCUMFLEX" },
1205 { 0x0109, "ccirc", "LATIN SMALL LETTER C WITH CIRCUMFLEX" },
1206 { 0x010A, "Cdot", "LATIN CAPITAL LETTER C WITH DOT ABOVE" },
1207 { 0x010B, "cdot", "DOT OPERATOR" },
1208 { 0x010C, "Ccaron", "LATIN CAPITAL LETTER C WITH CARON" },
1209 { 0x010D, "ccaron", "LATIN SMALL LETTER C WITH CARON" },
1210 { 0x010E, "Dcaron", "LATIN CAPITAL LETTER D WITH CARON" },
1211 { 0x010F, "dcaron", "LATIN SMALL LETTER D WITH CARON" },
1212 { 0x0110, "Dstrok", "LATIN CAPITAL LETTER D WITH STROKE" },
1213 { 0x0111, "dstrok", "LATIN SMALL LETTER D WITH STROKE" },
1214 { 0x0112, "Emacr", "LATIN CAPITAL LETTER E WITH MACRON" },
1215 { 0x0113, "emacr", "LATIN SMALL LETTER E WITH MACRON" },
1216 { 0x0116, "Edot", "LATIN CAPITAL LETTER E WITH DOT ABOVE" },
1217 { 0x0117, "edot", "LATIN SMALL LETTER E WITH DOT ABOVE" },
1218 { 0x0118, "Eogon", "LATIN CAPITAL LETTER E WITH OGONEK" },
1219 { 0x0119, "eogon", "LATIN SMALL LETTER E WITH OGONEK" },
1220 { 0x011A, "Ecaron", "LATIN CAPITAL LETTER E WITH CARON" },
1221 { 0x011B, "ecaron", "LATIN SMALL LETTER E WITH CARON" },
1222 { 0x011C, "Gcirc", "LATIN CAPITAL LETTER G WITH CIRCUMFLEX" },
1223 { 0x011D, "gcirc", "LATIN SMALL LETTER G WITH CIRCUMFLEX" },
1224 { 0x011E, "Gbreve", "LATIN CAPITAL LETTER G WITH BREVE" },
1225 { 0x011F, "gbreve", "LATIN SMALL LETTER G WITH BREVE" },
1226 { 0x0120, "Gdot", "LATIN CAPITAL LETTER G WITH DOT ABOVE" },
1227 { 0x0121, "gdot", "LATIN SMALL LETTER G WITH DOT ABOVE" },
1228 { 0x0122, "Gcedil", "LATIN CAPITAL LETTER G WITH CEDILLA" },
1229 { 0x0124, "Hcirc", "LATIN CAPITAL LETTER H WITH CIRCUMFLEX" },
1230 { 0x0125, "hcirc", "LATIN SMALL LETTER H WITH CIRCUMFLEX" },
1231 { 0x0126, "Hstrok", "LATIN CAPITAL LETTER H WITH STROKE" },
1232 { 0x0127, "hstrok", "LATIN SMALL LETTER H WITH STROKE" },
1233 { 0x0128, "Itilde", "LATIN CAPITAL LETTER I WITH TILDE" },
1234 { 0x0129, "itilde", "LATIN SMALL LETTER I WITH TILDE" },
1235 { 0x012A, "Imacr", "LATIN CAPITAL LETTER I WITH MACRON" },
1236 { 0x012B, "imacr", "LATIN SMALL LETTER I WITH MACRON" },
1237 { 0x012E, "Iogon", "LATIN CAPITAL LETTER I WITH OGONEK" },
1238 { 0x012F, "iogon", "LATIN SMALL LETTER I WITH OGONEK" },
1239 { 0x0130, "Idot", "LATIN CAPITAL LETTER I WITH DOT ABOVE" },
1240 { 0x0131, "inodot", "LATIN SMALL LETTER DOTLESS I" },
1241 { 0x0131, "inodot", "LATIN SMALL LETTER DOTLESS I" },
1242 { 0x0132, "IJlig", "LATIN CAPITAL LIGATURE IJ" },
1243 { 0x0133, "ijlig", "LATIN SMALL LIGATURE IJ" },
1244 { 0x0134, "Jcirc", "LATIN CAPITAL LETTER J WITH CIRCUMFLEX" },
1245 { 0x0135, "jcirc", "LATIN SMALL LETTER J WITH CIRCUMFLEX" },
1246 { 0x0136, "Kcedil", "LATIN CAPITAL LETTER K WITH CEDILLA" },
1247 { 0x0137, "kcedil", "LATIN SMALL LETTER K WITH CEDILLA" },
1248 { 0x0138, "kgreen", "LATIN SMALL LETTER KRA" },
1249 { 0x0139, "Lacute", "LATIN CAPITAL LETTER L WITH ACUTE" },
1250 { 0x013A, "lacute", "LATIN SMALL LETTER L WITH ACUTE" },
1251 { 0x013B, "Lcedil", "LATIN CAPITAL LETTER L WITH CEDILLA" },
1252 { 0x013C, "lcedil", "LATIN SMALL LETTER L WITH CEDILLA" },
1253 { 0x013D, "Lcaron", "LATIN CAPITAL LETTER L WITH CARON" },
1254 { 0x013E, "lcaron", "LATIN SMALL LETTER L WITH CARON" },
1255 { 0x013F, "Lmidot", "LATIN CAPITAL LETTER L WITH MIDDLE DOT" },
1256 { 0x0140, "lmidot", "LATIN SMALL LETTER L WITH MIDDLE DOT" },
1257 { 0x0141, "Lstrok", "LATIN CAPITAL LETTER L WITH STROKE" },
1258 { 0x0142, "lstrok", "LATIN SMALL LETTER L WITH STROKE" },
1259 { 0x0143, "Nacute", "LATIN CAPITAL LETTER N WITH ACUTE" },
1260 { 0x0144, "nacute", "LATIN SMALL LETTER N WITH ACUTE" },
1261 { 0x0145, "Ncedil", "LATIN CAPITAL LETTER N WITH CEDILLA" },
1262 { 0x0146, "ncedil", "LATIN SMALL LETTER N WITH CEDILLA" },
1263 { 0x0147, "Ncaron", "LATIN CAPITAL LETTER N WITH CARON" },
1264 { 0x0148, "ncaron", "LATIN SMALL LETTER N WITH CARON" },
1265 { 0x0149, "napos", "LATIN SMALL LETTER N PRECEDED BY APOSTROPHE" },
1266 { 0x014A, "ENG", "LATIN CAPITAL LETTER ENG" },
1267 { 0x014B, "eng", "LATIN SMALL LETTER ENG" },
1268 { 0x014C, "Omacr", "LATIN CAPITAL LETTER O WITH MACRON" },
1269 { 0x014D, "omacr", "LATIN SMALL LETTER O WITH MACRON" },
1270 { 0x0150, "Odblac", "LATIN CAPITAL LETTER O WITH DOUBLE ACUTE" },
1271 { 0x0151, "odblac", "LATIN SMALL LETTER O WITH DOUBLE ACUTE" },
1272 { 0x0152, "OElig", "LATIN CAPITAL LIGATURE OE" },
1273 { 0x0153, "oelig", "LATIN SMALL LIGATURE OE" },
1274 { 0x0154, "Racute", "LATIN CAPITAL LETTER R WITH ACUTE" },
1275 { 0x0155, "racute", "LATIN SMALL LETTER R WITH ACUTE" },
1276 { 0x0156, "Rcedil", "LATIN CAPITAL LETTER R WITH CEDILLA" },
1277 { 0x0157, "rcedil", "LATIN SMALL LETTER R WITH CEDILLA" },
1278 { 0x0158, "Rcaron", "LATIN CAPITAL LETTER R WITH CARON" },
1279 { 0x0159, "rcaron", "LATIN SMALL LETTER R WITH CARON" },
1280 { 0x015A, "Sacute", "LATIN CAPITAL LETTER S WITH ACUTE" },
1281 { 0x015B, "sacute", "LATIN SMALL LETTER S WITH ACUTE" },
1282 { 0x015C, "Scirc", "LATIN CAPITAL LETTER S WITH CIRCUMFLEX" },
1283 { 0x015D, "scirc", "LATIN SMALL LETTER S WITH CIRCUMFLEX" },
1284 { 0x015E, "Scedil", "LATIN CAPITAL LETTER S WITH CEDILLA" },
1285 { 0x015F, "scedil", "LATIN SMALL LETTER S WITH CEDILLA" },
1286 { 0x0160, "Scaron", "LATIN CAPITAL LETTER S WITH CARON" },
1287 { 0x0161, "scaron", "LATIN SMALL LETTER S WITH CARON" },
1288 { 0x0162, "Tcedil", "LATIN CAPITAL LETTER T WITH CEDILLA" },
1289 { 0x0163, "tcedil", "LATIN SMALL LETTER T WITH CEDILLA" },
1290 { 0x0164, "Tcaron", "LATIN CAPITAL LETTER T WITH CARON" },
1291 { 0x0165, "tcaron", "LATIN SMALL LETTER T WITH CARON" },
1292 { 0x0166, "Tstrok", "LATIN CAPITAL LETTER T WITH STROKE" },
1293 { 0x0167, "tstrok", "LATIN SMALL LETTER T WITH STROKE" },
1294 { 0x0168, "Utilde", "LATIN CAPITAL LETTER U WITH TILDE" },
1295 { 0x0169, "utilde", "LATIN SMALL LETTER U WITH TILDE" },
1296 { 0x016A, "Umacr", "LATIN CAPITAL LETTER U WITH MACRON" },
1297 { 0x016B, "umacr", "LATIN SMALL LETTER U WITH MACRON" },
1298 { 0x016C, "Ubreve", "LATIN CAPITAL LETTER U WITH BREVE" },
1299 { 0x016D, "ubreve", "LATIN SMALL LETTER U WITH BREVE" },
1300 { 0x016E, "Uring", "LATIN CAPITAL LETTER U WITH RING ABOVE" },
1301 { 0x016F, "uring", "LATIN SMALL LETTER U WITH RING ABOVE" },
1302 { 0x0170, "Udblac", "LATIN CAPITAL LETTER U WITH DOUBLE ACUTE" },
1303 { 0x0171, "udblac", "LATIN SMALL LETTER U WITH DOUBLE ACUTE" },
1304 { 0x0172, "Uogon", "LATIN CAPITAL LETTER U WITH OGONEK" },
1305 { 0x0173, "uogon", "LATIN SMALL LETTER U WITH OGONEK" },
1306 { 0x0174, "Wcirc", "LATIN CAPITAL LETTER W WITH CIRCUMFLEX" },
1307 { 0x0175, "wcirc", "LATIN SMALL LETTER W WITH CIRCUMFLEX" },
1308 { 0x0176, "Ycirc", "LATIN CAPITAL LETTER Y WITH CIRCUMFLEX" },
1309 { 0x0177, "ycirc", "LATIN SMALL LETTER Y WITH CIRCUMFLEX" },
1310 { 0x0178, "Yuml", "LATIN CAPITAL LETTER Y WITH DIAERESIS" },
1311 { 0x0179, "Zacute", "LATIN CAPITAL LETTER Z WITH ACUTE" },
1312 { 0x017A, "zacute", "LATIN SMALL LETTER Z WITH ACUTE" },
1313 { 0x017B, "Zdot", "LATIN CAPITAL LETTER Z WITH DOT ABOVE" },
1314 { 0x017C, "zdot", "LATIN SMALL LETTER Z WITH DOT ABOVE" },
1315 { 0x017D, "Zcaron", "LATIN CAPITAL LETTER Z WITH CARON" },
1316 { 0x017E, "zcaron", "LATIN SMALL LETTER Z WITH CARON" },
1317 { 0x0192, "fnof", "LATIN SMALL LETTER F WITH HOOK" },
1318 { 0x01F5, "gacute", "LATIN SMALL LETTER G WITH ACUTE" },
1319 { 0x02C7, "caron", "CARON" },
1320 { 0x02D8, "breve", "BREVE" },
1321 { 0x02D9, "dot", "DOT ABOVE" },
1322 { 0x02DA, "ring", "RING ABOVE" },
1323 { 0x02DB, "ogon", "OGONEK" },
1324 { 0x02DC, "tilde", "TILDE" },
1325 { 0x02DD, "dblac", "DOUBLE ACUTE ACCENT" },
1326 { 0x0386, "Aacgr", "GREEK CAPITAL LETTER ALPHA WITH TONOS" },
1327 { 0x0388, "Eacgr", "GREEK CAPITAL LETTER EPSILON WITH TONOS" },
1328 { 0x0389, "EEacgr", "GREEK CAPITAL LETTER ETA WITH TONOS" },
1329 { 0x038A, "Iacgr", "GREEK CAPITAL LETTER IOTA WITH TONOS" },
1330 { 0x038C, "Oacgr", "GREEK CAPITAL LETTER OMICRON WITH TONOS" },
1331 { 0x038E, "Uacgr", "GREEK CAPITAL LETTER UPSILON WITH TONOS" },
1332 { 0x038F, "OHacgr", "GREEK CAPITAL LETTER OMEGA WITH TONOS" },
1333 { 0x0390, "idiagr", "GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS" },
1334 { 0x0391, "Agr", "GREEK CAPITAL LETTER ALPHA" },
1335 { 0x0392, "Bgr", "GREEK CAPITAL LETTER BETA" },
1336 { 0x0393, "b.Gamma", "GREEK CAPITAL LETTER GAMMA" },
1337 { 0x0393, "Gamma", "GREEK CAPITAL LETTER GAMMA" },
1338 { 0x0393, "Ggr", "GREEK CAPITAL LETTER GAMMA" },
1339 { 0x0394, "b.Delta", "GREEK CAPITAL LETTER DELTA" },
1340 { 0x0394, "Delta", "GREEK CAPITAL LETTER DELTA" },
1341 { 0x0394, "Dgr", "GREEK CAPITAL LETTER DELTA" },
1342 { 0x0395, "Egr", "GREEK CAPITAL LETTER EPSILON" },
1343 { 0x0396, "Zgr", "GREEK CAPITAL LETTER ZETA" },
1344 { 0x0397, "EEgr", "GREEK CAPITAL LETTER ETA" },
1345 { 0x0398, "b.Theta", "GREEK CAPITAL LETTER THETA" },
1346 { 0x0398, "Theta", "GREEK CAPITAL LETTER THETA" },
1347 { 0x0398, "THgr", "GREEK CAPITAL LETTER THETA" },
1348 { 0x0399, "Igr", "GREEK CAPITAL LETTER IOTA" },
1349 { 0x039A, "Kgr", "GREEK CAPITAL LETTER KAPPA" },
1350 { 0x039B, "b.Lambda", "GREEK CAPITAL LETTER LAMDA" },
1351 { 0x039B, "Lambda", "GREEK CAPITAL LETTER LAMDA" },
1352 { 0x039B, "Lgr", "GREEK CAPITAL LETTER LAMDA" },
1353 { 0x039C, "Mgr", "GREEK CAPITAL LETTER MU" },
1354 { 0x039D, "Ngr", "GREEK CAPITAL LETTER NU" },
1355 { 0x039E, "b.Xi", "GREEK CAPITAL LETTER XI" },
1356 { 0x039E, "Xgr", "GREEK CAPITAL LETTER XI" },
1357 { 0x039E, "Xi", "GREEK CAPITAL LETTER XI" },
1358 { 0x039F, "Ogr", "GREEK CAPITAL LETTER OMICRON" },
1359 { 0x03A0, "b.Pi", "GREEK CAPITAL LETTER PI" },
1360 { 0x03A0, "Pgr", "GREEK CAPITAL LETTER PI" },
1361 { 0x03A0, "Pi", "GREEK CAPITAL LETTER PI" },
1362 { 0x03A1, "Rgr", "GREEK CAPITAL LETTER RHO" },
1363 { 0x03A3, "b.Sigma", "GREEK CAPITAL LETTER SIGMA" },
1364 { 0x03A3, "Sgr", "GREEK CAPITAL LETTER SIGMA" },
1365 { 0x03A3, "Sigma", "GREEK CAPITAL LETTER SIGMA" },
1366 { 0x03A4, "Tgr", "GREEK CAPITAL LETTER TAU" },
1367 { 0x03A5, "Ugr", "" },
1368 { 0x03A6, "b.Phi", "GREEK CAPITAL LETTER PHI" },
1369 { 0x03A6, "PHgr", "GREEK CAPITAL LETTER PHI" },
1370 { 0x03A6, "Phi", "GREEK CAPITAL LETTER PHI" },
1371 { 0x03A7, "KHgr", "GREEK CAPITAL LETTER CHI" },
1372 { 0x03A8, "b.Psi", "GREEK CAPITAL LETTER PSI" },
1373 { 0x03A8, "PSgr", "GREEK CAPITAL LETTER PSI" },
1374 { 0x03A8, "Psi", "GREEK CAPITAL LETTER PSI" },
1375 { 0x03A9, "b.Omega", "GREEK CAPITAL LETTER OMEGA" },
1376 { 0x03A9, "OHgr", "GREEK CAPITAL LETTER OMEGA" },
1377 { 0x03A9, "Omega", "GREEK CAPITAL LETTER OMEGA" },
1378 { 0x03AA, "Idigr", "GREEK CAPITAL LETTER IOTA WITH DIALYTIKA" },
1379 { 0x03AB, "Udigr", "GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA" },
1380 { 0x03AC, "aacgr", "GREEK SMALL LETTER ALPHA WITH TONOS" },
1381 { 0x03AD, "eacgr", "GREEK SMALL LETTER EPSILON WITH TONOS" },
1382 { 0x03AE, "eeacgr", "GREEK SMALL LETTER ETA WITH TONOS" },
1383 { 0x03AF, "iacgr", "GREEK SMALL LETTER IOTA WITH TONOS" },
1384 { 0x03B0, "udiagr", "GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS" },
1385 { 0x03B1, "agr", "" },
1386 { 0x03B1, "alpha", "" },
1387 { 0x03B1, "b.alpha", "" },
1388 { 0x03B2, "b.beta", "GREEK SMALL LETTER BETA" },
1389 { 0x03B2, "beta", "GREEK SMALL LETTER BETA" },
1390 { 0x03B2, "bgr", "GREEK SMALL LETTER BETA" },
1391 { 0x03B3, "b.gamma", "GREEK SMALL LETTER GAMMA" },
1392 { 0x03B3, "gamma", "GREEK SMALL LETTER GAMMA" },
1393 { 0x03B3, "ggr", "GREEK SMALL LETTER GAMMA" },
1394 { 0x03B4, "b.delta", "GREEK SMALL LETTER DELTA" },
1395 { 0x03B4, "delta", "GREEK SMALL LETTER DELTA" },
1396 { 0x03B4, "dgr", "GREEK SMALL LETTER DELTA" },
1397 { 0x03B5, "b.epsi", "" },
1398 { 0x03B5, "b.epsis", "" },
1399 { 0x03B5, "b.epsiv", "" },
1400 { 0x03B5, "egr", "" },
1401 { 0x03B5, "epsiv", "" },
1402 { 0x03B6, "b.zeta", "GREEK SMALL LETTER ZETA" },
1403 { 0x03B6, "zeta", "GREEK SMALL LETTER ZETA" },
1404 { 0x03B6, "zgr", "GREEK SMALL LETTER ZETA" },
1405 { 0x03B7, "b.eta", "GREEK SMALL LETTER ETA" },
1406 { 0x03B7, "eegr", "GREEK SMALL LETTER ETA" },
1407 { 0x03B7, "eta", "GREEK SMALL LETTER ETA" },
1408 { 0x03B8, "b.thetas", "" },
1409 { 0x03B8, "thetas", "" },
1410 { 0x03B8, "thgr", "" },
1411 { 0x03B9, "b.iota", "GREEK SMALL LETTER IOTA" },
1412 { 0x03B9, "igr", "GREEK SMALL LETTER IOTA" },
1413 { 0x03B9, "iota", "GREEK SMALL LETTER IOTA" },
1414 { 0x03BA, "b.kappa", "GREEK SMALL LETTER KAPPA" },
1415 { 0x03BA, "kappa", "GREEK SMALL LETTER KAPPA" },
1416 { 0x03BA, "kgr", "GREEK SMALL LETTER KAPPA" },
1417 { 0x03BB, "b.lambda", "GREEK SMALL LETTER LAMDA" },
1418 { 0x03BB, "lambda", "GREEK SMALL LETTER LAMDA" },
1419 { 0x03BB, "lgr", "GREEK SMALL LETTER LAMDA" },
1420 { 0x03BC, "b.mu", "GREEK SMALL LETTER MU" },
1421 { 0x03BC, "mgr", "GREEK SMALL LETTER MU" },
1422 { 0x03BC, "mu", "GREEK SMALL LETTER MU" },
1423 { 0x03BD, "b.nu", "GREEK SMALL LETTER NU" },
1424 { 0x03BD, "ngr", "GREEK SMALL LETTER NU" },
1425 { 0x03BD, "nu", "GREEK SMALL LETTER NU" },
1426 { 0x03BE, "b.xi", "GREEK SMALL LETTER XI" },
1427 { 0x03BE, "xgr", "GREEK SMALL LETTER XI" },
1428 { 0x03BE, "xi", "GREEK SMALL LETTER XI" },
1429 { 0x03BF, "ogr", "GREEK SMALL LETTER OMICRON" },
1430 { 0x03C0, "b.pi", "GREEK SMALL LETTER PI" },
1431 { 0x03C0, "pgr", "GREEK SMALL LETTER PI" },
1432 { 0x03C0, "pi", "GREEK SMALL LETTER PI" },
1433 { 0x03C1, "b.rho", "GREEK SMALL LETTER RHO" },
1434 { 0x03C1, "rgr", "GREEK SMALL LETTER RHO" },
1435 { 0x03C1, "rho", "GREEK SMALL LETTER RHO" },
1436 { 0x03C2, "b.sigmav", "" },
1437 { 0x03C2, "sfgr", "" },
1438 { 0x03C2, "sigmav", "" },
1439 { 0x03C3, "b.sigma", "GREEK SMALL LETTER SIGMA" },
1440 { 0x03C3, "sgr", "GREEK SMALL LETTER SIGMA" },
1441 { 0x03C3, "sigma", "GREEK SMALL LETTER SIGMA" },
1442 { 0x03C4, "b.tau", "GREEK SMALL LETTER TAU" },
1443 { 0x03C4, "tau", "GREEK SMALL LETTER TAU" },
1444 { 0x03C4, "tgr", "GREEK SMALL LETTER TAU" },
1445 { 0x03C5, "b.upsi", "GREEK SMALL LETTER UPSILON" },
1446 { 0x03C5, "ugr", "GREEK SMALL LETTER UPSILON" },
1447 { 0x03C5, "upsi", "GREEK SMALL LETTER UPSILON" },
1448 { 0x03C6, "b.phis", "GREEK SMALL LETTER PHI" },
1449 { 0x03C6, "phgr", "GREEK SMALL LETTER PHI" },
1450 { 0x03C6, "phis", "GREEK SMALL LETTER PHI" },
1451 { 0x03C7, "b.chi", "GREEK SMALL LETTER CHI" },
1452 { 0x03C7, "chi", "GREEK SMALL LETTER CHI" },
1453 { 0x03C7, "khgr", "GREEK SMALL LETTER CHI" },
1454 { 0x03C8, "b.psi", "GREEK SMALL LETTER PSI" },
1455 { 0x03C8, "psgr", "GREEK SMALL LETTER PSI" },
1456 { 0x03C8, "psi", "GREEK SMALL LETTER PSI" },
1457 { 0x03C9, "b.omega", "GREEK SMALL LETTER OMEGA" },
1458 { 0x03C9, "ohgr", "GREEK SMALL LETTER OMEGA" },
1459 { 0x03C9, "omega", "GREEK SMALL LETTER OMEGA" },
1460 { 0x03CA, "idigr", "GREEK SMALL LETTER IOTA WITH DIALYTIKA" },
1461 { 0x03CB, "udigr", "GREEK SMALL LETTER UPSILON WITH DIALYTIKA" },
1462 { 0x03CC, "oacgr", "GREEK SMALL LETTER OMICRON WITH TONOS" },
1463 { 0x03CD, "uacgr", "GREEK SMALL LETTER UPSILON WITH TONOS" },
1464 { 0x03CE, "ohacgr", "GREEK SMALL LETTER OMEGA WITH TONOS" },
1465 { 0x03D1, "b.thetav", "" },
1466 { 0x03D1, "thetav", "" },
1467 { 0x03D2, "b.Upsi", "" },
1468 { 0x03D2, "Upsi", "" },
1469 { 0x03D5, "b.phiv", "GREEK PHI SYMBOL" },
1470 { 0x03D5, "phiv", "GREEK PHI SYMBOL" },
1471 { 0x03D6, "b.piv", "GREEK PI SYMBOL" },
1472 { 0x03D6, "piv", "GREEK PI SYMBOL" },
1473 { 0x03DC, "b.gammad", "GREEK LETTER DIGAMMA" },
1474 { 0x03DC, "gammad", "GREEK LETTER DIGAMMA" },
1475 { 0x03F0, "b.kappav", "GREEK KAPPA SYMBOL" },
1476 { 0x03F0, "kappav", "GREEK KAPPA SYMBOL" },
1477 { 0x03F1, "b.rhov", "GREEK RHO SYMBOL" },
1478 { 0x03F1, "rhov", "GREEK RHO SYMBOL" },
1479 { 0x0401, "IOcy", "CYRILLIC CAPITAL LETTER IO" },
1480 { 0x0402, "DJcy", "CYRILLIC CAPITAL LETTER DJE" },
1481 { 0x0403, "GJcy", "CYRILLIC CAPITAL LETTER GJE" },
1482 { 0x0404, "Jukcy", "CYRILLIC CAPITAL LETTER UKRAINIAN IE" },
1483 { 0x0405, "DScy", "CYRILLIC CAPITAL LETTER DZE" },
1484 { 0x0406, "Iukcy", "CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I" },
1485 { 0x0407, "YIcy", "CYRILLIC CAPITAL LETTER YI" },
1486 { 0x0408, "Jsercy", "CYRILLIC CAPITAL LETTER JE" },
1487 { 0x0409, "LJcy", "CYRILLIC CAPITAL LETTER LJE" },
1488 { 0x040A, "NJcy", "CYRILLIC CAPITAL LETTER NJE" },
1489 { 0x040B, "TSHcy", "CYRILLIC CAPITAL LETTER TSHE" },
1490 { 0x040C, "KJcy", "CYRILLIC CAPITAL LETTER KJE" },
1491 { 0x040E, "Ubrcy", "CYRILLIC CAPITAL LETTER SHORT U" },
1492 { 0x040F, "DZcy", "CYRILLIC CAPITAL LETTER DZHE" },
1493 { 0x0410, "Acy", "CYRILLIC CAPITAL LETTER A" },
1494 { 0x0411, "Bcy", "CYRILLIC CAPITAL LETTER BE" },
1495 { 0x0412, "Vcy", "CYRILLIC CAPITAL LETTER VE" },
1496 { 0x0413, "Gcy", "CYRILLIC CAPITAL LETTER GHE" },
1497 { 0x0414, "Dcy", "CYRILLIC CAPITAL LETTER DE" },
1498 { 0x0415, "IEcy", "CYRILLIC CAPITAL LETTER IE" },
1499 { 0x0416, "ZHcy", "CYRILLIC CAPITAL LETTER ZHE" },
1500 { 0x0417, "Zcy", "CYRILLIC CAPITAL LETTER ZE" },
1501 { 0x0418, "Icy", "CYRILLIC CAPITAL LETTER I" },
1502 { 0x0419, "Jcy", "CYRILLIC CAPITAL LETTER SHORT I" },
1503 { 0x041A, "Kcy", "CYRILLIC CAPITAL LETTER KA" },
1504 { 0x041B, "Lcy", "CYRILLIC CAPITAL LETTER EL" },
1505 { 0x041C, "Mcy", "CYRILLIC CAPITAL LETTER EM" },
1506 { 0x041D, "Ncy", "CYRILLIC CAPITAL LETTER EN" },
1507 { 0x041E, "Ocy", "CYRILLIC CAPITAL LETTER O" },
1508 { 0x041F, "Pcy", "CYRILLIC CAPITAL LETTER PE" },
1509 { 0x0420, "Rcy", "CYRILLIC CAPITAL LETTER ER" },
1510 { 0x0421, "Scy", "CYRILLIC CAPITAL LETTER ES" },
1511 { 0x0422, "Tcy", "CYRILLIC CAPITAL LETTER TE" },
1512 { 0x0423, "Ucy", "CYRILLIC CAPITAL LETTER U" },
1513 { 0x0424, "Fcy", "CYRILLIC CAPITAL LETTER EF" },
1514 { 0x0425, "KHcy", "CYRILLIC CAPITAL LETTER HA" },
1515 { 0x0426, "TScy", "CYRILLIC CAPITAL LETTER TSE" },
1516 { 0x0427, "CHcy", "CYRILLIC CAPITAL LETTER CHE" },
1517 { 0x0428, "SHcy", "CYRILLIC CAPITAL LETTER SHA" },
1518 { 0x0429, "SHCHcy", "CYRILLIC CAPITAL LETTER SHCHA" },
1519 { 0x042A, "HARDcy", "CYRILLIC CAPITAL LETTER HARD SIGN" },
1520 { 0x042B, "Ycy", "CYRILLIC CAPITAL LETTER YERU" },
1521 { 0x042C, "SOFTcy", "CYRILLIC CAPITAL LETTER SOFT SIGN" },
1522 { 0x042D, "Ecy", "CYRILLIC CAPITAL LETTER E" },
1523 { 0x042E, "YUcy", "CYRILLIC CAPITAL LETTER YU" },
1524 { 0x042F, "YAcy", "CYRILLIC CAPITAL LETTER YA" },
1525 { 0x0430, "acy", "CYRILLIC SMALL LETTER A" },
1526 { 0x0431, "bcy", "CYRILLIC SMALL LETTER BE" },
1527 { 0x0432, "vcy", "CYRILLIC SMALL LETTER VE" },
1528 { 0x0433, "gcy", "CYRILLIC SMALL LETTER GHE" },
1529 { 0x0434, "dcy", "CYRILLIC SMALL LETTER DE" },
1530 { 0x0435, "iecy", "CYRILLIC SMALL LETTER IE" },
1531 { 0x0436, "zhcy", "CYRILLIC SMALL LETTER ZHE" },
1532 { 0x0437, "zcy", "CYRILLIC SMALL LETTER ZE" },
1533 { 0x0438, "icy", "CYRILLIC SMALL LETTER I" },
1534 { 0x0439, "jcy", "CYRILLIC SMALL LETTER SHORT I" },
1535 { 0x043A, "kcy", "CYRILLIC SMALL LETTER KA" },
1536 { 0x043B, "lcy", "CYRILLIC SMALL LETTER EL" },
1537 { 0x043C, "mcy", "CYRILLIC SMALL LETTER EM" },
1538 { 0x043D, "ncy", "CYRILLIC SMALL LETTER EN" },
1539 { 0x043E, "ocy", "CYRILLIC SMALL LETTER O" },
1540 { 0x043F, "pcy", "CYRILLIC SMALL LETTER PE" },
1541 { 0x0440, "rcy", "CYRILLIC SMALL LETTER ER" },
1542 { 0x0441, "scy", "CYRILLIC SMALL LETTER ES" },
1543 { 0x0442, "tcy", "CYRILLIC SMALL LETTER TE" },
1544 { 0x0443, "ucy", "CYRILLIC SMALL LETTER U" },
1545 { 0x0444, "fcy", "CYRILLIC SMALL LETTER EF" },
1546 { 0x0445, "khcy", "CYRILLIC SMALL LETTER HA" },
1547 { 0x0446, "tscy", "CYRILLIC SMALL LETTER TSE" },
1548 { 0x0447, "chcy", "CYRILLIC SMALL LETTER CHE" },
1549 { 0x0448, "shcy", "CYRILLIC SMALL LETTER SHA" },
1550 { 0x0449, "shchcy", "CYRILLIC SMALL LETTER SHCHA" },
1551 { 0x044A, "hardcy", "CYRILLIC SMALL LETTER HARD SIGN" },
1552 { 0x044B, "ycy", "CYRILLIC SMALL LETTER YERU" },
1553 { 0x044C, "softcy", "CYRILLIC SMALL LETTER SOFT SIGN" },
1554 { 0x044D, "ecy", "CYRILLIC SMALL LETTER E" },
1555 { 0x044E, "yucy", "CYRILLIC SMALL LETTER YU" },
1556 { 0x044F, "yacy", "CYRILLIC SMALL LETTER YA" },
1557 { 0x0451, "iocy", "CYRILLIC SMALL LETTER IO" },
1558 { 0x0452, "djcy", "CYRILLIC SMALL LETTER DJE" },
1559 { 0x0453, "gjcy", "CYRILLIC SMALL LETTER GJE" },
1560 { 0x0454, "jukcy", "CYRILLIC SMALL LETTER UKRAINIAN IE" },
1561 { 0x0455, "dscy", "CYRILLIC SMALL LETTER DZE" },
1562 { 0x0456, "iukcy", "CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I" },
1563 { 0x0457, "yicy", "CYRILLIC SMALL LETTER YI" },
1564 { 0x0458, "jsercy", "CYRILLIC SMALL LETTER JE" },
1565 { 0x0459, "ljcy", "CYRILLIC SMALL LETTER LJE" },
1566 { 0x045A, "njcy", "CYRILLIC SMALL LETTER NJE" },
1567 { 0x045B, "tshcy", "CYRILLIC SMALL LETTER TSHE" },
1568 { 0x045C, "kjcy", "CYRILLIC SMALL LETTER KJE" },
1569 { 0x045E, "ubrcy", "CYRILLIC SMALL LETTER SHORT U" },
1570 { 0x045F, "dzcy", "CYRILLIC SMALL LETTER DZHE" },
1571 { 0x2002, "ensp", "EN SPACE" },
1572 { 0x2003, "emsp", "EM SPACE" },
1573 { 0x2004, "emsp13", "THREE-PER-EM SPACE" },
1574 { 0x2005, "emsp14", "FOUR-PER-EM SPACE" },
1575 { 0x2007, "numsp", "FIGURE SPACE" },
1576 { 0x2008, "puncsp", "PUNCTUATION SPACE" },
1577 { 0x2009, "thinsp", "THIN SPACE" },
1578 { 0x200A, "hairsp", "HAIR SPACE" },
1579 { 0x2010, "dash", "HYPHEN" },
1580 { 0x2013, "ndash", "EN DASH" },
1581 { 0x2014, "mdash", "EM DASH" },
1582 { 0x2015, "horbar", "HORIZONTAL BAR" },
1583 { 0x2016, "Verbar", "DOUBLE VERTICAL LINE" },
1584 { 0x2018, "lsquo", "" },
1585 { 0x2018, "rsquor", "" },
1586 { 0x2019, "rsquo", "RIGHT SINGLE QUOTATION MARK" },
1587 { 0x201A, "lsquor", "SINGLE LOW-9 QUOTATION MARK" },
1588 { 0x201C, "ldquo", "" },
1589 { 0x201C, "rdquor", "" },
1590 { 0x201D, "rdquo", "RIGHT DOUBLE QUOTATION MARK" },
1591 { 0x201E, "ldquor", "DOUBLE LOW-9 QUOTATION MARK" },
1592 { 0x2020, "dagger", "DAGGER" },
1593 { 0x2021, "Dagger", "DOUBLE DAGGER" },
1594 { 0x2022, "bull", "BULLET" },
1595 { 0x2025, "nldr", "TWO DOT LEADER" },
1596 { 0x2026, "hellip", "HORIZONTAL ELLIPSIS" },
1597 { 0x2026, "mldr", "HORIZONTAL ELLIPSIS" },
1598 { 0x2030, "permil", "PER MILLE SIGN" },
1599 { 0x2032, "prime", "PRIME" },
1600 { 0x2032, "vprime", "PRIME" },
1601 { 0x2033, "Prime", "DOUBLE PRIME" },
1602 { 0x2034, "tprime", "TRIPLE PRIME" },
1603 { 0x2035, "bprime", "REVERSED PRIME" },
1604 { 0x2041, "caret", "CARET" },
1605 { 0x2043, "hybull", "HYPHEN BULLET" },
1606 { 0x20DB, "tdot", "COMBINING THREE DOTS ABOVE" },
1607 { 0x20DC, "DotDot", "COMBINING FOUR DOTS ABOVE" },
1608 { 0x2105, "incare", "CARE OF" },
1609 { 0x210B, "hamilt", "SCRIPT CAPITAL H" },
1610 { 0x210F, "planck", "PLANCK CONSTANT OVER TWO PI" },
1611 { 0x2111, "image", "BLACK-LETTER CAPITAL I" },
1612 { 0x2112, "lagran", "SCRIPT CAPITAL L" },
1613 { 0x2113, "ell", "SCRIPT SMALL L" },
1614 { 0x2116, "numero", "NUMERO SIGN" },
1615 { 0x2117, "copysr", "SOUND RECORDING COPYRIGHT" },
1616 { 0x2118, "weierp", "SCRIPT CAPITAL P" },
1617 { 0x211C, "real", "BLACK-LETTER CAPITAL R" },
1618 { 0x211E, "rx", "PRESCRIPTION TAKE" },
1619 { 0x2122, "trade", "TRADE MARK SIGN" },
1620 { 0x2126, "ohm", "OHM SIGN" },
1621 { 0x212B, "angst", "ANGSTROM SIGN" },
1622 { 0x212C, "bernou", "SCRIPT CAPITAL B" },
1623 { 0x2133, "phmmat", "SCRIPT CAPITAL M" },
1624 { 0x2134, "order", "SCRIPT SMALL O" },
1625 { 0x2135, "aleph", "ALEF SYMBOL" },
1626 { 0x2136, "beth", "BET SYMBOL" },
1627 { 0x2137, "gimel", "GIMEL SYMBOL" },
1628 { 0x2138, "daleth", "DALET SYMBOL" },
1629 { 0x2153, "frac13", "VULGAR FRACTION ONE THIRD" },
1630 { 0x2154, "frac23", "VULGAR FRACTION TWO THIRDS" },
1631 { 0x2155, "frac15", "VULGAR FRACTION ONE FIFTH" },
1632 { 0x2156, "frac25", "VULGAR FRACTION TWO FIFTHS" },
1633 { 0x2157, "frac35", "VULGAR FRACTION THREE FIFTHS" },
1634 { 0x2158, "frac45", "VULGAR FRACTION FOUR FIFTHS" },
1635 { 0x2159, "frac16", "VULGAR FRACTION ONE SIXTH" },
1636 { 0x215A, "frac56", "VULGAR FRACTION FIVE SIXTHS" },
1637 { 0x215B, "frac18", "" },
1638 { 0x215C, "frac38", "" },
1639 { 0x215D, "frac58", "" },
1640 { 0x215E, "frac78", "" },
1641 { 0x2190, "larr", "LEFTWARDS DOUBLE ARROW" },
1642 { 0x2191, "uarr", "UPWARDS ARROW" },
1643 { 0x2192, "rarr", "RIGHTWARDS DOUBLE ARROW" },
1644 { 0x2193, "darr", "DOWNWARDS ARROW" },
1645 { 0x2194, "harr", "LEFT RIGHT ARROW" },
1646 { 0x2194, "xhArr", "LEFT RIGHT ARROW" },
1647 { 0x2194, "xharr", "LEFT RIGHT ARROW" },
1648 { 0x2195, "varr", "UP DOWN ARROW" },
1649 { 0x2196, "nwarr", "NORTH WEST ARROW" },
1650 { 0x2197, "nearr", "NORTH EAST ARROW" },
1651 { 0x2198, "drarr", "SOUTH EAST ARROW" },
1652 { 0x2199, "dlarr", "SOUTH WEST ARROW" },
1653 { 0x219A, "nlarr", "LEFTWARDS ARROW WITH STROKE" },
1654 { 0x219B, "nrarr", "RIGHTWARDS ARROW WITH STROKE" },
1655 { 0x219D, "rarrw", "RIGHTWARDS SQUIGGLE ARROW" },
1656 { 0x219E, "Larr", "LEFTWARDS TWO HEADED ARROW" },
1657 { 0x21A0, "Rarr", "RIGHTWARDS TWO HEADED ARROW" },
1658 { 0x21A2, "larrtl", "LEFTWARDS ARROW WITH TAIL" },
1659 { 0x21A3, "rarrtl", "RIGHTWARDS ARROW WITH TAIL" },
1660 { 0x21A6, "map", "RIGHTWARDS ARROW FROM BAR" },
1661 { 0x21A9, "larrhk", "LEFTWARDS ARROW WITH HOOK" },
1662 { 0x21AA, "rarrhk", "RIGHTWARDS ARROW WITH HOOK" },
1663 { 0x21AB, "larrlp", "LEFTWARDS ARROW WITH LOOP" },
1664 { 0x21AC, "rarrlp", "RIGHTWARDS ARROW WITH LOOP" },
1665 { 0x21AD, "harrw", "LEFT RIGHT WAVE ARROW" },
1666 { 0x21AE, "nharr", "LEFT RIGHT ARROW WITH STROKE" },
1667 { 0x21B0, "lsh", "UPWARDS ARROW WITH TIP LEFTWARDS" },
1668 { 0x21B1, "rsh", "UPWARDS ARROW WITH TIP RIGHTWARDS" },
1669 { 0x21B6, "cularr", "ANTICLOCKWISE TOP SEMICIRCLE ARROW" },
1670 { 0x21B7, "curarr", "CLOCKWISE TOP SEMICIRCLE ARROW" },
1671 { 0x21BA, "olarr", "ANTICLOCKWISE OPEN CIRCLE ARROW" },
1672 { 0x21BB, "orarr", "CLOCKWISE OPEN CIRCLE ARROW" },
1673 { 0x21BC, "lharu", "LEFTWARDS HARPOON WITH BARB UPWARDS" },
1674 { 0x21BD, "lhard", "LEFTWARDS HARPOON WITH BARB DOWNWARDS" },
1675 { 0x21BE, "uharr", "UPWARDS HARPOON WITH BARB RIGHTWARDS" },
1676 { 0x21BF, "uharl", "UPWARDS HARPOON WITH BARB LEFTWARDS" },
1677 { 0x21C0, "rharu", "RIGHTWARDS HARPOON WITH BARB UPWARDS" },
1678 { 0x21C1, "rhard", "RIGHTWARDS HARPOON WITH BARB DOWNWARDS" },
1679 { 0x21C2, "dharr", "DOWNWARDS HARPOON WITH BARB RIGHTWARDS" },
1680 { 0x21C3, "dharl", "DOWNWARDS HARPOON WITH BARB LEFTWARDS" },
1681 { 0x21C4, "rlarr2", "RIGHTWARDS ARROW OVER LEFTWARDS ARROW" },
1682 { 0x21C6, "lrarr2", "LEFTWARDS ARROW OVER RIGHTWARDS ARROW" },
1683 { 0x21C7, "larr2", "LEFTWARDS PAIRED ARROWS" },
1684 { 0x21C8, "uarr2", "UPWARDS PAIRED ARROWS" },
1685 { 0x21C9, "rarr2", "RIGHTWARDS PAIRED ARROWS" },
1686 { 0x21CA, "darr2", "DOWNWARDS PAIRED ARROWS" },
1687 { 0x21CB, "lrhar2", "LEFTWARDS HARPOON OVER RIGHTWARDS HARPOON" },
1688 { 0x21CC, "rlhar2", "RIGHTWARDS HARPOON OVER LEFTWARDS HARPOON" },
1689 { 0x21CD, "nlArr", "LEFTWARDS DOUBLE ARROW WITH STROKE" },
1690 { 0x21CE, "nhArr", "LEFT RIGHT DOUBLE ARROW WITH STROKE" },
1691 { 0x21CF, "nrArr", "RIGHTWARDS DOUBLE ARROW WITH STROKE" },
1692 { 0x21D0, "lArr", "LEFTWARDS ARROW" },
1693 { 0x21D0, "xlArr", "LEFTWARDS DOUBLE ARROW" },
1694 { 0x21D1, "uArr", "UPWARDS DOUBLE ARROW" },
1695 { 0x21D2, "rArr", "RIGHTWARDS ARROW" },
1696 { 0x21D2, "xrArr", "RIGHTWARDS DOUBLE ARROW" },
1697 { 0x21D3, "dArr", "DOWNWARDS DOUBLE ARROW" },
1698 { 0x21D4, "hArr", "" },
1699 { 0x21D4, "iff", "LEFT RIGHT DOUBLE ARROW" },
1700 { 0x21D5, "vArr", "UP DOWN DOUBLE ARROW" },
1701 { 0x21DA, "lAarr", "LEFTWARDS TRIPLE ARROW" },
1702 { 0x21DB, "rAarr", "RIGHTWARDS TRIPLE ARROW" },
1703 { 0x2200, "forall", "" },
1704 { 0x2201, "comp", "COMPLEMENT" },
1705 { 0x2202, "part", "" },
1706 { 0x2203, "exist", "" },
1707 { 0x2204, "nexist", "THERE DOES NOT EXIST" },
1708 { 0x2205, "empty", "" },
1709 { 0x2207, "nabla", "NABLA" },
1710 { 0x2209, "notin", "" },
1711 { 0x220A, "epsi", "" },
1712 { 0x220A, "epsis", "" },
1713 { 0x220A, "isin", "" },
1714 { 0x220D, "bepsi", "SMALL CONTAINS AS MEMBER" },
1715 { 0x220D, "ni", "" },
1716 { 0x220F, "prod", "N-ARY PRODUCT" },
1717 { 0x2210, "amalg", "N-ARY COPRODUCT" },
1718 { 0x2210, "coprod", "N-ARY COPRODUCT" },
1719 { 0x2210, "samalg", "" },
1720 { 0x2211, "sum", "N-ARY SUMMATION" },
1721 { 0x2212, "minus", "MINUS SIGN" },
1722 { 0x2213, "mnplus", "" },
1723 { 0x2214, "plusdo", "DOT PLUS" },
1724 { 0x2216, "setmn", "SET MINUS" },
1725 { 0x2216, "ssetmn", "SET MINUS" },
1726 { 0x2217, "lowast", "ASTERISK OPERATOR" },
1727 { 0x2218, "compfn", "RING OPERATOR" },
1728 { 0x221A, "radic", "" },
1729 { 0x221D, "prop", "" },
1730 { 0x221D, "vprop", "" },
1731 { 0x221E, "infin", "" },
1732 { 0x221F, "ang90", "RIGHT ANGLE" },
1733 { 0x2220, "ang", "ANGLE" },
1734 { 0x2221, "angmsd", "MEASURED ANGLE" },
1735 { 0x2222, "angsph", "" },
1736 { 0x2223, "mid", "" },
1737 { 0x2224, "nmid", "DOES NOT DIVIDE" },
1738 { 0x2225, "par", "PARALLEL TO" },
1739 { 0x2225, "spar", "PARALLEL TO" },
1740 { 0x2226, "npar", "NOT PARALLEL TO" },
1741 { 0x2226, "nspar", "NOT PARALLEL TO" },
1742 { 0x2227, "and", "" },
1743 { 0x2228, "or", "" },
1744 { 0x2229, "cap", "" },
1745 { 0x222A, "cup", "" },
1746 { 0x222B, "int", "" },
1747 { 0x222E, "conint", "" },
1748 { 0x2234, "there4", "" },
1749 { 0x2235, "becaus", "BECAUSE" },
1750 { 0x223C, "sim", "" },
1751 { 0x223C, "thksim", "TILDE OPERATOR" },
1752 { 0x223D, "bsim", "" },
1753 { 0x2240, "wreath", "WREATH PRODUCT" },
1754 { 0x2241, "nsim", "" },
1755 { 0x2243, "sime", "" },
1756 { 0x2244, "nsime", "" },
1757 { 0x2245, "cong", "" },
1758 { 0x2247, "ncong", "NEITHER APPROXIMATELY NOR ACTUALLY EQUAL TO" },
1759 { 0x2248, "ap", "" },
1760 { 0x2248, "thkap", "ALMOST EQUAL TO" },
1761 { 0x2249, "nap", "NOT ALMOST EQUAL TO" },
1762 { 0x224A, "ape", "" },
1763 { 0x224C, "bcong", "ALL EQUAL TO" },
1764 { 0x224D, "asymp", "EQUIVALENT TO" },
1765 { 0x224E, "bump", "" },
1766 { 0x224F, "bumpe", "" },
1767 { 0x2250, "esdot", "" },
1768 { 0x2251, "eDot", "" },
1769 { 0x2252, "efDot", "" },
1770 { 0x2253, "erDot", "" },
1771 { 0x2254, "colone", "" },
1772 { 0x2255, "ecolon", "" },
1773 { 0x2256, "ecir", "" },
1774 { 0x2257, "cire", "" },
1775 { 0x2259, "wedgeq", "ESTIMATES" },
1776 { 0x225C, "trie", "" },
1777 { 0x2260, "ne", "" },
1778 { 0x2261, "equiv", "" },
1779 { 0x2262, "nequiv", "NOT IDENTICAL TO" },
1780 { 0x2264, "le", "" },
1781 { 0x2264, "les", "LESS-THAN OR EQUAL TO" },
1782 { 0x2265, "ge", "GREATER-THAN OR EQUAL TO" },
1783 { 0x2265, "ges", "GREATER-THAN OR EQUAL TO" },
1784 { 0x2266, "lE", "" },
1785 { 0x2267, "gE", "" },
1786 { 0x2268, "lnE", "" },
1787 { 0x2268, "lne", "" },
1788 { 0x2268, "lvnE", "LESS-THAN BUT NOT EQUAL TO" },
1789 { 0x2269, "gnE", "" },
1790 { 0x2269, "gne", "" },
1791 { 0x2269, "gvnE", "GREATER-THAN BUT NOT EQUAL TO" },
1792 { 0x226A, "Lt", "MUCH LESS-THAN" },
1793 { 0x226B, "Gt", "MUCH GREATER-THAN" },
1794 { 0x226C, "twixt", "BETWEEN" },
1795 { 0x226E, "nlt", "NOT LESS-THAN" },
1796 { 0x226F, "ngt", "NOT GREATER-THAN" },
1797 { 0x2270, "nlE", "" },
1798 { 0x2270, "nle", "NEITHER LESS-THAN NOR EQUAL TO" },
1799 { 0x2270, "nles", "" },
1800 { 0x2271, "ngE", "" },
1801 { 0x2271, "nge", "NEITHER GREATER-THAN NOR EQUAL TO" },
1802 { 0x2271, "nges", "" },
1803 { 0x2272, "lap", "LESS-THAN OR EQUIVALENT TO" },
1804 { 0x2272, "lsim", "LESS-THAN OR EQUIVALENT TO" },
1805 { 0x2273, "gap", "GREATER-THAN OR EQUIVALENT TO" },
1806 { 0x2273, "gsim", "GREATER-THAN OR EQUIVALENT TO" },
1807 { 0x2276, "lg", "LESS-THAN OR GREATER-THAN" },
1808 { 0x2277, "gl", "" },
1809 { 0x227A, "pr", "" },
1810 { 0x227B, "sc", "" },
1811 { 0x227C, "cupre", "" },
1812 { 0x227C, "pre", "" },
1813 { 0x227D, "sccue", "" },
1814 { 0x227D, "sce", "" },
1815 { 0x227E, "prap", "" },
1816 { 0x227E, "prsim", "" },
1817 { 0x227F, "scap", "" },
1818 { 0x227F, "scsim", "" },
1819 { 0x2280, "npr", "DOES NOT PRECEDE" },
1820 { 0x2281, "nsc", "DOES NOT SUCCEED" },
1821 { 0x2282, "sub", "" },
1822 { 0x2283, "sup", "" },
1823 { 0x2284, "nsub", "NOT A SUBSET OF" },
1824 { 0x2285, "nsup", "NOT A SUPERSET OF" },
1825 { 0x2286, "subE", "" },
1826 { 0x2286, "sube", "" },
1827 { 0x2287, "supE", "" },
1828 { 0x2287, "supe", "" },
1829 { 0x2288, "nsubE", "" },
1830 { 0x2288, "nsube", "" },
1831 { 0x2289, "nsupE", "" },
1832 { 0x2289, "nsupe", "" },
1833 { 0x228A, "subne", "" },
1834 { 0x228A, "subnE", "SUBSET OF WITH NOT EQUAL TO" },
1835 { 0x228A, "vsubne", "SUBSET OF WITH NOT EQUAL TO" },
1836 { 0x228B, "supnE", "" },
1837 { 0x228B, "supne", "" },
1838 { 0x228B, "vsupnE", "SUPERSET OF WITH NOT EQUAL TO" },
1839 { 0x228B, "vsupne", "SUPERSET OF WITH NOT EQUAL TO" },
1840 { 0x228E, "uplus", "MULTISET UNION" },
1841 { 0x228F, "sqsub", "" },
1842 { 0x2290, "sqsup", "" },
1843 { 0x2291, "sqsube", "" },
1844 { 0x2292, "sqsupe", "" },
1845 { 0x2293, "sqcap", "SQUARE CAP" },
1846 { 0x2294, "sqcup", "SQUARE CUP" },
1847 { 0x2295, "oplus", "CIRCLED PLUS" },
1848 { 0x2296, "ominus", "CIRCLED MINUS" },
1849 { 0x2297, "otimes", "CIRCLED TIMES" },
1850 { 0x2298, "osol", "CIRCLED DIVISION SLASH" },
1851 { 0x2299, "odot", "CIRCLED DOT OPERATOR" },
1852 { 0x229A, "ocir", "CIRCLED RING OPERATOR" },
1853 { 0x229B, "oast", "CIRCLED ASTERISK OPERATOR" },
1854 { 0x229D, "odash", "CIRCLED DASH" },
1855 { 0x229E, "plusb", "SQUARED PLUS" },
1856 { 0x229F, "minusb", "SQUARED MINUS" },
1857 { 0x22A0, "timesb", "SQUARED TIMES" },
1858 { 0x22A1, "sdotb", "SQUARED DOT OPERATOR" },
1859 { 0x22A2, "vdash", "" },
1860 { 0x22A3, "dashv", "" },
1861 { 0x22A4, "top", "DOWN TACK" },
1862 { 0x22A5, "bottom", "" },
1863 { 0x22A5, "perp", "" },
1864 { 0x22A7, "models", "MODELS" },
1865 { 0x22A8, "vDash", "" },
1866 { 0x22A9, "Vdash", "" },
1867 { 0x22AA, "Vvdash", "" },
1868 { 0x22AC, "nvdash", "DOES NOT PROVE" },
1869 { 0x22AD, "nvDash", "NOT TRUE" },
1870 { 0x22AE, "nVdash", "DOES NOT FORCE" },
1871 { 0x22AF, "nVDash", "NEGATED DOUBLE VERTICAL BAR DOUBLE RIGHT TURNSTILE" },
1872 { 0x22B2, "vltri", "" },
1873 { 0x22B3, "vrtri", "" },
1874 { 0x22B4, "ltrie", "" },
1875 { 0x22B5, "rtrie", "" },
1876 { 0x22B8, "mumap", "MULTIMAP" },
1877 { 0x22BA, "intcal", "INTERCALATE" },
1878 { 0x22BB, "veebar", "" },
1879 { 0x22BC, "barwed", "NAND" },
1880 { 0x22C4, "diam", "DIAMOND OPERATOR" },
1881 { 0x22C5, "sdot", "DOT OPERATOR" },
1882 { 0x22C6, "sstarf", "STAR OPERATOR" },
1883 { 0x22C6, "star", "STAR OPERATOR" },
1884 { 0x22C7, "divonx", "DIVISION TIMES" },
1885 { 0x22C8, "bowtie", "" },
1886 { 0x22C9, "ltimes", "LEFT NORMAL FACTOR SEMIDIRECT PRODUCT" },
1887 { 0x22CA, "rtimes", "RIGHT NORMAL FACTOR SEMIDIRECT PRODUCT" },
1888 { 0x22CB, "lthree", "LEFT SEMIDIRECT PRODUCT" },
1889 { 0x22CC, "rthree", "RIGHT SEMIDIRECT PRODUCT" },
1890 { 0x22CD, "bsime", "" },
1891 { 0x22CE, "cuvee", "CURLY LOGICAL OR" },
1892 { 0x22CF, "cuwed", "CURLY LOGICAL AND" },
1893 { 0x22D0, "Sub", "" },
1894 { 0x22D1, "Sup", "" },
1895 { 0x22D2, "Cap", "DOUBLE INTERSECTION" },
1896 { 0x22D3, "Cup", "DOUBLE UNION" },
1897 { 0x22D4, "fork", "" },
1898 { 0x22D6, "ldot", "" },
1899 { 0x22D7, "gsdot", "" },
1900 { 0x22D8, "Ll", "" },
1901 { 0x22D9, "Gg", "VERY MUCH GREATER-THAN" },
1902 { 0x22DA, "lEg", "" },
1903 { 0x22DA, "leg", "" },
1904 { 0x22DB, "gEl", "" },
1905 { 0x22DB, "gel", "" },
1906 { 0x22DC, "els", "" },
1907 { 0x22DD, "egs", "" },
1908 { 0x22DE, "cuepr", "" },
1909 { 0x22DF, "cuesc", "" },
1910 { 0x22E0, "npre", "DOES NOT PRECEDE OR EQUAL" },
1911 { 0x22E1, "nsce", "DOES NOT SUCCEED OR EQUAL" },
1912 { 0x22E6, "lnsim", "" },
1913 { 0x22E7, "gnsim", "GREATER-THAN BUT NOT EQUIVALENT TO" },
1914 { 0x22E8, "prnap", "" },
1915 { 0x22E8, "prnsim", "" },
1916 { 0x22E9, "scnap", "" },
1917 { 0x22E9, "scnsim", "" },
1918 { 0x22EA, "nltri", "NOT NORMAL SUBGROUP OF" },
1919 { 0x22EB, "nrtri", "DOES NOT CONTAIN AS NORMAL SUBGROUP" },
1920 { 0x22EC, "nltrie", "NOT NORMAL SUBGROUP OF OR EQUAL TO" },
1921 { 0x22ED, "nrtrie", "DOES NOT CONTAIN AS NORMAL SUBGROUP OR EQUAL" },
1922 { 0x22EE, "vellip", "" },
1923 { 0x2306, "Barwed", "PERSPECTIVE" },
1924 { 0x2308, "lceil", "LEFT CEILING" },
1925 { 0x2309, "rceil", "RIGHT CEILING" },
1926 { 0x230A, "lfloor", "LEFT FLOOR" },
1927 { 0x230B, "rfloor", "RIGHT FLOOR" },
1928 { 0x230C, "drcrop", "BOTTOM RIGHT CROP" },
1929 { 0x230D, "dlcrop", "BOTTOM LEFT CROP" },
1930 { 0x230E, "urcrop", "TOP RIGHT CROP" },
1931 { 0x230F, "ulcrop", "TOP LEFT CROP" },
1932 { 0x2315, "telrec", "TELEPHONE RECORDER" },
1933 { 0x2316, "target", "POSITION INDICATOR" },
1934 { 0x231C, "ulcorn", "TOP LEFT CORNER" },
1935 { 0x231D, "urcorn", "TOP RIGHT CORNER" },
1936 { 0x231E, "dlcorn", "BOTTOM LEFT CORNER" },
1937 { 0x231F, "drcorn", "BOTTOM RIGHT CORNER" },
1938 { 0x2322, "frown", "" },
1939 { 0x2322, "sfrown", "FROWN" },
1940 { 0x2323, "smile", "" },
1941 { 0x2323, "ssmile", "SMILE" },
1942 { 0x2423, "blank", "OPEN BOX" },
1943 { 0x24C8, "oS", "CIRCLED LATIN CAPITAL LETTER S" },
1944 { 0x2500, "boxh", "BOX DRAWINGS LIGHT HORIZONTAL" },
1945 { 0x2502, "boxv", "BOX DRAWINGS LIGHT VERTICAL" },
1946 { 0x250C, "boxdr", "BOX DRAWINGS LIGHT DOWN AND RIGHT" },
1947 { 0x2510, "boxdl", "BOX DRAWINGS LIGHT DOWN AND LEFT" },
1948 { 0x2514, "boxur", "BOX DRAWINGS LIGHT UP AND RIGHT" },
1949 { 0x2518, "boxul", "BOX DRAWINGS LIGHT UP AND LEFT" },
1950 { 0x251C, "boxvr", "BOX DRAWINGS LIGHT VERTICAL AND RIGHT" },
1951 { 0x2524, "boxvl", "BOX DRAWINGS LIGHT VERTICAL AND LEFT" },
1952 { 0x252C, "boxhd", "BOX DRAWINGS LIGHT DOWN AND HORIZONTAL" },
1953 { 0x2534, "boxhu", "BOX DRAWINGS LIGHT UP AND HORIZONTAL" },
1954 { 0x253C, "boxvh", "BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL" },
1955 { 0x2550, "boxH", "BOX DRAWINGS DOUBLE HORIZONTAL" },
1956 { 0x2551, "boxV", "BOX DRAWINGS DOUBLE VERTICAL" },
1957 { 0x2552, "boxDR", "BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE" },
1958 { 0x2553, "boxDr", "BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE" },
1959 { 0x2554, "boxdR", "BOX DRAWINGS DOUBLE DOWN AND RIGHT" },
1960 { 0x2555, "boxDL", "BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE" },
1961 { 0x2556, "boxdL", "BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE" },
1962 { 0x2557, "boxDl", "BOX DRAWINGS DOUBLE DOWN AND LEFT" },
1963 { 0x2558, "boxUR", "BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE" },
1964 { 0x2559, "boxuR", "BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE" },
1965 { 0x255A, "boxUr", "BOX DRAWINGS DOUBLE UP AND RIGHT" },
1966 { 0x255B, "boxUL", "BOX DRAWINGS UP SINGLE AND LEFT DOUBLE" },
1967 { 0x255C, "boxUl", "BOX DRAWINGS UP DOUBLE AND LEFT SINGLE" },
1968 { 0x255D, "boxuL", "BOX DRAWINGS DOUBLE UP AND LEFT" },
1969 { 0x255E, "boxvR", "BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE" },
1970 { 0x255F, "boxVR", "BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE" },
1971 { 0x2560, "boxVr", "BOX DRAWINGS DOUBLE VERTICAL AND RIGHT" },
1972 { 0x2561, "boxvL", "BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE" },
1973 { 0x2562, "boxVL", "BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE" },
1974 { 0x2563, "boxVl", "BOX DRAWINGS DOUBLE VERTICAL AND LEFT" },
1975 { 0x2564, "boxhD", "BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE" },
1976 { 0x2565, "boxHD", "BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE" },
1977 { 0x2566, "boxHd", "BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL" },
1978 { 0x2567, "boxhU", "BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE" },
1979 { 0x2568, "boxHU", "BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE" },
1980 { 0x2569, "boxHu", "BOX DRAWINGS DOUBLE UP AND HORIZONTAL" },
1981 { 0x256A, "boxvH", "BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE" },
1982 { 0x256B, "boxVH", "BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE" },
1983 { 0x256C, "boxVh", "BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL" },
1984 { 0x2580, "uhblk", "UPPER HALF BLOCK" },
1985 { 0x2584, "lhblk", "LOWER HALF BLOCK" },
1986 { 0x2588, "block", "FULL BLOCK" },
1987 { 0x2591, "blk14", "LIGHT SHADE" },
1988 { 0x2592, "blk12", "MEDIUM SHADE" },
1989 { 0x2593, "blk34", "DARK SHADE" },
1990 { 0x25A1, "square", "WHITE SQUARE" },
1991 { 0x25A1, "squ", "WHITE SQUARE" },
1992 { 0x25AA, "squf", "" },
1993 { 0x25AD, "rect", "WHITE RECTANGLE" },
1994 { 0x25AE, "marker", "BLACK VERTICAL RECTANGLE" },
1995 { 0x25B3, "xutri", "WHITE UP-POINTING TRIANGLE" },
1996 { 0x25B4, "utrif", "BLACK UP-POINTING TRIANGLE" },
1997 { 0x25B5, "utri", "WHITE UP-POINTING TRIANGLE" },
1998 { 0x25B8, "rtrif", "BLACK RIGHT-POINTING TRIANGLE" },
1999 { 0x25B9, "rtri", "WHITE RIGHT-POINTING TRIANGLE" },
2000 { 0x25BD, "xdtri", "WHITE DOWN-POINTING TRIANGLE" },
2001 { 0x25BE, "dtrif", "BLACK DOWN-POINTING TRIANGLE" },
2002 { 0x25BF, "dtri", "WHITE DOWN-POINTING TRIANGLE" },
2003 { 0x25C2, "ltrif", "BLACK LEFT-POINTING TRIANGLE" },
2004 { 0x25C3, "ltri", "WHITE LEFT-POINTING TRIANGLE" },
2005 { 0x25CA, "loz", "LOZENGE" },
2006 { 0x25CB, "cir", "WHITE CIRCLE" },
2007 { 0x25CB, "xcirc", "WHITE CIRCLE" },
2008 { 0x2605, "starf", "BLACK STAR" },
2009 { 0x260E, "phone", "TELEPHONE SIGN" },
2010 { 0x2640, "female", "" },
2011 { 0x2642, "male", "MALE SIGN" },
2012 { 0x2660, "spades", "BLACK SPADE SUIT" },
2013 { 0x2663, "clubs", "BLACK CLUB SUIT" },
2014 { 0x2665, "hearts", "BLACK HEART SUIT" },
2015 { 0x2666, "diams", "BLACK DIAMOND SUIT" },
2016 { 0x2669, "sung", "" },
2017 { 0x266D, "flat", "MUSIC FLAT SIGN" },
2018 { 0x266E, "natur", "MUSIC NATURAL SIGN" },
2019 { 0x266F, "sharp", "MUSIC SHARP SIGN" },
2020 { 0x2713, "check", "CHECK MARK" },
2021 { 0x2717, "cross", "BALLOT X" },
2022 { 0x2720, "malt", "MALTESE CROSS" },
2023 { 0x2726, "lozf", "" },
2024 { 0x2736, "sext", "SIX POINTED BLACK STAR" },
2025 { 0x3008, "lang", "" },
2026 { 0x3009, "rang", "" },
2027 { 0xE291, "rpargt", "" },
2028 { 0xE2A2, "lnap", "" },
2029 { 0xE2AA, "nsmid", "" },
2030 { 0xE2B3, "prnE", "" },
2031 { 0xE2B5, "scnE", "" },
2032 { 0xE2B8, "vsubnE", "" },
2033 { 0xE301, "smid", "" },
2034 { 0xE411, "gnap", "" },
2035 { 0xFB00, "fflig", "" },
2036 { 0xFB01, "filig", "" },
2037 { 0xFB02, "fllig", "" },
2038 { 0xFB03, "ffilig", "" },
2039 { 0xFB04, "ffllig", "" },
2040 { 0xFE68, "sbsol", "SMALL REVERSE SOLIDUS" },
2043 /************************************************************************
2045 * Commodity functions to handle entities *
2047 ************************************************************************/
2050 * Macro used to grow the current buffer.
2052 #define growBuffer(buffer) { \
2053 buffer##_size *= 2; \
2054 buffer = (xmlChar *) xmlRealloc(buffer, buffer##_size * sizeof(xmlChar)); \
2055 if (buffer == NULL) { \
2056 xmlGenericError(xmlGenericErrorContext, "realloc failed"); \
2063 * @name: the entity name
2065 * Lookup the given entity in EntitiesTable
2067 * TODO: the linear scan is really ugly, an hash table is really needed.
2069 * Returns the associated docbEntityDescPtr if found, NULL otherwise.
2071 static docbEntityDescPtr
2072 docbEntityLookup(const xmlChar
*name
) {
2075 for (i
= 0;i
< (sizeof(docbookEntitiesTable
)/
2076 sizeof(docbookEntitiesTable
[0]));i
++) {
2077 if (xmlStrEqual(name
, BAD_CAST docbookEntitiesTable
[i
].name
)) {
2079 xmlGenericError(xmlGenericErrorContext
,"Found entity %s\n", name
);
2081 return(&docbookEntitiesTable
[i
]);
2088 * docbEntityValueLookup:
2089 * @value: the entity's unicode value
2091 * Lookup the given entity in EntitiesTable
2093 * TODO: the linear scan is really ugly, an hash table is really needed.
2095 * Returns the associated docbEntityDescPtr if found, NULL otherwise.
2097 static docbEntityDescPtr
2098 docbEntityValueLookup(int value
) {
2104 for (i
= 0;i
< (sizeof(docbookEntitiesTable
)/
2105 sizeof(docbookEntitiesTable
[0]));i
++) {
2106 if (docbookEntitiesTable
[i
].value
>= value
) {
2107 if (docbookEntitiesTable
[i
].value
> value
)
2110 xmlGenericError(xmlGenericErrorContext
,"Found entity %s\n", docbookEntitiesTable
[i
].name
);
2112 return(&docbookEntitiesTable
[i
]);
2115 if (lv
> docbookEntitiesTable
[i
].value
) {
2116 xmlGenericError(xmlGenericErrorContext
,
2117 "docbookEntitiesTable[] is not sorted (%d > %d)!\n",
2118 lv
, docbookEntitiesTable
[i
].value
);
2120 lv
= docbookEntitiesTable
[i
].value
;
2129 * @out: a pointer to an array of bytes to store the result
2130 * @outlen: the length of @out
2131 * @in: a pointer to an array of UTF-8 chars
2132 * @inlen: the length of @in
2134 * Take a block of UTF-8 chars in and try to convert it to an ASCII
2135 * plus SGML entities block of chars out.
2137 * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise
2138 * The value of @inlen after return is the number of octets consumed
2139 * as the return value is positive, else unpredictable.
2140 * The value of @outlen after return is the number of octets consumed.
2143 UTF8ToSgml(unsigned char* out
, int *outlen
,
2144 const unsigned char* in
, int *inlen
) {
2145 const unsigned char* processed
= in
;
2146 const unsigned char* outend
;
2147 const unsigned char* outstart
= out
;
2148 const unsigned char* instart
= in
;
2149 const unsigned char* inend
;
2155 * initialization nothing to do
2161 inend
= in
+ (*inlen
);
2162 outend
= out
+ (*outlen
);
2163 while (in
< inend
) {
2165 if (d
< 0x80) { c
= d
; trailing
= 0; }
2166 else if (d
< 0xC0) {
2167 /* trailing byte in leading position */
2168 *outlen
= out
- outstart
;
2169 *inlen
= processed
- instart
;
2171 } else if (d
< 0xE0) { c
= d
& 0x1F; trailing
= 1; }
2172 else if (d
< 0xF0) { c
= d
& 0x0F; trailing
= 2; }
2173 else if (d
< 0xF8) { c
= d
& 0x07; trailing
= 3; }
2175 /* no chance for this in Ascii */
2176 *outlen
= out
- outstart
;
2177 *inlen
= processed
- instart
;
2181 if (inend
- in
< trailing
) {
2185 for ( ; trailing
; trailing
--) {
2186 if ((in
>= inend
) || (((d
= *in
++) & 0xC0) != 0x80))
2192 /* assertion: c is a single UTF-4 value */
2194 if (out
+ 1 >= outend
)
2199 docbEntityDescPtr ent
;
2202 * Try to lookup a predefined SGML entity for it
2205 ent
= docbEntityValueLookup(c
);
2207 /* no chance for this in Ascii */
2208 *outlen
= out
- outstart
;
2209 *inlen
= processed
- instart
;
2212 len
= strlen(ent
->name
);
2213 if (out
+ 2 + len
>= outend
)
2216 memcpy(out
, ent
->name
, len
);
2222 *outlen
= out
- outstart
;
2223 *inlen
= processed
- instart
;
2229 * docbEncodeEntities:
2230 * @out: a pointer to an array of bytes to store the result
2231 * @outlen: the length of @out
2232 * @in: a pointer to an array of UTF-8 chars
2233 * @inlen: the length of @in
2234 * @quoteChar: the quote character to escape (' or ") or zero.
2236 * Take a block of UTF-8 chars in and try to convert it to an ASCII
2237 * plus SGML entities block of chars out.
2239 * Returns 0 if success, -2 if the transcoding fails, or -1 otherwise
2240 * The value of @inlen after return is the number of octets consumed
2241 * as the return value is positive, else unpredictable.
2242 * The value of @outlen after return is the number of octets consumed.
2245 docbEncodeEntities(unsigned char* out
, int *outlen
,
2246 const unsigned char* in
, int *inlen
, int quoteChar
) {
2247 const unsigned char* processed
= in
;
2248 const unsigned char* outend
= out
+ (*outlen
);
2249 const unsigned char* outstart
= out
;
2250 const unsigned char* instart
= in
;
2251 const unsigned char* inend
= in
+ (*inlen
);
2255 while (in
< inend
) {
2257 if (d
< 0x80) { c
= d
; trailing
= 0; }
2258 else if (d
< 0xC0) {
2259 /* trailing byte in leading position */
2260 *outlen
= out
- outstart
;
2261 *inlen
= processed
- instart
;
2263 } else if (d
< 0xE0) { c
= d
& 0x1F; trailing
= 1; }
2264 else if (d
< 0xF0) { c
= d
& 0x0F; trailing
= 2; }
2265 else if (d
< 0xF8) { c
= d
& 0x07; trailing
= 3; }
2267 /* no chance for this in Ascii */
2268 *outlen
= out
- outstart
;
2269 *inlen
= processed
- instart
;
2273 if (inend
- in
< trailing
)
2276 while (trailing
--) {
2277 if (((d
= *in
++) & 0xC0) != 0x80) {
2278 *outlen
= out
- outstart
;
2279 *inlen
= processed
- instart
;
2286 /* assertion: c is a single UTF-4 value */
2287 if (c
< 0x80 && c
!= (unsigned int) quoteChar
&& c
!= '&' && c
!= '<' && c
!= '>') {
2292 docbEntityDescPtr ent
;
2298 * Try to lookup a predefined SGML entity for it
2300 ent
= docbEntityValueLookup(c
);
2302 snprintf(nbuf
, sizeof(nbuf
), "#%u", c
);
2308 if (out
+ 2 + len
> outend
)
2311 memcpy(out
, cp
, len
);
2317 *outlen
= out
- outstart
;
2318 *inlen
= processed
- instart
;
2323 /************************************************************************
2325 * Commodity functions to handle streams *
2327 ************************************************************************/
2330 * docbNewInputStream:
2331 * @ctxt: an SGML parser context
2333 * Create a new input stream structure
2334 * Returns the new input stream or NULL
2336 static docbParserInputPtr
2337 docbNewInputStream(docbParserCtxtPtr ctxt
) {
2338 docbParserInputPtr input
;
2340 input
= (xmlParserInputPtr
) xmlMalloc(sizeof(docbParserInput
));
2341 if (input
== NULL
) {
2342 ctxt
->errNo
= XML_ERR_NO_MEMORY
;
2343 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2344 ctxt
->sax
->error(ctxt
->userData
,
2345 "malloc: couldn't allocate a new input stream\n");
2348 memset(input
, 0, sizeof(docbParserInput
));
2349 input
->filename
= NULL
;
2350 input
->directory
= NULL
;
2358 input
->version
= NULL
;
2359 input
->consumed
= 0;
2365 /************************************************************************
2367 * Commodity functions, cleanup needed ? *
2369 ************************************************************************/
2373 * @ctxt: an SGML parser context
2375 * @len: the size of @str
2377 * Is this a sequence of blank chars that one can ignore ?
2379 * Returns 1 if ignorable 0 otherwise.
2382 static int areBlanks(docbParserCtxtPtr ctxt
, const xmlChar
*str
, int len
) {
2384 xmlNodePtr lastChild
;
2386 for (i
= 0;i
< len
;i
++)
2387 if (!(IS_BLANK(str
[i
]))) return(0);
2389 if (CUR
== 0) return(1);
2390 if (CUR
!= '<') return(0);
2391 if (ctxt
->name
== NULL
)
2393 if (ctxt
->node
== NULL
) return(0);
2394 lastChild
= xmlGetLastChild(ctxt
->node
);
2395 if (lastChild
== NULL
) {
2396 if ((ctxt
->node
->type
!= XML_ELEMENT_NODE
) &&
2397 (ctxt
->node
->content
!= NULL
)) return(0);
2398 } else if (xmlNodeIsText(lastChild
))
2403 /************************************************************************
2405 * External entities support *
2407 ************************************************************************/
2410 * docbParseCtxtExternalEntity:
2411 * @ctx: the existing parsing context
2412 * @URL: the URL for the entity to load
2413 * @ID: the System ID for the entity to load
2414 * @list: the return value for the set of parsed nodes
2416 * Parse an external general entity within an existing parsing context
2418 * Returns 0 if the entity is well formed, -1 in case of args problem and
2419 * the parser error code otherwise
2423 docbParseCtxtExternalEntity(xmlParserCtxtPtr ctx
, const xmlChar
*URL
,
2424 const xmlChar
*ID
, xmlNodePtr
*list
) {
2425 xmlParserCtxtPtr ctxt
;
2427 xmlSAXHandlerPtr oldsax
= NULL
;
2430 if (ctx
->depth
> 40) {
2431 return(XML_ERR_ENTITY_LOOP
);
2436 if ((URL
== NULL
) && (ID
== NULL
))
2438 if (ctx
->myDoc
== NULL
) /* @@ relax but check for dereferences */
2442 ctxt
= xmlCreateEntityParserCtxt(URL
, ID
, ctx
->myDoc
->URL
);
2443 if (ctxt
== NULL
) return(-1);
2444 ctxt
->userData
= ctxt
;
2446 ctxt
->sax
= ctx
->sax
;
2447 newDoc
= xmlNewDoc(BAD_CAST
"1.0");
2448 if (newDoc
== NULL
) {
2449 xmlFreeParserCtxt(ctxt
);
2452 if (ctx
->myDoc
!= NULL
) {
2453 newDoc
->intSubset
= ctx
->myDoc
->intSubset
;
2454 newDoc
->extSubset
= ctx
->myDoc
->extSubset
;
2456 if (ctx
->myDoc
->URL
!= NULL
) {
2457 newDoc
->URL
= xmlStrdup(ctx
->myDoc
->URL
);
2459 newDoc
->children
= xmlNewDocNode(newDoc
, NULL
, BAD_CAST
"pseudoroot", NULL
);
2460 if (newDoc
->children
== NULL
) {
2462 xmlFreeParserCtxt(ctxt
);
2463 newDoc
->intSubset
= NULL
;
2464 newDoc
->extSubset
= NULL
;
2468 nodePush(ctxt
, newDoc
->children
);
2469 if (ctx
->myDoc
== NULL
) {
2470 ctxt
->myDoc
= newDoc
;
2472 ctxt
->myDoc
= ctx
->myDoc
;
2473 newDoc
->children
->doc
= ctx
->myDoc
;
2477 * Parse a possible text declaration first
2480 if ((RAW
== '<') && (NXT(1) == '?') &&
2481 (NXT(2) == 'x') && (NXT(3) == 'm') &&
2482 (NXT(4) == 'l') && (IS_BLANK(NXT(5)))) {
2483 xmlParseTextDecl(ctxt
);
2487 * Doing validity checking on chunk doesn't make sense
2489 ctxt
->instate
= XML_PARSER_CONTENT
;
2490 ctxt
->validate
= ctx
->validate
;
2491 ctxt
->loadsubset
= ctx
->loadsubset
;
2492 ctxt
->depth
= ctx
->depth
+ 1;
2493 ctxt
->replaceEntities
= ctx
->replaceEntities
;
2494 if (ctxt
->validate
) {
2495 ctxt
->vctxt
.error
= ctx
->vctxt
.error
;
2496 ctxt
->vctxt
.warning
= ctx
->vctxt
.warning
;
2497 /* Allocate the Node stack */
2498 ctxt
->vctxt
.nodeTab
= (xmlNodePtr
*) xmlMalloc(4 * sizeof(xmlNodePtr
));
2499 if (ctxt
->vctxt
.nodeTab
== NULL
) {
2500 xmlGenericError(xmlGenericErrorContext
,
2501 "docbParseCtxtExternalEntity: out of memory\n");
2503 ctxt
->vctxt
.error
= NULL
;
2504 ctxt
->vctxt
.warning
= NULL
;
2506 ctxt
->vctxt
.nodeNr
= 0;
2507 ctxt
->vctxt
.nodeMax
= 4;
2508 ctxt
->vctxt
.node
= NULL
;
2511 ctxt
->vctxt
.error
= NULL
;
2512 ctxt
->vctxt
.warning
= NULL
;
2515 docbParseContent(ctxt
);
2517 if ((RAW
== '<') && (NXT(1) == '/')) {
2518 ctxt
->errNo
= XML_ERR_NOT_WELL_BALANCED
;
2519 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2520 ctxt
->sax
->error(ctxt
->userData
,
2521 "chunk is not well balanced\n");
2522 ctxt
->wellFormed
= 0;
2523 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
2524 } else if (RAW
!= 0) {
2525 ctxt
->errNo
= XML_ERR_EXTRA_CONTENT
;
2526 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2527 ctxt
->sax
->error(ctxt
->userData
,
2528 "extra content at the end of well balanced chunk\n");
2529 ctxt
->wellFormed
= 0;
2530 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
2532 if (ctxt
->node
!= newDoc
->children
) {
2533 ctxt
->errNo
= XML_ERR_NOT_WELL_BALANCED
;
2534 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2535 ctxt
->sax
->error(ctxt
->userData
,
2536 "chunk is not well balanced\n");
2537 ctxt
->wellFormed
= 0;
2538 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
2541 if (!ctxt
->wellFormed
) {
2542 if (ctxt
->errNo
== 0)
2551 * Return the newly created nodeset after unlinking it from
2552 * they pseudo parent.
2554 cur
= newDoc
->children
->children
;
2556 while (cur
!= NULL
) {
2560 newDoc
->children
->children
= NULL
;
2565 xmlFreeParserCtxt(ctxt
);
2566 newDoc
->intSubset
= NULL
;
2567 newDoc
->extSubset
= NULL
;
2573 /************************************************************************
2575 * The parser itself *
2577 ************************************************************************/
2580 * docbParseSGMLName:
2581 * @ctxt: an SGML parser context
2583 * parse an SGML tag or attribute name, note that we convert it to lowercase
2584 * since SGML names are not case-sensitive.
2586 * Returns the Tag Name parsed or NULL
2590 docbParseSGMLName(docbParserCtxtPtr ctxt
) {
2591 xmlChar
*ret
= NULL
;
2593 xmlChar loc
[DOCB_PARSER_BUFFER_SIZE
];
2595 if (!IS_LETTER(CUR
) && (CUR
!= '_') &&
2596 (CUR
!= ':')) return(NULL
);
2598 while ((i
< DOCB_PARSER_BUFFER_SIZE
) &&
2599 ((IS_LETTER(CUR
)) || (IS_DIGIT(CUR
)) ||
2600 (CUR
== ':') || (CUR
== '_'))) {
2601 if ((CUR
>= 'A') && (CUR
<= 'Z')) loc
[i
] = CUR
+ 0x20;
2608 ret
= xmlStrndup(loc
, i
);
2615 * @ctxt: an SGML parser context
2617 * parse an SGML name, this routine is case sensitive.
2619 * Returns the Name parsed or NULL
2623 docbParseName(docbParserCtxtPtr ctxt
) {
2624 xmlChar buf
[DOCB_MAX_NAMELEN
];
2628 if (!IS_LETTER(CUR
) && (CUR
!= '_')) {
2632 while ((IS_LETTER(CUR
)) || (IS_DIGIT(CUR
)) ||
2633 (CUR
== '.') || (CUR
== '-') ||
2634 (CUR
== '_') || (CUR
== ':') ||
2635 (IS_COMBINING(CUR
)) ||
2636 (IS_EXTENDER(CUR
))) {
2639 if (len
>= DOCB_MAX_NAMELEN
) {
2640 xmlGenericError(xmlGenericErrorContext
,
2641 "docbParseName: reached DOCB_MAX_NAMELEN limit\n");
2642 while ((IS_LETTER(CUR
)) || (IS_DIGIT(CUR
)) ||
2643 (CUR
== '.') || (CUR
== '-') ||
2644 (CUR
== '_') || (CUR
== ':') ||
2645 (IS_COMBINING(CUR
)) ||
2651 return(xmlStrndup(buf
, len
));
2655 * docbParseSGMLAttribute:
2656 * @ctxt: an SGML parser context
2657 * @stop: a char stop value
2659 * parse an SGML attribute value till the stop (quote), if
2660 * stop is 0 then it stops at the first space
2662 * Returns the attribute parsed or NULL
2666 docbParseSGMLAttribute(docbParserCtxtPtr ctxt
, const xmlChar stop
) {
2667 xmlChar
*buffer
= NULL
;
2668 int buffer_size
= 0;
2669 xmlChar
*out
= NULL
;
2670 xmlChar
*name
= NULL
;
2672 xmlChar
*cur
= NULL
;
2674 docbEntityDescPtr ent
;
2677 * allocate a translation buffer.
2679 buffer_size
= DOCB_PARSER_BIG_BUFFER_SIZE
;
2680 buffer
= (xmlChar
*) xmlMalloc(buffer_size
* sizeof(xmlChar
));
2681 if (buffer
== NULL
) {
2682 xmlGenericError(xmlGenericErrorContext
,
2683 "docbParseSGMLAttribute: malloc failed");
2689 * Ok loop until we reach one of the ending chars
2691 while ((CUR
!= 0) && (CUR
!= stop
) && (CUR
!= '>')) {
2692 if ((stop
== 0) && (IS_BLANK(CUR
))) break;
2694 if (NXT(1) == '#') {
2698 c
= docbParseCharRef(ctxt
);
2700 { *out
++ = c
; bits
= -6; }
2702 { *out
++ =((c
>> 6) & 0x1F) | 0xC0; bits
= 0; }
2703 else if (c
< 0x10000)
2704 { *out
++ =((c
>> 12) & 0x0F) | 0xE0; bits
= 6; }
2706 { *out
++ =((c
>> 18) & 0x07) | 0xF0; bits
= 12; }
2708 for ( ; bits
>= 0; bits
-= 6) {
2709 *out
++ = ((c
>> bits
) & 0x3F) | 0x80;
2712 xent
= docbParseEntityRef(ctxt
, &name
);
2715 if (out
- buffer
> buffer_size
- 100) {
2716 int indx
= out
- buffer
;
2719 out
= &buffer
[indx
];
2723 ent
= docbEntityLookup(name
);
2728 if (out
- buffer
> buffer_size
- 100) {
2729 int indx
= out
- buffer
;
2732 out
= &buffer
[indx
];
2741 if (out
- buffer
> buffer_size
- 100) {
2742 int indx
= out
- buffer
;
2745 out
= &buffer
[indx
];
2747 c
= (xmlChar
)ent
->value
;
2749 { *out
++ = c
; bits
= -6; }
2751 { *out
++ =((c
>> 6) & 0x1F) | 0xC0; bits
= 0; }
2752 else if (c
< 0x10000)
2753 { *out
++ =((c
>> 12) & 0x0F) | 0xE0; bits
= 6; }
2755 { *out
++ =((c
>> 18) & 0x07) | 0xF0; bits
= 12; }
2757 for ( ; bits
>= 0; bits
-= 6) {
2758 *out
++ = ((c
>> bits
) & 0x3F) | 0x80;
2768 if (out
- buffer
> buffer_size
- 100) {
2769 int indx
= out
- buffer
;
2772 out
= &buffer
[indx
];
2776 { *out
++ = c
; bits
= -6; }
2778 { *out
++ =((c
>> 6) & 0x1F) | 0xC0; bits
= 0; }
2779 else if (c
< 0x10000)
2780 { *out
++ =((c
>> 12) & 0x0F) | 0xE0; bits
= 6; }
2782 { *out
++ =((c
>> 18) & 0x07) | 0xF0; bits
= 12; }
2784 for ( ; bits
>= 0; bits
-= 6) {
2785 *out
++ = ((c
>> bits
) & 0x3F) | 0x80;
2796 * docbParseEntityRef:
2797 * @ctxt: an SGML parser context
2798 * @str: location to store the entity name
2800 * parse an SGML ENTITY references
2802 * [68] EntityRef ::= '&' Name ';'
2804 * Returns the associated xmlEntityPtr if found, or NULL otherwise,
2805 * if non-NULL *str will have to be freed by the caller.
2808 docbParseEntityRef(docbParserCtxtPtr ctxt
, xmlChar
**str
) {
2810 xmlEntityPtr ent
= NULL
;
2815 name
= docbParseName(ctxt
);
2817 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2818 ctxt
->sax
->error(ctxt
->userData
,
2819 "docbParseEntityRef: no name\n");
2820 ctxt
->wellFormed
= 0;
2827 * Ask first SAX for entity resolution, otherwise try the
2830 if (ctxt
->sax
!= NULL
) {
2831 if (ctxt
->sax
->getEntity
!= NULL
)
2832 ent
= ctxt
->sax
->getEntity(ctxt
->userData
, name
);
2834 ent
= xmlGetPredefinedEntity(name
);
2838 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2839 ctxt
->sax
->error(ctxt
->userData
,
2840 "docbParseEntityRef: expecting ';'\n");
2849 * docbParseAttValue:
2850 * @ctxt: an SGML parser context
2852 * parse a value for an attribute
2853 * Note: the parser won't do substitution of entities here, this
2854 * will be handled later in xmlStringGetNodeList, unless it was
2855 * asked for ctxt->replaceEntities != 0
2857 * Returns the AttValue parsed or NULL.
2861 docbParseAttValue(docbParserCtxtPtr ctxt
) {
2862 xmlChar
*ret
= NULL
;
2866 ret
= docbParseSGMLAttribute(ctxt
, '"');
2868 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2869 ctxt
->sax
->error(ctxt
->userData
, "AttValue: ' expected\n");
2870 ctxt
->wellFormed
= 0;
2873 } else if (CUR
== '\'') {
2875 ret
= docbParseSGMLAttribute(ctxt
, '\'');
2877 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2878 ctxt
->sax
->error(ctxt
->userData
, "AttValue: ' expected\n");
2879 ctxt
->wellFormed
= 0;
2884 * That's an SGMLism, the attribute value may not be quoted
2886 ret
= docbParseSGMLAttribute(ctxt
, 0);
2888 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2889 ctxt
->sax
->error(ctxt
->userData
, "AttValue: no value found\n");
2890 ctxt
->wellFormed
= 0;
2897 * docbParseSystemLiteral:
2898 * @ctxt: an SGML parser context
2900 * parse an SGML Literal
2902 * [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
2904 * Returns the SystemLiteral parsed or NULL
2908 docbParseSystemLiteral(docbParserCtxtPtr ctxt
) {
2910 xmlChar
*ret
= NULL
;
2915 while ((IS_CHAR(CUR
)) && (CUR
!= '"'))
2917 if (!IS_CHAR(CUR
)) {
2918 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2919 ctxt
->sax
->error(ctxt
->userData
, "Unfinished SystemLiteral\n");
2920 ctxt
->wellFormed
= 0;
2922 ret
= xmlStrndup(q
, CUR_PTR
- q
);
2925 } else if (CUR
== '\'') {
2928 while ((IS_CHAR(CUR
)) && (CUR
!= '\''))
2930 if (!IS_CHAR(CUR
)) {
2931 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2932 ctxt
->sax
->error(ctxt
->userData
, "Unfinished SystemLiteral\n");
2933 ctxt
->wellFormed
= 0;
2935 ret
= xmlStrndup(q
, CUR_PTR
- q
);
2939 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2940 ctxt
->sax
->error(ctxt
->userData
,
2941 "SystemLiteral \" or ' expected\n");
2942 ctxt
->wellFormed
= 0;
2949 * docbParsePubidLiteral:
2950 * @ctxt: an SGML parser context
2952 * parse an SGML public literal
2954 * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
2956 * Returns the PubidLiteral parsed or NULL.
2960 docbParsePubidLiteral(docbParserCtxtPtr ctxt
) {
2962 xmlChar
*ret
= NULL
;
2964 * Name ::= (Letter | '_') (NameChar)*
2969 while (IS_PUBIDCHAR(CUR
)) NEXT
;
2971 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2972 ctxt
->sax
->error(ctxt
->userData
, "Unfinished PubidLiteral\n");
2973 ctxt
->wellFormed
= 0;
2975 ret
= xmlStrndup(q
, CUR_PTR
- q
);
2978 } else if (CUR
== '\'') {
2981 while ((IS_LETTER(CUR
)) && (CUR
!= '\''))
2983 if (!IS_LETTER(CUR
)) {
2984 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2985 ctxt
->sax
->error(ctxt
->userData
, "Unfinished PubidLiteral\n");
2986 ctxt
->wellFormed
= 0;
2988 ret
= xmlStrndup(q
, CUR_PTR
- q
);
2992 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
2993 ctxt
->sax
->error(ctxt
->userData
, "SystemLiteral \" or ' expected\n");
2994 ctxt
->wellFormed
= 0;
3001 * docbParseCharData:
3002 * @ctxt: an SGML parser context
3003 * @cdata: int indicating whether we are within a CDATA section
3005 * parse a CharData section.
3006 * if we are within a CDATA section ']]>' marks an end of section.
3008 * [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
3012 docbParseCharData(docbParserCtxtPtr ctxt
) {
3013 xmlChar buf
[DOCB_PARSER_BIG_BUFFER_SIZE
+ 5];
3019 while (((cur
!= '<') || (ctxt
->token
== '<')) &&
3020 ((cur
!= '&') || (ctxt
->token
== '&')) &&
3022 COPY_BUF(l
,buf
,nbchar
,cur
);
3023 if (nbchar
>= DOCB_PARSER_BIG_BUFFER_SIZE
) {
3025 * Ok the segment is to be consumed as chars.
3027 if ((ctxt
->sax
!= NULL
) && (!ctxt
->disableSAX
)) {
3028 if (areBlanks(ctxt
, buf
, nbchar
)) {
3029 if (ctxt
->sax
->ignorableWhitespace
!= NULL
)
3030 ctxt
->sax
->ignorableWhitespace(ctxt
->userData
,
3033 if (ctxt
->sax
->characters
!= NULL
)
3034 ctxt
->sax
->characters(ctxt
->userData
, buf
, nbchar
);
3044 * Ok the segment is to be consumed as chars.
3046 if ((ctxt
->sax
!= NULL
) && (!ctxt
->disableSAX
)) {
3047 if (areBlanks(ctxt
, buf
, nbchar
)) {
3048 if (ctxt
->sax
->ignorableWhitespace
!= NULL
)
3049 ctxt
->sax
->ignorableWhitespace(ctxt
->userData
, buf
, nbchar
);
3051 if (ctxt
->sax
->characters
!= NULL
)
3052 ctxt
->sax
->characters(ctxt
->userData
, buf
, nbchar
);
3059 * docbParseExternalID:
3060 * @ctxt: an SGML parser context
3061 * @publicID: a xmlChar** receiving PubidLiteral
3063 * Parse an External ID or a Public ID
3065 * Returns the function returns SystemLiteral and in the second
3066 * case publicID receives PubidLiteral,
3067 * it is possible to return NULL and have publicID set.
3071 docbParseExternalID(docbParserCtxtPtr ctxt
, xmlChar
**publicID
) {
3072 xmlChar
*URI
= NULL
;
3074 if ((UPPER
== 'S') && (UPP(1) == 'Y') &&
3075 (UPP(2) == 'S') && (UPP(3) == 'T') &&
3076 (UPP(4) == 'E') && (UPP(5) == 'M')) {
3078 if (!IS_BLANK(CUR
)) {
3079 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3080 ctxt
->sax
->error(ctxt
->userData
,
3081 "Space required after 'SYSTEM'\n");
3082 ctxt
->wellFormed
= 0;
3085 URI
= docbParseSystemLiteral(ctxt
);
3087 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3088 ctxt
->sax
->error(ctxt
->userData
,
3089 "docbParseExternalID: SYSTEM, no URI\n");
3090 ctxt
->wellFormed
= 0;
3092 } else if ((UPPER
== 'P') && (UPP(1) == 'U') &&
3093 (UPP(2) == 'B') && (UPP(3) == 'L') &&
3094 (UPP(4) == 'I') && (UPP(5) == 'C')) {
3096 if (!IS_BLANK(CUR
)) {
3097 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3098 ctxt
->sax
->error(ctxt
->userData
,
3099 "Space required after 'PUBLIC'\n");
3100 ctxt
->wellFormed
= 0;
3103 *publicID
= docbParsePubidLiteral(ctxt
);
3104 if (*publicID
== NULL
) {
3105 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3106 ctxt
->sax
->error(ctxt
->userData
,
3107 "docbParseExternalID: PUBLIC, no Public Identifier\n");
3108 ctxt
->wellFormed
= 0;
3111 if ((CUR
== '"') || (CUR
== '\'')) {
3112 URI
= docbParseSystemLiteral(ctxt
);
3120 * @ctxt: an XML parser context
3122 * parse an XML Processing Instruction.
3124 * [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
3126 * The processing is transfered to SAX once parsed.
3130 docbParsePI(xmlParserCtxtPtr ctxt
) {
3131 xmlChar
*buf
= NULL
;
3133 int size
= DOCB_PARSER_BUFFER_SIZE
;
3136 xmlParserInputState state
;
3139 if ((RAW
== '<') && (NXT(1) == '?')) {
3140 xmlParserInputPtr input
= ctxt
->input
;
3141 state
= ctxt
->instate
;
3142 ctxt
->instate
= XML_PARSER_PI
;
3144 * this is a Processing Instruction.
3150 * Parse the target name and check for special support like
3153 target
= xmlParseName(ctxt
);
3154 if (target
!= NULL
) {
3155 xmlChar
*encoding
= NULL
;
3157 if ((RAW
== '?') && (NXT(1) == '>')) {
3158 if (input
!= ctxt
->input
) {
3159 ctxt
->errNo
= XML_ERR_ENTITY_BOUNDARY
;
3160 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3161 ctxt
->sax
->error(ctxt
->userData
,
3162 "PI declaration doesn't start and stop in the same entity\n");
3163 ctxt
->wellFormed
= 0;
3164 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
3171 if ((ctxt
->sax
) && (!ctxt
->disableSAX
) &&
3172 (ctxt
->sax
->processingInstruction
!= NULL
))
3173 ctxt
->sax
->processingInstruction(ctxt
->userData
,
3175 ctxt
->instate
= state
;
3179 if (xmlStrEqual(target
, BAD_CAST
"sgml-declaration")) {
3181 encoding
= xmlParseEncodingDecl(ctxt
);
3182 if (encoding
== NULL
) {
3183 xmlGenericError(xmlGenericErrorContext
,
3184 "sgml-declaration: failed to find/handle encoding\n");
3187 xmlGenericError(xmlGenericErrorContext
,
3188 "switched to encoding %s\n", encoding
);
3193 buf
= (xmlChar
*) xmlMalloc(size
* sizeof(xmlChar
));
3195 xmlGenericError(xmlGenericErrorContext
,
3196 "malloc of %d byte failed\n", size
);
3197 ctxt
->instate
= state
;
3201 if (encoding
!= NULL
) {
3202 len
= snprintf((char *) buf
, size
- 1,
3203 " encoding = \"%s\"", encoding
);
3207 if (!IS_BLANK(cur
)) {
3208 ctxt
->errNo
= XML_ERR_SPACE_REQUIRED
;
3209 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3210 ctxt
->sax
->error(ctxt
->userData
,
3211 "docbParsePI: PI %s space expected\n", target
);
3212 ctxt
->wellFormed
= 0;
3213 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
3218 while (IS_CHAR(cur
) && /* checked */
3219 ((cur
!= '?') || (NXT(1) != '>'))) {
3220 if (len
+ 5 >= size
) {
3222 buf
= (xmlChar
*) xmlRealloc(buf
, size
* sizeof(xmlChar
));
3224 xmlGenericError(xmlGenericErrorContext
,
3225 "realloc of %d byte failed\n", size
);
3226 ctxt
->instate
= state
;
3235 COPY_BUF(l
,buf
,len
,cur
);
3246 ctxt
->errNo
= XML_ERR_PI_NOT_FINISHED
;
3247 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3248 ctxt
->sax
->error(ctxt
->userData
,
3249 "docbParsePI: PI %s never end ...\n", target
);
3250 ctxt
->wellFormed
= 0;
3251 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
3253 if (input
!= ctxt
->input
) {
3254 ctxt
->errNo
= XML_ERR_ENTITY_BOUNDARY
;
3255 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3256 ctxt
->sax
->error(ctxt
->userData
,
3257 "PI declaration doesn't start and stop in the same entity\n");
3258 ctxt
->wellFormed
= 0;
3259 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
3266 if ((ctxt
->sax
) && (!ctxt
->disableSAX
) &&
3267 (ctxt
->sax
->processingInstruction
!= NULL
))
3268 ctxt
->sax
->processingInstruction(ctxt
->userData
,
3274 ctxt
->errNo
= XML_ERR_PI_NOT_STARTED
;
3275 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3276 ctxt
->sax
->error(ctxt
->userData
,
3277 "docbParsePI : no target name\n");
3278 ctxt
->wellFormed
= 0;
3279 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
3281 ctxt
->instate
= state
;
3287 * @ctxt: an SGML parser context
3289 * Parse an XML (SGML) comment <!-- .... -->
3291 * [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
3294 docbParseComment(docbParserCtxtPtr ctxt
) {
3295 xmlChar
*buf
= NULL
;
3297 int size
= DOCB_PARSER_BUFFER_SIZE
;
3301 xmlParserInputState state
;
3304 * Check that there is a comment right here.
3306 if ((RAW
!= '<') || (NXT(1) != '!') ||
3307 (NXT(2) != '-') || (NXT(3) != '-')) return;
3309 state
= ctxt
->instate
;
3310 ctxt
->instate
= XML_PARSER_COMMENT
;
3313 buf
= (xmlChar
*) xmlMalloc(size
* sizeof(xmlChar
));
3315 xmlGenericError(xmlGenericErrorContext
,
3316 "malloc of %d byte failed\n", size
);
3317 ctxt
->instate
= state
;
3326 while (IS_CHAR(cur
) &&
3328 (r
!= '-') || (q
!= '-'))) {
3329 if (len
+ 5 >= size
) {
3331 buf
= (xmlChar
*) xmlRealloc(buf
, size
* sizeof(xmlChar
));
3333 xmlGenericError(xmlGenericErrorContext
,
3334 "realloc of %d byte failed\n", size
);
3335 ctxt
->instate
= state
;
3339 COPY_BUF(ql
,buf
,len
,q
);
3353 if (!IS_CHAR(cur
)) {
3354 ctxt
->errNo
= XML_ERR_COMMENT_NOT_FINISHED
;
3355 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3356 ctxt
->sax
->error(ctxt
->userData
,
3357 "Comment not terminated \n<!--%.50s\n", buf
);
3358 ctxt
->wellFormed
= 0;
3362 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->comment
!= NULL
) &&
3363 (!ctxt
->disableSAX
))
3364 ctxt
->sax
->comment(ctxt
->userData
, buf
);
3367 ctxt
->instate
= state
;
3372 * @ctxt: an SGML parser context
3374 * parse Reference declarations
3376 * [66] CharRef ::= '&#' [0-9]+ ';' |
3377 * '&#x' [0-9a-fA-F]+ ';'
3379 * Returns the value parsed (as an int)
3382 docbParseCharRef(docbParserCtxtPtr ctxt
) {
3385 if ((CUR
== '&') && (NXT(1) == '#') &&
3388 while (CUR
!= ';') {
3389 if ((CUR
>= '0') && (CUR
<= '9'))
3390 val
= val
* 16 + (CUR
- '0');
3391 else if ((CUR
>= 'a') && (CUR
<= 'f'))
3392 val
= val
* 16 + (CUR
- 'a') + 10;
3393 else if ((CUR
>= 'A') && (CUR
<= 'F'))
3394 val
= val
* 16 + (CUR
- 'A') + 10;
3396 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3397 ctxt
->sax
->error(ctxt
->userData
,
3398 "docbParseCharRef: invalid hexadecimal value\n");
3399 ctxt
->wellFormed
= 0;
3407 } else if ((CUR
== '&') && (NXT(1) == '#')) {
3409 while (CUR
!= ';') {
3410 if ((CUR
>= '0') && (CUR
<= '9'))
3411 val
= val
* 10 + (CUR
- '0');
3413 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3414 ctxt
->sax
->error(ctxt
->userData
,
3415 "docbParseCharRef: invalid decimal value\n");
3416 ctxt
->wellFormed
= 0;
3425 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3426 ctxt
->sax
->error(ctxt
->userData
, "docbParseCharRef: invalid value\n");
3427 ctxt
->wellFormed
= 0;
3430 * Check the value IS_CHAR ...
3435 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3436 ctxt
->sax
->error(ctxt
->userData
, "docbParseCharRef: invalid xmlChar value %d\n",
3438 ctxt
->wellFormed
= 0;
3445 * docbParseDocTypeDecl :
3446 * @ctxt: an SGML parser context
3448 * parse a DOCTYPE declaration
3450 * [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S?
3451 * ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
3455 docbParseDocTypeDecl(docbParserCtxtPtr ctxt
) {
3457 xmlChar
*ExternalID
= NULL
;
3458 xmlChar
*URI
= NULL
;
3461 * We know that '<!DOCTYPE' has been detected.
3468 * Parse the DOCTYPE name.
3470 name
= docbParseName(ctxt
);
3472 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3473 ctxt
->sax
->error(ctxt
->userData
, "docbParseDocTypeDecl : no DOCTYPE name !\n");
3474 ctxt
->wellFormed
= 0;
3477 * Check that upper(name) == "SGML" !!!!!!!!!!!!!
3483 * Check for SystemID and ExternalID
3485 URI
= docbParseExternalID(ctxt
, &ExternalID
);
3489 * Create or update the document accordingly to the DOCTYPE
3490 * But use the predefined PUBLIC and SYSTEM ID of DocBook XML
3492 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->internalSubset
!= NULL
) &&
3493 (!ctxt
->disableSAX
))
3494 ctxt
->sax
->internalSubset(ctxt
->userData
, name
,
3495 XML_DOCBOOK_XML_PUBLIC
,
3496 XML_DOCBOOK_XML_SYSTEM
);
3499 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3500 ctxt
->sax
->error(ctxt
->userData
,
3501 "docbParseDocTypeDecl : internal subset not handled\n");
3507 * Cleanup, since we don't use all those identifiers
3509 if (URI
!= NULL
) xmlFree(URI
);
3510 if (ExternalID
!= NULL
) xmlFree(ExternalID
);
3511 if (name
!= NULL
) xmlFree(name
);
3515 * docbParseAttribute:
3516 * @ctxt: an SGML parser context
3517 * @value: a xmlChar ** used to store the value of the attribute
3519 * parse an attribute
3521 * [41] Attribute ::= Name Eq AttValue
3523 * [25] Eq ::= S? '=' S?
3527 * [NS 11] Attribute ::= QName Eq AttValue
3529 * Also the case QName == xmlns:??? is handled independently as a namespace
3532 * Returns the attribute name, and the value in *value.
3536 docbParseAttribute(docbParserCtxtPtr ctxt
, xmlChar
**value
) {
3537 xmlChar
*name
, *val
= NULL
;
3540 name
= docbParseName(ctxt
);
3542 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3543 ctxt
->sax
->error(ctxt
->userData
, "error parsing attribute name\n");
3544 ctxt
->wellFormed
= 0;
3555 val
= docbParseAttValue(ctxt
);
3558 * TODO : some attribute must have values, some may not
3559 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3560 ctxt->sax->warning(ctxt->userData,
3561 "No value for attribute %s\n", name); */
3569 * docbCheckEncoding:
3570 * @ctxt: an SGML parser context
3571 * @attvalue: the attribute value
3573 * Checks an http-equiv attribute from a Meta tag to detect
3575 * If a new encoding is detected the parser is switched to decode
3579 docbCheckEncoding(docbParserCtxtPtr ctxt
, const xmlChar
*attvalue
) {
3580 const xmlChar
*encoding
;
3582 if ((ctxt
== NULL
) || (attvalue
== NULL
))
3585 encoding
= xmlStrstr(attvalue
, BAD_CAST
"charset=");
3586 if (encoding
== NULL
)
3587 encoding
= xmlStrstr(attvalue
, BAD_CAST
"Charset=");
3588 if (encoding
== NULL
)
3589 encoding
= xmlStrstr(attvalue
, BAD_CAST
"CHARSET=");
3590 if (encoding
!= NULL
) {
3593 encoding
= xmlStrstr(attvalue
, BAD_CAST
"charset =");
3594 if (encoding
== NULL
)
3595 encoding
= xmlStrstr(attvalue
, BAD_CAST
"Charset =");
3596 if (encoding
== NULL
)
3597 encoding
= xmlStrstr(attvalue
, BAD_CAST
"CHARSET =");
3598 if (encoding
!= NULL
)
3602 * Restricted from 2.3.5 */
3603 if (encoding
!= NULL
) {
3604 xmlCharEncoding enc
;
3606 if (ctxt
->input
->encoding
!= NULL
)
3607 xmlFree((xmlChar
*) ctxt
->input
->encoding
);
3608 ctxt
->input
->encoding
= encoding
;
3610 enc
= xmlParseCharEncoding((const char *) encoding
);
3611 if (enc
== XML_CHAR_ENCODING_8859_1
) {
3612 ctxt
->charset
= XML_CHAR_ENCODING_8859_1
;
3613 } else if (enc
!= XML_CHAR_ENCODING_UTF8
) {
3614 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3615 ctxt
->sax
->error(ctxt
->userData
,
3616 "Unsupported encoding %s\n", encoding
);
3617 /* xmlFree(encoding); */
3618 ctxt
->wellFormed
= 0;
3619 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
3620 ctxt
->errNo
= XML_ERR_UNSUPPORTED_ENCODING
;
3627 * @ctxt: an SGML parser context
3628 * @atts: the attributes values
3630 * Checks an attributes from a Meta tag
3633 docbCheckMeta(docbParserCtxtPtr ctxt
, const xmlChar
**atts
) {
3635 const xmlChar
*att
, *value
;
3637 const xmlChar
*content
= NULL
;
3639 if ((ctxt
== NULL
) || (atts
== NULL
))
3644 while (att
!= NULL
) {
3646 if ((value
!= NULL
) &&
3647 ((xmlStrEqual(att
, BAD_CAST
"http-equiv")) ||
3648 (xmlStrEqual(att
, BAD_CAST
"Http-Equiv")) ||
3649 (xmlStrEqual(att
, BAD_CAST
"HTTP-EQUIV"))) &&
3650 ((xmlStrEqual(value
, BAD_CAST
"Content-Type")) ||
3651 (xmlStrEqual(value
, BAD_CAST
"content-type")) ||
3652 (xmlStrEqual(value
, BAD_CAST
"CONTENT-TYPE"))))
3654 else if ((value
!= NULL
) &&
3655 ((xmlStrEqual(att
, BAD_CAST
"content")) ||
3656 (xmlStrEqual(att
, BAD_CAST
"Content")) ||
3657 (xmlStrEqual(att
, BAD_CAST
"CONTENT"))))
3661 if ((http
) && (content
!= NULL
))
3662 docbCheckEncoding(ctxt
, content
);
3667 * docbParseStartTag:
3668 * @ctxt: an SGML parser context
3670 * parse a start of tag either for rule element or
3671 * EmptyElement. In both case we don't parse the tag closing chars.
3673 * [40] STag ::= '<' Name (S Attribute)* S? '>'
3675 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
3679 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>'
3681 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
3686 docbParseStartTag(docbParserCtxtPtr ctxt
) {
3690 const xmlChar
**atts
= NULL
;
3696 if (CUR
!= '<') return;
3700 name
= docbParseSGMLName(ctxt
);
3702 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3703 ctxt
->sax
->error(ctxt
->userData
,
3704 "docbParseStartTag: invalid element name\n");
3705 ctxt
->wellFormed
= 0;
3708 if (xmlStrEqual(name
, BAD_CAST
"meta"))
3712 * Check for auto-closure of SGML elements.
3714 docbAutoClose(ctxt
, name
);
3717 * Now parse the attributes, it ends up with the ending
3722 while ((IS_CHAR(CUR
)) &&
3724 ((CUR
!= '/') || (NXT(1) != '>'))) {
3725 long cons
= ctxt
->nbChars
;
3728 attname
= docbParseAttribute(ctxt
, &attvalue
);
3729 if (attname
!= NULL
) {
3732 * Well formedness requires at most one declaration of an attribute
3734 for (i
= 0; i
< nbatts
;i
+= 2) {
3735 if (xmlStrEqual(atts
[i
], attname
)) {
3736 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3737 ctxt
->sax
->error(ctxt
->userData
,
3738 "Attribute %s redefined\n",
3740 ctxt
->wellFormed
= 0;
3742 if (attvalue
!= NULL
)
3749 * Add the pair to atts
3753 atts
= (const xmlChar
**) xmlMalloc(maxatts
* sizeof(xmlChar
*));
3755 xmlGenericError(xmlGenericErrorContext
,
3756 "malloc of %ld byte failed\n",
3757 maxatts
* (long)sizeof(xmlChar
*));
3758 if (name
!= NULL
) xmlFree(name
);
3761 } else if (nbatts
+ 4 > maxatts
) {
3763 atts
= (const xmlChar
**) xmlRealloc((void *)atts
, maxatts
* sizeof(xmlChar
*));
3765 xmlGenericError(xmlGenericErrorContext
,
3766 "realloc of %ld byte failed\n",
3767 maxatts
* (long)sizeof(xmlChar
*));
3768 if (name
!= NULL
) xmlFree(name
);
3772 atts
[nbatts
++] = attname
;
3773 atts
[nbatts
++] = attvalue
;
3774 atts
[nbatts
] = NULL
;
3775 atts
[nbatts
+ 1] = NULL
;
3780 if (cons
== ctxt
->nbChars
) {
3781 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3782 ctxt
->sax
->error(ctxt
->userData
,
3783 "docbParseStartTag: problem parsing attributes\n");
3784 ctxt
->wellFormed
= 0;
3790 * Handle specific association to the META tag
3793 docbCheckMeta(ctxt
, atts
);
3796 * SAX: Start of Element !
3798 docbnamePush(ctxt
, xmlStrdup(name
));
3800 xmlGenericError(xmlGenericErrorContext
,"Start of element %s: pushed %s\n", name
, ctxt
->name
);
3802 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->startElement
!= NULL
))
3803 ctxt
->sax
->startElement(ctxt
->userData
, name
, atts
);
3806 for (i
= 0;i
< nbatts
;i
++) {
3807 if (atts
[i
] != NULL
)
3808 xmlFree((xmlChar
*) atts
[i
]);
3810 xmlFree((void *) atts
);
3812 if (name
!= NULL
) xmlFree(name
);
3817 * @ctxt: an SGML parser context
3819 * parse an end of tag
3821 * [42] ETag ::= '</' Name S? '>'
3825 * [NS 9] ETag ::= '</' QName S? '>'
3829 docbParseEndTag(docbParserCtxtPtr ctxt
) {
3834 if ((CUR
!= '<') || (NXT(1) != '/')) {
3835 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3836 ctxt
->sax
->error(ctxt
->userData
, "docbParseEndTag: '</' not found\n");
3837 ctxt
->wellFormed
= 0;
3842 name
= docbParseSGMLName(ctxt
);
3846 oldname
= docbnamePop(ctxt
);
3847 if (oldname
!= NULL
) {
3848 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->endElement
!= NULL
))
3849 ctxt
->sax
->endElement(ctxt
->userData
, name
);
3851 xmlGenericError(xmlGenericErrorContext
,"End of tag </>: popping out %s\n", oldname
);
3856 xmlGenericError(xmlGenericErrorContext
,"End of tag </>: stack empty !!!\n");
3865 * We should definitely be at the ending "S? '>'" part
3868 if ((!IS_CHAR(CUR
)) || (CUR
!= '>')) {
3869 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3870 ctxt
->sax
->error(ctxt
->userData
, "End tag : expected '>'\n");
3871 ctxt
->wellFormed
= 0;
3876 * If the name read is not one of the element in the parsing stack
3877 * then return, it's just an error.
3879 for (i
= (ctxt
->nameNr
- 1);i
>= 0;i
--) {
3880 if (xmlStrEqual(name
, ctxt
->nameTab
[i
])) break;
3883 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3884 ctxt
->sax
->error(ctxt
->userData
,
3885 "Unexpected end tag : %s\n", name
);
3887 ctxt
->wellFormed
= 0;
3893 * Check for auto-closure of SGML elements.
3896 docbAutoCloseOnClose(ctxt
, name
);
3899 * Well formedness constraints, opening and closing must match.
3900 * With the exception that the autoclose may have popped stuff out
3903 if (((name
[0] != '/') || (name
[1] != 0)) &&
3904 (!xmlStrEqual(name
, ctxt
->name
))) {
3906 xmlGenericError(xmlGenericErrorContext
,"End of tag %s: expecting %s\n", name
, ctxt
->name
);
3908 if ((ctxt
->name
!= NULL
) &&
3909 (!xmlStrEqual(ctxt
->name
, name
))) {
3910 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
3911 ctxt
->sax
->error(ctxt
->userData
,
3912 "Opening and ending tag mismatch: %s and %s\n",
3914 ctxt
->wellFormed
= 0;
3921 oldname
= ctxt
->name
;
3922 if (((name
[0] == '/') && (name
[1] == 0)) ||
3923 ((oldname
!= NULL
) && (xmlStrEqual(oldname
, name
)))) {
3924 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->endElement
!= NULL
))
3925 ctxt
->sax
->endElement(ctxt
->userData
, name
);
3926 oldname
= docbnamePop(ctxt
);
3927 if (oldname
!= NULL
) {
3929 xmlGenericError(xmlGenericErrorContext
,"End of tag %s: popping out %s\n", name
, oldname
);
3934 xmlGenericError(xmlGenericErrorContext
,"End of tag %s: stack empty !!!\n", name
);
3947 * docbParseReference:
3948 * @ctxt: an SGML parser context
3950 * parse and handle entity references in content,
3951 * this will end-up in a call to character() since this is either a
3952 * CharRef, or a predefined entity.
3955 docbParseReference(docbParserCtxtPtr ctxt
) {
3956 docbEntityDescPtr ent
;
3960 if (CUR
!= '&') return;
3962 if (NXT(1) == '#') {
3966 c
= docbParseCharRef(ctxt
);
3967 if (c
< 0x80) { out
[i
++]= c
; bits
= -6; }
3968 else if (c
< 0x800) { out
[i
++]=((c
>> 6) & 0x1F) | 0xC0; bits
= 0; }
3969 else if (c
< 0x10000) { out
[i
++]=((c
>> 12) & 0x0F) | 0xE0; bits
= 6; }
3970 else { out
[i
++]=((c
>> 18) & 0x07) | 0xF0; bits
= 12; }
3972 for ( ; bits
>= 0; bits
-= 6) {
3973 out
[i
++]= ((c
>> bits
) & 0x3F) | 0x80;
3977 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->characters
!= NULL
))
3978 ctxt
->sax
->characters(ctxt
->userData
, out
, i
);
3981 * Lookup the entity in the table.
3983 xent
= docbParseEntityRef(ctxt
, &name
);
3985 if (((ctxt
->replaceEntities
) || (ctxt
->loadsubset
)) &&
3986 ((xent
->children
== NULL
) &&
3987 (xent
->etype
== XML_EXTERNAL_GENERAL_PARSED_ENTITY
))) {
3989 * we really need to fetch and parse the external entity
3992 xmlNodePtr children
= NULL
;
3994 parse
= docbParseCtxtExternalEntity(ctxt
,
3995 xent
->SystemID
, xent
->ExternalID
, &children
);
3996 xmlAddChildList((xmlNodePtr
) xent
, children
);
3998 if (ctxt
->replaceEntities
) {
3999 if ((ctxt
->node
!= NULL
) && (xent
->children
!= NULL
)) {
4001 * Seems we are generating the DOM content, do
4002 * a simple tree copy
4005 new = xmlCopyNodeList(xent
->children
);
4007 xmlAddChildList(ctxt
->node
, new);
4009 * This is to avoid a nasty side effect, see
4010 * characters() in SAX.c
4016 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->reference
!= NULL
) &&
4017 (ctxt
->replaceEntities
== 0) && (!ctxt
->disableSAX
)) {
4021 ctxt
->sax
->reference(ctxt
->userData
, xent
->name
);
4024 } else if (name
!= NULL
) {
4025 ent
= docbEntityLookup(name
);
4026 if ((ent
== NULL
) || (ent
->value
<= 0)) {
4027 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->characters
!= NULL
)) {
4028 ctxt
->sax
->characters(ctxt
->userData
, BAD_CAST
"&", 1);
4029 ctxt
->sax
->characters(ctxt
->userData
, name
, xmlStrlen(name
));
4030 /* ctxt->sax->characters(ctxt->userData, BAD_CAST ";", 1); */
4038 { out
[i
++]= c
; bits
= -6; }
4040 { out
[i
++]=((c
>> 6) & 0x1F) | 0xC0; bits
= 0; }
4041 else if (c
< 0x10000)
4042 { out
[i
++]=((c
>> 12) & 0x0F) | 0xE0; bits
= 6; }
4044 { out
[i
++]=((c
>> 18) & 0x07) | 0xF0; bits
= 12; }
4046 for ( ; bits
>= 0; bits
-= 6) {
4047 out
[i
++]= ((c
>> bits
) & 0x3F) | 0x80;
4051 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->characters
!= NULL
))
4052 ctxt
->sax
->characters(ctxt
->userData
, out
, i
);
4055 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->characters
!= NULL
))
4056 ctxt
->sax
->characters(ctxt
->userData
, BAD_CAST
"&", 1);
4066 * @ctxt: an SGML parser context
4067 * @name: the node name
4069 * Parse a content: comment, sub-element, reference or text.
4073 docbParseContent(docbParserCtxtPtr ctxt
)
4075 xmlChar
*currentNode
;
4078 currentNode
= xmlStrdup(ctxt
->name
);
4079 depth
= ctxt
->nameNr
;
4081 long cons
= ctxt
->nbChars
;
4085 * Our tag or one of it's parent or children is ending.
4087 if ((CUR
== '<') && (NXT(1) == '/')) {
4088 docbParseEndTag(ctxt
);
4089 if (currentNode
!= NULL
)
4090 xmlFree(currentNode
);
4095 * Has this node been popped out during parsing of
4098 if ((!xmlStrEqual(currentNode
, ctxt
->name
)) &&
4099 (depth
>= ctxt
->nameNr
)) {
4100 if (currentNode
!= NULL
)
4101 xmlFree(currentNode
);
4106 * Sometimes DOCTYPE arrives in the middle of the document
4108 if ((CUR
== '<') && (NXT(1) == '!') &&
4109 (UPP(2) == 'D') && (UPP(3) == 'O') &&
4110 (UPP(4) == 'C') && (UPP(5) == 'T') &&
4111 (UPP(6) == 'Y') && (UPP(7) == 'P') && (UPP(8) == 'E')) {
4112 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4113 ctxt
->sax
->error(ctxt
->userData
,
4114 "Misplaced DOCTYPE declaration\n");
4115 ctxt
->wellFormed
= 0;
4116 docbParseDocTypeDecl(ctxt
);
4120 * First case : a comment
4122 if ((CUR
== '<') && (NXT(1) == '!') &&
4123 (NXT(2) == '-') && (NXT(3) == '-')) {
4124 docbParseComment(ctxt
);
4128 * Second case : a PI
4130 else if ((RAW
== '<') && (NXT(1) == '?')) {
4135 * Third case : a sub-element.
4137 else if (CUR
== '<') {
4138 docbParseElement(ctxt
);
4142 * Fourth case : a reference. If if has not been resolved,
4143 * parsing returns it's Name, create the node
4145 else if (CUR
== '&') {
4146 docbParseReference(ctxt
);
4150 * Fifth : end of the resource
4152 else if (CUR
== 0) {
4153 docbAutoClose(ctxt
, NULL
);
4154 if (ctxt
->nameNr
== 0)
4159 * Last case, text. Note that References are handled directly.
4162 docbParseCharData(ctxt
);
4165 if (cons
== ctxt
->nbChars
) {
4166 if (ctxt
->node
!= NULL
) {
4167 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4168 ctxt
->sax
->error(ctxt
->userData
,
4169 "detected an error in element content\n");
4170 ctxt
->wellFormed
= 0;
4177 if (currentNode
!= NULL
)
4178 xmlFree(currentNode
);
4183 * @ctxt: an SGML parser context
4185 * parse an SGML element, this is highly recursive
4187 * [39] element ::= EmptyElemTag | STag content ETag
4189 * [41] Attribute ::= Name Eq AttValue
4193 docbParseElement(docbParserCtxtPtr ctxt
) {
4195 xmlChar
*currentNode
= NULL
;
4196 docbElemDescPtr info
;
4197 docbParserNodeInfo node_info
;
4199 int depth
= ctxt
->nameNr
;
4201 /* Capture start position */
4202 if (ctxt
->record_info
) {
4203 node_info
.begin_pos
= ctxt
->input
->consumed
+
4204 (CUR_PTR
- ctxt
->input
->base
);
4205 node_info
.begin_line
= ctxt
->input
->line
;
4208 oldname
= xmlStrdup(ctxt
->name
);
4209 docbParseStartTag(ctxt
);
4212 if (oldname
== NULL
)
4213 xmlGenericError(xmlGenericErrorContext
,
4214 "Start of element %s\n", name
);
4215 else if (name
== NULL
)
4216 xmlGenericError(xmlGenericErrorContext
,
4217 "Start of element failed, was %s\n", oldname
);
4219 xmlGenericError(xmlGenericErrorContext
,
4220 "Start of element %s, was %s\n", name
, oldname
);
4222 if (((depth
== ctxt
->nameNr
) && (xmlStrEqual(oldname
, ctxt
->name
))) ||
4226 if (oldname
!= NULL
)
4230 if (oldname
!= NULL
)
4234 * Lookup the info for that element.
4236 info
= docbTagLookup(name
);
4238 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4239 ctxt
->sax
->error(ctxt
->userData
, "Tag %s unknown\n",
4241 ctxt
->wellFormed
= 0;
4242 } else if (info
->depr
) {
4243 /***************************
4244 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
4245 ctxt->sax->warning(ctxt->userData, "Tag %s is deprecated\n",
4247 ***************************/
4251 * Check for an Empty Element labeled the XML/SGML way
4253 if ((CUR
== '/') && (NXT(1) == '>')) {
4255 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->endElement
!= NULL
))
4256 ctxt
->sax
->endElement(ctxt
->userData
, name
);
4257 oldname
= docbnamePop(ctxt
);
4259 xmlGenericError(xmlGenericErrorContext
,"End of tag the XML way: popping out %s\n", oldname
);
4261 if (oldname
!= NULL
)
4269 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4270 ctxt
->sax
->error(ctxt
->userData
,
4271 "Couldn't find end of Start Tag %s\n",
4273 ctxt
->wellFormed
= 0;
4276 * end of parsing of this node.
4278 if (xmlStrEqual(name
, ctxt
->name
)) {
4280 oldname
= docbnamePop(ctxt
);
4282 xmlGenericError(xmlGenericErrorContext
,"End of start tag problem: popping out %s\n", oldname
);
4284 if (oldname
!= NULL
)
4289 * Capture end position and add node
4291 if ( currentNode
!= NULL
&& ctxt
->record_info
) {
4292 node_info
.end_pos
= ctxt
->input
->consumed
+
4293 (CUR_PTR
- ctxt
->input
->base
);
4294 node_info
.end_line
= ctxt
->input
->line
;
4295 node_info
.node
= ctxt
->node
;
4296 xmlParserAddNodeInfo(ctxt
, &node_info
);
4302 * Check for an Empty Element from DTD definition
4304 if ((info
!= NULL
) && (info
->empty
)) {
4305 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->endElement
!= NULL
))
4306 ctxt
->sax
->endElement(ctxt
->userData
, name
);
4307 oldname
= docbnamePop(ctxt
);
4309 xmlGenericError(xmlGenericErrorContext
,"End of empty tag %s : popping out %s\n", name
, oldname
);
4311 if (oldname
!= NULL
)
4317 * Parse the content of the element:
4319 currentNode
= xmlStrdup(ctxt
->name
);
4320 depth
= ctxt
->nameNr
;
4321 while (IS_CHAR(CUR
)) {
4322 docbParseContent(ctxt
);
4323 if (ctxt
->nameNr
< depth
) break;
4326 if (!IS_CHAR(CUR
)) {
4328 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4329 ctxt->sax->error(ctxt->userData,
4330 "Premature end of data in tag %s\n", currentNode);
4331 ctxt->wellFormed = 0;
4335 * end of parsing of this node.
4338 oldname
= docbnamePop(ctxt
);
4340 xmlGenericError(xmlGenericErrorContext
,"Premature end of tag %s : popping out %s\n", name
, oldname
);
4342 if (oldname
!= NULL
)
4344 if (currentNode
!= NULL
)
4345 xmlFree(currentNode
);
4350 * Capture end position and add node
4352 if ( currentNode
!= NULL
&& ctxt
->record_info
) {
4353 node_info
.end_pos
= ctxt
->input
->consumed
+
4354 (CUR_PTR
- ctxt
->input
->base
);
4355 node_info
.end_line
= ctxt
->input
->line
;
4356 node_info
.node
= ctxt
->node
;
4357 xmlParserAddNodeInfo(ctxt
, &node_info
);
4359 if (currentNode
!= NULL
)
4360 xmlFree(currentNode
);
4364 * docbParseEntityDecl:
4365 * @ctxt: an SGML parser context
4367 * parse <!ENTITY declarations
4372 docbParseEntityDecl(xmlParserCtxtPtr ctxt
) {
4373 xmlChar
*name
= NULL
;
4374 xmlChar
*value
= NULL
;
4375 xmlChar
*URI
= NULL
, *literal
= NULL
;
4376 xmlChar
*ndata
= NULL
;
4377 int isParameter
= 0;
4378 xmlChar
*orig
= NULL
;
4381 if ((RAW
== '<') && (NXT(1) == '!') &&
4382 (UPP(2) == 'E') && (UPP(3) == 'N') &&
4383 (UPP(4) == 'T') && (UPP(5) == 'I') &&
4384 (UPP(6) == 'T') && (UPP(7) == 'Y')) {
4385 xmlParserInputPtr input
= ctxt
->input
;
4386 ctxt
->instate
= XML_PARSER_ENTITY_DECL
;
4389 if (!IS_BLANK(CUR
)) {
4390 ctxt
->errNo
= XML_ERR_SPACE_REQUIRED
;
4391 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4392 ctxt
->sax
->error(ctxt
->userData
,
4393 "Space required after '<!ENTITY'\n");
4394 ctxt
->wellFormed
= 0;
4395 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4401 if (!IS_BLANK(CUR
)) {
4402 ctxt
->errNo
= XML_ERR_SPACE_REQUIRED
;
4403 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4404 ctxt
->sax
->error(ctxt
->userData
,
4405 "Space required after '%'\n");
4406 ctxt
->wellFormed
= 0;
4407 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4413 name
= xmlParseName(ctxt
);
4415 ctxt
->errNo
= XML_ERR_NAME_REQUIRED
;
4416 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4417 ctxt
->sax
->error(ctxt
->userData
, "sgmlarseEntityDecl: no name\n");
4418 ctxt
->wellFormed
= 0;
4419 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4422 if (!IS_BLANK(CUR
)) {
4423 ctxt
->errNo
= XML_ERR_SPACE_REQUIRED
;
4424 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4425 ctxt
->sax
->error(ctxt
->userData
,
4426 "Space required after the entity name\n");
4427 ctxt
->wellFormed
= 0;
4428 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4433 * handle the various case of definitions...
4436 if ((RAW
== '"') || (RAW
== '\'')) {
4437 value
= xmlParseEntityValue(ctxt
, &orig
);
4439 if ((ctxt
->sax
!= NULL
) &&
4440 (!ctxt
->disableSAX
) && (ctxt
->sax
->entityDecl
!= NULL
))
4441 ctxt
->sax
->entityDecl(ctxt
->userData
, name
,
4442 XML_INTERNAL_PARAMETER_ENTITY
,
4446 URI
= xmlParseExternalID(ctxt
, &literal
, 1);
4447 if ((URI
== NULL
) && (literal
== NULL
)) {
4448 ctxt
->errNo
= XML_ERR_VALUE_REQUIRED
;
4449 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4450 ctxt
->sax
->error(ctxt
->userData
,
4451 "Entity value required\n");
4452 ctxt
->wellFormed
= 0;
4453 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4458 uri
= xmlParseURI((const char *) URI
);
4460 ctxt
->errNo
= XML_ERR_INVALID_URI
;
4461 if ((ctxt
->sax
!= NULL
) &&
4462 (!ctxt
->disableSAX
) &&
4463 (ctxt
->sax
->error
!= NULL
))
4464 ctxt
->sax
->error(ctxt
->userData
,
4465 "Invalid URI: %s\n", URI
);
4466 ctxt
->wellFormed
= 0;
4468 if (uri
->fragment
!= NULL
) {
4469 ctxt
->errNo
= XML_ERR_URI_FRAGMENT
;
4470 if ((ctxt
->sax
!= NULL
) &&
4471 (!ctxt
->disableSAX
) &&
4472 (ctxt
->sax
->error
!= NULL
))
4473 ctxt
->sax
->error(ctxt
->userData
,
4474 "Fragment not allowed: %s\n", URI
);
4475 ctxt
->wellFormed
= 0;
4477 if ((ctxt
->sax
!= NULL
) &&
4478 (!ctxt
->disableSAX
) &&
4479 (ctxt
->sax
->entityDecl
!= NULL
))
4480 ctxt
->sax
->entityDecl(ctxt
->userData
, name
,
4481 XML_EXTERNAL_PARAMETER_ENTITY
,
4482 literal
, URI
, NULL
);
4489 if ((RAW
== '"') || (RAW
== '\'')) {
4490 value
= xmlParseEntityValue(ctxt
, &orig
);
4491 if ((ctxt
->sax
!= NULL
) &&
4492 (!ctxt
->disableSAX
) && (ctxt
->sax
->entityDecl
!= NULL
))
4493 ctxt
->sax
->entityDecl(ctxt
->userData
, name
,
4494 XML_INTERNAL_GENERAL_ENTITY
,
4497 URI
= xmlParseExternalID(ctxt
, &literal
, 1);
4498 if ((URI
== NULL
) && (literal
== NULL
)) {
4499 ctxt
->errNo
= XML_ERR_VALUE_REQUIRED
;
4500 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4501 ctxt
->sax
->error(ctxt
->userData
,
4502 "Entity value required\n");
4503 ctxt
->wellFormed
= 0;
4504 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4509 uri
= xmlParseURI((const char *)URI
);
4511 ctxt
->errNo
= XML_ERR_INVALID_URI
;
4512 if ((ctxt
->sax
!= NULL
) &&
4513 (!ctxt
->disableSAX
) &&
4514 (ctxt
->sax
->error
!= NULL
))
4515 ctxt
->sax
->error(ctxt
->userData
,
4516 "Invalid URI: %s\n", URI
);
4517 ctxt
->wellFormed
= 0;
4519 if (uri
->fragment
!= NULL
) {
4520 ctxt
->errNo
= XML_ERR_URI_FRAGMENT
;
4521 if ((ctxt
->sax
!= NULL
) &&
4522 (!ctxt
->disableSAX
) &&
4523 (ctxt
->sax
->error
!= NULL
))
4524 ctxt
->sax
->error(ctxt
->userData
,
4525 "Fragment not allowed: %s\n", URI
);
4526 ctxt
->wellFormed
= 0;
4531 if ((RAW
!= '>') && (!IS_BLANK(CUR
))) {
4532 ctxt
->errNo
= XML_ERR_SPACE_REQUIRED
;
4533 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4534 ctxt
->sax
->error(ctxt
->userData
,
4535 "Space required before content model\n");
4536 ctxt
->wellFormed
= 0;
4537 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4542 * SGML specific: here we can get the content model
4547 contmod
= xmlParseName(ctxt
);
4549 if (contmod
== NULL
) {
4550 ctxt
->errNo
= XML_ERR_SPACE_REQUIRED
;
4551 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4552 ctxt
->sax
->error(ctxt
->userData
,
4553 "Could not parse entity content model\n");
4554 ctxt
->wellFormed
= 0;
4555 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4557 if (xmlStrEqual(contmod
, BAD_CAST
"NDATA")) {
4558 if (!IS_BLANK(CUR
)) {
4559 ctxt
->errNo
= XML_ERR_SPACE_REQUIRED
;
4560 if ((ctxt
->sax
!= NULL
) &&
4561 (ctxt
->sax
->error
!= NULL
))
4562 ctxt
->sax
->error(ctxt
->userData
,
4563 "Space required after 'NDATA'\n");
4564 ctxt
->wellFormed
= 0;
4565 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4568 ndata
= xmlParseName(ctxt
);
4569 if ((ctxt
->sax
!= NULL
) && (!ctxt
->disableSAX
) &&
4570 (ctxt
->sax
->unparsedEntityDecl
!= NULL
)) {
4571 ctxt
->sax
->unparsedEntityDecl(ctxt
->userData
,
4572 name
, literal
, URI
, ndata
);
4574 } else if (xmlStrEqual(contmod
, BAD_CAST
"SUBDOC")) {
4575 if ((ctxt
->sax
!= NULL
) &&
4576 (ctxt
->sax
->warning
!= NULL
))
4577 ctxt
->sax
->warning(ctxt
->userData
,
4578 "SUBDOC entities are not supported\n");
4580 ndata
= xmlParseName(ctxt
);
4581 if ((ctxt
->sax
!= NULL
) && (!ctxt
->disableSAX
) &&
4582 (ctxt
->sax
->unparsedEntityDecl
!= NULL
)) {
4583 ctxt
->sax
->unparsedEntityDecl(ctxt
->userData
,
4584 name
, literal
, URI
, ndata
);
4586 } else if (xmlStrEqual(contmod
, BAD_CAST
"CDATA")) {
4587 if ((ctxt
->sax
!= NULL
) &&
4588 (ctxt
->sax
->warning
!= NULL
))
4589 ctxt
->sax
->warning(ctxt
->userData
,
4590 "CDATA entities are not supported\n");
4592 ndata
= xmlParseName(ctxt
);
4593 if ((ctxt
->sax
!= NULL
) && (!ctxt
->disableSAX
) &&
4594 (ctxt
->sax
->unparsedEntityDecl
!= NULL
)) {
4595 ctxt
->sax
->unparsedEntityDecl(ctxt
->userData
,
4596 name
, literal
, URI
, ndata
);
4602 if ((ctxt
->sax
!= NULL
) &&
4603 (!ctxt
->disableSAX
) && (ctxt
->sax
->entityDecl
!= NULL
))
4604 ctxt
->sax
->entityDecl(ctxt
->userData
, name
,
4605 XML_EXTERNAL_GENERAL_PARSED_ENTITY
,
4606 literal
, URI
, NULL
);
4612 ctxt
->errNo
= XML_ERR_ENTITY_NOT_FINISHED
;
4613 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4614 ctxt
->sax
->error(ctxt
->userData
,
4615 "docbParseEntityDecl: entity %s not terminated\n", name
);
4616 ctxt
->wellFormed
= 0;
4617 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4619 if (input
!= ctxt
->input
) {
4620 ctxt
->errNo
= XML_ERR_ENTITY_BOUNDARY
;
4621 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4622 ctxt
->sax
->error(ctxt
->userData
,
4623 "Entity declaration doesn't start and stop in the same entity\n");
4624 ctxt
->wellFormed
= 0;
4625 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4631 * Ugly mechanism to save the raw entity value.
4633 xmlEntityPtr cur
= NULL
;
4636 if ((ctxt
->sax
!= NULL
) &&
4637 (ctxt
->sax
->getParameterEntity
!= NULL
))
4638 cur
= ctxt
->sax
->getParameterEntity(ctxt
->userData
, name
);
4640 if ((ctxt
->sax
!= NULL
) &&
4641 (ctxt
->sax
->getEntity
!= NULL
))
4642 cur
= ctxt
->sax
->getEntity(ctxt
->userData
, name
);
4645 if (cur
->orig
!= NULL
)
4652 if (name
!= NULL
) xmlFree(name
);
4653 if (value
!= NULL
) xmlFree(value
);
4654 if (URI
!= NULL
) xmlFree(URI
);
4655 if (literal
!= NULL
) xmlFree(literal
);
4656 if (ndata
!= NULL
) xmlFree(ndata
);
4661 * docbParseMarkupDecl:
4662 * @ctxt: an SGML parser context
4664 * parse Markup declarations
4666 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
4667 * NotationDecl | PI | Comment
4670 docbParseMarkupDecl(xmlParserCtxtPtr ctxt
) {
4672 xmlParseElementDecl(ctxt
);
4673 xmlParseAttributeListDecl(ctxt
);
4674 docbParseEntityDecl(ctxt
);
4675 xmlParseNotationDecl(ctxt
);
4677 xmlParseComment(ctxt
);
4679 * This is only for internal subset. On external entities,
4680 * the replacement is done before parsing stage
4682 if ((ctxt
->external
== 0) && (ctxt
->inputNr
== 1))
4683 xmlParsePEReference(ctxt
);
4684 ctxt
->instate
= XML_PARSER_DTD
;
4688 * docbParseInternalSubset:
4689 * @ctxt: an SGML parser context
4691 * parse the internal subset declaration
4693 * [28 end] ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
4697 docbParseInternalSubset(xmlParserCtxtPtr ctxt
) {
4699 * Is there any DTD definition ?
4702 ctxt
->instate
= XML_PARSER_DTD
;
4705 * Parse the succession of Markup declarations and
4707 * Subsequence (markupdecl | PEReference | S)*
4709 while (RAW
!= ']') {
4710 const xmlChar
*check
= CUR_PTR
;
4711 int cons
= ctxt
->input
->consumed
;
4714 docbParseMarkupDecl(ctxt
);
4715 xmlParsePEReference(ctxt
);
4718 * Pop-up of finished entities.
4720 while ((RAW
== 0) && (ctxt
->inputNr
> 1))
4723 if ((CUR_PTR
== check
) && (cons
== ctxt
->input
->consumed
)) {
4724 ctxt
->errNo
= XML_ERR_INTERNAL_ERROR
;
4725 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4726 ctxt
->sax
->error(ctxt
->userData
,
4727 "docbParseInternalSubset: error detected in Markup declaration\n");
4728 ctxt
->wellFormed
= 0;
4729 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4740 * We should be at the end of the DOCTYPE declaration.
4743 ctxt
->errNo
= XML_ERR_DOCTYPE_NOT_FINISHED
;
4744 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4745 ctxt
->sax
->error(ctxt
->userData
, "DOCTYPE improperly terminated\n");
4746 ctxt
->wellFormed
= 0;
4747 if (ctxt
->recovery
== 0) ctxt
->disableSAX
= 1;
4754 * @ctxt: an XML parser context
4756 * parse an XML Misc* optional field.
4758 * [27] Misc ::= Comment | PI | S
4762 docbParseMisc(xmlParserCtxtPtr ctxt
) {
4763 while (((RAW
== '<') && (NXT(1) == '?')) ||
4764 ((RAW
== '<') && (NXT(1) == '!') &&
4765 (NXT(2) == '-') && (NXT(3) == '-')) ||
4767 if ((RAW
== '<') && (NXT(1) == '?')) {
4769 } else if (IS_BLANK(CUR
)) {
4772 xmlParseComment(ctxt
);
4777 * docbParseDocument :
4778 * @ctxt: an SGML parser context
4780 * parse an SGML document (and build a tree if using the standard SAX
4783 * Returns 0, -1 in case of error. the parser context is augmented
4784 * as a result of the parsing.
4788 docbParseDocument(docbParserCtxtPtr ctxt
) {
4790 xmlCharEncoding enc
;
4793 docbDefaultSAXHandlerInit();
4798 * SAX: beginning of the document processing.
4800 if ((ctxt
->sax
) && (ctxt
->sax
->setDocumentLocator
))
4801 ctxt
->sax
->setDocumentLocator(ctxt
->userData
, &xmlDefaultSAXLocator
);
4804 * Get the 4 first bytes and decode the charset
4805 * if enc != XML_CHAR_ENCODING_NONE
4806 * plug some encoding conversion routines.
4812 enc
= xmlDetectCharEncoding(start
, 4);
4813 if (enc
!= XML_CHAR_ENCODING_NONE
) {
4814 xmlSwitchEncoding(ctxt
, enc
);
4818 * Wipe out everything which is before the first '<'
4822 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
4823 ctxt
->sax
->error(ctxt
->userData
, "Document is empty\n");
4824 ctxt
->wellFormed
= 0;
4827 if ((ctxt
->sax
) && (ctxt
->sax
->startDocument
) && (!ctxt
->disableSAX
))
4828 ctxt
->sax
->startDocument(ctxt
->userData
);
4832 * The Misc part of the Prolog
4835 docbParseMisc(ctxt
);
4838 * Then possibly doc type declaration(s) and more Misc
4839 * (doctypedecl Misc*)?
4842 if ((RAW
== '<') && (NXT(1) == '!') &&
4843 (UPP(2) == 'D') && (UPP(3) == 'O') &&
4844 (UPP(4) == 'C') && (UPP(5) == 'T') &&
4845 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
4849 docbParseDocTypeDecl(ctxt
);
4851 ctxt
->instate
= XML_PARSER_DTD
;
4852 docbParseInternalSubset(ctxt
);
4856 * Create and update the external subset.
4859 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->internalSubset
!= NULL
) &&
4860 (!ctxt
->disableSAX
))
4861 ctxt
->sax
->internalSubset(ctxt
->userData
, ctxt
->intSubName
,
4862 ctxt
->extSubSystem
, ctxt
->extSubURI
);
4866 ctxt
->instate
= XML_PARSER_PROLOG
;
4867 docbParseMisc(ctxt
);
4871 * Time to start parsing the tree itself
4873 docbParseContent(ctxt
);
4879 docbAutoClose(ctxt
, NULL
);
4883 * SAX: end of the document processing.
4885 if ((ctxt
->sax
) && (ctxt
->sax
->endDocument
!= NULL
))
4886 ctxt
->sax
->endDocument(ctxt
->userData
);
4888 if (ctxt
->myDoc
!= NULL
) {
4889 dtd
= ctxt
->myDoc
->intSubset
;
4890 ctxt
->myDoc
->standalone
= -1;
4892 ctxt
->myDoc
->intSubset
=
4893 xmlCreateIntSubset(ctxt
->myDoc
, BAD_CAST
"SGML",
4894 BAD_CAST
"-//W3C//DTD SGML 4.0 Transitional//EN",
4895 BAD_CAST
"http://www.w3.org/TR/REC-docbook/loose.dtd");
4897 if (! ctxt
->wellFormed
) return(-1);
4902 /************************************************************************
4904 * Parser contexts handling *
4906 ************************************************************************/
4909 * docbInitParserCtxt:
4910 * @ctxt: an SGML parser context
4912 * Initialize a parser context
4916 docbInitParserCtxt(docbParserCtxtPtr ctxt
)
4918 docbSAXHandler
*sax
;
4920 if (ctxt
== NULL
) return;
4921 memset(ctxt
, 0, sizeof(docbParserCtxt
));
4923 sax
= (docbSAXHandler
*) xmlMalloc(sizeof(docbSAXHandler
));
4925 xmlGenericError(xmlGenericErrorContext
,
4926 "docbInitParserCtxt: out of memory\n");
4928 memset(sax
, 0, sizeof(docbSAXHandler
));
4930 /* Allocate the Input stack */
4931 ctxt
->inputTab
= (docbParserInputPtr
*)
4932 xmlMalloc(5 * sizeof(docbParserInputPtr
));
4933 if (ctxt
->inputTab
== NULL
) {
4934 xmlGenericError(xmlGenericErrorContext
,
4935 "docbInitParserCtxt: out of memory\n");
4940 ctxt
->version
= NULL
;
4941 ctxt
->encoding
= NULL
;
4942 ctxt
->standalone
= -1;
4943 ctxt
->instate
= XML_PARSER_START
;
4945 /* Allocate the Node stack */
4946 ctxt
->nodeTab
= (docbNodePtr
*) xmlMalloc(10 * sizeof(docbNodePtr
));
4951 /* Allocate the Name stack */
4952 ctxt
->nameTab
= (xmlChar
**) xmlMalloc(10 * sizeof(xmlChar
*));
4957 if (sax
== NULL
) ctxt
->sax
= &docbDefaultSAXHandler
;
4960 memcpy(sax
, &docbDefaultSAXHandler
, sizeof(docbSAXHandler
));
4962 ctxt
->userData
= ctxt
;
4964 ctxt
->wellFormed
= 1;
4965 ctxt
->linenumbers
= xmlLineNumbersDefaultValue
;
4966 ctxt
->replaceEntities
= xmlSubstituteEntitiesDefaultValue
;
4968 ctxt
->record_info
= 0;
4971 ctxt
->checkIndex
= 0;
4972 xmlInitNodeInfoSeq(&ctxt
->node_seq
);
4976 * docbFreeParserCtxt:
4977 * @ctxt: an SGML parser context
4979 * Free all the memory used by a parser context. However the parsed
4980 * document in ctxt->myDoc is not freed.
4984 docbFreeParserCtxt(docbParserCtxtPtr ctxt
)
4986 xmlFreeParserCtxt(ctxt
);
4990 * docbCreateDocParserCtxt :
4991 * @cur: a pointer to an array of xmlChar
4992 * @encoding: the SGML document encoding, or NULL
4994 * Create a parser context for an SGML document.
4996 * Returns the new parser context or NULL
4998 static docbParserCtxtPtr
4999 docbCreateDocParserCtxt(xmlChar
*cur
, const char *encoding ATTRIBUTE_UNUSED
) {
5000 docbParserCtxtPtr ctxt
;
5001 docbParserInputPtr input
;
5002 /* sgmlCharEncoding enc; */
5004 ctxt
= (docbParserCtxtPtr
) xmlMalloc(sizeof(docbParserCtxt
));
5006 xmlGenericError(xmlGenericErrorContext
, "malloc failed");
5009 docbInitParserCtxt(ctxt
);
5010 input
= (docbParserInputPtr
) xmlMalloc(sizeof(docbParserInput
));
5011 if (input
== NULL
) {
5012 xmlGenericError(xmlGenericErrorContext
, "malloc failed");
5016 memset(input
, 0, sizeof(docbParserInput
));
5023 inputPush(ctxt
, input
);
5027 /************************************************************************
5029 * Progressive parsing interfaces *
5031 ************************************************************************/
5034 * docbParseLookupSequence:
5035 * @ctxt: an SGML parser context
5036 * @first: the first char to lookup
5037 * @next: the next char to lookup or zero
5038 * @third: the next char to lookup or zero
5040 * Try to find if a sequence (first, next, third) or just (first next) or
5041 * (first) is available in the input stream.
5042 * This function has a side effect of (possibly) incrementing ctxt->checkIndex
5043 * to avoid rescanning sequences of bytes, it DOES change the state of the
5044 * parser, do not use liberally.
5045 * This is basically similar to xmlParseLookupSequence()
5047 * Returns the index to the current parsing point if the full sequence
5048 * is available, -1 otherwise.
5051 docbParseLookupSequence(docbParserCtxtPtr ctxt
, xmlChar first
,
5052 xmlChar next
, xmlChar third
) {
5054 docbParserInputPtr in
;
5058 if (in
== NULL
) return(-1);
5059 base
= in
->cur
- in
->base
;
5060 if (base
< 0) return(-1);
5061 if (ctxt
->checkIndex
> base
)
5062 base
= ctxt
->checkIndex
;
5063 if (in
->buf
== NULL
) {
5067 buf
= in
->buf
->buffer
->content
;
5068 len
= in
->buf
->buffer
->use
;
5070 /* take into account the sequence length */
5071 if (third
) len
-= 2;
5072 else if (next
) len
--;
5073 for (;base
< len
;base
++) {
5074 if (buf
[base
] == first
) {
5076 if ((buf
[base
+ 1] != next
) ||
5077 (buf
[base
+ 2] != third
)) continue;
5078 } else if (next
!= 0) {
5079 if (buf
[base
+ 1] != next
) continue;
5081 ctxt
->checkIndex
= 0;
5084 xmlGenericError(xmlGenericErrorContext
,
5085 "HPP: lookup '%c' found at %d\n",
5087 else if (third
== 0)
5088 xmlGenericError(xmlGenericErrorContext
,
5089 "HPP: lookup '%c%c' found at %d\n",
5092 xmlGenericError(xmlGenericErrorContext
,
5093 "HPP: lookup '%c%c%c' found at %d\n",
5094 first
, next
, third
, base
);
5096 return(base
- (in
->cur
- in
->base
));
5099 ctxt
->checkIndex
= base
;
5102 xmlGenericError(xmlGenericErrorContext
,
5103 "HPP: lookup '%c' failed\n", first
);
5104 else if (third
== 0)
5105 xmlGenericError(xmlGenericErrorContext
,
5106 "HPP: lookup '%c%c' failed\n", first
, next
);
5108 xmlGenericError(xmlGenericErrorContext
,
5109 "HPP: lookup '%c%c%c' failed\n", first
, next
, third
);
5115 * docbParseTryOrFinish:
5116 * @ctxt: an SGML parser context
5117 * @terminate: last chunk indicator
5119 * Try to progress on parsing
5121 * Returns zero if no parsing was possible
5124 docbParseTryOrFinish(docbParserCtxtPtr ctxt
, int terminate
) {
5126 docbParserInputPtr in
;
5131 switch (ctxt
->instate
) {
5132 case XML_PARSER_EOF
:
5133 xmlGenericError(xmlGenericErrorContext
,
5134 "HPP: try EOF\n"); break;
5135 case XML_PARSER_START
:
5136 xmlGenericError(xmlGenericErrorContext
,
5137 "HPP: try START\n"); break;
5138 case XML_PARSER_MISC
:
5139 xmlGenericError(xmlGenericErrorContext
,
5140 "HPP: try MISC\n");break;
5141 case XML_PARSER_COMMENT
:
5142 xmlGenericError(xmlGenericErrorContext
,
5143 "HPP: try COMMENT\n");break;
5144 case XML_PARSER_PROLOG
:
5145 xmlGenericError(xmlGenericErrorContext
,
5146 "HPP: try PROLOG\n");break;
5147 case XML_PARSER_START_TAG
:
5148 xmlGenericError(xmlGenericErrorContext
,
5149 "HPP: try START_TAG\n");break;
5150 case XML_PARSER_CONTENT
:
5151 xmlGenericError(xmlGenericErrorContext
,
5152 "HPP: try CONTENT\n");break;
5153 case XML_PARSER_CDATA_SECTION
:
5154 xmlGenericError(xmlGenericErrorContext
,
5155 "HPP: try CDATA_SECTION\n");break;
5156 case XML_PARSER_END_TAG
:
5157 xmlGenericError(xmlGenericErrorContext
,
5158 "HPP: try END_TAG\n");break;
5159 case XML_PARSER_ENTITY_DECL
:
5160 xmlGenericError(xmlGenericErrorContext
,
5161 "HPP: try ENTITY_DECL\n");break;
5162 case XML_PARSER_ENTITY_VALUE
:
5163 xmlGenericError(xmlGenericErrorContext
,
5164 "HPP: try ENTITY_VALUE\n");break;
5165 case XML_PARSER_ATTRIBUTE_VALUE
:
5166 xmlGenericError(xmlGenericErrorContext
,
5167 "HPP: try ATTRIBUTE_VALUE\n");break;
5168 case XML_PARSER_DTD
:
5169 xmlGenericError(xmlGenericErrorContext
,
5170 "HPP: try DTD\n");break;
5171 case XML_PARSER_EPILOG
:
5172 xmlGenericError(xmlGenericErrorContext
,
5173 "HPP: try EPILOG\n");break;
5175 xmlGenericError(xmlGenericErrorContext
,
5176 "HPP: try PI\n");break;
5183 if (in
== NULL
) break;
5184 if (in
->buf
== NULL
)
5185 avail
= in
->length
- (in
->cur
- in
->base
);
5187 avail
= in
->buf
->buffer
->use
- (in
->cur
- in
->base
);
5188 if ((avail
== 0) && (terminate
)) {
5189 docbAutoClose(ctxt
, NULL
);
5190 if ((ctxt
->nameNr
== 0) && (ctxt
->instate
!= XML_PARSER_EOF
)) {
5192 * SAX: end of the document processing.
5194 ctxt
->instate
= XML_PARSER_EOF
;
5195 if ((ctxt
->sax
) && (ctxt
->sax
->endDocument
!= NULL
))
5196 ctxt
->sax
->endDocument(ctxt
->userData
);
5201 switch (ctxt
->instate
) {
5202 case XML_PARSER_EOF
:
5204 * Document parsing is done !
5207 case XML_PARSER_START
:
5209 * Very first chars read from the document flow.
5212 if (IS_BLANK(cur
)) {
5214 if (in
->buf
== NULL
)
5215 avail
= in
->length
- (in
->cur
- in
->base
);
5217 avail
= in
->buf
->buffer
->use
- (in
->cur
- in
->base
);
5219 if ((ctxt
->sax
) && (ctxt
->sax
->setDocumentLocator
))
5220 ctxt
->sax
->setDocumentLocator(ctxt
->userData
,
5221 &xmlDefaultSAXLocator
);
5222 if ((ctxt
->sax
) && (ctxt
->sax
->startDocument
) &&
5223 (!ctxt
->disableSAX
))
5224 ctxt
->sax
->startDocument(ctxt
->userData
);
5228 if ((cur
== '<') && (next
== '!') &&
5229 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5230 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5231 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5234 (docbParseLookupSequence(ctxt
, '>', 0, 0) < 0))
5237 xmlGenericError(xmlGenericErrorContext
,
5238 "HPP: Parsing internal subset\n");
5240 docbParseDocTypeDecl(ctxt
);
5241 ctxt
->instate
= XML_PARSER_PROLOG
;
5243 xmlGenericError(xmlGenericErrorContext
,
5244 "HPP: entering PROLOG\n");
5247 ctxt
->instate
= XML_PARSER_MISC
;
5250 xmlGenericError(xmlGenericErrorContext
,
5251 "HPP: entering MISC\n");
5254 case XML_PARSER_MISC
:
5256 if (in
->buf
== NULL
)
5257 avail
= in
->length
- (in
->cur
- in
->base
);
5259 avail
= in
->buf
->buffer
->use
- (in
->cur
- in
->base
);
5264 if ((cur
== '<') && (next
== '!') &&
5265 (in
->cur
[2] == '-') && (in
->cur
[3] == '-')) {
5267 (docbParseLookupSequence(ctxt
, '-', '-', '>') < 0))
5270 xmlGenericError(xmlGenericErrorContext
,
5271 "HPP: Parsing Comment\n");
5273 docbParseComment(ctxt
);
5274 ctxt
->instate
= XML_PARSER_MISC
;
5275 } else if ((cur
== '<') && (next
== '!') &&
5276 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5277 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5278 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5281 (docbParseLookupSequence(ctxt
, '>', 0, 0) < 0))
5284 xmlGenericError(xmlGenericErrorContext
,
5285 "HPP: Parsing internal subset\n");
5287 docbParseDocTypeDecl(ctxt
);
5288 ctxt
->instate
= XML_PARSER_PROLOG
;
5290 xmlGenericError(xmlGenericErrorContext
,
5291 "HPP: entering PROLOG\n");
5293 } else if ((cur
== '<') && (next
== '!') &&
5297 ctxt
->instate
= XML_PARSER_START_TAG
;
5299 xmlGenericError(xmlGenericErrorContext
,
5300 "HPP: entering START_TAG\n");
5304 case XML_PARSER_PROLOG
:
5306 if (in
->buf
== NULL
)
5307 avail
= in
->length
- (in
->cur
- in
->base
);
5309 avail
= in
->buf
->buffer
->use
- (in
->cur
- in
->base
);
5314 if ((cur
== '<') && (next
== '!') &&
5315 (in
->cur
[2] == '-') && (in
->cur
[3] == '-')) {
5317 (docbParseLookupSequence(ctxt
, '-', '-', '>') < 0))
5320 xmlGenericError(xmlGenericErrorContext
,
5321 "HPP: Parsing Comment\n");
5323 docbParseComment(ctxt
);
5324 ctxt
->instate
= XML_PARSER_PROLOG
;
5325 } else if ((cur
== '<') && (next
== '!') &&
5329 ctxt
->instate
= XML_PARSER_START_TAG
;
5331 xmlGenericError(xmlGenericErrorContext
,
5332 "HPP: entering START_TAG\n");
5336 case XML_PARSER_EPILOG
:
5337 if (in
->buf
== NULL
)
5338 avail
= in
->length
- (in
->cur
- in
->base
);
5340 avail
= in
->buf
->buffer
->use
- (in
->cur
- in
->base
);
5344 if (IS_BLANK(cur
)) {
5345 docbParseCharData(ctxt
);
5351 if ((cur
== '<') && (next
== '!') &&
5352 (in
->cur
[2] == '-') && (in
->cur
[3] == '-')) {
5354 (docbParseLookupSequence(ctxt
, '-', '-', '>') < 0))
5357 xmlGenericError(xmlGenericErrorContext
,
5358 "HPP: Parsing Comment\n");
5360 docbParseComment(ctxt
);
5361 ctxt
->instate
= XML_PARSER_EPILOG
;
5362 } else if ((cur
== '<') && (next
== '!') &&
5366 ctxt
->errNo
= XML_ERR_DOCUMENT_END
;
5367 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
5368 ctxt
->sax
->error(ctxt
->userData
,
5369 "Extra content at the end of the document\n");
5370 ctxt
->wellFormed
= 0;
5371 ctxt
->instate
= XML_PARSER_EOF
;
5373 xmlGenericError(xmlGenericErrorContext
,
5374 "HPP: entering EOF\n");
5376 if ((ctxt
->sax
) && (ctxt
->sax
->endDocument
!= NULL
))
5377 ctxt
->sax
->endDocument(ctxt
->userData
);
5381 case XML_PARSER_START_TAG
: {
5382 xmlChar
*name
, *oldname
;
5383 int depth
= ctxt
->nameNr
;
5384 docbElemDescPtr info
;
5390 ctxt
->instate
= XML_PARSER_CONTENT
;
5392 xmlGenericError(xmlGenericErrorContext
,
5393 "HPP: entering CONTENT\n");
5398 (docbParseLookupSequence(ctxt
, '>', 0, 0) < 0))
5401 oldname
= xmlStrdup(ctxt
->name
);
5402 docbParseStartTag(ctxt
);
5405 if (oldname
== NULL
)
5406 xmlGenericError(xmlGenericErrorContext
,
5407 "Start of element %s\n", name
);
5408 else if (name
== NULL
)
5409 xmlGenericError(xmlGenericErrorContext
,
5410 "Start of element failed, was %s\n",
5413 xmlGenericError(xmlGenericErrorContext
,
5414 "Start of element %s, was %s\n",
5417 if (((depth
== ctxt
->nameNr
) &&
5418 (xmlStrEqual(oldname
, ctxt
->name
))) ||
5422 if (oldname
!= NULL
)
5426 if (oldname
!= NULL
)
5430 * Lookup the info for that element.
5432 info
= docbTagLookup(name
);
5434 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
5435 ctxt
->sax
->error(ctxt
->userData
, "Tag %s unknown\n",
5437 ctxt
->wellFormed
= 0;
5438 } else if (info
->depr
) {
5439 /***************************
5440 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
5441 ctxt->sax->warning(ctxt->userData,
5442 "Tag %s is deprecated\n",
5444 ***************************/
5448 * Check for an Empty Element labeled the XML/SGML way
5450 if ((CUR
== '/') && (NXT(1) == '>')) {
5452 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->endElement
!= NULL
))
5453 ctxt
->sax
->endElement(ctxt
->userData
, name
);
5454 oldname
= docbnamePop(ctxt
);
5456 xmlGenericError(xmlGenericErrorContext
,"End of tag the XML way: popping out %s\n",
5459 if (oldname
!= NULL
)
5461 ctxt
->instate
= XML_PARSER_CONTENT
;
5463 xmlGenericError(xmlGenericErrorContext
,
5464 "HPP: entering CONTENT\n");
5472 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
5473 ctxt
->sax
->error(ctxt
->userData
,
5474 "Couldn't find end of Start Tag %s\n",
5476 ctxt
->wellFormed
= 0;
5479 * end of parsing of this node.
5481 if (xmlStrEqual(name
, ctxt
->name
)) {
5483 oldname
= docbnamePop(ctxt
);
5485 xmlGenericError(xmlGenericErrorContext
,
5486 "End of start tag problem: popping out %s\n", oldname
);
5488 if (oldname
!= NULL
)
5492 ctxt
->instate
= XML_PARSER_CONTENT
;
5494 xmlGenericError(xmlGenericErrorContext
,
5495 "HPP: entering CONTENT\n");
5501 * Check for an Empty Element from DTD definition
5503 if ((info
!= NULL
) && (info
->empty
)) {
5504 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->endElement
!= NULL
))
5505 ctxt
->sax
->endElement(ctxt
->userData
, name
);
5506 oldname
= docbnamePop(ctxt
);
5508 xmlGenericError(xmlGenericErrorContext
,"End of empty tag %s : popping out %s\n", name
, oldname
);
5510 if (oldname
!= NULL
)
5513 ctxt
->instate
= XML_PARSER_CONTENT
;
5515 xmlGenericError(xmlGenericErrorContext
,
5516 "HPP: entering CONTENT\n");
5520 case XML_PARSER_CONTENT
: {
5523 * Handle preparsed entities and charRef
5525 if (ctxt
->token
!= 0) {
5526 xmlChar chr
[2] = { 0 , 0 } ;
5528 chr
[0] = (xmlChar
) ctxt
->token
;
5529 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->characters
!= NULL
))
5530 ctxt
->sax
->characters(ctxt
->userData
, chr
, 1);
5532 ctxt
->checkIndex
= 0;
5534 if ((avail
== 1) && (terminate
)) {
5536 if ((cur
!= '<') && (cur
!= '&')) {
5537 if (ctxt
->sax
!= NULL
) {
5538 if (IS_BLANK(cur
)) {
5539 if (ctxt
->sax
->ignorableWhitespace
!= NULL
)
5540 ctxt
->sax
->ignorableWhitespace(
5541 ctxt
->userData
, &cur
, 1);
5543 if (ctxt
->sax
->characters
!= NULL
)
5544 ctxt
->sax
->characters(
5545 ctxt
->userData
, &cur
, 1);
5549 ctxt
->checkIndex
= 0;
5558 cons
= ctxt
->nbChars
;
5560 * Sometimes DOCTYPE arrives in the middle of the document
5562 if ((cur
== '<') && (next
== '!') &&
5563 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5564 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5565 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5568 (docbParseLookupSequence(ctxt
, '>', 0, 0) < 0))
5570 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
5571 ctxt
->sax
->error(ctxt
->userData
,
5572 "Misplaced DOCTYPE declaration\n");
5573 ctxt
->wellFormed
= 0;
5574 docbParseDocTypeDecl(ctxt
);
5575 } else if ((cur
== '<') && (next
== '!') &&
5576 (in
->cur
[2] == '-') && (in
->cur
[3] == '-')) {
5578 (docbParseLookupSequence(ctxt
, '-', '-', '>') < 0))
5581 xmlGenericError(xmlGenericErrorContext
,
5582 "HPP: Parsing Comment\n");
5584 docbParseComment(ctxt
);
5585 ctxt
->instate
= XML_PARSER_CONTENT
;
5586 } else if ((cur
== '<') && (next
== '!') && (avail
< 4)) {
5588 } else if ((cur
== '<') && (next
== '/')) {
5589 ctxt
->instate
= XML_PARSER_END_TAG
;
5590 ctxt
->checkIndex
= 0;
5592 xmlGenericError(xmlGenericErrorContext
,
5593 "HPP: entering END_TAG\n");
5596 } else if (cur
== '<') {
5597 ctxt
->instate
= XML_PARSER_START_TAG
;
5598 ctxt
->checkIndex
= 0;
5600 xmlGenericError(xmlGenericErrorContext
,
5601 "HPP: entering START_TAG\n");
5604 } else if (cur
== '&') {
5606 (docbParseLookupSequence(ctxt
, ';', 0, 0) < 0))
5609 xmlGenericError(xmlGenericErrorContext
,
5610 "HPP: Parsing Reference\n");
5612 /* TODO: check generation of subtrees if noent !!! */
5613 docbParseReference(ctxt
);
5615 /* TODO Avoid the extra copy, handle directly !!!!!! */
5617 * Goal of the following test is :
5618 * - minimize calls to the SAX 'character' callback
5619 * when they are mergeable
5621 if ((ctxt
->inputNr
== 1) &&
5622 (avail
< DOCB_PARSER_BIG_BUFFER_SIZE
)) {
5624 (docbParseLookupSequence(ctxt
, '<', 0, 0) < 0))
5627 ctxt
->checkIndex
= 0;
5629 xmlGenericError(xmlGenericErrorContext
,
5630 "HPP: Parsing char data\n");
5632 docbParseCharData(ctxt
);
5634 if (cons
== ctxt
->nbChars
) {
5635 if (ctxt
->node
!= NULL
) {
5636 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
5637 ctxt
->sax
->error(ctxt
->userData
,
5638 "detected an error in element content\n");
5639 ctxt
->wellFormed
= 0;
5647 case XML_PARSER_END_TAG
:
5651 (docbParseLookupSequence(ctxt
, '>', 0, 0) < 0))
5653 docbParseEndTag(ctxt
);
5654 if (ctxt
->nameNr
== 0) {
5655 ctxt
->instate
= XML_PARSER_EPILOG
;
5657 ctxt
->instate
= XML_PARSER_CONTENT
;
5659 ctxt
->checkIndex
= 0;
5661 xmlGenericError(xmlGenericErrorContext
,
5662 "HPP: entering CONTENT\n");
5665 case XML_PARSER_CDATA_SECTION
:
5666 xmlGenericError(xmlGenericErrorContext
,
5667 "HPP: internal error, state == CDATA\n");
5668 ctxt
->instate
= XML_PARSER_CONTENT
;
5669 ctxt
->checkIndex
= 0;
5671 xmlGenericError(xmlGenericErrorContext
,
5672 "HPP: entering CONTENT\n");
5675 case XML_PARSER_DTD
:
5676 xmlGenericError(xmlGenericErrorContext
,
5677 "HPP: internal error, state == DTD\n");
5678 ctxt
->instate
= XML_PARSER_CONTENT
;
5679 ctxt
->checkIndex
= 0;
5681 xmlGenericError(xmlGenericErrorContext
,
5682 "HPP: entering CONTENT\n");
5685 case XML_PARSER_COMMENT
:
5686 xmlGenericError(xmlGenericErrorContext
,
5687 "HPP: internal error, state == COMMENT\n");
5688 ctxt
->instate
= XML_PARSER_CONTENT
;
5689 ctxt
->checkIndex
= 0;
5691 xmlGenericError(xmlGenericErrorContext
,
5692 "HPP: entering CONTENT\n");
5696 xmlGenericError(xmlGenericErrorContext
,
5697 "HPP: internal error, state == PI\n");
5698 ctxt
->instate
= XML_PARSER_CONTENT
;
5699 ctxt
->checkIndex
= 0;
5701 xmlGenericError(xmlGenericErrorContext
,
5702 "HPP: entering CONTENT\n");
5705 case XML_PARSER_ENTITY_DECL
:
5706 xmlGenericError(xmlGenericErrorContext
,
5707 "HPP: internal error, state == ENTITY_DECL\n");
5708 ctxt
->instate
= XML_PARSER_CONTENT
;
5709 ctxt
->checkIndex
= 0;
5711 xmlGenericError(xmlGenericErrorContext
,
5712 "HPP: entering CONTENT\n");
5715 case XML_PARSER_ENTITY_VALUE
:
5716 xmlGenericError(xmlGenericErrorContext
,
5717 "HPP: internal error, state == ENTITY_VALUE\n");
5718 ctxt
->instate
= XML_PARSER_CONTENT
;
5719 ctxt
->checkIndex
= 0;
5721 xmlGenericError(xmlGenericErrorContext
,
5722 "HPP: entering DTD\n");
5725 case XML_PARSER_ATTRIBUTE_VALUE
:
5726 xmlGenericError(xmlGenericErrorContext
,
5727 "HPP: internal error, state == ATTRIBUTE_VALUE\n");
5728 ctxt
->instate
= XML_PARSER_START_TAG
;
5729 ctxt
->checkIndex
= 0;
5731 xmlGenericError(xmlGenericErrorContext
,
5732 "HPP: entering START_TAG\n");
5735 case XML_PARSER_SYSTEM_LITERAL
:
5736 xmlGenericError(xmlGenericErrorContext
,
5737 "HPP: internal error, state == XML_PARSER_SYSTEM_LITERAL\n");
5738 ctxt
->instate
= XML_PARSER_CONTENT
;
5739 ctxt
->checkIndex
= 0;
5741 xmlGenericError(xmlGenericErrorContext
,
5742 "HPP: entering CONTENT\n");
5746 case XML_PARSER_IGNORE
:
5747 xmlGenericError(xmlGenericErrorContext
,
5748 "HPP: internal error, state == XML_PARSER_IGNORE\n");
5749 ctxt
->instate
= XML_PARSER_CONTENT
;
5750 ctxt
->checkIndex
= 0;
5752 xmlGenericError(xmlGenericErrorContext
,
5753 "HPP: entering CONTENT\n");
5756 case XML_PARSER_PUBLIC_LITERAL
:
5757 xmlGenericError(xmlGenericErrorContext
,
5758 "HPP: internal error, state == XML_PARSER_LITERAL\n");
5759 ctxt
->instate
= XML_PARSER_CONTENT
;
5760 ctxt
->checkIndex
= 0;
5762 xmlGenericError(xmlGenericErrorContext
,
5763 "HPP: entering CONTENT\n");
5769 if ((avail
== 0) && (terminate
)) {
5770 docbAutoClose(ctxt
, NULL
);
5771 if ((ctxt
->nameNr
== 0) && (ctxt
->instate
!= XML_PARSER_EOF
)) {
5773 * SAX: end of the document processing.
5775 ctxt
->instate
= XML_PARSER_EOF
;
5776 if ((ctxt
->sax
) && (ctxt
->sax
->endDocument
!= NULL
))
5777 ctxt
->sax
->endDocument(ctxt
->userData
);
5780 if ((ctxt
->myDoc
!= NULL
) &&
5781 ((terminate
) || (ctxt
->instate
== XML_PARSER_EOF
) ||
5782 (ctxt
->instate
== XML_PARSER_EPILOG
))) {
5784 dtd
= ctxt
->myDoc
->intSubset
;
5786 ctxt
->myDoc
->intSubset
=
5787 xmlCreateIntSubset(ctxt
->myDoc
, BAD_CAST
"SGML",
5788 BAD_CAST
"-//W3C//DTD SGML 4.0 Transitional//EN",
5789 BAD_CAST
"http://www.w3.org/TR/REC-docbook/loose.dtd");
5792 xmlGenericError(xmlGenericErrorContext
, "HPP: done %d\n", ret
);
5799 * @ctxt: an XML parser context
5800 * @chunk: an char array
5801 * @size: the size in byte of the chunk
5802 * @terminate: last chunk indicator
5804 * Parse a Chunk of memory
5806 * Returns zero if no error, the xmlParserErrors otherwise.
5809 docbParseChunk(docbParserCtxtPtr ctxt
, const char *chunk
, int size
,
5811 if ((size
> 0) && (chunk
!= NULL
) && (ctxt
->input
!= NULL
) &&
5812 (ctxt
->input
->buf
!= NULL
) && (ctxt
->instate
!= XML_PARSER_EOF
)) {
5813 int base
= ctxt
->input
->base
- ctxt
->input
->buf
->buffer
->content
;
5814 int cur
= ctxt
->input
->cur
- ctxt
->input
->base
;
5816 xmlParserInputBufferPush(ctxt
->input
->buf
, size
, chunk
);
5817 ctxt
->input
->base
= ctxt
->input
->buf
->buffer
->content
+ base
;
5818 ctxt
->input
->cur
= ctxt
->input
->base
+ cur
;
5820 xmlGenericError(xmlGenericErrorContext
, "HPP: pushed %d\n", size
);
5823 if ((terminate
) || (ctxt
->input
->buf
->buffer
->use
> 80))
5824 docbParseTryOrFinish(ctxt
, terminate
);
5825 } else if (ctxt
->instate
!= XML_PARSER_EOF
) {
5826 xmlParserInputBufferPush(ctxt
->input
->buf
, 0, "");
5827 docbParseTryOrFinish(ctxt
, terminate
);
5830 if ((ctxt
->instate
!= XML_PARSER_EOF
) &&
5831 (ctxt
->instate
!= XML_PARSER_EPILOG
) &&
5832 (ctxt
->instate
!= XML_PARSER_MISC
)) {
5833 ctxt
->errNo
= XML_ERR_DOCUMENT_END
;
5834 if ((ctxt
->sax
!= NULL
) && (ctxt
->sax
->error
!= NULL
))
5835 ctxt
->sax
->error(ctxt
->userData
,
5836 "Extra content at the end of the document\n");
5837 ctxt
->wellFormed
= 0;
5839 if (ctxt
->instate
!= XML_PARSER_EOF
) {
5840 if ((ctxt
->sax
) && (ctxt
->sax
->endDocument
!= NULL
))
5841 ctxt
->sax
->endDocument(ctxt
->userData
);
5843 ctxt
->instate
= XML_PARSER_EOF
;
5845 return((xmlParserErrors
) ctxt
->errNo
);
5848 /************************************************************************
5850 * User entry points *
5852 ************************************************************************/
5855 * docbCreatePushParserCtxt :
5856 * @sax: a SAX handler
5857 * @user_data: The user data returned on SAX callbacks
5858 * @chunk: a pointer to an array of chars
5859 * @size: number of chars in the array
5860 * @filename: an optional file name or URI
5861 * @enc: an optional encoding
5863 * Create a parser context for using the DocBook SGML parser in push mode
5864 * To allow content encoding detection, @size should be >= 4
5865 * The value of @filename is used for fetching external entities
5866 * and error/warning reports.
5868 * Returns the new parser context or NULL
5871 docbCreatePushParserCtxt(docbSAXHandlerPtr sax
, void *user_data
,
5872 const char *chunk
, int size
, const char *filename
,
5873 xmlCharEncoding enc
) {
5874 docbParserCtxtPtr ctxt
;
5875 docbParserInputPtr inputStream
;
5876 xmlParserInputBufferPtr buf
;
5878 buf
= xmlAllocParserInputBuffer(enc
);
5879 if (buf
== NULL
) return(NULL
);
5881 ctxt
= (docbParserCtxtPtr
) xmlMalloc(sizeof(docbParserCtxt
));
5886 memset(ctxt
, 0, sizeof(docbParserCtxt
));
5887 docbInitParserCtxt(ctxt
);
5889 if (ctxt
->sax
!= &docbDefaultSAXHandler
)
5891 ctxt
->sax
= (docbSAXHandlerPtr
) xmlMalloc(sizeof(docbSAXHandler
));
5892 if (ctxt
->sax
== NULL
) {
5897 memcpy(ctxt
->sax
, sax
, sizeof(docbSAXHandler
));
5898 if (user_data
!= NULL
)
5899 ctxt
->userData
= user_data
;
5901 if (filename
== NULL
) {
5902 ctxt
->directory
= NULL
;
5904 ctxt
->directory
= xmlParserGetDirectory(filename
);
5907 inputStream
= docbNewInputStream(ctxt
);
5908 if (inputStream
== NULL
) {
5909 xmlFreeParserCtxt(ctxt
);
5913 if (filename
== NULL
)
5914 inputStream
->filename
= NULL
;
5916 inputStream
->filename
= xmlMemStrdup(filename
);
5917 inputStream
->buf
= buf
;
5918 inputStream
->base
= inputStream
->buf
->buffer
->content
;
5919 inputStream
->cur
= inputStream
->buf
->buffer
->content
;
5921 inputPush(ctxt
, inputStream
);
5923 if ((size
> 0) && (chunk
!= NULL
) && (ctxt
->input
!= NULL
) &&
5924 (ctxt
->input
->buf
!= NULL
)) {
5925 xmlParserInputBufferPush(ctxt
->input
->buf
, size
, chunk
);
5927 xmlGenericError(xmlGenericErrorContext
, "HPP: pushed %d\n", size
);
5936 * @cur: a pointer to an array of xmlChar
5937 * @encoding: a free form C string describing the SGML document encoding, or NULL
5938 * @sax: the SAX handler block
5939 * @userData: if using SAX, this pointer will be provided on callbacks.
5941 * parse an SGML in-memory document and build a tree.
5942 * It use the given SAX function block to handle the parsing callback.
5943 * If sax is NULL, fallback to the default DOM tree building routines.
5945 * Returns the resulting document tree
5949 docbSAXParseDoc(xmlChar
*cur
, const char *encoding
, docbSAXHandlerPtr sax
, void *userData
) {
5951 docbParserCtxtPtr ctxt
;
5953 if (cur
== NULL
) return(NULL
);
5956 ctxt
= docbCreateDocParserCtxt(cur
, encoding
);
5957 if (ctxt
== NULL
) return(NULL
);
5960 ctxt
->userData
= userData
;
5963 docbParseDocument(ctxt
);
5967 ctxt
->userData
= NULL
;
5969 docbFreeParserCtxt(ctxt
);
5976 * @cur: a pointer to an array of xmlChar
5977 * @encoding: a free form C string describing the SGML document encoding, or NULL
5979 * parse an SGML in-memory document and build a tree.
5981 * Returns the resulting document tree
5985 docbParseDoc(xmlChar
*cur
, const char *encoding
) {
5986 return(docbSAXParseDoc(cur
, encoding
, NULL
, NULL
));
5991 * docbCreateFileParserCtxt :
5992 * @filename: the filename
5993 * @encoding: the SGML document encoding, or NULL
5995 * Create a parser context for a file content.
5996 * Automatic support for ZLIB/Compress compressed document is provided
5997 * by default if found at compile-time.
5999 * Returns the new parser context or NULL
6002 docbCreateFileParserCtxt(const char *filename
,
6003 const char *encoding ATTRIBUTE_UNUSED
)
6005 docbParserCtxtPtr ctxt
;
6006 docbParserInputPtr inputStream
;
6007 xmlParserInputBufferPtr buf
;
6008 /* sgmlCharEncoding enc; */
6010 buf
= xmlParserInputBufferCreateFilename(filename
, XML_CHAR_ENCODING_NONE
);
6011 if (buf
== NULL
) return(NULL
);
6013 ctxt
= (docbParserCtxtPtr
) xmlMalloc(sizeof(docbParserCtxt
));
6015 xmlGenericError(xmlGenericErrorContext
, "malloc failed");
6018 memset(ctxt
, 0, sizeof(docbParserCtxt
));
6019 docbInitParserCtxt(ctxt
);
6020 inputStream
= (docbParserInputPtr
) xmlMalloc(sizeof(docbParserInput
));
6021 if (inputStream
== NULL
) {
6022 xmlGenericError(xmlGenericErrorContext
, "malloc failed");
6026 memset(inputStream
, 0, sizeof(docbParserInput
));
6028 inputStream
->filename
= (char *)
6029 xmlNormalizeWindowsPath((const xmlChar
*)filename
);
6030 inputStream
->line
= 1;
6031 inputStream
->col
= 1;
6032 inputStream
->buf
= buf
;
6033 inputStream
->directory
= NULL
;
6035 inputStream
->base
= inputStream
->buf
->buffer
->content
;
6036 inputStream
->cur
= inputStream
->buf
->buffer
->content
;
6037 inputStream
->free
= NULL
;
6039 inputPush(ctxt
, inputStream
);
6044 * docbSAXParseFile :
6045 * @filename: the filename
6046 * @encoding: a free form C string describing the SGML document encoding, or NULL
6047 * @sax: the SAX handler block
6048 * @userData: if using SAX, this pointer will be provided on callbacks.
6050 * parse an SGML file and build a tree. Automatic support for ZLIB/Compress
6051 * compressed document is provided by default if found at compile-time.
6052 * It use the given SAX function block to handle the parsing callback.
6053 * If sax is NULL, fallback to the default DOM tree building routines.
6055 * Returns the resulting document tree
6059 docbSAXParseFile(const char *filename
, const char *encoding
, docbSAXHandlerPtr sax
,
6062 docbParserCtxtPtr ctxt
;
6063 docbSAXHandlerPtr oldsax
= NULL
;
6065 ctxt
= docbCreateFileParserCtxt(filename
, encoding
);
6066 if (ctxt
== NULL
) return(NULL
);
6070 ctxt
->userData
= userData
;
6073 docbParseDocument(ctxt
);
6078 ctxt
->userData
= NULL
;
6080 docbFreeParserCtxt(ctxt
);
6087 * @filename: the filename
6088 * @encoding: a free form C string describing document encoding, or NULL
6090 * parse a Docbook SGML file and build a tree. Automatic support for
6091 * ZLIB/Compress compressed document is provided by default if found
6094 * Returns the resulting document tree
6098 docbParseFile(const char *filename
, const char *encoding
) {
6099 return(docbSAXParseFile(filename
, encoding
, NULL
, NULL
));
6102 #endif /* LIBXML_DOCB_ENABLED */