Geant4 Cross Reference |
1 /* 1 2 __ __ 3 ___\ \/ /_ __ __ _| 4 / _ \\ /| '_ \ / _` | 5 | __// \| |_) | (_| | 6 \___/_/\_\ .__/ \__,_| 7 |_| XML parse 8 9 Copyright (c) 1997-2000 Thai Open Source So 10 Copyright (c) 2000 Clark Cooper <coope 11 Copyright (c) 2002 Fred L. Drake, Jr. 12 Copyright (c) 2002-2005 Karl Waclawek <karl 13 Copyright (c) 2016-2017 Sebastian Pipping < 14 Copyright (c) 2017 Rhodri James <rhodr 15 Licensed under the MIT license: 16 17 Permission is hereby granted, free of cha 18 a copy of this software and associat 19 "Software"), to deal in the Software w 20 without limitation the rights to use, c 21 distribute, sublicense, and/or sell copies 22 persons to whom the Software is furnish 23 following conditions: 24 25 The above copyright notice and this permis 26 in all copies or substantial portions of th 27 28 THE SOFTWARE IS PROVIDED "AS IS", WIT 29 EXPRESS OR IMPLIED, INCLUDING BUT NOT L 30 MERCHANTABILITY, FITNESS FOR A PARTICULAR P 31 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HO 32 DAMAGES OR OTHER LIABILITY, WHETHER IN AN 33 OTHERWISE, ARISING FROM, OUT OF OR IN CONNE 34 USE OR OTHER DEALINGS IN THE SOFTWARE. 35 */ 36 37 #ifndef XmlTok_INCLUDED 38 #define XmlTok_INCLUDED 1 39 40 #ifdef __cplusplus 41 extern "C" { 42 #endif 43 44 /* The following token may be returned by XmlC 45 #define XML_TOK_TRAILING_RSQB 46 -5 /* ] or ]] at the end of the scan; might 47 start of illegal ]]> sequence */ 48 /* The following tokens may be returned by bot 49 XmlContentTok. 50 */ 51 #define XML_TOK_NONE -4 /* The string to be sc 52 #define XML_TOK_TRAILING_CR 53 -3 /* A CR at the 54 might be pa 55 #define XML_TOK_PARTIAL_CHAR -2 /* only part o 56 #define XML_TOK_PARTIAL -1 /* only part o 57 #define XML_TOK_INVALID 0 58 59 /* The following tokens are returned by XmlCon 60 returned by XmlAttributeValueTok, XmlEntity 61 */ 62 #define XML_TOK_START_TAG_WITH_ATTS 1 63 #define XML_TOK_START_TAG_NO_ATTS 2 64 #define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* e 65 #define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4 66 #define XML_TOK_END_TAG 5 67 #define XML_TOK_DATA_CHARS 6 68 #define XML_TOK_DATA_NEWLINE 7 69 #define XML_TOK_CDATA_SECT_OPEN 8 70 #define XML_TOK_ENTITY_REF 9 71 #define XML_TOK_CHAR_REF 10 /* numeric charact 72 73 /* The following tokens may be returned by bot 74 XmlContentTok. 75 */ 76 #define XML_TOK_PI 11 /* processing inst 77 #define XML_TOK_XML_DECL 12 /* XML decl or tex 78 #define XML_TOK_COMMENT 13 79 #define XML_TOK_BOM 14 /* Byte order mark */ 80 81 /* The following tokens are returned only by X 82 #define XML_TOK_PROLOG_S 15 83 #define XML_TOK_DECL_OPEN 16 /* <!foo */ 84 #define XML_TOK_DECL_CLOSE 17 /* > */ 85 #define XML_TOK_NAME 18 86 #define XML_TOK_NMTOKEN 19 87 #define XML_TOK_POUND_NAME 20 /* #name */ 88 #define XML_TOK_OR 21 /* | */ 89 #define XML_TOK_PERCENT 22 90 #define XML_TOK_OPEN_PAREN 23 91 #define XML_TOK_CLOSE_PAREN 24 92 #define XML_TOK_OPEN_BRACKET 25 93 #define XML_TOK_CLOSE_BRACKET 26 94 #define XML_TOK_LITERAL 27 95 #define XML_TOK_PARAM_ENTITY_REF 28 96 #define XML_TOK_INSTANCE_START 29 97 98 /* The following occur only in element type de 99 #define XML_TOK_NAME_QUESTION 30 /* nam 100 #define XML_TOK_NAME_ASTERISK 31 /* nam 101 #define XML_TOK_NAME_PLUS 32 /* nam 102 #define XML_TOK_COND_SECT_OPEN 33 /* <![ 103 #define XML_TOK_COND_SECT_CLOSE 34 /* ]]> 104 #define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? 105 #define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* 106 #define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ 107 #define XML_TOK_COMMA 38 108 109 /* The following token is returned only by Xml 110 #define XML_TOK_ATTRIBUTE_VALUE_S 39 111 112 /* The following token is returned only by Xml 113 #define XML_TOK_CDATA_SECT_CLOSE 40 114 115 /* With namespace processing this is returned 116 name with a colon. 117 */ 118 #define XML_TOK_PREFIXED_NAME 41 119 120 #ifdef XML_DTD 121 # define XML_TOK_IGNORE_SECT 42 122 #endif /* XML_DTD */ 123 124 #ifdef XML_DTD 125 # define XML_N_STATES 4 126 #else /* not XML_DTD */ 127 # define XML_N_STATES 3 128 #endif /* not XML_DTD */ 129 130 #define XML_PROLOG_STATE 0 131 #define XML_CONTENT_STATE 1 132 #define XML_CDATA_SECTION_STATE 2 133 #ifdef XML_DTD 134 # define XML_IGNORE_SECTION_STATE 3 135 #endif /* XML_DTD */ 136 137 #define XML_N_LITERAL_TYPES 2 138 #define XML_ATTRIBUTE_VALUE_LITERAL 0 139 #define XML_ENTITY_VALUE_LITERAL 1 140 141 /* The size of the buffer passed to XmlUtf8Enc 142 #define XML_UTF8_ENCODE_MAX 4 143 /* The size of the buffer passed to XmlUtf16En 144 #define XML_UTF16_ENCODE_MAX 2 145 146 typedef struct position { 147 /* first line and first column are 0 not 1 * 148 XML_Size lineNumber; 149 XML_Size columnNumber; 150 } POSITION; 151 152 typedef struct { 153 const char *name; 154 const char *valuePtr; 155 const char *valueEnd; 156 char normalized; 157 } ATTRIBUTE; 158 159 struct encoding; 160 typedef struct encoding ENCODING; 161 162 typedef int(PTRCALL *SCANNER)(const ENCODING * 163 const char **); 164 165 enum XML_Convert_Result { 166 XML_CONVERT_COMPLETED = 0, 167 XML_CONVERT_INPUT_INCOMPLETE = 1, 168 XML_CONVERT_OUTPUT_EXHAUSTED 169 = 2 /* and therefore potentially input remai 170 }; 171 172 struct encoding { 173 SCANNER scanners[XML_N_STATES]; 174 SCANNER literalScanners[XML_N_LITERAL_TYPES] 175 int(PTRCALL *nameMatchesAscii)(const ENCODIN 176 const char *) 177 int(PTRFASTCALL *nameLength)(const ENCODING 178 const char *(PTRFASTCALL *skipS)(const ENCOD 179 int(PTRCALL *getAtts)(const ENCODING *enc, c 180 ATTRIBUTE *atts); 181 int(PTRFASTCALL *charRefNumber)(const ENCODI 182 int(PTRCALL *predefinedEntityName)(const ENC 183 const cha 184 void(PTRCALL *updatePosition)(const ENCODING 185 const char *en 186 int(PTRCALL *isPublicId)(const ENCODING *enc 187 const char *end, co 188 enum XML_Convert_Result(PTRCALL *utf8Convert 189 190 191 192 enum XML_Convert_Result(PTRCALL *utf16Conver 193 194 195 196 197 int minBytesPerChar; 198 char isUtf8; 199 char isUtf16; 200 }; 201 202 /* Scan the string starting at ptr until the e 203 token, but do not scan past eptr. Return a 204 type of token. 205 206 Return XML_TOK_NONE when ptr == eptr; nextT 207 208 Return XML_TOK_PARTIAL when the string does 209 token; nextTokPtr will not be set. 210 211 Return XML_TOK_INVALID when the string does 212 token; nextTokPtr will be set to point to t 213 the token invalid. 214 215 Otherwise the string starts with a valid to 216 set to point to the character following the 217 218 Each data character counts as a single toke 219 characters may be returned together. Simil 220 the prolog outside literals, comments and p 221 */ 222 223 #define XmlTok(enc, state, ptr, end, nextTokPt 224 (((enc)->scanners[state])(enc, ptr, end, nex 225 226 #define XmlPrologTok(enc, ptr, end, nextTokPtr 227 XmlTok(enc, XML_PROLOG_STATE, ptr, end, next 228 229 #define XmlContentTok(enc, ptr, end, nextTokPt 230 XmlTok(enc, XML_CONTENT_STATE, ptr, end, nex 231 232 #define XmlCdataSectionTok(enc, ptr, end, next 233 XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, en 234 235 #ifdef XML_DTD 236 237 # define XmlIgnoreSectionTok(enc, ptr, end, n 238 XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, 239 240 #endif /* XML_DTD */ 241 242 /* This is used for performing a 2nd-level tok 243 of a literal that has already been returned 244 */ 245 #define XmlLiteralTok(enc, literalType, ptr, e 246 (((enc)->literalScanners[literalType])(enc, 247 248 #define XmlAttributeValueTok(enc, ptr, end, ne 249 XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITER 250 251 #define XmlEntityValueTok(enc, ptr, end, nextT 252 XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, 253 254 #define XmlNameMatchesAscii(enc, ptr1, end1, p 255 (((enc)->nameMatchesAscii)(enc, ptr1, end1, 256 257 #define XmlNameLength(enc, ptr) (((enc)->nameL 258 259 #define XmlSkipS(enc, ptr) (((enc)->skipS)(enc 260 261 #define XmlGetAttributes(enc, ptr, attsMax, at 262 (((enc)->getAtts)(enc, ptr, attsMax, atts)) 263 264 #define XmlCharRefNumber(enc, ptr) (((enc)->ch 265 266 #define XmlPredefinedEntityName(enc, ptr, end) 267 (((enc)->predefinedEntityName)(enc, ptr, end 268 269 #define XmlUpdatePosition(enc, ptr, end, pos) 270 (((enc)->updatePosition)(enc, ptr, end, pos) 271 272 #define XmlIsPublicId(enc, ptr, end, badPtr) 273 (((enc)->isPublicId)(enc, ptr, end, badPtr)) 274 275 #define XmlUtf8Convert(enc, fromP, fromLim, to 276 (((enc)->utf8Convert)(enc, fromP, fromLim, t 277 278 #define XmlUtf16Convert(enc, fromP, fromLim, t 279 (((enc)->utf16Convert)(enc, fromP, fromLim, 280 281 typedef struct { 282 ENCODING initEnc; 283 const ENCODING **encPtr; 284 } INIT_ENCODING; 285 286 int XmlParseXmlDecl(int isGeneralTextEntity, c 287 const char *ptr, const cha 288 const char **versionPtr, c 289 const char **encodingNameP 290 const ENCODING **namedEnco 291 292 int XmlInitEncoding(INIT_ENCODING *, const ENC 293 const ENCODING *XmlGetUtf8InternalEncoding(voi 294 const ENCODING *XmlGetUtf16InternalEncoding(vo 295 int FASTCALL XmlUtf8Encode(int charNumber, cha 296 int FASTCALL XmlUtf16Encode(int charNumber, un 297 int XmlSizeOfUnknownEncoding(void); 298 299 typedef int(XMLCALL *CONVERTER)(void *userData 300 301 ENCODING *XmlInitUnknownEncoding(void *mem, in 302 void *userDat 303 304 int XmlParseXmlDeclNS(int isGeneralTextEntity, 305 const char *ptr, const c 306 const char **versionPtr, 307 const char **encodingNam 308 const ENCODING **namedEn 309 310 int XmlInitEncodingNS(INIT_ENCODING *, const E 311 const ENCODING *XmlGetUtf8InternalEncodingNS(v 312 const ENCODING *XmlGetUtf16InternalEncodingNS( 313 ENCODING *XmlInitUnknownEncodingNS(void *mem, 314 void *userD 315 #ifdef __cplusplus 316 } 317 #endif 318 319 #endif /* not XmlTok_INCLUDED */ 320