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