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