blob: 779e7abcb0aeb08f6da497c19c19d2ab0e9e3d3f [file] [log] [blame]
Daniel Veillardeae522a2001-04-23 13:41:34 +00001/*
2 * DOCBparser.c : an attempt to parse SGML Docbook documents
3 *
4 * See Copyright for the status of this software.
5 *
6 * Daniel.Veillard@w3.org
7 */
8
9#include "libxml.h"
10#ifdef LIBXML_DOCB_ENABLED
11
12#include <string.h>
13#ifdef HAVE_CTYPE_H
14#include <ctype.h>
15#endif
16#ifdef HAVE_STDLIB_H
17#include <stdlib.h>
18#endif
19#ifdef HAVE_SYS_STAT_H
20#include <sys/stat.h>
21#endif
22#ifdef HAVE_FCNTL_H
23#include <fcntl.h>
24#endif
25#ifdef HAVE_UNISTD_H
26#include <unistd.h>
27#endif
28#ifdef HAVE_ZLIB_H
29#include <zlib.h>
30#endif
31
32#include <libxml/xmlmemory.h>
33#include <libxml/tree.h>
34#include <libxml/SAX.h>
35#include <libxml/parser.h>
36#include <libxml/parserInternals.h>
37#include <libxml/xmlerror.h>
38#include <libxml/DOCBparser.h>
39#include <libxml/entities.h>
40#include <libxml/encoding.h>
41#include <libxml/valid.h>
42#include <libxml/xmlIO.h>
43#include <libxml/uri.h>
44
45/*
46 * Internal description of an SGML entity
47 */
48typedef struct _docbEntityDesc docbEntityDesc;
49typedef docbEntityDesc *docbEntityDescPtr;
50struct _docbEntityDesc {
51 int value; /* the UNICODE value for the character */
52 const char *name; /* The entity name */
53 const char *desc; /* the description */
54};
55
56#if 0
57docbElemDescPtr docbTagLookup (const xmlChar *tag);
58docbEntityDescPtr docbEntityLookup(const xmlChar *name);
59docbEntityDescPtr docbEntityValueLookup(int value);
60
61int docbIsAutoClosed(docbDocPtr doc,
62 docbNodePtr elem);
63int docbAutoCloseTag(docbDocPtr doc,
64 const xmlChar *name,
65 docbNodePtr elem);
66
67#endif
Daniel Veillard61b33d52001-04-24 13:55:12 +000068static int docbParseCharRef(docbParserCtxtPtr ctxt);
69static xmlEntityPtr docbParseEntityRef(docbParserCtxtPtr ctxt,
Daniel Veillardeae522a2001-04-23 13:41:34 +000070 xmlChar **str);
Daniel Veillard61b33d52001-04-24 13:55:12 +000071static void docbParseElement(docbParserCtxtPtr ctxt);
Daniel Veillard1034da22001-04-25 19:06:28 +000072static void docbParseContent(docbParserCtxtPtr ctxt);
Daniel Veillardeae522a2001-04-23 13:41:34 +000073
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, "" },
Daniel Veillard4ec0b0f2001-04-25 15:53:40 +0000442{ "artheader", 0, 0, 0, 9, 0, "" },
Daniel Veillardeae522a2001-04-23 13:41:34 +0000443{ "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 */
Daniel Veillardc057c5d2001-05-02 12:41:24 +0000506{ "docinfo", 0, 0, 0, 9, 0, "" },
Daniel Veillardeae522a2001-04-23 13:41:34 +0000507{ "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 */
Daniel Veillardc057c5d2001-05-02 12:41:24 +0000543{ "glossseealso",0, 0, 1, 2, 0, "" }, /* para */
544{ "glosssee", 0, 0, 1, 2, 0, "" }, /* para */
Daniel Veillardeae522a2001-04-23 13:41:34 +0000545{ "glossterm", 0, 0, 0, 2, 0, "" }, /* para */
Daniel Veillard4ec0b0f2001-04-25 15:53:40 +0000546{ "graphic", 0, 0, 0, 9, 0, "" },
Daniel Veillardeae522a2001-04-23 13:41:34 +0000547{ "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 */
Daniel Veillard02f077a2001-04-26 10:59:11 +0000574{ "inlinegraphic",0, 0, 0, 9, 0, "" },
Daniel Veillardeae522a2001-04-23 13:41:34 +0000575{ "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 */
Daniel Veillardc057c5d2001-05-02 12:41:24 +0000654{ "primary", 0, 0, 0, 9, 0, "" }, /* ndxterm */
Daniel Veillardeae522a2001-04-23 13:41:34 +0000655{ "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/************************************************************************
Daniel Veillard61b33d52001-04-24 13:55:12 +00002464 * *
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 * *
Daniel Veillardeae522a2001-04-23 13:41:34 +00002637 ************************************************************************/
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;
Daniel Veillard61b33d52001-04-24 13:55:12 +00002733 xmlEntityPtr xent;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002734 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 {
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002771 xent = docbParseEntityRef(ctxt, &name);
Daniel Veillardeae522a2001-04-23 13:41:34 +00002772 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 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002780 *out++ = '&';
Daniel Veillardeae522a2001-04-23 13:41:34 +00002781 } else {
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002782 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;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002789
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002790 growBuffer(buffer);
2791 out = &buffer[indx];
2792 }
2793 *out++ = *cur++;
2794 }
2795 xmlFree(name);
2796 } else {
2797 unsigned int c;
2798 int bits;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002799
Daniel Veillardc057c5d2001-05-02 12:41:24 +00002800 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 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002822 }
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 *
Daniel Veillard61b33d52001-04-24 13:55:12 +00002863 * Returns the associated xmlEntityPtr if found, or NULL otherwise,
Daniel Veillardeae522a2001-04-23 13:41:34 +00002864 * if non-NULL *str will have to be freed by the caller.
2865 */
Daniel Veillard61b33d52001-04-24 13:55:12 +00002866static xmlEntityPtr
Daniel Veillardeae522a2001-04-23 13:41:34 +00002867docbParseEntityRef(docbParserCtxtPtr ctxt, xmlChar **str) {
2868 xmlChar *name;
Daniel Veillard61b33d52001-04-24 13:55:12 +00002869 xmlEntityPtr ent = NULL;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002870 *str = NULL;
2871
2872 if (CUR == '&') {
2873 NEXT;
2874 name = docbParseName(ctxt);
Daniel Veillard61b33d52001-04-24 13:55:12 +00002875 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 {
Daniel Veillardeae522a2001-04-23 13:41:34 +00002881 GROW;
Daniel Veillard61b33d52001-04-24 13:55:12 +00002882 if (CUR == ';') {
2883 *str = name;
Daniel Veillardeae522a2001-04-23 13:41:34 +00002884
Daniel Veillard61b33d52001-04-24 13:55:12 +00002885 /*
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,
Daniel Veillardeae522a2001-04-23 13:41:34 +00002899 "docbParseEntityRef: expecting ';'\n");
Daniel Veillard61b33d52001-04-24 13:55:12 +00002900 *str = name;
2901 }
2902 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00002903 }
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 */
Daniel Veillard61b33d52001-04-24 13:55:12 +00003393 if (RAW != '[') {
Daniel Veillardeae522a2001-04-23 13:41:34 +00003394 return;
3395
Daniel Veillard61b33d52001-04-24 13:55:12 +00003396 /*
3397 * We should be at the end of the DOCTYPE declaration.
3398 */
3399 if (CUR != '>') {
3400 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3401 ctxt->sax->error(ctxt->userData,
3402 "DOCTYPE unproperly terminated\n");
3403 ctxt->wellFormed = 0;
3404 /* We shouldn't try to resynchronize ... */
3405 }
3406 NEXT;
Daniel Veillardeae522a2001-04-23 13:41:34 +00003407 }
Daniel Veillardeae522a2001-04-23 13:41:34 +00003408
3409 /*
3410 * Cleanup, since we don't use all those identifiers
3411 */
3412 if (URI != NULL) xmlFree(URI);
3413 if (ExternalID != NULL) xmlFree(ExternalID);
3414 if (name != NULL) xmlFree(name);
3415}
3416
3417/**
3418 * docbParseAttribute:
3419 * @ctxt: an SGML parser context
3420 * @value: a xmlChar ** used to store the value of the attribute
3421 *
3422 * parse an attribute
3423 *
3424 * [41] Attribute ::= Name Eq AttValue
3425 *
3426 * [25] Eq ::= S? '=' S?
3427 *
3428 * With namespace:
3429 *
3430 * [NS 11] Attribute ::= QName Eq AttValue
3431 *
3432 * Also the case QName == xmlns:??? is handled independently as a namespace
3433 * definition.
3434 *
3435 * Returns the attribute name, and the value in *value.
3436 */
3437
3438static xmlChar *
3439docbParseAttribute(docbParserCtxtPtr ctxt, xmlChar **value) {
3440 xmlChar *name, *val = NULL;
3441
3442 *value = NULL;
3443 name = docbParseName(ctxt);
3444 if (name == NULL) {
3445 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3446 ctxt->sax->error(ctxt->userData, "error parsing attribute name\n");
3447 ctxt->wellFormed = 0;
3448 return(NULL);
3449 }
3450
3451 /*
3452 * read the value
3453 */
3454 SKIP_BLANKS;
3455 if (CUR == '=') {
3456 NEXT;
3457 SKIP_BLANKS;
3458 val = docbParseAttValue(ctxt);
3459 /******
3460 } else {
3461 * TODO : some attribute must have values, some may not
3462 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3463 ctxt->sax->warning(ctxt->userData,
3464 "No value for attribute %s\n", name); */
3465 }
3466
3467 *value = val;
3468 return(name);
3469}
3470
3471/**
3472 * docbCheckEncoding:
3473 * @ctxt: an SGML parser context
3474 * @attvalue: the attribute value
3475 *
3476 * Checks an http-equiv attribute from a Meta tag to detect
3477 * the encoding
3478 * If a new encoding is detected the parser is switched to decode
3479 * it and pass UTF8
3480 */
3481static void
3482docbCheckEncoding(docbParserCtxtPtr ctxt, const xmlChar *attvalue) {
3483 const xmlChar *encoding;
3484
3485 if ((ctxt == NULL) || (attvalue == NULL))
3486 return;
3487
3488 encoding = xmlStrstr(attvalue, BAD_CAST"charset=");
3489 if (encoding == NULL)
3490 encoding = xmlStrstr(attvalue, BAD_CAST"Charset=");
3491 if (encoding == NULL)
3492 encoding = xmlStrstr(attvalue, BAD_CAST"CHARSET=");
3493 if (encoding != NULL) {
3494 encoding += 8;
3495 } else {
3496 encoding = xmlStrstr(attvalue, BAD_CAST"charset =");
3497 if (encoding == NULL)
3498 encoding = xmlStrstr(attvalue, BAD_CAST"Charset =");
3499 if (encoding == NULL)
3500 encoding = xmlStrstr(attvalue, BAD_CAST"CHARSET =");
3501 if (encoding != NULL)
3502 encoding += 9;
3503 }
3504 /*
3505 * Restricted from 2.3.5 */
3506 if (encoding != NULL) {
3507 xmlCharEncoding enc;
3508
3509 if (ctxt->input->encoding != NULL)
3510 xmlFree((xmlChar *) ctxt->input->encoding);
3511 ctxt->input->encoding = encoding;
3512
3513 enc = xmlParseCharEncoding((const char *) encoding);
3514 if (enc == XML_CHAR_ENCODING_8859_1) {
3515 ctxt->charset = XML_CHAR_ENCODING_8859_1;
3516 } else if (enc != XML_CHAR_ENCODING_UTF8) {
3517 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3518 ctxt->sax->error(ctxt->userData,
3519 "Unsupported encoding %s\n", encoding);
3520 /* xmlFree(encoding); */
3521 ctxt->wellFormed = 0;
3522 ctxt->disableSAX = 1;
3523 ctxt->errNo = XML_ERR_UNSUPPORTED_ENCODING;
3524 }
3525 }
3526}
3527
3528/**
3529 * docbCheckMeta:
3530 * @ctxt: an SGML parser context
3531 * @atts: the attributes values
3532 *
3533 * Checks an attributes from a Meta tag
3534 */
3535static void
3536docbCheckMeta(docbParserCtxtPtr ctxt, const xmlChar **atts) {
3537 int i;
3538 const xmlChar *att, *value;
3539 int http = 0;
3540 const xmlChar *content = NULL;
3541
3542 if ((ctxt == NULL) || (atts == NULL))
3543 return;
3544
3545 i = 0;
3546 att = atts[i++];
3547 while (att != NULL) {
3548 value = atts[i++];
3549 if ((value != NULL) &&
3550 ((xmlStrEqual(att, BAD_CAST"http-equiv")) ||
3551 (xmlStrEqual(att, BAD_CAST"Http-Equiv")) ||
3552 (xmlStrEqual(att, BAD_CAST"HTTP-EQUIV"))) &&
3553 ((xmlStrEqual(value, BAD_CAST"Content-Type")) ||
3554 (xmlStrEqual(value, BAD_CAST"content-type")) ||
3555 (xmlStrEqual(value, BAD_CAST"CONTENT-TYPE"))))
3556 http = 1;
3557 else if ((value != NULL) &&
3558 ((xmlStrEqual(att, BAD_CAST"content")) ||
3559 (xmlStrEqual(att, BAD_CAST"Content")) ||
3560 (xmlStrEqual(att, BAD_CAST"CONTENT"))))
3561 content = value;
3562 att = atts[i++];
3563 }
3564 if ((http) && (content != NULL))
3565 docbCheckEncoding(ctxt, content);
3566
3567}
3568
3569/**
3570 * docbParseStartTag:
3571 * @ctxt: an SGML parser context
3572 *
3573 * parse a start of tag either for rule element or
3574 * EmptyElement. In both case we don't parse the tag closing chars.
3575 *
3576 * [40] STag ::= '<' Name (S Attribute)* S? '>'
3577 *
3578 * [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>'
3579 *
3580 * With namespace:
3581 *
3582 * [NS 8] STag ::= '<' QName (S Attribute)* S? '>'
3583 *
3584 * [NS 10] EmptyElement ::= '<' QName (S Attribute)* S? '/>'
3585 *
3586 */
3587
3588static void
3589docbParseStartTag(docbParserCtxtPtr ctxt) {
3590 xmlChar *name;
3591 xmlChar *attname;
3592 xmlChar *attvalue;
3593 const xmlChar **atts = NULL;
3594 int nbatts = 0;
3595 int maxatts = 0;
3596 int meta = 0;
3597 int i;
3598
3599 if (CUR != '<') return;
3600 NEXT;
3601
3602 GROW;
3603 name = docbParseSGMLName(ctxt);
3604 if (name == NULL) {
3605 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3606 ctxt->sax->error(ctxt->userData,
3607 "docbParseStartTag: invalid element name\n");
3608 ctxt->wellFormed = 0;
3609 return;
3610 }
3611 if (xmlStrEqual(name, BAD_CAST"meta"))
3612 meta = 1;
3613
3614 /*
3615 * Check for auto-closure of SGML elements.
3616 */
3617 docbAutoClose(ctxt, name);
3618
3619 /*
3620 * Now parse the attributes, it ends up with the ending
3621 *
3622 * (S Attribute)* S?
3623 */
3624 SKIP_BLANKS;
3625 while ((IS_CHAR(CUR)) &&
3626 (CUR != '>') &&
3627 ((CUR != '/') || (NXT(1) != '>'))) {
3628 long cons = ctxt->nbChars;
3629
3630 GROW;
3631 attname = docbParseAttribute(ctxt, &attvalue);
3632 if (attname != NULL) {
3633
3634 /*
3635 * Well formedness requires at most one declaration of an attribute
3636 */
3637 for (i = 0; i < nbatts;i += 2) {
3638 if (xmlStrEqual(atts[i], attname)) {
3639 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3640 ctxt->sax->error(ctxt->userData,
3641 "Attribute %s redefined\n",
3642 attname);
3643 ctxt->wellFormed = 0;
3644 xmlFree(attname);
3645 if (attvalue != NULL)
3646 xmlFree(attvalue);
3647 goto failed;
3648 }
3649 }
3650
3651 /*
3652 * Add the pair to atts
3653 */
3654 if (atts == NULL) {
3655 maxatts = 10;
3656 atts = (const xmlChar **) xmlMalloc(maxatts * sizeof(xmlChar *));
3657 if (atts == NULL) {
3658 xmlGenericError(xmlGenericErrorContext,
3659 "malloc of %ld byte failed\n",
3660 maxatts * (long)sizeof(xmlChar *));
3661 if (name != NULL) xmlFree(name);
3662 return;
3663 }
3664 } else if (nbatts + 4 > maxatts) {
3665 maxatts *= 2;
3666 atts = (const xmlChar **) xmlRealloc(atts, maxatts * sizeof(xmlChar *));
3667 if (atts == NULL) {
3668 xmlGenericError(xmlGenericErrorContext,
3669 "realloc of %ld byte failed\n",
3670 maxatts * (long)sizeof(xmlChar *));
3671 if (name != NULL) xmlFree(name);
3672 return;
3673 }
3674 }
3675 atts[nbatts++] = attname;
3676 atts[nbatts++] = attvalue;
3677 atts[nbatts] = NULL;
3678 atts[nbatts + 1] = NULL;
3679 }
3680
3681failed:
3682 SKIP_BLANKS;
3683 if (cons == ctxt->nbChars) {
3684 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3685 ctxt->sax->error(ctxt->userData,
3686 "docbParseStartTag: problem parsing attributes\n");
3687 ctxt->wellFormed = 0;
3688 break;
3689 }
3690 }
3691
3692 /*
3693 * Handle specific association to the META tag
3694 */
3695 if (meta)
3696 docbCheckMeta(ctxt, atts);
3697
3698 /*
3699 * SAX: Start of Element !
3700 */
3701 docbnamePush(ctxt, xmlStrdup(name));
3702#ifdef DEBUG
3703 xmlGenericError(xmlGenericErrorContext,"Start of element %s: pushed %s\n", name, ctxt->name);
3704#endif
3705 if ((ctxt->sax != NULL) && (ctxt->sax->startElement != NULL))
3706 ctxt->sax->startElement(ctxt->userData, name, atts);
3707
3708 if (atts != NULL) {
3709 for (i = 0;i < nbatts;i++) {
3710 if (atts[i] != NULL)
3711 xmlFree((xmlChar *) atts[i]);
3712 }
3713 xmlFree((void *) atts);
3714 }
3715 if (name != NULL) xmlFree(name);
3716}
3717
3718/**
3719 * docbParseEndTag:
3720 * @ctxt: an SGML parser context
3721 *
3722 * parse an end of tag
3723 *
3724 * [42] ETag ::= '</' Name S? '>'
3725 *
3726 * With namespace
3727 *
3728 * [NS 9] ETag ::= '</' QName S? '>'
3729 */
3730
3731static void
3732docbParseEndTag(docbParserCtxtPtr ctxt) {
3733 xmlChar *name;
3734 xmlChar *oldname;
3735 int i;
3736
3737 if ((CUR != '<') || (NXT(1) != '/')) {
3738 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3739 ctxt->sax->error(ctxt->userData, "docbParseEndTag: '</' not found\n");
3740 ctxt->wellFormed = 0;
3741 return;
3742 }
3743 SKIP(2);
3744
3745 name = docbParseSGMLName(ctxt);
3746 if (name == NULL) {
3747 if (CUR == '>') {
3748 NEXT;
3749 oldname = docbnamePop(ctxt);
3750 if (oldname != NULL) {
3751 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
3752 ctxt->sax->endElement(ctxt->userData, name);
3753#ifdef DEBUG
3754 xmlGenericError(xmlGenericErrorContext,"End of tag </>: popping out %s\n", oldname);
3755#endif
3756 xmlFree(oldname);
3757#ifdef DEBUG
3758 } else {
3759 xmlGenericError(xmlGenericErrorContext,"End of tag </>: stack empty !!!\n");
3760#endif
3761 }
3762 return;
3763 } else
3764 return;
3765 }
3766
3767 /*
3768 * We should definitely be at the ending "S? '>'" part
3769 */
3770 SKIP_BLANKS;
3771 if ((!IS_CHAR(CUR)) || (CUR != '>')) {
3772 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3773 ctxt->sax->error(ctxt->userData, "End tag : expected '>'\n");
3774 ctxt->wellFormed = 0;
3775 } else
3776 NEXT;
3777
3778 /*
3779 * If the name read is not one of the element in the parsing stack
3780 * then return, it's just an error.
3781 */
3782 for (i = (ctxt->nameNr - 1);i >= 0;i--) {
3783 if (xmlStrEqual(name, ctxt->nameTab[i])) break;
3784 }
3785 if (i < 0) {
3786 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3787 ctxt->sax->error(ctxt->userData,
3788 "Unexpected end tag : %s\n", name);
3789 xmlFree(name);
3790 ctxt->wellFormed = 0;
3791 return;
3792 }
3793
3794
3795 /*
3796 * Check for auto-closure of SGML elements.
3797 */
3798
3799 docbAutoCloseOnClose(ctxt, name);
3800
3801 /*
3802 * Well formedness constraints, opening and closing must match.
3803 * With the exception that the autoclose may have popped stuff out
3804 * of the stack.
3805 */
3806 if (((name[0] != '/') || (name[1] != 0)) &&
3807 (!xmlStrEqual(name, ctxt->name))) {
3808#ifdef DEBUG
3809 xmlGenericError(xmlGenericErrorContext,"End of tag %s: expecting %s\n", name, ctxt->name);
3810#endif
3811 if ((ctxt->name != NULL) &&
3812 (!xmlStrEqual(ctxt->name, name))) {
3813 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
3814 ctxt->sax->error(ctxt->userData,
3815 "Opening and ending tag mismatch: %s and %s\n",
3816 name, ctxt->name);
3817 ctxt->wellFormed = 0;
3818 }
3819 }
3820
3821 /*
3822 * SAX: End of Tag
3823 */
3824 oldname = ctxt->name;
3825 if (((name[0] == '/') && (name[1] == 0)) ||
3826 ((oldname != NULL) && (xmlStrEqual(oldname, name)))) {
3827 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
3828 ctxt->sax->endElement(ctxt->userData, name);
3829 oldname = docbnamePop(ctxt);
3830 if (oldname != NULL) {
3831#ifdef DEBUG
3832 xmlGenericError(xmlGenericErrorContext,"End of tag %s: popping out %s\n", name, oldname);
3833#endif
3834 xmlFree(oldname);
3835#ifdef DEBUG
3836 } else {
3837 xmlGenericError(xmlGenericErrorContext,"End of tag %s: stack empty !!!\n", name);
3838#endif
3839 }
3840 }
3841
3842 if (name != NULL)
3843 xmlFree(name);
3844
3845 return;
3846}
3847
3848
3849/**
3850 * docbParseReference:
3851 * @ctxt: an SGML parser context
3852 *
3853 * parse and handle entity references in content,
3854 * this will end-up in a call to character() since this is either a
3855 * CharRef, or a predefined entity.
3856 */
3857static void
3858docbParseReference(docbParserCtxtPtr ctxt) {
3859 docbEntityDescPtr ent;
Daniel Veillard61b33d52001-04-24 13:55:12 +00003860 xmlEntityPtr xent;
Daniel Veillardeae522a2001-04-23 13:41:34 +00003861 xmlChar out[6];
3862 xmlChar *name;
3863 if (CUR != '&') return;
3864
3865 if (NXT(1) == '#') {
3866 unsigned int c;
3867 int bits, i = 0;
3868
3869 c = docbParseCharRef(ctxt);
3870 if (c < 0x80) { out[i++]= c; bits= -6; }
3871 else if (c < 0x800) { out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }
3872 else if (c < 0x10000) { out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }
3873 else { out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }
3874
3875 for ( ; bits >= 0; bits-= 6) {
3876 out[i++]= ((c >> bits) & 0x3F) | 0x80;
3877 }
3878 out[i] = 0;
3879
3880 docbCheckParagraph(ctxt);
3881 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
3882 ctxt->sax->characters(ctxt->userData, out, i);
3883 } else {
Daniel Veillard61b33d52001-04-24 13:55:12 +00003884 /*
3885 * Lookup the entity in the table.
3886 */
3887 xent = docbParseEntityRef(ctxt, &name);
3888 if (xent != NULL) {
Daniel Veillard1034da22001-04-25 19:06:28 +00003889 if (((ctxt->replaceEntities) || (ctxt->loadsubset)) &&
3890 ((xent->children == NULL) &&
3891 (xent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY))) {
Daniel Veillard61b33d52001-04-24 13:55:12 +00003892 /*
3893 * we really need to fetch and parse the external entity
3894 */
3895 int parse;
3896 xmlNodePtr children = NULL;
3897
3898 parse = docbParseCtxtExternalEntity(ctxt,
3899 xent->SystemID, xent->ExternalID, &children);
3900 xmlAddChildList((xmlNodePtr) xent, children);
Daniel Veillard1034da22001-04-25 19:06:28 +00003901 }
3902 if (ctxt->replaceEntities) {
Daniel Veillard61b33d52001-04-24 13:55:12 +00003903 if ((ctxt->node != NULL) && (xent->children != NULL)) {
3904 /*
3905 * Seems we are generating the DOM content, do
3906 * a simple tree copy
3907 */
3908 xmlNodePtr new;
3909 new = xmlCopyNodeList(xent->children);
3910
3911 xmlAddChildList(ctxt->node, new);
3912 /*
3913 * This is to avoid a nasty side effect, see
3914 * characters() in SAX.c
3915 */
3916 ctxt->nodemem = 0;
3917 ctxt->nodelen = 0;
3918 }
Daniel Veillard1034da22001-04-25 19:06:28 +00003919 } else {
3920 if ((ctxt->sax != NULL) && (ctxt->sax->reference != NULL) &&
3921 (ctxt->replaceEntities == 0) && (!ctxt->disableSAX)) {
3922 /*
3923 * Create a node.
3924 */
3925 ctxt->sax->reference(ctxt->userData, xent->name);
3926 }
Daniel Veillard61b33d52001-04-24 13:55:12 +00003927 }
3928 } else if (name != NULL) {
3929 ent = docbEntityLookup(name);
3930 if ((ent == NULL) || (ent->value <= 0)) {
3931 docbCheckParagraph(ctxt);
3932 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL)) {
3933 ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1);
3934 ctxt->sax->characters(ctxt->userData, name, xmlStrlen(name));
3935 /* ctxt->sax->characters(ctxt->userData, BAD_CAST ";", 1); */
3936 }
3937 } else {
3938 unsigned int c;
3939 int bits, i = 0;
3940
3941 c = ent->value;
3942 if (c < 0x80)
3943 { out[i++]= c; bits= -6; }
3944 else if (c < 0x800)
3945 { out[i++]=((c >> 6) & 0x1F) | 0xC0; bits= 0; }
3946 else if (c < 0x10000)
3947 { out[i++]=((c >> 12) & 0x0F) | 0xE0; bits= 6; }
3948 else
3949 { out[i++]=((c >> 18) & 0x07) | 0xF0; bits= 12; }
3950
3951 for ( ; bits >= 0; bits-= 6) {
3952 out[i++]= ((c >> bits) & 0x3F) | 0x80;
3953 }
3954 out[i] = 0;
3955
3956 docbCheckParagraph(ctxt);
3957 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
3958 ctxt->sax->characters(ctxt->userData, out, i);
3959 }
3960 } else {
Daniel Veillardeae522a2001-04-23 13:41:34 +00003961 docbCheckParagraph(ctxt);
3962 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
3963 ctxt->sax->characters(ctxt->userData, BAD_CAST "&", 1);
3964 return;
3965 }
Daniel Veillard61b33d52001-04-24 13:55:12 +00003966 if (name != NULL)
3967 xmlFree(name);
Daniel Veillardeae522a2001-04-23 13:41:34 +00003968 }
3969}
3970
3971/**
3972 * docbParseContent:
3973 * @ctxt: an SGML parser context
3974 * @name: the node name
3975 *
3976 * Parse a content: comment, sub-element, reference or text.
3977 *
3978 */
3979
3980static void
3981docbParseContent(docbParserCtxtPtr ctxt) {
3982 xmlChar *currentNode;
3983 int depth;
3984
3985 currentNode = xmlStrdup(ctxt->name);
3986 depth = ctxt->nameNr;
3987 while (1) {
3988 long cons = ctxt->nbChars;
3989
3990 GROW;
3991 /*
3992 * Our tag or one of it's parent or children is ending.
3993 */
3994 if ((CUR == '<') && (NXT(1) == '/')) {
3995 docbParseEndTag(ctxt);
3996 if (currentNode != NULL) xmlFree(currentNode);
3997 return;
3998 }
3999
4000 /*
4001 * Has this node been popped out during parsing of
4002 * the next element
4003 */
4004 if ((!xmlStrEqual(currentNode, ctxt->name)) &&
4005 (depth >= ctxt->nameNr)) {
4006 if (currentNode != NULL) xmlFree(currentNode);
4007 return;
4008 }
4009
4010 /*
4011 * Sometimes DOCTYPE arrives in the middle of the document
4012 */
4013 if ((CUR == '<') && (NXT(1) == '!') &&
4014 (UPP(2) == 'D') && (UPP(3) == 'O') &&
4015 (UPP(4) == 'C') && (UPP(5) == 'T') &&
4016 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
4017 (UPP(8) == 'E')) {
4018 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4019 ctxt->sax->error(ctxt->userData,
4020 "Misplaced DOCTYPE declaration\n");
4021 ctxt->wellFormed = 0;
4022 docbParseDocTypeDecl(ctxt);
4023 }
4024
4025 /*
4026 * First case : a comment
4027 */
4028 if ((CUR == '<') && (NXT(1) == '!') &&
4029 (NXT(2) == '-') && (NXT(3) == '-')) {
4030 docbParseComment(ctxt);
4031 }
4032
4033 /*
4034 * Second case : a sub-element.
4035 */
4036 else if (CUR == '<') {
4037 docbParseElement(ctxt);
4038 }
4039
4040 /*
4041 * Third case : a reference. If if has not been resolved,
4042 * parsing returns it's Name, create the node
4043 */
4044 else if (CUR == '&') {
4045 docbParseReference(ctxt);
4046 }
4047
4048 /*
4049 * Fourth : end of the resource
4050 */
4051 else if (CUR == 0) {
4052 docbAutoClose(ctxt, NULL);
Daniel Veillard61b33d52001-04-24 13:55:12 +00004053 if (ctxt->nameNr == 0)
4054 break;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004055 }
4056
4057 /*
4058 * Last case, text. Note that References are handled directly.
4059 */
4060 else {
4061 docbParseCharData(ctxt);
4062 }
4063
4064 if (cons == ctxt->nbChars) {
4065 if (ctxt->node != NULL) {
4066 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4067 ctxt->sax->error(ctxt->userData,
4068 "detected an error in element content\n");
4069 ctxt->wellFormed = 0;
4070 }
Daniel Veillard61b33d52001-04-24 13:55:12 +00004071 break;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004072 }
4073
4074 GROW;
4075 }
4076 if (currentNode != NULL) xmlFree(currentNode);
4077}
4078
4079/**
4080 * docbParseElement:
4081 * @ctxt: an SGML parser context
4082 *
4083 * parse an SGML element, this is highly recursive
4084 *
4085 * [39] element ::= EmptyElemTag | STag content ETag
4086 *
4087 * [41] Attribute ::= Name Eq AttValue
4088 */
4089
4090static void
4091docbParseElement(docbParserCtxtPtr ctxt) {
4092 xmlChar *name;
4093 xmlChar *currentNode = NULL;
4094 docbElemDescPtr info;
4095 docbParserNodeInfo node_info;
4096 xmlChar *oldname;
4097 int depth = ctxt->nameNr;
4098
4099 /* Capture start position */
4100 if (ctxt->record_info) {
4101 node_info.begin_pos = ctxt->input->consumed +
4102 (CUR_PTR - ctxt->input->base);
4103 node_info.begin_line = ctxt->input->line;
4104 }
4105
4106 oldname = xmlStrdup(ctxt->name);
4107 docbParseStartTag(ctxt);
4108 name = ctxt->name;
4109#ifdef DEBUG
4110 if (oldname == NULL)
4111 xmlGenericError(xmlGenericErrorContext,
4112 "Start of element %s\n", name);
4113 else if (name == NULL)
4114 xmlGenericError(xmlGenericErrorContext,
4115 "Start of element failed, was %s\n", oldname);
4116 else
4117 xmlGenericError(xmlGenericErrorContext,
4118 "Start of element %s, was %s\n", name, oldname);
4119#endif
4120 if (((depth == ctxt->nameNr) && (xmlStrEqual(oldname, ctxt->name))) ||
4121 (name == NULL)) {
4122 if (CUR == '>')
4123 NEXT;
4124 if (oldname != NULL)
4125 xmlFree(oldname);
4126 return;
4127 }
4128 if (oldname != NULL)
4129 xmlFree(oldname);
4130
4131 /*
4132 * Lookup the info for that element.
4133 */
4134 info = docbTagLookup(name);
4135 if (info == NULL) {
4136 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4137 ctxt->sax->error(ctxt->userData, "Tag %s unknown\n",
4138 name);
4139 ctxt->wellFormed = 0;
4140 } else if (info->depr) {
4141/***************************
4142 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
4143 ctxt->sax->warning(ctxt->userData, "Tag %s is deprecated\n",
4144 name);
4145 ***************************/
4146 }
4147
4148 /*
4149 * Check for an Empty Element labelled the XML/SGML way
4150 */
4151 if ((CUR == '/') && (NXT(1) == '>')) {
4152 SKIP(2);
4153 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
4154 ctxt->sax->endElement(ctxt->userData, name);
4155 oldname = docbnamePop(ctxt);
4156#ifdef DEBUG
4157 xmlGenericError(xmlGenericErrorContext,"End of tag the XML way: popping out %s\n", oldname);
4158#endif
4159 if (oldname != NULL)
4160 xmlFree(oldname);
4161 return;
4162 }
4163
4164 if (CUR == '>') {
4165 NEXT;
4166 } else {
4167 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4168 ctxt->sax->error(ctxt->userData,
4169 "Couldn't find end of Start Tag %s\n",
4170 name);
4171 ctxt->wellFormed = 0;
4172
4173 /*
4174 * end of parsing of this node.
4175 */
4176 if (xmlStrEqual(name, ctxt->name)) {
4177 nodePop(ctxt);
4178 oldname = docbnamePop(ctxt);
4179#ifdef DEBUG
4180 xmlGenericError(xmlGenericErrorContext,"End of start tag problem: popping out %s\n", oldname);
4181#endif
4182 if (oldname != NULL)
4183 xmlFree(oldname);
4184 }
4185
4186 /*
4187 * Capture end position and add node
4188 */
4189 if ( currentNode != NULL && ctxt->record_info ) {
4190 node_info.end_pos = ctxt->input->consumed +
4191 (CUR_PTR - ctxt->input->base);
4192 node_info.end_line = ctxt->input->line;
4193 node_info.node = ctxt->node;
4194 xmlParserAddNodeInfo(ctxt, &node_info);
4195 }
4196 return;
4197 }
4198
4199 /*
4200 * Check for an Empty Element from DTD definition
4201 */
4202 if ((info != NULL) && (info->empty)) {
4203 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
4204 ctxt->sax->endElement(ctxt->userData, name);
4205 oldname = docbnamePop(ctxt);
4206#ifdef DEBUG
4207 xmlGenericError(xmlGenericErrorContext,"End of empty tag %s : popping out %s\n", name, oldname);
4208#endif
4209 if (oldname != NULL)
4210 xmlFree(oldname);
4211 return;
4212 }
4213
4214 /*
4215 * Parse the content of the element:
4216 */
4217 currentNode = xmlStrdup(ctxt->name);
4218 depth = ctxt->nameNr;
4219 while (IS_CHAR(CUR)) {
4220 docbParseContent(ctxt);
4221 if (ctxt->nameNr < depth) break;
4222 }
4223
4224 if (!IS_CHAR(CUR)) {
4225 /************
4226 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4227 ctxt->sax->error(ctxt->userData,
4228 "Premature end of data in tag %s\n", currentNode);
4229 ctxt->wellFormed = 0;
4230 *************/
4231
4232 /*
4233 * end of parsing of this node.
4234 */
4235 nodePop(ctxt);
4236 oldname = docbnamePop(ctxt);
4237#ifdef DEBUG
4238 xmlGenericError(xmlGenericErrorContext,"Premature end of tag %s : popping out %s\n", name, oldname);
4239#endif
4240 if (oldname != NULL)
4241 xmlFree(oldname);
4242 if (currentNode != NULL)
4243 xmlFree(currentNode);
4244 return;
4245 }
4246
4247 /*
4248 * Capture end position and add node
4249 */
4250 if ( currentNode != NULL && ctxt->record_info ) {
4251 node_info.end_pos = ctxt->input->consumed +
4252 (CUR_PTR - ctxt->input->base);
4253 node_info.end_line = ctxt->input->line;
4254 node_info.node = ctxt->node;
4255 xmlParserAddNodeInfo(ctxt, &node_info);
4256 }
4257 if (currentNode != NULL)
4258 xmlFree(currentNode);
4259}
4260
4261/**
4262 * docbParseEntityDecl:
4263 * @ctxt: an SGML parser context
4264 *
4265 * parse <!ENTITY declarations
4266 *
4267 */
4268
4269static void
4270docbParseEntityDecl(xmlParserCtxtPtr ctxt) {
4271 xmlChar *name = NULL;
4272 xmlChar *value = NULL;
4273 xmlChar *URI = NULL, *literal = NULL;
4274 xmlChar *ndata = NULL;
4275 int isParameter = 0;
4276 xmlChar *orig = NULL;
4277
4278 GROW;
4279 if ((RAW == '<') && (NXT(1) == '!') &&
Daniel Veillard61b33d52001-04-24 13:55:12 +00004280 (UPP(2) == 'E') && (UPP(3) == 'N') &&
4281 (UPP(4) == 'T') && (UPP(5) == 'I') &&
4282 (UPP(6) == 'T') && (UPP(7) == 'Y')) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004283 xmlParserInputPtr input = ctxt->input;
4284 ctxt->instate = XML_PARSER_ENTITY_DECL;
4285 SHRINK;
4286 SKIP(8);
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 '<!ENTITY'\n");
4292 ctxt->wellFormed = 0;
4293 ctxt->disableSAX = 1;
4294 }
4295 SKIP_BLANKS;
4296
4297 if (RAW == '%') {
4298 NEXT;
4299 if (!IS_BLANK(CUR)) {
4300 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4301 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4302 ctxt->sax->error(ctxt->userData,
4303 "Space required after '%'\n");
4304 ctxt->wellFormed = 0;
4305 ctxt->disableSAX = 1;
4306 }
4307 SKIP_BLANKS;
4308 isParameter = 1;
4309 }
4310
4311 name = xmlParseName(ctxt);
4312 if (name == NULL) {
4313 ctxt->errNo = XML_ERR_NAME_REQUIRED;
4314 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4315 ctxt->sax->error(ctxt->userData, "sgmlarseEntityDecl: no name\n");
4316 ctxt->wellFormed = 0;
4317 ctxt->disableSAX = 1;
4318 return;
4319 }
4320 if (!IS_BLANK(CUR)) {
4321 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4322 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4323 ctxt->sax->error(ctxt->userData,
4324 "Space required after the entity name\n");
4325 ctxt->wellFormed = 0;
4326 ctxt->disableSAX = 1;
4327 }
4328 SKIP_BLANKS;
4329
4330 /*
4331 * handle the various case of definitions...
4332 */
4333 if (isParameter) {
4334 if ((RAW == '"') || (RAW == '\'')) {
4335 value = xmlParseEntityValue(ctxt, &orig);
4336 if (value) {
4337 if ((ctxt->sax != NULL) &&
4338 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4339 ctxt->sax->entityDecl(ctxt->userData, name,
4340 XML_INTERNAL_PARAMETER_ENTITY,
4341 NULL, NULL, value);
4342 }
4343 } else {
4344 URI = xmlParseExternalID(ctxt, &literal, 1);
4345 if ((URI == NULL) && (literal == NULL)) {
4346 ctxt->errNo = XML_ERR_VALUE_REQUIRED;
4347 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4348 ctxt->sax->error(ctxt->userData,
4349 "Entity value required\n");
4350 ctxt->wellFormed = 0;
4351 ctxt->disableSAX = 1;
4352 }
4353 if (URI) {
4354 xmlURIPtr uri;
4355
4356 uri = xmlParseURI((const char *) URI);
4357 if (uri == NULL) {
4358 ctxt->errNo = XML_ERR_INVALID_URI;
4359 if ((ctxt->sax != NULL) &&
4360 (!ctxt->disableSAX) &&
4361 (ctxt->sax->error != NULL))
4362 ctxt->sax->error(ctxt->userData,
4363 "Invalid URI: %s\n", URI);
4364 ctxt->wellFormed = 0;
4365 } else {
4366 if (uri->fragment != NULL) {
4367 ctxt->errNo = XML_ERR_URI_FRAGMENT;
4368 if ((ctxt->sax != NULL) &&
4369 (!ctxt->disableSAX) &&
4370 (ctxt->sax->error != NULL))
4371 ctxt->sax->error(ctxt->userData,
4372 "Fragment not allowed: %s\n", URI);
4373 ctxt->wellFormed = 0;
4374 } else {
4375 if ((ctxt->sax != NULL) &&
4376 (!ctxt->disableSAX) &&
4377 (ctxt->sax->entityDecl != NULL))
4378 ctxt->sax->entityDecl(ctxt->userData, name,
4379 XML_EXTERNAL_PARAMETER_ENTITY,
4380 literal, URI, NULL);
4381 }
4382 xmlFreeURI(uri);
4383 }
4384 }
4385 }
4386 } else {
4387 if ((RAW == '"') || (RAW == '\'')) {
4388 value = xmlParseEntityValue(ctxt, &orig);
4389 if ((ctxt->sax != NULL) &&
4390 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4391 ctxt->sax->entityDecl(ctxt->userData, name,
4392 XML_INTERNAL_GENERAL_ENTITY,
4393 NULL, NULL, value);
4394 } else {
4395 URI = xmlParseExternalID(ctxt, &literal, 1);
4396 if ((URI == NULL) && (literal == NULL)) {
4397 ctxt->errNo = XML_ERR_VALUE_REQUIRED;
4398 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4399 ctxt->sax->error(ctxt->userData,
4400 "Entity value required\n");
4401 ctxt->wellFormed = 0;
4402 ctxt->disableSAX = 1;
4403 }
4404 if (URI) {
4405 xmlURIPtr uri;
4406
4407 uri = xmlParseURI((const char *)URI);
4408 if (uri == NULL) {
4409 ctxt->errNo = XML_ERR_INVALID_URI;
4410 if ((ctxt->sax != NULL) &&
4411 (!ctxt->disableSAX) &&
4412 (ctxt->sax->error != NULL))
4413 ctxt->sax->error(ctxt->userData,
4414 "Invalid URI: %s\n", URI);
4415 ctxt->wellFormed = 0;
4416 } else {
4417 if (uri->fragment != NULL) {
4418 ctxt->errNo = XML_ERR_URI_FRAGMENT;
4419 if ((ctxt->sax != NULL) &&
4420 (!ctxt->disableSAX) &&
4421 (ctxt->sax->error != NULL))
4422 ctxt->sax->error(ctxt->userData,
4423 "Fragment not allowed: %s\n", URI);
4424 ctxt->wellFormed = 0;
4425 }
4426 xmlFreeURI(uri);
4427 }
4428 }
4429 if ((RAW != '>') && (!IS_BLANK(CUR))) {
4430 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4431 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4432 ctxt->sax->error(ctxt->userData,
4433 "Space required before content model\n");
4434 ctxt->wellFormed = 0;
4435 ctxt->disableSAX = 1;
4436 }
4437 SKIP_BLANKS;
4438
4439 /*
4440 * SGML specific: here we can get the content model
4441 */
4442 if (RAW != '>') {
4443 xmlChar *contmod;
4444
4445 contmod = xmlParseName(ctxt);
4446
4447 if (contmod == NULL) {
4448 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4449 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4450 ctxt->sax->error(ctxt->userData,
4451 "Could not parse entity content model\n");
4452 ctxt->wellFormed = 0;
4453 ctxt->disableSAX = 1;
4454 } else {
4455 if (xmlStrEqual(contmod, BAD_CAST"NDATA")) {
4456 if (!IS_BLANK(CUR)) {
4457 ctxt->errNo = XML_ERR_SPACE_REQUIRED;
4458 if ((ctxt->sax != NULL) &&
4459 (ctxt->sax->error != NULL))
4460 ctxt->sax->error(ctxt->userData,
4461 "Space required after 'NDATA'\n");
4462 ctxt->wellFormed = 0;
4463 ctxt->disableSAX = 1;
4464 }
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"SUBDOC")) {
4473 if ((ctxt->sax != NULL) &&
4474 (ctxt->sax->warning != NULL))
4475 ctxt->sax->warning(ctxt->userData,
4476 "SUBDOC 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 } else if (xmlStrEqual(contmod, BAD_CAST"CDATA")) {
4485 if ((ctxt->sax != NULL) &&
4486 (ctxt->sax->warning != NULL))
4487 ctxt->sax->warning(ctxt->userData,
4488 "CDATA entities are not supported\n");
4489 SKIP_BLANKS;
4490 ndata = xmlParseName(ctxt);
4491 if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
4492 (ctxt->sax->unparsedEntityDecl != NULL)) {
4493 ctxt->sax->unparsedEntityDecl(ctxt->userData,
4494 name, literal, URI, ndata);
4495 }
4496 }
4497 xmlFree(contmod);
4498 }
4499 } else {
4500 if ((ctxt->sax != NULL) &&
4501 (!ctxt->disableSAX) && (ctxt->sax->entityDecl != NULL))
4502 ctxt->sax->entityDecl(ctxt->userData, name,
4503 XML_EXTERNAL_GENERAL_PARSED_ENTITY,
4504 literal, URI, NULL);
4505 }
4506 }
4507 }
4508 SKIP_BLANKS;
4509 if (RAW != '>') {
4510 ctxt->errNo = XML_ERR_ENTITY_NOT_FINISHED;
4511 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4512 ctxt->sax->error(ctxt->userData,
4513 "docbParseEntityDecl: entity %s not terminated\n", name);
4514 ctxt->wellFormed = 0;
4515 ctxt->disableSAX = 1;
4516 } else {
4517 if (input != ctxt->input) {
4518 ctxt->errNo = XML_ERR_ENTITY_BOUNDARY;
4519 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4520 ctxt->sax->error(ctxt->userData,
4521"Entity declaration doesn't start and stop in the same entity\n");
4522 ctxt->wellFormed = 0;
4523 ctxt->disableSAX = 1;
4524 }
4525 NEXT;
4526 }
4527 if (orig != NULL) {
4528 /*
4529 * Ugly mechanism to save the raw entity value.
4530 */
4531 xmlEntityPtr cur = NULL;
4532
4533 if (isParameter) {
4534 if ((ctxt->sax != NULL) &&
4535 (ctxt->sax->getParameterEntity != NULL))
4536 cur = ctxt->sax->getParameterEntity(ctxt->userData, name);
4537 } else {
4538 if ((ctxt->sax != NULL) &&
4539 (ctxt->sax->getEntity != NULL))
4540 cur = ctxt->sax->getEntity(ctxt->userData, name);
4541 }
4542 if (cur != NULL) {
4543 if (cur->orig != NULL)
4544 xmlFree(orig);
4545 else
4546 cur->orig = orig;
4547 } else
4548 xmlFree(orig);
4549 }
4550 if (name != NULL) xmlFree(name);
4551 if (value != NULL) xmlFree(value);
4552 if (URI != NULL) xmlFree(URI);
4553 if (literal != NULL) xmlFree(literal);
4554 if (ndata != NULL) xmlFree(ndata);
4555 }
4556}
4557
4558/**
4559 * docbParseMarkupDecl:
4560 * @ctxt: an SGML parser context
4561 *
4562 * parse Markup declarations
4563 *
4564 * [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl |
4565 * NotationDecl | PI | Comment
4566 */
4567static void
4568docbParseMarkupDecl(xmlParserCtxtPtr ctxt) {
4569 GROW;
4570 xmlParseElementDecl(ctxt);
4571 xmlParseAttributeListDecl(ctxt);
4572 docbParseEntityDecl(ctxt);
4573 xmlParseNotationDecl(ctxt);
4574 xmlParsePI(ctxt);
4575 xmlParseComment(ctxt);
4576 /*
4577 * This is only for internal subset. On external entities,
4578 * the replacement is done before parsing stage
4579 */
4580 if ((ctxt->external == 0) && (ctxt->inputNr == 1))
4581 xmlParsePEReference(ctxt);
4582 ctxt->instate = XML_PARSER_DTD;
4583}
4584
4585/**
4586 * docbParseInternalsubset:
4587 * @ctxt: an SGML parser context
4588 *
4589 * parse the internal subset declaration
4590 *
4591 * [28 end] ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
4592 */
4593
4594static void
4595docbParseInternalSubset(xmlParserCtxtPtr ctxt) {
4596 /*
4597 * Is there any DTD definition ?
4598 */
4599 if (RAW == '[') {
4600 ctxt->instate = XML_PARSER_DTD;
4601 NEXT;
4602 /*
4603 * Parse the succession of Markup declarations and
4604 * PEReferences.
4605 * Subsequence (markupdecl | PEReference | S)*
4606 */
4607 while (RAW != ']') {
4608 const xmlChar *check = CUR_PTR;
4609 int cons = ctxt->input->consumed;
4610
4611 SKIP_BLANKS;
4612 docbParseMarkupDecl(ctxt);
4613 xmlParsePEReference(ctxt);
4614
4615 /*
4616 * Pop-up of finished entities.
4617 */
4618 while ((RAW == 0) && (ctxt->inputNr > 1))
4619 xmlPopInput(ctxt);
4620
4621 if ((CUR_PTR == check) && (cons == ctxt->input->consumed)) {
4622 ctxt->errNo = XML_ERR_INTERNAL_ERROR;
4623 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4624 ctxt->sax->error(ctxt->userData,
4625 "docbParseInternalSubset: error detected in Markup declaration\n");
4626 ctxt->wellFormed = 0;
4627 ctxt->disableSAX = 1;
4628 break;
4629 }
4630 }
4631 if (RAW == ']') {
4632 NEXT;
4633 SKIP_BLANKS;
4634 }
4635 }
4636
4637 /*
4638 * We should be at the end of the DOCTYPE declaration.
4639 */
4640 if (RAW != '>') {
4641 ctxt->errNo = XML_ERR_DOCTYPE_NOT_FINISHED;
4642 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4643 ctxt->sax->error(ctxt->userData, "DOCTYPE unproperly terminated\n");
4644 ctxt->wellFormed = 0;
4645 ctxt->disableSAX = 1;
4646 }
4647 NEXT;
4648}
4649
4650/**
4651 * docbParseMisc:
4652 * @ctxt: an XML parser context
4653 *
4654 * parse an XML Misc* optionnal field.
4655 *
4656 * [27] Misc ::= Comment | PI | S
4657 */
4658
4659static void
4660docbParseMisc(xmlParserCtxtPtr ctxt) {
4661 while (((RAW == '<') && (NXT(1) == '?')) ||
4662 ((RAW == '<') && (NXT(1) == '!') &&
4663 (NXT(2) == '-') && (NXT(3) == '-')) ||
4664 IS_BLANK(CUR)) {
4665 if ((RAW == '<') && (NXT(1) == '?')) {
4666 xmlParsePI(ctxt); /* TODO: SGML PIs differs */
4667 } else if (IS_BLANK(CUR)) {
4668 NEXT;
4669 } else
4670 xmlParseComment(ctxt);
4671 }
4672}
4673
4674/**
4675 * docbParseDocument :
4676 * @ctxt: an SGML parser context
4677 *
4678 * parse an SGML document (and build a tree if using the standard SAX
4679 * interface).
4680 *
4681 * Returns 0, -1 in case of error. the parser context is augmented
4682 * as a result of the parsing.
4683 */
4684
4685int
4686docbParseDocument(docbParserCtxtPtr ctxt) {
4687 xmlChar start[4];
4688 xmlCharEncoding enc;
4689 xmlDtdPtr dtd;
4690
4691 docbDefaultSAXHandlerInit();
4692 ctxt->html = 2;
4693
4694 GROW;
4695 /*
4696 * SAX: beginning of the document processing.
4697 */
4698 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
4699 ctxt->sax->setDocumentLocator(ctxt->userData, &xmlDefaultSAXLocator);
4700
4701 /*
4702 * Get the 4 first bytes and decode the charset
4703 * if enc != XML_CHAR_ENCODING_NONE
4704 * plug some encoding conversion routines.
4705 */
4706 start[0] = RAW;
4707 start[1] = NXT(1);
4708 start[2] = NXT(2);
4709 start[3] = NXT(3);
4710 enc = xmlDetectCharEncoding(start, 4);
4711 if (enc != XML_CHAR_ENCODING_NONE) {
4712 xmlSwitchEncoding(ctxt, enc);
4713 }
4714
4715 /*
4716 * Wipe out everything which is before the first '<'
4717 */
4718 SKIP_BLANKS;
4719 if (CUR == 0) {
4720 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
4721 ctxt->sax->error(ctxt->userData, "Document is empty\n");
4722 ctxt->wellFormed = 0;
4723 }
4724
4725 if ((ctxt->sax) && (ctxt->sax->startDocument) && (!ctxt->disableSAX))
4726 ctxt->sax->startDocument(ctxt->userData);
4727
4728
4729 /*
4730 * The Misc part of the Prolog
4731 */
4732 GROW;
4733 docbParseMisc(ctxt);
4734
4735 /*
4736 * Then possibly doc type declaration(s) and more Misc
4737 * (doctypedecl Misc*)?
4738 */
4739 GROW;
4740 if ((RAW == '<') && (NXT(1) == '!') &&
Daniel Veillard61b33d52001-04-24 13:55:12 +00004741 (UPP(2) == 'D') && (UPP(3) == 'O') &&
4742 (UPP(4) == 'C') && (UPP(5) == 'T') &&
4743 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
4744 (UPP(8) == 'E')) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004745
4746 ctxt->inSubset = 1;
4747 docbParseDocTypeDecl(ctxt);
4748 if (RAW == '[') {
4749 ctxt->instate = XML_PARSER_DTD;
4750 docbParseInternalSubset(ctxt);
4751 }
4752
4753 /*
4754 * Create and update the external subset.
4755 */
4756 ctxt->inSubset = 2;
4757 if ((ctxt->sax != NULL) && (ctxt->sax->internalSubset != NULL) &&
4758 (!ctxt->disableSAX))
4759 ctxt->sax->internalSubset(ctxt->userData, ctxt->intSubName,
4760 ctxt->extSubSystem, ctxt->extSubURI);
4761 ctxt->inSubset = 0;
4762
4763
4764 ctxt->instate = XML_PARSER_PROLOG;
4765 docbParseMisc(ctxt);
4766 }
4767
4768 /*
4769 * Time to start parsing the tree itself
4770 */
4771 docbParseContent(ctxt);
4772
4773 /*
4774 * autoclose
4775 */
4776 if (CUR == 0)
4777 docbAutoClose(ctxt, NULL);
4778
4779
4780 /*
4781 * SAX: end of the document processing.
4782 */
4783 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
4784 ctxt->sax->endDocument(ctxt->userData);
4785
4786 if (ctxt->myDoc != NULL) {
4787 dtd = ctxt->myDoc->intSubset;
4788 if (dtd == NULL)
4789 ctxt->myDoc->intSubset =
4790 xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "SGML",
4791 BAD_CAST "-//W3C//DTD SGML 4.0 Transitional//EN",
4792 BAD_CAST "http://www.w3.org/TR/REC-docbook/loose.dtd");
4793 }
4794 if (! ctxt->wellFormed) return(-1);
4795 return(0);
4796}
4797
4798
4799/************************************************************************
4800 * *
4801 * Parser contexts handling *
4802 * *
4803 ************************************************************************/
4804
4805/**
Daniel Veillard1034da22001-04-25 19:06:28 +00004806 * docbInitParserCtxt:
Daniel Veillardeae522a2001-04-23 13:41:34 +00004807 * @ctxt: an SGML parser context
4808 *
4809 * Initialize a parser context
4810 */
4811
4812static void
4813docbInitParserCtxt(docbParserCtxtPtr ctxt)
4814{
4815 docbSAXHandler *sax;
4816
4817 if (ctxt == NULL) return;
4818 memset(ctxt, 0, sizeof(docbParserCtxt));
4819
4820 sax = (docbSAXHandler *) xmlMalloc(sizeof(docbSAXHandler));
4821 if (sax == NULL) {
4822 xmlGenericError(xmlGenericErrorContext,
4823 "docbInitParserCtxt: out of memory\n");
4824 }
4825 memset(sax, 0, sizeof(docbSAXHandler));
4826
4827 /* Allocate the Input stack */
4828 ctxt->inputTab = (docbParserInputPtr *)
4829 xmlMalloc(5 * sizeof(docbParserInputPtr));
4830 if (ctxt->inputTab == NULL) {
4831 xmlGenericError(xmlGenericErrorContext,
4832 "docbInitParserCtxt: out of memory\n");
4833 }
4834 ctxt->inputNr = 0;
4835 ctxt->inputMax = 5;
4836 ctxt->input = NULL;
4837 ctxt->version = NULL;
4838 ctxt->encoding = NULL;
4839 ctxt->standalone = -1;
4840 ctxt->instate = XML_PARSER_START;
4841
4842 /* Allocate the Node stack */
4843 ctxt->nodeTab = (docbNodePtr *) xmlMalloc(10 * sizeof(docbNodePtr));
4844 ctxt->nodeNr = 0;
4845 ctxt->nodeMax = 10;
4846 ctxt->node = NULL;
4847
4848 /* Allocate the Name stack */
4849 ctxt->nameTab = (xmlChar **) xmlMalloc(10 * sizeof(xmlChar *));
4850 ctxt->nameNr = 0;
4851 ctxt->nameMax = 10;
4852 ctxt->name = NULL;
4853
4854 if (sax == NULL) ctxt->sax = &docbDefaultSAXHandler;
4855 else {
4856 ctxt->sax = sax;
4857 memcpy(sax, &docbDefaultSAXHandler, sizeof(docbSAXHandler));
4858 }
4859 ctxt->userData = ctxt;
4860 ctxt->myDoc = NULL;
4861 ctxt->wellFormed = 1;
Daniel Veillard61b33d52001-04-24 13:55:12 +00004862 ctxt->replaceEntities = xmlSubstituteEntitiesDefaultValue;
Daniel Veillardeae522a2001-04-23 13:41:34 +00004863 ctxt->html = 2;
4864 ctxt->record_info = 0;
4865 ctxt->validate = 0;
4866 ctxt->nbChars = 0;
4867 ctxt->checkIndex = 0;
4868 xmlInitNodeInfoSeq(&ctxt->node_seq);
4869}
4870
4871/**
4872 * docbFreeParserCtxt:
4873 * @ctxt: an SGML parser context
4874 *
4875 * Free all the memory used by a parser context. However the parsed
4876 * document in ctxt->myDoc is not freed.
4877 */
4878
4879void
4880docbFreeParserCtxt(docbParserCtxtPtr ctxt)
4881{
4882 xmlFreeParserCtxt(ctxt);
4883}
4884
4885/**
4886 * docbCreateDocParserCtxt :
4887 * @cur: a pointer to an array of xmlChar
Daniel Veillard1034da22001-04-25 19:06:28 +00004888 * @encoding: the SGML document encoding, or NULL
Daniel Veillardeae522a2001-04-23 13:41:34 +00004889 *
4890 * Create a parser context for an SGML document.
4891 *
4892 * Returns the new parser context or NULL
4893 */
4894static docbParserCtxtPtr
Daniel Veillard1034da22001-04-25 19:06:28 +00004895docbCreateDocParserCtxt(xmlChar *cur, const char *encoding ATTRIBUTE_UNUSED) {
Daniel Veillardeae522a2001-04-23 13:41:34 +00004896 docbParserCtxtPtr ctxt;
4897 docbParserInputPtr input;
4898 /* sgmlCharEncoding enc; */
4899
4900 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
4901 if (ctxt == NULL) {
4902 perror("malloc");
4903 return(NULL);
4904 }
4905 docbInitParserCtxt(ctxt);
4906 input = (docbParserInputPtr) xmlMalloc(sizeof(docbParserInput));
4907 if (input == NULL) {
4908 perror("malloc");
4909 xmlFree(ctxt);
4910 return(NULL);
4911 }
4912 memset(input, 0, sizeof(docbParserInput));
4913
4914 input->line = 1;
4915 input->col = 1;
4916 input->base = cur;
4917 input->cur = cur;
4918
4919 inputPush(ctxt, input);
4920 return(ctxt);
4921}
4922
4923/************************************************************************
4924 * *
4925 * Progressive parsing interfaces *
4926 * *
4927 ************************************************************************/
4928
4929/**
4930 * docbParseLookupSequence:
4931 * @ctxt: an SGML parser context
4932 * @first: the first char to lookup
4933 * @next: the next char to lookup or zero
4934 * @third: the next char to lookup or zero
4935 *
4936 * Try to find if a sequence (first, next, third) or just (first next) or
4937 * (first) is available in the input stream.
4938 * This function has a side effect of (possibly) incrementing ctxt->checkIndex
4939 * to avoid rescanning sequences of bytes, it DOES change the state of the
4940 * parser, do not use liberally.
4941 * This is basically similar to xmlParseLookupSequence()
4942 *
4943 * Returns the index to the current parsing point if the full sequence
4944 * is available, -1 otherwise.
4945 */
4946static int
4947docbParseLookupSequence(docbParserCtxtPtr ctxt, xmlChar first,
4948 xmlChar next, xmlChar third) {
4949 int base, len;
4950 docbParserInputPtr in;
4951 const xmlChar *buf;
4952
4953 in = ctxt->input;
4954 if (in == NULL) return(-1);
4955 base = in->cur - in->base;
4956 if (base < 0) return(-1);
4957 if (ctxt->checkIndex > base)
4958 base = ctxt->checkIndex;
4959 if (in->buf == NULL) {
4960 buf = in->base;
4961 len = in->length;
4962 } else {
4963 buf = in->buf->buffer->content;
4964 len = in->buf->buffer->use;
4965 }
4966 /* take into account the sequence length */
4967 if (third) len -= 2;
4968 else if (next) len --;
4969 for (;base < len;base++) {
4970 if (buf[base] == first) {
4971 if (third != 0) {
4972 if ((buf[base + 1] != next) ||
4973 (buf[base + 2] != third)) continue;
4974 } else if (next != 0) {
4975 if (buf[base + 1] != next) continue;
4976 }
4977 ctxt->checkIndex = 0;
4978#ifdef DEBUG_PUSH
4979 if (next == 0)
4980 xmlGenericError(xmlGenericErrorContext,
4981 "HPP: lookup '%c' found at %d\n",
4982 first, base);
4983 else if (third == 0)
4984 xmlGenericError(xmlGenericErrorContext,
4985 "HPP: lookup '%c%c' found at %d\n",
4986 first, next, base);
4987 else
4988 xmlGenericError(xmlGenericErrorContext,
4989 "HPP: lookup '%c%c%c' found at %d\n",
4990 first, next, third, base);
4991#endif
4992 return(base - (in->cur - in->base));
4993 }
4994 }
4995 ctxt->checkIndex = base;
4996#ifdef DEBUG_PUSH
4997 if (next == 0)
4998 xmlGenericError(xmlGenericErrorContext,
4999 "HPP: lookup '%c' failed\n", first);
5000 else if (third == 0)
5001 xmlGenericError(xmlGenericErrorContext,
5002 "HPP: lookup '%c%c' failed\n", first, next);
5003 else
5004 xmlGenericError(xmlGenericErrorContext,
5005 "HPP: lookup '%c%c%c' failed\n", first, next, third);
5006#endif
5007 return(-1);
5008}
5009
5010/**
5011 * docbParseTryOrFinish:
5012 * @ctxt: an SGML parser context
5013 * @terminate: last chunk indicator
5014 *
5015 * Try to progress on parsing
5016 *
5017 * Returns zero if no parsing was possible
5018 */
5019static int
5020docbParseTryOrFinish(docbParserCtxtPtr ctxt, int terminate) {
5021 int ret = 0;
5022 docbParserInputPtr in;
5023 int avail = 0;
5024 xmlChar cur, next;
5025
5026#ifdef DEBUG_PUSH
5027 switch (ctxt->instate) {
5028 case XML_PARSER_EOF:
5029 xmlGenericError(xmlGenericErrorContext,
5030 "HPP: try EOF\n"); break;
5031 case XML_PARSER_START:
5032 xmlGenericError(xmlGenericErrorContext,
5033 "HPP: try START\n"); break;
5034 case XML_PARSER_MISC:
5035 xmlGenericError(xmlGenericErrorContext,
5036 "HPP: try MISC\n");break;
5037 case XML_PARSER_COMMENT:
5038 xmlGenericError(xmlGenericErrorContext,
5039 "HPP: try COMMENT\n");break;
5040 case XML_PARSER_PROLOG:
5041 xmlGenericError(xmlGenericErrorContext,
5042 "HPP: try PROLOG\n");break;
5043 case XML_PARSER_START_TAG:
5044 xmlGenericError(xmlGenericErrorContext,
5045 "HPP: try START_TAG\n");break;
5046 case XML_PARSER_CONTENT:
5047 xmlGenericError(xmlGenericErrorContext,
5048 "HPP: try CONTENT\n");break;
5049 case XML_PARSER_CDATA_SECTION:
5050 xmlGenericError(xmlGenericErrorContext,
5051 "HPP: try CDATA_SECTION\n");break;
5052 case XML_PARSER_END_TAG:
5053 xmlGenericError(xmlGenericErrorContext,
5054 "HPP: try END_TAG\n");break;
5055 case XML_PARSER_ENTITY_DECL:
5056 xmlGenericError(xmlGenericErrorContext,
5057 "HPP: try ENTITY_DECL\n");break;
5058 case XML_PARSER_ENTITY_VALUE:
5059 xmlGenericError(xmlGenericErrorContext,
5060 "HPP: try ENTITY_VALUE\n");break;
5061 case XML_PARSER_ATTRIBUTE_VALUE:
5062 xmlGenericError(xmlGenericErrorContext,
5063 "HPP: try ATTRIBUTE_VALUE\n");break;
5064 case XML_PARSER_DTD:
5065 xmlGenericError(xmlGenericErrorContext,
5066 "HPP: try DTD\n");break;
5067 case XML_PARSER_EPILOG:
5068 xmlGenericError(xmlGenericErrorContext,
5069 "HPP: try EPILOG\n");break;
5070 case XML_PARSER_PI:
5071 xmlGenericError(xmlGenericErrorContext,
5072 "HPP: try PI\n");break;
5073 }
5074#endif
5075
5076 while (1) {
5077
5078 in = ctxt->input;
5079 if (in == NULL) break;
5080 if (in->buf == NULL)
5081 avail = in->length - (in->cur - in->base);
5082 else
5083 avail = in->buf->buffer->use - (in->cur - in->base);
5084 if ((avail == 0) && (terminate)) {
5085 docbAutoClose(ctxt, NULL);
5086 if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
5087 /*
5088 * SAX: end of the document processing.
5089 */
5090 ctxt->instate = XML_PARSER_EOF;
5091 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5092 ctxt->sax->endDocument(ctxt->userData);
5093 }
5094 }
5095 if (avail < 1)
5096 goto done;
5097 switch (ctxt->instate) {
5098 case XML_PARSER_EOF:
5099 /*
5100 * Document parsing is done !
5101 */
5102 goto done;
5103 case XML_PARSER_START:
5104 /*
5105 * Very first chars read from the document flow.
5106 */
5107 cur = in->cur[0];
5108 if (IS_BLANK(cur)) {
5109 SKIP_BLANKS;
5110 if (in->buf == NULL)
5111 avail = in->length - (in->cur - in->base);
5112 else
5113 avail = in->buf->buffer->use - (in->cur - in->base);
5114 }
5115 if ((ctxt->sax) && (ctxt->sax->setDocumentLocator))
5116 ctxt->sax->setDocumentLocator(ctxt->userData,
5117 &xmlDefaultSAXLocator);
5118 if ((ctxt->sax) && (ctxt->sax->startDocument) &&
5119 (!ctxt->disableSAX))
5120 ctxt->sax->startDocument(ctxt->userData);
5121
5122 cur = in->cur[0];
5123 next = in->cur[1];
5124 if ((cur == '<') && (next == '!') &&
5125 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5126 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5127 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5128 (UPP(8) == 'E')) {
5129 if ((!terminate) &&
5130 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5131 goto done;
5132#ifdef DEBUG_PUSH
5133 xmlGenericError(xmlGenericErrorContext,
5134 "HPP: Parsing internal subset\n");
5135#endif
5136 docbParseDocTypeDecl(ctxt);
5137 ctxt->instate = XML_PARSER_PROLOG;
5138#ifdef DEBUG_PUSH
5139 xmlGenericError(xmlGenericErrorContext,
5140 "HPP: entering PROLOG\n");
5141#endif
5142 } else {
5143 ctxt->instate = XML_PARSER_MISC;
5144 }
5145#ifdef DEBUG_PUSH
5146 xmlGenericError(xmlGenericErrorContext,
5147 "HPP: entering MISC\n");
5148#endif
5149 break;
5150 case XML_PARSER_MISC:
5151 SKIP_BLANKS;
5152 if (in->buf == NULL)
5153 avail = in->length - (in->cur - in->base);
5154 else
5155 avail = in->buf->buffer->use - (in->cur - in->base);
5156 if (avail < 2)
5157 goto done;
5158 cur = in->cur[0];
5159 next = in->cur[1];
5160 if ((cur == '<') && (next == '!') &&
5161 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5162 if ((!terminate) &&
5163 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5164 goto done;
5165#ifdef DEBUG_PUSH
5166 xmlGenericError(xmlGenericErrorContext,
5167 "HPP: Parsing Comment\n");
5168#endif
5169 docbParseComment(ctxt);
5170 ctxt->instate = XML_PARSER_MISC;
5171 } else if ((cur == '<') && (next == '!') &&
5172 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5173 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5174 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5175 (UPP(8) == 'E')) {
5176 if ((!terminate) &&
5177 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5178 goto done;
5179#ifdef DEBUG_PUSH
5180 xmlGenericError(xmlGenericErrorContext,
5181 "HPP: Parsing internal subset\n");
5182#endif
5183 docbParseDocTypeDecl(ctxt);
5184 ctxt->instate = XML_PARSER_PROLOG;
5185#ifdef DEBUG_PUSH
5186 xmlGenericError(xmlGenericErrorContext,
5187 "HPP: entering PROLOG\n");
5188#endif
5189 } else if ((cur == '<') && (next == '!') &&
5190 (avail < 9)) {
5191 goto done;
5192 } else {
5193 ctxt->instate = XML_PARSER_START_TAG;
5194#ifdef DEBUG_PUSH
5195 xmlGenericError(xmlGenericErrorContext,
5196 "HPP: entering START_TAG\n");
5197#endif
5198 }
5199 break;
5200 case XML_PARSER_PROLOG:
5201 SKIP_BLANKS;
5202 if (in->buf == NULL)
5203 avail = in->length - (in->cur - in->base);
5204 else
5205 avail = in->buf->buffer->use - (in->cur - in->base);
5206 if (avail < 2)
5207 goto done;
5208 cur = in->cur[0];
5209 next = in->cur[1];
5210 if ((cur == '<') && (next == '!') &&
5211 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5212 if ((!terminate) &&
5213 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5214 goto done;
5215#ifdef DEBUG_PUSH
5216 xmlGenericError(xmlGenericErrorContext,
5217 "HPP: Parsing Comment\n");
5218#endif
5219 docbParseComment(ctxt);
5220 ctxt->instate = XML_PARSER_PROLOG;
5221 } else if ((cur == '<') && (next == '!') &&
5222 (avail < 4)) {
5223 goto done;
5224 } else {
5225 ctxt->instate = XML_PARSER_START_TAG;
5226#ifdef DEBUG_PUSH
5227 xmlGenericError(xmlGenericErrorContext,
5228 "HPP: entering START_TAG\n");
5229#endif
5230 }
5231 break;
5232 case XML_PARSER_EPILOG:
5233 if (in->buf == NULL)
5234 avail = in->length - (in->cur - in->base);
5235 else
5236 avail = in->buf->buffer->use - (in->cur - in->base);
5237 if (avail < 1)
5238 goto done;
5239 cur = in->cur[0];
5240 if (IS_BLANK(cur)) {
5241 docbParseCharData(ctxt);
5242 goto done;
5243 }
5244 if (avail < 2)
5245 goto done;
5246 next = in->cur[1];
5247 if ((cur == '<') && (next == '!') &&
5248 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5249 if ((!terminate) &&
5250 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5251 goto done;
5252#ifdef DEBUG_PUSH
5253 xmlGenericError(xmlGenericErrorContext,
5254 "HPP: Parsing Comment\n");
5255#endif
5256 docbParseComment(ctxt);
5257 ctxt->instate = XML_PARSER_EPILOG;
5258 } else if ((cur == '<') && (next == '!') &&
5259 (avail < 4)) {
5260 goto done;
5261 } else {
5262 ctxt->errNo = XML_ERR_DOCUMENT_END;
5263 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5264 ctxt->sax->error(ctxt->userData,
5265 "Extra content at the end of the document\n");
5266 ctxt->wellFormed = 0;
5267 ctxt->instate = XML_PARSER_EOF;
5268#ifdef DEBUG_PUSH
5269 xmlGenericError(xmlGenericErrorContext,
5270 "HPP: entering EOF\n");
5271#endif
5272 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5273 ctxt->sax->endDocument(ctxt->userData);
5274 goto done;
5275 }
5276 break;
5277 case XML_PARSER_START_TAG: {
5278 xmlChar *name, *oldname;
5279 int depth = ctxt->nameNr;
5280 docbElemDescPtr info;
5281
5282 if (avail < 2)
5283 goto done;
5284 cur = in->cur[0];
5285 if (cur != '<') {
5286 ctxt->instate = XML_PARSER_CONTENT;
5287#ifdef DEBUG_PUSH
5288 xmlGenericError(xmlGenericErrorContext,
5289 "HPP: entering CONTENT\n");
5290#endif
5291 break;
5292 }
5293 if ((!terminate) &&
5294 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5295 goto done;
5296
5297 oldname = xmlStrdup(ctxt->name);
5298 docbParseStartTag(ctxt);
5299 name = ctxt->name;
5300#ifdef DEBUG
5301 if (oldname == NULL)
5302 xmlGenericError(xmlGenericErrorContext,
5303 "Start of element %s\n", name);
5304 else if (name == NULL)
5305 xmlGenericError(xmlGenericErrorContext,
5306 "Start of element failed, was %s\n",
5307 oldname);
5308 else
5309 xmlGenericError(xmlGenericErrorContext,
5310 "Start of element %s, was %s\n",
5311 name, oldname);
5312#endif
5313 if (((depth == ctxt->nameNr) &&
5314 (xmlStrEqual(oldname, ctxt->name))) ||
5315 (name == NULL)) {
5316 if (CUR == '>')
5317 NEXT;
5318 if (oldname != NULL)
5319 xmlFree(oldname);
5320 break;
5321 }
5322 if (oldname != NULL)
5323 xmlFree(oldname);
5324
5325 /*
5326 * Lookup the info for that element.
5327 */
5328 info = docbTagLookup(name);
5329 if (info == NULL) {
5330 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5331 ctxt->sax->error(ctxt->userData, "Tag %s unknown\n",
5332 name);
5333 ctxt->wellFormed = 0;
5334 } else if (info->depr) {
5335 /***************************
5336 if ((ctxt->sax != NULL) && (ctxt->sax->warning != NULL))
5337 ctxt->sax->warning(ctxt->userData,
5338 "Tag %s is deprecated\n",
5339 name);
5340 ***************************/
5341 }
5342
5343 /*
5344 * Check for an Empty Element labelled the XML/SGML way
5345 */
5346 if ((CUR == '/') && (NXT(1) == '>')) {
5347 SKIP(2);
5348 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
5349 ctxt->sax->endElement(ctxt->userData, name);
5350 oldname = docbnamePop(ctxt);
5351#ifdef DEBUG
5352 xmlGenericError(xmlGenericErrorContext,"End of tag the XML way: popping out %s\n",
5353 oldname);
5354#endif
5355 if (oldname != NULL)
5356 xmlFree(oldname);
5357 ctxt->instate = XML_PARSER_CONTENT;
5358#ifdef DEBUG_PUSH
5359 xmlGenericError(xmlGenericErrorContext,
5360 "HPP: entering CONTENT\n");
5361#endif
5362 break;
5363 }
5364
5365 if (CUR == '>') {
5366 NEXT;
5367 } else {
5368 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5369 ctxt->sax->error(ctxt->userData,
5370 "Couldn't find end of Start Tag %s\n",
5371 name);
5372 ctxt->wellFormed = 0;
5373
5374 /*
5375 * end of parsing of this node.
5376 */
5377 if (xmlStrEqual(name, ctxt->name)) {
5378 nodePop(ctxt);
5379 oldname = docbnamePop(ctxt);
5380#ifdef DEBUG
5381 xmlGenericError(xmlGenericErrorContext,
5382 "End of start tag problem: popping out %s\n", oldname);
5383#endif
5384 if (oldname != NULL)
5385 xmlFree(oldname);
5386 }
5387
5388 ctxt->instate = XML_PARSER_CONTENT;
5389#ifdef DEBUG_PUSH
5390 xmlGenericError(xmlGenericErrorContext,
5391 "HPP: entering CONTENT\n");
5392#endif
5393 break;
5394 }
5395
5396 /*
5397 * Check for an Empty Element from DTD definition
5398 */
5399 if ((info != NULL) && (info->empty)) {
5400 if ((ctxt->sax != NULL) && (ctxt->sax->endElement != NULL))
5401 ctxt->sax->endElement(ctxt->userData, name);
5402 oldname = docbnamePop(ctxt);
5403#ifdef DEBUG
5404 xmlGenericError(xmlGenericErrorContext,"End of empty tag %s : popping out %s\n", name, oldname);
5405#endif
5406 if (oldname != NULL)
5407 xmlFree(oldname);
5408 }
5409 ctxt->instate = XML_PARSER_CONTENT;
5410#ifdef DEBUG_PUSH
5411 xmlGenericError(xmlGenericErrorContext,
5412 "HPP: entering CONTENT\n");
5413#endif
5414 break;
5415 }
5416 case XML_PARSER_CONTENT: {
5417 long cons;
5418 /*
5419 * Handle preparsed entities and charRef
5420 */
5421 if (ctxt->token != 0) {
5422 xmlChar chr[2] = { 0 , 0 } ;
5423
5424 chr[0] = (xmlChar) ctxt->token;
5425 docbCheckParagraph(ctxt);
5426 if ((ctxt->sax != NULL) && (ctxt->sax->characters != NULL))
5427 ctxt->sax->characters(ctxt->userData, chr, 1);
5428 ctxt->token = 0;
5429 ctxt->checkIndex = 0;
5430 }
5431 if ((avail == 1) && (terminate)) {
5432 cur = in->cur[0];
5433 if ((cur != '<') && (cur != '&')) {
5434 if (ctxt->sax != NULL) {
5435 if (IS_BLANK(cur)) {
5436 if (ctxt->sax->ignorableWhitespace != NULL)
5437 ctxt->sax->ignorableWhitespace(
5438 ctxt->userData, &cur, 1);
5439 } else {
5440 docbCheckParagraph(ctxt);
5441 if (ctxt->sax->characters != NULL)
5442 ctxt->sax->characters(
5443 ctxt->userData, &cur, 1);
5444 }
5445 }
5446 ctxt->token = 0;
5447 ctxt->checkIndex = 0;
5448 NEXT;
5449 }
5450 break;
5451 }
5452 if (avail < 2)
5453 goto done;
5454 cur = in->cur[0];
5455 next = in->cur[1];
5456 cons = ctxt->nbChars;
5457 /*
5458 * Sometimes DOCTYPE arrives in the middle of the document
5459 */
5460 if ((cur == '<') && (next == '!') &&
5461 (UPP(2) == 'D') && (UPP(3) == 'O') &&
5462 (UPP(4) == 'C') && (UPP(5) == 'T') &&
5463 (UPP(6) == 'Y') && (UPP(7) == 'P') &&
5464 (UPP(8) == 'E')) {
5465 if ((!terminate) &&
5466 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5467 goto done;
5468 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5469 ctxt->sax->error(ctxt->userData,
5470 "Misplaced DOCTYPE declaration\n");
5471 ctxt->wellFormed = 0;
5472 docbParseDocTypeDecl(ctxt);
5473 } else if ((cur == '<') && (next == '!') &&
5474 (in->cur[2] == '-') && (in->cur[3] == '-')) {
5475 if ((!terminate) &&
5476 (docbParseLookupSequence(ctxt, '-', '-', '>') < 0))
5477 goto done;
5478#ifdef DEBUG_PUSH
5479 xmlGenericError(xmlGenericErrorContext,
5480 "HPP: Parsing Comment\n");
5481#endif
5482 docbParseComment(ctxt);
5483 ctxt->instate = XML_PARSER_CONTENT;
5484 } else if ((cur == '<') && (next == '!') && (avail < 4)) {
5485 goto done;
5486 } else if ((cur == '<') && (next == '/')) {
5487 ctxt->instate = XML_PARSER_END_TAG;
5488 ctxt->checkIndex = 0;
5489#ifdef DEBUG_PUSH
5490 xmlGenericError(xmlGenericErrorContext,
5491 "HPP: entering END_TAG\n");
5492#endif
5493 break;
5494 } else if (cur == '<') {
5495 ctxt->instate = XML_PARSER_START_TAG;
5496 ctxt->checkIndex = 0;
5497#ifdef DEBUG_PUSH
5498 xmlGenericError(xmlGenericErrorContext,
5499 "HPP: entering START_TAG\n");
5500#endif
5501 break;
5502 } else if (cur == '&') {
5503 if ((!terminate) &&
5504 (docbParseLookupSequence(ctxt, ';', 0, 0) < 0))
5505 goto done;
5506#ifdef DEBUG_PUSH
5507 xmlGenericError(xmlGenericErrorContext,
5508 "HPP: Parsing Reference\n");
5509#endif
5510 /* TODO: check generation of subtrees if noent !!! */
5511 docbParseReference(ctxt);
5512 } else {
5513 /* TODO Avoid the extra copy, handle directly !!!!!! */
5514 /*
5515 * Goal of the following test is :
5516 * - minimize calls to the SAX 'character' callback
5517 * when they are mergeable
5518 */
5519 if ((ctxt->inputNr == 1) &&
5520 (avail < DOCB_PARSER_BIG_BUFFER_SIZE)) {
5521 if ((!terminate) &&
5522 (docbParseLookupSequence(ctxt, '<', 0, 0) < 0))
5523 goto done;
5524 }
5525 ctxt->checkIndex = 0;
5526#ifdef DEBUG_PUSH
5527 xmlGenericError(xmlGenericErrorContext,
5528 "HPP: Parsing char data\n");
5529#endif
5530 docbParseCharData(ctxt);
5531 }
5532 if (cons == ctxt->nbChars) {
5533 if (ctxt->node != NULL) {
5534 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5535 ctxt->sax->error(ctxt->userData,
5536 "detected an error in element content\n");
5537 ctxt->wellFormed = 0;
5538 NEXT;
5539 }
5540 break;
5541 }
5542
5543 break;
5544 }
5545 case XML_PARSER_END_TAG:
5546 if (avail < 2)
5547 goto done;
5548 if ((!terminate) &&
5549 (docbParseLookupSequence(ctxt, '>', 0, 0) < 0))
5550 goto done;
5551 docbParseEndTag(ctxt);
5552 if (ctxt->nameNr == 0) {
5553 ctxt->instate = XML_PARSER_EPILOG;
5554 } else {
5555 ctxt->instate = XML_PARSER_CONTENT;
5556 }
5557 ctxt->checkIndex = 0;
5558#ifdef DEBUG_PUSH
5559 xmlGenericError(xmlGenericErrorContext,
5560 "HPP: entering CONTENT\n");
5561#endif
5562 break;
5563 case XML_PARSER_CDATA_SECTION:
5564 xmlGenericError(xmlGenericErrorContext,
5565 "HPP: internal error, state == CDATA\n");
5566 ctxt->instate = XML_PARSER_CONTENT;
5567 ctxt->checkIndex = 0;
5568#ifdef DEBUG_PUSH
5569 xmlGenericError(xmlGenericErrorContext,
5570 "HPP: entering CONTENT\n");
5571#endif
5572 break;
5573 case XML_PARSER_DTD:
5574 xmlGenericError(xmlGenericErrorContext,
5575 "HPP: internal error, state == DTD\n");
5576 ctxt->instate = XML_PARSER_CONTENT;
5577 ctxt->checkIndex = 0;
5578#ifdef DEBUG_PUSH
5579 xmlGenericError(xmlGenericErrorContext,
5580 "HPP: entering CONTENT\n");
5581#endif
5582 break;
5583 case XML_PARSER_COMMENT:
5584 xmlGenericError(xmlGenericErrorContext,
5585 "HPP: internal error, state == COMMENT\n");
5586 ctxt->instate = XML_PARSER_CONTENT;
5587 ctxt->checkIndex = 0;
5588#ifdef DEBUG_PUSH
5589 xmlGenericError(xmlGenericErrorContext,
5590 "HPP: entering CONTENT\n");
5591#endif
5592 break;
5593 case XML_PARSER_PI:
5594 xmlGenericError(xmlGenericErrorContext,
5595 "HPP: internal error, state == PI\n");
5596 ctxt->instate = XML_PARSER_CONTENT;
5597 ctxt->checkIndex = 0;
5598#ifdef DEBUG_PUSH
5599 xmlGenericError(xmlGenericErrorContext,
5600 "HPP: entering CONTENT\n");
5601#endif
5602 break;
5603 case XML_PARSER_ENTITY_DECL:
5604 xmlGenericError(xmlGenericErrorContext,
5605 "HPP: internal error, state == ENTITY_DECL\n");
5606 ctxt->instate = XML_PARSER_CONTENT;
5607 ctxt->checkIndex = 0;
5608#ifdef DEBUG_PUSH
5609 xmlGenericError(xmlGenericErrorContext,
5610 "HPP: entering CONTENT\n");
5611#endif
5612 break;
5613 case XML_PARSER_ENTITY_VALUE:
5614 xmlGenericError(xmlGenericErrorContext,
5615 "HPP: internal error, state == ENTITY_VALUE\n");
5616 ctxt->instate = XML_PARSER_CONTENT;
5617 ctxt->checkIndex = 0;
5618#ifdef DEBUG_PUSH
5619 xmlGenericError(xmlGenericErrorContext,
5620 "HPP: entering DTD\n");
5621#endif
5622 break;
5623 case XML_PARSER_ATTRIBUTE_VALUE:
5624 xmlGenericError(xmlGenericErrorContext,
5625 "HPP: internal error, state == ATTRIBUTE_VALUE\n");
5626 ctxt->instate = XML_PARSER_START_TAG;
5627 ctxt->checkIndex = 0;
5628#ifdef DEBUG_PUSH
5629 xmlGenericError(xmlGenericErrorContext,
5630 "HPP: entering START_TAG\n");
5631#endif
5632 break;
5633 case XML_PARSER_SYSTEM_LITERAL:
5634 xmlGenericError(xmlGenericErrorContext,
5635 "HPP: internal error, state == XML_PARSER_SYSTEM_LITERAL\n");
5636 ctxt->instate = XML_PARSER_CONTENT;
5637 ctxt->checkIndex = 0;
5638#ifdef DEBUG_PUSH
5639 xmlGenericError(xmlGenericErrorContext,
5640 "HPP: entering CONTENT\n");
5641#endif
5642 break;
5643
5644 case XML_PARSER_IGNORE:
5645 xmlGenericError(xmlGenericErrorContext,
5646 "HPP: internal error, state == XML_PARSER_IGNORE\n");
5647 ctxt->instate = XML_PARSER_CONTENT;
5648 ctxt->checkIndex = 0;
5649#ifdef DEBUG_PUSH
5650 xmlGenericError(xmlGenericErrorContext,
5651 "HPP: entering CONTENT\n");
5652#endif
5653 break;
5654 }
5655 }
5656done:
5657 if ((avail == 0) && (terminate)) {
5658 docbAutoClose(ctxt, NULL);
5659 if ((ctxt->nameNr == 0) && (ctxt->instate != XML_PARSER_EOF)) {
5660 /*
5661 * SAX: end of the document processing.
5662 */
5663 ctxt->instate = XML_PARSER_EOF;
5664 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5665 ctxt->sax->endDocument(ctxt->userData);
5666 }
5667 }
5668 if ((ctxt->myDoc != NULL) &&
5669 ((terminate) || (ctxt->instate == XML_PARSER_EOF) ||
5670 (ctxt->instate == XML_PARSER_EPILOG))) {
5671 xmlDtdPtr dtd;
5672 dtd = ctxt->myDoc->intSubset;
5673 if (dtd == NULL)
5674 ctxt->myDoc->intSubset =
5675 xmlCreateIntSubset(ctxt->myDoc, BAD_CAST "SGML",
5676 BAD_CAST "-//W3C//DTD SGML 4.0 Transitional//EN",
5677 BAD_CAST "http://www.w3.org/TR/REC-docbook/loose.dtd");
5678 }
5679#ifdef DEBUG_PUSH
5680 xmlGenericError(xmlGenericErrorContext, "HPP: done %d\n", ret);
5681#endif
5682 return(ret);
5683}
5684
5685/**
5686 * docbParseChunk:
5687 * @ctxt: an XML parser context
5688 * @chunk: an char array
5689 * @size: the size in byte of the chunk
5690 * @terminate: last chunk indicator
5691 *
5692 * Parse a Chunk of memory
5693 *
5694 * Returns zero if no error, the xmlParserErrors otherwise.
5695 */
5696int
5697docbParseChunk(docbParserCtxtPtr ctxt, const char *chunk, int size,
5698 int terminate) {
5699 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
5700 (ctxt->input->buf != NULL) && (ctxt->instate != XML_PARSER_EOF)) {
5701 int base = ctxt->input->base - ctxt->input->buf->buffer->content;
5702 int cur = ctxt->input->cur - ctxt->input->base;
5703
5704 xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
5705 ctxt->input->base = ctxt->input->buf->buffer->content + base;
5706 ctxt->input->cur = ctxt->input->base + cur;
5707#ifdef DEBUG_PUSH
5708 xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
5709#endif
5710
5711 if ((terminate) || (ctxt->input->buf->buffer->use > 80))
5712 docbParseTryOrFinish(ctxt, terminate);
5713 } else if (ctxt->instate != XML_PARSER_EOF) {
5714 xmlParserInputBufferPush(ctxt->input->buf, 0, "");
5715 docbParseTryOrFinish(ctxt, terminate);
5716 }
5717 if (terminate) {
5718 if ((ctxt->instate != XML_PARSER_EOF) &&
5719 (ctxt->instate != XML_PARSER_EPILOG) &&
5720 (ctxt->instate != XML_PARSER_MISC)) {
5721 ctxt->errNo = XML_ERR_DOCUMENT_END;
5722 if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
5723 ctxt->sax->error(ctxt->userData,
5724 "Extra content at the end of the document\n");
5725 ctxt->wellFormed = 0;
5726 }
5727 if (ctxt->instate != XML_PARSER_EOF) {
5728 if ((ctxt->sax) && (ctxt->sax->endDocument != NULL))
5729 ctxt->sax->endDocument(ctxt->userData);
5730 }
5731 ctxt->instate = XML_PARSER_EOF;
5732 }
5733 return((xmlParserErrors) ctxt->errNo);
5734}
5735
5736/************************************************************************
5737 * *
5738 * User entry points *
5739 * *
5740 ************************************************************************/
5741
5742/**
5743 * docbCreatePushParserCtxt :
5744 * @sax: a SAX handler
5745 * @user_data: The user data returned on SAX callbacks
5746 * @chunk: a pointer to an array of chars
5747 * @size: number of chars in the array
5748 * @filename: an optional file name or URI
5749 * @enc: an optional encoding
5750 *
5751 * Create a parser context for using the DocBook SGML parser in push mode
5752 * To allow content encoding detection, @size should be >= 4
5753 * The value of @filename is used for fetching external entities
5754 * and error/warning reports.
5755 *
5756 * Returns the new parser context or NULL
5757 */
5758docbParserCtxtPtr
5759docbCreatePushParserCtxt(docbSAXHandlerPtr sax, void *user_data,
5760 const char *chunk, int size, const char *filename,
5761 xmlCharEncoding enc) {
5762 docbParserCtxtPtr ctxt;
5763 docbParserInputPtr inputStream;
5764 xmlParserInputBufferPtr buf;
5765
5766 buf = xmlAllocParserInputBuffer(enc);
5767 if (buf == NULL) return(NULL);
5768
5769 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
5770 if (ctxt == NULL) {
5771 xmlFree(buf);
5772 return(NULL);
5773 }
5774 memset(ctxt, 0, sizeof(docbParserCtxt));
5775 docbInitParserCtxt(ctxt);
5776 if (sax != NULL) {
5777 if (ctxt->sax != &docbDefaultSAXHandler)
5778 xmlFree(ctxt->sax);
5779 ctxt->sax = (docbSAXHandlerPtr) xmlMalloc(sizeof(docbSAXHandler));
5780 if (ctxt->sax == NULL) {
5781 xmlFree(buf);
5782 xmlFree(ctxt);
5783 return(NULL);
5784 }
5785 memcpy(ctxt->sax, sax, sizeof(docbSAXHandler));
5786 if (user_data != NULL)
5787 ctxt->userData = user_data;
5788 }
5789 if (filename == NULL) {
5790 ctxt->directory = NULL;
5791 } else {
5792 ctxt->directory = xmlParserGetDirectory(filename);
5793 }
5794
5795 inputStream = docbNewInputStream(ctxt);
5796 if (inputStream == NULL) {
5797 xmlFreeParserCtxt(ctxt);
5798 return(NULL);
5799 }
5800
5801 if (filename == NULL)
5802 inputStream->filename = NULL;
5803 else
5804 inputStream->filename = xmlMemStrdup(filename);
5805 inputStream->buf = buf;
5806 inputStream->base = inputStream->buf->buffer->content;
5807 inputStream->cur = inputStream->buf->buffer->content;
5808
5809 inputPush(ctxt, inputStream);
5810
5811 if ((size > 0) && (chunk != NULL) && (ctxt->input != NULL) &&
5812 (ctxt->input->buf != NULL)) {
5813 xmlParserInputBufferPush(ctxt->input->buf, size, chunk);
5814#ifdef DEBUG_PUSH
5815 xmlGenericError(xmlGenericErrorContext, "HPP: pushed %d\n", size);
5816#endif
5817 }
5818
5819 return(ctxt);
5820}
5821
5822/**
5823 * docbSAXParseDoc :
5824 * @cur: a pointer to an array of xmlChar
5825 * @encoding: a free form C string describing the SGML document encoding, or NULL
5826 * @sax: the SAX handler block
5827 * @userData: if using SAX, this pointer will be provided on callbacks.
5828 *
5829 * parse an SGML in-memory document and build a tree.
5830 * It use the given SAX function block to handle the parsing callback.
5831 * If sax is NULL, fallback to the default DOM tree building routines.
5832 *
5833 * Returns the resulting document tree
5834 */
5835
5836docbDocPtr
5837docbSAXParseDoc(xmlChar *cur, const char *encoding, docbSAXHandlerPtr sax, void *userData) {
5838 docbDocPtr ret;
5839 docbParserCtxtPtr ctxt;
5840
5841 if (cur == NULL) return(NULL);
5842
5843
5844 ctxt = docbCreateDocParserCtxt(cur, encoding);
5845 if (ctxt == NULL) return(NULL);
5846 if (sax != NULL) {
5847 ctxt->sax = sax;
5848 ctxt->userData = userData;
5849 }
5850
5851 docbParseDocument(ctxt);
5852 ret = ctxt->myDoc;
5853 if (sax != NULL) {
5854 ctxt->sax = NULL;
5855 ctxt->userData = NULL;
5856 }
5857 docbFreeParserCtxt(ctxt);
5858
5859 return(ret);
5860}
5861
5862/**
5863 * docbParseDoc :
5864 * @cur: a pointer to an array of xmlChar
5865 * @encoding: a free form C string describing the SGML document encoding, or NULL
5866 *
5867 * parse an SGML in-memory document and build a tree.
5868 *
5869 * Returns the resulting document tree
5870 */
5871
5872docbDocPtr
5873docbParseDoc(xmlChar *cur, const char *encoding) {
5874 return(docbSAXParseDoc(cur, encoding, NULL, NULL));
5875}
5876
5877
5878/**
5879 * docbCreateFileParserCtxt :
5880 * @filename: the filename
Daniel Veillard1034da22001-04-25 19:06:28 +00005881 * @encoding: the SGML document encoding, or NULL
Daniel Veillardeae522a2001-04-23 13:41:34 +00005882 *
5883 * Create a parser context for a file content.
5884 * Automatic support for ZLIB/Compress compressed document is provided
5885 * by default if found at compile-time.
5886 *
5887 * Returns the new parser context or NULL
5888 */
5889docbParserCtxtPtr
Daniel Veillard1034da22001-04-25 19:06:28 +00005890docbCreateFileParserCtxt(const char *filename,
5891 const char *encoding ATTRIBUTE_UNUSED)
Daniel Veillardeae522a2001-04-23 13:41:34 +00005892{
5893 docbParserCtxtPtr ctxt;
5894 docbParserInputPtr inputStream;
5895 xmlParserInputBufferPtr buf;
5896 /* sgmlCharEncoding enc; */
5897
5898 buf = xmlParserInputBufferCreateFilename(filename, XML_CHAR_ENCODING_NONE);
5899 if (buf == NULL) return(NULL);
5900
5901 ctxt = (docbParserCtxtPtr) xmlMalloc(sizeof(docbParserCtxt));
5902 if (ctxt == NULL) {
5903 perror("malloc");
5904 return(NULL);
5905 }
5906 memset(ctxt, 0, sizeof(docbParserCtxt));
5907 docbInitParserCtxt(ctxt);
5908 inputStream = (docbParserInputPtr) xmlMalloc(sizeof(docbParserInput));
5909 if (inputStream == NULL) {
5910 perror("malloc");
5911 xmlFree(ctxt);
5912 return(NULL);
5913 }
5914 memset(inputStream, 0, sizeof(docbParserInput));
5915
5916 inputStream->filename = xmlMemStrdup(filename);
5917 inputStream->line = 1;
5918 inputStream->col = 1;
5919 inputStream->buf = buf;
5920 inputStream->directory = NULL;
5921
5922 inputStream->base = inputStream->buf->buffer->content;
5923 inputStream->cur = inputStream->buf->buffer->content;
5924 inputStream->free = NULL;
5925
5926 inputPush(ctxt, inputStream);
5927 return(ctxt);
5928}
5929
5930/**
5931 * docbSAXParseFile :
5932 * @filename: the filename
5933 * @encoding: a free form C string describing the SGML document encoding, or NULL
5934 * @sax: the SAX handler block
5935 * @userData: if using SAX, this pointer will be provided on callbacks.
5936 *
5937 * parse an SGML file and build a tree. Automatic support for ZLIB/Compress
5938 * compressed document is provided by default if found at compile-time.
5939 * It use the given SAX function block to handle the parsing callback.
5940 * If sax is NULL, fallback to the default DOM tree building routines.
5941 *
5942 * Returns the resulting document tree
5943 */
5944
5945docbDocPtr
5946docbSAXParseFile(const char *filename, const char *encoding, docbSAXHandlerPtr sax,
5947 void *userData) {
5948 docbDocPtr ret;
5949 docbParserCtxtPtr ctxt;
5950 docbSAXHandlerPtr oldsax = NULL;
5951
5952 ctxt = docbCreateFileParserCtxt(filename, encoding);
5953 if (ctxt == NULL) return(NULL);
5954 if (sax != NULL) {
5955 oldsax = ctxt->sax;
5956 ctxt->sax = sax;
5957 ctxt->userData = userData;
5958 }
5959
5960 docbParseDocument(ctxt);
5961
5962 ret = ctxt->myDoc;
5963 if (sax != NULL) {
5964 ctxt->sax = oldsax;
5965 ctxt->userData = NULL;
5966 }
5967 docbFreeParserCtxt(ctxt);
5968
5969 return(ret);
5970}
5971
5972/**
5973 * docbParseFile :
5974 * @filename: the filename
5975 * @encoding: a free form C string describing document encoding, or NULL
5976 *
5977 * parse a Docbook SGML file and build a tree. Automatic support for
5978 * ZLIB/Compress compressed document is provided by default if found
5979 * at compile-time.
5980 *
5981 * Returns the resulting document tree
5982 */
5983
5984docbDocPtr
5985docbParseFile(const char *filename, const char *encoding) {
5986 return(docbSAXParseFile(filename, encoding, NULL, NULL));
5987}
5988
5989#endif /* LIBXML_DOCB_ENABLED */