source: trunk/include/expat/xmltok.h@ 90

Last change on this file since 90 was 38, checked in by umoeller, 25 years ago

Updates to XML.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 KB
Line 
1/*
2Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
3See the file COPYING for copying permission.
4*/
5
6#ifndef XmlTok_INCLUDED
7#define XmlTok_INCLUDED 1
8
9#include "expat\expat_setup.h"
10 // V0.9.9 (2001-02-10) [umoeller]
11 // to save the app from having to include this as well
12
13#ifdef __cplusplus
14extern "C" {
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
112typedef struct position {
113 /* first line and first column are 0 not 1 */
114 unsigned long lineNumber;
115 unsigned long columnNumber;
116} POSITION;
117
118typedef struct
119{
120 const char *name;
121 const char *valuePtr;
122 const char *valueEnd;
123 char normalized;
124} ATTRIBUTE, *PATTRIBUTE;
125
126struct encoding;
127typedef struct encoding ENCODING, *PENCODING;
128
129typedef int EXPATENTRY SCANNERFUNC(const ENCODING *,
130 const char *,
131 const char *,
132 const char **);
133typedef SCANNERFUNC *PSCANNERFUNC;
134
135struct encoding
136{
137 PSCANNERFUNC scanners[XML_N_STATES];
138 PSCANNERFUNC literalScanners[XML_N_LITERAL_TYPES];
139 int (* EXPATENTRY sameName)(const ENCODING *,
140 const char *,
141 const char *);
142 int (* EXPATENTRY nameMatchesAscii)(const ENCODING *,
143 const char *,
144 const char *,
145 const char *);
146 int (* EXPATENTRY nameLength)(const ENCODING *,
147 const char *);
148 const char *(*skipS)(const ENCODING *,
149 const char *);
150 int (* EXPATENTRY getAtts)(const ENCODING *enc,
151 const char *ptr,
152 int attsMax,
153 ATTRIBUTE *atts);
154 int (* EXPATENTRY charRefNumber)(const ENCODING *enc,
155 const char *ptr);
156 int (* EXPATENTRY predefinedEntityName)(const ENCODING *,
157 const char *,
158 const char *);
159 void (* EXPATENTRY updatePosition)(const ENCODING *,
160 const char *ptr,
161 const char *end,
162 POSITION *);
163 int (* EXPATENTRY isPublicId)(const ENCODING *enc,
164 const char *ptr,
165 const char *end,
166 const char **badPtr);
167 void (* EXPATENTRY utf8Convert)(const ENCODING *enc,
168 const char **fromP,
169 const char *fromLim,
170 char **toP,
171 const char *toLim);
172 void (* EXPATENTRY utf16Convert)(const ENCODING *enc,
173 const char **fromP,
174 const char *fromLim,
175 unsigned short **toP,
176 const unsigned short *toLim);
177 int minBytesPerChar;
178 char isUtf8;
179 char isUtf16;
180};
181
182/*
183Scan the string starting at ptr until the end of the next complete token,
184but do not scan past eptr. Return an integer giving the type of token.
185
186Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
187
188Return XML_TOK_PARTIAL when the string does not contain a complete token;
189nextTokPtr will not be set.
190
191Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr
192will be set to point to the character which made the token invalid.
193
194Otherwise the string starts with a valid token; nextTokPtr will be set to point
195to the character following the end of that token.
196
197Each data character counts as a single token, but adjacent data characters
198may be returned together. Similarly for characters in the prolog outside
199literals, comments and processing instructions.
200*/
201
202
203#define XmlTok(enc, state, ptr, end, nextTokPtr) \
204 (((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
205
206#define XmlPrologTok(enc, ptr, end, nextTokPtr) \
207 XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
208
209#define XmlContentTok(enc, ptr, end, nextTokPtr) \
210 XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
211
212#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
213 XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
214
215#ifdef XML_DTD
216
217#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \
218 XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr)
219
220#endif /* XML_DTD */
221
222/* This is used for performing a 2nd-level tokenization on
223the content of a literal that has already been returned by XmlTok. */
224
225#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
226 (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
227
228#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
229 XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
230
231#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
232 XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
233
234#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
235
236#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \
237 (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2))
238
239#define XmlNameLength(enc, ptr) \
240 (((enc)->nameLength)(enc, ptr))
241
242#define XmlSkipS(enc, ptr) \
243 (((enc)->skipS)(enc, ptr))
244
245#define XmlGetAttributes(enc, ptr, attsMax, atts) \
246 (((enc)->getAtts)(enc, ptr, attsMax, atts))
247
248#define XmlCharRefNumber(enc, ptr) \
249 (((enc)->charRefNumber)(enc, ptr))
250
251#define XmlPredefinedEntityName(enc, ptr, end) \
252 (((enc)->predefinedEntityName)(enc, ptr, end))
253
254#define XmlUpdatePosition(enc, ptr, end, pos) \
255 (((enc)->updatePosition)(enc, ptr, end, pos))
256
257#define XmlIsPublicId(enc, ptr, end, badPtr) \
258 (((enc)->isPublicId)(enc, ptr, end, badPtr))
259
260#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
261 (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
262
263#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
264 (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
265
266typedef struct {
267 ENCODING initEnc;
268 const ENCODING **encPtr;
269} INIT_ENCODING;
270
271int XmlParseXmlDecl(int isGeneralTextEntity,
272 const ENCODING *enc,
273 const char *ptr,
274 const char *end,
275 const char **badPtr,
276 const char **versionPtr,
277 const char **versionEndPtr,
278 const char **encodingNamePtr,
279 const ENCODING **namedEncodingPtr,
280 int *standalonePtr);
281
282int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
283const ENCODING *XmlGetUtf8InternalEncoding(void);
284const ENCODING *XmlGetUtf16InternalEncoding(void);
285int XmlUtf8Encode(int charNumber, char *buf);
286int XmlUtf16Encode(int charNumber, unsigned short *buf);
287
288int XmlSizeOfUnknownEncoding(void);
289ENCODING *
290XmlInitUnknownEncoding(void *mem,
291 int *table,
292 int (*conv)(void *userData, const char *p),
293 void *userData);
294
295int XmlParseXmlDeclNS(int isGeneralTextEntity,
296 const ENCODING *enc,
297 const char *ptr,
298 const char *end,
299 const char **badPtr,
300 const char **versionPtr,
301 const char **versionEndPtr,
302 const char **encodingNamePtr,
303 const ENCODING **namedEncodingPtr,
304 int *standalonePtr);
305int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
306const ENCODING *XmlGetUtf8InternalEncodingNS(void);
307const ENCODING *XmlGetUtf16InternalEncodingNS(void);
308ENCODING *
309XmlInitUnknownEncodingNS(void *mem,
310 int *table,
311 int (*conv)(void *userData, const char *p),
312 void *userData);
313#ifdef __cplusplus
314}
315#endif
316
317#endif /* not XmlTok_INCLUDED */
Note: See TracBrowser for help on using the repository browser.