1 |
adcroft |
1.1 |
/* |
2 |
|
|
Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd |
3 |
|
|
See the file copying.txt for copying permission. |
4 |
|
|
*/ |
5 |
|
|
|
6 |
|
|
#ifndef XmlTok_INCLUDED |
7 |
|
|
#define XmlTok_INCLUDED 1 |
8 |
|
|
|
9 |
|
|
#ifdef __cplusplus |
10 |
|
|
extern "C" { |
11 |
|
|
#endif |
12 |
|
|
|
13 |
|
|
#ifndef XMLTOKAPI |
14 |
|
|
#define XMLTOKAPI /* as nothing */ |
15 |
|
|
#endif |
16 |
|
|
|
17 |
|
|
/* The following token may be returned by XmlContentTok */ |
18 |
|
|
#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be start of |
19 |
|
|
illegal ]]> sequence */ |
20 |
|
|
/* The following tokens may be returned by both XmlPrologTok and XmlContentTok */ |
21 |
|
|
#define XML_TOK_NONE -4 /* The string to be scanned is empty */ |
22 |
|
|
#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan; |
23 |
|
|
might be part of CRLF sequence */ |
24 |
|
|
#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ |
25 |
|
|
#define XML_TOK_PARTIAL -1 /* only part of a token */ |
26 |
|
|
#define XML_TOK_INVALID 0 |
27 |
|
|
|
28 |
|
|
/* The following tokens are returned by XmlContentTok; some are also |
29 |
|
|
returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok */ |
30 |
|
|
|
31 |
|
|
#define XML_TOK_START_TAG_WITH_ATTS 1 |
32 |
|
|
#define XML_TOK_START_TAG_NO_ATTS 2 |
33 |
|
|
#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */ |
34 |
|
|
#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4 |
35 |
|
|
#define XML_TOK_END_TAG 5 |
36 |
|
|
#define XML_TOK_DATA_CHARS 6 |
37 |
|
|
#define XML_TOK_DATA_NEWLINE 7 |
38 |
|
|
#define XML_TOK_CDATA_SECT_OPEN 8 |
39 |
|
|
#define XML_TOK_ENTITY_REF 9 |
40 |
|
|
#define XML_TOK_CHAR_REF 10 /* numeric character reference */ |
41 |
|
|
|
42 |
|
|
/* The following tokens may be returned by both XmlPrologTok and XmlContentTok */ |
43 |
|
|
#define XML_TOK_PI 11 /* processing instruction */ |
44 |
|
|
#define XML_TOK_XML_DECL 12 /* XML decl or text decl */ |
45 |
|
|
#define XML_TOK_COMMENT 13 |
46 |
|
|
#define XML_TOK_BOM 14 /* Byte order mark */ |
47 |
|
|
|
48 |
|
|
/* The following tokens are returned only by XmlPrologTok */ |
49 |
|
|
#define XML_TOK_PROLOG_S 15 |
50 |
|
|
#define XML_TOK_DECL_OPEN 16 /* <!foo */ |
51 |
|
|
#define XML_TOK_DECL_CLOSE 17 /* > */ |
52 |
|
|
#define XML_TOK_NAME 18 |
53 |
|
|
#define XML_TOK_NMTOKEN 19 |
54 |
|
|
#define XML_TOK_POUND_NAME 20 /* #name */ |
55 |
|
|
#define XML_TOK_OR 21 /* | */ |
56 |
|
|
#define XML_TOK_PERCENT 22 |
57 |
|
|
#define XML_TOK_OPEN_PAREN 23 |
58 |
|
|
#define XML_TOK_CLOSE_PAREN 24 |
59 |
|
|
#define XML_TOK_OPEN_BRACKET 25 |
60 |
|
|
#define XML_TOK_CLOSE_BRACKET 26 |
61 |
|
|
#define XML_TOK_LITERAL 27 |
62 |
|
|
#define XML_TOK_PARAM_ENTITY_REF 28 |
63 |
|
|
#define XML_TOK_INSTANCE_START 29 |
64 |
|
|
|
65 |
|
|
/* The following occur only in element type declarations */ |
66 |
|
|
#define XML_TOK_NAME_QUESTION 30 /* name? */ |
67 |
|
|
#define XML_TOK_NAME_ASTERISK 31 /* name* */ |
68 |
|
|
#define XML_TOK_NAME_PLUS 32 /* name+ */ |
69 |
|
|
#define XML_TOK_COND_SECT_OPEN 33 /* <![ */ |
70 |
|
|
#define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */ |
71 |
|
|
#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ |
72 |
|
|
#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ |
73 |
|
|
#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ |
74 |
|
|
#define XML_TOK_COMMA 38 |
75 |
|
|
|
76 |
|
|
/* The following token is returned only by XmlAttributeValueTok */ |
77 |
|
|
#define XML_TOK_ATTRIBUTE_VALUE_S 39 |
78 |
|
|
|
79 |
|
|
/* The following token is returned only by XmlCdataSectionTok */ |
80 |
|
|
#define XML_TOK_CDATA_SECT_CLOSE 40 |
81 |
|
|
|
82 |
|
|
/* With namespace processing this is returned by XmlPrologTok |
83 |
|
|
for a name with a colon. */ |
84 |
|
|
#define XML_TOK_PREFIXED_NAME 41 |
85 |
|
|
|
86 |
|
|
#ifdef XML_DTD |
87 |
|
|
#define XML_TOK_IGNORE_SECT 42 |
88 |
|
|
#endif /* XML_DTD */ |
89 |
|
|
|
90 |
|
|
#ifdef XML_DTD |
91 |
|
|
#define XML_N_STATES 4 |
92 |
|
|
#else /* not XML_DTD */ |
93 |
|
|
#define XML_N_STATES 3 |
94 |
|
|
#endif /* not XML_DTD */ |
95 |
|
|
|
96 |
|
|
#define XML_PROLOG_STATE 0 |
97 |
|
|
#define XML_CONTENT_STATE 1 |
98 |
|
|
#define XML_CDATA_SECTION_STATE 2 |
99 |
|
|
#ifdef XML_DTD |
100 |
|
|
#define XML_IGNORE_SECTION_STATE 3 |
101 |
|
|
#endif /* XML_DTD */ |
102 |
|
|
|
103 |
|
|
#define XML_N_LITERAL_TYPES 2 |
104 |
|
|
#define XML_ATTRIBUTE_VALUE_LITERAL 0 |
105 |
|
|
#define XML_ENTITY_VALUE_LITERAL 1 |
106 |
|
|
|
107 |
|
|
/* The size of the buffer passed to XmlUtf8Encode must be at least this. */ |
108 |
|
|
#define XML_UTF8_ENCODE_MAX 4 |
109 |
|
|
/* The size of the buffer passed to XmlUtf16Encode must be at least this. */ |
110 |
|
|
#define XML_UTF16_ENCODE_MAX 2 |
111 |
|
|
|
112 |
|
|
typedef struct position { |
113 |
|
|
/* first line and first column are 0 not 1 */ |
114 |
|
|
unsigned long lineNumber; |
115 |
|
|
unsigned long columnNumber; |
116 |
|
|
} POSITION; |
117 |
|
|
|
118 |
|
|
typedef struct { |
119 |
|
|
const char *name; |
120 |
|
|
const char *valuePtr; |
121 |
|
|
const char *valueEnd; |
122 |
|
|
char normalized; |
123 |
|
|
} ATTRIBUTE; |
124 |
|
|
|
125 |
|
|
struct encoding; |
126 |
|
|
typedef struct encoding ENCODING; |
127 |
|
|
|
128 |
|
|
struct encoding { |
129 |
|
|
int (*scanners[XML_N_STATES])(const ENCODING *, |
130 |
|
|
const char *, |
131 |
|
|
const char *, |
132 |
|
|
const char **); |
133 |
|
|
int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *, |
134 |
|
|
const char *, |
135 |
|
|
const char *, |
136 |
|
|
const char **); |
137 |
|
|
int (*sameName)(const ENCODING *, |
138 |
|
|
const char *, const char *); |
139 |
|
|
int (*nameMatchesAscii)(const ENCODING *, |
140 |
|
|
const char *, const char *, const char *); |
141 |
|
|
int (*nameLength)(const ENCODING *, const char *); |
142 |
|
|
const char *(*skipS)(const ENCODING *, const char *); |
143 |
|
|
int (*getAtts)(const ENCODING *enc, const char *ptr, |
144 |
|
|
int attsMax, ATTRIBUTE *atts); |
145 |
|
|
int (*charRefNumber)(const ENCODING *enc, const char *ptr); |
146 |
|
|
int (*predefinedEntityName)(const ENCODING *, const char *, const char *); |
147 |
|
|
void (*updatePosition)(const ENCODING *, |
148 |
|
|
const char *ptr, |
149 |
|
|
const char *end, |
150 |
|
|
POSITION *); |
151 |
|
|
int (*isPublicId)(const ENCODING *enc, const char *ptr, const char *end, |
152 |
|
|
const char **badPtr); |
153 |
|
|
void (*utf8Convert)(const ENCODING *enc, |
154 |
|
|
const char **fromP, |
155 |
|
|
const char *fromLim, |
156 |
|
|
char **toP, |
157 |
|
|
const char *toLim); |
158 |
|
|
void (*utf16Convert)(const ENCODING *enc, |
159 |
|
|
const char **fromP, |
160 |
|
|
const char *fromLim, |
161 |
|
|
unsigned short **toP, |
162 |
|
|
const unsigned short *toLim); |
163 |
|
|
int minBytesPerChar; |
164 |
|
|
char isUtf8; |
165 |
|
|
char isUtf16; |
166 |
|
|
}; |
167 |
|
|
|
168 |
|
|
/* |
169 |
|
|
Scan the string starting at ptr until the end of the next complete token, |
170 |
|
|
but do not scan past eptr. Return an integer giving the type of token. |
171 |
|
|
|
172 |
|
|
Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set. |
173 |
|
|
|
174 |
|
|
Return XML_TOK_PARTIAL when the string does not contain a complete token; |
175 |
|
|
nextTokPtr will not be set. |
176 |
|
|
|
177 |
|
|
Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr |
178 |
|
|
will be set to point to the character which made the token invalid. |
179 |
|
|
|
180 |
|
|
Otherwise the string starts with a valid token; nextTokPtr will be set to point |
181 |
|
|
to the character following the end of that token. |
182 |
|
|
|
183 |
|
|
Each data character counts as a single token, but adjacent data characters |
184 |
|
|
may be returned together. Similarly for characters in the prolog outside |
185 |
|
|
literals, comments and processing instructions. |
186 |
|
|
*/ |
187 |
|
|
|
188 |
|
|
|
189 |
|
|
#define XmlTok(enc, state, ptr, end, nextTokPtr) \ |
190 |
|
|
(((enc)->scanners[state])(enc, ptr, end, nextTokPtr)) |
191 |
|
|
|
192 |
|
|
#define XmlPrologTok(enc, ptr, end, nextTokPtr) \ |
193 |
|
|
XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) |
194 |
|
|
|
195 |
|
|
#define XmlContentTok(enc, ptr, end, nextTokPtr) \ |
196 |
|
|
XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) |
197 |
|
|
|
198 |
|
|
#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ |
199 |
|
|
XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) |
200 |
|
|
|
201 |
|
|
#ifdef XML_DTD |
202 |
|
|
|
203 |
|
|
#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ |
204 |
|
|
XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) |
205 |
|
|
|
206 |
|
|
#endif /* XML_DTD */ |
207 |
|
|
|
208 |
|
|
/* This is used for performing a 2nd-level tokenization on |
209 |
|
|
the content of a literal that has already been returned by XmlTok. */ |
210 |
|
|
|
211 |
|
|
#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ |
212 |
|
|
(((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr)) |
213 |
|
|
|
214 |
|
|
#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ |
215 |
|
|
XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) |
216 |
|
|
|
217 |
|
|
#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ |
218 |
|
|
XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) |
219 |
|
|
|
220 |
|
|
#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2)) |
221 |
|
|
|
222 |
|
|
#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ |
223 |
|
|
(((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2)) |
224 |
|
|
|
225 |
|
|
#define XmlNameLength(enc, ptr) \ |
226 |
|
|
(((enc)->nameLength)(enc, ptr)) |
227 |
|
|
|
228 |
|
|
#define XmlSkipS(enc, ptr) \ |
229 |
|
|
(((enc)->skipS)(enc, ptr)) |
230 |
|
|
|
231 |
|
|
#define XmlGetAttributes(enc, ptr, attsMax, atts) \ |
232 |
|
|
(((enc)->getAtts)(enc, ptr, attsMax, atts)) |
233 |
|
|
|
234 |
|
|
#define XmlCharRefNumber(enc, ptr) \ |
235 |
|
|
(((enc)->charRefNumber)(enc, ptr)) |
236 |
|
|
|
237 |
|
|
#define XmlPredefinedEntityName(enc, ptr, end) \ |
238 |
|
|
(((enc)->predefinedEntityName)(enc, ptr, end)) |
239 |
|
|
|
240 |
|
|
#define XmlUpdatePosition(enc, ptr, end, pos) \ |
241 |
|
|
(((enc)->updatePosition)(enc, ptr, end, pos)) |
242 |
|
|
|
243 |
|
|
#define XmlIsPublicId(enc, ptr, end, badPtr) \ |
244 |
|
|
(((enc)->isPublicId)(enc, ptr, end, badPtr)) |
245 |
|
|
|
246 |
|
|
#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ |
247 |
|
|
(((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) |
248 |
|
|
|
249 |
|
|
#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ |
250 |
|
|
(((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim)) |
251 |
|
|
|
252 |
|
|
typedef struct { |
253 |
|
|
ENCODING initEnc; |
254 |
|
|
const ENCODING **encPtr; |
255 |
|
|
} INIT_ENCODING; |
256 |
|
|
|
257 |
|
|
int XMLTOKAPI XmlParseXmlDecl(int isGeneralTextEntity, |
258 |
|
|
const ENCODING *enc, |
259 |
|
|
const char *ptr, |
260 |
|
|
const char *end, |
261 |
|
|
const char **badPtr, |
262 |
|
|
const char **versionPtr, |
263 |
|
|
const char **encodingNamePtr, |
264 |
|
|
const ENCODING **namedEncodingPtr, |
265 |
|
|
int *standalonePtr); |
266 |
|
|
|
267 |
|
|
int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); |
268 |
|
|
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding(void); |
269 |
|
|
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding(void); |
270 |
|
|
int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf); |
271 |
|
|
int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf); |
272 |
|
|
|
273 |
|
|
int XMLTOKAPI XmlSizeOfUnknownEncoding(void); |
274 |
|
|
ENCODING XMLTOKAPI * |
275 |
|
|
XmlInitUnknownEncoding(void *mem, |
276 |
|
|
int *table, |
277 |
|
|
int (*conv)(void *userData, const char *p), |
278 |
|
|
void *userData); |
279 |
|
|
|
280 |
|
|
int XMLTOKAPI XmlParseXmlDeclNS(int isGeneralTextEntity, |
281 |
|
|
const ENCODING *enc, |
282 |
|
|
const char *ptr, |
283 |
|
|
const char *end, |
284 |
|
|
const char **badPtr, |
285 |
|
|
const char **versionPtr, |
286 |
|
|
const char **encodingNamePtr, |
287 |
|
|
const ENCODING **namedEncodingPtr, |
288 |
|
|
int *standalonePtr); |
289 |
|
|
int XMLTOKAPI XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); |
290 |
|
|
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncodingNS(void); |
291 |
|
|
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncodingNS(void); |
292 |
|
|
ENCODING XMLTOKAPI * |
293 |
|
|
XmlInitUnknownEncodingNS(void *mem, |
294 |
|
|
int *table, |
295 |
|
|
int (*conv)(void *userData, const char *p), |
296 |
|
|
void *userData); |
297 |
|
|
#ifdef __cplusplus |
298 |
|
|
} |
299 |
|
|
#endif |
300 |
|
|
|
301 |
|
|
#endif /* not XmlTok_INCLUDED */ |