torcs - 1.2.2

src/libs/txml/xmltok.h

Go to the documentation of this file.
00001 /*
00002 The contents of this file are subject to the Mozilla Public License
00003 Version 1.0 (the "License"); you may not use this file except in
00004 compliance with the License. You may obtain a copy of the License at
00005 http://www.mozilla.org/MPL/
00006 
00007 Software distributed under the License is distributed on an "AS IS"
00008 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
00009 License for the specific language governing rights and limitations
00010 under the License.
00011 
00012 The Original Code is expat.
00013 
00014 The Initial Developer of the Original Code is James Clark.
00015 Portions created by James Clark are Copyright (C) 1998
00016 James Clark. All Rights Reserved.
00017 
00018 Contributor(s):
00019 $Id: xmltok.h,v 1.2 2001/09/15 10:14:27 torcs Exp $
00020 */
00021 
00022 #ifndef XmlTok_INCLUDED
00023 #define XmlTok_INCLUDED 1
00024 
00025 #ifdef __cplusplus
00026 extern "C" {
00027 #endif
00028 
00029 #ifndef XMLTOKAPI
00030 #define XMLTOKAPI /* as nothing */
00031 #endif
00032 
00033 /* The following token may be returned by XmlContentTok */
00034 #define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be start of
00035                                     illegal ]]> sequence */
00036 /* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
00037 #define XML_TOK_NONE -4    /* The string to be scanned is empty */
00038 #define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan;
00039                                   might be part of CRLF sequence */ 
00040 #define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */
00041 #define XML_TOK_PARTIAL -1 /* only part of a token */
00042 #define XML_TOK_INVALID 0
00043 
00044 /* The following tokens are returned by XmlContentTok; some are also
00045   returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok */
00046 
00047 #define XML_TOK_START_TAG_WITH_ATTS 1
00048 #define XML_TOK_START_TAG_NO_ATTS 2
00049 #define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */
00050 #define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4
00051 #define XML_TOK_END_TAG 5
00052 #define XML_TOK_DATA_CHARS 6
00053 #define XML_TOK_DATA_NEWLINE 7
00054 #define XML_TOK_CDATA_SECT_OPEN 8
00055 #define XML_TOK_ENTITY_REF 9
00056 #define XML_TOK_CHAR_REF 10     /* numeric character reference */
00057 
00058 /* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
00059 #define XML_TOK_PI 11      /* processing instruction */
00060 #define XML_TOK_XML_DECL 12 /* XML decl or text decl */
00061 #define XML_TOK_COMMENT 13
00062 #define XML_TOK_BOM 14     /* Byte order mark */
00063 
00064 /* The following tokens are returned only by XmlPrologTok */
00065 #define XML_TOK_PROLOG_S 15
00066 #define XML_TOK_DECL_OPEN 16 /* <!foo */
00067 #define XML_TOK_DECL_CLOSE 17 /* > */
00068 #define XML_TOK_NAME 18
00069 #define XML_TOK_NMTOKEN 19
00070 #define XML_TOK_POUND_NAME 20 /* #name */
00071 #define XML_TOK_OR 21 /* | */
00072 #define XML_TOK_PERCENT 22
00073 #define XML_TOK_OPEN_PAREN 23
00074 #define XML_TOK_CLOSE_PAREN 24
00075 #define XML_TOK_OPEN_BRACKET 25
00076 #define XML_TOK_CLOSE_BRACKET 26
00077 #define XML_TOK_LITERAL 27
00078 #define XML_TOK_PARAM_ENTITY_REF 28
00079 #define XML_TOK_INSTANCE_START 29
00080 
00081 /* The following occur only in element type declarations */
00082 #define XML_TOK_NAME_QUESTION 30 /* name? */
00083 #define XML_TOK_NAME_ASTERISK 31 /* name* */
00084 #define XML_TOK_NAME_PLUS 32 /* name+ */
00085 #define XML_TOK_COND_SECT_OPEN 33 /* <![ */
00086 #define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */
00087 #define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */
00088 #define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */
00089 #define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */
00090 #define XML_TOK_COMMA 38
00091 
00092 /* The following token is returned only by XmlAttributeValueTok */
00093 #define XML_TOK_ATTRIBUTE_VALUE_S 39
00094 
00095 /* The following token is returned only by XmlCdataSectionTok */
00096 #define XML_TOK_CDATA_SECT_CLOSE 40
00097 
00098 #define XML_N_STATES 3
00099 #define XML_PROLOG_STATE 0
00100 #define XML_CONTENT_STATE 1
00101 #define XML_CDATA_SECTION_STATE 2
00102 
00103 #define XML_N_LITERAL_TYPES 2
00104 #define XML_ATTRIBUTE_VALUE_LITERAL 0
00105 #define XML_ENTITY_VALUE_LITERAL 1
00106 
00107 /* The size of the buffer passed to XmlUtf8Encode must be at least this. */
00108 #define XML_UTF8_ENCODE_MAX 4
00109 /* The size of the buffer passed to XmlUtf16Encode must be at least this. */
00110 #define XML_UTF16_ENCODE_MAX 2
00111 
00112 typedef struct position {
00113   /* first line and first column are 0 not 1 */
00114   unsigned long lineNumber;
00115   unsigned long columnNumber;
00116 } POSITION;
00117 
00118 typedef struct {
00119   const char *name;
00120   const char *valuePtr;
00121   const char *valueEnd;
00122   char normalized;
00123 } ATTRIBUTE;
00124 
00125 struct encoding;
00126 typedef struct encoding ENCODING;
00127 
00128 struct encoding {
00129   int (*scanners[XML_N_STATES])(const ENCODING *,
00130                                 const char *,
00131                                 const char *,
00132                                 const char **);
00133   int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
00134                                               const char *,
00135                                               const char *,
00136                                               const char **);
00137   int (*sameName)(const ENCODING *,
00138                   const char *, const char *);
00139   int (*nameMatchesAscii)(const ENCODING *,
00140                           const char *, const char *);
00141   int (*nameLength)(const ENCODING *, const char *);
00142   const char *(*skipS)(const ENCODING *, const char *);
00143   int (*getAtts)(const ENCODING *enc, const char *ptr,
00144                  int attsMax, ATTRIBUTE *atts);
00145   int (*charRefNumber)(const ENCODING *enc, const char *ptr);
00146   int (*predefinedEntityName)(const ENCODING *, const char *, const char *);
00147   void (*updatePosition)(const ENCODING *,
00148                          const char *ptr,
00149                          const char *end,
00150                          POSITION *);
00151   int (*isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
00152                     const char **badPtr);
00153   void (*utf8Convert)(const ENCODING *enc,
00154                       const char **fromP,
00155                       const char *fromLim,
00156                       char **toP,
00157                       const char *toLim);
00158   void (*utf16Convert)(const ENCODING *enc,
00159                        const char **fromP,
00160                        const char *fromLim,
00161                        unsigned short **toP,
00162                        const unsigned short *toLim);
00163   int minBytesPerChar;
00164   char isUtf8;
00165   char isUtf16;
00166 };
00167 
00168 /*
00169 Scan the string starting at ptr until the end of the next complete token,
00170 but do not scan past eptr.  Return an integer giving the type of token.
00171 
00172 Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
00173 
00174 Return XML_TOK_PARTIAL when the string does not contain a complete token;
00175 nextTokPtr will not be set.
00176 
00177 Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr
00178 will be set to point to the character which made the token invalid.
00179 
00180 Otherwise the string starts with a valid token; nextTokPtr will be set to point
00181 to the character following the end of that token.
00182 
00183 Each data character counts as a single token, but adjacent data characters
00184 may be returned together.  Similarly for characters in the prolog outside
00185 literals, comments and processing instructions.
00186 */
00187 
00188 
00189 #define XmlTok(enc, state, ptr, end, nextTokPtr) \
00190   (((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
00191 
00192 #define XmlPrologTok(enc, ptr, end, nextTokPtr) \
00193    XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
00194 
00195 #define XmlContentTok(enc, ptr, end, nextTokPtr) \
00196    XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
00197 
00198 #define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
00199    XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
00200 
00201 /* This is used for performing a 2nd-level tokenization on
00202 the content of a literal that has already been returned by XmlTok. */ 
00203 
00204 #define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
00205   (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
00206 
00207 #define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
00208    XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
00209 
00210 #define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
00211    XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
00212 
00213 #define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
00214 
00215 #define XmlNameMatchesAscii(enc, ptr1, ptr2) \
00216   (((enc)->nameMatchesAscii)(enc, ptr1, ptr2))
00217 
00218 #define XmlNameLength(enc, ptr) \
00219   (((enc)->nameLength)(enc, ptr))
00220 
00221 #define XmlSkipS(enc, ptr) \
00222   (((enc)->skipS)(enc, ptr))
00223 
00224 #define XmlGetAttributes(enc, ptr, attsMax, atts) \
00225   (((enc)->getAtts)(enc, ptr, attsMax, atts))
00226 
00227 #define XmlCharRefNumber(enc, ptr) \
00228   (((enc)->charRefNumber)(enc, ptr))
00229 
00230 #define XmlPredefinedEntityName(enc, ptr, end) \
00231   (((enc)->predefinedEntityName)(enc, ptr, end))
00232 
00233 #define XmlUpdatePosition(enc, ptr, end, pos) \
00234   (((enc)->updatePosition)(enc, ptr, end, pos))
00235 
00236 #define XmlIsPublicId(enc, ptr, end, badPtr) \
00237   (((enc)->isPublicId)(enc, ptr, end, badPtr))
00238 
00239 #define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
00240   (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
00241 
00242 #define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
00243   (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
00244 
00245 typedef struct {
00246   ENCODING initEnc;
00247   const ENCODING **encPtr;
00248 } INIT_ENCODING;
00249 
00250 int XMLTOKAPI XmlParseXmlDecl(int isGeneralTextEntity,
00251                               const ENCODING *enc,
00252                               const char *ptr,
00253                               const char *end,
00254                               const char **badPtr,
00255                               const char **versionPtr,
00256                               const char **encodingNamePtr,
00257                               const ENCODING **namedEncodingPtr,
00258                               int *standalonePtr);
00259 
00260 int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
00261 const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding(void);
00262 const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding(void);
00263 int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf);
00264 int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf);
00265 
00266 int XMLTOKAPI XmlSizeOfUnknownEncoding(void);
00267 ENCODING XMLTOKAPI *
00268 XmlInitUnknownEncoding(void *mem,
00269                        int *table,
00270                        int (*convert)(void *userData, const char *p),
00271                        void *userData);
00272 
00273 #ifdef __cplusplus
00274 }
00275 #endif
00276 
00277 #endif /* not XmlTok_INCLUDED */

Generated at Thu Feb 26 21:52:28 2004 for torcs by doxygen 1.3.3 written by Dimitri van Heesch, © 1997-1999
TORCS © Eric Espié 1999, 2002.