Changeset 97 for trunk/src/helpers/xmlparse.c
- Timestamp:
- Aug 12, 2001, 5:34:51 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/xmlparse.c
r75 r97 2 2 /* 3 3 *@@sourcefile xmlparse.c: 4 * contains the API of the expat XML parser 1.95.1, as released on 5 * SourceForge Oct 22, 2000. 6 * 7 * This was ported to and integrated with the xwphelpers 8 * for V0.9.9 (2001-02-10) [umoeller]. See xml.c for a general 9 * introduction to @XML support in the xwphelpers. 4 * contains the API of the expat XML parser 1.95.2, as released on 5 * http://sourceforge.net/projects/expat/ on July 26, 2001. 6 * 7 * V1.95.1 was ported to and integrated with the xwphelpers 8 * for V0.9.9 (2001-02-10) [umoeller]. V1.95.2 was re-ported 9 * with V0.9.14 (2001-08-09) [umoeller]. 10 * 11 * See xml.c for a general introduction to @XML support in the 12 * xwphelpers. 10 13 * 11 14 * Expat is a library, written in C, for parsing XML @documents. It's … … 70 73 // this code generates those options HEAVILY 71 74 72 // #include <config.h> 75 76 /* #ifdef COMPILED_FROM_DSP 77 * # include "winconfig.h" 78 * # define XMLPARSEAPI(type) __declspec(dllexport) type __cdecl 79 * # include "expat.h" 80 * # undef XMLPARSEAPI 81 * #else 82 * #include <config.h> */ 73 83 74 84 #ifdef __declspec 75 #define XMLPARSEAPI __declspec(dllexport)85 #define XMLPARSEAPI(type) __declspec(dllexport) type __cdecl 76 86 #endif 77 87 … … 79 89 80 90 #ifdef __declspec 81 91 #undef XMLPARSEAPI 82 92 #endif 93 // #endif /* ndef COMPILED_FROM_DSP */ 83 94 84 95 #include <stddef.h> … … 86 97 87 98 #ifdef XML_UNICODE 88 #define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX 89 #define XmlConvert XmlUtf16Convert 90 #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding 91 #define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS 92 #define XmlEncode XmlUtf16Encode 93 #define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1)) 94 typedef unsigned short ICHAR; 99 #define XML_ENCODE_MAX XML_UTF16_ENCODE_MAX 100 #define XmlConvert XmlUtf16Convert 101 #define XmlGetInternalEncoding XmlGetUtf16InternalEncoding 102 #define XmlGetInternalEncodingNS XmlGetUtf16InternalEncodingNS 103 #define XmlEncode XmlUtf16Encode 104 #define MUST_CONVERT(enc, s) (!(enc)->isUtf16 || (((unsigned long)s) & 1)) 105 typedef unsigned short ICHAR; 106 95 107 #else 96 #define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX 97 #define XmlConvert XmlUtf8Convert 98 #define XmlGetInternalEncoding XmlGetUtf8InternalEncoding 99 #define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS 100 #define XmlEncode XmlUtf8Encode 101 #define MUST_CONVERT(enc, s) (!(enc)->isUtf8) 102 typedef char ICHAR; 108 #define XML_ENCODE_MAX XML_UTF8_ENCODE_MAX 109 #define XmlConvert XmlUtf8Convert 110 #define XmlGetInternalEncoding XmlGetUtf8InternalEncoding 111 #define XmlGetInternalEncodingNS XmlGetUtf8InternalEncodingNS 112 #define XmlEncode XmlUtf8Encode 113 #define MUST_CONVERT(enc, s) (!(enc)->isUtf8) 114 typedef char ICHAR; 115 103 116 #endif 104 117 118 105 119 #ifndef XML_NS 106 #define XmlInitEncodingNS XmlInitEncoding 107 #define XmlInitUnknownEncodingNS XmlInitUnknownEncoding 108 #undef XmlGetInternalEncodingNS 109 #define XmlGetInternalEncodingNS XmlGetInternalEncoding 110 #define XmlParseXmlDeclNS XmlParseXmlDecl 120 121 #define XmlInitEncodingNS XmlInitEncoding 122 #define XmlInitUnknownEncodingNS XmlInitUnknownEncoding 123 #undef XmlGetInternalEncodingNS 124 #define XmlGetInternalEncodingNS XmlGetInternalEncoding 125 #define XmlParseXmlDeclNS XmlParseXmlDecl 126 111 127 #endif 112 128 113 129 #ifdef XML_UNICODE_WCHAR_T 114 130 #define XML_T(x) L ## x 115 131 #else 116 132 #define XML_T(x) x 117 133 #endif 118 134 … … 125 141 typedef const XML_Char *KEY; 126 142 127 typedef struct _NAMED143 typedef struct 128 144 { 129 145 KEY name; 130 } NAMED, *PNAMED; 131 132 typedef struct _HASH_TABLE 146 } 147 NAMED; 148 149 typedef struct 133 150 { 134 151 NAMED **v; … … 137 154 size_t usedLim; 138 155 XML_Memory_Handling_Suite *mem; 139 } HASH_TABLE, *PHASH_TABLE; 140 141 typedef struct _HASH_TABLE_ITER 156 } 157 HASH_TABLE; 158 159 typedef struct 142 160 { 143 161 NAMED **p; 144 162 NAMED **end; 145 } HASH_TABLE_ITER, *PHASH_TABLE_ITER; 163 } 164 HASH_TABLE_ITER; 146 165 147 166 #define INIT_TAG_BUF_SIZE 32 /* must be a multiple of sizeof(XML_Char) */ … … 155 174 typedef struct binding 156 175 { 157 struct prefix *prefix; 158 struct binding *nextTagBinding; 159 struct binding *prevPrefixBinding; 160 const struct attribute_id *attId; 161 XML_Char *uri; 162 int uriLen; 163 int uriAlloc; 164 } BINDING, *PBINDING; 176 struct prefix *prefix; 177 struct binding *nextTagBinding; 178 struct binding *prevPrefixBinding; 179 const struct attribute_id *attId; 180 XML_Char *uri; 181 int uriLen; 182 int uriAlloc; 183 } 184 BINDING; 165 185 166 186 typedef struct prefix 167 187 { 168 const XML_Char *name; 169 BINDING *binding; 170 } PREFIX, *PPREFIX; 188 const XML_Char *name; 189 BINDING *binding; 190 } 191 PREFIX; 171 192 172 193 typedef struct 173 194 { 174 const XML_Char 175 const XML_Char 195 const XML_Char *str; 196 const XML_Char *localPart; 176 197 int uriLen; 177 } TAG_NAME, *PTAG_NAME; 198 } 199 TAG_NAME; 178 200 179 201 typedef struct tag 180 202 { 181 struct tag *parent; 182 const char *rawName; 183 int rawNameLength; 184 TAG_NAME name; 185 char *buf; 186 char *bufEnd; 187 BINDING *bindings; 188 } TAG, *PTAG; 203 struct tag *parent; 204 const char *rawName; 205 int rawNameLength; 206 TAG_NAME name; 207 char *buf; 208 char *bufEnd; 209 BINDING *bindings; 210 } 211 TAG; 189 212 190 213 typedef struct 191 214 { 192 const XML_Char 193 const XML_Char 194 int 195 const XML_Char 196 const XML_Char 197 const XML_Char 198 const XML_Char 215 const XML_Char *name; 216 const XML_Char *textPtr; 217 int textLen; 218 const XML_Char *systemId; 219 const XML_Char *base; 220 const XML_Char *publicId; 221 const XML_Char *notation; 199 222 char open; 200 223 char is_param; 201 } ENTITY, *PENTITY; 224 } 225 ENTITY; 202 226 203 227 typedef struct 204 228 { 205 enum XML_Content_Type type; 206 enum XML_Content_Quant quant; 207 const XML_Char *name; 208 int firstchild; 209 int lastchild; 210 int childcnt; 211 int nextsib; 212 } CONTENT_SCAFFOLD, *PCONTENT_SCAFFOLD; 229 enum XML_Content_Type type; 230 enum XML_Content_Quant quant; 231 const XML_Char *name; 232 int firstchild; 233 int lastchild; 234 int childcnt; 235 int nextsib; 236 } 237 CONTENT_SCAFFOLD; 213 238 214 239 typedef struct block … … 217 242 int size; 218 243 XML_Char s[1]; 219 } BLOCK, *PBLOCK; 244 } 245 BLOCK; 220 246 221 247 typedef struct … … 227 253 XML_Char *start; 228 254 XML_Memory_Handling_Suite *mem; 229 } STRING_POOL, *PSTRING_POOL; 255 } 256 STRING_POOL; 230 257 231 258 /* The XML_Char before the name is used to determine whether … … 237 264 char maybeTokenized; 238 265 char xmlns; 239 } ATTRIBUTE_ID, *PATTRIBUTE_ID; 266 } 267 ATTRIBUTE_ID; 240 268 241 269 typedef struct … … 244 272 char isCdata; 245 273 const XML_Char *value; 246 } DEFAULT_ATTRIBUTE, *PDEFAULT_ATTRIBUTE; 274 } 275 DEFAULT_ATTRIBUTE; 247 276 248 277 typedef struct … … 254 283 int allocDefaultAtts; 255 284 DEFAULT_ATTRIBUTE *defaultAtts; 256 } ELEMENT_TYPE, *PELEMENT_TYPE; 285 } 286 ELEMENT_TYPE; 257 287 258 288 typedef struct … … 277 307 int scaffLevel; 278 308 int *scaffIndex; 279 } DTD, *PDTD; 309 } 310 DTD; 280 311 281 312 typedef struct open_internal_entity … … 285 316 struct open_internal_entity *next; 286 317 ENTITY *entity; 287 } OPEN_INTERNAL_ENTITY, *POPEN_INTERNAL_ENTITY; 318 } 319 OPEN_INTERNAL_ENTITY; 288 320 289 321 typedef XMLERROR Processor(XML_Parser parser, 290 291 292 322 const char *start, 323 const char *end, 324 const char **endPtr); 293 325 294 326 static Processor prologProcessor; … … 299 331 #ifdef XML_DTD 300 332 static Processor ignoreSectionProcessor; 333 301 334 #endif /* XML_DTD */ 302 303 335 static Processor epilogProcessor; 304 336 static Processor errorProcessor; … … 308 340 static Processor externalEntityContentProcessor; 309 341 310 static XMLERROR handleUnknownEncoding(XML_Parser parser, 311 const XML_Char * encodingName); 312 static XMLERROR processXmlDecl(XML_Parser parser, 313 int isGeneralTextEntity, 314 const char *, 315 const char *); 316 static XMLERROR initializeEncoding(XML_Parser parser); 317 static XMLERROR doProlog(XML_Parser parser, 318 const ENCODING * enc, 319 const char *s, 320 const char *end, 321 int tok, 322 const char *next, 323 const char **nextPtr); 324 static XMLERROR processInternalParamEntity(XML_Parser parser, 325 ENTITY * entity); 326 static XMLERROR doContent(XML_Parser parser, 327 int startTagLevel, 328 const ENCODING * enc, 329 const char *start, 330 const char *end, 331 const char **endPtr); 332 static XMLERROR doCdataSection(XML_Parser parser, 333 const ENCODING *, 334 const char **startPtr, 335 const char *end, 336 const char **nextPtr); 342 static XMLERROR 343 handleUnknownEncoding(XML_Parser parser, const XML_Char * encodingName); 344 static XMLERROR 345 processXmlDecl(XML_Parser parser, int isGeneralTextEntity, const char *, const char *); 346 static XMLERROR 347 initializeEncoding(XML_Parser parser); 348 static XMLERROR 349 doProlog(XML_Parser parser, const ENCODING * enc, const char *s, 350 const char *end, int tok, const char *next, const char **nextPtr); 351 static XMLERROR 352 processInternalParamEntity(XML_Parser parser, ENTITY * entity); 353 static XMLERROR 354 doContent(XML_Parser parser, int startTagLevel, const ENCODING * enc, 355 const char *start, const char *end, const char **endPtr); 356 static XMLERROR 357 doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, const char *end, const char **nextPtr); 337 358 338 359 #ifdef XML_DTD 339 static XMLERROR doIgnoreSection(XML_Parser parser, 340 const ENCODING *, 341 const char **startPtr, 342 const char *end, 343 const char **nextPtr); 360 static XMLERROR 361 doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, const char *end, const char **nextPtr); 362 344 363 #endif /* XML_DTD */ 345 346 static XMLERROR storeAtts(XML_Parser parser, 347 const ENCODING *, 348 const char *s, 349 TAG_NAME * tagNamePtr, 350 BINDING ** bindingsPtr); 351 static int addBinding(XML_Parser parser, 352 PREFIX * prefix, 353 const ATTRIBUTE_ID * attId, 354 const XML_Char * uri, 355 BINDING ** bindingsPtr); 356 357 static int defineAttribute(ELEMENT_TYPE * type, 358 ATTRIBUTE_ID *, 359 int isCdata, 360 int isId, 361 const XML_Char * dfltValue, 362 XML_Parser parser); 363 364 static XMLERROR storeAttributeValue(XML_Parser parser, 365 const ENCODING *, 366 int isCdata, 367 const char *, 368 const char *, 369 STRING_POOL *); 370 static XMLERROR appendAttributeValue(XML_Parser parser, 371 const ENCODING *, 372 int isCdata, 373 const char *, 374 const char *, 375 STRING_POOL *); 376 static ATTRIBUTE_ID * getAttributeId(XML_Parser parser, 377 const ENCODING * enc, 378 const char *start, 379 const char *end); 364 static XMLERROR storeAtts(XML_Parser parser, const ENCODING *, const char *s, 365 TAG_NAME * tagNamePtr, BINDING ** bindingsPtr); 366 static 367 int addBinding(XML_Parser parser, PREFIX * prefix, const ATTRIBUTE_ID * attId, const XML_Char * uri, BINDING ** bindingsPtr); 368 369 static int 370 defineAttribute(ELEMENT_TYPE * type, ATTRIBUTE_ID *, 371 int isCdata, int isId, const XML_Char * dfltValue, 372 XML_Parser parser); 373 374 static XMLERROR 375 storeAttributeValue(XML_Parser parser, const ENCODING *, int isCdata, const char *, const char *, 376 STRING_POOL *); 377 static XMLERROR 378 appendAttributeValue(XML_Parser parser, const ENCODING *, int isCdata, const char *, const char *, 379 STRING_POOL *); 380 static ATTRIBUTE_ID * 381 getAttributeId(XML_Parser parser, const ENCODING * enc, const char *start, const char *end); 380 382 static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); 381 static XMLERROR storeEntityValue(XML_Parser parser, 382 const ENCODING * enc, 383 const char *start, 384 const char *end); 385 static int reportProcessingInstruction(XML_Parser parser, 386 const ENCODING * enc, 387 const char *start, 388 const char *end); 389 static int reportComment(XML_Parser parser, 390 const ENCODING * enc, 391 const char *start, 392 const char *end); 393 static void reportDefault(XML_Parser parser, 394 const ENCODING * enc, 395 const char *start, 396 const char *end); 383 static XMLERROR 384 storeEntityValue(XML_Parser parser, const ENCODING * enc, const char *start, const char *end); 385 static int 386 reportProcessingInstruction(XML_Parser parser, const ENCODING * enc, const char *start, const char *end); 387 static int 388 reportComment(XML_Parser parser, const ENCODING * enc, const char *start, const char *end); 389 static void 390 reportDefault(XML_Parser parser, const ENCODING * enc, const char *start, const char *end); 397 391 398 392 static const XML_Char *getContext(XML_Parser parser); … … 405 399 static int dtdCopy(DTD * newDtd, const DTD * oldDtd, XML_Parser parser); 406 400 407 static int copyEntityTable(HASH_TABLE *, 408 STRING_POOL *, 409 const HASH_TABLE *, 401 static int copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *, 410 402 XML_Parser parser); 411 403 412 404 #ifdef XML_DTD 413 405 static void dtdSwap(DTD *, DTD *); 406 414 407 #endif /* XML_DTD */ 415 408 … … 424 417 static void poolClear(STRING_POOL *); 425 418 static void poolDestroy(STRING_POOL *); 426 static XML_Char *poolAppend(STRING_POOL * pool, const ENCODING * enc, 427 const char *ptr, const char *end); 428 static XML_Char *poolStoreString(STRING_POOL * pool, const ENCODING * enc, 429 const char *ptr, const char *end); 419 static XML_Char *poolAppend(STRING_POOL *pool, 420 const ENCODING *enc, 421 const char *ptr, 422 const char *end, 423 unsigned long *pulOfs); // V0.9.14 (2001-08-09) [umoeller] 424 static XML_Char *poolStoreString(STRING_POOL *pool, 425 const ENCODING *enc, 426 const char *ptr, 427 const char *end, 428 unsigned long *pulOfs); // V0.9.14 (2001-08-09) [umoeller] 430 429 431 430 static int poolGrow(STRING_POOL * pool); … … 502 501 void *m_unknownEncodingData; 503 502 void *m_unknownEncodingHandlerData; 504 void (* EXPATENTRYm_unknownEncodingRelease) (void *);503 void (*m_unknownEncodingRelease) (void *); 505 504 PROLOG_STATE m_prologState; 506 505 Processor *m_processor; … … 544 543 XML_Parser m_parentParser; 545 544 #endif 546 } Parser, *PParser; 545 } 546 Parser; 547 547 548 548 #define MALLOC(s) (((Parser *)parser)->m_mem.malloc_fcn((s))) … … 569 569 #define externalEntityRefHandler (((Parser *)parser)->m_externalEntityRefHandler) 570 570 #define externalEntityRefHandlerArg (((Parser *)parser)->m_externalEntityRefHandlerArg) 571 #define internalEntityRefHandler (((Parser *)parser)->m_internalEntityRefHandler) 571 572 #define unknownEncodingHandler (((Parser *)parser)->m_unknownEncodingHandler) 572 573 #define elementDeclHandler (((Parser *)parser)->m_elementDeclHandler) … … 579 580 #define unknownEncodingMem (((Parser *)parser)->m_unknownEncodingMem) 580 581 #define unknownEncodingData (((Parser *)parser)->m_unknownEncodingData) 581 #define unknownEncodingHandlerData (((Parser *)parser)->m_unknownEncodingHandlerData) 582 #define unknownEncodingRelease (((Parser*)parser)->m_unknownEncodingRelease) 582 #define unknownEncodingHandlerData \ 583 (((Parser *)parser)->m_unknownEncodingHandlerData) 584 #define unknownEncodingRelease (((Parser *)parser)->m_unknownEncodingRelease) 583 585 #define protocolEncodingName (((Parser *)parser)->m_protocolEncodingName) 584 586 #define ns (((Parser *)parser)->m_ns) … … 594 596 #define defaultExpandInternalEntities (((Parser *)parser)->m_defaultExpandInternalEntities) 595 597 #define tagLevel (((Parser *)parser)->m_tagLevel) 596 #define buffer (((Parser *)parser)->m_buffer)598 #define buffer (((Parser *)parser)->m_buffer) 597 599 #define bufferPtr (((Parser *)parser)->m_bufferPtr) 598 600 #define bufferEnd (((Parser *)parser)->m_bufferEnd) … … 634 636 #endif /* XML_DTD */ 635 637 638 #ifdef COMPILED_FROM_DSP 639 BOOL WINAPI DllMain(HINSTANCE h, DWORD r, LPVOID p) 640 { 641 return TRUE; 642 } 643 #endif /* def COMPILED_FROM_DSP */ 644 645 #ifdef _MSC_VER 646 #ifdef _DEBUG 647 Parser *asParser(XML_Parser parser) 648 { 649 return parser; 650 } 651 #endif 652 #endif 653 636 654 /* 637 655 *@@ XML_ParserCreate: … … 748 766 */ 749 767 750 XML_Parser XML_ParserCreate(const XML_Char * encodingName)768 XML_Parser XML_ParserCreate(const XML_Char * encodingName) 751 769 { 752 770 return XML_ParserCreate_MM(encodingName, NULL, NULL); … … 830 848 */ 831 849 832 XML_Parser XML_ParserCreate_MM(const XML_Char * encodingName, 833 const XML_Memory_Handling_Suite * memsuite, 834 const XML_Char * nameSep) 850 XML_Parser 851 XML_ParserCreate_MM(const XML_Char * encodingName, 852 const XML_Memory_Handling_Suite * memsuite, 853 const XML_Char * nameSep) 835 854 { 836 855 … … 857 876 858 877 parser = memsuite->malloc_fcn(sizeof(Parser)); 859 mtemp = &(((Parser *)parser)->m_mem);878 mtemp = &(((Parser *) parser)->m_mem); 860 879 mtemp->malloc_fcn = memsuite->malloc_fcn; 861 880 mtemp->realloc_fcn = memsuite->realloc_fcn; … … 866 885 XML_Memory_Handling_Suite *mtemp; 867 886 868 parser = (malloc)(sizeof(Parser)); 869 mtemp = &(((Parser*)parser)->m_mem); 870 887 parser = malloc(sizeof(Parser)); 888 mtemp = &(((Parser *) parser)->m_mem); 871 889 mtemp->malloc_fcn = malloc; 872 890 mtemp->realloc_fcn = realloc; … … 929 947 inheritedBindings = 0; 930 948 attsSize = INIT_ATTS_SIZE; 931 atts = (PATTRIBUTE)MALLOC(attsSize * sizeof(ATTRIBUTE));949 atts = MALLOC(attsSize * sizeof(ATTRIBUTE)); 932 950 nSpecifiedAtts = 0; 933 dataBuf = (XML_Char*)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));951 dataBuf = MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char)); 934 952 groupSize = 0; 935 953 groupConnector = 0; … … 946 964 ns = 0; 947 965 ns_triplets = 0; 948 poolInit(&tempPool, &(((Parser *)parser)->m_mem));949 poolInit(&temp2Pool, &(((Parser *)parser)->m_mem));966 poolInit(&tempPool, &(((Parser *) parser)->m_mem)); 967 poolInit(&temp2Pool, &(((Parser *) parser)->m_mem)); 950 968 protocolEncodingName = encodingName ? poolCopyString(&tempPool, encodingName) : 0; 951 969 curBase = 0; … … 1047 1065 1048 1066 #ifdef XML_DTD 1049 enum XML_ParamEntityParsingoldParamEntityParsing = paramEntityParsing;1067 int oldParamEntityParsing = paramEntityParsing; 1050 1068 1051 1069 #endif … … 1057 1075 1058 1076 *tmp = namespaceSeparator; 1059 parser = XML_ParserCreate_MM(encodingName, &((Parser *)parser)->m_mem,1077 parser = XML_ParserCreate_MM(encodingName, &((Parser *) parser)->m_mem, 1060 1078 tmp); 1061 1079 } 1062 1080 else 1063 1081 { 1064 parser = XML_ParserCreate_MM(encodingName, &((Parser *)parser)->m_mem,1082 parser = XML_ParserCreate_MM(encodingName, &((Parser *) parser)->m_mem, 1065 1083 NULL); 1066 1084 } … … 1123 1141 } 1124 1142 1125 static void destroyBindings(BINDING * bindings, XML_Parser parser) 1143 static 1144 void destroyBindings(BINDING * bindings, XML_Parser parser) 1126 1145 { 1127 1146 for (;;) … … 1172 1191 if (hadExternalDoctype) 1173 1192 dtd.complete = 0; 1174 dtdSwap(&dtd, &((Parser *)parentParser)->m_dtd);1193 dtdSwap(&dtd, &((Parser *) parentParser)->m_dtd); 1175 1194 } 1176 1195 #endif /* XML_DTD */ … … 1275 1294 */ 1276 1295 1277 const XML_Char *XML_GetBase(XML_Parser parser)1296 const XML_Char *XML_GetBase(XML_Parser parser) 1278 1297 { 1279 1298 return curBase; … … 1433 1452 1434 1453 void XML_SetProcessingInstructionHandler(XML_Parser parser, 1435 1454 XML_ProcessingInstructionHandler handler) 1436 1455 { 1437 1456 processingInstructionHandler = handler; … … 1741 1760 * Handler prototype: 1742 1761 + 1743 + int EXPATENTRY ExternalEntityRefHandler(XML_Parser parser, 1762 + int EXPATENTRY ExternalEntityRefHandler(void *pUser, 1763 + XML_Parser parser, 1744 1764 + const XML_Char *pcszContext, 1745 1765 + const XML_Char *pcszBase, … … 1787 1807 * external entities may refer to other external entities, your 1788 1808 * handler should be prepared to be called recursively. 1809 * 1810 *@@changed V0.9.14 (2001-08-09) [umoeller]: changed prototype to contain user data 1789 1811 */ 1790 1812 … … 1841 1863 * 1842 1864 * See _XML_Encoding for more details about that structure and 1843 * what to do with it. 1844 * 1845 * Expat places restrictions on character encodings that it can 1846 * support by filling in the XML_Encoding structure. 1847 * 1848 * 1. Every ASCII character that can appear in a well-formed XML 1849 * document must be represented by a single byte, and that byte 1850 * must correspond to its ASCII encoding (except for the 1851 * characters $@\^'{}~). 1852 * 1853 * 2. Characters must be encoded in 4 bytes or less. 1854 * 1855 * 3. All characters encoded must have Unicode scalar values less 1856 * than or equal to 65535 (0xFFFF). (This does not apply to 1857 * the built-in support for UTF-16 and UTF-8.) 1858 * 1859 * 4. No character may be encoded by more than one distinct 1860 * sequence of bytes. 1865 * what to do with it, and restrictions imposed by expat. 1866 * 1861 1867 */ 1862 1868 … … 2073 2079 */ 2074 2080 2075 int XML_Parse(XML_Parser parser, 2076 const char *s, 2077 int len, 2078 int isFinal) 2081 int XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) 2079 2082 { 2080 2083 if (len == 0) … … 2083 2086 return 1; 2084 2087 positionPtr = bufferPtr; 2085 errorCode = processor(parser, 2086 bufferPtr, 2087 parseEndPtr = bufferEnd, 2088 0); 2088 errorCode = processor(parser, bufferPtr, parseEndPtr = bufferEnd, 0); 2089 2089 if (errorCode == ERROR_EXPAT_NONE) 2090 2090 return 1; … … 2103 2103 if (isFinal) 2104 2104 { 2105 errorCode = processor(parser, 2106 s, 2107 parseEndPtr = s + len, 2108 0); 2105 errorCode = processor(parser, s, parseEndPtr = s + len, 0); 2109 2106 if (errorCode == ERROR_EXPAT_NONE) 2110 2107 return 1; … … 2127 2124 { 2128 2125 /* FIXME avoid integer overflow */ 2129 buffer = buffer == 0 ? (char*)MALLOC(len * 2) : (char*)REALLOC(buffer, len * 2);2126 buffer = buffer == 0 ? MALLOC(len * 2) : REALLOC(buffer, len * 2); 2130 2127 /* FIXME storage leak if realloc fails */ 2131 2128 if (!buffer) … … 2212 2209 */ 2213 2210 2214 void *XML_GetBuffer(XML_Parser parser, int len)2211 void *XML_GetBuffer(XML_Parser parser, int len) 2215 2212 { 2216 2213 if (len > bufferLim - bufferEnd) … … 2255 2252 } 2256 2253 while (bufferSize < neededSize); 2257 newBuf = (char*)MALLOC(bufferSize);2254 newBuf = MALLOC(bufferSize); 2258 2255 if (newBuf == 0) 2259 2256 { … … 2362 2359 */ 2363 2360 2364 const char *XML_GetInputContext(XML_Parser parser, int *offset, int *size)2361 const char *XML_GetInputContext(XML_Parser parser, int *offset, int *size) 2365 2362 { 2366 2363 #ifdef XML_CONTEXT_BYTES … … 2429 2426 } 2430 2427 2431 /* 2432 *@@ XML_ExpatVersion: 2433 * returns the library version string (e.g. "expat_1.95.1"). 2434 */ 2435 2436 const XML_LChar* XML_ExpatVersion(void) 2437 { 2438 return "expat_1.95.1"; 2439 } 2440 2441 static XMLERROR contentProcessor(XML_Parser parser, 2442 const char *start, 2443 const char *end, 2444 const char **endPtr) 2428 const XML_LChar *XML_ErrorString(int code) 2429 { 2430 static const XML_LChar *message[] = 2431 { 2432 0, 2433 XML_T("out of memory"), 2434 XML_T("syntax error"), 2435 XML_T("no element found"), 2436 XML_T("not well-formed (invalid token)"), 2437 XML_T("unclosed token"), 2438 XML_T("unclosed token"), 2439 XML_T("mismatched tag"), 2440 XML_T("duplicate attribute"), 2441 XML_T("junk after document element"), 2442 XML_T("illegal parameter entity reference"), 2443 XML_T("undefined entity"), 2444 XML_T("recursive entity reference"), 2445 XML_T("asynchronous entity"), 2446 XML_T("reference to invalid character number"), 2447 XML_T("reference to binary entity"), 2448 XML_T("reference to external entity in attribute"), 2449 XML_T("xml processing instruction not at start of external entity"), 2450 XML_T("unknown encoding"), 2451 XML_T("encoding specified in XML declaration is incorrect"), 2452 XML_T("unclosed CDATA section"), 2453 XML_T("error in processing external entity reference"), 2454 XML_T("document is not standalone"), 2455 XML_T("unexpected parser state - please send a bug report") 2456 }; 2457 2458 if (code > 0 && code < sizeof(message) / sizeof(message[0])) 2459 return message[code]; 2460 return 0; 2461 } 2462 2463 /* const XML_LChar * 2464 * XML_ExpatVersion(void) { 2465 * return VERSION; 2466 * } 2467 * 2468 * XML_Expat_Version 2469 * XML_ExpatVersionInfo(void) { 2470 * XML_Expat_Version version; 2471 * 2472 * version.major = XML_MAJOR_VERSION; 2473 * version.minor = XML_MINOR_VERSION; 2474 * version.micro = XML_MICRO_VERSION; 2475 * 2476 * return version; 2477 * } */ 2478 2479 static 2480 XMLERROR contentProcessor(XML_Parser parser, 2481 const char *start, 2482 const char *end, 2483 const char **endPtr) 2445 2484 { 2446 2485 return doContent(parser, 0, encoding, start, end, endPtr); 2447 2486 } 2448 2487 2449 static XMLERROR externalEntityInitProcessor(XML_Parser parser, 2450 const char *start, 2451 const char *end, 2452 const char **endPtr) 2488 static 2489 XMLERROR externalEntityInitProcessor(XML_Parser parser, 2490 const char *start, 2491 const char *end, 2492 const char **endPtr) 2453 2493 { 2454 2494 XMLERROR result = initializeEncoding(parser); … … 2460 2500 } 2461 2501 2462 static XMLERROR externalEntityInitProcessor2(XML_Parser parser, 2463 const char *start, 2464 const char *end, 2465 const char **endPtr) 2502 static 2503 XMLERROR externalEntityInitProcessor2(XML_Parser parser, 2504 const char *start, 2505 const char *end, 2506 const char **endPtr) 2466 2507 { 2467 2508 const char *next; … … 2494 2535 } 2495 2536 2496 static XMLERROR externalEntityInitProcessor3(XML_Parser parser, 2497 const char *start, 2498 const char *end, 2499 const char **endPtr) 2537 static 2538 XMLERROR externalEntityInitProcessor3(XML_Parser parser, 2539 const char *start, 2540 const char *end, 2541 const char **endPtr) 2500 2542 { 2501 2543 const char *next; … … 2535 2577 } 2536 2578 2537 static XMLERROR externalEntityContentProcessor(XML_Parser parser, 2538 const char *start, 2539 const char *end, 2540 const char **endPtr) 2579 static 2580 XMLERROR externalEntityContentProcessor(XML_Parser parser, 2581 const char *start, 2582 const char *end, 2583 const char **endPtr) 2541 2584 { 2542 2585 return doContent(parser, 1, encoding, start, end, endPtr); 2543 2586 } 2544 2587 2545 static XMLERROR 2546 doContent(XML_Parser parser, 2547 int startTagLevel, 2548 const ENCODING * enc, 2549 const char *s, 2550 const char *end, 2551 const char **nextPtr) 2588 /* 2589 *@@ doContent: 2590 * 2591 *@@changed V0.9.14 (2001-08-09) [umoeller]: fixed ERROR_EXPAT_UNDEFINED_ENTITY with callback-defined encodings 2592 */ 2593 2594 static XMLERROR doContent(XML_Parser parser, 2595 int startTagLevel, 2596 const ENCODING * enc, 2597 const char *s, 2598 const char *end, 2599 const char **nextPtr) 2552 2600 { 2553 2601 const char **eventPP; … … 2627 2675 const XML_Char *name; 2628 2676 ENTITY *entity; 2677 unsigned long ulOfs; // V0.9.14 (2001-08-09) [umoeller] 2629 2678 XML_Char ch = XmlPredefinedEntityName(enc, 2630 s + enc->minBytesPerChar,2631 next - enc->minBytesPerChar);2679 s + enc->minBytesPerChar, 2680 next - enc->minBytesPerChar); 2632 2681 2633 2682 if (ch) … … 2639 2688 break; 2640 2689 } 2641 name = poolStoreString(&dtd.pool, enc, 2690 name = poolStoreString(&dtd.pool, 2691 enc, 2642 2692 s + enc->minBytesPerChar, 2643 next - enc->minBytesPerChar); 2693 next - enc->minBytesPerChar, 2694 &ulOfs); 2644 2695 if (!name) 2645 2696 return ERROR_EXPAT_NO_MEMORY; 2646 entity = (ENTITY*)lookup(&dtd.generalEntities, name, 0); 2697 entity = (ENTITY*)lookup(&dtd.generalEntities, 2698 name + ulOfs, // V0.9.14 (2001-08-09) [umoeller] 2699 0); 2647 2700 poolDiscard(&dtd.pool); 2648 2701 if (!entity) … … 2696 2749 if (!context) 2697 2750 return ERROR_EXPAT_NO_MEMORY; 2698 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 2751 if (!externalEntityRefHandler(handlerArg, // V0.9.14 (2001-08-09) [umoeller] 2752 externalEntityRefHandlerArg, 2699 2753 context, 2700 2754 entity->base, … … 2729 2783 else 2730 2784 { 2731 tag = (TAG*)MALLOC(sizeof(TAG));2785 tag = MALLOC(sizeof(TAG)); 2732 2786 if (!tag) 2733 2787 return ERROR_EXPAT_NO_MEMORY; 2734 tag->buf = (char*)MALLOC(INIT_TAG_BUF_SIZE);2788 tag->buf = MALLOC(INIT_TAG_BUF_SIZE); 2735 2789 if (!tag->buf) 2736 2790 return ERROR_EXPAT_NO_MEMORY; … … 2752 2806 2753 2807 bufSize = ROUND_UP(bufSize, sizeof(XML_Char)); 2754 tag->buf = (char*)REALLOC(tag->buf, bufSize);2808 tag->buf = REALLOC(tag->buf, bufSize); 2755 2809 if (!tag->buf) 2756 2810 return ERROR_EXPAT_NO_MEMORY; … … 2773 2827 2774 2828 if (nextPtr) 2775 toPtr = (XML_Char *)(tag->buf + ROUND_UP(tag->rawNameLength, sizeof(XML_Char)));2829 toPtr = (XML_Char *) (tag->buf + ROUND_UP(tag->rawNameLength, sizeof(XML_Char))); 2776 2830 else 2777 toPtr = (XML_Char *)tag->buf;2831 toPtr = (XML_Char *) tag->buf; 2778 2832 tag->name.str = toPtr; 2779 2833 XmlConvert(enc, 2780 2834 &fromPtr, rawNameEnd, 2781 (ICHAR **) & toPtr, (ICHAR *)tag->bufEnd - 1);2835 (ICHAR **) & toPtr, (ICHAR *) tag->bufEnd - 1); 2782 2836 if (fromPtr == rawNameEnd) 2783 2837 break; 2784 2838 bufSize = (tag->bufEnd - tag->buf) << 1; 2785 tag->buf = (char*)REALLOC(tag->buf, bufSize);2839 tag->buf = REALLOC(tag->buf, bufSize); 2786 2840 if (!tag->buf) 2787 2841 return ERROR_EXPAT_NO_MEMORY; … … 2822 2876 TAG_NAME name; 2823 2877 2824 name.str = poolStoreString(&tempPool, enc, rawName, 2825 rawName + XmlNameLength(enc, rawName)); 2878 name.str = poolStoreString(&tempPool, 2879 enc, 2880 rawName, 2881 rawName + XmlNameLength(enc, rawName), 2882 NULL); 2826 2883 if (!name.str) 2827 2884 return ERROR_EXPAT_NO_MEMORY; … … 2882 2939 if (tag->name.localPart) 2883 2940 { 2884 XML_Char *to = (XML_Char *)tag->name.str + tag->name.uriLen;2941 XML_Char *to = (XML_Char *) tag->name.str + tag->name.uriLen; 2885 2942 const XML_Char *from = tag->name.localPart; 2886 2943 … … 2917 2974 XML_Char buf[XML_ENCODE_MAX]; 2918 2975 2919 characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *)buf));2976 characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *) buf)); 2920 2977 } 2921 2978 else if (defaultHandler) … … 2976 3033 if (MUST_CONVERT(enc, s)) 2977 3034 { 2978 ICHAR *dataPtr = (ICHAR *)dataBuf;2979 2980 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);2981 characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);3035 ICHAR *dataPtr = (ICHAR *) dataBuf; 3036 3037 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *) dataBufEnd); 3038 characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *) dataBuf); 2982 3039 } 2983 3040 else 2984 3041 characterDataHandler(handlerArg, 2985 (XML_Char *)s,2986 (XML_Char *)end - (XML_Char*)s);3042 (XML_Char *) s, 3043 (XML_Char *) end - (XML_Char *) s); 2987 3044 } 2988 3045 else if (defaultHandler) … … 3006 3063 for (;;) 3007 3064 { 3008 ICHAR *dataPtr = (ICHAR *)dataBuf;3009 3010 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);3065 ICHAR *dataPtr = (ICHAR *) dataBuf; 3066 3067 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *) dataBufEnd); 3011 3068 *eventEndPP = s; 3012 characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);3069 characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *) dataBuf); 3013 3070 if (s == next) 3014 3071 break; … … 3018 3075 else 3019 3076 characterDataHandler(handlerArg, 3020 (XML_Char *)s,3021 (XML_Char *)next - (XML_Char*)s);3077 (XML_Char *) s, 3078 (XML_Char *) next - (XML_Char *) s); 3022 3079 } 3023 3080 else if (defaultHandler) … … 3045 3102 * otherwise just check the attributes for well-formedness. */ 3046 3103 3047 static XMLERROR storeAtts(XML_Parser parser, 3048 const ENCODING * enc, 3049 const char *attStr, 3050 TAG_NAME * tagNamePtr, 3051 BINDING ** bindingsPtr) 3104 static XMLERROR storeAtts(XML_Parser parser, const ENCODING * enc, 3105 const char *attStr, TAG_NAME * tagNamePtr, 3106 BINDING ** bindingsPtr) 3052 3107 { 3053 3108 ELEMENT_TYPE *elementType = 0; … … 3064 3119 if (tagNamePtr) 3065 3120 { 3066 elementType = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, tagNamePtr->str, 0);3121 elementType = (ELEMENT_TYPE *) lookup(&dtd.elementTypes, tagNamePtr->str, 0); 3067 3122 if (!elementType) 3068 3123 { … … 3070 3125 if (!tagNamePtr->str) 3071 3126 return ERROR_EXPAT_NO_MEMORY; 3072 elementType = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, tagNamePtr->str, sizeof(ELEMENT_TYPE));3127 elementType = (ELEMENT_TYPE *) lookup(&dtd.elementTypes, tagNamePtr->str, sizeof(ELEMENT_TYPE)); 3073 3128 if (!elementType) 3074 3129 return ERROR_EXPAT_NO_MEMORY; … … 3085 3140 3086 3141 attsSize = n + nDefaultAtts + INIT_ATTS_SIZE; 3087 atts = (PATTRIBUTE)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));3142 atts = REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); 3088 3143 if (!atts) 3089 3144 return ERROR_EXPAT_NO_MEMORY; … … 3147 3202 { 3148 3203 /* the value did not need normalizing */ 3149 appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, atts[i].valueEnd); 3204 appAtts[attIndex] = poolStoreString(&tempPool, 3205 enc, 3206 atts[i].valuePtr, 3207 atts[i].valueEnd, 3208 NULL); 3150 3209 if (appAtts[attIndex] == 0) 3151 3210 return ERROR_EXPAT_NO_MEMORY; … … 3231 3290 ATTRIBUTE_ID *id; 3232 3291 3233 ((XML_Char *)(appAtts[i]))[-1] = 0;3234 id = (ATTRIBUTE_ID *)lookup(&dtd.attributeIds, appAtts[i], 0);3292 ((XML_Char *) (appAtts[i]))[-1] = 0; 3293 id = (ATTRIBUTE_ID *) lookup(&dtd.attributeIds, appAtts[i], 0); 3235 3294 if (id->prefix->binding) 3236 3295 { … … 3271 3330 } 3272 3331 else 3273 ((XML_Char *)(appAtts[i]))[-1] = 0;3332 ((XML_Char *) (appAtts[i]))[-1] = 0; 3274 3333 } 3275 3334 } 3276 3335 /* clear the flags that say whether attributes were specified */ 3277 3336 for (; i < attIndex; i += 2) 3278 ((XML_Char *)(appAtts[i]))[-1] = 0;3337 ((XML_Char *) (appAtts[i]))[-1] = 0; 3279 3338 if (!tagNamePtr) 3280 3339 return ERROR_EXPAT_NONE; … … 3306 3365 { 3307 3366 TAG *p; 3308 XML_Char *uri = (XML_Char*)MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char));3367 XML_Char *uri = MALLOC((n + EXPAND_SPARE) * sizeof(XML_Char)); 3309 3368 3310 3369 if (!uri) … … 3323 3382 } 3324 3383 3325 static int addBinding(XML_Parser parser, PREFIX * prefix, const ATTRIBUTE_ID * attId, const XML_Char * uri, BINDING ** bindingsPtr) 3384 static 3385 int addBinding(XML_Parser parser, PREFIX * prefix, const ATTRIBUTE_ID * attId, const XML_Char * uri, BINDING ** bindingsPtr) 3326 3386 { 3327 3387 BINDING *b; … … 3337 3397 if (len > b->uriAlloc) 3338 3398 { 3339 b->uri = (XML_Char*)REALLOC(b->uri, sizeof(XML_Char) * (len + EXPAND_SPARE));3399 b->uri = REALLOC(b->uri, sizeof(XML_Char) * (len + EXPAND_SPARE)); 3340 3400 if (!b->uri) 3341 3401 return 0; … … 3346 3406 else 3347 3407 { 3348 b = (PBINDING)MALLOC(sizeof(BINDING));3408 b = MALLOC(sizeof(BINDING)); 3349 3409 if (!b) 3350 3410 return 0; 3351 b->uri = (XML_Char*)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE));3411 b->uri = MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE)); 3352 3412 if (!b->uri) 3353 3413 { … … 3379 3439 * the whole file is parsed with one call. */ 3380 3440 3381 static XMLERROR cdataSectionProcessor(XML_Parser parser, 3382 const char *start, 3383 const char *end, 3384 const char **endPtr) 3441 static 3442 XMLERROR cdataSectionProcessor(XML_Parser parser, 3443 const char *start, 3444 const char *end, 3445 const char **endPtr) 3385 3446 { 3386 3447 XMLERROR result = doCdataSection(parser, encoding, &start, end, endPtr); … … 3397 3458 * the section is not yet closed. */ 3398 3459 3399 static XMLERROR doCdataSection(XML_Parser parser, 3400 const ENCODING * enc, 3401 const char **startPtr, 3402 const char *end, 3403 const char **nextPtr) 3460 static 3461 XMLERROR doCdataSection(XML_Parser parser, 3462 const ENCODING * enc, 3463 const char **startPtr, 3464 const char *end, 3465 const char **nextPtr) 3404 3466 { 3405 3467 const char *s = *startPtr; … … 3457 3519 for (;;) 3458 3520 { 3459 ICHAR *dataPtr = (ICHAR *)dataBuf;3460 3461 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *)dataBufEnd);3521 ICHAR *dataPtr = (ICHAR *) dataBuf; 3522 3523 XmlConvert(enc, &s, next, &dataPtr, (ICHAR *) dataBufEnd); 3462 3524 *eventEndPP = next; 3463 characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);3525 characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *) dataBuf); 3464 3526 if (s == next) 3465 3527 break; … … 3469 3531 else 3470 3532 characterDataHandler(handlerArg, 3471 (XML_Char *)s,3472 (XML_Char *)next - (XML_Char*)s);3533 (XML_Char *) s, 3534 (XML_Char *) next - (XML_Char *) s); 3473 3535 } 3474 3536 else if (defaultHandler) … … 3507 3569 * the whole file is parsed with one call. */ 3508 3570 3509 static XMLERROR ignoreSectionProcessor(XML_Parser parser, 3510 const char *start, 3511 const char *end, 3512 const char **endPtr) 3571 static 3572 XMLERROR ignoreSectionProcessor(XML_Parser parser, 3573 const char *start, 3574 const char *end, 3575 const char **endPtr) 3513 3576 { 3514 3577 XMLERROR result = doIgnoreSection(parser, encoding, &start, end, endPtr); … … 3525 3588 * the section is not yet closed. */ 3526 3589 3527 static XMLERROR doIgnoreSection(XML_Parser parser, 3528 const ENCODING * enc, 3529 const char **startPtr, 3530 const char *end, 3531 const char **nextPtr) 3590 static 3591 XMLERROR doIgnoreSection(XML_Parser parser, 3592 const ENCODING * enc, 3593 const char **startPtr, 3594 const char *end, 3595 const char **nextPtr) 3532 3596 { 3533 3597 const char *next; … … 3576 3640 return ERROR_EXPAT_NONE; 3577 3641 } 3578 return ERROR_EXPAT_SYNTAX; 3642 return ERROR_EXPAT_SYNTAX; /* ERROR_EXPAT_UNCLOSED_IGNORE_SECTION */ 3579 3643 default: 3580 3644 *eventPP = next; … … 3586 3650 #endif /* XML_DTD */ 3587 3651 3588 static XMLERROR initializeEncoding(XML_Parser parser) 3652 static XMLERROR 3653 initializeEncoding(XML_Parser parser) 3589 3654 { 3590 3655 const char *s; … … 3620 3685 } 3621 3686 3622 static XMLERROR processXmlDecl(XML_Parser parser, int isGeneralTextEntity, 3687 static XMLERROR 3688 processXmlDecl(XML_Parser parser, int isGeneralTextEntity, 3623 3689 const char *s, const char *next) 3624 3690 { … … 3660 3726 encodingName, 3661 3727 encodingName 3662 + XmlNameLength(encoding, encodingName)); 3728 + XmlNameLength(encoding, encodingName), 3729 NULL); 3663 3730 if (!storedEncName) 3664 3731 return ERROR_EXPAT_NO_MEMORY; … … 3670 3737 encoding, 3671 3738 version, 3672 versionend - encoding->minBytesPerChar); 3739 versionend - encoding->minBytesPerChar, 3740 NULL); 3673 3741 if (!storedversion) 3674 3742 return ERROR_EXPAT_NO_MEMORY; … … 3699 3767 encodingName, 3700 3768 encodingName 3701 + XmlNameLength(encoding, encodingName)); 3769 + XmlNameLength(encoding, encodingName), 3770 NULL); 3702 3771 if (!storedEncName) 3703 3772 return ERROR_EXPAT_NO_MEMORY; … … 3717 3786 } 3718 3787 3719 static XMLERROR handleUnknownEncoding(XML_Parser parser,3720 const XML_Char* encodingName)3788 static XMLERROR 3789 handleUnknownEncoding(XML_Parser parser, const XML_Char * encodingName) 3721 3790 { 3722 3791 if (unknownEncodingHandler) … … 3730 3799 info.data = 0; 3731 3800 info.release = 0; 3732 if (unknownEncodingHandler(unknownEncodingHandlerData, 3733 encodingName, 3734 &info)) 3801 if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName, &info)) 3735 3802 { 3736 3803 ENCODING *enc; … … 3763 3830 } 3764 3831 3765 static XMLERROR prologInitProcessor(XML_Parser parser, 3832 static XMLERROR 3833 prologInitProcessor(XML_Parser parser, 3766 3834 const char *s, 3767 3835 const char *end, … … 3776 3844 } 3777 3845 3778 static XMLERROR prologProcessor(XML_Parser parser, 3846 static XMLERROR 3847 prologProcessor(XML_Parser parser, 3779 3848 const char *s, 3780 3849 const char *end, … … 3787 3856 } 3788 3857 3789 static XMLERROR doProlog(XML_Parser parser, 3858 static XMLERROR 3859 doProlog(XML_Parser parser, 3790 3860 const ENCODING * enc, 3791 3861 const char *s, … … 3872 3942 if (startDoctypeDeclHandler) 3873 3943 { 3874 doctypeName = poolStoreString(&tempPool, enc, s, next );3944 doctypeName = poolStoreString(&tempPool, enc, s, next, NULL); 3875 3945 if (!doctypeName) 3876 3946 return ERROR_EXPAT_NO_MEMORY; … … 3903 3973 if (startDoctypeDeclHandler) 3904 3974 { 3905 doctypePubid = poolStoreString(&tempPool, enc, s + 1, next - 1 );3975 doctypePubid = poolStoreString(&tempPool, enc, s + 1, next - 1, NULL); 3906 3976 if (!doctypePubid) 3907 3977 return ERROR_EXPAT_NO_MEMORY; … … 3909 3979 } 3910 3980 #ifdef XML_DTD 3911 declEntity = (ENTITY *)lookup(&dtd.paramEntities,3981 declEntity = (ENTITY *) lookup(&dtd.paramEntities, 3912 3982 externalSubsetName, 3913 3983 sizeof(ENTITY)); … … 3924 3994 enc, 3925 3995 s + enc->minBytesPerChar, 3926 next - enc->minBytesPerChar); 3996 next - enc->minBytesPerChar, 3997 NULL); 3927 3998 3928 3999 if (!tem) … … 3946 4017 if (paramEntityParsing && externalEntityRefHandler) 3947 4018 { 3948 ENTITY *entity = (ENTITY *)lookup(&dtd.paramEntities,4019 ENTITY *entity = (ENTITY *) lookup(&dtd.paramEntities, 3949 4020 externalSubsetName, 3950 4021 0); 3951 4022 3952 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 4023 if (!externalEntityRefHandler(handlerArg, // V0.9.14 (2001-08-09) [umoeller] 4024 externalEntityRefHandlerArg, 3953 4025 0, 3954 4026 entity->base, … … 4028 4100 if (!poolAppendString(&tempPool, prefix)) 4029 4101 return ERROR_EXPAT_NO_MEMORY; 4030 if (!poolAppend(&tempPool, enc, s, next ))4102 if (!poolAppend(&tempPool, enc, s, next, NULL)) 4031 4103 return ERROR_EXPAT_NO_MEMORY; 4032 4104 declAttributeType = tempPool.start; … … 4043 4115 { 4044 4116 if (*declAttributeType == '(' 4045 || *declAttributeType == 'N' && declAttributeType[1] == 'O')4117 || (*declAttributeType == 'N' && declAttributeType[1] == 'O')) 4046 4118 { 4047 4119 /* Enumerated or Notation type */ … … 4080 4152 { 4081 4153 if (*declAttributeType == '(' 4082 || *declAttributeType == 'N' && declAttributeType[1] == 'O')4154 || (*declAttributeType == 'N' && declAttributeType[1] == 'O')) 4083 4155 { 4084 4156 /* Enumerated or Notation type */ … … 4129 4201 if (startDoctypeDeclHandler) 4130 4202 { 4131 doctypeSysid = poolStoreString(&tempPool, enc, s + 1, next - 1); 4203 doctypeSysid = poolStoreString(&tempPool, 4204 enc, 4205 s + 1, 4206 next - 1, 4207 NULL); 4132 4208 if (!doctypeSysid) 4133 4209 return ERROR_EXPAT_NO_MEMORY; … … 4147 4223 if (!declEntity) 4148 4224 { 4149 declEntity = (ENTITY *)lookup(&dtd.paramEntities,4225 declEntity = (ENTITY *) lookup(&dtd.paramEntities, 4150 4226 externalSubsetName, 4151 4227 sizeof(ENTITY)); … … 4159 4235 if (declEntity) 4160 4236 { 4161 declEntity->systemId = poolStoreString(&dtd.pool, enc, 4162 s + enc->minBytesPerChar, 4163 next - enc->minBytesPerChar); 4237 declEntity->systemId = poolStoreString(&dtd.pool, 4238 enc, 4239 s + enc->minBytesPerChar, 4240 next - enc->minBytesPerChar, 4241 NULL); 4164 4242 if (!declEntity->systemId) 4165 4243 return ERROR_EXPAT_NO_MEMORY; … … 4184 4262 if (declEntity) 4185 4263 { 4186 declEntity->notation = poolStoreString(&dtd.pool, enc, s, next); 4264 declEntity->notation = poolStoreString(&dtd.pool, 4265 enc, 4266 s, 4267 next, 4268 NULL); 4187 4269 if (!declEntity->notation) 4188 4270 return ERROR_EXPAT_NO_MEMORY; … … 4220 4302 break; 4221 4303 } 4222 name = poolStoreString(&dtd.pool, enc, s, next); 4304 name = poolStoreString(&dtd.pool, 4305 enc, 4306 s, 4307 next, 4308 NULL); 4223 4309 if (!name) 4224 4310 return ERROR_EXPAT_NO_MEMORY; 4225 4311 if (dtd.complete) 4226 4312 { 4227 declEntity = (ENTITY *)lookup(&dtd.generalEntities, name, sizeof(ENTITY));4313 declEntity = (ENTITY *) lookup(&dtd.generalEntities, name, sizeof(ENTITY)); 4228 4314 if (!declEntity) 4229 4315 return ERROR_EXPAT_NO_MEMORY; … … 4251 4337 if (dtd.complete) 4252 4338 { 4253 const XML_Char *name = poolStoreString(&dtd.pool, enc, s, next );4339 const XML_Char *name = poolStoreString(&dtd.pool, enc, s, next, NULL); 4254 4340 4255 4341 if (!name) 4256 4342 return ERROR_EXPAT_NO_MEMORY; 4257 declEntity = (ENTITY *)lookup(&dtd.paramEntities,4343 declEntity = (ENTITY *) lookup(&dtd.paramEntities, 4258 4344 name, sizeof(ENTITY)); 4259 4345 if (!declEntity) … … 4280 4366 if (notationDeclHandler) 4281 4367 { 4282 declNotationName = poolStoreString(&tempPool, enc, s, next );4368 declNotationName = poolStoreString(&tempPool, enc, s, next, NULL); 4283 4369 if (!declNotationName) 4284 4370 return ERROR_EXPAT_NO_MEMORY; … … 4294 4380 enc, 4295 4381 s + enc->minBytesPerChar, 4296 next - enc->minBytesPerChar); 4382 next - enc->minBytesPerChar, 4383 NULL); 4297 4384 4298 4385 if (!tem) … … 4309 4396 = poolStoreString(&tempPool, enc, 4310 4397 s + enc->minBytesPerChar, 4311 next - enc->minBytesPerChar); 4398 next - enc->minBytesPerChar, 4399 NULL); 4312 4400 4313 4401 if (!systemId) … … 4365 4453 if (groupSize) 4366 4454 { 4367 groupConnector = (char*)REALLOC(groupConnector, groupSize *= 2);4455 groupConnector = REALLOC(groupConnector, groupSize *= 2); 4368 4456 if (dtd.scaffIndex) 4369 dtd.scaffIndex = (int*)REALLOC(dtd.scaffIndex, groupSize * sizeof(int));4457 dtd.scaffIndex = REALLOC(dtd.scaffIndex, groupSize * sizeof(int)); 4370 4458 } 4371 4459 else 4372 groupConnector = (char*)MALLOC(groupSize = 32);4460 groupConnector = MALLOC(groupSize = 32); 4373 4461 if (!groupConnector) 4374 4462 return ERROR_EXPAT_NO_MEMORY; … … 4414 4502 name = poolStoreString(&dtd.pool, enc, 4415 4503 s + enc->minBytesPerChar, 4416 next - enc->minBytesPerChar); 4504 next - enc->minBytesPerChar, 4505 NULL); 4417 4506 if (!name) 4418 4507 return ERROR_EXPAT_NO_MEMORY; 4419 entity = (ENTITY *)lookup(&dtd.paramEntities, name, 0);4508 entity = (ENTITY *) lookup(&dtd.paramEntities, name, 0); 4420 4509 poolDiscard(&dtd.pool); 4421 4510 if (!entity) … … 4441 4530 dtd.complete = 0; 4442 4531 entity->open = 1; 4443 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 4532 if (!externalEntityRefHandler(handlerArg, // V0.9.14 (2001-08-09) [umoeller] 4533 externalEntityRefHandlerArg, 4444 4534 0, 4445 4535 entity->base, … … 4485 4575 if (elementDeclHandler) 4486 4576 { 4487 XMLCONTENT *content = (XMLCONTENT *)MALLOC(sizeof(XMLCONTENT));4577 XMLCONTENT *content = (XMLCONTENT *) MALLOC(sizeof(XMLCONTENT)); 4488 4578 4489 4579 if (!content) … … 4614 4704 } 4615 4705 4616 static XMLERROR epilogProcessor(XML_Parser parser, 4617 const char *s, 4618 const char *end, 4619 const char **nextPtr) 4706 static 4707 XMLERROR epilogProcessor(XML_Parser parser, 4708 const char *s, 4709 const char *end, 4710 const char **nextPtr) 4620 4711 { 4621 4712 processor = epilogProcessor; … … 4678 4769 #ifdef XML_DTD 4679 4770 4680 static XMLERROR processInternalParamEntity(XML_Parser parser, ENTITY * entity) 4771 static XMLERROR 4772 processInternalParamEntity(XML_Parser parser, ENTITY * entity) 4681 4773 { 4682 4774 const char *s, *end, *next; … … 4702 4794 #endif /* XML_DTD */ 4703 4795 4704 static XMLERROR errorProcessor(XML_Parser parser, 4705 const char *s, 4706 const char *end, 4707 const char **nextPtr) 4796 static 4797 XMLERROR errorProcessor(XML_Parser parser, 4798 const char *s, 4799 const char *end, 4800 const char **nextPtr) 4708 4801 { 4709 4802 return errorCode; 4710 4803 } 4711 4804 4712 static XMLERROR storeAttributeValue(XML_Parser parser, 4713 const ENCODING * enc, 4714 int isCdata, 4715 const char *ptr, 4716 const char *end, 4717 STRING_POOL * pool) 4805 static XMLERROR 4806 storeAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata, 4807 const char *ptr, const char *end, 4808 STRING_POOL * pool) 4718 4809 { 4719 4810 XMLERROR result = appendAttributeValue(parser, enc, isCdata, ptr, end, pool); … … 4728 4819 } 4729 4820 4730 static XMLERROR appendAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata, 4731 const char *ptr, const char *end, 4732 STRING_POOL * pool) 4821 4822 /* 4823 *@@ appendAttributeValue: 4824 * 4825 *@@changed V0.9.14 (2001-08-09) [umoeller]: fixed ERROR_EXPAT_UNDEFINED_ENTITY with callback-defined encodings 4826 */ 4827 4828 static XMLERROR appendAttributeValue(XML_Parser parser, 4829 const ENCODING * enc, 4830 int isCdata, 4831 const char *ptr, 4832 const char *end, 4833 STRING_POOL * pool) 4733 4834 { 4734 4835 for (;;) … … 4765 4866 && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20)) 4766 4867 break; 4767 n = XmlEncode(n, (ICHAR *)buf);4868 n = XmlEncode(n, (ICHAR *) buf); 4768 4869 if (!n) 4769 4870 { … … 4780 4881 break; 4781 4882 case XML_TOK_DATA_CHARS: 4782 if (!poolAppend(pool, enc, ptr, next ))4883 if (!poolAppend(pool, enc, ptr, next, NULL)) 4783 4884 return ERROR_EXPAT_NO_MEMORY; 4885 break; 4784 4886 break; 4785 4887 case XML_TOK_TRAILING_CR: … … 4797 4899 const XML_Char *name; 4798 4900 ENTITY *entity; 4901 unsigned long ulOfs; // V0.9.14 (2001-08-09) [umoeller] 4799 4902 XML_Char ch = XmlPredefinedEntityName(enc, 4800 4903 ptr + enc->minBytesPerChar, … … 4809 4912 name = poolStoreString(&temp2Pool, enc, 4810 4913 ptr + enc->minBytesPerChar, 4811 next - enc->minBytesPerChar); 4914 next - enc->minBytesPerChar, 4915 &ulOfs); // V0.9.14 (2001-08-09) [umoeller] 4812 4916 if (!name) 4813 4917 return ERROR_EXPAT_NO_MEMORY; 4814 entity = (ENTITY*)lookup(&dtd.generalEntities, name, 0); 4918 entity = (ENTITY *) lookup(&dtd.generalEntities, 4919 name + ulOfs, // V0.9.14 (2001-08-09) [umoeller] 4920 0); 4815 4921 poolDiscard(&temp2Pool); 4816 4922 if (!entity) … … 4864 4970 } 4865 4971 4866 static XMLERROR storeEntityValue(XML_Parser parser, 4867 const ENCODING * enc, 4868 const char *entityTextPtr, 4869 const char *entityTextEnd) 4972 static 4973 XMLERROR storeEntityValue(XML_Parser parser, 4974 const ENCODING * enc, 4975 const char *entityTextPtr, 4976 const char *entityTextEnd) 4870 4977 { 4871 4978 STRING_POOL *pool = &(dtd.pool); … … 4887 4994 4888 4995 name = poolStoreString(&tempPool, enc, 4889 entityTextPtr + enc->minBytesPerChar, 4890 next - enc->minBytesPerChar); 4996 entityTextPtr + enc->minBytesPerChar, 4997 next - enc->minBytesPerChar, 4998 NULL); 4891 4999 if (!name) 4892 5000 return ERROR_EXPAT_NO_MEMORY; 4893 entity = (ENTITY *)lookup(&dtd.paramEntities, name, 0);5001 entity = (ENTITY *) lookup(&dtd.paramEntities, name, 0); 4894 5002 poolDiscard(&tempPool); 4895 5003 if (!entity) … … 4928 5036 case XML_TOK_ENTITY_REF: 4929 5037 case XML_TOK_DATA_CHARS: 4930 if (!poolAppend(pool, enc, entityTextPtr, next ))5038 if (!poolAppend(pool, enc, entityTextPtr, next, NULL)) 4931 5039 return ERROR_EXPAT_NO_MEMORY; 4932 5040 break; … … 4951 5059 return ERROR_EXPAT_BAD_CHAR_REF; 4952 5060 } 4953 n = XmlEncode(n, (ICHAR *)buf);5061 n = XmlEncode(n, (ICHAR *) buf); 4954 5062 if (!n) 4955 5063 { … … 4984 5092 } 4985 5093 4986 static void normalizeLines(XML_Char * s) 5094 static void 5095 normalizeLines(XML_Char * s) 4987 5096 { 4988 5097 XML_Char *p; … … 5011 5120 } 5012 5121 5013 static int reportProcessingInstruction(XML_Parser parser, const ENCODING * enc, const char *start, const char *end) 5122 static int 5123 reportProcessingInstruction(XML_Parser parser, const ENCODING * enc, const char *start, const char *end) 5014 5124 { 5015 5125 const XML_Char *target; … … 5025 5135 start += enc->minBytesPerChar * 2; 5026 5136 tem = start + XmlNameLength(enc, start); 5027 target = poolStoreString(&tempPool, enc, start, tem );5137 target = poolStoreString(&tempPool, enc, start, tem, NULL); 5028 5138 if (!target) 5029 5139 return 0; … … 5031 5141 data = poolStoreString(&tempPool, enc, 5032 5142 XmlSkipS(enc, tem), 5033 end - enc->minBytesPerChar * 2); 5143 end - enc->minBytesPerChar * 2, 5144 NULL); 5034 5145 if (!data) 5035 5146 return 0; … … 5040 5151 } 5041 5152 5042 static int reportComment(XML_Parser parser, const ENCODING * enc, const char *start, const char *end) 5153 static int 5154 reportComment(XML_Parser parser, const ENCODING * enc, const char *start, const char *end) 5043 5155 { 5044 5156 XML_Char *data; … … 5053 5165 enc, 5054 5166 start + enc->minBytesPerChar * 4, 5055 end - enc->minBytesPerChar * 3); 5167 end - enc->minBytesPerChar * 3, 5168 NULL); 5056 5169 if (!data) 5057 5170 return 0; … … 5062 5175 } 5063 5176 5064 static void reportDefault(XML_Parser parser, const ENCODING * enc, const char *s, const char *end) 5177 static void 5178 reportDefault(XML_Parser parser, const ENCODING * enc, const char *s, const char *end) 5065 5179 { 5066 5180 if (MUST_CONVERT(enc, s)) … … 5081 5195 do 5082 5196 { 5083 ICHAR *dataPtr = (ICHAR *)dataBuf;5084 5085 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);5197 ICHAR *dataPtr = (ICHAR *) dataBuf; 5198 5199 XmlConvert(enc, &s, end, &dataPtr, (ICHAR *) dataBufEnd); 5086 5200 *eventEndPP = s; 5087 defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);5201 defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *) dataBuf); 5088 5202 *eventPP = s; 5089 5203 } … … 5091 5205 } 5092 5206 else 5093 defaultHandler(handlerArg, (XML_Char*)s, (XML_Char*)end - (XML_Char*)s); 5094 } 5095 5096 5097 static int defineAttribute(ELEMENT_TYPE * type, ATTRIBUTE_ID * attId, int isCdata, 5207 defaultHandler(handlerArg, (XML_Char *) s, (XML_Char *) end - (XML_Char *) s); 5208 } 5209 5210 5211 static int 5212 defineAttribute(ELEMENT_TYPE * type, ATTRIBUTE_ID * attId, int isCdata, 5098 5213 int isId, const XML_Char * value, XML_Parser parser) 5099 5214 { … … 5117 5232 { 5118 5233 type->allocDefaultAtts = 8; 5119 type->defaultAtts = (PDEFAULT_ATTRIBUTE)MALLOC(type->allocDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));5234 type->defaultAtts = MALLOC(type->allocDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); 5120 5235 } 5121 5236 else 5122 5237 { 5123 5238 type->allocDefaultAtts *= 2; 5124 type->defaultAtts = (PDEFAULT_ATTRIBUTE)REALLOC(type->defaultAtts,5239 type->defaultAtts = REALLOC(type->defaultAtts, 5125 5240 type->allocDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); 5126 5241 } … … 5156 5271 if (!poolAppendChar(&dtd.pool, XML_T('\0'))) 5157 5272 return 0; 5158 prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&dtd.pool), sizeof(PREFIX));5273 prefix = (PREFIX *) lookup(&dtd.prefixes, poolStart(&dtd.pool), sizeof(PREFIX)); 5159 5274 if (!prefix) 5160 5275 return 0; … … 5170 5285 } 5171 5286 5172 static ATTRIBUTE_ID* getAttributeId(XML_Parser parser, const ENCODING * enc, const char *start, const char *end) 5287 static ATTRIBUTE_ID * 5288 getAttributeId(XML_Parser parser, const ENCODING * enc, const char *start, const char *end) 5173 5289 { 5174 5290 ATTRIBUTE_ID *id; … … 5177 5293 if (!poolAppendChar(&dtd.pool, XML_T('\0'))) 5178 5294 return 0; 5179 name = poolStoreString(&dtd.pool, enc, start, end );5295 name = poolStoreString(&dtd.pool, enc, start, end, NULL); 5180 5296 if (!name) 5181 5297 return 0; 5182 5298 ++name; 5183 id = (ATTRIBUTE_ID *)lookup(&dtd.attributeIds, name, sizeof(ATTRIBUTE_ID));5299 id = (ATTRIBUTE_ID *) lookup(&dtd.attributeIds, name, sizeof(ATTRIBUTE_ID)); 5184 5300 if (!id) 5185 5301 return 0; … … 5201 5317 id->prefix = &dtd.defaultPrefix; 5202 5318 else 5203 id->prefix = (PREFIX *)lookup(&dtd.prefixes, name + 6, sizeof(PREFIX));5319 id->prefix = (PREFIX *) lookup(&dtd.prefixes, name + 6, sizeof(PREFIX)); 5204 5320 id->xmlns = 1; 5205 5321 } … … 5221 5337 if (!poolAppendChar(&dtd.pool, XML_T('\0'))) 5222 5338 return 0; 5223 id->prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&dtd.pool), sizeof(PREFIX));5339 id->prefix = (PREFIX *) lookup(&dtd.prefixes, poolStart(&dtd.pool), sizeof(PREFIX)); 5224 5340 if (id->prefix->name == poolStart(&dtd.pool)) 5225 5341 poolFinish(&dtd.pool); … … 5236 5352 #define CONTEXT_SEP XML_T('\f') 5237 5353 5238 static const XML_Char *getContext(XML_Parser parser) 5354 static 5355 const XML_Char *getContext(XML_Parser parser) 5239 5356 { 5240 5357 HASH_TABLE_ITER iter; … … 5263 5380 int len; 5264 5381 const XML_Char *s; 5265 PREFIX *prefix = (PREFIX *)hashTableIterNext(&iter);5382 PREFIX *prefix = (PREFIX *) hashTableIterNext(&iter); 5266 5383 5267 5384 if (!prefix) … … 5290 5407 { 5291 5408 const XML_Char *s; 5292 ENTITY *e = (ENTITY *)hashTableIterNext(&iter);5409 ENTITY *e = (ENTITY *) hashTableIterNext(&iter); 5293 5410 5294 5411 if (!e) … … 5309 5426 } 5310 5427 5311 static int setContext(XML_Parser parser, const XML_Char * context) 5428 static 5429 int setContext(XML_Parser parser, const XML_Char * context) 5312 5430 { 5313 5431 const XML_Char *s = context; … … 5321 5439 if (!poolAppendChar(&tempPool, XML_T('\0'))) 5322 5440 return 0; 5323 e = (ENTITY *)lookup(&dtd.generalEntities, poolStart(&tempPool), 0);5441 e = (ENTITY *) lookup(&dtd.generalEntities, poolStart(&tempPool), 0); 5324 5442 if (e) 5325 5443 e->open = 1; … … 5339 5457 if (!poolAppendChar(&tempPool, XML_T('\0'))) 5340 5458 return 0; 5341 prefix = (PREFIX *)lookup(&dtd.prefixes, poolStart(&tempPool), sizeof(PREFIX));5459 prefix = (PREFIX *) lookup(&dtd.prefixes, poolStart(&tempPool), sizeof(PREFIX)); 5342 5460 if (!prefix) 5343 5461 return 0; … … 5373 5491 5374 5492 5375 static void normalizePublicId(XML_Char * publicId) 5493 static 5494 void normalizePublicId(XML_Char * publicId) 5376 5495 { 5377 5496 XML_Char *p = publicId; … … 5399 5518 static int dtdInit(DTD * p, XML_Parser parser) 5400 5519 { 5401 XML_Memory_Handling_Suite *ms = &((Parser *)parser)->m_mem;5520 XML_Memory_Handling_Suite *ms = &((Parser *) parser)->m_mem; 5402 5521 5403 5522 poolInit(&(p->pool), ms); … … 5445 5564 for (;;) 5446 5565 { 5447 ELEMENT_TYPE *e = (ELEMENT_TYPE *)hashTableIterNext(&iter);5566 ELEMENT_TYPE *e = (ELEMENT_TYPE *) hashTableIterNext(&iter); 5448 5567 5449 5568 if (!e) … … 5466 5585 } 5467 5586 5468 /* 5469 * Do a deep copy of the DTD. Return 0 for out of memory; non-zero otherwise. 5470 * The new DTD has already been initialized. 5471 * 5472 */ 5587 /* Do a deep copy of the DTD. Return 0 for out of memory; non-zero otherwise. 5588 * The new DTD has already been initialized. */ 5473 5589 5474 5590 static int dtdCopy(DTD * newDtd, const DTD * oldDtd, XML_Parser parser) … … 5482 5598 { 5483 5599 const XML_Char *name; 5484 const PREFIX *oldP = (PREFIX *)hashTableIterNext(&iter);5600 const PREFIX *oldP = (PREFIX *) hashTableIterNext(&iter); 5485 5601 5486 5602 if (!oldP) … … 5501 5617 ATTRIBUTE_ID *newA; 5502 5618 const XML_Char *name; 5503 const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *)hashTableIterNext(&iter);5619 const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *) hashTableIterNext(&iter); 5504 5620 5505 5621 if (!oldA) … … 5512 5628 return 0; 5513 5629 ++name; 5514 newA = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), name, sizeof(ATTRIBUTE_ID));5630 newA = (ATTRIBUTE_ID *) lookup(&(newDtd->attributeIds), name, sizeof(ATTRIBUTE_ID)); 5515 5631 if (!newA) 5516 5632 return 0; … … 5522 5638 newA->prefix = &newDtd->defaultPrefix; 5523 5639 else 5524 newA->prefix = (PREFIX *)lookup(&(newDtd->prefixes), oldA->prefix->name, 0);5640 newA->prefix = (PREFIX *) lookup(&(newDtd->prefixes), oldA->prefix->name, 0); 5525 5641 } 5526 5642 } … … 5535 5651 ELEMENT_TYPE *newE; 5536 5652 const XML_Char *name; 5537 const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *)hashTableIterNext(&iter);5653 const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *) hashTableIterNext(&iter); 5538 5654 5539 5655 if (!oldE) … … 5542 5658 if (!name) 5543 5659 return 0; 5544 newE = (ELEMENT_TYPE *)lookup(&(newDtd->elementTypes), name, sizeof(ELEMENT_TYPE));5660 newE = (ELEMENT_TYPE *) lookup(&(newDtd->elementTypes), name, sizeof(ELEMENT_TYPE)); 5545 5661 if (!newE) 5546 5662 return 0; 5547 5663 if (oldE->nDefaultAtts) 5548 5664 { 5549 newE->defaultAtts = (DEFAULT_ATTRIBUTE *)MALLOC(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));5665 newE->defaultAtts = (DEFAULT_ATTRIBUTE *) MALLOC(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE)); 5550 5666 if (!newE->defaultAtts) 5551 5667 return 0; 5552 5668 } 5553 5669 if (oldE->idAtt) 5554 newE->idAtt = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0);5670 newE->idAtt = (ATTRIBUTE_ID *) lookup(&(newDtd->attributeIds), oldE->idAtt->name, 0); 5555 5671 newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts; 5556 5672 if (oldE->prefix) 5557 newE->prefix = (PREFIX *)lookup(&(newDtd->prefixes), oldE->prefix->name, 0);5673 newE->prefix = (PREFIX *) lookup(&(newDtd->prefixes), oldE->prefix->name, 0); 5558 5674 for (i = 0; i < newE->nDefaultAtts; i++) 5559 5675 { 5560 newE->defaultAtts[i].id = (ATTRIBUTE_ID *)lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0);5676 newE->defaultAtts[i].id = (ATTRIBUTE_ID *) lookup(&(newDtd->attributeIds), oldE->defaultAtts[i].id->name, 0); 5561 5677 newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata; 5562 5678 if (oldE->defaultAtts[i].value) … … 5613 5729 ENTITY *newE; 5614 5730 const XML_Char *name; 5615 const ENTITY *oldE = (ENTITY *)hashTableIterNext(&iter);5731 const ENTITY *oldE = (ENTITY *) hashTableIterNext(&iter); 5616 5732 5617 5733 if (!oldE) … … 5620 5736 if (!name) 5621 5737 return 0; 5622 newE = (ENTITY *)lookup(newTable, name, sizeof(ENTITY));5738 newE = (ENTITY *) lookup(newTable, name, sizeof(ENTITY)); 5623 5739 if (!newE) 5624 5740 return 0; … … 5667 5783 #define INIT_SIZE 64 5668 5784 5669 static int keyeq(KEY s1, KEY s2) 5785 static 5786 int keyeq(KEY s1, KEY s2) 5670 5787 { 5671 5788 for (; *s1 == *s2; s1++, s2++) … … 5675 5792 } 5676 5793 5677 static unsigned long hash(KEY s) 5794 static 5795 unsigned long hash(KEY s) 5678 5796 { 5679 5797 unsigned long h = 0; … … 5684 5802 } 5685 5803 5686 static NAMED *lookup(HASH_TABLE * table, KEY name, size_t createSize) 5804 static 5805 NAMED *lookup(HASH_TABLE * table, KEY name, size_t createSize) 5687 5806 { 5688 5807 size_t i; … … 5695 5814 return 0; 5696 5815 tsize = INIT_SIZE * sizeof(NAMED *); 5697 table->v = (NAMED**)table->mem->malloc_fcn(tsize);5816 table->v = table->mem->malloc_fcn(tsize); 5698 5817 if (!table->v) 5699 5818 return 0; … … 5721 5840 size_t newSize = table->size * 2; 5722 5841 size_t tsize = newSize * sizeof(NAMED *); 5723 NAMED **newV = (NAMED**)table->mem->malloc_fcn(tsize);5842 NAMED **newV = table->mem->malloc_fcn(tsize); 5724 5843 5725 5844 if (!newV) … … 5747 5866 } 5748 5867 } 5749 table->v[i] = (NAMED*)table->mem->malloc_fcn(createSize);5868 table->v[i] = table->mem->malloc_fcn(createSize); 5750 5869 if (!table->v[i]) 5751 5870 return 0; … … 5756 5875 } 5757 5876 5758 static void hashTableDestroy(HASH_TABLE * table) 5877 static 5878 void hashTableDestroy(HASH_TABLE * table) 5759 5879 { 5760 5880 size_t i; … … 5771 5891 } 5772 5892 5773 static void hashTableInit(HASH_TABLE * p, XML_Memory_Handling_Suite * ms) 5893 static 5894 void hashTableInit(HASH_TABLE * p, XML_Memory_Handling_Suite * ms) 5774 5895 { 5775 5896 p->size = 0; … … 5780 5901 } 5781 5902 5782 static void hashTableIterInit(HASH_TABLE_ITER * iter, const HASH_TABLE * table) 5903 static 5904 void hashTableIterInit(HASH_TABLE_ITER * iter, const HASH_TABLE * table) 5783 5905 { 5784 5906 iter->p = table->v; … … 5786 5908 } 5787 5909 5788 static NAMED* hashTableIterNext(HASH_TABLE_ITER * iter) 5910 static 5911 NAMED *hashTableIterNext(HASH_TABLE_ITER * iter) 5789 5912 { 5790 5913 while (iter->p != iter->end) … … 5799 5922 5800 5923 5801 static void poolInit(STRING_POOL * pool, XML_Memory_Handling_Suite * ms) 5924 static 5925 void poolInit(STRING_POOL * pool, XML_Memory_Handling_Suite * ms) 5802 5926 { 5803 5927 pool->blocks = 0; … … 5809 5933 } 5810 5934 5811 static void poolClear(STRING_POOL * pool) 5935 static 5936 void poolClear(STRING_POOL * pool) 5812 5937 { 5813 5938 if (!pool->freeBlocks) … … 5832 5957 } 5833 5958 5834 static void poolDestroy(STRING_POOL * pool) 5959 static 5960 void poolDestroy(STRING_POOL * pool) 5835 5961 { 5836 5962 BLOCK *p = pool->blocks; … … 5858 5984 } 5859 5985 5860 static XML_Char *poolAppend(STRING_POOL * pool, const ENCODING * enc, 5861 const char *ptr, const char *end) 5986 /* 5987 *@@ poolAppend: 5988 * appends a new string to a pool. 5989 * Returns pool->start if the pool is valid, 5990 * or NULL if storing failed. 5991 * 5992 * V0.9.14: I added the pulOfs parameter which, after 5993 * the string was stored, receives the offset from 5994 * pool->start at which the string was stored in the 5995 * pool. I am not quite sure how all this works, but 5996 * if a user-defined encoding is in place (via 5997 * XML_SetUnknownEncodingHandler), the first entry 5998 * in the pool is always the encoding name from the 5999 * xml header, and all entity references failed here 6000 * because the lookup would always be done for 6001 * the encoding name instead of the entity name 6002 * (which then is the second entry in the pool). 6003 * Whatever. 6004 * 6005 *@@changed V0.9.14 (2001-08-09) [umoeller]: added pulOfs param 6006 */ 6007 6008 static XML_Char* poolAppend(STRING_POOL * pool, 6009 const ENCODING * enc, 6010 const char *ptr, 6011 const char *end, 6012 unsigned long *pulOfs) // out: offset of beginning of stored 6013 // string from pool->start 6014 // V0.9.14 (2001-08-09) [umoeller] 5862 6015 { 5863 6016 if (!pool->ptr && !poolGrow(pool)) … … 5865 6018 for (;;) 5866 6019 { 5867 XmlConvert(enc, &ptr, end, (ICHAR **) & (pool->ptr), (ICHAR*)pool->end); 6020 char *pOldStart = pool->ptr; 6021 XmlConvert(enc, 6022 &ptr, // fromP 6023 end, 6024 (ICHAR**)&(pool->ptr), // toP 6025 (ICHAR *)pool->end); 6026 // expands to: 6027 // (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim)) 6028 // -- for cp850, we end up in 6029 // -- for Latin1, we end up in 6030 if (pulOfs) 6031 *pulOfs = pOldStart - pool->start; // V0.9.14 (2001-08-09) [umoeller] 6032 5868 6033 if (ptr == end) 5869 6034 break; … … 5874 6039 } 5875 6040 5876 static const XML_Char *poolCopyString(STRING_POOL * pool, const XML_Char * s) 6041 static const XML_Char* poolCopyString(STRING_POOL *pool, 6042 const XML_Char *s) 5877 6043 { 5878 6044 do … … 5902 6068 } 5903 6069 5904 static const XML_Char* poolAppendString(STRING_POOL * pool, const XML_Char * s) 6070 static const XML_Char* poolAppendString(STRING_POOL *pool, 6071 const XML_Char *s) 5905 6072 { 5906 6073 while (*s) … … 5913 6080 } /* End poolAppendString */ 5914 6081 5915 static XML_Char* poolStoreString(STRING_POOL * pool, const ENCODING * enc, 5916 const char *ptr, const char *end) 5917 { 5918 if (!poolAppend(pool, enc, ptr, end)) 6082 /* 6083 *@@ poolStoreString: 6084 * 6085 *@@changed V0.9.14 (2001-08-09) [umoeller]: added pulOfs param 6086 */ 6087 6088 static XML_Char* poolStoreString(STRING_POOL *pool, 6089 const ENCODING *enc, 6090 const char *ptr, 6091 const char *end, 6092 unsigned long *pulOfs) // V0.9.14 (2001-08-09) [umoeller] 6093 { 6094 if (!poolAppend(pool, 6095 enc, 6096 ptr, 6097 end, 6098 pulOfs)) // V0.9.14 (2001-08-09) [umoeller] 5919 6099 return 0; 5920 if (pool->ptr == pool->end && !poolGrow(pool)) 6100 if ( (pool->ptr == pool->end) 6101 && (!poolGrow(pool)) 6102 ) 5921 6103 return 0; 5922 6104 *(pool->ptr)++ = 0; … … 5924 6106 } 5925 6107 5926 static int poolGrow(STRING_POOL * 6108 static int poolGrow(STRING_POOL *pool) 5927 6109 { 5928 6110 if (pool->freeBlocks) … … 5945 6127 pool->blocks = pool->freeBlocks; 5946 6128 pool->freeBlocks = tem; 5947 memcpy(pool->blocks->s, pool->start, (pool->end - pool->start) * sizeof(XML_Char)); 6129 memcpy(pool->blocks->s, 6130 pool->start, 6131 (pool->end - pool->start) * sizeof(XML_Char)); 5948 6132 pool->ptr = pool->blocks->s + (pool->ptr - pool->start); 5949 6133 pool->start = pool->blocks->s; … … 5956 6140 int blockSize = (pool->end - pool->start) * 2; 5957 6141 5958 pool->blocks = (BLOCK*)pool->mem->realloc_fcn(pool->blocks, 5959 offsetof(BLOCK, s) 5960 + blockSize * sizeof(XML_Char)); 6142 pool->blocks = pool->mem->realloc_fcn(pool->blocks, offsetof(BLOCK, s) + blockSize * sizeof(XML_Char)); 5961 6143 if (!pool->blocks) 5962 6144 return 0; … … 5975 6157 else 5976 6158 blockSize *= 2; 5977 tem = (BLOCK*)pool->mem->malloc_fcn(offsetof(BLOCK, s) + blockSize * sizeof(XML_Char));6159 tem = pool->mem->malloc_fcn(offsetof(BLOCK, s) + blockSize * sizeof(XML_Char)); 5978 6160 if (!tem) 5979 6161 return 0; … … 5990 6172 } 5991 6173 5992 static int nextScaffoldPart(XML_Parser parser) 6174 static int 6175 nextScaffoldPart(XML_Parser parser) 5993 6176 { 5994 6177 CONTENT_SCAFFOLD *me; … … 5997 6180 if (!dtd.scaffIndex) 5998 6181 { 5999 dtd.scaffIndex = (int*)MALLOC(groupSize * sizeof(int));6182 dtd.scaffIndex = MALLOC(groupSize * sizeof(int)); 6000 6183 6001 6184 if (!dtd.scaffIndex) … … 6009 6192 { 6010 6193 dtd.scaffSize *= 2; 6011 dtd.scaffold = (CONTENT_SCAFFOLD *)REALLOC(dtd.scaffold,6194 dtd.scaffold = (CONTENT_SCAFFOLD *) REALLOC(dtd.scaffold, 6012 6195 dtd.scaffSize * sizeof(CONTENT_SCAFFOLD)); 6013 6196 } … … 6015 6198 { 6016 6199 dtd.scaffSize = 32; 6017 dtd.scaffold = (CONTENT_SCAFFOLD *)MALLOC(dtd.scaffSize * sizeof(CONTENT_SCAFFOLD));6200 dtd.scaffold = (CONTENT_SCAFFOLD *) MALLOC(dtd.scaffSize * sizeof(CONTENT_SCAFFOLD)); 6018 6201 } 6019 6202 if (!dtd.scaffold) … … 6039 6222 } /* End nextScaffoldPart */ 6040 6223 6041 static void build_node(XML_Parser parser, 6224 static void 6225 build_node(XML_Parser parser, 6042 6226 int src_node, 6043 6227 XMLCONTENT * dest, … … 6081 6265 } /* End build_node */ 6082 6266 6083 static XMLCONTENT * build_model(XML_Parser parser) 6267 static XMLCONTENT * 6268 build_model(XML_Parser parser) 6084 6269 { 6085 6270 XMLCONTENT *ret; … … 6088 6273 int allocsize = dtd.scaffCount * sizeof(XMLCONTENT) + dtd.contentStringLen; 6089 6274 6090 ret = (XMLCONTENT*)MALLOC(allocsize);6275 ret = MALLOC(allocsize); 6091 6276 if (!ret) 6092 6277 return 0; … … 6099 6284 } /* End build_model */ 6100 6285 6101 static ELEMENT_TYPE * getElementType(XML_Parser parser, 6286 static ELEMENT_TYPE * 6287 getElementType(XML_Parser parser, 6102 6288 const ENCODING * enc, 6103 6289 const char *ptr, 6104 6290 const char *end) 6105 6291 { 6106 const XML_Char *name = poolStoreString(&dtd.pool, enc, ptr, end );6292 const XML_Char *name = poolStoreString(&dtd.pool, enc, ptr, end, NULL); 6107 6293 ELEMENT_TYPE *ret; 6108 6294 6109 6295 if (!name) 6110 6296 return 0; 6111 ret = (ELEMENT_TYPE *)lookup(&dtd.elementTypes, name, sizeof(ELEMENT_TYPE));6297 ret = (ELEMENT_TYPE *) lookup(&dtd.elementTypes, name, sizeof(ELEMENT_TYPE)); 6112 6298 if (!ret) 6113 6299 return 0; … … 6122 6308 return ret; 6123 6309 } /* End getElementType */ 6124
Note:
See TracChangeset
for help on using the changeset viewer.