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