Ignore:
Timestamp:
Aug 12, 2001, 5:34:51 PM (24 years ago)
Author:
umoeller
Message:

XML updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/xmlparse.c

    r75 r97  
    22/*
    33 *@@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.
    1013 *
    1114 *      Expat is a library, written in C, for parsing XML @documents. It's
     
    7073        // this code generates those options HEAVILY
    7174
    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> */
    7383
    7484#ifdef __declspec
    75 #define XMLPARSEAPI __declspec(dllexport)
     85#define XMLPARSEAPI(type) __declspec(dllexport) type __cdecl
    7686#endif
    7787
     
    7989
    8090#ifdef __declspec
    81     #undef XMLPARSEAPI
     91#undef XMLPARSEAPI
    8292#endif
     93// #endif /* ndef COMPILED_FROM_DSP */
    8394
    8495#include <stddef.h>
     
    8697
    8798#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))
     105typedef unsigned short ICHAR;
     106
    95107#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)
     114typedef char ICHAR;
     115
    103116#endif
    104117
     118
    105119#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
    111127#endif
    112128
    113129#ifdef XML_UNICODE_WCHAR_T
    114     #define XML_T(x) L ## x
     130#define XML_T(x) L ## x
    115131#else
    116     #define XML_T(x) x
     132#define XML_T(x) x
    117133#endif
    118134
     
    125141typedef const XML_Char *KEY;
    126142
    127 typedef struct _NAMED
     143typedef struct
    128144{
    129145    KEY name;
    130 } NAMED, *PNAMED;
    131 
    132 typedef struct _HASH_TABLE
     146}
     147NAMED;
     148
     149typedef struct
    133150{
    134151    NAMED **v;
     
    137154    size_t usedLim;
    138155    XML_Memory_Handling_Suite *mem;
    139 } HASH_TABLE, *PHASH_TABLE;
    140 
    141 typedef struct _HASH_TABLE_ITER
     156}
     157HASH_TABLE;
     158
     159typedef struct
    142160{
    143161    NAMED **p;
    144162    NAMED **end;
    145 } HASH_TABLE_ITER, *PHASH_TABLE_ITER;
     163}
     164HASH_TABLE_ITER;
    146165
    147166#define INIT_TAG_BUF_SIZE 32    /* must be a multiple of sizeof(XML_Char) */
     
    155174typedef struct binding
    156175{
    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}
     184BINDING;
    165185
    166186typedef struct prefix
    167187{
    168     const XML_Char              *name;
    169     BINDING                     *binding;
    170 } PREFIX, *PPREFIX;
     188    const XML_Char *name;
     189    BINDING *binding;
     190}
     191PREFIX;
    171192
    172193typedef struct
    173194{
    174     const XML_Char              *str;
    175     const XML_Char              *localPart;
     195    const XML_Char *str;
     196    const XML_Char *localPart;
    176197    int uriLen;
    177 } TAG_NAME, *PTAG_NAME;
     198}
     199TAG_NAME;
    178200
    179201typedef struct tag
    180202{
    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}
     211TAG;
    189212
    190213typedef struct
    191214{
    192     const XML_Char              *name;
    193     const XML_Char              *textPtr;
    194     int                         textLen;
    195     const XML_Char              *systemId;
    196     const XML_Char              *base;
    197     const XML_Char              *publicId;
    198     const XML_Char              *notation;
     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;
    199222    char open;
    200223    char is_param;
    201 } ENTITY, *PENTITY;
     224}
     225ENTITY;
    202226
    203227typedef struct
    204228{
    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}
     237CONTENT_SCAFFOLD;
    213238
    214239typedef struct block
     
    217242    int size;
    218243    XML_Char s[1];
    219 } BLOCK, *PBLOCK;
     244}
     245BLOCK;
    220246
    221247typedef struct
     
    227253    XML_Char *start;
    228254    XML_Memory_Handling_Suite *mem;
    229 } STRING_POOL, *PSTRING_POOL;
     255}
     256STRING_POOL;
    230257
    231258/* The XML_Char before the name is used to determine whether
     
    237264    char maybeTokenized;
    238265    char xmlns;
    239 } ATTRIBUTE_ID, *PATTRIBUTE_ID;
     266}
     267ATTRIBUTE_ID;
    240268
    241269typedef struct
     
    244272    char isCdata;
    245273    const XML_Char *value;
    246 } DEFAULT_ATTRIBUTE, *PDEFAULT_ATTRIBUTE;
     274}
     275DEFAULT_ATTRIBUTE;
    247276
    248277typedef struct
     
    254283    int allocDefaultAtts;
    255284    DEFAULT_ATTRIBUTE *defaultAtts;
    256 } ELEMENT_TYPE, *PELEMENT_TYPE;
     285}
     286ELEMENT_TYPE;
    257287
    258288typedef struct
     
    277307    int scaffLevel;
    278308    int *scaffIndex;
    279 } DTD, *PDTD;
     309}
     310DTD;
    280311
    281312typedef struct open_internal_entity
     
    285316    struct open_internal_entity *next;
    286317    ENTITY *entity;
    287 } OPEN_INTERNAL_ENTITY, *POPEN_INTERNAL_ENTITY;
     318}
     319OPEN_INTERNAL_ENTITY;
    288320
    289321typedef XMLERROR Processor(XML_Parser parser,
    290                                  const char *start,
    291                                  const char *end,
    292                                  const char **endPtr);
     322                           const char *start,
     323                           const char *end,
     324                           const char **endPtr);
    293325
    294326static Processor prologProcessor;
     
    299331#ifdef XML_DTD
    300332static Processor ignoreSectionProcessor;
     333
    301334#endif /* XML_DTD */
    302 
    303335static Processor epilogProcessor;
    304336static Processor errorProcessor;
     
    308340static Processor externalEntityContentProcessor;
    309341
    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);
     342static XMLERROR
     343 handleUnknownEncoding(XML_Parser parser, const XML_Char * encodingName);
     344static XMLERROR
     345 processXmlDecl(XML_Parser parser, int isGeneralTextEntity, const char *, const char *);
     346static XMLERROR
     347 initializeEncoding(XML_Parser parser);
     348static XMLERROR
     349 doProlog(XML_Parser parser, const ENCODING * enc, const char *s,
     350          const char *end, int tok, const char *next, const char **nextPtr);
     351static XMLERROR
     352 processInternalParamEntity(XML_Parser parser, ENTITY * entity);
     353static XMLERROR
     354 doContent(XML_Parser parser, int startTagLevel, const ENCODING * enc,
     355           const char *start, const char *end, const char **endPtr);
     356static XMLERROR
     357 doCdataSection(XML_Parser parser, const ENCODING *, const char **startPtr, const char *end, const char **nextPtr);
    337358
    338359#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);
     360static XMLERROR
     361 doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr, const char *end, const char **nextPtr);
     362
    344363#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);
     364static XMLERROR storeAtts(XML_Parser parser, const ENCODING *, const char *s,
     365                          TAG_NAME * tagNamePtr, BINDING ** bindingsPtr);
     366static
     367int addBinding(XML_Parser parser, PREFIX * prefix, const ATTRIBUTE_ID * attId, const XML_Char * uri, BINDING ** bindingsPtr);
     368
     369static int
     370 defineAttribute(ELEMENT_TYPE * type, ATTRIBUTE_ID *,
     371                 int isCdata, int isId, const XML_Char * dfltValue,
     372                 XML_Parser parser);
     373
     374static XMLERROR
     375 storeAttributeValue(XML_Parser parser, const ENCODING *, int isCdata, const char *, const char *,
     376                     STRING_POOL *);
     377static XMLERROR
     378 appendAttributeValue(XML_Parser parser, const ENCODING *, int isCdata, const char *, const char *,
     379                      STRING_POOL *);
     380static ATTRIBUTE_ID *
     381 getAttributeId(XML_Parser parser, const ENCODING * enc, const char *start, const char *end);
    380382static 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);
     383static XMLERROR
     384 storeEntityValue(XML_Parser parser, const ENCODING * enc, const char *start, const char *end);
     385static int
     386 reportProcessingInstruction(XML_Parser parser, const ENCODING * enc, const char *start, const char *end);
     387static int
     388 reportComment(XML_Parser parser, const ENCODING * enc, const char *start, const char *end);
     389static void
     390 reportDefault(XML_Parser parser, const ENCODING * enc, const char *start, const char *end);
    397391
    398392static const XML_Char *getContext(XML_Parser parser);
     
    405399static int dtdCopy(DTD * newDtd, const DTD * oldDtd, XML_Parser parser);
    406400
    407 static int copyEntityTable(HASH_TABLE *,
    408                            STRING_POOL *,
    409                            const HASH_TABLE *,
     401static int copyEntityTable(HASH_TABLE *, STRING_POOL *, const HASH_TABLE *,
    410402                           XML_Parser parser);
    411403
    412404#ifdef XML_DTD
    413405static void dtdSwap(DTD *, DTD *);
     406
    414407#endif /* XML_DTD */
    415408
     
    424417static void poolClear(STRING_POOL *);
    425418static 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);
     419static 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]
     424static 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]
    430429
    431430static int poolGrow(STRING_POOL * pool);
     
    502501    void *m_unknownEncodingData;
    503502    void *m_unknownEncodingHandlerData;
    504     void (* EXPATENTRY m_unknownEncodingRelease) (void *);
     503    void (*m_unknownEncodingRelease) (void *);
    505504    PROLOG_STATE m_prologState;
    506505    Processor *m_processor;
     
    544543    XML_Parser m_parentParser;
    545544#endif
    546 } Parser, *PParser;
     545}
     546Parser;
    547547
    548548#define MALLOC(s) (((Parser *)parser)->m_mem.malloc_fcn((s)))
     
    569569#define externalEntityRefHandler (((Parser *)parser)->m_externalEntityRefHandler)
    570570#define externalEntityRefHandlerArg (((Parser *)parser)->m_externalEntityRefHandlerArg)
     571#define internalEntityRefHandler (((Parser *)parser)->m_internalEntityRefHandler)
    571572#define unknownEncodingHandler (((Parser *)parser)->m_unknownEncodingHandler)
    572573#define elementDeclHandler (((Parser *)parser)->m_elementDeclHandler)
     
    579580#define unknownEncodingMem (((Parser *)parser)->m_unknownEncodingMem)
    580581#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)
    583585#define protocolEncodingName (((Parser *)parser)->m_protocolEncodingName)
    584586#define ns (((Parser *)parser)->m_ns)
     
    594596#define defaultExpandInternalEntities (((Parser *)parser)->m_defaultExpandInternalEntities)
    595597#define tagLevel (((Parser *)parser)->m_tagLevel)
    596 #define buffer (((Parser*)parser)->m_buffer)
     598#define buffer (((Parser *)parser)->m_buffer)
    597599#define bufferPtr (((Parser *)parser)->m_bufferPtr)
    598600#define bufferEnd (((Parser *)parser)->m_bufferEnd)
     
    634636#endif /* XML_DTD */
    635637
     638#ifdef COMPILED_FROM_DSP
     639BOOL 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
     647Parser *asParser(XML_Parser parser)
     648{
     649    return parser;
     650}
     651#endif
     652#endif
     653
    636654/*
    637655 *@@ XML_ParserCreate:
     
    748766 */
    749767
    750 XML_Parser XML_ParserCreate(const XML_Char* encodingName)
     768XML_Parser XML_ParserCreate(const XML_Char * encodingName)
    751769{
    752770    return XML_ParserCreate_MM(encodingName, NULL, NULL);
     
    830848 */
    831849
    832 XML_Parser XML_ParserCreate_MM(const XML_Char * encodingName,
    833                                const XML_Memory_Handling_Suite * memsuite,
    834                                const XML_Char * nameSep)
     850XML_Parser
     851XML_ParserCreate_MM(const XML_Char * encodingName,
     852                    const XML_Memory_Handling_Suite * memsuite,
     853                    const XML_Char * nameSep)
    835854{
    836855
     
    857876
    858877        parser = memsuite->malloc_fcn(sizeof(Parser));
    859         mtemp = &(((Parser*)parser)->m_mem);
     878        mtemp = &(((Parser *) parser)->m_mem);
    860879        mtemp->malloc_fcn = memsuite->malloc_fcn;
    861880        mtemp->realloc_fcn = memsuite->realloc_fcn;
     
    866885        XML_Memory_Handling_Suite *mtemp;
    867886
    868         parser = (malloc)(sizeof(Parser));
    869         mtemp = &(((Parser*)parser)->m_mem);
    870 
     887        parser = malloc(sizeof(Parser));
     888        mtemp = &(((Parser *) parser)->m_mem);
    871889        mtemp->malloc_fcn = malloc;
    872890        mtemp->realloc_fcn = realloc;
     
    929947    inheritedBindings = 0;
    930948    attsSize = INIT_ATTS_SIZE;
    931     atts = (PATTRIBUTE)MALLOC(attsSize * sizeof(ATTRIBUTE));
     949    atts = MALLOC(attsSize * sizeof(ATTRIBUTE));
    932950    nSpecifiedAtts = 0;
    933     dataBuf = (XML_Char*)MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));
     951    dataBuf = MALLOC(INIT_DATA_BUF_SIZE * sizeof(XML_Char));
    934952    groupSize = 0;
    935953    groupConnector = 0;
     
    946964    ns = 0;
    947965    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));
    950968    protocolEncodingName = encodingName ? poolCopyString(&tempPool, encodingName) : 0;
    951969    curBase = 0;
     
    10471065
    10481066#ifdef XML_DTD
    1049     enum XML_ParamEntityParsing oldParamEntityParsing = paramEntityParsing;
     1067    int oldParamEntityParsing = paramEntityParsing;
    10501068
    10511069#endif
     
    10571075
    10581076        *tmp = namespaceSeparator;
    1059         parser = XML_ParserCreate_MM(encodingName, &((Parser*)parser)->m_mem,
     1077        parser = XML_ParserCreate_MM(encodingName, &((Parser *) parser)->m_mem,
    10601078                                     tmp);
    10611079    }
    10621080    else
    10631081    {
    1064         parser = XML_ParserCreate_MM(encodingName, &((Parser*)parser)->m_mem,
     1082        parser = XML_ParserCreate_MM(encodingName, &((Parser *) parser)->m_mem,
    10651083                                     NULL);
    10661084    }
     
    11231141}
    11241142
    1125 static void destroyBindings(BINDING * bindings, XML_Parser parser)
     1143static
     1144void destroyBindings(BINDING * bindings, XML_Parser parser)
    11261145{
    11271146    for (;;)
     
    11721191        if (hadExternalDoctype)
    11731192            dtd.complete = 0;
    1174         dtdSwap(&dtd, &((Parser*)parentParser)->m_dtd);
     1193        dtdSwap(&dtd, &((Parser *) parentParser)->m_dtd);
    11751194    }
    11761195#endif /* XML_DTD */
     
    12751294 */
    12761295
    1277 const XML_Char* XML_GetBase(XML_Parser parser)
     1296const XML_Char *XML_GetBase(XML_Parser parser)
    12781297{
    12791298    return curBase;
     
    14331452
    14341453void XML_SetProcessingInstructionHandler(XML_Parser parser,
    1435                                          XML_ProcessingInstructionHandler handler)
     1454                                     XML_ProcessingInstructionHandler handler)
    14361455{
    14371456    processingInstructionHandler = handler;
     
    17411760 *      Handler prototype:
    17421761 +
    1743  +      int EXPATENTRY ExternalEntityRefHandler(XML_Parser parser,
     1762 +      int EXPATENTRY ExternalEntityRefHandler(void *pUser,
     1763 +                                              XML_Parser parser,
    17441764 +                                              const XML_Char *pcszContext,
    17451765 +                                              const XML_Char *pcszBase,
     
    17871807 *      external entities may refer to other external entities, your
    17881808 *      handler should be prepared to be called recursively.
     1809 *
     1810 *@@changed V0.9.14 (2001-08-09) [umoeller]: changed prototype to contain user data
    17891811 */
    17901812
     
    18411863 *
    18421864 *      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 *
    18611867 */
    18621868
     
    20732079 */
    20742080
    2075 int XML_Parse(XML_Parser parser,
    2076               const char *s,
    2077               int len,
    2078               int isFinal)
     2081int XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
    20792082{
    20802083    if (len == 0)
     
    20832086            return 1;
    20842087        positionPtr = bufferPtr;
    2085         errorCode = processor(parser,
    2086                               bufferPtr,
    2087                               parseEndPtr = bufferEnd,
    2088                               0);
     2088        errorCode = processor(parser, bufferPtr, parseEndPtr = bufferEnd, 0);
    20892089        if (errorCode == ERROR_EXPAT_NONE)
    20902090            return 1;
     
    21032103        if (isFinal)
    21042104        {
    2105             errorCode = processor(parser,
    2106                                   s,
    2107                                   parseEndPtr = s + len,
    2108                                   0);
     2105            errorCode = processor(parser, s, parseEndPtr = s + len, 0);
    21092106            if (errorCode == ERROR_EXPAT_NONE)
    21102107                return 1;
     
    21272124            {
    21282125                /* 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);
    21302127                /* FIXME storage leak if realloc fails */
    21312128                if (!buffer)
     
    22122209 */
    22132210
    2214 void* XML_GetBuffer(XML_Parser parser, int len)
     2211void *XML_GetBuffer(XML_Parser parser, int len)
    22152212{
    22162213    if (len > bufferLim - bufferEnd)
     
    22552252            }
    22562253            while (bufferSize < neededSize);
    2257             newBuf = (char*)MALLOC(bufferSize);
     2254            newBuf = MALLOC(bufferSize);
    22582255            if (newBuf == 0)
    22592256            {
     
    23622359 */
    23632360
    2364 const char* XML_GetInputContext(XML_Parser parser, int *offset, int *size)
     2361const char *XML_GetInputContext(XML_Parser parser, int *offset, int *size)
    23652362{
    23662363#ifdef XML_CONTEXT_BYTES
     
    24292426}
    24302427
    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)
     2428const 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
     2479static
     2480XMLERROR contentProcessor(XML_Parser parser,
     2481                          const char *start,
     2482                          const char *end,
     2483                          const char **endPtr)
    24452484{
    24462485    return doContent(parser, 0, encoding, start, end, endPtr);
    24472486}
    24482487
    2449 static XMLERROR externalEntityInitProcessor(XML_Parser parser,
    2450                                                   const char *start,
    2451                                                   const char *end,
    2452                                                   const char **endPtr)
     2488static
     2489XMLERROR externalEntityInitProcessor(XML_Parser parser,
     2490                                     const char *start,
     2491                                     const char *end,
     2492                                     const char **endPtr)
    24532493{
    24542494    XMLERROR result = initializeEncoding(parser);
     
    24602500}
    24612501
    2462 static XMLERROR externalEntityInitProcessor2(XML_Parser parser,
    2463                                                    const char *start,
    2464                                                    const char *end,
    2465                                                    const char **endPtr)
     2502static
     2503XMLERROR externalEntityInitProcessor2(XML_Parser parser,
     2504                                      const char *start,
     2505                                      const char *end,
     2506                                      const char **endPtr)
    24662507{
    24672508    const char *next;
     
    24942535}
    24952536
    2496 static XMLERROR externalEntityInitProcessor3(XML_Parser parser,
    2497                                                    const char *start,
    2498                                                    const char *end,
    2499                                                    const char **endPtr)
     2537static
     2538XMLERROR externalEntityInitProcessor3(XML_Parser parser,
     2539                                      const char *start,
     2540                                      const char *end,
     2541                                      const char **endPtr)
    25002542{
    25012543    const char *next;
     
    25352577}
    25362578
    2537 static XMLERROR externalEntityContentProcessor(XML_Parser parser,
    2538                                                      const char *start,
    2539                                                      const char *end,
    2540                                                      const char **endPtr)
     2579static
     2580XMLERROR externalEntityContentProcessor(XML_Parser parser,
     2581                                        const char *start,
     2582                                        const char *end,
     2583                                        const char **endPtr)
    25412584{
    25422585    return doContent(parser, 1, encoding, start, end, endPtr);
    25432586}
    25442587
    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
     2594static XMLERROR doContent(XML_Parser parser,
     2595                          int startTagLevel,
     2596                          const ENCODING * enc,
     2597                          const char *s,
     2598                          const char *end,
     2599                          const char **nextPtr)
    25522600{
    25532601    const char **eventPP;
     
    26272675                    const XML_Char *name;
    26282676                    ENTITY *entity;
     2677                    unsigned long ulOfs; // V0.9.14 (2001-08-09) [umoeller]
    26292678                    XML_Char ch = XmlPredefinedEntityName(enc,
    2630                                                      s + enc->minBytesPerChar,
    2631                                                  next - enc->minBytesPerChar);
     2679                                                          s + enc->minBytesPerChar,
     2680                                                          next - enc->minBytesPerChar);
    26322681
    26332682                    if (ch)
     
    26392688                        break;
    26402689                    }
    2641                     name = poolStoreString(&dtd.pool, enc,
     2690                    name = poolStoreString(&dtd.pool,
     2691                                           enc,
    26422692                                           s + enc->minBytesPerChar,
    2643                                            next - enc->minBytesPerChar);
     2693                                           next - enc->minBytesPerChar,
     2694                                           &ulOfs);
    26442695                    if (!name)
    26452696                        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);
    26472700                    poolDiscard(&dtd.pool);
    26482701                    if (!entity)
     
    26962749                            if (!context)
    26972750                                return ERROR_EXPAT_NO_MEMORY;
    2698                             if (!externalEntityRefHandler(externalEntityRefHandlerArg,
     2751                            if (!externalEntityRefHandler(handlerArg,   // V0.9.14 (2001-08-09) [umoeller]
     2752                                                          externalEntityRefHandlerArg,
    26992753                                                          context,
    27002754                                                          entity->base,
     
    27292783                    else
    27302784                    {
    2731                         tag = (TAG*)MALLOC(sizeof(TAG));
     2785                        tag = MALLOC(sizeof(TAG));
    27322786                        if (!tag)
    27332787                            return ERROR_EXPAT_NO_MEMORY;
    2734                         tag->buf = (char*)MALLOC(INIT_TAG_BUF_SIZE);
     2788                        tag->buf = MALLOC(INIT_TAG_BUF_SIZE);
    27352789                        if (!tag->buf)
    27362790                            return ERROR_EXPAT_NO_MEMORY;
     
    27522806
    27532807                            bufSize = ROUND_UP(bufSize, sizeof(XML_Char));
    2754                             tag->buf = (char*)REALLOC(tag->buf, bufSize);
     2808                            tag->buf = REALLOC(tag->buf, bufSize);
    27552809                            if (!tag->buf)
    27562810                                return ERROR_EXPAT_NO_MEMORY;
     
    27732827
    27742828                            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)));
    27762830                            else
    2777                                 toPtr = (XML_Char*)tag->buf;
     2831                                toPtr = (XML_Char *) tag->buf;
    27782832                            tag->name.str = toPtr;
    27792833                            XmlConvert(enc,
    27802834                                       &fromPtr, rawNameEnd,
    2781                                (ICHAR **) & toPtr, (ICHAR*)tag->bufEnd - 1);
     2835                               (ICHAR **) & toPtr, (ICHAR *) tag->bufEnd - 1);
    27822836                            if (fromPtr == rawNameEnd)
    27832837                                break;
    27842838                            bufSize = (tag->bufEnd - tag->buf) << 1;
    2785                             tag->buf = (char*)REALLOC(tag->buf, bufSize);
     2839                            tag->buf = REALLOC(tag->buf, bufSize);
    27862840                            if (!tag->buf)
    27872841                                return ERROR_EXPAT_NO_MEMORY;
     
    28222876                    TAG_NAME name;
    28232877
    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);
    28262883                    if (!name.str)
    28272884                        return ERROR_EXPAT_NO_MEMORY;
     
    28822939                        if (tag->name.localPart)
    28832940                        {
    2884                             XML_Char *to = (XML_Char*)tag->name.str + tag->name.uriLen;
     2941                            XML_Char *to = (XML_Char *) tag->name.str + tag->name.uriLen;
    28852942                            const XML_Char *from = tag->name.localPart;
    28862943
     
    29172974                        XML_Char buf[XML_ENCODE_MAX];
    29182975
    2919                         characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR*)buf));
     2976                        characterDataHandler(handlerArg, buf, XmlEncode(n, (ICHAR *) buf));
    29202977                    }
    29212978                    else if (defaultHandler)
     
    29763033                    if (MUST_CONVERT(enc, s))
    29773034                    {
    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);
    29823039                    }
    29833040                    else
    29843041                        characterDataHandler(handlerArg,
    2985                                              (XML_Char*)s,
    2986                                            (XML_Char*)end - (XML_Char*)s);
     3042                                             (XML_Char *) s,
     3043                                           (XML_Char *) end - (XML_Char *) s);
    29873044                }
    29883045                else if (defaultHandler)
     
    30063063                        for (;;)
    30073064                        {
    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);
    30113068                            *eventEndPP = s;
    3012                             characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR*)dataBuf);
     3069                            characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *) dataBuf);
    30133070                            if (s == next)
    30143071                                break;
     
    30183075                    else
    30193076                        characterDataHandler(handlerArg,
    3020                                              (XML_Char*)s,
    3021                                           (XML_Char*)next - (XML_Char*)s);
     3077                                             (XML_Char *) s,
     3078                                          (XML_Char *) next - (XML_Char *) s);
    30223079                }
    30233080                else if (defaultHandler)
     
    30453102 * otherwise just check the attributes for well-formedness. */
    30463103
    3047 static XMLERROR storeAtts(XML_Parser parser,
    3048                                 const ENCODING * enc,
    3049                                 const char *attStr,
    3050                                 TAG_NAME * tagNamePtr,
    3051                                 BINDING ** bindingsPtr)
     3104static XMLERROR storeAtts(XML_Parser parser, const ENCODING * enc,
     3105                          const char *attStr, TAG_NAME * tagNamePtr,
     3106                          BINDING ** bindingsPtr)
    30523107{
    30533108    ELEMENT_TYPE *elementType = 0;
     
    30643119    if (tagNamePtr)
    30653120    {
    3066         elementType = (ELEMENT_TYPE*)lookup(&dtd.elementTypes, tagNamePtr->str, 0);
     3121        elementType = (ELEMENT_TYPE *) lookup(&dtd.elementTypes, tagNamePtr->str, 0);
    30673122        if (!elementType)
    30683123        {
     
    30703125            if (!tagNamePtr->str)
    30713126                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));
    30733128            if (!elementType)
    30743129                return ERROR_EXPAT_NO_MEMORY;
     
    30853140
    30863141        attsSize = n + nDefaultAtts + INIT_ATTS_SIZE;
    3087         atts = (PATTRIBUTE)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));
     3142        atts = REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));
    30883143        if (!atts)
    30893144            return ERROR_EXPAT_NO_MEMORY;
     
    31473202        {
    31483203            /* 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);
    31503209            if (appAtts[attIndex] == 0)
    31513210                return ERROR_EXPAT_NO_MEMORY;
     
    32313290                ATTRIBUTE_ID *id;
    32323291
    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);
    32353294                if (id->prefix->binding)
    32363295                {
     
    32713330            }
    32723331            else
    3273                 ((XML_Char*)(appAtts[i]))[-1] = 0;
     3332                ((XML_Char *) (appAtts[i]))[-1] = 0;
    32743333        }
    32753334    }
    32763335    /* clear the flags that say whether attributes were specified */
    32773336    for (; i < attIndex; i += 2)
    3278         ((XML_Char*)(appAtts[i]))[-1] = 0;
     3337        ((XML_Char *) (appAtts[i]))[-1] = 0;
    32793338    if (!tagNamePtr)
    32803339        return ERROR_EXPAT_NONE;
     
    33063365    {
    33073366        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));
    33093368
    33103369        if (!uri)
     
    33233382}
    33243383
    3325 static int addBinding(XML_Parser parser, PREFIX * prefix, const ATTRIBUTE_ID * attId, const XML_Char * uri, BINDING ** bindingsPtr)
     3384static
     3385int addBinding(XML_Parser parser, PREFIX * prefix, const ATTRIBUTE_ID * attId, const XML_Char * uri, BINDING ** bindingsPtr)
    33263386{
    33273387    BINDING *b;
     
    33373397        if (len > b->uriAlloc)
    33383398        {
    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));
    33403400            if (!b->uri)
    33413401                return 0;
     
    33463406    else
    33473407    {
    3348         b = (PBINDING)MALLOC(sizeof(BINDING));
     3408        b = MALLOC(sizeof(BINDING));
    33493409        if (!b)
    33503410            return 0;
    3351         b->uri = (XML_Char*)MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE));
     3411        b->uri = MALLOC(sizeof(XML_Char) * (len + EXPAND_SPARE));
    33523412        if (!b->uri)
    33533413        {
     
    33793439 * the whole file is parsed with one call. */
    33803440
    3381 static XMLERROR cdataSectionProcessor(XML_Parser parser,
    3382                                      const char *start,
    3383                                      const char *end,
    3384                                      const char **endPtr)
     3441static
     3442XMLERROR cdataSectionProcessor(XML_Parser parser,
     3443                               const char *start,
     3444                               const char *end,
     3445                               const char **endPtr)
    33853446{
    33863447    XMLERROR result = doCdataSection(parser, encoding, &start, end, endPtr);
     
    33973458 * the section is not yet closed. */
    33983459
    3399 static XMLERROR doCdataSection(XML_Parser parser,
    3400                               const ENCODING * enc,
    3401                               const char **startPtr,
    3402                               const char *end,
    3403                               const char **nextPtr)
     3460static
     3461XMLERROR doCdataSection(XML_Parser parser,
     3462                        const ENCODING * enc,
     3463                        const char **startPtr,
     3464                        const char *end,
     3465                        const char **nextPtr)
    34043466{
    34053467    const char *s = *startPtr;
     
    34573519                        for (;;)
    34583520                        {
    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);
    34623524                            *eventEndPP = next;
    3463                             characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR*)dataBuf);
     3525                            characterDataHandler(handlerArg, dataBuf, dataPtr - (ICHAR *) dataBuf);
    34643526                            if (s == next)
    34653527                                break;
     
    34693531                    else
    34703532                        characterDataHandler(handlerArg,
    3471                                              (XML_Char*)s,
    3472                                           (XML_Char*)next - (XML_Char*)s);
     3533                                             (XML_Char *) s,
     3534                                          (XML_Char *) next - (XML_Char *) s);
    34733535                }
    34743536                else if (defaultHandler)
     
    35073569 * the whole file is parsed with one call. */
    35083570
    3509 static XMLERROR ignoreSectionProcessor(XML_Parser parser,
    3510                                       const char *start,
    3511                                       const char *end,
    3512                                       const char **endPtr)
     3571static
     3572XMLERROR ignoreSectionProcessor(XML_Parser parser,
     3573                                const char *start,
     3574                                const char *end,
     3575                                const char **endPtr)
    35133576{
    35143577    XMLERROR result = doIgnoreSection(parser, encoding, &start, end, endPtr);
     
    35253588 * the section is not yet closed. */
    35263589
    3527 static XMLERROR doIgnoreSection(XML_Parser parser,
    3528                                const ENCODING * enc,
    3529                                const char **startPtr,
    3530                                const char *end,
    3531                                const char **nextPtr)
     3590static
     3591XMLERROR doIgnoreSection(XML_Parser parser,
     3592                         const ENCODING * enc,
     3593                         const char **startPtr,
     3594                         const char *end,
     3595                         const char **nextPtr)
    35323596{
    35333597    const char *next;
     
    35763640                return ERROR_EXPAT_NONE;
    35773641            }
    3578             return ERROR_EXPAT_SYNTAX;    /* ERROR_EXPAT_UNCLOSED_IGNORE_SECTION */
     3642            return ERROR_EXPAT_SYNTAX;  /* ERROR_EXPAT_UNCLOSED_IGNORE_SECTION */
    35793643        default:
    35803644            *eventPP = next;
     
    35863650#endif /* XML_DTD */
    35873651
    3588 static XMLERROR  initializeEncoding(XML_Parser parser)
     3652static XMLERROR
     3653 initializeEncoding(XML_Parser parser)
    35893654{
    35903655    const char *s;
     
    36203685}
    36213686
    3622 static XMLERROR  processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
     3687static XMLERROR
     3688 processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
    36233689                const char *s, const char *next)
    36243690{
     
    36603726                                            encodingName,
    36613727                                            encodingName
    3662                                      + XmlNameLength(encoding, encodingName));
     3728                                            + XmlNameLength(encoding, encodingName),
     3729                                            NULL);
    36633730            if (!storedEncName)
    36643731                return ERROR_EXPAT_NO_MEMORY;
     
    36703737                                            encoding,
    36713738                                            version,
    3672                                       versionend - encoding->minBytesPerChar);
     3739                                            versionend - encoding->minBytesPerChar,
     3740                                            NULL);
    36733741            if (!storedversion)
    36743742                return ERROR_EXPAT_NO_MEMORY;
     
    36993767                                                encodingName,
    37003768                                                encodingName
    3701                                      + XmlNameLength(encoding, encodingName));
     3769                                                + XmlNameLength(encoding, encodingName),
     3770                                                NULL);
    37023771                if (!storedEncName)
    37033772                    return ERROR_EXPAT_NO_MEMORY;
     
    37173786}
    37183787
    3719 static XMLERROR handleUnknownEncoding(XML_Parser parser,
    3720                                             const XML_Char* encodingName)
     3788static XMLERROR
     3789 handleUnknownEncoding(XML_Parser parser, const XML_Char * encodingName)
    37213790{
    37223791    if (unknownEncodingHandler)
     
    37303799        info.data = 0;
    37313800        info.release = 0;
    3732         if (unknownEncodingHandler(unknownEncodingHandlerData,
    3733                                    encodingName,
    3734                                    &info))
     3801        if (unknownEncodingHandler(unknownEncodingHandlerData, encodingName, &info))
    37353802        {
    37363803            ENCODING *enc;
     
    37633830}
    37643831
    3765 static XMLERROR prologInitProcessor(XML_Parser parser,
     3832static XMLERROR
     3833 prologInitProcessor(XML_Parser parser,
    37663834                     const char *s,
    37673835                     const char *end,
     
    37763844}
    37773845
    3778 static XMLERROR prologProcessor(XML_Parser parser,
     3846static XMLERROR
     3847 prologProcessor(XML_Parser parser,
    37793848                 const char *s,
    37803849                 const char *end,
     
    37873856}
    37883857
    3789 static XMLERROR doProlog(XML_Parser parser,
     3858static XMLERROR
     3859 doProlog(XML_Parser parser,
    37903860          const ENCODING * enc,
    37913861          const char *s,
     
    38723942                if (startDoctypeDeclHandler)
    38733943                {
    3874                     doctypeName = poolStoreString(&tempPool, enc, s, next);
     3944                    doctypeName = poolStoreString(&tempPool, enc, s, next, NULL);
    38753945                    if (!doctypeName)
    38763946                        return ERROR_EXPAT_NO_MEMORY;
     
    39033973                if (startDoctypeDeclHandler)
    39043974                {
    3905                     doctypePubid = poolStoreString(&tempPool, enc, s + 1, next - 1);
     3975                    doctypePubid = poolStoreString(&tempPool, enc, s + 1, next - 1, NULL);
    39063976                    if (!doctypePubid)
    39073977                        return ERROR_EXPAT_NO_MEMORY;
     
    39093979                }
    39103980#ifdef XML_DTD
    3911                 declEntity = (ENTITY*)lookup(&dtd.paramEntities,
     3981                declEntity = (ENTITY *) lookup(&dtd.paramEntities,
    39123982                                               externalSubsetName,
    39133983                                               sizeof(ENTITY));
     
    39243994                                                    enc,
    39253995                                                    s + enc->minBytesPerChar,
    3926                                                  next - enc->minBytesPerChar);
     3996                                                    next - enc->minBytesPerChar,
     3997                                                    NULL);
    39273998
    39283999                    if (!tem)
     
    39464017                    if (paramEntityParsing && externalEntityRefHandler)
    39474018                    {
    3948                         ENTITY *entity = (ENTITY*)lookup(&dtd.paramEntities,
     4019                        ENTITY *entity = (ENTITY *) lookup(&dtd.paramEntities,
    39494020                                                           externalSubsetName,
    39504021                                                           0);
    39514022
    3952                         if (!externalEntityRefHandler(externalEntityRefHandlerArg,
     4023                        if (!externalEntityRefHandler(handlerArg,   // V0.9.14 (2001-08-09) [umoeller]
     4024                                                      externalEntityRefHandlerArg,
    39534025                                                      0,
    39544026                                                      entity->base,
     
    40284100                    if (!poolAppendString(&tempPool, prefix))
    40294101                        return ERROR_EXPAT_NO_MEMORY;
    4030                     if (!poolAppend(&tempPool, enc, s, next))
     4102                    if (!poolAppend(&tempPool, enc, s, next, NULL))
    40314103                        return ERROR_EXPAT_NO_MEMORY;
    40324104                    declAttributeType = tempPool.start;
     
    40434115                {
    40444116                    if (*declAttributeType == '('
    4045                         || *declAttributeType == 'N' && declAttributeType[1] == 'O')
     4117                        || (*declAttributeType == 'N' && declAttributeType[1] == 'O'))
    40464118                    {
    40474119                        /* Enumerated or Notation type */
     
    40804152                    {
    40814153                        if (*declAttributeType == '('
    4082                             || *declAttributeType == 'N' && declAttributeType[1] == 'O')
     4154                            || (*declAttributeType == 'N' && declAttributeType[1] == 'O'))
    40834155                        {
    40844156                            /* Enumerated or Notation type */
     
    41294201                if (startDoctypeDeclHandler)
    41304202                {
    4131                     doctypeSysid = poolStoreString(&tempPool, enc, s + 1, next - 1);
     4203                    doctypeSysid = poolStoreString(&tempPool,
     4204                                                   enc,
     4205                                                   s + 1,
     4206                                                   next - 1,
     4207                                                   NULL);
    41324208                    if (!doctypeSysid)
    41334209                        return ERROR_EXPAT_NO_MEMORY;
     
    41474223                if (!declEntity)
    41484224                {
    4149                     declEntity = (ENTITY*)lookup(&dtd.paramEntities,
     4225                    declEntity = (ENTITY *) lookup(&dtd.paramEntities,
    41504226                                                   externalSubsetName,
    41514227                                                   sizeof(ENTITY));
     
    41594235                if (declEntity)
    41604236                {
    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);
    41644242                    if (!declEntity->systemId)
    41654243                        return ERROR_EXPAT_NO_MEMORY;
     
    41844262                if (declEntity)
    41854263                {
    4186                     declEntity->notation = poolStoreString(&dtd.pool, enc, s, next);
     4264                    declEntity->notation = poolStoreString(&dtd.pool,
     4265                                                           enc,
     4266                                                           s,
     4267                                                           next,
     4268                                                           NULL);
    41874269                    if (!declEntity->notation)
    41884270                        return ERROR_EXPAT_NO_MEMORY;
     
    42204302                        break;
    42214303                    }
    4222                     name = poolStoreString(&dtd.pool, enc, s, next);
     4304                    name = poolStoreString(&dtd.pool,
     4305                                           enc,
     4306                                           s,
     4307                                           next,
     4308                                           NULL);
    42234309                    if (!name)
    42244310                        return ERROR_EXPAT_NO_MEMORY;
    42254311                    if (dtd.complete)
    42264312                    {
    4227                         declEntity = (ENTITY*)lookup(&dtd.generalEntities, name, sizeof(ENTITY));
     4313                        declEntity = (ENTITY *) lookup(&dtd.generalEntities, name, sizeof(ENTITY));
    42284314                        if (!declEntity)
    42294315                            return ERROR_EXPAT_NO_MEMORY;
     
    42514337                if (dtd.complete)
    42524338                {
    4253                     const XML_Char *name = poolStoreString(&dtd.pool, enc, s, next);
     4339                    const XML_Char *name = poolStoreString(&dtd.pool, enc, s, next, NULL);
    42544340
    42554341                    if (!name)
    42564342                        return ERROR_EXPAT_NO_MEMORY;
    4257                     declEntity = (ENTITY*)lookup(&dtd.paramEntities,
     4343                    declEntity = (ENTITY *) lookup(&dtd.paramEntities,
    42584344                                                   name, sizeof(ENTITY));
    42594345                    if (!declEntity)
     
    42804366                if (notationDeclHandler)
    42814367                {
    4282                     declNotationName = poolStoreString(&tempPool, enc, s, next);
     4368                    declNotationName = poolStoreString(&tempPool, enc, s, next, NULL);
    42834369                    if (!declNotationName)
    42844370                        return ERROR_EXPAT_NO_MEMORY;
     
    42944380                                                    enc,
    42954381                                                    s + enc->minBytesPerChar,
    4296                                                  next - enc->minBytesPerChar);
     4382                                                    next - enc->minBytesPerChar,
     4383                                                    NULL);
    42974384
    42984385                    if (!tem)
     
    43094396                    = poolStoreString(&tempPool, enc,
    43104397                                      s + enc->minBytesPerChar,
    4311                                       next - enc->minBytesPerChar);
     4398                                      next - enc->minBytesPerChar,
     4399                                      NULL);
    43124400
    43134401                    if (!systemId)
     
    43654453                    if (groupSize)
    43664454                    {
    4367                         groupConnector = (char*)REALLOC(groupConnector, groupSize *= 2);
     4455                        groupConnector = REALLOC(groupConnector, groupSize *= 2);
    43684456                        if (dtd.scaffIndex)
    4369                             dtd.scaffIndex = (int*)REALLOC(dtd.scaffIndex, groupSize * sizeof(int));
     4457                            dtd.scaffIndex = REALLOC(dtd.scaffIndex, groupSize * sizeof(int));
    43704458                    }
    43714459                    else
    4372                         groupConnector = (char*)MALLOC(groupSize = 32);
     4460                        groupConnector = MALLOC(groupSize = 32);
    43734461                    if (!groupConnector)
    43744462                        return ERROR_EXPAT_NO_MEMORY;
     
    44144502                    name = poolStoreString(&dtd.pool, enc,
    44154503                                           s + enc->minBytesPerChar,
    4416                                            next - enc->minBytesPerChar);
     4504                                           next - enc->minBytesPerChar,
     4505                                           NULL);
    44174506                    if (!name)
    44184507                        return ERROR_EXPAT_NO_MEMORY;
    4419                     entity = (ENTITY*)lookup(&dtd.paramEntities, name, 0);
     4508                    entity = (ENTITY *) lookup(&dtd.paramEntities, name, 0);
    44204509                    poolDiscard(&dtd.pool);
    44214510                    if (!entity)
     
    44414530                        dtd.complete = 0;
    44424531                        entity->open = 1;
    4443                         if (!externalEntityRefHandler(externalEntityRefHandlerArg,
     4532                        if (!externalEntityRefHandler(handlerArg,       // V0.9.14 (2001-08-09) [umoeller]
     4533                                                      externalEntityRefHandlerArg,
    44444534                                                      0,
    44454535                                                      entity->base,
     
    44854575                    if (elementDeclHandler)
    44864576                    {
    4487                         XMLCONTENT *content = (XMLCONTENT*)MALLOC(sizeof(XMLCONTENT));
     4577                        XMLCONTENT *content = (XMLCONTENT *) MALLOC(sizeof(XMLCONTENT));
    44884578
    44894579                        if (!content)
     
    46144704}
    46154705
    4616 static XMLERROR epilogProcessor(XML_Parser parser,
    4617                                const char *s,
    4618                                const char *end,
    4619                                const char **nextPtr)
     4706static
     4707XMLERROR epilogProcessor(XML_Parser parser,
     4708                         const char *s,
     4709                         const char *end,
     4710                         const char **nextPtr)
    46204711{
    46214712    processor = epilogProcessor;
     
    46784769#ifdef XML_DTD
    46794770
    4680 static XMLERROR processInternalParamEntity(XML_Parser parser, ENTITY * entity)
     4771static XMLERROR
     4772 processInternalParamEntity(XML_Parser parser, ENTITY * entity)
    46814773{
    46824774    const char *s, *end, *next;
     
    47024794#endif /* XML_DTD */
    47034795
    4704 static XMLERROR errorProcessor(XML_Parser parser,
    4705                               const char *s,
    4706                               const char *end,
    4707                               const char **nextPtr)
     4796static
     4797XMLERROR errorProcessor(XML_Parser parser,
     4798                        const char *s,
     4799                        const char *end,
     4800                        const char **nextPtr)
    47084801{
    47094802    return errorCode;
    47104803}
    47114804
    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)
     4805static XMLERROR
     4806 storeAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata,
     4807                     const char *ptr, const char *end,
     4808                     STRING_POOL * pool)
    47184809{
    47194810    XMLERROR result = appendAttributeValue(parser, enc, isCdata, ptr, end, pool);
     
    47284819}
    47294820
    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
     4828static XMLERROR appendAttributeValue(XML_Parser parser,
     4829                                     const ENCODING * enc,
     4830                                     int isCdata,
     4831                                     const char *ptr,
     4832                                     const char *end,
     4833                                     STRING_POOL * pool)
    47334834{
    47344835    for (;;)
     
    47654866                     && (poolLength(pool) == 0 || poolLastChar(pool) == 0x20))
    47664867                        break;
    4767                     n = XmlEncode(n, (ICHAR*)buf);
     4868                    n = XmlEncode(n, (ICHAR *) buf);
    47684869                    if (!n)
    47694870                    {
     
    47804881                break;
    47814882            case XML_TOK_DATA_CHARS:
    4782                 if (!poolAppend(pool, enc, ptr, next))
     4883                if (!poolAppend(pool, enc, ptr, next, NULL))
    47834884                    return ERROR_EXPAT_NO_MEMORY;
     4885                break;
    47844886                break;
    47854887            case XML_TOK_TRAILING_CR:
     
    47974899                    const XML_Char *name;
    47984900                    ENTITY *entity;
     4901                    unsigned long ulOfs; // V0.9.14 (2001-08-09) [umoeller]
    47994902                    XML_Char ch = XmlPredefinedEntityName(enc,
    48004903                                                   ptr + enc->minBytesPerChar,
     
    48094912                    name = poolStoreString(&temp2Pool, enc,
    48104913                                           ptr + enc->minBytesPerChar,
    4811                                            next - enc->minBytesPerChar);
     4914                                           next - enc->minBytesPerChar,
     4915                                           &ulOfs); // V0.9.14 (2001-08-09) [umoeller]
    48124916                    if (!name)
    48134917                        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);
    48154921                    poolDiscard(&temp2Pool);
    48164922                    if (!entity)
     
    48644970}
    48654971
    4866 static XMLERROR storeEntityValue(XML_Parser parser,
    4867                                 const ENCODING * enc,
    4868                                 const char *entityTextPtr,
    4869                                 const char *entityTextEnd)
     4972static
     4973XMLERROR storeEntityValue(XML_Parser parser,
     4974                          const ENCODING * enc,
     4975                          const char *entityTextPtr,
     4976                          const char *entityTextEnd)
    48704977{
    48714978    STRING_POOL *pool = &(dtd.pool);
     
    48874994
    48884995                    name = poolStoreString(&tempPool, enc,
    4889                                          entityTextPtr + enc->minBytesPerChar,
    4890                                            next - enc->minBytesPerChar);
     4996                                           entityTextPtr + enc->minBytesPerChar,
     4997                                           next - enc->minBytesPerChar,
     4998                                           NULL);
    48914999                    if (!name)
    48925000                        return ERROR_EXPAT_NO_MEMORY;
    4893                     entity = (ENTITY*)lookup(&dtd.paramEntities, name, 0);
     5001                    entity = (ENTITY *) lookup(&dtd.paramEntities, name, 0);
    48945002                    poolDiscard(&tempPool);
    48955003                    if (!entity)
     
    49285036            case XML_TOK_ENTITY_REF:
    49295037            case XML_TOK_DATA_CHARS:
    4930                 if (!poolAppend(pool, enc, entityTextPtr, next))
     5038                if (!poolAppend(pool, enc, entityTextPtr, next, NULL))
    49315039                    return ERROR_EXPAT_NO_MEMORY;
    49325040                break;
     
    49515059                        return ERROR_EXPAT_BAD_CHAR_REF;
    49525060                    }
    4953                     n = XmlEncode(n, (ICHAR*)buf);
     5061                    n = XmlEncode(n, (ICHAR *) buf);
    49545062                    if (!n)
    49555063                    {
     
    49845092}
    49855093
    4986 static void normalizeLines(XML_Char * s)
     5094static void
     5095 normalizeLines(XML_Char * s)
    49875096{
    49885097    XML_Char *p;
     
    50115120}
    50125121
    5013 static int reportProcessingInstruction(XML_Parser parser, const ENCODING * enc, const char *start, const char *end)
     5122static int
     5123 reportProcessingInstruction(XML_Parser parser, const ENCODING * enc, const char *start, const char *end)
    50145124{
    50155125    const XML_Char *target;
     
    50255135    start += enc->minBytesPerChar * 2;
    50265136    tem = start + XmlNameLength(enc, start);
    5027     target = poolStoreString(&tempPool, enc, start, tem);
     5137    target = poolStoreString(&tempPool, enc, start, tem, NULL);
    50285138    if (!target)
    50295139        return 0;
     
    50315141    data = poolStoreString(&tempPool, enc,
    50325142                           XmlSkipS(enc, tem),
    5033                            end - enc->minBytesPerChar * 2);
     5143                           end - enc->minBytesPerChar * 2,
     5144                           NULL);
    50345145    if (!data)
    50355146        return 0;
     
    50405151}
    50415152
    5042 static int reportComment(XML_Parser parser, const ENCODING * enc, const char *start, const char *end)
     5153static int
     5154 reportComment(XML_Parser parser, const ENCODING * enc, const char *start, const char *end)
    50435155{
    50445156    XML_Char *data;
     
    50535165                           enc,
    50545166                           start + enc->minBytesPerChar * 4,
    5055                            end - enc->minBytesPerChar * 3);
     5167                           end - enc->minBytesPerChar * 3,
     5168                           NULL);
    50565169    if (!data)
    50575170        return 0;
     
    50625175}
    50635176
    5064 static void reportDefault(XML_Parser parser, const ENCODING * enc, const char *s, const char *end)
     5177static void
     5178 reportDefault(XML_Parser parser, const ENCODING * enc, const char *s, const char *end)
    50655179{
    50665180    if (MUST_CONVERT(enc, s))
     
    50815195        do
    50825196        {
    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);
    50865200            *eventEndPP = s;
    5087             defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR*)dataBuf);
     5201            defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *) dataBuf);
    50885202            *eventPP = s;
    50895203        }
     
    50915205    }
    50925206    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
     5211static int
     5212 defineAttribute(ELEMENT_TYPE * type, ATTRIBUTE_ID * attId, int isCdata,
    50985213                 int isId, const XML_Char * value, XML_Parser parser)
    50995214{
     
    51175232        {
    51185233            type->allocDefaultAtts = 8;
    5119             type->defaultAtts = (PDEFAULT_ATTRIBUTE)MALLOC(type->allocDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
     5234            type->defaultAtts = MALLOC(type->allocDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
    51205235        }
    51215236        else
    51225237        {
    51235238            type->allocDefaultAtts *= 2;
    5124             type->defaultAtts = (PDEFAULT_ATTRIBUTE)REALLOC(type->defaultAtts,
     5239            type->defaultAtts = REALLOC(type->defaultAtts,
    51255240                          type->allocDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
    51265241        }
     
    51565271            if (!poolAppendChar(&dtd.pool, XML_T('\0')))
    51575272                return 0;
    5158             prefix = (PREFIX*)lookup(&dtd.prefixes, poolStart(&dtd.pool), sizeof(PREFIX));
     5273            prefix = (PREFIX *) lookup(&dtd.prefixes, poolStart(&dtd.pool), sizeof(PREFIX));
    51595274            if (!prefix)
    51605275                return 0;
     
    51705285}
    51715286
    5172 static ATTRIBUTE_ID* getAttributeId(XML_Parser parser, const ENCODING * enc, const char *start, const char *end)
     5287static ATTRIBUTE_ID *
     5288 getAttributeId(XML_Parser parser, const ENCODING * enc, const char *start, const char *end)
    51735289{
    51745290    ATTRIBUTE_ID *id;
     
    51775293    if (!poolAppendChar(&dtd.pool, XML_T('\0')))
    51785294        return 0;
    5179     name = poolStoreString(&dtd.pool, enc, start, end);
     5295    name = poolStoreString(&dtd.pool, enc, start, end, NULL);
    51805296    if (!name)
    51815297        return 0;
    51825298    ++name;
    5183     id = (ATTRIBUTE_ID*)lookup(&dtd.attributeIds, name, sizeof(ATTRIBUTE_ID));
     5299    id = (ATTRIBUTE_ID *) lookup(&dtd.attributeIds, name, sizeof(ATTRIBUTE_ID));
    51845300    if (!id)
    51855301        return 0;
     
    52015317                id->prefix = &dtd.defaultPrefix;
    52025318            else
    5203                 id->prefix = (PREFIX*)lookup(&dtd.prefixes, name + 6, sizeof(PREFIX));
     5319                id->prefix = (PREFIX *) lookup(&dtd.prefixes, name + 6, sizeof(PREFIX));
    52045320            id->xmlns = 1;
    52055321        }
     
    52215337                    if (!poolAppendChar(&dtd.pool, XML_T('\0')))
    52225338                        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));
    52245340                    if (id->prefix->name == poolStart(&dtd.pool))
    52255341                        poolFinish(&dtd.pool);
     
    52365352#define CONTEXT_SEP XML_T('\f')
    52375353
    5238 static const XML_Char *getContext(XML_Parser parser)
     5354static
     5355const XML_Char *getContext(XML_Parser parser)
    52395356{
    52405357    HASH_TABLE_ITER iter;
     
    52635380        int len;
    52645381        const XML_Char *s;
    5265         PREFIX *prefix = (PREFIX*)hashTableIterNext(&iter);
     5382        PREFIX *prefix = (PREFIX *) hashTableIterNext(&iter);
    52665383
    52675384        if (!prefix)
     
    52905407    {
    52915408        const XML_Char *s;
    5292         ENTITY *e = (ENTITY*)hashTableIterNext(&iter);
     5409        ENTITY *e = (ENTITY *) hashTableIterNext(&iter);
    52935410
    52945411        if (!e)
     
    53095426}
    53105427
    5311 static int setContext(XML_Parser parser, const XML_Char * context)
     5428static
     5429int setContext(XML_Parser parser, const XML_Char * context)
    53125430{
    53135431    const XML_Char *s = context;
     
    53215439            if (!poolAppendChar(&tempPool, XML_T('\0')))
    53225440                return 0;
    5323             e = (ENTITY*)lookup(&dtd.generalEntities, poolStart(&tempPool), 0);
     5441            e = (ENTITY *) lookup(&dtd.generalEntities, poolStart(&tempPool), 0);
    53245442            if (e)
    53255443                e->open = 1;
     
    53395457                if (!poolAppendChar(&tempPool, XML_T('\0')))
    53405458                    return 0;
    5341                 prefix = (PREFIX*)lookup(&dtd.prefixes, poolStart(&tempPool), sizeof(PREFIX));
     5459                prefix = (PREFIX *) lookup(&dtd.prefixes, poolStart(&tempPool), sizeof(PREFIX));
    53425460                if (!prefix)
    53435461                    return 0;
     
    53735491
    53745492
    5375 static void normalizePublicId(XML_Char * publicId)
     5493static
     5494void normalizePublicId(XML_Char * publicId)
    53765495{
    53775496    XML_Char *p = publicId;
     
    53995518static int dtdInit(DTD * p, XML_Parser parser)
    54005519{
    5401     XML_Memory_Handling_Suite *ms = &((Parser*)parser)->m_mem;
     5520    XML_Memory_Handling_Suite *ms = &((Parser *) parser)->m_mem;
    54025521
    54035522    poolInit(&(p->pool), ms);
     
    54455564    for (;;)
    54465565    {
    5447         ELEMENT_TYPE *e = (ELEMENT_TYPE*)hashTableIterNext(&iter);
     5566        ELEMENT_TYPE *e = (ELEMENT_TYPE *) hashTableIterNext(&iter);
    54485567
    54495568        if (!e)
     
    54665585}
    54675586
    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. */
    54735589
    54745590static int dtdCopy(DTD * newDtd, const DTD * oldDtd, XML_Parser parser)
     
    54825598    {
    54835599        const XML_Char *name;
    5484         const PREFIX *oldP = (PREFIX*)hashTableIterNext(&iter);
     5600        const PREFIX *oldP = (PREFIX *) hashTableIterNext(&iter);
    54855601
    54865602        if (!oldP)
     
    55015617        ATTRIBUTE_ID *newA;
    55025618        const XML_Char *name;
    5503         const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID*)hashTableIterNext(&iter);
     5619        const ATTRIBUTE_ID *oldA = (ATTRIBUTE_ID *) hashTableIterNext(&iter);
    55045620
    55055621        if (!oldA)
     
    55125628            return 0;
    55135629        ++name;
    5514         newA = (ATTRIBUTE_ID*)lookup(&(newDtd->attributeIds), name, sizeof(ATTRIBUTE_ID));
     5630        newA = (ATTRIBUTE_ID *) lookup(&(newDtd->attributeIds), name, sizeof(ATTRIBUTE_ID));
    55155631        if (!newA)
    55165632            return 0;
     
    55225638                newA->prefix = &newDtd->defaultPrefix;
    55235639            else
    5524                 newA->prefix = (PREFIX*)lookup(&(newDtd->prefixes), oldA->prefix->name, 0);
     5640                newA->prefix = (PREFIX *) lookup(&(newDtd->prefixes), oldA->prefix->name, 0);
    55255641        }
    55265642    }
     
    55355651        ELEMENT_TYPE *newE;
    55365652        const XML_Char *name;
    5537         const ELEMENT_TYPE *oldE = (ELEMENT_TYPE*)hashTableIterNext(&iter);
     5653        const ELEMENT_TYPE *oldE = (ELEMENT_TYPE *) hashTableIterNext(&iter);
    55385654
    55395655        if (!oldE)
     
    55425658        if (!name)
    55435659            return 0;
    5544         newE = (ELEMENT_TYPE*)lookup(&(newDtd->elementTypes), name, sizeof(ELEMENT_TYPE));
     5660        newE = (ELEMENT_TYPE *) lookup(&(newDtd->elementTypes), name, sizeof(ELEMENT_TYPE));
    55455661        if (!newE)
    55465662            return 0;
    55475663        if (oldE->nDefaultAtts)
    55485664        {
    5549             newE->defaultAtts = (DEFAULT_ATTRIBUTE*)MALLOC(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
     5665            newE->defaultAtts = (DEFAULT_ATTRIBUTE *) MALLOC(oldE->nDefaultAtts * sizeof(DEFAULT_ATTRIBUTE));
    55505666            if (!newE->defaultAtts)
    55515667                return 0;
    55525668        }
    55535669        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);
    55555671        newE->allocDefaultAtts = newE->nDefaultAtts = oldE->nDefaultAtts;
    55565672        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);
    55585674        for (i = 0; i < newE->nDefaultAtts; i++)
    55595675        {
    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);
    55615677            newE->defaultAtts[i].isCdata = oldE->defaultAtts[i].isCdata;
    55625678            if (oldE->defaultAtts[i].value)
     
    56135729        ENTITY *newE;
    56145730        const XML_Char *name;
    5615         const ENTITY *oldE = (ENTITY*)hashTableIterNext(&iter);
     5731        const ENTITY *oldE = (ENTITY *) hashTableIterNext(&iter);
    56165732
    56175733        if (!oldE)
     
    56205736        if (!name)
    56215737            return 0;
    5622         newE = (ENTITY*)lookup(newTable, name, sizeof(ENTITY));
     5738        newE = (ENTITY *) lookup(newTable, name, sizeof(ENTITY));
    56235739        if (!newE)
    56245740            return 0;
     
    56675783#define INIT_SIZE 64
    56685784
    5669 static int keyeq(KEY s1, KEY s2)
     5785static
     5786int keyeq(KEY s1, KEY s2)
    56705787{
    56715788    for (; *s1 == *s2; s1++, s2++)
     
    56755792}
    56765793
    5677 static unsigned long hash(KEY s)
     5794static
     5795unsigned long hash(KEY s)
    56785796{
    56795797    unsigned long h = 0;
     
    56845802}
    56855803
    5686 static NAMED *lookup(HASH_TABLE * table, KEY name, size_t createSize)
     5804static
     5805NAMED *lookup(HASH_TABLE * table, KEY name, size_t createSize)
    56875806{
    56885807    size_t i;
     
    56955814            return 0;
    56965815        tsize = INIT_SIZE * sizeof(NAMED *);
    5697         table->v = (NAMED**)table->mem->malloc_fcn(tsize);
     5816        table->v = table->mem->malloc_fcn(tsize);
    56985817        if (!table->v)
    56995818            return 0;
     
    57215840            size_t newSize = table->size * 2;
    57225841            size_t tsize = newSize * sizeof(NAMED *);
    5723             NAMED **newV = (NAMED**)table->mem->malloc_fcn(tsize);
     5842            NAMED **newV = table->mem->malloc_fcn(tsize);
    57245843
    57255844            if (!newV)
     
    57475866        }
    57485867    }
    5749     table->v[i] = (NAMED*)table->mem->malloc_fcn(createSize);
     5868    table->v[i] = table->mem->malloc_fcn(createSize);
    57505869    if (!table->v[i])
    57515870        return 0;
     
    57565875}
    57575876
    5758 static void hashTableDestroy(HASH_TABLE * table)
     5877static
     5878void hashTableDestroy(HASH_TABLE * table)
    57595879{
    57605880    size_t i;
     
    57715891}
    57725892
    5773 static void hashTableInit(HASH_TABLE * p, XML_Memory_Handling_Suite * ms)
     5893static
     5894void hashTableInit(HASH_TABLE * p, XML_Memory_Handling_Suite * ms)
    57745895{
    57755896    p->size = 0;
     
    57805901}
    57815902
    5782 static void hashTableIterInit(HASH_TABLE_ITER * iter, const HASH_TABLE * table)
     5903static
     5904void hashTableIterInit(HASH_TABLE_ITER * iter, const HASH_TABLE * table)
    57835905{
    57845906    iter->p = table->v;
     
    57865908}
    57875909
    5788 static NAMED* hashTableIterNext(HASH_TABLE_ITER * iter)
     5910static
     5911NAMED *hashTableIterNext(HASH_TABLE_ITER * iter)
    57895912{
    57905913    while (iter->p != iter->end)
     
    57995922
    58005923
    5801 static void poolInit(STRING_POOL * pool, XML_Memory_Handling_Suite * ms)
     5924static
     5925void poolInit(STRING_POOL * pool, XML_Memory_Handling_Suite * ms)
    58025926{
    58035927    pool->blocks = 0;
     
    58095933}
    58105934
    5811 static void poolClear(STRING_POOL * pool)
     5935static
     5936void poolClear(STRING_POOL * pool)
    58125937{
    58135938    if (!pool->freeBlocks)
     
    58325957}
    58335958
    5834 static void poolDestroy(STRING_POOL * pool)
     5959static
     5960void poolDestroy(STRING_POOL * pool)
    58355961{
    58365962    BLOCK *p = pool->blocks;
     
    58585984}
    58595985
    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
     6008static 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]
    58626015{
    58636016    if (!pool->ptr && !poolGrow(pool))
     
    58656018    for (;;)
    58666019    {
    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
    58686033        if (ptr == end)
    58696034            break;
     
    58746039}
    58756040
    5876 static const XML_Char *poolCopyString(STRING_POOL * pool, const XML_Char * s)
     6041static const XML_Char* poolCopyString(STRING_POOL *pool,
     6042                                      const XML_Char *s)
    58776043{
    58786044    do
     
    59026068}
    59036069
    5904 static const XML_Char* poolAppendString(STRING_POOL * pool, const XML_Char * s)
     6070static const XML_Char* poolAppendString(STRING_POOL *pool,
     6071                                        const XML_Char *s)
    59056072{
    59066073    while (*s)
     
    59136080}                               /* End poolAppendString */
    59146081
    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
     6088static 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]
    59196099        return 0;
    5920     if (pool->ptr == pool->end && !poolGrow(pool))
     6100    if (    (pool->ptr == pool->end)
     6101         && (!poolGrow(pool))
     6102       )
    59216103        return 0;
    59226104    *(pool->ptr)++ = 0;
     
    59246106}
    59256107
    5926 static int poolGrow(STRING_POOL * pool)
     6108static int poolGrow(STRING_POOL *pool)
    59276109{
    59286110    if (pool->freeBlocks)
     
    59456127            pool->blocks = pool->freeBlocks;
    59466128            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));
    59486132            pool->ptr = pool->blocks->s + (pool->ptr - pool->start);
    59496133            pool->start = pool->blocks->s;
     
    59566140        int blockSize = (pool->end - pool->start) * 2;
    59576141
    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));
    59616143        if (!pool->blocks)
    59626144            return 0;
     
    59756157        else
    59766158            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));
    59786160        if (!tem)
    59796161            return 0;
     
    59906172}
    59916173
    5992 static int  nextScaffoldPart(XML_Parser parser)
     6174static int
     6175 nextScaffoldPart(XML_Parser parser)
    59936176{
    59946177    CONTENT_SCAFFOLD *me;
     
    59976180    if (!dtd.scaffIndex)
    59986181    {
    5999         dtd.scaffIndex = (int*)MALLOC(groupSize * sizeof(int));
     6182        dtd.scaffIndex = MALLOC(groupSize * sizeof(int));
    60006183
    60016184        if (!dtd.scaffIndex)
     
    60096192        {
    60106193            dtd.scaffSize *= 2;
    6011             dtd.scaffold = (CONTENT_SCAFFOLD*)REALLOC(dtd.scaffold,
     6194            dtd.scaffold = (CONTENT_SCAFFOLD *) REALLOC(dtd.scaffold,
    60126195                                    dtd.scaffSize * sizeof(CONTENT_SCAFFOLD));
    60136196        }
     
    60156198        {
    60166199            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));
    60186201        }
    60196202        if (!dtd.scaffold)
     
    60396222}                               /* End nextScaffoldPart */
    60406223
    6041 static void build_node(XML_Parser parser,
     6224static void
     6225 build_node(XML_Parser parser,
    60426226            int src_node,
    60436227            XMLCONTENT * dest,
     
    60816265}                               /* End build_node */
    60826266
    6083 static XMLCONTENT * build_model(XML_Parser parser)
     6267static XMLCONTENT *
     6268 build_model(XML_Parser parser)
    60846269{
    60856270    XMLCONTENT *ret;
     
    60886273    int allocsize = dtd.scaffCount * sizeof(XMLCONTENT) + dtd.contentStringLen;
    60896274
    6090     ret = (XMLCONTENT*)MALLOC(allocsize);
     6275    ret = MALLOC(allocsize);
    60916276    if (!ret)
    60926277        return 0;
     
    60996284}                               /* End build_model */
    61006285
    6101 static ELEMENT_TYPE * getElementType(XML_Parser parser,
     6286static ELEMENT_TYPE *
     6287 getElementType(XML_Parser parser,
    61026288                const ENCODING * enc,
    61036289                const char *ptr,
    61046290                const char *end)
    61056291{
    6106     const XML_Char *name = poolStoreString(&dtd.pool, enc, ptr, end);
     6292    const XML_Char *name = poolStoreString(&dtd.pool, enc, ptr, end, NULL);
    61076293    ELEMENT_TYPE *ret;
    61086294
    61096295    if (!name)
    61106296        return 0;
    6111     ret = (ELEMENT_TYPE*)lookup(&dtd.elementTypes, name, sizeof(ELEMENT_TYPE));
     6297    ret = (ELEMENT_TYPE *) lookup(&dtd.elementTypes, name, sizeof(ELEMENT_TYPE));
    61126298    if (!ret)
    61136299        return 0;
     
    61226308    return ret;
    61236309}                               /* End getElementType */
    6124 
Note: See TracChangeset for help on using the changeset viewer.