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