1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/parser/expat/lib/xmltok.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,316 @@ 1.4 +/* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd 1.5 + See the file COPYING for copying permission. 1.6 +*/ 1.7 + 1.8 +#ifndef XmlTok_INCLUDED 1.9 +#define XmlTok_INCLUDED 1 1.10 + 1.11 +#ifdef __cplusplus 1.12 +extern "C" { 1.13 +#endif 1.14 + 1.15 +/* The following token may be returned by XmlContentTok */ 1.16 +#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be 1.17 + start of illegal ]]> sequence */ 1.18 +/* The following tokens may be returned by both XmlPrologTok and 1.19 + XmlContentTok. 1.20 +*/ 1.21 +#define XML_TOK_NONE -4 /* The string to be scanned is empty */ 1.22 +#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan; 1.23 + might be part of CRLF sequence */ 1.24 +#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ 1.25 +#define XML_TOK_PARTIAL -1 /* only part of a token */ 1.26 +#define XML_TOK_INVALID 0 1.27 + 1.28 +/* The following tokens are returned by XmlContentTok; some are also 1.29 + returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok. 1.30 +*/ 1.31 +#define XML_TOK_START_TAG_WITH_ATTS 1 1.32 +#define XML_TOK_START_TAG_NO_ATTS 2 1.33 +#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */ 1.34 +#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4 1.35 +#define XML_TOK_END_TAG 5 1.36 +#define XML_TOK_DATA_CHARS 6 1.37 +#define XML_TOK_DATA_NEWLINE 7 1.38 +#define XML_TOK_CDATA_SECT_OPEN 8 1.39 +#define XML_TOK_ENTITY_REF 9 1.40 +#define XML_TOK_CHAR_REF 10 /* numeric character reference */ 1.41 + 1.42 +/* The following tokens may be returned by both XmlPrologTok and 1.43 + XmlContentTok. 1.44 +*/ 1.45 +#define XML_TOK_PI 11 /* processing instruction */ 1.46 +#define XML_TOK_XML_DECL 12 /* XML decl or text decl */ 1.47 +#define XML_TOK_COMMENT 13 1.48 +#define XML_TOK_BOM 14 /* Byte order mark */ 1.49 + 1.50 +/* The following tokens are returned only by XmlPrologTok */ 1.51 +#define XML_TOK_PROLOG_S 15 1.52 +#define XML_TOK_DECL_OPEN 16 /* <!foo */ 1.53 +#define XML_TOK_DECL_CLOSE 17 /* > */ 1.54 +#define XML_TOK_NAME 18 1.55 +#define XML_TOK_NMTOKEN 19 1.56 +#define XML_TOK_POUND_NAME 20 /* #name */ 1.57 +#define XML_TOK_OR 21 /* | */ 1.58 +#define XML_TOK_PERCENT 22 1.59 +#define XML_TOK_OPEN_PAREN 23 1.60 +#define XML_TOK_CLOSE_PAREN 24 1.61 +#define XML_TOK_OPEN_BRACKET 25 1.62 +#define XML_TOK_CLOSE_BRACKET 26 1.63 +#define XML_TOK_LITERAL 27 1.64 +#define XML_TOK_PARAM_ENTITY_REF 28 1.65 +#define XML_TOK_INSTANCE_START 29 1.66 + 1.67 +/* The following occur only in element type declarations */ 1.68 +#define XML_TOK_NAME_QUESTION 30 /* name? */ 1.69 +#define XML_TOK_NAME_ASTERISK 31 /* name* */ 1.70 +#define XML_TOK_NAME_PLUS 32 /* name+ */ 1.71 +#define XML_TOK_COND_SECT_OPEN 33 /* <![ */ 1.72 +#define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */ 1.73 +#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ 1.74 +#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ 1.75 +#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ 1.76 +#define XML_TOK_COMMA 38 1.77 + 1.78 +/* The following token is returned only by XmlAttributeValueTok */ 1.79 +#define XML_TOK_ATTRIBUTE_VALUE_S 39 1.80 + 1.81 +/* The following token is returned only by XmlCdataSectionTok */ 1.82 +#define XML_TOK_CDATA_SECT_CLOSE 40 1.83 + 1.84 +/* With namespace processing this is returned by XmlPrologTok for a 1.85 + name with a colon. 1.86 +*/ 1.87 +#define XML_TOK_PREFIXED_NAME 41 1.88 + 1.89 +#ifdef XML_DTD 1.90 +#define XML_TOK_IGNORE_SECT 42 1.91 +#endif /* XML_DTD */ 1.92 + 1.93 +#ifdef XML_DTD 1.94 +#define XML_N_STATES 4 1.95 +#else /* not XML_DTD */ 1.96 +#define XML_N_STATES 3 1.97 +#endif /* not XML_DTD */ 1.98 + 1.99 +#define XML_PROLOG_STATE 0 1.100 +#define XML_CONTENT_STATE 1 1.101 +#define XML_CDATA_SECTION_STATE 2 1.102 +#ifdef XML_DTD 1.103 +#define XML_IGNORE_SECTION_STATE 3 1.104 +#endif /* XML_DTD */ 1.105 + 1.106 +#define XML_N_LITERAL_TYPES 2 1.107 +#define XML_ATTRIBUTE_VALUE_LITERAL 0 1.108 +#define XML_ENTITY_VALUE_LITERAL 1 1.109 + 1.110 +/* The size of the buffer passed to XmlUtf8Encode must be at least this. */ 1.111 +#define XML_UTF8_ENCODE_MAX 4 1.112 +/* The size of the buffer passed to XmlUtf16Encode must be at least this. */ 1.113 +#define XML_UTF16_ENCODE_MAX 2 1.114 + 1.115 +typedef struct position { 1.116 + /* first line and first column are 0 not 1 */ 1.117 + XML_Size lineNumber; 1.118 + XML_Size columnNumber; 1.119 +} POSITION; 1.120 + 1.121 +typedef struct { 1.122 + const char *name; 1.123 + const char *valuePtr; 1.124 + const char *valueEnd; 1.125 + char normalized; 1.126 +} ATTRIBUTE; 1.127 + 1.128 +struct encoding; 1.129 +typedef struct encoding ENCODING; 1.130 + 1.131 +typedef int (PTRCALL *SCANNER)(const ENCODING *, 1.132 + const char *, 1.133 + const char *, 1.134 + const char **); 1.135 + 1.136 +struct encoding { 1.137 + SCANNER scanners[XML_N_STATES]; 1.138 + SCANNER literalScanners[XML_N_LITERAL_TYPES]; 1.139 + int (PTRCALL *sameName)(const ENCODING *, 1.140 + const char *, 1.141 + const char *); 1.142 + int (PTRCALL *nameMatchesAscii)(const ENCODING *, 1.143 + const char *, 1.144 + const char *, 1.145 + const char *); 1.146 + int (PTRFASTCALL *nameLength)(const ENCODING *, const char *); 1.147 + const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *); 1.148 + int (PTRCALL *getAtts)(const ENCODING *enc, 1.149 + const char *ptr, 1.150 + int attsMax, 1.151 + ATTRIBUTE *atts); 1.152 + int (PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); 1.153 + int (PTRCALL *predefinedEntityName)(const ENCODING *, 1.154 + const char *, 1.155 + const char *); 1.156 + void (PTRCALL *updatePosition)(const ENCODING *, 1.157 + const char *ptr, 1.158 + const char *end, 1.159 + POSITION *); 1.160 + int (PTRCALL *isPublicId)(const ENCODING *enc, 1.161 + const char *ptr, 1.162 + const char *end, 1.163 + const char **badPtr); 1.164 + void (PTRCALL *utf8Convert)(const ENCODING *enc, 1.165 + const char **fromP, 1.166 + const char *fromLim, 1.167 + char **toP, 1.168 + const char *toLim); 1.169 + void (PTRCALL *utf16Convert)(const ENCODING *enc, 1.170 + const char **fromP, 1.171 + const char *fromLim, 1.172 + unsigned short **toP, 1.173 + const unsigned short *toLim); 1.174 + int minBytesPerChar; 1.175 + char isUtf8; 1.176 + char isUtf16; 1.177 +}; 1.178 + 1.179 +/* Scan the string starting at ptr until the end of the next complete 1.180 + token, but do not scan past eptr. Return an integer giving the 1.181 + type of token. 1.182 + 1.183 + Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set. 1.184 + 1.185 + Return XML_TOK_PARTIAL when the string does not contain a complete 1.186 + token; nextTokPtr will not be set. 1.187 + 1.188 + Return XML_TOK_INVALID when the string does not start a valid 1.189 + token; nextTokPtr will be set to point to the character which made 1.190 + the token invalid. 1.191 + 1.192 + Otherwise the string starts with a valid token; nextTokPtr will be 1.193 + set to point to the character following the end of that token. 1.194 + 1.195 + Each data character counts as a single token, but adjacent data 1.196 + characters may be returned together. Similarly for characters in 1.197 + the prolog outside literals, comments and processing instructions. 1.198 +*/ 1.199 + 1.200 + 1.201 +#define XmlTok(enc, state, ptr, end, nextTokPtr) \ 1.202 + (((enc)->scanners[state])(enc, ptr, end, nextTokPtr)) 1.203 + 1.204 +#define XmlPrologTok(enc, ptr, end, nextTokPtr) \ 1.205 + XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) 1.206 + 1.207 +#define XmlContentTok(enc, ptr, end, nextTokPtr) \ 1.208 + XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) 1.209 + 1.210 +#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ 1.211 + XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) 1.212 + 1.213 +#ifdef XML_DTD 1.214 + 1.215 +#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ 1.216 + XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) 1.217 + 1.218 +#endif /* XML_DTD */ 1.219 + 1.220 +/* This is used for performing a 2nd-level tokenization on the content 1.221 + of a literal that has already been returned by XmlTok. 1.222 +*/ 1.223 +#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ 1.224 + (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr)) 1.225 + 1.226 +#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ 1.227 + XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) 1.228 + 1.229 +#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ 1.230 + XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) 1.231 + 1.232 +#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2)) 1.233 + 1.234 +#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ 1.235 + (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2)) 1.236 + 1.237 +#define XmlNameLength(enc, ptr) \ 1.238 + (((enc)->nameLength)(enc, ptr)) 1.239 + 1.240 +#define XmlSkipS(enc, ptr) \ 1.241 + (((enc)->skipS)(enc, ptr)) 1.242 + 1.243 +#define XmlGetAttributes(enc, ptr, attsMax, atts) \ 1.244 + (((enc)->getAtts)(enc, ptr, attsMax, atts)) 1.245 + 1.246 +#define XmlCharRefNumber(enc, ptr) \ 1.247 + (((enc)->charRefNumber)(enc, ptr)) 1.248 + 1.249 +#define XmlPredefinedEntityName(enc, ptr, end) \ 1.250 + (((enc)->predefinedEntityName)(enc, ptr, end)) 1.251 + 1.252 +#define XmlUpdatePosition(enc, ptr, end, pos) \ 1.253 + (((enc)->updatePosition)(enc, ptr, end, pos)) 1.254 + 1.255 +#define XmlIsPublicId(enc, ptr, end, badPtr) \ 1.256 + (((enc)->isPublicId)(enc, ptr, end, badPtr)) 1.257 + 1.258 +#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ 1.259 + (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) 1.260 + 1.261 +#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ 1.262 + (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim)) 1.263 + 1.264 +typedef struct { 1.265 + ENCODING initEnc; 1.266 + const ENCODING **encPtr; 1.267 +} INIT_ENCODING; 1.268 + 1.269 +int XmlParseXmlDecl(int isGeneralTextEntity, 1.270 + const ENCODING *enc, 1.271 + const char *ptr, 1.272 + const char *end, 1.273 + const char **badPtr, 1.274 + const char **versionPtr, 1.275 + const char **versionEndPtr, 1.276 + const char **encodingNamePtr, 1.277 + const ENCODING **namedEncodingPtr, 1.278 + int *standalonePtr); 1.279 + 1.280 +int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); 1.281 +const ENCODING *XmlGetUtf8InternalEncoding(void); 1.282 +const ENCODING *XmlGetUtf16InternalEncoding(void); 1.283 +int FASTCALL XmlUtf8Encode(int charNumber, char *buf); 1.284 +int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf); 1.285 +int XmlSizeOfUnknownEncoding(void); 1.286 + 1.287 + 1.288 +typedef int (XMLCALL *CONVERTER) (void *userData, const char *p); 1.289 + 1.290 +ENCODING * 1.291 +XmlInitUnknownEncoding(void *mem, 1.292 + int *table, 1.293 + CONVERTER convert, 1.294 + void *userData); 1.295 + 1.296 +int XmlParseXmlDeclNS(int isGeneralTextEntity, 1.297 + const ENCODING *enc, 1.298 + const char *ptr, 1.299 + const char *end, 1.300 + const char **badPtr, 1.301 + const char **versionPtr, 1.302 + const char **versionEndPtr, 1.303 + const char **encodingNamePtr, 1.304 + const ENCODING **namedEncodingPtr, 1.305 + int *standalonePtr); 1.306 + 1.307 +int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); 1.308 +const ENCODING *XmlGetUtf8InternalEncodingNS(void); 1.309 +const ENCODING *XmlGetUtf16InternalEncodingNS(void); 1.310 +ENCODING * 1.311 +XmlInitUnknownEncodingNS(void *mem, 1.312 + int *table, 1.313 + CONVERTER convert, 1.314 + void *userData); 1.315 +#ifdef __cplusplus 1.316 +} 1.317 +#endif 1.318 + 1.319 +#endif /* not XmlTok_INCLUDED */