michael@0: /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd michael@0: See the file COPYING for copying permission. michael@0: */ michael@0: michael@0: #ifndef XmlTok_INCLUDED michael@0: #define XmlTok_INCLUDED 1 michael@0: michael@0: #ifdef __cplusplus michael@0: extern "C" { michael@0: #endif michael@0: michael@0: /* The following token may be returned by XmlContentTok */ michael@0: #define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be michael@0: start of illegal ]]> sequence */ michael@0: /* The following tokens may be returned by both XmlPrologTok and michael@0: XmlContentTok. michael@0: */ michael@0: #define XML_TOK_NONE -4 /* The string to be scanned is empty */ michael@0: #define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan; michael@0: might be part of CRLF sequence */ michael@0: #define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */ michael@0: #define XML_TOK_PARTIAL -1 /* only part of a token */ michael@0: #define XML_TOK_INVALID 0 michael@0: michael@0: /* The following tokens are returned by XmlContentTok; some are also michael@0: returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok. michael@0: */ michael@0: #define XML_TOK_START_TAG_WITH_ATTS 1 michael@0: #define XML_TOK_START_TAG_NO_ATTS 2 michael@0: #define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag */ michael@0: #define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4 michael@0: #define XML_TOK_END_TAG 5 michael@0: #define XML_TOK_DATA_CHARS 6 michael@0: #define XML_TOK_DATA_NEWLINE 7 michael@0: #define XML_TOK_CDATA_SECT_OPEN 8 michael@0: #define XML_TOK_ENTITY_REF 9 michael@0: #define XML_TOK_CHAR_REF 10 /* numeric character reference */ michael@0: michael@0: /* The following tokens may be returned by both XmlPrologTok and michael@0: XmlContentTok. michael@0: */ michael@0: #define XML_TOK_PI 11 /* processing instruction */ michael@0: #define XML_TOK_XML_DECL 12 /* XML decl or text decl */ michael@0: #define XML_TOK_COMMENT 13 michael@0: #define XML_TOK_BOM 14 /* Byte order mark */ michael@0: michael@0: /* The following tokens are returned only by XmlPrologTok */ michael@0: #define XML_TOK_PROLOG_S 15 michael@0: #define XML_TOK_DECL_OPEN 16 /* */ michael@0: #define XML_TOK_NAME 18 michael@0: #define XML_TOK_NMTOKEN 19 michael@0: #define XML_TOK_POUND_NAME 20 /* #name */ michael@0: #define XML_TOK_OR 21 /* | */ michael@0: #define XML_TOK_PERCENT 22 michael@0: #define XML_TOK_OPEN_PAREN 23 michael@0: #define XML_TOK_CLOSE_PAREN 24 michael@0: #define XML_TOK_OPEN_BRACKET 25 michael@0: #define XML_TOK_CLOSE_BRACKET 26 michael@0: #define XML_TOK_LITERAL 27 michael@0: #define XML_TOK_PARAM_ENTITY_REF 28 michael@0: #define XML_TOK_INSTANCE_START 29 michael@0: michael@0: /* The following occur only in element type declarations */ michael@0: #define XML_TOK_NAME_QUESTION 30 /* name? */ michael@0: #define XML_TOK_NAME_ASTERISK 31 /* name* */ michael@0: #define XML_TOK_NAME_PLUS 32 /* name+ */ michael@0: #define XML_TOK_COND_SECT_OPEN 33 /* */ michael@0: #define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */ michael@0: #define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */ michael@0: #define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */ michael@0: #define XML_TOK_COMMA 38 michael@0: michael@0: /* The following token is returned only by XmlAttributeValueTok */ michael@0: #define XML_TOK_ATTRIBUTE_VALUE_S 39 michael@0: michael@0: /* The following token is returned only by XmlCdataSectionTok */ michael@0: #define XML_TOK_CDATA_SECT_CLOSE 40 michael@0: michael@0: /* With namespace processing this is returned by XmlPrologTok for a michael@0: name with a colon. michael@0: */ michael@0: #define XML_TOK_PREFIXED_NAME 41 michael@0: michael@0: #ifdef XML_DTD michael@0: #define XML_TOK_IGNORE_SECT 42 michael@0: #endif /* XML_DTD */ michael@0: michael@0: #ifdef XML_DTD michael@0: #define XML_N_STATES 4 michael@0: #else /* not XML_DTD */ michael@0: #define XML_N_STATES 3 michael@0: #endif /* not XML_DTD */ michael@0: michael@0: #define XML_PROLOG_STATE 0 michael@0: #define XML_CONTENT_STATE 1 michael@0: #define XML_CDATA_SECTION_STATE 2 michael@0: #ifdef XML_DTD michael@0: #define XML_IGNORE_SECTION_STATE 3 michael@0: #endif /* XML_DTD */ michael@0: michael@0: #define XML_N_LITERAL_TYPES 2 michael@0: #define XML_ATTRIBUTE_VALUE_LITERAL 0 michael@0: #define XML_ENTITY_VALUE_LITERAL 1 michael@0: michael@0: /* The size of the buffer passed to XmlUtf8Encode must be at least this. */ michael@0: #define XML_UTF8_ENCODE_MAX 4 michael@0: /* The size of the buffer passed to XmlUtf16Encode must be at least this. */ michael@0: #define XML_UTF16_ENCODE_MAX 2 michael@0: michael@0: typedef struct position { michael@0: /* first line and first column are 0 not 1 */ michael@0: XML_Size lineNumber; michael@0: XML_Size columnNumber; michael@0: } POSITION; michael@0: michael@0: typedef struct { michael@0: const char *name; michael@0: const char *valuePtr; michael@0: const char *valueEnd; michael@0: char normalized; michael@0: } ATTRIBUTE; michael@0: michael@0: struct encoding; michael@0: typedef struct encoding ENCODING; michael@0: michael@0: typedef int (PTRCALL *SCANNER)(const ENCODING *, michael@0: const char *, michael@0: const char *, michael@0: const char **); michael@0: michael@0: struct encoding { michael@0: SCANNER scanners[XML_N_STATES]; michael@0: SCANNER literalScanners[XML_N_LITERAL_TYPES]; michael@0: int (PTRCALL *sameName)(const ENCODING *, michael@0: const char *, michael@0: const char *); michael@0: int (PTRCALL *nameMatchesAscii)(const ENCODING *, michael@0: const char *, michael@0: const char *, michael@0: const char *); michael@0: int (PTRFASTCALL *nameLength)(const ENCODING *, const char *); michael@0: const char *(PTRFASTCALL *skipS)(const ENCODING *, const char *); michael@0: int (PTRCALL *getAtts)(const ENCODING *enc, michael@0: const char *ptr, michael@0: int attsMax, michael@0: ATTRIBUTE *atts); michael@0: int (PTRFASTCALL *charRefNumber)(const ENCODING *enc, const char *ptr); michael@0: int (PTRCALL *predefinedEntityName)(const ENCODING *, michael@0: const char *, michael@0: const char *); michael@0: void (PTRCALL *updatePosition)(const ENCODING *, michael@0: const char *ptr, michael@0: const char *end, michael@0: POSITION *); michael@0: int (PTRCALL *isPublicId)(const ENCODING *enc, michael@0: const char *ptr, michael@0: const char *end, michael@0: const char **badPtr); michael@0: void (PTRCALL *utf8Convert)(const ENCODING *enc, michael@0: const char **fromP, michael@0: const char *fromLim, michael@0: char **toP, michael@0: const char *toLim); michael@0: void (PTRCALL *utf16Convert)(const ENCODING *enc, michael@0: const char **fromP, michael@0: const char *fromLim, michael@0: unsigned short **toP, michael@0: const unsigned short *toLim); michael@0: int minBytesPerChar; michael@0: char isUtf8; michael@0: char isUtf16; michael@0: }; michael@0: michael@0: /* Scan the string starting at ptr until the end of the next complete michael@0: token, but do not scan past eptr. Return an integer giving the michael@0: type of token. michael@0: michael@0: Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set. michael@0: michael@0: Return XML_TOK_PARTIAL when the string does not contain a complete michael@0: token; nextTokPtr will not be set. michael@0: michael@0: Return XML_TOK_INVALID when the string does not start a valid michael@0: token; nextTokPtr will be set to point to the character which made michael@0: the token invalid. michael@0: michael@0: Otherwise the string starts with a valid token; nextTokPtr will be michael@0: set to point to the character following the end of that token. michael@0: michael@0: Each data character counts as a single token, but adjacent data michael@0: characters may be returned together. Similarly for characters in michael@0: the prolog outside literals, comments and processing instructions. michael@0: */ michael@0: michael@0: michael@0: #define XmlTok(enc, state, ptr, end, nextTokPtr) \ michael@0: (((enc)->scanners[state])(enc, ptr, end, nextTokPtr)) michael@0: michael@0: #define XmlPrologTok(enc, ptr, end, nextTokPtr) \ michael@0: XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr) michael@0: michael@0: #define XmlContentTok(enc, ptr, end, nextTokPtr) \ michael@0: XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr) michael@0: michael@0: #define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \ michael@0: XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr) michael@0: michael@0: #ifdef XML_DTD michael@0: michael@0: #define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \ michael@0: XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr) michael@0: michael@0: #endif /* XML_DTD */ michael@0: michael@0: /* This is used for performing a 2nd-level tokenization on the content michael@0: of a literal that has already been returned by XmlTok. michael@0: */ michael@0: #define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \ michael@0: (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr)) michael@0: michael@0: #define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \ michael@0: XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr) michael@0: michael@0: #define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \ michael@0: XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr) michael@0: michael@0: #define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2)) michael@0: michael@0: #define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \ michael@0: (((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2)) michael@0: michael@0: #define XmlNameLength(enc, ptr) \ michael@0: (((enc)->nameLength)(enc, ptr)) michael@0: michael@0: #define XmlSkipS(enc, ptr) \ michael@0: (((enc)->skipS)(enc, ptr)) michael@0: michael@0: #define XmlGetAttributes(enc, ptr, attsMax, atts) \ michael@0: (((enc)->getAtts)(enc, ptr, attsMax, atts)) michael@0: michael@0: #define XmlCharRefNumber(enc, ptr) \ michael@0: (((enc)->charRefNumber)(enc, ptr)) michael@0: michael@0: #define XmlPredefinedEntityName(enc, ptr, end) \ michael@0: (((enc)->predefinedEntityName)(enc, ptr, end)) michael@0: michael@0: #define XmlUpdatePosition(enc, ptr, end, pos) \ michael@0: (((enc)->updatePosition)(enc, ptr, end, pos)) michael@0: michael@0: #define XmlIsPublicId(enc, ptr, end, badPtr) \ michael@0: (((enc)->isPublicId)(enc, ptr, end, badPtr)) michael@0: michael@0: #define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \ michael@0: (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) michael@0: michael@0: #define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \ michael@0: (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim)) michael@0: michael@0: typedef struct { michael@0: ENCODING initEnc; michael@0: const ENCODING **encPtr; michael@0: } INIT_ENCODING; michael@0: michael@0: int XmlParseXmlDecl(int isGeneralTextEntity, michael@0: const ENCODING *enc, michael@0: const char *ptr, michael@0: const char *end, michael@0: const char **badPtr, michael@0: const char **versionPtr, michael@0: const char **versionEndPtr, michael@0: const char **encodingNamePtr, michael@0: const ENCODING **namedEncodingPtr, michael@0: int *standalonePtr); michael@0: michael@0: int XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name); michael@0: const ENCODING *XmlGetUtf8InternalEncoding(void); michael@0: const ENCODING *XmlGetUtf16InternalEncoding(void); michael@0: int FASTCALL XmlUtf8Encode(int charNumber, char *buf); michael@0: int FASTCALL XmlUtf16Encode(int charNumber, unsigned short *buf); michael@0: int XmlSizeOfUnknownEncoding(void); michael@0: michael@0: michael@0: typedef int (XMLCALL *CONVERTER) (void *userData, const char *p); michael@0: michael@0: ENCODING * michael@0: XmlInitUnknownEncoding(void *mem, michael@0: int *table, michael@0: CONVERTER convert, michael@0: void *userData); michael@0: michael@0: int XmlParseXmlDeclNS(int isGeneralTextEntity, michael@0: const ENCODING *enc, michael@0: const char *ptr, michael@0: const char *end, michael@0: const char **badPtr, michael@0: const char **versionPtr, michael@0: const char **versionEndPtr, michael@0: const char **encodingNamePtr, michael@0: const ENCODING **namedEncodingPtr, michael@0: int *standalonePtr); michael@0: michael@0: int XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name); michael@0: const ENCODING *XmlGetUtf8InternalEncodingNS(void); michael@0: const ENCODING *XmlGetUtf16InternalEncodingNS(void); michael@0: ENCODING * michael@0: XmlInitUnknownEncodingNS(void *mem, michael@0: int *table, michael@0: CONVERTER convert, michael@0: void *userData); michael@0: #ifdef __cplusplus michael@0: } michael@0: #endif michael@0: michael@0: #endif /* not XmlTok_INCLUDED */