Changeset 38


Ignore:
Timestamp:
Feb 17, 2001, 3:03:14 PM (25 years ago)
Author:
umoeller
Message:

Updates to XML.

Location:
trunk
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/expat/expat.h

    r36 r38  
    3131typedef char XML_LChar;
    3232
    33 enum XML_Content_Type {
    34   XML_CTYPE_EMPTY = 1,
    35   XML_CTYPE_ANY,
    36   XML_CTYPE_MIXED,
    37   XML_CTYPE_NAME,
    38   XML_CTYPE_CHOICE,
    39   XML_CTYPE_SEQ
     33enum XML_Content_Type
     34{
     35    XML_CTYPE_EMPTY = 1,
     36    XML_CTYPE_ANY,
     37    XML_CTYPE_MIXED,
     38    XML_CTYPE_NAME,
     39    XML_CTYPE_CHOICE,
     40    XML_CTYPE_SEQ
    4041};
    4142
    42 enum XML_Content_Quant {
    43   XML_CQUANT_NONE,
    44   XML_CQUANT_OPT,
    45   XML_CQUANT_REP,
    46   XML_CQUANT_PLUS
     43enum XML_Content_Quant
     44{
     45    XML_CQUANT_NONE,
     46    XML_CQUANT_OPT,
     47    XML_CQUANT_REP,
     48    XML_CQUANT_PLUS
    4749};
    4850
    49 /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
    50    XML_CQUANT_NONE, and the other fields will be zero or NULL.
    51    If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
    52    numchildren will contain number of elements that may be mixed in
    53    and children point to an array of XML_Content cells that will be
    54    all of XML_CTYPE_NAME type with no quantification.
    55 
    56    If type == XML_CTYPE_NAME, then the name points to the name, and
    57    the numchildren field will be zero and children will be NULL. The
    58    quant fields indicates any quantifiers placed on the name.
    59 
    60    CHOICE and SEQ will have name NULL, the number of children in
    61    numchildren and children will point, recursively, to an array
    62    of XML_Content cells.
    63 
    64    The EMPTY, ANY, and MIXED types will only occur at top level.
    65 */
    66 
    67 typedef struct XML_cp XML_Content;
    68 
    69 struct XML_cp {
    70   enum XML_Content_Type     type;
    71   enum XML_Content_Quant    quant;
    72   const XML_Char *      name;
    73   unsigned int          numchildren;
    74   XML_Content *         children;
    75 };
     51/*
     52 *@@ XMLCONTENT:
     53 *      structure passed with the @expat "element declaration handler"
     54 *      (see XML_SetElementDeclHandler).
     55 *
     56 *      The model argument is the root of a tree of XMLCONTENT
     57 *      nodes. If type equals XML_CTYPE_EMPTY or XML_CTYPE_ANY,
     58 *      then quant will be XML_CQUANT_NONE, and the other fields
     59 *      will be zero or NULL.
     60 *
     61 *      If type is XML_CTYPE_MIXED:
     62 *
     63 *      --  "quant" will be XML_CQUANT_NONE or XML_CQUANT_REP.
     64 *
     65 *      --  "numchildren" will contain the number of elements that
     66 *          are allowed to be mixed in.
     67 *
     68 *      --  "children" points to a sub-array of XMLCONTENT structures
     69 *          that will all have type XML_CTYPE_NAME with no quantification.
     70 *
     71 *      Only the root node can be type XML_CTYPE_EMPTY, XML_CTYPE_ANY,
     72 *      or XML_CTYPE_MIXED.
     73 *
     74 *      For type XML_CTYPE_NAME, the name field points to the
     75 *      name and the numchildren and children fields will be
     76 *      zero and NULL. The quant field will indicate any
     77 *      quantifiers placed on the name.
     78 *
     79 *      Types XML_CTYPE_CHOICE and XML_CTYPE_SEQ indicate a
     80 *      choice or sequence respectively. The numchildren field
     81 *      indicates how many nodes in the choice or sequence and
     82 *      children points to the nodes.
     83 *
     84 *@@added V0.9.9 (2001-02-14) [umoeller]
     85 */
     86
     87typedef struct _XMLCONTENT
     88{
     89    enum XML_Content_Type       type;
     90                    // one of:
     91                    // -- XML_CTYPE_EMPTY   --> quant will be XML_CQUANT_NONE, rest is NULL
     92                    // -- XML_CTYPE_ANY,    --> quant will be XML_CQUANT_NONE, rest is NULL
     93                    // -- XML_CTYPE_MIXED,  --> (#PCDATA) gives us this
     94                    // -- XML_CTYPE_CHOICE, --> choice ("|" list)
     95                    // -- XML_CTYPE_SEQ     --> sequence (comma list)
     96
     97                    // -- XML_CTYPE_NAME: used for sub-content if content has CML_CTYPE_MIXED;
     98                    //                    only "name" is valid for sub-content
     99
     100    enum XML_Content_Quant      quant;
     101                    // one of:
     102                    // -- XML_CQUANT_NONE   --> all fields below are NULL
     103                    // -- XML_CQUANT_OPT,
     104                    // -- XML_CQUANT_REP,
     105                    // -- XML_CQUANT_PLUS
     106
     107    const XML_Char              *name;
     108
     109    unsigned int                numchildren;
     110
     111    struct _XMLCONTENT          *children;
     112
     113} XMLCONTENT, *PXMLCONTENT;
    76114
    77115
     
    82120
    83121typedef void (* EXPATENTRY XML_ElementDeclHandler) (void *userData,
    84                     const XML_Char *name,
    85                     XML_Content *model);
     122                                                    const XML_Char *name,
     123                                                    XMLCONTENT *model);
    86124
    87125void XMLPARSEAPI XML_SetElementDeclHandler(XML_Parser parser,
     
    292330have standalone="yes"). If this handler returns 0, then processing
    293331will not continue, and the parser will return a
    294 XML_ERROR_NOT_STANDALONE error. */
     332ERROR_EXPAT_NOT_STANDALONE error. */
    295333
    296334typedef int (* EXPATENTRY XML_NotStandaloneHandler)(void *userData);
     
    316354The handler should return 0 if processing should not continue because of
    317355a fatal error in the handling of the external entity.
    318 In this case the calling parser will return an XML_ERROR_EXTERNAL_ENTITY_HANDLING
     356In this case the calling parser will return an ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING
    319357error.
    320358Note that unlike other handlers the first argument is the parser, not userData. */
     
    406444} XML_Encoding;
    407445
    408 /* This is called for an encoding that is unknown to the parser.
    409 The encodingHandlerData argument is that which was passed as the
    410 second argument to XML_SetUnknownEncodingHandler.
    411 The name argument gives the name of the encoding as specified in
    412 the encoding declaration.
    413 If the callback can provide information about the encoding,
    414 it must fill in the XML_Encoding structure, and return 1.
    415 Otherwise it must return 0.
    416 If info does not describe a suitable encoding,
    417 then the parser will return an XML_UNKNOWN_ENCODING error. */
    418 
    419446typedef int (* EXPATENTRY XML_UnknownEncodingHandler)(void *encodingHandlerData,
    420                       const XML_Char *name,
    421                       XML_Encoding *info);
     447                                                      const XML_Char *name,
     448                                                      XML_Encoding *info);
    422449
    423450void XMLPARSEAPI XML_SetElementHandler(XML_Parser parser,
    424               XML_StartElementHandler start,
    425               XML_EndElementHandler end);
     451                                       XML_StartElementHandler start,
     452                                       XML_EndElementHandler end);
    426453
    427454void XMLPARSEAPI XML_SetStartElementHandler(XML_Parser, XML_StartElementHandler);
     
    430457
    431458void XMLPARSEAPI XML_SetCharacterDataHandler(XML_Parser parser,
    432                 XML_CharacterDataHandler handler);
     459                                             XML_CharacterDataHandler handler);
    433460
    434461void XMLPARSEAPI XML_SetProcessingInstructionHandler(XML_Parser parser,
    435                     XML_ProcessingInstructionHandler handler);
     462                                                     XML_ProcessingInstructionHandler handler);
    436463void XMLPARSEAPI XML_SetCommentHandler(XML_Parser parser,
    437                       XML_CommentHandler handler);
     464                                       XML_CommentHandler handler);
    438465
    439466void XMLPARSEAPI XML_SetCdataSectionHandler(XML_Parser parser,
    440                XML_StartCdataSectionHandler start,
    441                XML_EndCdataSectionHandler end);
     467                                            XML_StartCdataSectionHandler start,
     468                                            XML_EndCdataSectionHandler end);
    442469
    443470void XMLPARSEAPI XML_SetStartCdataSectionHandler(XML_Parser parser,
     
    594621};
    595622
    596 /* Controls parsing of parameter entities (including the external DTD
    597 subset). If parsing of parameter entities is enabled, then references
    598 to external parameter entities (including the external DTD subset)
    599 will be passed to the handler set with
    600 XML_SetExternalEntityRefHandler.  The context passed will be 0.
    601 Unlike external general entities, external parameter entities can only
    602 be parsed synchronously.  If the external parameter entity is to be
    603 parsed, it must be parsed during the call to the external entity ref
    604 handler: the complete sequence of XML_ExternalEntityParserCreate,
    605 XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during
    606 this call.  After XML_ExternalEntityParserCreate has been called to
    607 create the parser for the external parameter entity (context must be 0
    608 for this call), it is illegal to make any calls on the old parser
    609 until XML_ParserFree has been called on the newly created parser.  If
    610 the library has been compiled without support for parameter entity
    611 parsing (ie without XML_DTD being defined), then
    612 XML_SetParamEntityParsing will return 0 if parsing of parameter
    613 entities is requested; otherwise it will return non-zero. */
    614 
    615623int XMLPARSEAPI XML_SetParamEntityParsing(XML_Parser parser,
    616               enum XML_ParamEntityParsing parsing);
    617 
    618 enum XML_Error {
    619   XML_ERROR_NONE,
    620   XML_ERROR_NO_MEMORY,
    621   XML_ERROR_SYNTAX,
    622   XML_ERROR_NO_ELEMENTS,
    623   XML_ERROR_INVALID_TOKEN,
    624   XML_ERROR_UNCLOSED_TOKEN,
    625   XML_ERROR_PARTIAL_CHAR,
    626   XML_ERROR_TAG_MISMATCH,
    627   XML_ERROR_DUPLICATE_ATTRIBUTE,
    628   XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
    629   XML_ERROR_PARAM_ENTITY_REF,
    630   XML_ERROR_UNDEFINED_ENTITY,
    631   XML_ERROR_RECURSIVE_ENTITY_REF,
    632   XML_ERROR_ASYNC_ENTITY,
    633   XML_ERROR_BAD_CHAR_REF,
    634   XML_ERROR_BINARY_ENTITY_REF,
    635   XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
    636   XML_ERROR_MISPLACED_XML_PI,
    637   XML_ERROR_UNKNOWN_ENCODING,
    638   XML_ERROR_INCORRECT_ENCODING,
    639   XML_ERROR_UNCLOSED_CDATA_SECTION,
    640   XML_ERROR_EXTERNAL_ENTITY_HANDLING,
    641   XML_ERROR_NOT_STANDALONE,
    642   XML_ERROR_UNEXPECTED_STATE
    643 };
     624                                          enum XML_ParamEntityParsing parsing);
     625
     626#define ERROR_EXPAT_NONE        0   // explicitly added V0.9.9 (2001-02-14) [umoeller]
     627
     628#define ERROR_XML_FIRST         40000   // first error code used
     629
     630typedef enum _XMLERROR
     631{
     632    // ERROR_EXPAT_NONE,            // removed to adhere with APIRET V0.9.9 (2001-02-14) [umoeller]
     633    ERROR_EXPAT_NO_MEMORY = ERROR_XML_FIRST,
     634    ERROR_EXPAT_SYNTAX,
     635    ERROR_EXPAT_NO_ELEMENTS,
     636    ERROR_EXPAT_INVALID_TOKEN,
     637    ERROR_EXPAT_UNCLOSED_TOKEN,
     638    ERROR_EXPAT_PARTIAL_CHAR,
     639    ERROR_EXPAT_TAG_MISMATCH,
     640    ERROR_EXPAT_DUPLICATE_ATTRIBUTE,
     641    ERROR_EXPAT_JUNK_AFTER_DOC_ELEMENT,
     642    ERROR_EXPAT_PARAM_ENTITY_REF,
     643    ERROR_EXPAT_UNDEFINED_ENTITY,
     644    ERROR_EXPAT_RECURSIVE_ENTITY_REF,
     645    ERROR_EXPAT_ASYNC_ENTITY,
     646    ERROR_EXPAT_BAD_CHAR_REF,
     647    ERROR_EXPAT_BINARY_ENTITY_REF,
     648    ERROR_EXPAT_ATTRIBUTE_EXTERNAL_ENTITY_REF,
     649    ERROR_EXPAT_MISPLACED_XML_PI,
     650    ERROR_EXPAT_UNKNOWN_ENCODING,
     651    ERROR_EXPAT_INCORRECT_ENCODING,
     652    ERROR_EXPAT_UNCLOSED_CDATA_SECTION,
     653    ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING,
     654    ERROR_EXPAT_NOT_STANDALONE,
     655    ERROR_EXPAT_UNEXPECTED_STATE,
     656
     657    ERROR_EXPAT_AFTER_LAST      // added V0.9.9 (2001-02-14) [umoeller];
     658                                // xml.h builds on this
     659} XMLERROR;
    644660
    645661/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
    646662returns information about the error. */
    647663
    648 enum XML_Error  XMLPARSEAPI XML_GetErrorCode(XML_Parser parser);
     664XMLERROR  XMLPARSEAPI XML_GetErrorCode(XML_Parser parser);
    649665
    650666/* These functions return information about the current parse location.
     
    687703
    688704/* Returns a string describing the error. */
    689 const XML_LChar XMLPARSEAPI * XML_ErrorString(int code);
     705// const XML_LChar XMLPARSEAPI * XML_ErrorString(int code);
     706        // moved this to xml.c V0.9.9 (2001-02-16) [umoeller]
    690707
    691708/* Return a string containing the version number of this expat */
  • trunk/include/expat/expat_setup.h

    r36 r38  
    1818        #define EXPATENTRY _Optlink
    1919    #endif
     20
     21    #define XML_DTD 1
     22
    2023#endif
    2124
  • trunk/include/expat/xmlrole.h

    r36 r38  
    66#ifndef XmlRole_INCLUDED
    77#define XmlRole_INCLUDED 1
     8
     9#include "expat\expat_setup.h"
     10                        // V0.9.9 (2001-02-10) [umoeller]
     11                        // to save the app from having to include this as well
    812
    913#include "expat\xmltok.h"
  • trunk/include/expat/xmltok.h

    r36 r38  
    66#ifndef XmlTok_INCLUDED
    77#define XmlTok_INCLUDED 1
     8
     9#include "expat\expat_setup.h"
     10                        // V0.9.9 (2001-02-10) [umoeller]
     11                        // to save the app from having to include this as well
    812
    913#ifdef __cplusplus
     
    154158                              const char *);
    155159  void (* EXPATENTRY updatePosition)(const ENCODING *,
    156                          const char *ptr,
    157                          const char *end,
    158                          POSITION *);
     160                                     const char *ptr,
     161                                     const char *end,
     162                                     POSITION *);
    159163  int (* EXPATENTRY isPublicId)(const ENCODING *enc,
    160164                    const char *ptr,
  • trunk/include/helpers/linklist.h

    r35 r38  
    153153    typedef LSTQUERYFIRSTNODE *PLSTQUERYFIRSTNODE;
    154154
     155    PLISTNODE XWPENTRY lstQueryLastNode(PLINKLIST pList);
     156    typedef PLISTNODE XWPENTRY LSTQUERYLASTNODE(PLINKLIST pList);
     157    typedef LSTQUERYLASTNODE *PLSTQUERYLASTNODE;
     158
    155159    PLISTNODE XWPENTRY lstNodeFromIndex(PLINKLIST pList, unsigned long ulIndex);
    156160    typedef PLISTNODE XWPENTRY LSTNODEFROMINDEX(PLINKLIST pList, unsigned long ulIndex);
  • trunk/include/helpers/stringh.h

    r23 r38  
    3535
    3636    PSZ strhdup(const char *pszSource);
     37
     38    int strhcmp(const char *p1, const char *p2);
    3739
    3840    PSZ strhistr(const char *string1, const char *string2);
  • trunk/include/helpers/tree.h

    r33 r38  
    107107    // --  -1: t1 < t2
    108108    // --  +1: t1 > t2
    109     typedef int (FNTREE_COMPARE_NODES) (TREE *t1, TREE *t2);
    110     typedef int (FNTREE_COMPARE_DATA) (TREE *t1, void *pData);
     109    typedef int XWPENTRY FNTREE_COMPARE_NODES(TREE *t1, TREE *t2);
     110    typedef int XWPENTRY FNTREE_COMPARE_DATA(TREE *t1, void *pData);
    111111
    112112    //  Define a function type for use with the tree traversal function
    113     typedef void (TREE_PROCESS) (TREE *t, void *pUser);
     113    typedef void XWPENTRY TREE_PROCESS(TREE *t, void *pUser);
    114114
    115115    //  Global variables
  • trunk/include/helpers/xml.h

    r35 r38  
    88 *@@added V0.9.6 (2000-10-29) [umoeller]
    99 *@@include #include <os2.h>
    10  *@@include #include "expat\expat.h"
     10 *@@include #include "expat\expat.h"                // must come before xml.h
    1111 *@@include #include "helpers\linklist.h"
     12 *@@include #include "helpers\tree.h"
    1213 *@@include #include "helpers\xstring.h"
    1314 *@@include #include "helpers\xml.h"
     
    3637    #endif
    3738
    38     #define ERROR_DOM_FIRST                14000
    39 
    40     #define ERROR_DOM_INDEX_SIZE                   (ERROR_DOM_FIRST + 1)
    41     #define ERROR_DOM_DOMSTRING_SIZE               (ERROR_DOM_FIRST + 2)
    42     #define ERROR_DOM_HIERARCHY_REQUEST            (ERROR_DOM_FIRST + 3)
    43     #define ERROR_DOM_WRONG_DOCUMENT               (ERROR_DOM_FIRST + 4)
    44     #define ERROR_DOM_INVALID_CHARACTER            (ERROR_DOM_FIRST + 5)
    45     #define ERROR_DOM_NO_DATA_ALLOWED              (ERROR_DOM_FIRST + 6)
    46     #define ERROR_DOM_NO_MODIFICATION_ALLOWED      (ERROR_DOM_FIRST + 7)
    47     #define ERROR_DOM_NOT_FOUND                    (ERROR_DOM_FIRST + 8)
    48     #define ERROR_DOM_NOT_SUPPORTED                (ERROR_DOM_FIRST + 9)
    49     #define ERROR_DOM_INUSE_ATTRIBUTE              (ERROR_DOM_FIRST + 10)
    50 
    51     #define ERROR_DOM_PARSING                      (ERROR_DOM_FIRST + 11)
    52 
    53     #define DOMNODE_ELEMENT         1          // node is an ELEMENT
    54     #define DOMNODE_ATTRIBUTE       2          // node is an ATTRIBUTE
    55     #define DOMNODE_TEXT            3          // node is a TEXT node
    56     // #define DOMNODE_CDATA_SECTION   4
    57     // #define DOMNODE_ENTITY_REFERENCE   5
    58     // #define DOMNODE_ENTITY          6
    59     // #define DOMNODE_PROCESSING_INSTRUCTION   7
    60     #define DOMNODE_COMMENT         8          // node is a COMMENT
    61     #define DOMNODE_DOCUMENT        9          // node is a document
    62     #define DOMNODE_DOCUMENT_TYPE   10         // node is a DOCUMENTTYPE
    63     // #define DOMNODE_DOCUMENT_FRAGMENT   11
    64     // #define DOMNODE_NOTATION        12
     39    typedef enum _DOMERROR
     40    {
     41        // validity errors:
     42// START MATCHING ERROR MESSAGES (xmlDescribeError)
     43        ERROR_DOM_UNDECLARED_ELEMENT = ERROR_EXPAT_AFTER_LAST,
     44                // invalidity: element is undeclared
     45        ERROR_DOM_ROOT_ELEMENT_MISNAMED,
     46        ERROR_DOM_INVALID_ROOT_ELEMENT,
     47        ERROR_DOM_INVALID_SUBELEMENT,
     48                // subelement may not appear in its parent element
     49        ERROR_DOM_DUPLICATE_ELEMENT_DECL,
     50                // more than one declaration for an element type
     51        ERROR_DOM_DUPLICATE_ATTRIBUTE_DECL,
     52                // more than one declaration for an attribute type
     53        ERROR_DOM_UNDECLARED_ATTRIBUTE,
     54// END MATCHING ERROR MESSAGES (xmlDescribeError)
     55
     56        // error categories:
     57        ERROR_DOM_PARSING,
     58        ERROR_DOM_VALIDITY,
     59
     60        // additional DOM errors
     61        ERROR_DOM_NODETYPE_NOT_SUPPORTED,
     62                // invalid node type in xmlCreateNode
     63        ERROR_DOM_NO_DOCUMENT,
     64                // cannot find document node
     65        ERROR_DOM_NO_ELEMENT,
     66        ERROR_DOM_DUPLICATE_DOCTYPE,
     67        ERROR_DOM_DOCTYPE_STRUCTURE,
     68                // DOCTYPE is given and root element name does not match doctype name
     69        ERROR_DOM_INTEGRITY,
     70        ERROR_DOM_DUPLICATE_ATTRIBUTE
     71    } DOMERROR;
     72
     73    /* ******************************************************************
     74     *
     75     *   Most basic node management
     76     *
     77     ********************************************************************/
     78
     79    // content model node types:
     80    typedef enum _NODEBASETYPE
     81    {
     82        DOMNODE_ELEMENT,                // node is a DOM ELEMENT
     83        DOMNODE_ATTRIBUTE,              // node is a DOM ATTRIBUTE
     84        DOMNODE_TEXT,                   // node is a DOM TEXT node
     85            // DOMNODE_CDATA_SECTION   4
     86            // DOMNODE_ENTITY_REFERENCE   5
     87            // DOMNODE_ENTITY          6
     88        DOMNODE_PROCESSING_INSTRUCTION, // node is a DOM PI
     89        DOMNODE_COMMENT,                // node is a DOM COMMENT
     90        DOMNODE_DOCUMENT,               // node is a DOM document
     91        DOMNODE_DOCUMENT_TYPE,          // node is a DOM DOCUMENTTYPE
     92            // #define DOMNODE_DOCUMENT_FRAGMENT   11
     93            // #define DOMNODE_NOTATION        12
     94
     95        // the following are all CMELEMENTPARTICLE nodes
     96        ELEMENTPARTICLE_EMPTY,
     97        ELEMENTPARTICLE_ANY,
     98        ELEMENTPARTICLE_MIXED,
     99        ELEMENTPARTICLE_CHOICE,
     100        ELEMENTPARTICLE_SEQ,
     101        ELEMENTPARTICLE_NAME,
     102
     103        ATTRIBUTE_DECLARATION_BASE,     // node is a CMATTRIBUTEDECLBASE
     104        ATTRIBUTE_DECLARATION,          // node is a CMATTRIBUTEDECL
     105        ATTRIBUTE_DECLARATION_ENUM      // node is a plain NODEBASE, part of an attr value enum
     106    } NODEBASETYPE;
     107
     108    /*
     109     *@@ NODEBASE:
     110     *      "content model" node. With the DOM content models,
     111     *      this represents an entry in a DTD or XML schema.
     112     *
     113     *@@added V0.9.9 (2001-02-14) [umoeller]
     114     */
     115
     116    typedef struct _NODEBASE
     117    {
     118        TREE            Tree;
     119
     120        NODEBASETYPE    ulNodeType;
     121
     122        XSTRING         strNodeName;
     123                    // node name;
     124                    // -- for the various DOMNODE_* items, see _DOMNODE;
     125                    // -- for CMELEMENTPARTICLE nodes, this is the particle's name
     126                    // -- for CMELEMENTDECLNODE nodes, element name being declared
     127                    // -- for CMATTRIBUTEDECLBASE nodes, name of element to which this
     128                    //          attrib decl belongs
     129                    // -- for CMATTRIBUTEDECL nodes, name of attribute;
     130                    // -- for ATTRIBUTE_DECLARATION_ENUM, attribute value in the
     131                    //          possible values list.
     132
     133    } NODEBASE, *PNODEBASE;
     134
     135    /* ******************************************************************
     136     *
     137     *   DOM level 1
     138     *
     139     ********************************************************************/
    65140
    66141    /*
    67142     *@@ DOMNODE:
    68      *      this represents one node in an XML document.
    69      *
    70      *      Per definition, each XML document is broken down into
    71      *      DOM nodes. The document itself is represented by a
    72      *      node with the DOMNODE_DOCUMENT type, which in turn
    73      *      contains all the other nodes. This thus forms a tree
    74      *      as shown with xmlParse.
     143     *      this represents one @DOM node in an @XML document.
     144     *
     145     *      The document itself is represented by a node with the
     146     *      DOMNODE_DOCUMENT type, which is the root of a tree as
     147     *      shown with xmlParse.
    75148     *
    76149     *      The contents of the members vary according
    77      *      to ulNodeType:
    78      *
    79      +      ulNodeType      pszNodeName     pszNodeValue        listAttributeNodes
     150     *      to ulNodeType (0 specifies that the field does not
     151     *      apply to that type).
     152     *
     153     *      The first member of a DOMNODE is a NODEBASE to allow
     154     *      inserting these things in a tree. NODEBASE.ulNodeType
     155     *      _always_ specifies the various types that are using
     156     *      that structure to allow for type-safety (if we watch out).
     157     *      This is for faking inheritance.
     158     *
     159     *      Note that we also implement specialized sub-structures of
     160     *      DOMNODE, whose first member is the DOMNODE (and therefore
     161     *      a NODEBASE as well):
     162     *
     163     *      --  DOCUMENT nodes are given a _DOMDOCUMENTNODE structure.
     164     *
     165     *      --  DOCTYPE nodes are given a _DOMDOCTYPENODE structure.
     166     *
     167     *      Overview of member fields usage:
    80168     +
    81      +      ELEMENT         tag name        0                   named node map
     169     +      ulNodeType    | strNodeName | strNodeValue | llChildren | llAttributes
     170     +      =======================================================================
     171     +                    |             |              |            |
     172     +      DOCUMENT      | name from   | 0            | 1 root     | 0
     173     +                    | DOCTYPE or  |              | ELEMENT    |
     174     +                    | NULL        |              |            |
     175     +                    |             |              |            |
     176     +      --------------+-------------+--------------+------------+--------------
     177     +                    |             |              |            |
     178     +      ELEMENT       | tag name    | 0          8  | ELEMENT    | ATTRIBUTE
     179     +                    |             |              | nodes      | nodes
     180     +                    |             |              |            |
     181     +      --------------+-------------+--------------+------------+--------------
     182     +                    |             |              |            |
     183     +      ATTRIBUTE     | attribute   | attribute    | 0          | 0
     184     +                    | name        | value        |            |
     185     +                    |             |              |            |
     186     +      --------------+-------------+--------------+------------+--------------
     187     +                    |             |              |            |
     188     +      TEXT          | 0           | text         | 0          | 0
     189     +                    |             | contents     |            |
     190     +                    |             |              |            |
     191     +      --------------+-------------+--------------+------------+--------------
     192     +                    |             |              |            |
     193     +      COMMENT       | 0           | comment      | 0          | 0
     194     +                    |             | contents     |            |
     195     +                    |             |              |            |
     196     +      --------------+-------------+--------------+------------+--------------
     197     +                    |             |              |            |
     198     +      PI            | PI target   | PI data      | 0          | 0
     199     +                    |             |              |            |
     200     +                    |             |              |            |
     201     +      --------------+-------------+--------------+------------+--------------
     202     +                    |             |              |            |
     203     +      DOCTYPE       | doctype     |              | 0          | 0
     204     +                    | name        |              |            |
     205     +                    |             |              |            |
    82206     +
    83      +      ATTRIBUTE       attribute name  attribute value     0
    84      +
    85      +      TEXT            0               text contents       0
    86      +
    87      +      COMMENT         0               comment contents    0
    88      +
    89      +      DOCUMENT        0               0                   0
     207     *      The xwphelpers implementation does not implement CDATA sections,
     208     *      for which we have no need because @expat properly converts these
     209     *      into plain @content.
     210     *
     211     *      In addition, W3C DOM specifies that the "node name" members contain
     212     *      "#document", "#text", and "#comment" strings for DOCUMENT,
     213     *      TEXT, and COMMENT nodes, respectively. I see no point in this other
     214     *      than consuming memory, so these fields are empty with this implementation.
    90215     */
    91216
    92217    typedef struct _DOMNODE
    93218    {
    94         ULONG       ulNodeType;
    95                     // one of:
    96                     // -- DOMNODE_ELEMENT
    97                     // -- DOMNODE_ATTRIBUTE
    98                     // -- DOMNODE_TEXT
    99                     // -- DOMNODE_CDATA_SECTION
    100                     // -- DOMNODE_ENTITY_REFERENCE
    101                     // -- DOMNODE_ENTITY
    102                     // -- DOMNODE_PROCESSING_INSTRUCTION
    103                     // -- DOMNODE_COMMENT
    104                     // -- DOMNODE_DOCUMENT: the root document. See @documents.
    105                     // -- DOMNODE_DOCUMENT_TYPE
    106                     // -- DOMNODE_DOCUMENT_FRAGMENT
    107                     // -- DOMNODE_NOTATION
    108 
    109         XSTRING     strNodeName;            // malloc()'d
    110         XSTRING     strNodeValue;           // malloc()'d
     219        NODEBASE        NodeBase;
     220
     221        // PXSTRING    pstrNodeName;            // ptr is NULL if none
     222        PXSTRING        pstrNodeValue;           // ptr is NULL if none
    111223
    112224        struct _DOMNODE *pParentNode;
    113225                        // the parent node;
    114                         // NULL for DOCUMENT, DOCUMENT_FRAGMENT and ATTR
    115 
    116         LINKLIST    llChildNodes;     // of DOMNODE* pointers, no auto-free
    117 
    118         LINKLIST    llAttributeNodes; // of DOMNODE* pointers, no auto-free
     226                        // NULL for DOCUMENT, DOCUMENT_FRAGMENT.
     227                        // The DOM spec says that attribs have no parent,
     228                        // but even though the attribute is not added to
     229                        // the "children" list of an element (but to the
     230                        // attributes map instead), we specify the element
     231                        // as the attribute's parent here.
     232
     233        struct _DOMNODE *pDocumentNode;
     234                        // the document node, unless this is a DOCUMENT in itself.
     235
     236        LINKLIST        llChildren;     // of DOMNODE* pointers, no auto-free
     237
     238        TREE            *AttributesMap; // of DOMNODE* pointers
    119239
    120240    } DOMNODE, *PDOMNODE;
    121241
    122     #define XMLACTION_BREAKUP               1
    123     #define XMLACTION_COPYASTEXT            2
    124 
    125     typedef ULONG _Optlink FNVALIDATE(const char *pcszTag);
    126     typedef FNVALIDATE *PFNVALIDATE;
    127 
    128     PDOMNODE xmlCreateNode(PDOMNODE pParentNode,
    129                            ULONG ulNodeType);
     242    /*
     243     *@@ DOMDOCTYPENODE:
     244     *      specific _DOMNODE replacement structure which
     245     *      is used for DOCTYPE nodes.
     246     *
     247     *      The DOMDOCTYPENODE is special (other than having
     248     *      extra fields) in that it is stored both in
     249     *      the document node's children list and in its
     250     *      pDocType field.
     251     *
     252     *      DOMNODE.pstrNodeName is set to the name in the
     253     *      DOCTYPE statement by xmlCreateDocumentTypeNode,
     254     *      or is NULL if there's no DOCTYPE.
     255     *
     256     *@@added V0.9.9 (2001-02-14) [umoeller]
     257     */
     258
     259    typedef struct _DOMDOCTYPENODE
     260    {
     261        DOMNODE     DomNode;
     262
     263        XSTRING     strPublicID;
     264        XSTRING     strSystemID;
     265
     266        BOOL        fHasInternalSubset;
     267
     268        TREE        *ElementDeclsTree;
     269                    // tree with pointers to _CMELEMENTDECLNODE nodes
     270
     271        TREE        *AttribDeclBasesTree;
     272                    // tree with pointers to _CMATTRIBUTEDEDECLBASE nodes
     273
     274    } DOMDOCTYPENODE, *PDOMDOCTYPENODE;
     275
     276    /*
     277     *@@ DOMDOCUMENTNODE:
     278     *      specific _DOMNODE replacement structure which
     279     *      is used for DOCUMENT nodes.
     280     *
     281     *@@added V0.9.9 (2001-02-14) [umoeller]
     282     */
     283
     284    typedef struct _DOMDOCUMENTNODE
     285    {
     286        DOMNODE             DomNode;
     287
     288        PDOMDOCTYPENODE     pDocType;
     289                        // != NULL if DOCTYPE was found
     290
     291    } DOMDOCUMENTNODE, *PDOMDOCUMENTNODE;
     292
     293    APIRET xmlCreateNode(PDOMNODE pParentNode,
     294                         ULONG ulNodeType,
     295                         PDOMNODE *ppNew);
    130296
    131297    ULONG xmlDeleteNode(PDOMNODE pNode);
     298
     299    /* ******************************************************************
     300     *
     301     *   DOM level 3 content models
     302     *
     303     ********************************************************************/
     304
     305    // data types (XML schemes):
     306    #define STRING_DATATYPE                1
     307    #define BOOLEAN_DATATYPE               2
     308    #define FLOAT_DATATYPE                 3
     309    #define DOUBLE_DATATYPE                4
     310    #define LONG_DATATYPE                  5
     311    #define INT_DATATYPE                   6
     312    #define SHORT_DATATYPE                 7
     313    #define BYTE_DATATYPE                  8
     314
     315    /*
     316     *@@ CMELEMENTPARTICLE:
     317     *      element declaration particle in a
     318     *      _CMELEMENTDECLNODE.
     319     *
     320     *      One of these structures is a full
     321     *      (non-pointer) member in _CMELEMENTDECLNODE.
     322     *      This struct in turn has a linked list with
     323     *      possible subnodes. See _CMELEMENTDECLNODE.
     324     *
     325     *@@added V0.9.9 (2001-02-16) [umoeller]
     326     */
     327
     328    typedef struct _CMELEMENTPARTICLE
     329    {
     330        NODEBASE          CMNode;         // has TREE* as first item in turn
     331                    // NODEBASE.ulCMNodeType may be one of these:
     332                    // -- ELEMENTPARTICLE_EMPTY:
     333                    //          ulRepeater will be XML_CQUANT_NONE, rest is NULL
     334                    // -- ELEMENTPARTICLE_ANY:
     335                    //          ulRepeater will be XML_CQUANT_NONE, rest is NULL
     336                    // -- ELEMENTPARTICLE_MIXED:
     337                    //          mixed content (with PCDATA); if the list contains
     338                    //          something, the element may have PCDATA and sub-elements
     339                    //          mixed
     340                    // -- ELEMENTPARTICLE_CHOICE:
     341                    //          list is a choicelist
     342                    // -- ELEMENTPARTICLE_SEQ:
     343                    //          list is a seqlist
     344                    // -- ELEMENTPARTICLE_NAME:
     345                    //          used for terminal particles in a parent particle's
     346                    //          list, which finally specifies the name of a sub-particle.
     347                    //          This can never appear in a root particle.
     348
     349        ULONG           ulRepeater;
     350                    // one of:
     351                    // -- XML_CQUANT_NONE   --> all fields below are NULL
     352                    // -- XML_CQUANT_OPT,
     353                    // -- XML_CQUANT_REP,
     354                    // -- XML_CQUANT_PLUS
     355
     356        PLINKLIST       pllSubNodes;
     357                    // linked list of sub-CMELEMENTPARTICLE structs
     358                    // (for mixed, choice, seq types);
     359                    // if NULL, there's no sub-CMELEMENTPARTICLE
     360
     361    } CMELEMENTPARTICLE, *PCMELEMENTPARTICLE;
     362
     363    /*
     364     *@@ CMELEMENTDECLNODE:
     365     *      representation of an @element_declaration within a
     366     *      _DOMDOCTYPENODE (a document @DTD).
     367     *
     368     *      This is complicated because element declarations
     369     *      are complicated with nested lists and content
     370     *      particles. For this, we introduce the representation
     371     *      of a _CMELEMENTPARTICLE, which is contained in the
     372     *      "Particle" member.
     373     *
     374     *      For minimal memory consumption, the _CMELEMENTDECLNODE
     375     *      is an _CMELEMENTPARTICLE with extra fields, while the
     376     *      list in _CMELEMENTPARTICLE points to plain
     377     *      _CMELEMENTPARTICLE structs only.
     378     *
     379     *      For the "root" element declaration in the DTD,
     380     *      Particle.NODEBASE.ulCMNodeType will always be one of the following:
     381     *
     382     *      -- ELEMENTPARTICLE_EMPTY: element must be empty.
     383     *
     384     *      -- ELEMENTPARTICLE_ANY: element can have any content.
     385     *
     386     *      -- ELEMENTPARTICLE_CHOICE: _CMELEMENTPARTICLE has a choicelist with
     387     *                           more _CMELEMENTPARTICLE structs.
     388     *
     389     *      -- ELEMENTPARTICLE_SEQ: _CMELEMENTPARTICLE has a seqlist with
     390     *                           more _CMELEMENTPARTICLE structs.
     391     *
     392     *      -- ELEMENTPARTICLE_MIXED: element can have mixed content including #PCDATA.
     393     *            If there is no content particle list, then the element may
     394     *            ONLY have PCDATA. If there's a content particle list, then the
     395     *            element may have both sub-elements and PCDATA. Oh my.
     396     *
     397     *@@added V0.9.9 (2001-02-14) [umoeller]
     398     */
     399
     400    typedef struct _CMELEMENTDECLNODE
     401    {
     402        CMELEMENTPARTICLE   Particle;
     403                    // root particle for this element decl; this may contain
     404                    // sub-particles...
     405                    // this has a NODEBASE as first member, which has TREE* as
     406                    // first item in turn
     407
     408        TREE            *ParticleNamesTree;
     409                    // tree sorted by element names with all sub-particles,
     410                    // no matter how deeply nested; this is just for quickly
     411                    // checking if an element name is allowed as a sub-element
     412                    // at all. Tree items are _CMELEMENTPARTICLE nodes.
     413
     414    } CMELEMENTDECLNODE, *PCMELEMENTDECLNODE;
     415
     416    typedef enum _ATTRIBCONSTRAINT
     417    {
     418        CMAT_IMPLIED,
     419        CMAT_REQUIRED,
     420        CMAT_DEFAULT_VALUE,
     421        CMAT_FIXED_VALUE
     422    } ATTRIBCONSTRAINT;
     423
     424    typedef enum _ATTRIBTYPE
     425    {
     426        CMAT_CDATA,
     427        CMAT_ID,
     428        CMAT_IDREF,
     429        CMAT_IDREFS,
     430        CMAT_ENTITY,
     431        CMAT_ENTITIES,
     432        CMAT_NMTOKEN,
     433        CMAT_NMTOKENS,
     434        CMAT_ENUM
     435    } ATTRIBTYPE;
     436
     437    /*
     438     *@@ CMATTRIBUTEDECL:
     439     *      single attribute declaration within the attribute
     440     *      declarations tree in _CMATTRIBUTEDEDECLBASE.
     441     *
     442     *@@added V0.9.9 (2001-02-16) [umoeller]
     443     */
     444
     445    typedef struct _CMATTRIBUTEDECL
     446    {
     447        NODEBASE          CMNode;         // has TREE* as first item in turn
     448                    // CMNode.strName is attribute name
     449
     450        // XSTRING         strType;
     451
     452        ATTRIBTYPE      ulAttrType;
     453                    // one of:
     454                    // -- CMAT_CDATA
     455                    // -- CMAT_ID
     456                    // -- CMAT_IDREF
     457                    // -- CMAT_IDREFS
     458                    // -- CMAT_ENTITY
     459                    // -- CMAT_ENTITIES
     460                    // -- CMAT_NMTOKEN
     461                    // -- CMAT_NMTOKENS
     462                    // -- CMAT_ENUM: pllEnum lists the allowed values.
     463        TREE            *ValuesTree;
     464                    // enumeration of allowed values, if CMAT_ENUM;
     465                    // tree entries are plain NODEBASEs
     466
     467        ATTRIBCONSTRAINT    ulConstraint;
     468                    // one of:
     469                    // -- CMAT_IMPLIED: attrib can have any value.
     470                    // -- CMAT_REQUIRED: attrib must be specified.
     471                    // -- CMAT_DEFAULT_VALUE: attrib is optional and has default
     472                    //                        value as in pstrDefaultValue.
     473                    // -- CMAT_FIXED_VALUE: attrib is optional, but must have
     474                    //                        fixed value as in pstrDefaultValue.
     475        PXSTRING        pstrDefaultValue;
     476                    // default value of this attribute; NULL with implied or required
     477
     478    } CMATTRIBUTEDECL, *PCMATTRIBUTEDECL;
     479
     480    /*
     481     *@@ CMATTRIBUTEDEDECLBASE:
     482     *      representation of an @attribute_declaration.
     483     *
     484     *      I'd love to have stored the attribute declarations with
     485     *      the element specifications, but the XML spec says that
     486     *      attribute declarations are allowed even if no element
     487     *      declaration exists for the element to which the attribute
     488     *      belongs. Now, whatever this is good for... anyway, this
     489     *      forces us to do a second tree in the _DOMDOCTYPENODE node
     490     *      according to attribute's element names.
     491     *
     492     *@@added V0.9.9 (2001-02-14) [umoeller]
     493     */
     494
     495    typedef struct _CMATTRIBUTEDEDECLBASE
     496    {
     497        NODEBASE        CMNode;         // has TREE* as first item in turn
     498                    // CMNode.strName is element name
     499
     500        TREE            *AttribDeclsTree;
     501                            // root of tree with CMATTRIBUTEDECL;
     502
     503    } CMATTRIBUTEDEDECLBASE, *PCMATTRIBUTEDEDECLBASE;
     504
     505    /*
     506     *@@ CMENTITYDECLNODE:
     507     *
     508     *      See @entity_declaration.
     509     *
     510     *@@added V0.9.9 (2001-02-14) [umoeller]
     511     */
     512
     513    typedef struct _CMENTITYDECLNODE
     514    {
     515        NODEBASE          CMNode;
     516    } CMENTITYDECLNODE, *PCMENTITYDECLNODE;
     517
     518    /*
     519     *@@ CMNOTATIONDECLNODE:
     520     *
     521     *      See @notation_declaration.
     522     *
     523     *@@added V0.9.9 (2001-02-14) [umoeller]
     524     */
     525
     526    typedef struct _CMNOTATIONDECLNODE
     527    {
     528        NODEBASE          CMNode;
     529    } CMNOTATIONDECLNODE, *PCMNOTATIONDECLNODE;
    132530
    133531    /* ******************************************************************
     
    141539     *      DOM instance returned by xmlCreateDOM.
    142540     *
    143      *@@added V0.9.9 (2000-02-14) [umoeller]
     541     *@@added V0.9.9 (2001-02-14) [umoeller]
    144542     */
    145543
     
    150548         */
    151549
    152         PDOMNODE        pDocumentNode;
    153 
    154         enum XML_Error  Error;
     550        PDOMDOCUMENTNODE pDocumentNode;
     551
     552        PDOMDOCTYPENODE pDocTypeNode;
     553                        // != NULL only if the document has a DOCTYPE
     554
     555        APIRET          arcDOM;         // validation errors etc.
     556        BOOL            fInvalid;       // TRUE after validation failed
     557
    155558        const char      *pcszErrorDescription;
    156559        ULONG           ulErrorLine;
    157560        ULONG           ulErrorColumn;
     561        PXSTRING        pxstrFailingNode; // element or attribute name
    158562
    159563        /*
     
    169573
    170574        PDOMNODE        pLastWasTextNode;
     575
     576        PCMATTRIBUTEDEDECLBASE pAttListDeclCache;
     577                            // cache for attribute declarations according
     578                            // to attdecl element name
    171579    } XMLDOM, *PXMLDOM;
     580
     581    #define DF_PARSECOMMENTS        0x0001
     582    #define DF_PARSEDTD             0x0002
    172583
    173584    APIRET xmlCreateDOM(ULONG flParserFlags,
     
    181592    APIRET xmlFreeDOM(PXMLDOM pDom);
    182593
     594    PCMELEMENTDECLNODE xmlFindElementDecl(PXMLDOM pDom,
     595                                          const XSTRING *pstrElementName);
     596
     597    PCMATTRIBUTEDEDECLBASE xmlFindAttribDeclBase(PXMLDOM pDom,
     598                                                 const XSTRING *pstrElementName);
     599
     600    PCMATTRIBUTEDECL xmlFindAttribDecl(PXMLDOM pDom,
     601                                       const XSTRING *pstrElementName,
     602                                       const XSTRING *pstrAttribName);
     603
    183604#endif
    184605
  • trunk/include/helpers/xstring.h

    r32 r38  
    8686    typedef XSTRCPY *PXSTRCPY;
    8787
     88    ULONG XWPENTRY xstrcpys(PXSTRING pxstr, const XSTRING *pcstrSource);
     89    typedef ULONG XWPENTRY XSTRCPYS(PXSTRING pxstr, const XSTRING *pcstrSource);
     90    typedef XSTRCPYS *PXSTRCPYS;
     91
    8892    ULONG XWPENTRY xstrcat(PXSTRING pxstr, const char *pcszSource, ULONG ulSourceLength);
    8993    typedef ULONG XWPENTRY XSTRCAT(PXSTRING pxstr, const char *pcszSource, ULONG ulSourceLength);
     
    9397    typedef ULONG XWPENTRY XSTRCATC(PXSTRING pxstr, CHAR c);
    9498    typedef XSTRCATC *PXSTRCATC;
     99
     100    ULONG XWPENTRY xstrcats(PXSTRING pxstr, const XSTRING *pcstrSource);
     101    typedef ULONG XWPENTRY XSTRCATS(PXSTRING pxstr, const XSTRING *pcstrSource);
     102    typedef XSTRCATS *PXSTRCATS;
    95103
    96104    /*
  • trunk/src/helpers/dosh.c

    r33 r38  
    18281828 *
    18291829 *@@added V0.9.7 (2000-12-02) [umoeller]
    1830  *@@changed V0.9.9 (2000-02-06) [umoeller]: removed disable; this broke the WarpCenter
     1830 *@@changed V0.9.9 (2001-02-06) [umoeller]: removed disable; this broke the WarpCenter
    18311831 */
    18321832
  • trunk/src/helpers/gpih.c

    r29 r38  
    55 *
    66 *      Usage: All PM programs.
    7  *
    8  *      A word about GPI rectangles: In general, graphics operations
    9  *      involving device coordinates (such as regions, bit maps and
    10  *      bit blts, and window management) use inclusive-exclusive
    11  *      rectangles.  All other graphics operations, such as GPI
    12  *      functions that define paths, use inclusive-inclusive rectangles.
    13  *
    14  *      This can be a problem with mixing Win and Gpi functions. For
    15  *      example, WinQueryWindowRect returns an inclusive-exclusive
    16  *      rectangle (so that the xRight value is the same as the window
    17  *      width -- tested V0.9.7 (2000-12-20) [umoeller]).
    18  *
    19  *      WinFillRect expects an inclusive-exclusive rectangle, so it
    20  *      will work with a rectangle from WinQueryWindowRect directly.
    21  *
    22  *      By contrast, the GpiBox expects an inclusive-inclusive rectangle.
    237 *
    248 *      Function prefixes (new with V0.81):
     
    8771 */
    8872
     73/*
     74 *@@gloss: GPI_rectangles GPI rectangles
     75 *      OS/2 PM (and GPI) uses two types of rectangles. This is rarely
     76 *      mentioned in the documentation, so a word is in order here.
     77 *
     78 *      In general, graphics operations
     79 *      involving device coordinates (such as regions, bit maps and
     80 *      bit blts, and window management) use inclusive-exclusive
     81 *      rectangles.  All other graphics operations, such as GPI
     82 *      functions that define paths, use inclusive-inclusive rectangles.
     83 *
     84 *      This can be a problem with mixing Win and Gpi functions. For
     85 *      example, WinQueryWindowRect returns an inclusive-exclusive
     86 *      rectangle (so that the xRight value is the same as the window
     87 *      width -- tested V0.9.7 (2000-12-20) [umoeller]).
     88 *
     89 *      WinFillRect expects an inclusive-exclusive rectangle, so it
     90 *      will work with a rectangle from WinQueryWindowRect directly.
     91 *
     92 *      By contrast, the GpiBox expects an inclusive-inclusive rectangle.
     93 */
     94
    8995/* ******************************************************************
    9096 *
     
    187193 *
    188194 *      The specified rectangle is inclusive, that is, the top
    189  *      right corner specifies the top right pixel to be drawn.
     195 *      right corner specifies the top right pixel to be drawn
     196 *      (see @GPI_rectangles).
    190197 *
    191198 *      This sets the current position to the bottom left corner
     
    223230 *      The specified rectangle is inclusive, that is, the top
    224231 *      right corner specifies the top right pixel to be drawn.
    225  *      This is different from WinFillRect.
     232 *      This is different from WinFillRect
     233 *      (see @GPI_rectangles).
    226234 *
    227235 *      If (lColor != -1), the HPS's current foreground color
     
    294302 *      The specified rectangle is inclusive, that is, the top
    295303 *      right corner specifies the top right pixel to be drawn.
    296  *      This is different from WinFillRect.
     304 *      This is different from WinFillRect
     305 *      (see @GPI_rectangles).
    297306 *
    298307 *      If usWidth > 1, the additional pixels will be drawn towards
     
    341350 *      The specified rectangle is inclusive, that is, the top
    342351 *      right corner specifies the top right pixel to be drawn.
    343  *      This is different from WinFillRect.
     352 *      This is different from WinFillRect
     353 *      (see @GPI_rectangles).
    344354 *
    345355 *      If usWidth > 1, the additional pixels will be drawn towards
  • trunk/src/helpers/helpers_post.in

    r35 r38  
    186186$(OUTPUTDIR)\xml.obj:      $(@B).c $(HLPINC)\$(@B).h \
    187187               $(PROJECTINC)\setup.h \
    188                $(HLPINC)\stringh.h
     188               $(HLPINC)\linklist.h $(HLPINC)\stringh.h $(HLPINC)\tree.h $(HLPINC)\xstring.h
    189189
    190190$(OUTPUTDIR)\xprf.obj:  $(@B).c $(HLPINC)\$(@B).h \
     
    205205$(INC)\expat\asciitab.h \
    206206$(INC)\expat\expat.h \
     207$(INC)\expat\expat_setup.h \
    207208$(INC)\expat\iasciitab.h \
    208209$(INC)\expat\latin1tab.h \
    209210$(INC)\expat\nametab.h \
    210211$(INC)\expat\utf8tab.h \
    211 $(INC)\expat\winconfig.h \
    212212$(INC)\expat\xmlrole.h \
    213213$(INC)\expat\xmltok.h \
  • trunk/src/helpers/linklist.c

    r35 r38  
    373373PLISTNODE lstQueryFirstNode(PLINKLIST pList)
    374374{
    375     if (pList)
    376         if (pList->ulMagic == LINKLISTMAGIC)
    377             return (pList->pFirst);
     375    if (    (pList)
     376         && (pList->ulMagic == LINKLISTMAGIC)
     377       )
     378        return (pList->pFirst);
     379
     380    return (0);
     381}
     382
     383/*
     384 *@@ lstQueryLastNode:
     385 *      similar to lstQueryFirstNode, but this returns
     386 *      the last node.
     387 *
     388 *@@added V0.9.9 (2001-02-14) [umoeller]
     389 */
     390
     391PLISTNODE lstQueryLastNode(PLINKLIST pList)
     392{
     393    if (    (pList)
     394         && (pList->ulMagic == LINKLISTMAGIC)
     395       )
     396        return (pList->pLast);
    378397
    379398    return (0);
  • trunk/src/helpers/prfh.c

    r33 r38  
    468468 *      --  PRFERR_WRITE: couldn't write data to target (PrfWriteProfileData error)
    469469 *
    470  *@@added V0.9.9 (2000-02-06) [umoeller]
     470 *@@added V0.9.9 (2001-02-06) [umoeller]
    471471 */
    472472
  • trunk/src/helpers/stringh.c

    r23 r38  
    8282    else
    8383        return (0);
     84}
     85
     86/*
     87 *@@ strhcmp:
     88 *      better strcmp. This doesn't crash if any of the
     89 *      string pointers are NULL, but returns a proper
     90 *      value then.
     91 *
     92 *      Besides, this is guaranteed to only return -1, 0,
     93 *      or +1, while strcmp can return any positive or
     94 *      negative value.
     95 *
     96 *@@added V0.9.9 (2001-02-16) [umoeller]
     97 */
     98
     99int strhcmp(const char *p1, const char *p2)
     100{
     101    if (p1 && p2)
     102    {
     103        int i = strcmp(p1, p2);
     104        if (i < 0) return (-1);
     105        if (i > 0) return (+1);
     106    }
     107    else if (p1)
     108        // but p2 is NULL: p1 greater than p2 then
     109        return (+1);
     110    else if (p2)
     111        // but p1 is NULL: p1 less than p2 then
     112        return (-1);
     113
     114    // return 0 if strcmp returned 0 above or both strings are NULL
     115    return (0);
    84116}
    85117
  • trunk/src/helpers/threads.c

    r33 r38  
    193193 *@@changed V0.9.5 (2000-08-26) [umoeller]: now using PTHREADINFO
    194194 *@@changed V0.9.7 (2000-12-18) [lafaix]: THRF_TRANSIENT support added
    195  *@@changed V0.9.9 (2000-02-06) [umoeller]: now returning TID
     195 *@@changed V0.9.9 (2001-02-06) [umoeller]: now returning TID
    196196 */
    197197
     
    203203                ULONG ulData)        // in: user data to be stored in THREADINFO
    204204{
    205     ULONG ulrc = 0;     // V0.9.9 (2000-02-06) [umoeller]
     205    ULONG ulrc = 0;     // V0.9.9 (2001-02-06) [umoeller]
    206206
    207207    // (2000-12-18) [lafaix] TRANSIENT
  • trunk/src/helpers/tree.c

    r33 r38  
    194194 * fnCompareIDs:
    195195 *
    196  *added V0.9.9 (2000-02-06) [umoeller]
     196 *added V0.9.9 (2001-02-06) [umoeller]
    197197 */
    198198
     
    252252 *          exists.
    253253 *
    254  *@@changed V0.9.9 (2000-02-06) [umoeller]: removed comparison func
     254 *@@changed V0.9.9 (2001-02-06) [umoeller]: removed comparison func
    255255 */
    256256
     
    927927 *      -- 1: current node first, then left node, then right node.
    928928 *      -- 2: left node first, then right node, then current node.
    929  *      -- other: left node first, then current node, then right node.
     929 *      -- 0 or other: left node first, then current node, then right node.
     930 *           This is the sorted order.
    930931 */
    931932
  • trunk/src/helpers/xml.c

    r35 r38  
    77 *      layers:
    88 *
    9  *      --  The bottom layer is implemented by expat, which I have
    10  *          ported to this library. See xmlparse.c for an introduction.
     9 *      --  The bottom layer is implemented by @expat, which I have
     10 *          ported and hacked to the xwphelpers. See xmlparse.c for
     11 *          an introduction.
    1112 *
    1213 *      --  Because expat requires so many callbacks and is non-validating,
     
    1516 *          (DOM) standardized by the W3C. That's this file.
    1617 *
    17  *      To understand and use this code, you should be familiar with
    18  *      the following:
    19  *
    20  *      -- XML parsers operate on XML @documents.
    21  *
    22  *      -- Each XML document has both a logical and a physical
    23  *         structure.
    24  *
    25  *         Physically, the document is composed of units called
    26  *         @entities.
    27  *
    28  *         Logically, the document is composed of @markup and
    29  *         @content. Among other things, markup separates the content
    30  *         into @elements.
    31  *
    32  *      -- The logical and physical structures must nest properly (be
    33  *         @well-formed) for each entity, which results in the entire
    34  *         XML document being well-formed as well.
     18 *      <B>XML</B>
     19 *
     20 *      In order to understand XML myself, I have written a couple of
     21 *      glossary entries for the complex XML terminology. See @XML
     22 *      for a start.
    3523 *
    3624 *      <B>Document Object Model (DOM)</B>
    3725 *
    38  *      In short, DOM specifies that an XML document is broken
    39  *      up into a tree of nodes, representing the various parts
    40  *      of an XML document. The W3C calls this "a platform- and
    41  *      language-neutral interface that allows programs and scripts
    42  *      to dynamically access and update the content, structure
    43  *      and style of documents. The Document Object Model provides
    44  *      a standard set of objects for representing HTML and XML
    45  *      documents, a standard model of how these objects can
    46  *      be combined, and a standard interface for accessing and
    47  *      manipulating them. Vendors can support the DOM as an
    48  *      interface to their proprietary data structures and APIs,
    49  *      and content authors can write to the standard DOM
    50  *      interfaces rather than product-specific APIs, thus
    51  *      increasing interoperability on the Web."
    52  *
    53  *      Example: Take this HTML table definition:
    54  +
    55  +          <TABLE>
    56  +          <TBODY>
    57  +          <TR>
    58  +          <TD>Column 1-1</TD>
    59  +          <TD>Column 1-2</TD>
    60  +          </TR>
    61  +          <TR>
    62  +          <TD>Column 2-1</TD>
    63  +          <TD>Column 2-2</TD>
    64  +          </TR>
    65  +          </TBODY>
    66  +          </TABLE>
    67  *
    68  *      This function will create a tree as follows:
    69  +
    70  +                          ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿
    71  +                          ³   TABLE    ³        (only ELEMENT node in root DOCUMENT node)
    72  +                          ÀÄÄÄÄÄÂÄÄÄÄÄÄÙ
    73  +                                ³
    74  +                          ÚÄÄÄÄÄÁÄÄÄÄÄÄ¿
    75  +                          ³   TBODY    ³        (only ELEMENT node in root "TABLE" node)
    76  +                          ÀÄÄÄÄÄÂÄÄÄÄÄÄÙ
    77  +                    ÚÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄ¿
    78  +              ÚÄÄÄÄÄÁÄÄÄÄÄÄ¿          ÚÄÄÄÄÄÁÄÄÄÄÄÄ¿
    79  +              ³   TR       ³          ³   TR       ³
    80  +              ÀÄÄÄÄÄÂÄÄÄÄÄÄÙ          ÀÄÄÄÄÄÂÄÄÄÄÄÄÙ
    81  +                ÚÄÄÄÁÄÄÄÄÄÄ¿            ÚÄÄÄÁÄÄÄÄÄÄ¿
    82  +            ÚÄÄÄÁÄ¿     ÚÄÄÁÄÄ¿     ÚÄÄÄÁÄ¿     ÚÄÄÁÄÄ¿
    83  +            ³ TD  ³     ³ TD  ³     ³ TD  ³     ³ TD  ³
    84  +            ÀÄÄÂÄÄÙ     ÀÄÄÂÄÄÙ     ÀÄÄÄÂÄÙ     ÀÄÄÂÄÄÙ
    85  +         ÉÍÍÍÍÍÊÍÍÍÍ» ÉÍÍÍÍÊÍÍÍÍÍ» ÉÍÍÍÍÊÍÍÍÍÍ» ÉÍÍÊÍÍÍÍÍÍÍ»
    86  +         ºColumn 1-1º ºColumn 1-2º ºColumn 2-1º ºColumn 2-2º    (one TEXT node in each parent node)
    87  +         ÈÍÍÍÍÍÍÍÍÍÍŒ ÈÍÍÍÍÍÍÍÍÍÍŒ ÈÍÍÍÍÍÍÍÍÍÍŒ ÈÍÍÍÍÍÍÍÍÍÍŒ
     26 *      See @DOM for a general introduction.
    8827 *
    8928 *      DOM really calls for object oriented programming so the various
    9029 *      structs can inherit from each other. Since this implementation
    91  *      was supposed to be a C-only interface, we do not implement
    92  *      inheritance. Instead, each XML document is broken up into a tree
    93  *      of DOMNODE's only, each of which has a special type.
     30 *      was supposed to be a C-only interface, we cannot implement
     31 *      inheritance at the language level. Instead, each XML document
     32 *      is broken up into a tree of node structures only (see _DOMNODE),
     33 *      each of which has a special type. The W3C DOM allows this
     34 *      (and calls this the "flattened" view, as opposed to the
     35 *      "inheritance view").
     36 *
     37 *      The W3C DOM specification prescribes tons of methods, which I
     38 *      really had no use for, so I didn't implement them. This implementation
     39 *      is only a DOM insofar as it uses nodes which represent @documents,
     40 *      @elements, @attributes, @comments, and @processing_instructions.
     41 *
     42 *      Most notably, there are the following differences:
     43 *
     44 *      --  Not all node types are implemented. See _DOMNODE for
     45 *          the supported types.
     46 *
     47 *      --  Only a small subset of the standardized methods is implemented,
     48 *          and they are called differently to adhere to the xwphelpers
     49 *          conventions.
     50 *
     51 *      --  DOM uses UTF-16 for its DOMString type. @expat gives UTF-8
     52 *          strings to all the handlers though, so all data in the DOM nodes
     53 *          is UTF-8 encoded. This still needs to be fixed.
     54 *
     55 *      --  DOM defines the DOMException class. This isn't supported in C.
     56 *          Instead, we use special error codes which add to the standard
     57 *          OS/2 error codes (APIRET). All our error codes are >= 40000
     58 *          to avoid conflicts.
    9459 *
    9560 *      It shouldn't be too difficult to write a C++ encapsulation
    96  *      of this which implements all the methods required by the DOM
    97  *      standard.
    98  *
    99  *      The main entry point into this is xmlParse or
    100  *      xmlCreateDocumentFromString. See remarks there for details.
    101  *
    102  *      Limitations:
    103  *
    104  *      1)  This presently only parses ELEMENT, ATTRIBUTE, TEXT,
    105  *          and COMMENT nodes.
    106  *
    107  *      2)  This doesn't use 16-bit characters, but 8-bit characters.
     61 *      of this though which fully implements all the DOM methods.
     62 *
     63 *      However, we do implement node management as in the standard.
     64 *      See xmlCreateNode and xmlDeleteNode.
     65 *
     66 *      The main entry point into this is xmlCreateDOM. See remarks
     67 *      there for details.
     68 *
     69 *      <B>Validation</B>
     70 *
     71 *      @expat doesn't check XML documents for whether they are @valid.
     72 *      In other words, expat is a non-validating XML processor.
     73 *
     74 *      By contrast, this pseudo-DOM implementation can validate. To
     75 *      do this, you must pass DF_PARSEDTD to xmlCreateDOM (otherwise
     76 *      the @DTD entries will not be stored in the DOM nodes). This
     77 *      will not validate yet; to do this, explicitly call xmlValidate.
    10878 *
    10979 *@@header "helpers\xml.h"
     
    141111#include "helpers\linklist.h"
    142112#include "helpers\stringh.h"
     113#include "helpers\tree.h"
    143114#include "helpers\xstring.h"
    144115#include "helpers\xml.h"
     
    158129/* ******************************************************************
    159130 *
    160  *   Node management
     131 *   Generic methods
    161132 *
    162133 ********************************************************************/
     134
     135/*
     136 *@@ CompareCMNodeNodes:
     137 *      tree comparison func for CMNodes.
     138 *      This works for all trees which contain structures
     139 *      whose first item is a _NODEBASE because NODEBASE's first
     140 *      member is a TREE.
     141 *
     142 *      Used in two places:
     143 *
     144 *      --  to insert _CMELEMENTDECLNODE nodes into
     145 *          _DOMDOCTYPENODE.ElementDeclsTree;
     146 *
     147 *      --  to insert _CMELEMENTPARTICLE nodes into
     148 *          _CMELEMENTDECLNODE.ElementNamesTree.
     149 *
     150 *@@added V0.9.9 (2001-02-16) [umoeller]
     151 */
     152
     153int CompareCMNodeNodes(TREE *t1,
     154                       TREE *t2)
     155{
     156    PNODEBASE   p1 = (PNODEBASE)t1,
     157                p2 = (PNODEBASE)t2;
     158    return (strhcmp(p1->strNodeName.psz, p2->strNodeName.psz));
     159}
     160
     161/*
     162 *@@ CompareCMNodeNodes:
     163 *      tree comparison func for element declarations.
     164 *      Used to find nodes in _DOMDOCTYPENODE.ElementDeclsTree.
     165 *
     166 *@@added V0.9.9 (2001-02-16) [umoeller]
     167 */
     168
     169int CompareCMNodeData(TREE *t1,
     170                           void *pData)
     171{
     172    PNODEBASE     p1 = (PNODEBASE)t1;
     173    return (strhcmp(p1->strNodeName.psz, (const char*)pData));
     174}
    163175
    164176/*
     
    166178 *      creates a new DOMNODE with the specified
    167179 *      type and parent. Other than that, the
    168  *      node is zeroed.
    169  */
    170 
    171 PDOMNODE xmlCreateNode(PDOMNODE pParentNode,        // in: parent node or NULL if root
    172                        ULONG ulNodeType)            // in: DOMNODE_* type
    173 {
    174     PDOMNODE pNewNode = (PDOMNODE)malloc(sizeof(DOMNODE));
    175     if (pNewNode)
    176     {
    177         memset(pNewNode, 0, sizeof(DOMNODE));
    178         pNewNode->ulNodeType = ulNodeType;
     180 *      node fields are zeroed.
     181 *
     182 *      If pParentNode is specified (which is required,
     183 *      unless you are creating a document node),
     184 *      its children list is automatically updated
     185 *      (unless this is an attribute node, which updates
     186 *      the attributes map).
     187 *
     188 *      This returns the following errors:
     189 *
     190 *      --  ERROR_NOT_ENOUGH_MEMORY
     191 *
     192 *      --  ERROR_DOM_NOT_SUPPORTED: invalid ulNodeType
     193 *          specified.
     194 *
     195 *      --  ERROR_DOM_WRONG_DOCUMENT: cannot find the
     196 *          document for this node. This happens if you do
     197 *          not have a document node at the root of your tree.
     198 */
     199
     200APIRET xmlCreateNode(PDOMNODE pParentNode,        // in: parent node or NULL if root
     201                     ULONG ulNodeType,            // in: DOMNODE_* type
     202                     PDOMNODE *ppNew)             // out: new node
     203{
     204    PDOMNODE pNewNode = NULL;
     205    APIRET  arc = NO_ERROR;
     206
     207    ULONG   cb = 0;
     208
     209    switch (ulNodeType)
     210    {
     211        case DOMNODE_DOCUMENT:
     212            cb = sizeof(DOMDOCUMENTNODE);
     213        break;
     214
     215        case DOMNODE_DOCUMENT_TYPE:
     216            cb = sizeof(DOMDOCTYPENODE);
     217        break;
     218
     219        default:
     220            cb = sizeof(DOMNODE);
     221        break;
     222    }
     223
     224    pNewNode = (PDOMNODE)malloc(cb);
     225
     226    if (!pNewNode)
     227        arc = ERROR_NOT_ENOUGH_MEMORY;
     228    else
     229    {
     230        memset(pNewNode, 0, cb);
     231        pNewNode->NodeBase.ulNodeType = ulNodeType;
     232        xstrInit(&pNewNode->NodeBase.strNodeName, 0);
    179233        pNewNode->pParentNode = pParentNode;
     234
    180235        if (pParentNode)
    181236        {
    182237            // parent specified:
    183             // append this new node to the parent's
    184             // list of child nodes
    185             lstAppendItem(&pParentNode->llChildNodes,
    186                           pNewNode);
     238            // check if this is an attribute
     239            if (ulNodeType == DOMNODE_ATTRIBUTE)
     240            {
     241                // attribute:
     242                // add to parent's attributes list
     243                if (treeInsertNode(&pParentNode->AttributesMap,
     244                                   (TREE*)pNewNode,
     245                                   CompareCMNodeNodes,
     246                                   FALSE)      // no duplicates
     247                        == TREE_DUPLICATE)
     248                    arc = ERROR_DOM_DUPLICATE_ATTRIBUTE;
     249                                // shouldn't happen, because expat takes care of this
     250            }
     251            else
     252                // append this new node to the parent's
     253                // list of child nodes
     254                lstAppendItem(&pParentNode->llChildren,
     255                              pNewNode);
     256
     257            if (!arc)
     258            {
     259                // set document pointer...
     260                // if the parent node has a document pointer,
     261                // we can copy that
     262                if (pParentNode->pDocumentNode)
     263                    pNewNode->pDocumentNode = pParentNode->pDocumentNode;
     264                else
     265                    // parent has no document pointer: then it is probably
     266                    // the document itself... check
     267                    if (pParentNode->NodeBase.ulNodeType == DOMNODE_DOCUMENT)
     268                        pNewNode->pDocumentNode = pParentNode;
     269                    else
     270                        arc = ERROR_DOM_NO_DOCUMENT;
     271            }
    187272        }
    188273
    189         lstInit(&pNewNode->llChildNodes, FALSE);
    190         lstInit(&pNewNode->llAttributeNodes, FALSE);
    191     }
    192 
    193     return (pNewNode);
     274        lstInit(&pNewNode->llChildren, FALSE);
     275        treeInit(&pNewNode->AttributesMap);
     276    }
     277
     278    if (!arc)
     279        *ppNew = pNewNode;
     280    else
     281        if (pNewNode)
     282            free(pNewNode);
     283
     284    return (arc);
    194285}
    195286
    196287/*
    197288 *@@ xmlDeleteNode:
    198  *      deletes the specified node.
     289 *      deletes the specified node and updates the
     290 *      parent node's children list.
    199291 *
    200292 *      If the node has child nodes, all of them are deleted
     
    205297 *      child nodes.
    206298 *
    207  *      Returns:
    208  *
    209  *      -- 0: NO_ERROR.
    210  */
    211 
    212 ULONG xmlDeleteNode(PDOMNODE pNode)
     299 *      This returns the following errors:
     300 *
     301 *      -- ERROR_DOM_NOT_FOUND
     302 */
     303
     304APIRET xmlDeleteNode(PDOMNODE pNode)
    213305{
    214306    ULONG ulrc = 0;
     
    216308    if (!pNode)
    217309    {
    218         ulrc = ERROR_DOM_NOT_FOUND;
     310        ulrc = ERROR_INVALID_PARAMETER;
    219311    }
    220312    else
    221313    {
     314        PLISTNODE   pNodeThis;
     315
    222316        // recurse into child nodes
    223         PLISTNODE   pNodeThis = lstQueryFirstNode(&pNode->llChildNodes);
    224         while (pNodeThis)
    225         {
     317        while (pNodeThis  = lstQueryFirstNode(&pNode->llChildren))
    226318            // recurse!!
    227319            xmlDeleteNode((PDOMNODE)(pNodeThis->pItemData));
    228 
    229             pNodeThis = pNodeThis->pNext;
    230         }
    231 
    232         // delete attribute nodes
    233         pNodeThis = lstQueryFirstNode(&pNode->llAttributeNodes);
    234         while (pNodeThis)
    235         {
    236             // recurse!!
    237             xmlDeleteNode((PDOMNODE)(pNodeThis->pItemData));
    238 
    239             pNodeThis = pNodeThis->pNext;
    240         }
     320                        // this updates llChildren
     321
     322        // recurse into attribute nodes
     323        // while (pNodeThis = lstQueryFirstNode(&pNode->llAttributes))
     324            // recurse!! ###
     325            // xmlDeleteNode((PDOMNODE)(pNodeThis->pItemData));
     326                        // this updates llAttributes
    241327
    242328        if (pNode->pParentNode)
    243329        {
    244330            // node has a parent:
    245             // remove this node from the parent's list
    246             // of child nodes before deleting this node
    247             lstRemoveItem(&pNode->pParentNode->llChildNodes,
    248                           pNode);
     331            if (pNode->NodeBase.ulNodeType == DOMNODE_ATTRIBUTE)
     332                // this is an attribute:
     333                // remove from parent's attributes map
     334                treeDelete(&pNode->pParentNode->AttributesMap,
     335                           (TREE*)pNode);
     336            else
     337                // remove this node from the parent's list
     338                // of child nodes before deleting this node
     339                lstRemoveItem(&pNode->pParentNode->llChildren,
     340                              pNode);
     341
    249342            pNode->pParentNode = NULL;
    250343        }
    251344
    252         xstrClear(&pNode->strNodeName);
    253         xstrClear(&pNode->strNodeValue);
    254 
    255         lstClear(&pNode->llChildNodes);
    256         lstClear(&pNode->llAttributeNodes);
     345        xstrClear(&pNode->NodeBase.strNodeName);
     346        xstrFree(pNode->pstrNodeValue);
     347
     348        lstClear(&pNode->llChildren);
     349        // lstClear(&pNode->llAttributes); ###
    257350
    258351        free(pNode);
     
    262355}
    263356
     357/*
     358 *@@ xmlGetFirstChild:
     359 *      returns the first child node of pDomNode.
     360 *      See _DOMNODE for what a "child" can be for the
     361 *      various node types.
     362 *
     363 *@@added V0.9.9 (2001-02-14) [umoeller]
     364 */
     365
     366PDOMNODE xmlGetFirstChild(PDOMNODE pDomNode)
     367{
     368    PLISTNODE pListNode = lstQueryFirstNode(&pDomNode->llChildren);
     369    if (pListNode)
     370        return ((PDOMNODE)pListNode->pItemData);
     371
     372    return (0);
     373}
     374
     375/*
     376 *@@ xmlGetLastChild:
     377 *      returns the last child node of pDomNode.
     378 *      See _DOMNODE for what a "child" can be for the
     379 *      various node types.
     380 *
     381 *@@added V0.9.9 (2001-02-14) [umoeller]
     382 */
     383
     384PDOMNODE xmlGetLastChild(PDOMNODE pDomNode)
     385{
     386    PLISTNODE pListNode = lstQueryLastNode(&pDomNode->llChildren);
     387    if (pListNode)
     388        return ((PDOMNODE)pListNode->pItemData);
     389
     390    return (0);
     391}
     392
     393/*
     394 *@@ xmlDescribeError:
     395 *      returns a string describing the error corresponding to code.
     396 *      The code should be one of the enums that can be returned from
     397 *      XML_GetErrorCode.
     398 *
     399 *@@changed V0.9.9 (2001-02-14) [umoeller]: adjusted for new error codes
     400 *@@changed V0.9.9 (2001-02-16) [umoeller]: moved this here from xmlparse.c
     401 */
     402
     403const char* xmlDescribeError(int code)
     404{
     405    static const char *message[] =
     406    {
     407        // start of expat (parser) errors
     408        "Out of memory",
     409        "Syntax error",
     410        "No element found",
     411        "Not well-formed (invalid token)",
     412        "Unclosed token",
     413        "Unclosed token",
     414        "Mismatched tag",
     415        "Duplicate attribute",
     416        "Junk after root element",
     417        "Illegal parameter entity reference",
     418        "Undefined entity",
     419        "Recursive entity reference",
     420        "Asynchronous entity",
     421        "Reference to invalid character number",
     422        "Reference to binary entity",
     423        "Reference to external entity in attribute",
     424        "XML processing instruction not at start of external entity",
     425        "Unknown encoding",
     426        "Encoding specified in XML declaration is incorrect",
     427        "Unclosed CDATA section",
     428        "Error in processing external entity reference",
     429        "Document is not standalone",
     430        "Unexpected parser state - please send a bug report",
     431        // end of expat (parser) errors
     432
     433        // start of validation errors
     434        "Element has not been declared",
     435        "Root element name does not match DOCTYPE name",
     436        "Invalid or duplicate root element",
     437        "Invalid sub-element in parent element",
     438        "Duplicate element declaration",
     439        "Duplicate attribute declaration",
     440        "Undeclared attribute in element"
     441    };
     442
     443    int code2 = code - ERROR_XML_FIRST;
     444
     445    if (    code2 >= 0
     446         && code2 < sizeof(message) / sizeof(message[0])
     447       )
     448        return message[code2];
     449
     450    return 0;
     451}
     452
     453/*
     454 *@@ xmlSetError:
     455 *      sets the DOM's error state and stores error information
     456 *      and parser position.
     457 *
     458 *@@added V0.9.9 (2001-02-16) [umoeller]
     459 */
     460
     461VOID xmlSetError(PXMLDOM pDom,
     462                 APIRET arc,
     463                 const char *pcszFailing,
     464                 BOOL fValidityError)   // in: if TRUE, this is a validation error;
     465                                        // if FALSE, this is a parser error
     466{
     467    pDom->arcDOM = arc;
     468    pDom->pcszErrorDescription = xmlDescribeError(pDom->arcDOM);
     469    pDom->ulErrorLine = XML_GetCurrentLineNumber(pDom->pParser);
     470    pDom->ulErrorColumn = XML_GetCurrentColumnNumber(pDom->pParser);
     471
     472    if (pcszFailing)
     473    {
     474        if (!pDom->pxstrFailingNode)
     475            pDom->pxstrFailingNode = xstrCreate(0);
     476
     477        xstrcpy(pDom->pxstrFailingNode, pcszFailing, 0);
     478    }
     479
     480    if (fValidityError)
     481        pDom->fInvalid = TRUE;
     482}
     483
    264484/* ******************************************************************
    265485 *
     486 *   Specific DOM node methods
     487 *
     488 ********************************************************************/
     489
     490/*
     491 *@@ xmlCreateElementNode:
     492 *      creates a new element node with the specified name.
     493 *
     494 *@@added V0.9.9 (2001-02-14) [umoeller]
     495 */
     496
     497APIRET xmlCreateElementNode(PDOMNODE pParent,         // in: parent node (either document or element)
     498                            const char *pcszElement,  // in: element name (null-terminated)
     499                            PDOMNODE *ppNew)
     500{
     501    PDOMNODE pNew = NULL;
     502    APIRET arc = xmlCreateNode(pParent,
     503                               DOMNODE_ELEMENT,
     504                               &pNew);
     505
     506    if (arc == NO_ERROR)
     507    {
     508        xstrcpy(&pNew->NodeBase.strNodeName, pcszElement, 0);
     509
     510        *ppNew = pNew;
     511    }
     512
     513    return (arc);
     514}
     515
     516/*
     517 *@@ xmlCreateAttributeNode:
     518 *      creates a new attribute node with the specified data.
     519 *
     520 *      NOTE: Attributes have no "parent" node, technically.
     521 *      They are added to a special, separate list in @DOM_ELEMENT
     522 *      nodes.
     523 *
     524 *      This returns the following errors:
     525 *
     526 *      --  Error codes from xmlCreateNode.
     527 *
     528 *      --  ERROR_DOM_NO_ELEMENT: pElement is invalid or does
     529 *          not point to an @DOM_ELEMENT node.
     530 *
     531 *@@added V0.9.9 (2001-02-14) [umoeller]
     532 */
     533
     534APIRET xmlCreateAttributeNode(PDOMNODE pElement,        // in: element node
     535                              const char *pcszName,     // in: attribute name (null-terminated)
     536                              const char *pcszValue,    // in: attribute value (null-terminated)
     537                              PDOMNODE *ppNew)
     538{
     539    APIRET arc = NO_ERROR;
     540
     541    if (    !pElement
     542         || pElement->NodeBase.ulNodeType != DOMNODE_ELEMENT
     543       )
     544        arc = ERROR_DOM_NO_ELEMENT;
     545    else
     546    {
     547        PDOMNODE pNew = NULL;
     548        arc = xmlCreateNode(pElement,          // this takes care of adding to the list
     549                            DOMNODE_ATTRIBUTE,
     550                            &pNew);
     551        if (arc == NO_ERROR)
     552        {
     553            xstrcpy(&pNew->NodeBase.strNodeName, pcszName, 0);
     554            pNew->pstrNodeValue = xstrCreate(0);
     555            xstrcpy(pNew->pstrNodeValue, pcszValue, 0);
     556
     557            *ppNew = pNew;
     558        }
     559    }
     560
     561    return (arc);
     562}
     563
     564/*
     565 *@@ xmlCreateTextNode:
     566 *      creates a new text node with the specified content.
     567 *
     568 *      Note: This differs from the createText method
     569 *      as specified by DOM, which has no ulLength parameter.
     570 *      We need this for speed with @expat though.
     571 *
     572 *@@added V0.9.9 (2001-02-14) [umoeller]
     573 */
     574
     575APIRET xmlCreateTextNode(PDOMNODE pParent,         // in: parent element node
     576                         const char *pcszText,     // in: ptr to start of text
     577                         ULONG ulLength,           // in: length of *pcszText
     578                         PDOMNODE *ppNew)
     579{
     580    PDOMNODE pNew = NULL;
     581    APIRET arc = xmlCreateNode(pParent,
     582                               DOMNODE_TEXT,
     583                               &pNew);
     584    if (arc == NO_ERROR)
     585    {
     586        PSZ pszNodeValue = (PSZ)malloc(ulLength + 1);
     587        if (!pszNodeValue)
     588        {
     589            arc = ERROR_NOT_ENOUGH_MEMORY;
     590            xmlDeleteNode(pNew);
     591        }
     592        else
     593        {
     594            memcpy(pszNodeValue, pcszText, ulLength);
     595            pszNodeValue[ulLength] = '\0';
     596            pNew->pstrNodeValue = xstrCreate(0);
     597            xstrset(pNew->pstrNodeValue, pszNodeValue);
     598
     599            *ppNew = pNew;
     600        }
     601    }
     602
     603    return (arc);
     604}
     605
     606/*
     607 *@@ xmlCreateCommentNode:
     608 *      creates a new comment node with the specified
     609 *      content.
     610 *
     611 *@@added V0.9.9 (2001-02-14) [umoeller]
     612 */
     613
     614APIRET xmlCreateCommentNode(PDOMNODE pParent,         // in: parent element node
     615                            const char *pcszText,     // in: comment (null-terminated)
     616                            PDOMNODE *ppNew)
     617{
     618    PDOMNODE pNew = NULL;
     619    APIRET arc = xmlCreateNode(pParent,
     620                               DOMNODE_COMMENT,
     621                               &pNew);
     622    if (arc == NO_ERROR)
     623    {
     624        pNew->pstrNodeValue = xstrCreate(0);
     625        xstrcpy(pNew->pstrNodeValue, pcszText, 0);
     626        *ppNew = pNew;
     627    }
     628
     629    return (arc);
     630}
     631
     632/*
     633 *@@ xmlCreatePINode:
     634 *      creates a new processing instruction node with the
     635 *      specified data.
     636 *
     637 *@@added V0.9.9 (2001-02-14) [umoeller]
     638 */
     639
     640APIRET xmlCreatePINode(PDOMNODE pParent,         // in: parent element node
     641                       const char *pcszTarget,   // in: PI target (null-terminated)
     642                       const char *pcszData,     // in: PI data (null-terminated)
     643                       PDOMNODE *ppNew)
     644{
     645    PDOMNODE pNew = NULL;
     646    APIRET arc = xmlCreateNode(pParent,
     647                               DOMNODE_PROCESSING_INSTRUCTION,
     648                               &pNew);
     649    if (arc == NO_ERROR)
     650    {
     651        xstrcpy(&pNew->NodeBase.strNodeName, pcszTarget, 0);
     652        pNew->pstrNodeValue = xstrCreate(0);
     653        xstrcpy(pNew->pstrNodeValue, pcszData, 0);
     654
     655        *ppNew = pNew;
     656    }
     657
     658    return (arc);
     659}
     660
     661/*
     662 *@@ xmlCreateDocumentTypeNode:
     663 *      creates a new document type node with the
     664 *      specified data.
     665 *
     666 *@@added V0.9.9 (2001-02-14) [umoeller]
     667 */
     668
     669APIRET xmlCreateDocumentTypeNode(PDOMDOCUMENTNODE pDocumentNode,            // in: document node
     670                                 const char *pcszDoctypeName,
     671                                 const char *pcszSysid,
     672                                 const char *pcszPubid,
     673                                 int fHasInternalSubset,
     674                                 PDOMDOCTYPENODE *ppNew)
     675{
     676    APIRET arc = NO_ERROR;
     677
     678    if (pDocumentNode->pDocType)
     679        // we already have a doctype:
     680        arc = ERROR_DOM_DUPLICATE_DOCTYPE;
     681    else
     682    {
     683        // create doctype node
     684        PDOMDOCTYPENODE pNew = NULL;
     685        arc = xmlCreateNode((PDOMNODE)pDocumentNode,
     686                            DOMNODE_DOCUMENT_TYPE,
     687                            (PDOMNODE*)&pNew);
     688
     689        if (!arc)
     690        {
     691            // the node has already been added to the children
     692            // list of the document node... in addition, set
     693            // the doctype field in the document
     694            pDocumentNode->pDocType = pNew;
     695
     696            // initialize the extra fields
     697            xstrcpy(&pNew->strPublicID, pcszPubid, 0);
     698            xstrcpy(&pNew->strSystemID, pcszSysid, 0);
     699            pNew->fHasInternalSubset = fHasInternalSubset;
     700
     701            if (pcszDoctypeName)
     702            {
     703                ULONG ul = strlen(pcszDoctypeName);
     704                if (ul)
     705                {
     706                    xstrcpy(&pDocumentNode->DomNode.NodeBase.strNodeName,
     707                            pcszDoctypeName,
     708                            ul);
     709                }
     710            }
     711
     712            treeInit(&pNew->ElementDeclsTree);
     713            treeInit(&pNew->AttribDeclBasesTree);
     714
     715            *ppNew = pNew;
     716        }
     717    }
     718    return (arc);
     719}
     720
     721/*
     722 *@@ xmlGetElementsByTagName:
     723 *      returns a linked list of @DOM_ELEMENT nodes which
     724 *      match the specified element name. The special name
     725 *      "*" matches all elements.
     726 *
     727 *      The caller must free the list by calling lstFree.
     728 *      Returns NULL if no such elements could be found.
     729 *
     730 *@@added V0.9.9 (2001-02-14) [umoeller]
     731 */
     732
     733PLINKLIST xmlGetElementsByTagName(const char *pcszName)
     734{
     735    APIRET arc = NO_ERROR;
     736
     737    return (0);
     738}
     739
     740/* ******************************************************************
     741 *
     742 *   Content model methods
     743 *
     744 ********************************************************************/
     745
     746/*
     747 *@@ SetupParticleAndSubs:
     748 *
     749 *      This creates sub-particles and recurses to set them up,
     750 *      if necessary.
     751 *
     752 *@@added V0.9.9 (2001-02-16) [umoeller]
     753 */
     754
     755APIRET SetupParticleAndSubs(PCMELEMENTPARTICLE pParticle,
     756                            PXMLCONTENT pModel,
     757                            TREE **ppElementNamesTree) // in: ptr to _CMELEMENTDECLNODE.ElementNamesTree
     758                                                       // (passed to all recursions)
     759{
     760    APIRET arc = NO_ERROR;
     761
     762    // set up member NODEBASE
     763    switch (pModel->type)
     764    {
     765        case XML_CTYPE_EMPTY: // that's easy
     766            pParticle->CMNode.ulNodeType = ELEMENTPARTICLE_EMPTY;
     767        break;
     768
     769        case XML_CTYPE_ANY:   // that's easy
     770            pParticle->CMNode.ulNodeType = ELEMENTPARTICLE_ANY;
     771        break;
     772
     773        case XML_CTYPE_NAME:   // that's easy
     774            pParticle->CMNode.ulNodeType = ELEMENTPARTICLE_NAME;
     775            xstrInitCopy(&pParticle->CMNode.strNodeName, pModel->name, 0);
     776            treeInsertNode(ppElementNamesTree,
     777                           &pParticle->CMNode.Tree,
     778                           CompareCMNodeNodes,
     779                           TRUE);       // allow duplicates here
     780        break;
     781
     782        case XML_CTYPE_MIXED:
     783            pParticle->CMNode.ulNodeType = ELEMENTPARTICLE_MIXED;
     784        break;
     785
     786        case XML_CTYPE_CHOICE:
     787            pParticle->CMNode.ulNodeType = ELEMENTPARTICLE_CHOICE;
     788        break;
     789
     790        case XML_CTYPE_SEQ:
     791            pParticle->CMNode.ulNodeType = ELEMENTPARTICLE_SEQ;
     792        break;
     793    }
     794
     795    pParticle->ulRepeater = pModel->quant;
     796
     797    if (pModel->numchildren)
     798    {
     799        // these are the three cases where we have subnodes
     800        // in the XMLCONTENT... go for these and recurse
     801        ULONG ul;
     802        pParticle->pllSubNodes = lstCreate(FALSE);
     803        for (ul = 0;
     804             ul < pModel->numchildren;
     805             ul++)
     806        {
     807            PXMLCONTENT pSubModel = &pModel->children[ul];
     808            PCMELEMENTPARTICLE pSubNew
     809                = (PCMELEMENTPARTICLE)malloc(sizeof(*pSubNew));
     810            if (!pSubNew)
     811                arc = ERROR_NOT_ENOUGH_MEMORY;
     812            else
     813            {
     814                memset(pSubNew, 0, sizeof(*pSubNew));
     815
     816                arc = SetupParticleAndSubs(pSubNew,
     817                                           pSubModel,
     818                                           ppElementNamesTree);
     819
     820                if (!arc)
     821                    // no error: append sub-particle to this particle's
     822                    // children list
     823                    lstAppendItem(pParticle->pllSubNodes,
     824                                  pSubNew);
     825            }
     826
     827            if (arc)
     828                break;
     829        }
     830    }
     831
     832    return (arc);
     833}
     834
     835/*
     836 *@@ xmlCreateElementDecl:
     837 *      creates a new _CMELEMENTDECLNODE for the specified
     838 *      _XMLCONTENT content model (which is the @expat structure).
     839 *      This recurses, if necessary.
     840 *
     841 *@@added V0.9.9 (2001-02-16) [umoeller]
     842 */
     843
     844APIRET xmlCreateElementDecl(const char *pcszName,
     845                            PXMLCONTENT pModel,
     846                            PCMELEMENTDECLNODE *ppNew)
     847{
     848    APIRET arc = NO_ERROR;
     849    PCMELEMENTDECLNODE pNew = (PCMELEMENTDECLNODE)malloc(sizeof(*pNew));
     850    if (!pNew)
     851        arc = ERROR_NOT_ENOUGH_MEMORY;
     852    else
     853    {
     854        memset(pNew, 0, sizeof(CMELEMENTDECLNODE));
     855
     856        // pNew->Particle.CMNode.ulNodeType = ELEMENT_DECLARATION;
     857
     858        xstrcpy(&pNew->Particle.CMNode.strNodeName, pcszName, 0);
     859
     860        treeInit(&pNew->ParticleNamesTree);
     861
     862        // set up the "particle" member and recurse into sub-particles
     863        arc = SetupParticleAndSubs(&pNew->Particle,
     864                                   pModel,
     865                                   &pNew->ParticleNamesTree);
     866
     867        if (!arc)
     868            *ppNew = pNew;
     869        else
     870            free(pNew);
     871    }
     872
     873    return (arc);
     874}
     875
     876/*
     877 *@@ xmlFindElementDecl:
     878 *      returns the _CMELEMENTDECLNODE for the element
     879 *      with the specified name or NULL if there's none.
     880 *
     881 *@@added V0.9.9 (2001-02-16) [umoeller]
     882 */
     883
     884PCMELEMENTDECLNODE xmlFindElementDecl(PXMLDOM pDom,
     885                                      const XSTRING *pstrElementName)
     886{
     887    PCMELEMENTDECLNODE pElementDecl = NULL;
     888
     889    PDOMDOCTYPENODE pDocTypeNode = pDom->pDocTypeNode;
     890    if (    (pDocTypeNode)
     891         && (pstrElementName)
     892         && (pstrElementName->ulLength)
     893       )
     894    {
     895        pElementDecl = treeFindEQData(&pDocTypeNode->ElementDeclsTree,
     896                                      (void*)pstrElementName->psz,
     897                                      CompareCMNodeData);
     898    }
     899
     900    return (pElementDecl);
     901}
     902
     903/*
     904 *@@ xmlFindAttribDeclBase:
     905 *      returns the _CMATTRIBUTEDEDECLBASE for the specified
     906 *      element name, or NULL if none exists.
     907 *
     908 *      To find a specific attribute declaration from both
     909 *      an element and an attribute name, use xmlFindAttribDecl
     910 *      instead.
     911 *
     912 *@@added V0.9.9 (2001-02-16) [umoeller]
     913 */
     914
     915PCMATTRIBUTEDEDECLBASE xmlFindAttribDeclBase(PXMLDOM pDom,
     916                                             const XSTRING *pstrElementName)
     917{
     918    PCMATTRIBUTEDEDECLBASE pAttribDeclBase = NULL;
     919
     920    PDOMDOCTYPENODE pDocTypeNode = pDom->pDocTypeNode;
     921    if (    (pDocTypeNode)
     922         && (pstrElementName)
     923         && (pstrElementName->ulLength)
     924       )
     925    {
     926        pAttribDeclBase = treeFindEQData(&pDocTypeNode->AttribDeclBasesTree,
     927                                         (void*)pstrElementName->psz,
     928                                         CompareCMNodeData);
     929    }
     930
     931    return (pAttribDeclBase);
     932}
     933
     934/*
     935 *@@ xmlFindAttribDecl:
     936 *      returns the _CMATTRIBUTEDEDECL for the specified
     937 *      element and attribute name, or NULL if none exists.
     938 *
     939 *@@added V0.9.9 (2001-02-16) [umoeller]
     940 */
     941
     942PCMATTRIBUTEDECL xmlFindAttribDecl(PXMLDOM pDom,
     943                                   const XSTRING *pstrElementName,
     944                                   const XSTRING *pstrAttribName)
     945{
     946    PCMATTRIBUTEDECL pAttribDecl = NULL;
     947    if (pstrElementName && pstrAttribName)
     948    {
     949        PCMATTRIBUTEDEDECLBASE pAttribDeclBase = xmlFindAttribDeclBase(pDom,
     950                                                                       pstrElementName);
     951        if (pAttribDeclBase)
     952        {
     953            pAttribDecl = treeFindEQData(&pAttribDeclBase->AttribDeclsTree,
     954                                         (void*)pstrAttribName->psz,
     955                                         CompareCMNodeData);
     956        }
     957    }
     958
     959    return (pAttribDecl);
     960}
     961
     962/*
     963 *@@ ValidateElement:
     964 *      validates the specified element against the document's
     965 *      @DTD.
     966 *
     967 *      This sets arcDOM in XMLDOM on errors.
     968 *
     969 *      According to the XML spec, an element is valid if there
     970 *      is a declaration matching the element declaration where the
     971 *      element's name matches the element type, and _one_ of the
     972 *      following holds: ###
     973 *
     974 *      (1) The declaration matches EMPTY and the element has no @content.
     975 *
     976 *      (2) The declaration matches (children) (see @element_declaration)
     977 *          and the sequence of child elements belongs to the language
     978 *          generated by the regular expression in the content model, with
     979 *          optional @white_space between the start-tag and the first child
     980 *          element, between child elements, or between the last
     981 *          child element and the end-tag. Note that a CDATA section
     982 *          is never considered "whitespace", even if it contains
     983 *          white space only.
     984 *
     985 *      (3) The declaration matches (mixed) (see @element_declaration)
     986 *          and the content consists of @content and child elements
     987 *          whose types match names in the content model.
     988 *
     989 *      (4) The declaration matches ANY, and the types of any child
     990 *          elements have been declared. (done)
     991 *
     992 *@@added V0.9.9 (2001-02-16) [umoeller]
     993 */
     994
     995VOID ValidateElement(PXMLDOM pDom,
     996                     PDOMNODE pElement)
     997{
     998    // yes: get the element decl from the tree
     999    PCMELEMENTDECLNODE pElementDecl = xmlFindElementDecl(pDom,
     1000                                                         &pElement->NodeBase.strNodeName);
     1001    if (!pElementDecl)
     1002    {
     1003        xmlSetError(pDom,
     1004                    ERROR_DOM_UNDECLARED_ELEMENT,
     1005                    pElement->NodeBase.strNodeName.psz,
     1006                    TRUE);
     1007    }
     1008    else
     1009    {
     1010        // element has been declared:
     1011        // check if it may appear in this element's parent...
     1012        PDOMNODE pParentElement = pElement->pParentNode;
     1013
     1014        if (!pParentElement)
     1015            pDom->arcDOM = ERROR_DOM_INTEGRITY;
     1016        else switch (pParentElement->NodeBase.ulNodeType)
     1017        {
     1018            case DOMNODE_DOCUMENT:
     1019            {
     1020                // if this is the root element, compare its name
     1021                // to the DOCTYPE name
     1022                if (pParentElement != (PDOMNODE)pDom->pDocumentNode)
     1023                    xmlSetError(pDom,
     1024                                ERROR_DOM_INVALID_ROOT_ELEMENT,
     1025                                pElement->NodeBase.strNodeName.psz,
     1026                                TRUE);
     1027                else if (strcmp(pDom->pDocumentNode->DomNode.NodeBase.strNodeName.psz,
     1028                                pElement->NodeBase.strNodeName.psz))
     1029                    // no match:
     1030                    xmlSetError(pDom,
     1031                                ERROR_DOM_ROOT_ELEMENT_MISNAMED,
     1032                                pElement->NodeBase.strNodeName.psz,
     1033                                TRUE);
     1034            break; }
     1035
     1036            case DOMNODE_ELEMENT:
     1037            {
     1038                // parent of element is another element:
     1039                // check the parent in the DTD and find out if
     1040                // this element may appear in the parent element
     1041                PCMELEMENTDECLNODE pParentElementDecl
     1042                        = xmlFindElementDecl(pDom,
     1043                                             &pParentElement->NodeBase.strNodeName);
     1044                if (!pParentElementDecl)
     1045                    pDom->arcDOM = ERROR_DOM_INTEGRITY;
     1046                else
     1047                {
     1048                    // now check the element names tree of the parent element decl
     1049                    // for whether this element is allowed as a sub-element at all
     1050                    PCMELEMENTPARTICLE pParticle
     1051                        = treeFindEQData(&pParentElementDecl->ParticleNamesTree,
     1052                                         (void*)pElement->NodeBase.strNodeName.psz,
     1053                                         CompareCMNodeData);
     1054                    if (!pParticle)
     1055                        // not found: then this element is not allowed within this
     1056                        // parent
     1057                        xmlSetError(pDom,
     1058                                    ERROR_DOM_INVALID_SUBELEMENT,
     1059                                    pElement->NodeBase.strNodeName.psz,
     1060                                    TRUE);
     1061                }
     1062            break; }
     1063        }
     1064    }
     1065}
     1066
     1067/*
     1068 *@@ ValidateAttribute:
     1069 *      validates the specified element against the document's
     1070 *      @DTD.
     1071 *
     1072 *      This sets arcDOM in XMLDOM on errors.
     1073 *
     1074 *@@added V0.9.9 (2001-02-16) [umoeller]
     1075 */
     1076
     1077VOID ValidateAttribute(PXMLDOM pDom,
     1078                       PDOMNODE pAttrib)
     1079{
     1080    PDOMNODE pElement = pAttrib->pParentNode;
     1081
     1082    PCMATTRIBUTEDECL pAttribDecl = xmlFindAttribDecl(pDom,
     1083                                                     &pElement->NodeBase.strNodeName,
     1084                                                     &pAttrib->NodeBase.strNodeName);
     1085    if (!pAttribDecl)
     1086        xmlSetError(pDom,
     1087                    ERROR_DOM_UNDECLARED_ATTRIBUTE,
     1088                    pAttrib->NodeBase.strNodeName.psz,
     1089                    TRUE);
     1090}
     1091
     1092/* ******************************************************************
     1093 *
    2661094 *   Expat handlers
    2671095 *
     
    2701098/*
    2711099 *@@ StartElementHandler:
    272  *      expat handler called when a new element is
     1100 *      @expat handler called when a new element is
    2731101 *      found.
    2741102 *
     
    2791107 */
    2801108
    281 void EXPATENTRY StartElementHandler(void *data,           // in: our PXMLFILE really
     1109void EXPATENTRY StartElementHandler(void *pUserData,      // in: our PXMLDOM really
    2821110                                    const char *pcszElement,
    2831111                                    const char **papcszAttribs)
    2841112{
    285     PXMLDOM     pDom = (PXMLDOM)data;
    286 
    287     ULONG       i;
    288 
    289     PDOMNODE    pParent = NULL,
    290                 pNew = NULL;
    291 
    292     PLISTNODE   pParentNode = lstPop(&pDom->llStack);
    293 
    294     if (pParentNode)
    295     {
    296         // non-root level:
    297         pParent = (PDOMNODE)pParentNode->pItemData;
    298 
    299         pNew = xmlCreateNode(pParent,
    300                              DOMNODE_ELEMENT);
    301 
    302         if (pNew)
    303             xstrcpy(&pNew->strNodeName, pcszElement, 0);
    304 
    305         // push this on the stack so we can add child elements
    306         lstPush(&pDom->llStack, pNew);
    307 
    308         // now for the attribs
    309         for (i = 0;
    310              papcszAttribs[i];
    311              i += 2)
     1113    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1114
     1115    // continue parsing only if we had no errors so far
     1116    if (!pDom->arcDOM)
     1117    {
     1118        ULONG       i;
     1119
     1120        PDOMNODE    pParent = NULL,
     1121                    pNew = NULL;
     1122
     1123        PLISTNODE   pParentNode = lstPop(&pDom->llStack);
     1124
     1125        if (!pParentNode)
     1126            pDom->arcDOM = ERROR_DOM_NO_DOCUMENT;
     1127        else
    3121128        {
    313             PDOMNODE    pAttrNode = xmlCreateNode(pNew,     // element
    314                                                   DOMNODE_ATTRIBUTE);
    315             if (pAttrNode)
     1129            // we have at least one node:
     1130            pParent = (PDOMNODE)pParentNode->pItemData;
     1131
     1132            pDom->arcDOM = xmlCreateElementNode(pParent,
     1133                                                pcszElement,
     1134                                                &pNew);
     1135
     1136            if (!pDom->arcDOM)
    3161137            {
    317                 xstrcpy(&pAttrNode->strNodeName, papcszAttribs[i], 0);
    318                 xstrcpy(&pAttrNode->strNodeValue, papcszAttribs[i + 1], 0);
     1138                // shall we validate?
     1139                if (pDom->pDocTypeNode)
     1140                {
     1141                    // yes:
     1142                    ValidateElement(pDom,
     1143                                    pNew);
     1144                }
     1145
     1146                if (!pDom->arcDOM)
     1147                {
     1148                    // OK, node is valid:
     1149                    // push this on the stack so we can add child elements
     1150                    lstPush(&pDom->llStack, pNew);
     1151
     1152                    // now for the attribs
     1153                    for (i = 0;
     1154                         (papcszAttribs[i]) && (!pDom->arcDOM);
     1155                         i += 2)
     1156                    {
     1157                        PDOMNODE pAttrib;
     1158
     1159                        pDom->arcDOM = xmlCreateAttributeNode(pNew,                    // element,
     1160                                                              papcszAttribs[i],        // attr name
     1161                                                              papcszAttribs[i + 1],    // attr value
     1162                                                              &pAttrib);
     1163
     1164                        // shall we validate?
     1165                        if (pDom->pDocTypeNode)
     1166                        {
     1167                            ValidateAttribute(pDom,
     1168                                              pAttrib);
     1169                        }
     1170                    }
     1171                }
    3191172            }
    3201173        }
    321     }
    322 
    323     pDom->pLastWasTextNode = NULL;
     1174
     1175        pDom->pLastWasTextNode = NULL;
     1176    }
    3241177}
    3251178
    3261179/*
    3271180 *@@ EndElementHandler:
    328  *
    329  */
    330 
    331 void EXPATENTRY EndElementHandler(void *data,             // in: our PXMLFILE really
     1181 *      @expat handler for when parsing an element is done.
     1182 *      We pop the element off of our stack then.
     1183 */
     1184
     1185void EXPATENTRY EndElementHandler(void *pUserData,      // in: our PXMLDOM really
    3321186                                  const XML_Char *name)
    3331187{
    334     PXMLDOM     pDom = (PXMLDOM)data;
    335     PLISTNODE   pNode = lstPop(&pDom->llStack);
    336     if (pNode)
    337         lstRemoveNode(&pDom->llStack, pNode);
    338 
    339     pDom->pLastWasTextNode = NULL;
     1188    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1189    // continue parsing only if we had no errors so far
     1190    if (!pDom->arcDOM)
     1191    {
     1192        PLISTNODE   pNode = lstPop(&pDom->llStack);
     1193        if (pNode)
     1194            lstRemoveNode(&pDom->llStack, pNode);
     1195
     1196        pDom->pLastWasTextNode = NULL;
     1197    }
    3401198}
    3411199
    3421200/*
    3431201 *@@ CharacterDataHandler:
    344  *
    345  */
    346 
    347 void EXPATENTRY CharacterDataHandler(void *userData,      // in: our PXMLFILE really
     1202 *      @expat handler for character data (@content).
     1203 *
     1204 *      Note: expat passes chunks of content without zero-terminating
     1205 *      them. We must concatenate the chunks to a full text node.
     1206 */
     1207
     1208void EXPATENTRY CharacterDataHandler(void *pUserData,      // in: our PXMLDOM really
    3481209                                     const XML_Char *s,
    3491210                                     int len)
    3501211{
    351     PXMLDOM     pDom = (PXMLDOM)userData;
    352 
    353     ULONG       i;
    354 
    355     if (len)
    356     {
    357         if (pDom->pLastWasTextNode)
     1212    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1213
     1214    // continue parsing only if we had no errors so far
     1215    if (!pDom->arcDOM)
     1216    {
     1217        ULONG       i;
     1218
     1219        if (len)
    3581220        {
    359             // we had a text node, and no elements or other
    360             // stuff in between:
    361             xstrcat(&pDom->pLastWasTextNode->strNodeValue,
    362                     s,
    363                     len);
     1221            if (pDom->pLastWasTextNode)
     1222            {
     1223                // we had a text node, and no elements or other
     1224                // stuff in between:
     1225                xstrcat(pDom->pLastWasTextNode->pstrNodeValue,
     1226                        s,
     1227                        len);
     1228            }
     1229            else
     1230            {
     1231                // we need a new text node:
     1232                PDOMNODE pNew,
     1233                         pParent;
     1234                // non-root level:
     1235                PLISTNODE pParentNode = lstPop(&pDom->llStack);
     1236                pParent = (PDOMNODE)pParentNode->pItemData;
     1237
     1238                pDom->arcDOM = xmlCreateTextNode(pParent,
     1239                                                 s,
     1240                                                 len,
     1241                                                 &pDom->pLastWasTextNode);
     1242            }
    3641243        }
     1244    }
     1245}
     1246
     1247/*
     1248 *@@ CommentHandler:
     1249 *      @expat handler for @comments.
     1250 *
     1251 *      Note: This is only set if DF_PARSECOMMENTS is
     1252 *      flagged with xmlCreateDOM.
     1253 *
     1254 *@@added V0.9.9 (2001-02-14) [umoeller]
     1255 */
     1256
     1257void EXPATENTRY CommentHandler(void *pUserData,      // in: our PXMLDOM really
     1258                               const XML_Char *data)
     1259{
     1260    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1261
     1262    // continue parsing only if we had no errors so far
     1263    if (!pDom->arcDOM)
     1264    {
     1265        PLISTNODE   pParentNode = lstPop(&pDom->llStack);
     1266
     1267        if (pParentNode)
     1268        {
     1269            // non-root level:
     1270            PDOMNODE pParent = (PDOMNODE)pParentNode->pItemData;
     1271            PDOMNODE pComment;
     1272
     1273            pDom->arcDOM = xmlCreateCommentNode(pParent,
     1274                                                data,
     1275                                                &pComment);
     1276        }
     1277    }
     1278}
     1279
     1280/*
     1281 *@@ StartDoctypeDeclHandler:
     1282 *      @expat handler that is called at the start of a DOCTYPE
     1283 *      declaration, before any external or internal subset is
     1284 *      parsed.
     1285 *
     1286 *      Both pcszSysid and pcszPubid may be NULL. "fHasInternalSubset"
     1287 *      will be non-zero if the DOCTYPE declaration has an internal subset.
     1288 *
     1289 *@@added V0.9.9 (2001-02-14) [umoeller]
     1290 */
     1291
     1292void EXPATENTRY StartDoctypeDeclHandler(void *pUserData,
     1293                                        const XML_Char *pcszDoctypeName,
     1294                                        const XML_Char *pcszSysid,
     1295                                        const XML_Char *pcszPubid,
     1296                                        int fHasInternalSubset)
     1297{
     1298    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1299
     1300    // continue parsing only if we had no errors so far
     1301    if (!pDom->arcDOM)
     1302    {
     1303        // get the document node
     1304        PDOMDOCUMENTNODE pDocumentNode = pDom->pDocumentNode;
     1305        if (!pDocumentNode)
     1306            pDom->arcDOM = ERROR_DOM_NO_DOCUMENT;
    3651307        else
    3661308        {
    367             // we need a new text node:
    368             PDOMNODE pNew,
    369                      pParent;
    370             // non-root level:
    371             PLISTNODE pParentNode = lstPop(&pDom->llStack);
    372             pParent = (PDOMNODE)pParentNode->pItemData;
    373 
    374             pNew = xmlCreateNode(pParent,
    375                                  DOMNODE_TEXT);
    376             if (pNew)
     1309            pDom->arcDOM = xmlCreateDocumentTypeNode(pDocumentNode,
     1310                                                     pcszDoctypeName,
     1311                                                     pcszSysid,
     1312                                                     pcszPubid,
     1313                                                     fHasInternalSubset,
     1314                                                     &pDom->pDocTypeNode);
     1315
     1316            // push this on the stack so we can add child elements
     1317            lstPush(&pDom->llStack, pDom->pDocTypeNode);
     1318        }
     1319    }
     1320}
     1321
     1322/*
     1323 *@@ EndDoctypeDeclHandler:
     1324 *      @expat handler that is called at the end of a DOCTYPE
     1325 *      declaration, after parsing any external subset.
     1326 *
     1327 *@@added V0.9.9 (2001-02-14) [umoeller]
     1328 */
     1329
     1330void EXPATENTRY EndDoctypeDeclHandler(void *pUserData)      // in: our PXMLDOM really
     1331{
     1332    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1333
     1334    PLISTNODE pListNode = lstPop(&pDom->llStack);
     1335    if (!pListNode)
     1336        pDom->arcDOM = ERROR_DOM_DOCTYPE_STRUCTURE;
     1337    else
     1338    {
     1339        PDOMNODE pDomNode = (PDOMNODE)pListNode->pItemData;
     1340        if (pDomNode->NodeBase.ulNodeType != DOMNODE_DOCUMENT_TYPE)
     1341            pDom->arcDOM = ERROR_DOM_DOCTYPE_STRUCTURE;
     1342
     1343        lstRemoveNode(&pDom->llStack, pListNode);
     1344    }
     1345
     1346    // continue parsing only if we had no errors so far
     1347    if (!pDom->arcDOM)
     1348    {
     1349
     1350    }
     1351}
     1352
     1353/*
     1354 *@@ NotationDeclHandler:
     1355 *      @expat handler for @notation_declarations.
     1356 *
     1357 *@@added V0.9.9 (2001-02-14) [umoeller]
     1358 */
     1359
     1360void EXPATENTRY NotationDeclHandler(void *pUserData,      // in: our PXMLDOM really
     1361                                    const XML_Char *pcszNotationName,
     1362                                    const XML_Char *pcszBase,
     1363                                    const XML_Char *pcszSystemId,
     1364                                    const XML_Char *pcszPublicId)
     1365{
     1366    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1367
     1368    // continue parsing only if we had no errors so far
     1369    if (!pDom->arcDOM)
     1370    {
     1371    }
     1372}
     1373
     1374/*
     1375 *@@ ExternalEntityRefHandler:
     1376 *      @expat handler for references to @external_entities.
     1377 *
     1378 *      This handler is also called for processing an external DTD
     1379 *      subset if parameter entity parsing is in effect.
     1380 *      (See XML_SetParamEntityParsing.)
     1381 *
     1382 *      The pcszContext argument specifies the parsing context in the
     1383 *      format expected by the context argument to
     1384 *      XML_ExternalEntityParserCreate; pcszContext is valid only until
     1385 *      the handler returns, so if the referenced entity is to be
     1386 *      parsed later, it must be copied.
     1387 *
     1388 *      The pcszBase parameter is the base to use for relative system
     1389 *      identifiers. It is set by XML_SetBase and may be null.
     1390 *
     1391 *      The pcszPublicId parameter is the public id given in the entity
     1392 *      declaration and may be null.
     1393 *
     1394 *      The pcszSystemId is the system identifier specified in the
     1395 *      entity declaration and is never null.
     1396 *
     1397 *      There are a couple of ways in which this handler differs
     1398 *      from others. First, this handler returns an integer. A
     1399 *      non-zero value should be returned for successful handling
     1400 *      of the external entity reference. Returning a zero indicates
     1401 *      failure, and causes the calling parser to return an
     1402 *      ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING error.
     1403 *
     1404 *      Second, instead of having pUserData as its first argument,
     1405 *      it receives the parser that encountered the entity reference.
     1406 *      This, along with the context parameter, may be used as
     1407 *      arguments to a call to XML_ExternalEntityParserCreate.
     1408 *      Using the returned parser, the body of the external entity
     1409 *      can be recursively parsed.
     1410 *
     1411 *      Since this handler may be called recursively, it should not
     1412 *      be saving information into global or static variables.
     1413 *
     1414 *      Your handler isn't actually responsible for parsing the entity,
     1415 *      but it is responsible for creating a subsidiary parser with
     1416 *      XML_ExternalEntityParserCreate that will do the job. That returns
     1417 *      an instance of XML_Parser that has handlers and other data
     1418 *      structures initialized from the parent parser. You may then use
     1419 *      XML_Parse or XML_ParseBuffer calls against that parser. Since
     1420 *      external entities may refer to other external entities, your
     1421 *      handler should be prepared to be called recursively.
     1422 *
     1423 *@@added V0.9.9 (2001-02-14) [umoeller]
     1424 */
     1425
     1426int EXPATENTRY ExternalEntityRefHandler(XML_Parser parser,
     1427                                        const XML_Char *pcszContext,
     1428                                        const XML_Char *pcszBase,
     1429                                        const XML_Char *pcszSystemId,
     1430                                        const XML_Char *pcszPublicId)
     1431{
     1432    int i = 1;
     1433
     1434    /* PXMLDOM     pDom = (PXMLDOM)pUserData;
     1435
     1436    // continue parsing only if we had no errors so far
     1437    if (!pDom->arcDOM)
     1438    {
     1439    } */
     1440
     1441    return (i);
     1442}
     1443
     1444/*
     1445 *@@ ElementDeclHandler:
     1446 *      @expat handler for element declarations in a DTD. The
     1447 *      handler gets called with the name of the element in
     1448 *      the declaration and a pointer to a structure that contains
     1449 *      the element model.
     1450 *
     1451 *      It is the application's responsibility to free this data
     1452 *      structure. ###
     1453 *
     1454 *      The XML spec defines that no element may be declared more
     1455 *      than once.
     1456 *
     1457 *@@added V0.9.9 (2001-02-14) [umoeller]
     1458 */
     1459
     1460void EXPATENTRY ElementDeclHandler(void *pUserData,      // in: our PXMLDOM really
     1461                                   const XML_Char *pcszName,
     1462                                   XMLCONTENT *pModel)
     1463{
     1464    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1465
     1466    // continue parsing only if we had no errors so far
     1467    if (!pDom->arcDOM)
     1468    {
     1469        // pop the last DOMNODE off the stack and check if it's a DOCTYPE
     1470        PLISTNODE pListNode = lstPop(&pDom->llStack);
     1471        if (!pListNode)
     1472            pDom->arcDOM = ERROR_DOM_DOCTYPE_STRUCTURE;
     1473        else
     1474        {
     1475            PDOMNODE pDomNode = (PDOMNODE)pListNode->pItemData;
     1476            if (pDomNode->NodeBase.ulNodeType != DOMNODE_DOCUMENT_TYPE)
     1477                pDom->arcDOM = ERROR_DOM_DOCTYPE_STRUCTURE;
     1478            else
    3771479            {
    378                 PSZ pszNodeValue = (PSZ)malloc(len + 1);
    379                 memcpy(pszNodeValue, s, len);
    380                 pszNodeValue[len] = '\0';
    381                 xstrInitSet(&pNew->strNodeValue, pszNodeValue);
     1480                // OK, we're in a DOCTYPE node:
     1481                PDOMDOCTYPENODE pDocType = (PDOMDOCTYPENODE)pDomNode;
     1482
     1483                // create an element declaration and push it unto the
     1484                // declarations tree
     1485                PCMELEMENTDECLNODE pNew = NULL;
     1486                pDom->arcDOM = xmlCreateElementDecl(pcszName,
     1487                                                    pModel,
     1488                                                    &pNew);
     1489                                        // this recurses!!
     1490
     1491                if (pDom->arcDOM == NO_ERROR)
     1492                {
     1493                    // add this to the doctype's declarations tree
     1494                    if (treeInsertNode(&pDocType->ElementDeclsTree,
     1495                                       (TREE*)pNew,
     1496                                       CompareCMNodeNodes,
     1497                                       FALSE)
     1498                            == TREE_DUPLICATE)
     1499                        // element already declared:
     1500                        // according to the XML specs, this is a validity
     1501                        // constraint, so we report a validation error
     1502                        xmlSetError(pDom,
     1503                                    ERROR_DOM_DUPLICATE_ELEMENT_DECL,
     1504                                    pNew->Particle.CMNode.strNodeName.psz,
     1505                                    TRUE);
     1506                }
    3821507            }
    383 
    384             pDom->pLastWasTextNode = pNew;
    3851508        }
    3861509    }
    3871510}
    3881511
     1512/*
     1513 *@@ AddEnum:
     1514 *
     1515 *@@added V0.9.9 (2001-02-16) [umoeller]
     1516 */
     1517
     1518VOID AddEnum(PCMATTRIBUTEDECL pNew,
     1519             const char *p,
     1520             const char *pNext)
     1521{
     1522    PSZ pszType = strhSubstr(p, pNext);
     1523    PNODEBASE pCMNode = (PNODEBASE)malloc(sizeof(*pCMNode));
     1524    memset(pCMNode, 0, sizeof(*pCMNode));
     1525    pCMNode->ulNodeType = ATTRIBUTE_DECLARATION_ENUM;
     1526    xstrInitSet(&pCMNode->strNodeName, pszType);
     1527
     1528    treeInsertNode(&pNew->ValuesTree,
     1529                   (TREE*)pCMNode,
     1530                   CompareCMNodeNodes,
     1531                   FALSE);
     1532}
     1533
     1534/*
     1535 *@@ AttlistDeclHandler:
     1536 *      @expat handler for attlist declarations in the DTD.
     1537 *
     1538 *      This handler is called for each attribute. So a single attlist
     1539 *      declaration with multiple attributes declared will generate
     1540 *      multiple calls to this handler.
     1541 *
     1542 *      --  pcszElementName is the name of the  element for which the
     1543 *          attribute is being declared.
     1544 *
     1545 *      --  pcszAttribName has the attribute name being declared.
     1546 *
     1547 *      --  pcszAttribType is the attribute type.
     1548 *          It is the string representing the type in the declaration
     1549 *          with whitespace removed.
     1550 *
     1551 *      --  pcszDefault holds the default value. It will be
     1552 *          NULL in the case of "#IMPLIED" or "#REQUIRED" attributes.
     1553 *          You can distinguish these two cases by checking the
     1554 *          fIsRequired parameter, which will be true in the case of
     1555 *          "#REQUIRED" attributes. Attributes which are "#FIXED"
     1556 *          will have also have a TRUE fIsRequired, but they will have
     1557 *          the non-NULL fixed value in the pcszDefault parameter.
     1558 *
     1559 *@@added V0.9.9 (2001-02-14) [umoeller]
     1560 */
     1561
     1562void EXPATENTRY AttlistDeclHandler(void *pUserData,      // in: our PXMLDOM really
     1563                                   const XML_Char *pcszElementName,
     1564                                   const XML_Char *pcszAttribName,
     1565                                   const XML_Char *pcszAttribType,
     1566                                   const XML_Char *pcszDefault,
     1567                                   int fIsRequired)
     1568{
     1569    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1570
     1571    // continue parsing only if we had no errors so far
     1572    if (!pDom->arcDOM)
     1573    {
     1574        // pop the last DOMNODE off the stack and check if it's a DOCTYPE
     1575        PLISTNODE pListNode = lstPop(&pDom->llStack);
     1576        if (!pListNode)
     1577            pDom->arcDOM = ERROR_DOM_DOCTYPE_STRUCTURE;
     1578        else
     1579        {
     1580            PDOMNODE pDomNode = (PDOMNODE)pListNode->pItemData;
     1581            if (pDomNode->NodeBase.ulNodeType != DOMNODE_DOCUMENT_TYPE)
     1582                pDom->arcDOM = ERROR_DOM_DOCTYPE_STRUCTURE;
     1583            else
     1584            {
     1585                // OK, we're in a DOCTYPE node:
     1586                PDOMDOCTYPENODE pDocType = (PDOMDOCTYPENODE)pDomNode;
     1587                PCMATTRIBUTEDEDECLBASE    pThis = NULL,
     1588                                        pCache = pDom->pAttListDeclCache;
     1589
     1590                // check if this is for the same attlist as the previous
     1591                // call (we cache the pointer for speed)
     1592                if (    (pCache)
     1593                     && (!strhcmp(pCache->CMNode.strNodeName.psz,
     1594                                  pcszElementName))
     1595                   )
     1596                    // this attdecl is for the same element:
     1597                    // use that (we won't have to search the tree)
     1598                    pThis = pDom->pAttListDeclCache;
     1599
     1600                if (!pThis)
     1601                {
     1602                    // cache didn't match: look up attributes tree then
     1603                    pThis = treeFindEQData(&pDocType->AttribDeclBasesTree,
     1604                                           (void*)pcszElementName,
     1605                                           CompareCMNodeData);
     1606
     1607                    if (!pThis)
     1608                    {
     1609                        // still not found:
     1610                        // we need a new node then
     1611                        pThis = (PCMATTRIBUTEDEDECLBASE)malloc(sizeof(*pThis));
     1612                        if (!pThis)
     1613                            pDom->arcDOM = ERROR_NOT_ENOUGH_MEMORY;
     1614                        else
     1615                        {
     1616                            pThis->CMNode.ulNodeType = ATTRIBUTE_DECLARATION_BASE;
     1617                            xstrInitCopy(&pThis->CMNode.strNodeName, pcszElementName, 0);
     1618
     1619                            // initialize the subtree
     1620                            treeInit(&pThis->AttribDeclsTree);
     1621
     1622                            treeInsertNode(&pDocType->AttribDeclBasesTree,
     1623                                           (TREE*)pThis,
     1624                                           CompareCMNodeNodes,
     1625                                           FALSE);
     1626                        }
     1627                    }
     1628
     1629                    pDom->pAttListDeclCache = pThis;
     1630                }
     1631
     1632                if (pThis)
     1633                {
     1634                    // pThis now has either an existing or a new CMATTRIBUTEDEDECLBASE;
     1635                    // add a new attribute def (CMATTRIBUTEDEDECL) to that
     1636                    PCMATTRIBUTEDECL  pNew = (PCMATTRIBUTEDECL)malloc(sizeof(*pNew));
     1637                    if (!pNew)
     1638                        pDom->arcDOM = ERROR_NOT_ENOUGH_MEMORY;
     1639                    else
     1640                    {
     1641                        memset(pNew, 0, sizeof(*pNew));
     1642                        pNew->CMNode.ulNodeType = ATTRIBUTE_DECLARATION;
     1643
     1644                        xstrInitCopy(&pNew->CMNode.strNodeName,
     1645                                     pcszAttribName,
     1646                                     0);
     1647
     1648                        // fill the other fields
     1649                        /* xstrInitCopy(&pNew->strType,
     1650                                     pcszAttribType,
     1651                                     0); */
     1652
     1653                        treeInit(&pNew->ValuesTree);
     1654
     1655                        // check the type... expat is too lazy to parse this for
     1656                        // us, so we must check manually. Expat only normalizes
     1657                        // the "type" string to kick out whitespace, so we get:
     1658                        // (TYPE1|TYPE2|TYPE3)
     1659                        if (*pcszAttribType == '(')
     1660                        {
     1661                            // enumeration:
     1662                            const char *p = pcszAttribType + 1,
     1663                                       *pNext;
     1664                            while (pNext = strchr(p, '|'))
     1665                            {
     1666                                AddEnum(pNew, p, pNext);
     1667                                p = pNext + 1;
     1668                            }
     1669
     1670                            pNext = strchr(p, ')');
     1671                            AddEnum(pNew, p, pNext);
     1672
     1673                            pNew->ulAttrType = CMAT_ENUM;
     1674                        }
     1675                        else if (!strcmp(pcszAttribType, "CDATA"))
     1676                            pNew->ulAttrType = CMAT_CDATA;
     1677                        else if (!strcmp(pcszAttribType, "ID"))
     1678                            pNew->ulAttrType = CMAT_ID;
     1679                        else if (!strcmp(pcszAttribType, "IDREF"))
     1680                            pNew->ulAttrType = CMAT_IDREF;
     1681                        else if (!strcmp(pcszAttribType, "IDREFS"))
     1682                            pNew->ulAttrType = CMAT_IDREFS;
     1683                        else if (!strcmp(pcszAttribType, "ENTITY"))
     1684                            pNew->ulAttrType = CMAT_ENTITY;
     1685                        else if (!strcmp(pcszAttribType, "ENTITIES"))
     1686                            pNew->ulAttrType = CMAT_ENTITIES;
     1687                        else if (!strcmp(pcszAttribType, "NMTOKEN"))
     1688                            pNew->ulAttrType = CMAT_NMTOKEN;
     1689                        else if (!strcmp(pcszAttribType, "NMTOKENS"))
     1690                            pNew->ulAttrType = CMAT_NMTOKENS;
     1691
     1692                        if (pcszDefault)
     1693                        {
     1694                            // fixed or default:
     1695                            if (fIsRequired)
     1696                                // fixed:
     1697                                pNew->ulConstraint = CMAT_FIXED_VALUE;
     1698                            else
     1699                                pNew->ulConstraint = CMAT_DEFAULT_VALUE;
     1700
     1701                            pNew->pstrDefaultValue = xstrCreate(0);
     1702                            xstrcpy(pNew->pstrDefaultValue, pcszDefault, 0);
     1703                        }
     1704                        else
     1705                            // implied or required:
     1706                            if (fIsRequired)
     1707                                pNew->ulConstraint = CMAT_REQUIRED;
     1708                            else
     1709                                pNew->ulConstraint = CMAT_IMPLIED;
     1710
     1711                        if (treeInsertNode(&pThis->AttribDeclsTree,
     1712                                           (TREE*)pNew,
     1713                                           CompareCMNodeNodes,
     1714                                           FALSE)
     1715                                == TREE_DUPLICATE)
     1716                            xmlSetError(pDom,
     1717                                        ERROR_DOM_DUPLICATE_ATTRIBUTE_DECL,
     1718                                        pcszAttribName,
     1719                                        TRUE);
     1720                    }
     1721                }
     1722            }
     1723        }
     1724    }
     1725}
     1726
     1727/*
     1728 *@@ EntityDeclHandler:
     1729 *      @expat handler that will be called for all entity declarations.
     1730 *
     1731 *      The fIsParameterEntity argument will be non-zero in the case
     1732 *      of parameter entities and zero otherwise.
     1733 *
     1734 *      For internal entities (<!ENTITY foo "bar">), pcszValue will be
     1735 *      non-NULL and pcszSystemId, pcszPublicId, and pcszNotationName
     1736 *      will all be NULL. The value string is not NULL terminated; the
     1737 *      length is provided in the iValueLength parameter. Do not use
     1738 *      iValueLength to test for internal entities, since it is legal
     1739 *      to have zero-length values. Instead check for whether or not
     1740 *      pcszValue is NULL.
     1741 *
     1742 *      The pcszNotationName argument will have a non-NULL value only
     1743 *      for unparsed entity declarations.
     1744 *
     1745 *@@added V0.9.9 (2001-02-14) [umoeller]
     1746 */
     1747
     1748void EXPATENTRY EntityDeclHandler(void *pUserData,      // in: our PXMLDOM really
     1749                                  const XML_Char *pcszEntityName,
     1750                                  int fIsParameterEntity,
     1751                                  const XML_Char *pcszValue,
     1752                                  int iValueLength,
     1753                                  const XML_Char *pcszBase,
     1754                                  const XML_Char *pcszSystemId,
     1755                                  const XML_Char *pcszPublicId,
     1756                                  const XML_Char *pcszNotationName)
     1757{
     1758    PXMLDOM     pDom = (PXMLDOM)pUserData;
     1759
     1760    // continue parsing only if we had no errors so far
     1761    if (!pDom->arcDOM)
     1762    {
     1763    }
     1764}
     1765
    3891766/* ******************************************************************
    3901767 *
     
    3951772/*
    3961773 *@@ xmlCreateDOM:
     1774 *      creates an XMLDOM instance, which can be used for parsing
     1775 *      an XML document and building a @DOM tree from it at the
     1776 *      same time.
     1777 *
     1778 *      Pass the XMLDOM returned here to xmlParse afterwards.
     1779 *
     1780 *      ulFlags is any combination of the following:
     1781 *
     1782 *      --  DF_PARSECOMMENTS: XML @comments are to be returned in
     1783 *          the DOM tree. Otherwise they are silently ignored.
     1784 *
     1785 *      --  DF_PARSEDTD: add the @DTD of the document into the DOM tree
     1786 *          as well and validate the document.
    3971787 *
    3981788 *      Usage:
     
    4131803 *         call xmlFreeDOM, which will free all memory.
    4141804 *
    415  *@@added V0.9.9 (2000-02-14) [umoeller]
     1805 *@@added V0.9.9 (2001-02-14) [umoeller]
    4161806 */
    4171807
     
    4211811    APIRET  arc = NO_ERROR;
    4221812
    423     PXMLDOM pDom = (PXMLDOM)malloc(sizeof(XMLDOM));
     1813    PXMLDOM pDom = (PXMLDOM)malloc(sizeof(*pDom));
    4241814    if (!pDom)
    4251815        arc = ERROR_NOT_ENOUGH_MEMORY;
    4261816    else
    4271817    {
     1818        PDOMNODE pDocument = NULL;
     1819
    4281820        memset(pDom, 0, sizeof(XMLDOM));
    4291821
     
    4321824
    4331825        // create the document node
    434         pDom->pDocumentNode = xmlCreateNode(NULL, // no parent
    435                                             DOMNODE_DOCUMENT);
    436 
    437         if (!pDom->pDocumentNode)
    438             arc = ERROR_NOT_ENOUGH_MEMORY;
    439         else
     1826        arc = xmlCreateNode(NULL, // no parent
     1827                            DOMNODE_DOCUMENT,
     1828                            &pDocument);
     1829
     1830        if (arc == NO_ERROR)
    4401831        {
     1832            // store the document in the DOM
     1833            pDom->pDocumentNode = (PDOMDOCUMENTNODE)pDocument;
     1834
    4411835            // push the document on the stack so the handlers
    4421836            // will append to that
     
    4571851                                            CharacterDataHandler);
    4581852
     1853                // XML_SetProcessingInstructionHandler(XML_Parser parser,
     1854                //                          XML_ProcessingInstructionHandler handler);
     1855
     1856
     1857                if (flParserFlags & DF_PARSECOMMENTS)
     1858                    XML_SetCommentHandler(pDom->pParser,
     1859                                          CommentHandler);
     1860
     1861                if (flParserFlags & DF_PARSEDTD)
     1862                {
     1863                    XML_SetDoctypeDeclHandler(pDom->pParser,
     1864                                              StartDoctypeDeclHandler,
     1865                                              EndDoctypeDeclHandler);
     1866
     1867                    XML_SetNotationDeclHandler(pDom->pParser,
     1868                                               NotationDeclHandler);
     1869
     1870                    XML_SetExternalEntityRefHandler(pDom->pParser,
     1871                                                    ExternalEntityRefHandler);
     1872
     1873                    XML_SetElementDeclHandler(pDom->pParser,
     1874                                              ElementDeclHandler);
     1875
     1876                    XML_SetAttlistDeclHandler(pDom->pParser,
     1877                                              AttlistDeclHandler);
     1878
     1879                    XML_SetEntityDeclHandler(pDom->pParser,
     1880                                             EntityDeclHandler);
     1881
     1882                    XML_SetParamEntityParsing(pDom->pParser,
     1883                                              XML_PARAM_ENTITY_PARSING_ALWAYS);
     1884                }
     1885
     1886                // XML_SetXmlDeclHandler ... do we care for this? I guess not
     1887
    4591888                // pass the XMLDOM as user data to the handlers
    4601889                XML_SetUserData(pDom->pParser,
    4611890                                pDom);
    462 
    4631891            }
    4641892        }
     
    4771905 *      parses another piece of XML data.
    4781906 *
    479  *      If (fIsLast == TRUE), the internal expat parser
     1907 *      If (fIsLast == TRUE), the internal @expat parser
    4801908 *      will be freed, but not the DOM itself.
    4811909 *
     
    4851913 *
    4861914 *      This returns NO_ERROR if the chunk was successfully
    487  *      parsed. Otherwise ERROR_DOM_PARSING is returned,
    488  *      and you will find error information in the XMLDOM
    489  *      fields.
    490  *
    491  *@@added V0.9.9 (2000-02-14) [umoeller]
     1915 *      parsed. Otherwise one of the following errors is
     1916 *      returned:
     1917 *
     1918 *      -- ERROR_INVALID_PARAMETER
     1919 *
     1920 *      -- ERROR_DOM_PARSING: an @expat parsing error occured.
     1921 *         This might also be memory problems.
     1922 *         With this error code, you will find specific
     1923 *         error information in the XMLDOM fields.
     1924 *
     1925 *      -- ERROR_DOM_PARSING: the document is not @valid.
     1926 *         This can only happen if @DTD parsing was enabled
     1927 *         with xmlCreateDOM.
     1928 *         With this error code, you will find specific
     1929 *         error information in the XMLDOM fields.
     1930 *
     1931 *@@added V0.9.9 (2001-02-14) [umoeller]
    4921932 */
    4931933
     
    5101950        if (!fSuccess)
    5111951        {
    512             // error:
    513             pDom->Error = XML_GetErrorCode(pDom->pParser);
    514             pDom->pcszErrorDescription = XML_ErrorString(pDom->Error);
    515             pDom->ulErrorLine = XML_GetCurrentLineNumber(pDom->pParser);
    516             pDom->ulErrorColumn = XML_GetCurrentColumnNumber(pDom->pParser);
     1952            // expat parsing error:
     1953            xmlSetError(pDom,
     1954                        XML_GetErrorCode(pDom->pParser),
     1955                        NULL,
     1956                        FALSE);
    5171957
    5181958            if (pDom->pDocumentNode)
    5191959            {
    520                 xmlDeleteNode(pDom->pDocumentNode);
     1960                xmlDeleteNode((PDOMNODE)pDom->pDocumentNode);
    5211961                pDom->pDocumentNode = NULL;
    5221962            }
     
    5241964            arc = ERROR_DOM_PARSING;
    5251965        }
    526 
    527 
    528         if (!fSuccess && fIsLast)
     1966        else if (pDom->fInvalid)
     1967        {
     1968            // expat was doing OK, but the handlers' validation failed:
     1969            arc = ERROR_DOM_VALIDITY;
     1970                        // error info has already been set
     1971        }
     1972        else
     1973            // expat was doing OK, but maybe we have integrity errors
     1974            // from our DOM callbacks:
     1975            if (pDom->arcDOM)
     1976                arc = pDom->arcDOM;
     1977
     1978        if (arc != NO_ERROR || fIsLast)
    5291979        {
    5301980            // last call or error: clean up
     
    5512001 *      calling this function.
    5522002 *
    553  *@@added V0.9.9 (2000-02-14) [umoeller]
     2003 *@@added V0.9.9 (2001-02-14) [umoeller]
    5542004 */
    5552005
  • trunk/src/helpers/xmldefs.c

    r36 r38  
    2222
    2323/*
    24  *@@category: Helpers\XML
    25  *      see xml.c.
     24 *@@gloss: expat expat
     25 *      Expat is one of the most well-known XML processors (parsers).
     26 *      I (umoeller) have ported expat to the XWorkplace Helpers
     27 *      library. See xmlparse.c for an introduction to expat. See
     28 *      xml.c for an introduction to XML support in the XWorkplace
     29 *      Helpers in general.
     30 */
     31
     32
     33/*
     34 *@@gloss: XML XML
     35 *      XML is the Extensible Markup Language, as defined by
     36 *      the W3C. XML isn't really a language, but a meta-language
     37 *      for describing markup languages. It is a simplified subset
     38 *      of SGML.
     39 *
     40 *      You should be familiar with the following:
     41 *
     42 *      -- XML parsers operate on XML @documents.
     43 *
     44 *      -- Each XML document has both a physical and a logical
     45 *         structure.
     46 *
     47 *         Physically, the document is composed of units called
     48 *         @entities.
     49 *
     50 *         Logically, the document is composed of @markup and
     51 *         @content. Among other things, markup separates the content
     52 *         into @elements.
     53 *
     54 *      -- The logical and physical structures must nest properly (be
     55 *         @well-formed) for each entity, which results in the entire
     56 *         XML document being well-formed as well.
    2657 */
    2758
    2859/*
    2960 *@@gloss: entities entities
    30  *      An "entity" is an XML storage unit. In the simplest case, an
    31  *      XML document has only one entity, which is an XML file.
    32  *      Except for the document entity (which is nameless), all
    33  *      entities are identified by their names.
    34  *
    35  *      Entities are marked as either parsed or unparsed.
    36  *
     61 *      An "entity" is an XML storage unit. It's a very abstract
     62 *      concept, and the term doesn't make much sense, but it was
     63 *      in SGML already, and XML chose to inherit it.
     64 *
     65 *      In the simplest case, an XML document has only one entity,
     66 *      which is an XML file (or memory buffer from wherever).
    3767 *      The document entity serves as the root of the entity tree
    3868 *      and a starting-point for an XML processor. Unlike other
     
    4070 *      appear on a processor input stream without any identification
    4171 *      at all.
     72 *
     73 *      Entities are defined to be either parsed or unparsed.
    4274 *
    4375 *      Other than that, there are @internal_entities,
     
    119151 *          They must be escaped unless used in a @CDATA section.
    120152 *
    121  *      --  To allow values in an @attribute to contain both single and double
     153 *      --  To allow values in @attributes to contain both single and double
    122154 *          quotes, the apostrophe or single-quote character (') may be
    123155 *          represented as "&amp;apos;", and the double-quote character
    124156 *          (") as "&amp;quot;".
    125157 *
    126  *      In addition, a @character_reference is a special case of an entity reference.
     158 *      A numeric @character_reference is a special case of an entity reference.
    127159 *
    128160 *      An internal entity is always parsed.
     
    210242 *
    211243 *      Markup is either @elements, @entity_references, @comments, @CDATA
    212  *      section delimiters, @DTD's, and
    213  *      @processing_instructions.
     244 *      section delimiters, @DTD's, or @processing_instructions.
    214245 *
    215246 *      XML "text" consists of markup and @content.
     
    226257 *      or may not be interested in white space. Whitespace
    227258 *      handling can therefore be handled differently for each
    228  *      element with the use of the special "xml:space" @attribute.
     259 *      element with the use of the special "xml:space" @attributes.
    229260 */
    230261
     
    291322 +           <P /> <IMG align="left" src="http://www.w3.org/Icons/WWW/w3c_home" />
    292323 *
    293  *      An @attribute contains additional an parameter to an element.
     324 *      In addition, @attributes contains extra parameters to elements.
    294325 *      If the element has attributes, they must be in the start-tag
    295326 *      (or empty-element tag).
     
    311342
    312343/*
    313  *@@gloss: attribute attribute
     344 *@@gloss: attributes attributes
    314345 *      "Attributes" are name-value pairs that have been associated
    315346 *      with @elements. Attributes can only appear in start-tags
     
    370401 *      document's @content; an XML processor may, but
    371402 *      need not, make it possible for an application to retrieve
    372  *      the text of comments (expat has a handler for this).
     403 *      the text of comments (@expat has a handler for this).
    373404 *
    374405 *      Comments may contain any text except "--" (double-hyphen).
     
    464495 *@@gloss: valid valid
    465496 *      XML @documents are said to be "valid" if they have a @DTD
    466  *      associated and they confirm to it.
     497 *      associated and they confirm to it. While XML documents
     498 *      must always be @well-formed, validation and validity is up
     499 *      to the implementation (i.e. at option to the application).
    467500 *
    468501 *      Validating processors must report violations of the constraints
     
    473506 *      referenced in the document.
    474507 *
    475  *      Non-validating processors are required to check only the
    476  *      document entity (see @entitites), including the entire
    477  *      internal DTD subset, for whether it is @well-formed. While
    478  *      they are  not required to check the document for validity,
     508 *      Non-validating processors (such as @expat) are required to
     509 *      check only the document entity (see @entitites), including the
     510 *      entire internal DTD subset, for whether it is @well-formed.
     511 *
     512 *      While they are  not required to check the document for validity,
    479513 *      they are required to process all the declarations they
    480514 *      read in the internal DTD subset and in any parameter entity
     
    482516 *      entity that they do not read; that is to say, they must
    483517 *      use the information in those declarations to normalize
    484  *      @attribute values, include the replacement text of
     518 *      values of @attributes, include the replacement text of
    485519 *      @internal_entities, and supply default attribute values.
    486520 *      They must not process entity declarations or attribute-list
     
    492526/*
    493527 *@@gloss: encodings encodings
    494  *      In an encoding declaration, the values "UTF-8", "UTF-16",
    495  *      "ISO-10646-UCS-2", and "ISO-10646-UCS-4" should be used
    496  *      for the various encodings and transformations of Unicode /
    497  *      ISO/IEC 10646, the values "ISO-8859-1", "ISO-8859-2", ...
    498  *      "ISO-8859-9" should be used for the parts of ISO 8859, and
    499  *      the values "ISO-2022-JP", "Shift_JIS", and "EUC-JP" should
    500  *      be used for the various encoded forms of JIS X-0208-1997.
     528 *      XML supports a wide variety of character encodings. These
     529 *      must be specified in the XML @text_declaration.
     530 *
     531 *      There are too many character encodings on the planet to
     532 *      be listed here. The most common ones are:
     533 *
     534 *      --  "UTF-8", "UTF-16", "ISO-10646-UCS-2", and "ISO-10646-UCS-4"
     535 *          should be used for the various encodings and transformations
     536 *          of Unicode / ISO/IEC 10646.
     537 *
     538 *      --  "ISO-8859-x" (with "x" being a number from 1 to 9) represent
     539 *          the various ISO 8859 ("Latin") encodings.
     540 *
     541 *      --  "ISO-2022-JP", "Shift_JIS", and "EUC-JP" should be used for
     542 *          the various encoded forms of JIS X-0208-1997.
     543 *
     544 *      Example of a @text_declaration:
     545 *
     546 +          <?xml version="1.0" encoding="ISO-8859-2"?>
    501547 *
    502548 *      All XML processors must be able to read @entities in either
    503  *      UTF-8 or UTF-16.
     549 *      UTF-8 or UTF-16. See XML_SetUnknownEncodingHandler for additional
     550 *      encodings directly supported by @expat.
    504551 *
    505552 *      Entities encoded in UTF-16 must begin with the ZERO WIDTH NO-BREAK
     
    508555 *      XML processors must be able to use this character to differentiate
    509556 *      between UTF-8 and UTF-16 encoded documents.
    510  *
    511  *      See XML_ParserCreate for the encodings directly supported
    512  *      by expat.
    513557 */
    514558
     
    576620 *      nature of their content. They look like this:
    577621 +
    578  +          <!ELEMENT name contentmodel>
     622 +          <!ELEMENT name contentspec>
    579623 +
    580  *      The "name" of the element is obvious. The "contentmodel"
     624 *      No element may be declared more than once.
     625 *
     626 *      The "name" of the element is obvious. The "contentspec"
    581627 *      is not. This specifies what may appear in the element
    582  *      and can be a list of:
    583  *
    584  *      --  "#PCDATA", meaning "parsed character data" -- in
    585  *          other words, @content.
    586  *
    587  *      --  Another element name with a specification about
    588  *          whether the element may or must appear once or
    589  *          more than once.
    590  *
    591  *      --  "EMPTY" marks the element as being empty (i.e. no
    592  *          start- and end-tags, but a single tag only).
    593  *
    594  *      The element specifyer can be:
    595  *
    596  *      --  None: the subelement _must_ appear exactly once.
    597  *
    598  *      --  "+": the subelement _must_ appear at _least_ once.
    599  *
    600  *      --  "?": the subelement _may_ appear exactly once.
    601  *
    602  *      --  "*": the subelement _may_ appear once or more than
    603  *          once or not at all. Note that this must always be
    604  *          specified with "#PCDATA".
    605  *
    606  *      The list items can be separated with:
     628 *      and can be one of the following:
     629 *
     630 *      --  "EMPTY" marks the element as being empty (i.e.
     631 *          having no content at all).
     632 *
     633 *      --  "ANY" does not impose any restrictions.
     634 *
     635 *      --  (mixed): a "list" which declares the element to have
     636 *          mixed content. See below.
     637 *
     638 *      --  (children): a "list" which declares the element to
     639 *          have child elements only, but no content. See below.
     640 *
     641 *      <B>(mixed): content with elements</B>
     642 *
     643 *      With the (mixed) contentspec, an element may either contain
     644 *      @content only or @content with subelements.
     645 *
     646 *      While the (children) contentspec allows you to define sequences
     647 *      and orders, this is not possible with (mixed).
     648 *
     649 *      "contentspec" must then be a pair of parentheses, optionally
     650 *      followed by "*". In the brackets, there must be at least the
     651 *      keyword "#PCDATA", optionally followed by "|" and element
     652 *      names. Note that if no #PCDATA appears, the (children) model
     653 *      is assumed (see below).
     654 *
     655 *      Examples:
     656 *
     657 +          <!ELEMENT name (#PCDATA)* >
     658 +          <!ELEMENT name (#PCDATA | subname1 | subname2)* >
     659 +          <!ELEMENT name (#PCDATA) >
     660 *
     661 *      Note that if you specify sub-element names, you must terminate
     662 *      the contentspec with "*". Again, there's no way to specify
     663 *      orders etc. with (mixed).
     664 *
     665 *      <B>(children): Element content only</B>
     666 *
     667 *      With the (children) contentspec, an element may contain
     668 *      only other elements (and @whitespace), but no other @content.
     669 *
     670 *      This can become fairly complicated. "contentspec" then must be
     671 *      a "list" followed by a "repeater".
     672 *
     673 *      A "repeater" can be:
     674 *
     675 *      --  Nothing: the preceding item _must_ appear exactly once.
     676 *
     677 *      --  "+": the preceding item _must_ appear at _least_ once.
     678 *
     679 *      --  "?": the preceding item _may_ appear exactly once.
     680 *
     681 *      --  "*": the preceding item _may_ appear once or more than
     682 *          once or not at all.
     683 *
     684 *      Here's the most simple example (precluding that "SUBELEMENT"
     685 *      is a valid "list" here):
     686 *
     687 +          <!ELEMENT name (SUBELEMENT)* >
     688 *
     689 *      In other words, in (children) mode, "contentspec" must always
     690 *      be in brackets and is followed by a "repeater" (which can be
     691 *      nothing).
     692 *
     693 *      About "lists"... since these declarations may nest, this is
     694 *      where the recursive definition of a "content particle" comes
     695 *      in:
     696 *
     697 *      --  A "content particle" is either a sub-element name or
     698 *          a nested list, followed by a "repeater".
     699 *
     700 *      --  A "list" is defined as an enumeration of content particles,
     701 *          enclosed in parentheses, where the content particles are
     702 *          separated by list separators.
     703 *
     704 *      There are two types of list separators:
    607705 *
    608706 *      --  Commas (",") indicate that the elements must appear
    609  *          in the same order.
     707 *          in the specified order ("sequence").
    610708 *
    611709 *      --  Vertical bars ("|") specify that the elements may
    612  *          occur alternatively.
    613  *
    614  *      Examples:
    615  +
    616  +          <!ELEMENT oldjoke  (burns+, allen, applause?)>
    617  +          <!ELEMENT burns    (#PCDATA | quote)*>
    618  +          <!ELEMENT allen    (#PCDATA | quote)*>
    619  +          <!ELEMENT quote    (#PCDATA)*>
    620  +          <!ELEMENT applause EMPTY>
    621  *
    622  *      This defines that the element "oldjoke" must contain
    623  *      "burns" and "allen" and may contain "applause".
    624  *      Only "burns" may appear more than once.
     710 *          occur alternatively ("choice").
     711 *
     712 *      The list separators cannot be mixed; the list must be
     713 *      either completely "sequence" or "choice".
     714 *
     715 *      Examples of content particles:
     716 *
     717 +              SUBELEMENT+
     718 +              list*
     719 *
     720 *      Examples of lists:
     721 *
     722 +          ( cp | cp | cp | cp )
     723 +          ( cp , cp , cp , cp )
     724 *
     725 *      Full examples for (children):
     726 *
     727 +          <!ELEMENT oldjoke  ( burns+, allen, applause? ) >
     728 +                             | |       +cp-+          | |
     729 +                             | |                      | |
     730 +                             | +------- list ---------+ |
     731 +                             +-------contentspec--------+
     732 *
     733 *      This specifies a "seqlist" for the "oldjoke" element. The
     734 *      list is not nested, so the content particles are element
     735 *      names only.
     736 *
     737 *      Within "oldjoke", "burns" must appear first and can appear
     738 *      once or several times.
     739 *
     740 *      Next must be "allen", exactly once (since there's no repeater).
     741 *
     742 *      Optionally ("?"), there can be "applause" at the end.
     743 *
     744 *      Now, a nested example:
     745 *
     746 +          <!ELEMENT WARPIN (REXX*, VARPROMPT*, MSG?, TITLE?, (GROUP | PCK)+), PAGE+) >
     747 *
    625748 */
    626749
     
    754877 *      in whole or in part within @parameter_entities.
    755878 */
     879
     880/*
     881 *@@gloss: DOM DOM
     882 *      DOM is the "Document Object Model", as defined by the W3C.
     883 *
     884 *      The DOM is a programming interface for @XML @documents.
     885 *      (XML is a metalanguage and describes the documents
     886 *      themselves. DOM is a programming interface -- an API --
     887 *      to access XML documents.)
     888 *
     889 *      The W3C calls this "a platform- and language-neutral
     890 *      interface that allows programs and scripts to dynamically
     891 *      access and update the content, structure and style of
     892 *      documents. The Document Object Model provides
     893 *      a standard set of objects for representing HTML and XML
     894 *      documents, a standard model of how these objects can
     895 *      be combined, and a standard interface for accessing and
     896 *      manipulating them. Vendors can support the DOM as an
     897 *      interface to their proprietary data structures and APIs,
     898 *      and content authors can write to the standard DOM
     899 *      interfaces rather than product-specific APIs, thus
     900 *      increasing interoperability on the Web."
     901 *
     902 *      In short, DOM specifies that an XML document is broken
     903 *      up into a tree of "nodes", representing the various parts
     904 *      of an XML document. Such nodes represent @documents,
     905 *      @elements, @attributes, @processing_instructions,
     906 *      @comments, @content, and more.
     907 *
     908 *      See xml.c for an introduction to XML and DOM support in
     909 *      the XWorkplace helpers.
     910 *
     911 *      Example: Take this HTML table definition:
     912 +
     913 +          <TABLE>
     914 +          <TBODY>
     915 +          <TR>
     916 +          <TD>Column 1-1</TD>
     917 +          <TD>Column 1-2</TD>
     918 +          </TR>
     919 +          <TR>
     920 +          <TD>Column 2-1</TD>
     921 +          <TD>Column 2-2</TD>
     922 +          </TR>
     923 +          </TBODY>
     924 +          </TABLE>
     925 *
     926 *      In the DOM, this would be represented by a tree as follows:
     927 +
     928 +                          ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿
     929 +                          ³   TABLE    ³        (only ELEMENT node in root DOCUMENT node)
     930 +                          ÀÄÄÄÄÄÂÄÄÄÄÄÄÙ
     931 +                                ³
     932 +                          ÚÄÄÄÄÄÁÄÄÄÄÄÄ¿
     933 +                          ³   TBODY    ³        (only ELEMENT node in root "TABLE" node)
     934 +                          ÀÄÄÄÄÄÂÄÄÄÄÄÄÙ
     935 +                    ÚÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄ¿
     936 +              ÚÄÄÄÄÄÁÄÄÄÄÄÄ¿          ÚÄÄÄÄÄÁÄÄÄÄÄÄ¿
     937 +              ³   TR       ³          ³   TR       ³
     938 +              ÀÄÄÄÄÄÂÄÄÄÄÄÄÙ          ÀÄÄÄÄÄÂÄÄÄÄÄÄÙ
     939 +                ÚÄÄÄÁÄÄÄÄÄÄ¿            ÚÄÄÄÁÄÄÄÄÄÄ¿
     940 +            ÚÄÄÄÁÄ¿     ÚÄÄÁÄÄ¿     ÚÄÄÄÁÄ¿     ÚÄÄÁÄÄ¿
     941 +            ³ TD  ³     ³ TD  ³     ³ TD  ³     ³ TD  ³
     942 +            ÀÄÄÂÄÄÙ     ÀÄÄÂÄÄÙ     ÀÄÄÄÂÄÙ     ÀÄÄÂÄÄÙ
     943 +         ÉÍÍÍÍÍÊÍÍÍÍ» ÉÍÍÍÍÊÍÍÍÍÍ» ÉÍÍÍÍÊÍÍÍÍÍ» ÉÍÍÊÍÍÍÍÍÍÍ»
     944 +         ºColumn 1-1º ºColumn 1-2º ºColumn 2-1º ºColumn 2-2º    (one TEXT node in each parent node)
     945 +         ÈÍÍÍÍÍÍÍÍÍÍŒ ÈÍÍÍÍÍÍÍÍÍÍŒ ÈÍÍÍÍÍÍÍÍÍÍŒ ÈÍÍÍÍÍÍÍÍÍÍŒ
     946 */
     947
     948/*
     949 *@@gloss: DOM_DOCUMENT DOCUMENT
     950 *      representation of XML @documents in the @DOM.
     951 *
     952 *      The xwphelpers implementation has the following differences
     953 *      to the DOM specs:
     954 *
     955 *      -- The "doctype" member points to the documents @DTD, or is NULL.
     956 *         In our implementation, this is the pvExtra pointer, which points
     957 *         to a _DOMDTD.
     958 *
     959 *      -- The "implementation" member points to a DOMImplementation object.
     960 *         This is not supported here.
     961 *
     962 *      -- The "documentElement" member is a convenience pointer to the
     963 *         document's root element. We don't supply this field; instead,
     964 *         the llChildren list only contains a single ELEMENT node for the
     965 *         root element.
     966 *
     967 *      -- The "createElement" method is implemented by xmlCreateElementNode.
     968 *
     969 *      -- The "createAttribute" method is implemented by xmlCreateAttributeNode.
     970 *
     971 *      -- The "createTextNode" method is implemented by xmlCreateTextNode,
     972 *         which has an extra parameter though.
     973 *
     974 *      -- The "createComment" method is implemented by xmlCreateCommentNode.
     975 *
     976 *      -- The "createProcessingInstruction" method is implemented by
     977 *         xmlCreatePINode.
     978 *
     979 *      -- The "createDocumentFragment", "createCDATASection", and
     980 *         "createEntityReference" methods are not supported.
     981 */
     982
     983
  • trunk/src/helpers/xmlparse.c

    r36 r38  
    55 *      SourceForge Oct 22, 2000.
    66 *
    7  *      Expat is a library, written in C, for parsing XML documents. It's
     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.
     10 *
     11 *      Expat is a library, written in C, for parsing XML @documents. It's
    812 *      the underlying XML parser for the open source Mozilla project,
    913 *      perl's XML::Parser, and other open-source XML parsers.
     
    1822 *      that comes with expat as an HTML file. I (umoeller)
    1923 *      have integrated the docs into the sources and added a
    20  *      couple of remarks on the way.
    21  *
    22  *      See XML_ParserCreate for an introduction to expat.
     24 *      couple of remarks while trying to implement parsers.
     25 *
     26 *      See XML_ParserCreate for instructions how to parse XML.
     27 *
     28 *      Note that expat is a non-validating XML processor. Validation
     29 *      is supported by the top layer of xwphelpers XML support. See
     30 *      xml.c.
    2331 *
    2432 *@@added V0.9.9 (2001-02-10) [umoeller]
     33 *@@header "expat\expat.h"
    2534 */
    2635
     
    4857 *      TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    4958 *      SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     59 */
     60
     61/*
     62 *@@category: Helpers\C helpers\XML\expat
     63 *      expat XML parser. See xmlparse.c.
    5064 */
    5165
     
    95109    typedef char ICHAR;
    96110#endif
    97 
    98111
    99112#ifndef XML_NS
     
    281294} OPEN_INTERNAL_ENTITY, *POPEN_INTERNAL_ENTITY;
    282295
    283 typedef enum XML_Error Processor(XML_Parser parser,
     296typedef XMLERROR Processor(XML_Parser parser,
    284297                                 const char *start,
    285298                                 const char *end,
     
    302315static Processor externalEntityContentProcessor;
    303316
    304 static enum XML_Error handleUnknownEncoding(XML_Parser parser,
     317static XMLERROR handleUnknownEncoding(XML_Parser parser,
    305318                                            const XML_Char * encodingName);
    306 static enum XML_Error processXmlDecl(XML_Parser parser,
     319static XMLERROR processXmlDecl(XML_Parser parser,
    307320                                     int isGeneralTextEntity,
    308321                                     const char *,
    309322                                     const char *);
    310 static enum XML_Error initializeEncoding(XML_Parser parser);
    311 static enum XML_Error doProlog(XML_Parser parser,
     323static XMLERROR initializeEncoding(XML_Parser parser);
     324static XMLERROR doProlog(XML_Parser parser,
    312325                               const ENCODING * enc,
    313326                               const char *s,
     
    316329                               const char *next,
    317330                               const char **nextPtr);
    318 static enum XML_Error processInternalParamEntity(XML_Parser parser,
     331static XMLERROR processInternalParamEntity(XML_Parser parser,
    319332                                                 ENTITY * entity);
    320 static enum XML_Error doContent(XML_Parser parser,
     333static XMLERROR doContent(XML_Parser parser,
    321334                                int startTagLevel,
    322335                                const ENCODING * enc,
     
    324337                                const char *end,
    325338                                const char **endPtr);
    326 static enum XML_Error doCdataSection(XML_Parser parser,
     339static XMLERROR doCdataSection(XML_Parser parser,
    327340                                     const ENCODING *,
    328341                                     const char **startPtr,
     
    331344
    332345#ifdef XML_DTD
    333 static enum XML_Error doIgnoreSection(XML_Parser parser,
     346static XMLERROR doIgnoreSection(XML_Parser parser,
    334347                                      const ENCODING *,
    335348                                      const char **startPtr,
     
    338351#endif /* XML_DTD */
    339352
    340 static enum XML_Error storeAtts(XML_Parser parser,
     353static XMLERROR storeAtts(XML_Parser parser,
    341354                                const ENCODING *,
    342355                                const char *s,
     
    356369                           XML_Parser parser);
    357370
    358 static enum XML_Error storeAttributeValue(XML_Parser parser,
     371static XMLERROR storeAttributeValue(XML_Parser parser,
    359372                                          const ENCODING *,
    360373                                          int isCdata,
     
    362375                                          const char *,
    363376                                          STRING_POOL *);
    364 static enum XML_Error appendAttributeValue(XML_Parser parser,
     377static XMLERROR appendAttributeValue(XML_Parser parser,
    365378                                           const ENCODING *,
    366379                                           int isCdata,
     
    373386                                     const char *end);
    374387static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *);
    375 static enum XML_Error storeEntityValue(XML_Parser parser,
     388static XMLERROR storeEntityValue(XML_Parser parser,
    376389                                       const ENCODING * enc,
    377390                                       const char *start,
     
    426439
    427440static int nextScaffoldPart(XML_Parser parser);
    428 static XML_Content *build_model(XML_Parser parser);
     441static XMLCONTENT *build_model(XML_Parser parser);
    429442
    430443static const XML_Char *poolCopyString(STRING_POOL * pool, const XML_Char * s);
     
    499512    PROLOG_STATE m_prologState;
    500513    Processor *m_processor;
    501     enum XML_Error m_errorCode;
     514    XMLERROR m_errorCode;
    502515    const char *m_eventPtr;
    503516    const char *m_eventEndPtr;
     
    631644 *@@ XML_ParserCreate:
    632645 *      constructs a new parser. If encoding is non-null, it specifies
    633  *      a character encoding to use for the document. This overrides
    634  *      the document encoding declaration.
     646 *      a character encoding to use for the document (see below).
     647 *      This overrides the document encoding declaration.
    635648 *
    636649 *      Expat is a stream-oriented parser. You register callback (or
     
    638651 *      the document. As the parser recognizes parts of the document,
    639652 *      it will call the appropriate handler for that part (if you've
    640  *      registered one.) The document is fed to the parser in pieces,
     653 *      registered one). The document is fed to the parser in pieces,
    641654 *      so you can start parsing before you have all the document.
    642655 *      This also allows you to parse really huge documents that won't
     
    685698 *
    686699 *      The things you're likely to want to keep on a stack are the
    687  *      currently opened element and it's attributes. You push this
     700 *      currently opened element and its attributes. You push this
    688701 *      information onto the stack in the start handler and you pop
    689702 *      it off in the end handler.
    690703 *
    691704 *      For some tasks, it is sufficient to just keep information on
    692  *      what the depth of the stack is (or would be if you had one.)
     705 *      what the depth of the stack is (or would be if you had one).
    693706 *      The outline program shown above presents one example. Another
    694707 *      such task would be skipping over a complete element. When you
     
    710723 *      While XML is based on Unicode, and every XML processor is
    711724 *      required to recognized UTF-8 and UTF-16 (1 and 2 byte
    712  *      encodings of Unicode), other encodings may be declared in
     725 *      encodings of Unicode), other @encodings may be declared in
    713726 *      XML documents or entities. For the main document, an XML
    714727 *      declaration may contain an encoding declaration in its
    715  *      @text_declaration:
    716  *
    717  +          <?xml version="1.0" encoding="ISO-8859-2"?>
     728 *      @text_declaration. See @encodings for additional
     729 *      information.
    718730 *
    719731 *      With expat, you may also specify an encoding at the time
    720732 *      of creating a parser. This is useful when the encoding
    721733 *      information may come from a source outside the document
    722  *      itself (like a higher level protocol.)
    723  *
    724  *      There are four built-in encodings in expat:
    725  *
    726  *      --   UTF-8: 8-bit encoding of Unicode.
    727  *
    728  *      --   UTF-16: 16-bit encoding of Unicode.
    729  *
    730  *      --   ISO-8859-1: that's "latin 1".
    731  *
    732  *      --   US-ASCII
    733  *
    734  *      Anything else discovered in an encoding declaration or in
    735  *      the protocol encoding specified in the parser constructor,
    736  *      triggers a call to the UnknownEncodingHandler (see
    737  *      XML_SetUnknownEncodingHandler). This handler gets passed
    738  *      the encoding name and a pointer to an XML_Encoding data
    739  *      structure. Your handler must fill in this structure and
    740  *      return 1 if it knows how to deal with the encoding. Otherwise
    741  *      the handler should return 0. The handler also gets passed a
    742  *      pointer to an optional application data structure that you may
    743  *      indicate when you set the handler.
     734 *      itself (like a higher level protocol).
     735 *
     736 *      See XML_SetUnknownEncodingHandler for encodings directly
     737 *      supported by expat and for how to handle other encodings.
    744738 *
    745739 *      One pitfall that novice expat users are likely to fall into is
     
    751745 *      <B>Handling External Entity References</B>
    752746 *
    753  *      Expat does not read or parse external entities directly. Note that
    754  *      any external @DTD is a special case of an external entity. If you've
    755  *      set no ExternalEntityRefHandler (see XML_SetExternalEntityRefHandler),
    756  *      then external entity references are silently ignored. Otherwise, it
    757  *      calls your handler with the information needed to read and parse the
    758  *      external entity.
    759  *
    760  *      <B>Parsing DTDs</B>
     747 *      Expat does not read or parse @external_entities directly. Note that
     748 *      any external @DTD is a special case of an external entity. For how to
     749 *      handle external entities, see XML_SetExternalEntityRefHandler.
     750 *
     751 *      <B>Parsing Parameter Entities</B>
    761752 *
    762753 *      In order to parse @parameter_entities, before starting the parse,
     
    933924    declNotationPublicId = 0;
    934925    memset(&position, 0, sizeof(POSITION));
    935     errorCode = XML_ERROR_NONE;
     926    errorCode = ERROR_EXPAT_NONE;
    936927    eventPtr = 0;
    937928    eventEndPtr = 0;
     
    13491340 *      This handler must have the following prototype:
    13501341 *
    1351  +          void EXPATENTRY StartElementHandler(void *userData,
    1352  +                                            const XML_Char *name,
    1353  +                                            const XML_Char **atts);
     1342 +          void EXPATENTRY StartElementHandler(void *pUserData,
     1343 +                                              const XML_Char *name,
     1344 +                                              const XML_Char **atts);
    13541345 +
    13551346 *      "data" is the user data pointer set with XML_SetUserData.
     
    13981389 *      Handler prototype:
    13991390 +
    1400  +          void EXPATENTRY (void *userData,
    1401  +                         const XML_Char *name);
     1391 +          void EXPATENTRY EndElementHandler(void *pUserData,
     1392 +                                            const XML_Char *name);
    14021393 */
    14031394
     
    14101401/*
    14111402 *@@ XML_SetCharacterDataHandler:
    1412  *      sets a character data (text) handler.
     1403 *      sets a character data (text, @content) handler.
    14131404 *
    14141405 *      Handler prototype:
    14151406 *
    1416  +          void EXPATENTRY CharacterDataHandler(void *userData,
    1417  +                                             const XML_Char *s,
    1418  +                                             int len);
     1407 +          void EXPATENTRY CharacterDataHandler(void *pUserData,
     1408 +                                               const XML_Char *s,
     1409 +                                               int len);
    14191410 +
    14201411 *      The string your handler receives is NOT zero terminated.
     
    14381429 *      Handler prototype:
    14391430 *
    1440  +          void EXPATENTRY ProcessingInstructionHandler(void *userData,
    1441  +                                                     const XML_Char *target,
    1442  +                                                     const XML_Char *data);
     1431 +          void EXPATENTRY ProcessingInstructionHandler(void *pUserData,
     1432 +                                                       const XML_Char *target,
     1433 +                                                       const XML_Char *data);
    14431434 +
    14441435 *      The target is the first word in the processing instruction. The data
     
    14601451 *      Handler prototype:
    14611452 *
    1462  +          void EXPATENTRY CommentHandler(void *userData,
    1463  +                                       const XML_Char *data);
     1453 +          void EXPATENTRY CommentHandler(void *pUserData,
     1454 +                                         const XML_Char *data);
    14641455 *
    14651456 */
     
    14921483 *      Handler prototype:
    14931484 *
    1494  +          void EXPATENTRY StartCdataSectionHandler(void *userData);
     1485 +          void EXPATENTRY StartCdataSectionHandler(void *pUserData);
    14951486 *
    14961487 */
     
    15091500 *      Handler prototype:
    15101501 *
    1511  *          void EXPATENTRY EndCdataSectionHandler(void *userData);
     1502 *          void EXPATENTRY EndCdataSectionHandler(void *pUserData);
    15121503 */
    15131504
     
    15291520 *      Handler prototype:
    15301521 +
    1531  +          void EXPATENTRY DefaultHandler(void *userData,
    1532  +                                       const XML_Char *s,
    1533  +                                       int len);
     1522 +          void EXPATENTRY DefaultHandler(void *pUserData,
     1523 +                                         const XML_Char *s,
     1524 +                                         int len);
    15341525 *
    15351526 *      The characters are passed exactly as they were in the XML
     
    15471538 *      turning off expansion of references to internally defined
    15481539 *      general entities. Instead these references are passed to
    1549  *      the default handler.
     1540 *      the default handler. To avoid that, use XML_SetDefaultHandlerExpand.
    15501541 */
    15511542
     
    15941585 *      Handler prototype:
    15951586 *
    1596  +          void EXPATENTRY StartDoctypeDeclHandler(void *userData,
    1597  +                                                const XML_Char *doctypeName,
    1598  +                                                const XML_Char *sysid,
    1599  +                                                const XML_Char *pubid,
    1600  +                                                int has_internal_subset);
    1601  *
    1602  *      Both sysid and pubid may be NULL. The has_internal_subset
     1587 +          void EXPATENTRY StartDoctypeDeclHandler(void *pUserData,
     1588 +                                                  const XML_Char *pcszDoctypeName,
     1589 +                                                  const XML_Char *pcszSysid,
     1590 +                                                  const XML_Char *pcszPubid,
     1591 +                                                  int fHasInternalSubset);
     1592 *
     1593 *      Both pcszSysid and pcszPubid may be NULL. "fHasInternalSubset"
    16031594 *      will be non-zero if the DOCTYPE declaration has an internal subset.
    16041595 */
     
    16171608 *      Handler prototype:
    16181609 *
    1619  +          void EXPATENTRY EndDoctypeDeclHandler(void *userData);
     1610 +          void EXPATENTRY EndDoctypeDeclHandler(void *pUserData);
    16201611 *
    16211612 */
     
    16511642 *      Handler prototype:
    16521643 +
    1653  +      void EXPATENTRY NotationDeclHandler(void *userData,
    1654  +                                        const XML_Char *notationName,
    1655  +                                        const XML_Char *base,
    1656  +                                        const XML_Char *systemId,
    1657  +                                        const XML_Char *publicId);
     1644 +      void EXPATENTRY NotationDeclHandler(void *pUserData,
     1645 +                                          const XML_Char *pcszNotationName,
     1646 +                                          const XML_Char *pcszBase,
     1647 +                                          const XML_Char *pcszSystemId,
     1648 +                                          const XML_Char *pcszPublicId);
    16581649 +
    16591650 */
     
    16891680 *      Handler prototype:
    16901681 *
    1691  +      void EXPATENTRY StartNamespaceDeclHandler(void *userData,
    1692  +                                              const XML_Char *prefix,
    1693  +                                              const XML_Char *uri);
     1682 +      void EXPATENTRY StartNamespaceDeclHandler(void *pUserData,
     1683 +                                                const XML_Char *prefix,
     1684 +                                                const XML_Char *uri);
    16941685 +
    16951686 */
     
    17101701 *      Handler prototype:
    17111702 +
    1712  +      void EXPATENTRY EndNamespaceDeclHandler)(void *userData,
    1713  +                                             const XML_Char *prefix);
     1703 +      void EXPATENTRY EndNamespaceDeclHandler(void *pUserData,
     1704 +                                              const XML_Char *prefix);
    17141705 */
    17151706
     
    17281719 *      not have standalone set to "yes" in an XML declaration.
    17291720 *      If this handler returns 0, then the parser will throw an
    1730  *      XML_ERROR_NOT_STANDALONE error.
     1721 *      ERROR_EXPAT_NOT_STANDALONE error.
    17311722 *
    17321723 *      Handler prototype:
    17331724 *
    1734  +          int EXPATENTRY NotStandaloneHandler(void *userData);
     1725 +          int EXPATENTRY NotStandaloneHandler(void *pUserData);
    17351726 */
    17361727
     
    17431734/*
    17441735 *@@ XML_SetExternalEntityRefHandler:
    1745  *      sets an external entity reference handler. This handler is
    1746  *      also called for processing an external DTD subset if
    1747  *      parameter entity parsing is in effect.
     1736 *      sets a handler for references to @external_entities.
     1737 *
     1738 *      This handler is also called for processing an external DTD
     1739 *      subset if parameter entity parsing is in effect.
    17481740 *      (See XML_SetParamEntityParsing.)
     1741 *
     1742 *      Warning: If you have set no ExternalEntityRefHandler, then
     1743 *      external entity references are silently ignored. Otherwise,
     1744 *      they trigger a call to your handler with the information
     1745 *      needed to read and parse the external entity.
    17491746 *
    17501747 *      Handler prototype:
    17511748 +
    17521749 +      int EXPATENTRY ExternalEntityRefHandler(XML_Parser parser,
    1753  +                                            const XML_Char *context,
    1754  +                                            const XML_Char *base,
    1755  +                                            const XML_Char *systemId,
    1756  +                                            const XML_Char *publicId);
     1750 +                                              const XML_Char *pcszContext,
     1751 +                                              const XML_Char *pcszBase,
     1752 +                                              const XML_Char *pcszSystemId,
     1753 +                                              const XML_Char *pcszPublicId);
    17571754 +
    1758  *      The context argument specifies the parsing context in the
     1755 *      The pcszContext argument specifies the parsing context in the
    17591756 *      format expected by the context argument to
    1760  *      XML_ExternalEntityParserCreate; context is valid only until
     1757 *      XML_ExternalEntityParserCreate; pcszContext is valid only until
    17611758 *      the handler returns, so if the referenced entity is to be
    17621759 *      parsed later, it must be copied.
    17631760 *
    1764  *      The base parameter is the base to use for relative system
     1761 *      The pcszBase parameter is the base to use for relative system
    17651762 *      identifiers. It is set by XML_SetBase and may be null.
    17661763 *
    1767  *      The publicId parameter is the public id given in the entity
     1764 *      The pcszPublicId parameter is the public id given in the entity
    17681765 *      declaration and may be null.
    17691766 *
    1770  *      The systemId is the system identifier specified in the
     1767 *      The pcszSystemId is the system identifier specified in the
    17711768 *      entity declaration and is never null.
    17721769 *
     
    17761773 *      of the external entity reference. Returning a zero indicates
    17771774 *      failure, and causes the calling parser to return an
    1778  *      XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
    1779  *
    1780  *      Second, instead of having userData as its first argument,
     1775 *      ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING error.
     1776 *
     1777 *      Second, instead of having pUserData as its first argument,
    17811778 *      it receives the parser that encountered the entity reference.
    17821779 *      This, along with the context parameter, may be used as
     
    17901787 *      Your handler isn't actually responsible for parsing the entity,
    17911788 *      but it is responsible for creating a subsidiary parser with
    1792  *      XML_ExternalEntityParserCreate that will do the job. This returns
     1789 *      XML_ExternalEntityParserCreate that will do the job. That returns
    17931790 *      an instance of XML_Parser that has handlers and other data
    17941791 *      structures initialized from the parent parser. You may then use
    1795  *      XML_Parse or XML_ParseBuffer calls against this parser. Since
     1792 *      XML_Parse or XML_ParseBuffer calls against that parser. Since
    17961793 *      external entities may refer to other external entities, your
    17971794 *      handler should be prepared to be called recursively.
     
    18141811/*
    18151812 *@@ XML_SetUnknownEncodingHandler:
    1816  *      sets a handler to deal with encodings other than the
    1817  *      built in set (see XML_ParserCreate).
     1813 *      sets a handler to deal with @encodings other than the
     1814 *      built-in set.
     1815 *
     1816 *      There are four built-in encodings in expat:
     1817 *
     1818 *      --   UTF-8: 8-bit encoding of Unicode.
     1819 *
     1820 *      --   UTF-16: 16-bit encoding of Unicode.
     1821 *
     1822 *      --   ISO-8859-1: that's "latin 1".
     1823 *
     1824 *      --   US-ASCII
     1825 *
     1826 *      Anything else discovered in an encoding declaration or in
     1827 *      the protocol encoding specified in the parser constructor
     1828 *      triggers a call to the UnknownEncodingHandler.
    18181829 *
    18191830 *      Handler prototype:
    18201831 *
    18211832 +          int EXPATENTRY UnknownEncodingHandler(void *encodingHandlerData,
    1822  +                                              const XML_Char *name,
    1823  +                                              XML_Encoding *info);
     1833 +                                                const XML_Char *name,
     1834 +                                                XML_Encoding *info);
    18241835 +
    18251836 *      The encodingHandlerData argument is that which was passed as the
     
    18431854 *      1.  Every ASCII character that can appear in a well-formed XML
    18441855 *          document must be represented by a single byte, and that byte
    1845  *          must correspond to it's ASCII encoding (except for the
     1856 *          must correspond to its ASCII encoding (except for the
    18461857 *          characters $@\^'{}~).
    18471858 *
     
    18521863 *          the built-in support for UTF-16 and UTF-8.)
    18531864 *
    1854  *      4.  No character may be encoded by more that one distinct
     1865 *      4.  No character may be encoded by more than one distinct
    18551866 *          sequence of bytes.
    18561867 */
     
    18661877/*
    18671878 *@@ XML_SetElementDeclHandler:
    1868  *      sets a handler for element declarations in a DTD. The
     1879 *      sets a handler for an @element_declaration in a @DTD. The
    18691880 *      handler gets called with the name of the element in
    18701881 *      the declaration and a pointer to a structure that contains
     
    18741885 *      This handler must have the following prototype:
    18751886 *
    1876  +          void EXPATENTRY ElementDeclHandler(void *userData,
    1877  +                                           const XML_Char *name,
    1878  +                                           XML_Content *model);
    1879  *
    1880  *      The model argument is the root of a tree of XML_Content
    1881  *      nodes. If type equals XML_CTYPE_EMPTY or XML_CTYPE_ANY,
    1882  *      then quant will be XML_CQUANT_NONE, and the other fields
    1883  *      will be zero or NULL.
    1884  *
    1885  *      If type is XML_CTYPE_MIXED, then quant will be
    1886  *      XML_CQUANT_NONE or XML_CQUANT_REP and numchildren will
    1887  *      contain the number of elements that are allowed to be
    1888  *      mixed in and children points to an array of XML_Content
    1889  *      structures that will all have type XML_CTYPE_NAME with no
    1890  *      quantification. Only the root node can be type
    1891  *      XML_CTYPE_EMPTY, XML_CTYPE_ANY, or XML_CTYPE_MIXED.
    1892  *
    1893  *      For type XML_CTYPE_NAME, the name field points to the
    1894  *      name and the numchildren and children fields will be
    1895  *      zero and NULL. The quant field will indicate any
    1896  *      quantifiers placed on the name.
    1897  *
    1898  *      Types XML_CTYPE_CHOICE and XML_CTYPE_SEQ indicate a
    1899  *      choice or sequence respectively. The numchildren field
    1900  *      indicates how many nodes in the choice or sequence and
    1901  *      children points to the nodes.
     1887 +          void EXPATENTRY ElementDeclHandler(void *pUserData,
     1888 +                                             const XML_Char *name,
     1889 +                                             XMLCONTENT *model);
     1890 *
     1891 *      See _XMLCONTENT for details.
    19021892 */
    19031893
     
    19101900/*
    19111901 *@@ XML_SetAttlistDeclHandler:
    1912  *      sets a handler for attlist declarations in the DTD.
     1902 *      sets a handler for an @attribute_declaration in the @DTD.
    19131903 *
    19141904 *      This handler must have the following prototype:
    19151905 *
    1916  +          void EXPATENTRY AttlistDeclHandler(void *userData,
    1917  +                                           const XML_Char  *elname,
    1918  +                                           const XML_Char  *attname,
    1919  +                                           const XML_Char  *att_type,
    1920  +                                           const XML_Char  *dflt,
    1921  +                                           int     isrequired);
     1906 +          void EXPATENTRY AttlistDeclHandler(void *pUserData,
     1907 +                                             const XML_Char *pcszElementName,
     1908 +                                             const XML_Char *pcszAttribName,
     1909 +                                             const XML_Char *pcszAttribType,
     1910 +                                             const XML_Char *pcszDefault,
     1911 +                                             int fIsRequired);
    19221912 *
    19231913 *      This handler is called for each attribute. So a single attlist
    19241914 *      declaration with multiple attributes declared will generate
    1925  *      multiple calls to this handler. The elname parameter
    1926  *      returns the name of the element for which the attribute
    1927  *      is being declared. The attribute name is in the attname
    1928  *      parameter. The attribute type is in the att_type parameter.
    1929  *      It is the string representing the type in the declaration
    1930  *      with whitespace removed.
    1931  *
    1932  *      The dflt parameter holds the default value. It will be
    1933  *      NULL in the case of "#IMPLIED" or "#REQUIRED" attributes.
    1934  *      You can distinguish these two cases by checking the
    1935  *      isrequired parameter, which will be true in the case of
    1936  *      "#REQUIRED" attributes. Attributes which are "#FIXED"
    1937  *      will have also have a true isrequired, but they will have
    1938  *      the non-NULL fixed value in the dflt parameter.
     1915 *      multiple calls to this handler.
     1916 *
     1917 *      --  pcszElementName is the name of the  element for which the
     1918 *          attribute is being declared.
     1919 *
     1920 *      --  pcszAttribName has the attribute name being declared.
     1921 *
     1922 *      --  pcszAttribType is the attribute type.
     1923 *          It is the string representing the type in the declaration
     1924 *          with whitespace removed.
     1925 *
     1926 *      --  pcszDefault holds the default value. It will be
     1927 *          NULL in the case of "#IMPLIED" or "#REQUIRED" attributes.
     1928 *          You can distinguish these two cases by checking the
     1929 *          fIsRequired parameter, which will be true in the case of
     1930 *          "#REQUIRED" attributes. Attributes which are "#FIXED"
     1931 *          will have also have a TRUE fIsRequired, but they will have
     1932 *          the non-NULL fixed value in the pcszDefault parameter.
    19391933 */
    19401934
     
    19511945 *      Handler prototype:
    19521946 *
    1953  +          void EXPATENTRY EntityDeclHandler(void *userData,
    1954  +                                          const XML_Char *entityName,
    1955  +                                          int is_parameter_entity,
    1956  +                                          const XML_Char *value,
    1957  +                                          int value_length,
    1958  +                                          const XML_Char *base,
    1959  +                                          const XML_Char *systemId,
    1960  +                                          const XML_Char *publicId,
    1961  +                                          const XML_Char *notationName);
     1947 +          void EXPATENTRY EntityDeclHandler(void *pUserData,
     1948 +                                            const XML_Char *pcszEntityName,
     1949 +                                            int fIsParameterEntity,
     1950 +                                            const XML_Char *pcszValue,
     1951 +                                            int iValueLength,
     1952 +                                            const XML_Char *pcszBase,
     1953 +                                            const XML_Char *pcszSystemId,
     1954 +                                            const XML_Char *pcszPublicId,
     1955 +                                            const XML_Char *pcszNotationName);
    19621956 +
    1963  *      The is_parameter_entity argument will be non-zero in the case
     1957 *      The fIsParameterEntity argument will be non-zero in the case
    19641958 *      of parameter entities and zero otherwise.
    19651959 *
    1966  *      For internal entities (<!ENTITY foo "bar">), value will be
    1967  *      non-NULL and systemId, publicId, and notationName will all
    1968  *      be NULL. The value string is not NULL terminated; the length
    1969  *      is provided in the value_length parameter. Do not use
    1970  *      value_length to test for internal entities, since it is legal
     1960 *      For internal entities (<!ENTITY foo "bar">), pcszValue will be
     1961 *      non-NULL and pcszSystemId, pcszPublicId, and pcszNotationName
     1962 *      will all be NULL. The value string is not NULL terminated; the
     1963 *      lengthis provided in the iValueLength parameter. Do not use
     1964 *      iValueLength to test for internal entities, since it is legal
    19711965 *      to have zero-length values. Instead check for whether or not
    1972  *      value is NULL.
    1973  *
    1974  *      The notationName argument will have a non-NULL value only for
    1975  *      unparsed entity declarations.
     1966 *      pcszValue is NULL.
     1967 *
     1968 *      The pcszNotationName argument will have a non-NULL value only
     1969 *      for unparsed entity declarations.
    19761970 */
    19771971
     
    19891983 *      Handler prototype:
    19901984 *
    1991  +          void EXPATENTRY XmlDeclHandler(void           *userData,
    1992  +                                       const XML_Char *version,
    1993  +                                       const XML_Char *encoding,
    1994  +                                       int            standalone);
     1985 +          void EXPATENTRY XmlDeclHandler(void *pUserData,
     1986 +                                         const XML_Char *pcszVersion,
     1987 +                                         const XML_Char *pcszEncoding,
     1988 +                                         int standalone);
    19951989 *
    19961990 *      The way to distinguish is that the version parameter will
     
    20102004/*
    20112005 *@@ XML_SetParamEntityParsing:
    2012  *      this enables parsing of parameter entities, including the
    2013  *      external parameter entity that is the external DTD subset,
    2014  *      according to code. The choices for code are:
     2006 *      this enables parsing of @parameter_entities, including the
     2007 *      external parameter entity that is the external @DTD subset,
     2008 *      according to code.
     2009 *
     2010 *      If parsing of parameter entities is enabled, then references
     2011 *      to external parameter entities (including the external DTD
     2012 *      subset) will be passed to the handler set with
     2013 *      XML_SetExternalEntityRefHandler. The context passed will be 0.
     2014 *
     2015 *      Unlike external general entities, external parameter entities
     2016 *      can only be parsed synchronously. If the external parameter
     2017 *      entity is to be parsed, it must be parsed during the call to
     2018 *      the external entity ref handler: the complete sequence of
     2019 *      XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
     2020 *      XML_ParserFree calls must be made during this call.
     2021 *
     2022 *      After XML_ExternalEntityParserCreate has been called to create
     2023 *      the parser for the external parameter entity (context must be 0
     2024 *      for this call), it is illegal to make any calls on the old parser
     2025 *      until XML_ParserFree has been called on the newly created parser.
     2026 *      If the library has been compiled without support for parameter
     2027 *      entity parsing (ie without XML_DTD being defined), then
     2028 *      XML_SetParamEntityParsing will return 0 if parsing of parameter
     2029 *      entities is requested; otherwise it will return non-zero.
     2030 *
     2031 *      NOTE: The xwphelpers implementation #defines XML_DTD in
     2032 *      include\expat\expat_setup.h, which is included in all expat
     2033 *      files.
     2034 *
     2035 *      The choices for code are:
    20152036 *
    20162037 *      --  XML_PARAM_ENTITY_PARSING_NEVER:
    2017  *          Don't parse parameter entities or the external subset
     2038 *          Don't parse parameter entities or the external subset.
     2039 *          This is the only choice if XML_DTD is not defined.
    20182040 *
    20192041 *      --  XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE:
    2020  *          Parse parameter entites and the external subset unless
     2042 *          Parse parameter entities and the external subset unless
    20212043 *          standalone was set to "yes" in the XML declaration.
    20222044 *
     
    20672089            return 1;
    20682090        positionPtr = bufferPtr;
    2069         errorCode = processor(parser, bufferPtr, parseEndPtr = bufferEnd, 0);
    2070         if (errorCode == XML_ERROR_NONE)
     2091        errorCode = processor(parser,
     2092                              bufferPtr,
     2093                              parseEndPtr = bufferEnd,
     2094                              0);
     2095        if (errorCode == ERROR_EXPAT_NONE)
    20712096            return 1;
    20722097        eventEndPtr = eventPtr;
     
    20842109        if (isFinal)
    20852110        {
    2086             errorCode = processor(parser, s, parseEndPtr = s + len, 0);
    2087             if (errorCode == XML_ERROR_NONE)
     2111            errorCode = processor(parser,
     2112                                  s,
     2113                                  parseEndPtr = s + len,
     2114                                  0);
     2115            if (errorCode == ERROR_EXPAT_NONE)
    20882116                return 1;
    20892117            eventEndPtr = eventPtr;
     
    20922120        }
    20932121        errorCode = processor(parser, s, parseEndPtr = s + len, &end);
    2094         if (errorCode != XML_ERROR_NONE)
     2122        if (errorCode != ERROR_EXPAT_NONE)
    20952123        {
    20962124            eventEndPtr = eventPtr;
     
    21092137                if (!buffer)
    21102138                {
    2111                     errorCode = XML_ERROR_NO_MEMORY;
     2139                    errorCode = ERROR_EXPAT_NO_MEMORY;
    21122140                    eventPtr = eventEndPtr = 0;
    21132141                    processor = errorProcessor;
     
    21472175    errorCode = processor(parser, start, parseEndPtr = bufferEnd,
    21482176                          isFinal ? (const char **)0 : &bufferPtr);
    2149     if (errorCode == XML_ERROR_NONE)
     2177    if (errorCode == ERROR_EXPAT_NONE)
    21502178    {
    21512179        if (!isFinal)
     
    22362264            if (newBuf == 0)
    22372265            {
    2238                 errorCode = XML_ERROR_NO_MEMORY;
     2266                errorCode = ERROR_EXPAT_NO_MEMORY;
    22392267                return 0;
    22402268            }
     
    22892317 */
    22902318
    2291 enum XML_Error XML_GetErrorCode(XML_Parser parser)
     2319XMLERROR XML_GetErrorCode(XML_Parser parser)
    22922320{
    22932321    return errorCode;
     
    23572385 *      returns the line number of the position.
    23582386 *
    2359  *      To be called on parser errors. See XML_GetErrorCode.
     2387 *      Can be called on parser errors. See XML_GetErrorCode.
    23602388 */
    23612389
     
    23752403 *      line, of the position.
    23762404 *
    2377  *      To be called on parser errors. See XML_GetErrorCode.
     2405 *      Can be called on parser errors. See XML_GetErrorCode.
    23782406 */
    23792407
     
    24082436
    24092437/*
    2410  *@@ XML_ErrorString:
    2411  *      returns a string describing the error corresponding to code.
    2412  *      The code should be one of the enums that can be returned from
    2413  *      XML_GetErrorCode.
    2414  */
    2415 
    2416 const XML_LChar* XML_ErrorString(int code)
    2417 {
    2418     static const XML_LChar *message[] =
    2419     {
    2420         0,
    2421         XML_T("out of memory"),
    2422         XML_T("syntax error"),
    2423         XML_T("no element found"),
    2424         XML_T("not well-formed (invalid token)"),
    2425         XML_T("unclosed token"),
    2426         XML_T("unclosed token"),
    2427         XML_T("mismatched tag"),
    2428         XML_T("duplicate attribute"),
    2429         XML_T("junk after document element"),
    2430         XML_T("illegal parameter entity reference"),
    2431         XML_T("undefined entity"),
    2432         XML_T("recursive entity reference"),
    2433         XML_T("asynchronous entity"),
    2434         XML_T("reference to invalid character number"),
    2435         XML_T("reference to binary entity"),
    2436         XML_T("reference to external entity in attribute"),
    2437         XML_T("xml processing instruction not at start of external entity"),
    2438         XML_T("unknown encoding"),
    2439         XML_T("encoding specified in XML declaration is incorrect"),
    2440         XML_T("unclosed CDATA section"),
    2441         XML_T("error in processing external entity reference"),
    2442         XML_T("document is not standalone"),
    2443         XML_T("unexpected parser state - please send a bug report")
    2444     };
    2445 
    2446     if (code > 0 && code < sizeof(message) / sizeof(message[0]))
    2447         return message[code];
    2448     return 0;
    2449 }
    2450 
    2451 /*
    24522438 *@@ XML_ExpatVersion:
    24532439 *      returns the library version string (e.g. "expat_1.95.1").
     
    24592445}
    24602446
    2461 static enum XML_Error contentProcessor(XML_Parser parser,
     2447static XMLERROR contentProcessor(XML_Parser parser,
    24622448                                       const char *start,
    24632449                                       const char *end,
     
    24672453}
    24682454
    2469 static enum XML_Error externalEntityInitProcessor(XML_Parser parser,
     2455static XMLERROR externalEntityInitProcessor(XML_Parser parser,
    24702456                                                  const char *start,
    24712457                                                  const char *end,
    24722458                                                  const char **endPtr)
    24732459{
    2474     enum XML_Error result = initializeEncoding(parser);
    2475 
    2476     if (result != XML_ERROR_NONE)
     2460    XMLERROR result = initializeEncoding(parser);
     2461
     2462    if (result != ERROR_EXPAT_NONE)
    24772463        return result;
    24782464    processor = externalEntityInitProcessor2;
     
    24802466}
    24812467
    2482 static enum XML_Error externalEntityInitProcessor2(XML_Parser parser,
     2468static XMLERROR externalEntityInitProcessor2(XML_Parser parser,
    24832469                                                   const char *start,
    24842470                                                   const char *end,
     
    24972483            {
    24982484                *endPtr = start;
    2499                 return XML_ERROR_NONE;
     2485                return ERROR_EXPAT_NONE;
    25002486            }
    25012487            eventPtr = start;
    2502             return XML_ERROR_UNCLOSED_TOKEN;
     2488            return ERROR_EXPAT_UNCLOSED_TOKEN;
    25032489        case XML_TOK_PARTIAL_CHAR:
    25042490            if (endPtr)
    25052491            {
    25062492                *endPtr = start;
    2507                 return XML_ERROR_NONE;
     2493                return ERROR_EXPAT_NONE;
    25082494            }
    25092495            eventPtr = start;
    2510             return XML_ERROR_PARTIAL_CHAR;
     2496            return ERROR_EXPAT_PARTIAL_CHAR;
    25112497    }
    25122498    processor = externalEntityInitProcessor3;
     
    25142500}
    25152501
    2516 static enum XML_Error externalEntityInitProcessor3(XML_Parser parser,
     2502static XMLERROR externalEntityInitProcessor3(XML_Parser parser,
    25172503                                                   const char *start,
    25182504                                                   const char *end,
     
    25262512        case XML_TOK_XML_DECL:
    25272513            {
    2528                 enum XML_Error result = processXmlDecl(parser, 1, start, next);
    2529 
    2530                 if (result != XML_ERROR_NONE)
     2514                XMLERROR result = processXmlDecl(parser, 1, start, next);
     2515
     2516                if (result != ERROR_EXPAT_NONE)
    25312517                    return result;
    25322518                start = next;
     
    25372523            {
    25382524                *endPtr = start;
    2539                 return XML_ERROR_NONE;
     2525                return ERROR_EXPAT_NONE;
    25402526            }
    25412527            eventPtr = start;
    2542             return XML_ERROR_UNCLOSED_TOKEN;
     2528            return ERROR_EXPAT_UNCLOSED_TOKEN;
    25432529        case XML_TOK_PARTIAL_CHAR:
    25442530            if (endPtr)
    25452531            {
    25462532                *endPtr = start;
    2547                 return XML_ERROR_NONE;
     2533                return ERROR_EXPAT_NONE;
    25482534            }
    25492535            eventPtr = start;
    2550             return XML_ERROR_PARTIAL_CHAR;
     2536            return ERROR_EXPAT_PARTIAL_CHAR;
    25512537    }
    25522538    processor = externalEntityContentProcessor;
     
    25552541}
    25562542
    2557 static enum XML_Error externalEntityContentProcessor(XML_Parser parser,
     2543static XMLERROR externalEntityContentProcessor(XML_Parser parser,
    25582544                                                     const char *start,
    25592545                                                     const char *end,
     
    25632549}
    25642550
    2565 static enum XML_Error
     2551static XMLERROR
    25662552 doContent(XML_Parser parser,
    25672553           int startTagLevel,
     
    25972583                {
    25982584                    *nextPtr = s;
    2599                     return XML_ERROR_NONE;
     2585                    return ERROR_EXPAT_NONE;
    26002586                }
    26012587                *eventEndPP = end;
     
    26092595                    reportDefault(parser, enc, s, end);
    26102596                if (startTagLevel == 0)
    2611                     return XML_ERROR_NO_ELEMENTS;
     2597                    return ERROR_EXPAT_NO_ELEMENTS;
    26122598                if (tagLevel != startTagLevel)
    2613                     return XML_ERROR_ASYNC_ENTITY;
    2614                 return XML_ERROR_NONE;
     2599                    return ERROR_EXPAT_ASYNC_ENTITY;
     2600                return ERROR_EXPAT_NONE;
    26152601            case XML_TOK_NONE:
    26162602                if (nextPtr)
    26172603                {
    26182604                    *nextPtr = s;
    2619                     return XML_ERROR_NONE;
     2605                    return ERROR_EXPAT_NONE;
    26202606                }
    26212607                if (startTagLevel > 0)
    26222608                {
    26232609                    if (tagLevel != startTagLevel)
    2624                         return XML_ERROR_ASYNC_ENTITY;
    2625                     return XML_ERROR_NONE;
    2626                 }
    2627                 return XML_ERROR_NO_ELEMENTS;
     2610                        return ERROR_EXPAT_ASYNC_ENTITY;
     2611                    return ERROR_EXPAT_NONE;
     2612                }
     2613                return ERROR_EXPAT_NO_ELEMENTS;
    26282614            case XML_TOK_INVALID:
    26292615                *eventPP = next;
    2630                 return XML_ERROR_INVALID_TOKEN;
     2616                return ERROR_EXPAT_INVALID_TOKEN;
    26312617            case XML_TOK_PARTIAL:
    26322618                if (nextPtr)
    26332619                {
    26342620                    *nextPtr = s;
    2635                     return XML_ERROR_NONE;
    2636                 }
    2637                 return XML_ERROR_UNCLOSED_TOKEN;
     2621                    return ERROR_EXPAT_NONE;
     2622                }
     2623                return ERROR_EXPAT_UNCLOSED_TOKEN;
    26382624            case XML_TOK_PARTIAL_CHAR:
    26392625                if (nextPtr)
    26402626                {
    26412627                    *nextPtr = s;
    2642                     return XML_ERROR_NONE;
    2643                 }
    2644                 return XML_ERROR_PARTIAL_CHAR;
     2628                    return ERROR_EXPAT_NONE;
     2629                }
     2630                return ERROR_EXPAT_PARTIAL_CHAR;
    26452631            case XML_TOK_ENTITY_REF:
    26462632                {
     
    26632649                                           next - enc->minBytesPerChar);
    26642650                    if (!name)
    2665                         return XML_ERROR_NO_MEMORY;
     2651                        return ERROR_EXPAT_NO_MEMORY;
    26662652                    entity = (ENTITY*)lookup(&dtd.generalEntities, name, 0);
    26672653                    poolDiscard(&dtd.pool);
     
    26692655                    {
    26702656                        if (dtd.complete || dtd.standalone)
    2671                             return XML_ERROR_UNDEFINED_ENTITY;
     2657                            return ERROR_EXPAT_UNDEFINED_ENTITY;
    26722658                        if (defaultHandler)
    26732659                            reportDefault(parser, enc, s, next);
     
    26752661                    }
    26762662                    if (entity->open)
    2677                         return XML_ERROR_RECURSIVE_ENTITY_REF;
     2663                        return ERROR_EXPAT_RECURSIVE_ENTITY_REF;
    26782664                    if (entity->notation)
    2679                         return XML_ERROR_BINARY_ENTITY_REF;
     2665                        return ERROR_EXPAT_BINARY_ENTITY_REF;
    26802666                    if (entity)
    26812667                    {
    26822668                        if (entity->textPtr)
    26832669                        {
    2684                             enum XML_Error result;
     2670                            XMLERROR result;
    26852671                            OPEN_INTERNAL_ENTITY openEntity;
    26862672
     
    27152701                            entity->open = 0;
    27162702                            if (!context)
    2717                                 return XML_ERROR_NO_MEMORY;
     2703                                return ERROR_EXPAT_NO_MEMORY;
    27182704                            if (!externalEntityRefHandler(externalEntityRefHandlerArg,
    27192705                                                          context,
     
    27212707                                                          entity->systemId,
    27222708                                                          entity->publicId))
    2723                                 return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
     2709                                return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING;
    27242710                            poolDiscard(&tempPool);
    27252711                        }
     
    27322718                if (!startElementHandler)
    27332719                {
    2734                     enum XML_Error result = storeAtts(parser, enc, s, 0, 0);
     2720                    XMLERROR result = storeAtts(parser, enc, s, 0, 0);
    27352721
    27362722                    if (result)
     
    27512737                        tag = (TAG*)MALLOC(sizeof(TAG));
    27522738                        if (!tag)
    2753                             return XML_ERROR_NO_MEMORY;
     2739                            return ERROR_EXPAT_NO_MEMORY;
    27542740                        tag->buf = (char*)MALLOC(INIT_TAG_BUF_SIZE);
    27552741                        if (!tag->buf)
    2756                             return XML_ERROR_NO_MEMORY;
     2742                            return ERROR_EXPAT_NO_MEMORY;
    27572743                        tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE;
    27582744                    }
     
    27742760                            tag->buf = (char*)REALLOC(tag->buf, bufSize);
    27752761                            if (!tag->buf)
    2776                                 return XML_ERROR_NO_MEMORY;
     2762                                return ERROR_EXPAT_NO_MEMORY;
    27772763                            tag->bufEnd = tag->buf + bufSize;
    27782764                        }
     
    27832769                    if (startElementHandler)
    27842770                    {
    2785                         enum XML_Error result;
     2771                        XMLERROR result;
    27862772                        XML_Char *toPtr;
    27872773
     
    28052791                            tag->buf = (char*)REALLOC(tag->buf, bufSize);
    28062792                            if (!tag->buf)
    2807                                 return XML_ERROR_NO_MEMORY;
     2793                                return ERROR_EXPAT_NO_MEMORY;
    28082794                            tag->bufEnd = tag->buf + bufSize;
    28092795                            if (nextPtr)
     
    28282814                if (!startElementHandler)
    28292815                {
    2830                     enum XML_Error result = storeAtts(parser, enc, s, 0, 0);
     2816                    XMLERROR result = storeAtts(parser, enc, s, 0, 0);
    28312817
    28322818                    if (result)
     
    28382824                {
    28392825                    const char *rawName = s + enc->minBytesPerChar;
    2840                     enum XML_Error result;
     2826                    XMLERROR result;
    28412827                    BINDING *bindings = 0;
    28422828                    TAG_NAME name;
     
    28452831                                       rawName + XmlNameLength(enc, rawName));
    28462832                    if (!name.str)
    2847                         return XML_ERROR_NO_MEMORY;
     2833                        return ERROR_EXPAT_NO_MEMORY;
    28482834                    poolFinish(&tempPool);
    28492835                    result = storeAtts(parser, enc, s, &name, &bindings);
     
    28792865            case XML_TOK_END_TAG:
    28802866                if (tagLevel == startTagLevel)
    2881                     return XML_ERROR_ASYNC_ENTITY;
     2867                    return ERROR_EXPAT_ASYNC_ENTITY;
    28822868                else
    28832869                {
     
    28952881                    {
    28962882                        *eventPP = rawName;
    2897                         return XML_ERROR_TAG_MISMATCH;
     2883                        return ERROR_EXPAT_TAG_MISMATCH;
    28982884                    }
    28992885                    --tagLevel;
     
    29322918
    29332919                    if (n < 0)
    2934                         return XML_ERROR_BAD_CHAR_REF;
     2920                        return ERROR_EXPAT_BAD_CHAR_REF;
    29352921                    if (characterDataHandler)
    29362922                    {
     
    29442930                break;
    29452931            case XML_TOK_XML_DECL:
    2946                 return XML_ERROR_MISPLACED_XML_PI;
     2932                return ERROR_EXPAT_MISPLACED_XML_PI;
    29472933            case XML_TOK_DATA_NEWLINE:
    29482934                if (characterDataHandler)
     
    29572943            case XML_TOK_CDATA_SECT_OPEN:
    29582944                {
    2959                     enum XML_Error result;
     2945                    XMLERROR result;
    29602946
    29612947                    if (startCdataSectionHandler)
     
    29902976                {
    29912977                    *nextPtr = s;
    2992                     return XML_ERROR_NONE;
     2978                    return ERROR_EXPAT_NONE;
    29932979                }
    29942980                if (characterDataHandler)
     
    30112997                {
    30122998                    *eventPP = end;
    3013                     return XML_ERROR_NO_ELEMENTS;
     2999                    return ERROR_EXPAT_NO_ELEMENTS;
    30143000                }
    30153001                if (tagLevel != startTagLevel)
    30163002                {
    30173003                    *eventPP = end;
    3018                     return XML_ERROR_ASYNC_ENTITY;
    3019                 }
    3020                 return XML_ERROR_NONE;
     3004                    return ERROR_EXPAT_ASYNC_ENTITY;
     3005                }
     3006                return ERROR_EXPAT_NONE;
    30213007            case XML_TOK_DATA_CHARS:
    30223008                if (characterDataHandler)
     
    30463032            case XML_TOK_PI:
    30473033                if (!reportProcessingInstruction(parser, enc, s, next))
    3048                     return XML_ERROR_NO_MEMORY;
     3034                    return ERROR_EXPAT_NO_MEMORY;
    30493035                break;
    30503036            case XML_TOK_COMMENT:
    30513037                if (!reportComment(parser, enc, s, next))
    3052                     return XML_ERROR_NO_MEMORY;
     3038                    return ERROR_EXPAT_NO_MEMORY;
    30533039                break;
    30543040            default:
     
    30653051 * otherwise just check the attributes for well-formedness. */
    30663052
    3067 static enum XML_Error storeAtts(XML_Parser parser,
     3053static XMLERROR storeAtts(XML_Parser parser,
    30683054                                const ENCODING * enc,
    30693055                                const char *attStr,
     
    30893075            tagNamePtr->str = poolCopyString(&dtd.pool, tagNamePtr->str);
    30903076            if (!tagNamePtr->str)
    3091                 return XML_ERROR_NO_MEMORY;
     3077                return ERROR_EXPAT_NO_MEMORY;
    30923078            elementType = (ELEMENT_TYPE*)lookup(&dtd.elementTypes, tagNamePtr->str, sizeof(ELEMENT_TYPE));
    30933079            if (!elementType)
    3094                 return XML_ERROR_NO_MEMORY;
     3080                return ERROR_EXPAT_NO_MEMORY;
    30953081            if (ns && !setElementTypePrefix(parser, elementType))
    3096                 return XML_ERROR_NO_MEMORY;
     3082                return ERROR_EXPAT_NO_MEMORY;
    30973083        }
    30983084        nDefaultAtts = elementType->nDefaultAtts;
     
    31073093        atts = (PATTRIBUTE)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE));
    31083094        if (!atts)
    3109             return XML_ERROR_NO_MEMORY;
     3095            return ERROR_EXPAT_NO_MEMORY;
    31103096        if (n > oldAttsSize)
    31113097            XmlGetAttributes(enc, attStr, n, atts);
     
    31203106
    31213107        if (!attId)
    3122             return XML_ERROR_NO_MEMORY;
     3108            return ERROR_EXPAT_NO_MEMORY;
    31233109        /* detect duplicate attributes */
    31243110        if ((attId->name)[-1])
     
    31263112            if (enc == encoding)
    31273113                eventPtr = atts[i].name;
    3128             return XML_ERROR_DUPLICATE_ATTRIBUTE;
     3114            return ERROR_EXPAT_DUPLICATE_ATTRIBUTE;
    31293115        }
    31303116        (attId->name)[-1] = 1;
     
    31323118        if (!atts[i].normalized)
    31333119        {
    3134             enum XML_Error result;
     3120            XMLERROR result;
    31353121            int isCdata = 1;
    31363122
     
    31693155            appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, atts[i].valueEnd);
    31703156            if (appAtts[attIndex] == 0)
    3171                 return XML_ERROR_NO_MEMORY;
     3157                return ERROR_EXPAT_NO_MEMORY;
    31723158            poolFinish(&tempPool);
    31733159        }
     
    31793165                /* deal with namespace declarations here */
    31803166                if (!addBinding(parser, attId->prefix, attId, appAtts[attIndex], bindingsPtr))
    3181                     return XML_ERROR_NO_MEMORY;
     3167                    return ERROR_EXPAT_NO_MEMORY;
    31823168                --attIndex;
    31833169            }
     
    32213207                    {
    32223208                        if (!addBinding(parser, da->id->prefix, da->id, da->value, bindingsPtr))
    3223                             return XML_ERROR_NO_MEMORY;
     3209                            return ERROR_EXPAT_NO_MEMORY;
    32243210                    }
    32253211                    else
     
    32623248                    {
    32633249                        if (!poolAppendChar(&tempPool, b->uri[j]))
    3264                             return XML_ERROR_NO_MEMORY;
     3250                            return ERROR_EXPAT_NO_MEMORY;
    32653251                    }
    32663252                    while (*s++ != ':')
     
    32693255                    {
    32703256                        if (!poolAppendChar(&tempPool, *s))
    3271                             return XML_ERROR_NO_MEMORY;
     3257                            return ERROR_EXPAT_NO_MEMORY;
    32723258                    }
    32733259                    while (*s++);
     
    32793265                        {
    32803266                            if (!poolAppendChar(&tempPool, *s))
    3281                                 return XML_ERROR_NO_MEMORY;
     3267                                return ERROR_EXPAT_NO_MEMORY;
    32823268                        }
    32833269                        while (*s++);
     
    32983284        ((XML_Char*)(appAtts[i]))[-1] = 0;
    32993285    if (!tagNamePtr)
    3300         return XML_ERROR_NONE;
     3286        return ERROR_EXPAT_NONE;
    33013287    for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding)
    33023288        binding->attId->name[-1] = 0;
     
    33063292        binding = elementType->prefix->binding;
    33073293        if (!binding)
    3308             return XML_ERROR_NONE;
     3294            return ERROR_EXPAT_NONE;
    33093295        localPart = tagNamePtr->str;
    33103296        while (*localPart++ != XML_T(':'))
     
    33173303    }
    33183304    else
    3319         return XML_ERROR_NONE;
     3305        return ERROR_EXPAT_NONE;
    33203306    tagNamePtr->localPart = localPart;
    33213307    tagNamePtr->uriLen = binding->uriLen;
     
    33293315
    33303316        if (!uri)
    3331             return XML_ERROR_NO_MEMORY;
     3317            return ERROR_EXPAT_NO_MEMORY;
    33323318        binding->uriAlloc = n + EXPAND_SPARE;
    33333319        memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char));
     
    33403326    memcpy(binding->uri + binding->uriLen, localPart, i * sizeof(XML_Char));
    33413327    tagNamePtr->str = binding->uri;
    3342     return XML_ERROR_NONE;
     3328    return ERROR_EXPAT_NONE;
    33433329}
    33443330
     
    33993385 * the whole file is parsed with one call. */
    34003386
    3401 static enum XML_Error cdataSectionProcessor(XML_Parser parser,
     3387static XMLERROR cdataSectionProcessor(XML_Parser parser,
    34023388                                     const char *start,
    34033389                                     const char *end,
    34043390                                     const char **endPtr)
    34053391{
    3406     enum XML_Error result = doCdataSection(parser, encoding, &start, end, endPtr);
     3392    XMLERROR result = doCdataSection(parser, encoding, &start, end, endPtr);
    34073393
    34083394    if (start)
     
    34173403 * the section is not yet closed. */
    34183404
    3419 static enum XML_Error doCdataSection(XML_Parser parser,
     3405static XMLERROR doCdataSection(XML_Parser parser,
    34203406                              const ENCODING * enc,
    34213407                              const char **startPtr,
     
    34593445                    reportDefault(parser, enc, s, next);
    34603446                *startPtr = next;
    3461                 return XML_ERROR_NONE;
     3447                return ERROR_EXPAT_NONE;
    34623448            case XML_TOK_DATA_NEWLINE:
    34633449                if (characterDataHandler)
     
    34973483            case XML_TOK_INVALID:
    34983484                *eventPP = next;
    3499                 return XML_ERROR_INVALID_TOKEN;
     3485                return ERROR_EXPAT_INVALID_TOKEN;
    35003486            case XML_TOK_PARTIAL_CHAR:
    35013487                if (nextPtr)
    35023488                {
    35033489                    *nextPtr = s;
    3504                     return XML_ERROR_NONE;
    3505                 }
    3506                 return XML_ERROR_PARTIAL_CHAR;
     3490                    return ERROR_EXPAT_NONE;
     3491                }
     3492                return ERROR_EXPAT_PARTIAL_CHAR;
    35073493            case XML_TOK_PARTIAL:
    35083494            case XML_TOK_NONE:
     
    35103496                {
    35113497                    *nextPtr = s;
    3512                     return XML_ERROR_NONE;
    3513                 }
    3514                 return XML_ERROR_UNCLOSED_CDATA_SECTION;
     3498                    return ERROR_EXPAT_NONE;
     3499                }
     3500                return ERROR_EXPAT_UNCLOSED_CDATA_SECTION;
    35153501            default:
    35163502                *eventPP = next;
    3517                 return XML_ERROR_UNEXPECTED_STATE;
     3503                return ERROR_EXPAT_UNEXPECTED_STATE;
    35183504        }
    35193505        *eventPP = s = next;
     
    35273513 * the whole file is parsed with one call. */
    35283514
    3529 static enum XML_Error ignoreSectionProcessor(XML_Parser parser,
     3515static XMLERROR ignoreSectionProcessor(XML_Parser parser,
    35303516                                      const char *start,
    35313517                                      const char *end,
    35323518                                      const char **endPtr)
    35333519{
    3534     enum XML_Error result = doIgnoreSection(parser, encoding, &start, end, endPtr);
     3520    XMLERROR result = doIgnoreSection(parser, encoding, &start, end, endPtr);
    35353521
    35363522    if (start)
     
    35453531 * the section is not yet closed. */
    35463532
    3547 static enum XML_Error doIgnoreSection(XML_Parser parser,
     3533static XMLERROR doIgnoreSection(XML_Parser parser,
    35483534                               const ENCODING * enc,
    35493535                               const char **startPtr,
     
    35783564                reportDefault(parser, enc, s, next);
    35793565            *startPtr = next;
    3580             return XML_ERROR_NONE;
     3566            return ERROR_EXPAT_NONE;
    35813567        case XML_TOK_INVALID:
    35823568            *eventPP = next;
    3583             return XML_ERROR_INVALID_TOKEN;
     3569            return ERROR_EXPAT_INVALID_TOKEN;
    35843570        case XML_TOK_PARTIAL_CHAR:
    35853571            if (nextPtr)
    35863572            {
    35873573                *nextPtr = s;
    3588                 return XML_ERROR_NONE;
     3574                return ERROR_EXPAT_NONE;
    35893575            }
    3590             return XML_ERROR_PARTIAL_CHAR;
     3576            return ERROR_EXPAT_PARTIAL_CHAR;
    35913577        case XML_TOK_PARTIAL:
    35923578        case XML_TOK_NONE:
     
    35943580            {
    35953581                *nextPtr = s;
    3596                 return XML_ERROR_NONE;
     3582                return ERROR_EXPAT_NONE;
    35973583            }
    3598             return XML_ERROR_SYNTAX;    /* XML_ERROR_UNCLOSED_IGNORE_SECTION */
     3584            return ERROR_EXPAT_SYNTAX;    /* ERROR_EXPAT_UNCLOSED_IGNORE_SECTION */
    35993585        default:
    36003586            *eventPP = next;
    3601             return XML_ERROR_UNEXPECTED_STATE;
     3587            return ERROR_EXPAT_UNEXPECTED_STATE;
    36023588    }
    36033589    /* not reached */
     
    36063592#endif /* XML_DTD */
    36073593
    3608 static enum XML_Error  initializeEncoding(XML_Parser parser)
     3594static XMLERROR  initializeEncoding(XML_Parser parser)
    36093595{
    36103596    const char *s;
     
    36363622#endif
    36373623    if ((ns ? XmlInitEncodingNS : XmlInitEncoding) (&initEncoding, &encoding, s))
    3638         return XML_ERROR_NONE;
     3624        return ERROR_EXPAT_NONE;
    36393625    return handleUnknownEncoding(parser, protocolEncodingName);
    36403626}
    36413627
    3642 static enum XML_Error  processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
     3628static XMLERROR  processXmlDecl(XML_Parser parser, int isGeneralTextEntity,
    36433629                const char *s, const char *next)
    36443630{
     
    36633649                              &newEncoding,
    36643650                              &standalone))
    3665         return XML_ERROR_SYNTAX;
     3651        return ERROR_EXPAT_SYNTAX;
    36663652    if (!isGeneralTextEntity && standalone == 1)
    36673653    {
     
    36823668                                     + XmlNameLength(encoding, encodingName));
    36833669            if (!storedEncName)
    3684                 return XML_ERROR_NO_MEMORY;
     3670                return ERROR_EXPAT_NO_MEMORY;
    36853671            poolFinish(&temp2Pool);
    36863672        }
     
    36923678                                      versionend - encoding->minBytesPerChar);
    36933679            if (!storedversion)
    3694                 return XML_ERROR_NO_MEMORY;
     3680                return ERROR_EXPAT_NO_MEMORY;
    36953681        }
    36963682        xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone);
     
    37053691            {
    37063692                eventPtr = encodingName;
    3707                 return XML_ERROR_INCORRECT_ENCODING;
     3693                return ERROR_EXPAT_INCORRECT_ENCODING;
    37083694            }
    37093695            encoding = newEncoding;
     
    37113697        else if (encodingName)
    37123698        {
    3713             enum XML_Error result;
     3699            XMLERROR result;
    37143700
    37153701            if (!storedEncName)
     
    37213707                                     + XmlNameLength(encoding, encodingName));
    37223708                if (!storedEncName)
    3723                     return XML_ERROR_NO_MEMORY;
     3709                    return ERROR_EXPAT_NO_MEMORY;
    37243710            }
    37253711            result = handleUnknownEncoding(parser, storedEncName);
    37263712            poolClear(&tempPool);
    3727             if (result == XML_ERROR_UNKNOWN_ENCODING)
     3713            if (result == ERROR_EXPAT_UNKNOWN_ENCODING)
    37283714                eventPtr = encodingName;
    37293715            return result;
     
    37343720        poolClear(&temp2Pool);
    37353721
    3736     return XML_ERROR_NONE;
    3737 }
    3738 
    3739 static enum XML_Error handleUnknownEncoding(XML_Parser parser,
     3722    return ERROR_EXPAT_NONE;
     3723}
     3724
     3725static XMLERROR handleUnknownEncoding(XML_Parser parser,
    37403726                                            const XML_Char* encodingName)
    37413727{
     
    37613747                if (info.release)
    37623748                    info.release(info.data);
    3763                 return XML_ERROR_NO_MEMORY;
     3749                return ERROR_EXPAT_NO_MEMORY;
    37643750            }
    37653751            enc = (ns
     
    37743760                unknownEncodingRelease = info.release;
    37753761                encoding = enc;
    3776                 return XML_ERROR_NONE;
     3762                return ERROR_EXPAT_NONE;
    37773763            }
    37783764        }
     
    37803766            info.release(info.data);
    37813767    }
    3782     return XML_ERROR_UNKNOWN_ENCODING;
    3783 }
    3784 
    3785 static enum XML_Error prologInitProcessor(XML_Parser parser,
     3768    return ERROR_EXPAT_UNKNOWN_ENCODING;
     3769}
     3770
     3771static XMLERROR prologInitProcessor(XML_Parser parser,
    37863772                     const char *s,
    37873773                     const char *end,
    37883774                     const char **nextPtr)
    37893775{
    3790     enum XML_Error result = initializeEncoding(parser);
    3791 
    3792     if (result != XML_ERROR_NONE)
     3776    XMLERROR result = initializeEncoding(parser);
     3777
     3778    if (result != ERROR_EXPAT_NONE)
    37933779        return result;
    37943780    processor = prologProcessor;
     
    37963782}
    37973783
    3798 static enum XML_Error prologProcessor(XML_Parser parser,
     3784static XMLERROR prologProcessor(XML_Parser parser,
    37993785                 const char *s,
    38003786                 const char *end,
     
    38073793}
    38083794
    3809 static enum XML_Error doProlog(XML_Parser parser,
     3795static XMLERROR doProlog(XML_Parser parser,
    38103796          const ENCODING * enc,
    38113797          const char *s,
     
    38463832            {
    38473833                *nextPtr = s;
    3848                 return XML_ERROR_NONE;
     3834                return ERROR_EXPAT_NONE;
    38493835            }
    38503836            switch (tok)
     
    38523838                case XML_TOK_INVALID:
    38533839                    *eventPP = next;
    3854                     return XML_ERROR_INVALID_TOKEN;
     3840                    return ERROR_EXPAT_INVALID_TOKEN;
    38553841                case XML_TOK_PARTIAL:
    3856                     return XML_ERROR_UNCLOSED_TOKEN;
     3842                    return ERROR_EXPAT_UNCLOSED_TOKEN;
    38573843                case XML_TOK_PARTIAL_CHAR:
    3858                     return XML_ERROR_PARTIAL_CHAR;
     3844                    return ERROR_EXPAT_PARTIAL_CHAR;
    38593845                case XML_TOK_NONE:
    38603846#ifdef XML_DTD
    38613847                    if (enc != encoding)
    3862                         return XML_ERROR_NONE;
     3848                        return ERROR_EXPAT_NONE;
    38633849                    if (parentParser)
    38643850                    {
    38653851                        if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc)
    38663852                            == XML_ROLE_ERROR)
    3867                             return XML_ERROR_SYNTAX;
     3853                            return ERROR_EXPAT_SYNTAX;
    38683854                        hadExternalDoctype = 0;
    3869                         return XML_ERROR_NONE;
     3855                        return ERROR_EXPAT_NONE;
    38703856                    }
    38713857#endif /* XML_DTD */
    3872                     return XML_ERROR_NO_ELEMENTS;
     3858                    return ERROR_EXPAT_NO_ELEMENTS;
    38733859                default:
    38743860                    tok = -tok;
     
    38823868            case XML_ROLE_XML_DECL:
    38833869                {
    3884                     enum XML_Error result = processXmlDecl(parser, 0, s, next);
    3885 
    3886                     if (result != XML_ERROR_NONE)
     3870                    XMLERROR result = processXmlDecl(parser, 0, s, next);
     3871
     3872                    if (result != ERROR_EXPAT_NONE)
    38873873                        return result;
    38883874                    enc = encoding;
     
    38943880                    doctypeName = poolStoreString(&tempPool, enc, s, next);
    38953881                    if (!doctypeName)
    3896                         return XML_ERROR_NO_MEMORY;
     3882                        return ERROR_EXPAT_NO_MEMORY;
    38973883                    poolFinish(&tempPool);
    38983884                    doctypeSysid = 0;
     
    39123898            case XML_ROLE_TEXT_DECL:
    39133899                {
    3914                     enum XML_Error result = processXmlDecl(parser, 1, s, next);
    3915 
    3916                     if (result != XML_ERROR_NONE)
     3900                    XMLERROR result = processXmlDecl(parser, 1, s, next);
     3901
     3902                    if (result != ERROR_EXPAT_NONE)
    39173903                        return result;
    39183904                    enc = encoding;
     
    39253911                    doctypePubid = poolStoreString(&tempPool, enc, s + 1, next - 1);
    39263912                    if (!doctypePubid)
    3927                         return XML_ERROR_NO_MEMORY;
     3913                        return ERROR_EXPAT_NO_MEMORY;
    39283914                    poolFinish(&tempPool);
    39293915                }
     
    39333919                                               sizeof(ENTITY));
    39343920                if (!declEntity)
    3935                     return XML_ERROR_NO_MEMORY;
     3921                    return ERROR_EXPAT_NO_MEMORY;
    39363922#endif /* XML_DTD */
    39373923                /* fall through */
    39383924            case XML_ROLE_ENTITY_PUBLIC_ID:
    39393925                if (!XmlIsPublicId(enc, s, next, eventPP))
    3940                     return XML_ERROR_SYNTAX;
     3926                    return ERROR_EXPAT_SYNTAX;
    39413927                if (declEntity)
    39423928                {
     
    39473933
    39483934                    if (!tem)
    3949                         return XML_ERROR_NO_MEMORY;
     3935                        return ERROR_EXPAT_NO_MEMORY;
    39503936                    normalizePublicId(tem);
    39513937                    declEntity->publicId = tem;
     
    39753961                                                      entity->systemId,
    39763962                                                      entity->publicId))
    3977                             return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
     3963                            return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING;
    39783964                    }
    39793965#endif /* XML_DTD */
     
    39823968                        && notStandaloneHandler
    39833969                        && !notStandaloneHandler(handlerArg))
    3984                         return XML_ERROR_NOT_STANDALONE;
     3970                        return ERROR_EXPAT_NOT_STANDALONE;
    39853971                }
    39863972                if (endDoctypeDeclHandler)
     
    39933979                declElementType = getElementType(parser, enc, s, next);
    39943980                if (!declElementType)
    3995                     return XML_ERROR_NO_MEMORY;
     3981                    return ERROR_EXPAT_NO_MEMORY;
    39963982                break;
    39973983            case XML_ROLE_ATTRIBUTE_NAME:
    39983984                declAttributeId = getAttributeId(parser, enc, s, next);
    39993985                if (!declAttributeId)
    4000                     return XML_ERROR_NO_MEMORY;
     3986                    return ERROR_EXPAT_NO_MEMORY;
    40013987                declAttributeIsCdata = 0;
    40023988                declAttributeType = 0;
     
    40474033                    }
    40484034                    if (!poolAppendString(&tempPool, prefix))
    4049                         return XML_ERROR_NO_MEMORY;
     4035                        return ERROR_EXPAT_NO_MEMORY;
    40504036                    if (!poolAppend(&tempPool, enc, s, next))
    4051                         return XML_ERROR_NO_MEMORY;
     4037                        return ERROR_EXPAT_NO_MEMORY;
    40524038                    declAttributeType = tempPool.start;
    40534039                }
     
    40594045                                   declAttributeIsCdata, declAttributeIsId, 0,
    40604046                                        parser))
    4061                     return XML_ERROR_NO_MEMORY;
     4047                    return ERROR_EXPAT_NO_MEMORY;
    40624048                if (attlistDeclHandler && declAttributeType)
    40634049                {
     
    40684054                        if (!poolAppendChar(&tempPool, ')')
    40694055                            || !poolAppendChar(&tempPool, '\0'))
    4070                             return XML_ERROR_NO_MEMORY;
     4056                            return ERROR_EXPAT_NO_MEMORY;
    40714057                        declAttributeType = tempPool.start;
    40724058                        poolFinish(&tempPool);
     
    40834069                {
    40844070                    const XML_Char *attVal;
    4085                     enum XML_Error result
     4071                    XMLERROR result
    40864072                    = storeAttributeValue(parser, enc, declAttributeIsCdata,
    40874073                                          s + enc->minBytesPerChar,
     
    40964082                    /* ID attributes aren't allowed to have a default */
    40974083                        && !defineAttribute(declElementType, declAttributeId, declAttributeIsCdata, 0, attVal, parser))
    4098                         return XML_ERROR_NO_MEMORY;
     4084                        return ERROR_EXPAT_NO_MEMORY;
    40994085                    if (attlistDeclHandler && declAttributeType)
    41004086                    {
     
    41054091                            if (!poolAppendChar(&tempPool, ')')
    41064092                                || !poolAppendChar(&tempPool, '\0'))
    4107                                 return XML_ERROR_NO_MEMORY;
     4093                                return ERROR_EXPAT_NO_MEMORY;
    41084094                            declAttributeType = tempPool.start;
    41094095                            poolFinish(&tempPool);
     
    41204106            case XML_ROLE_ENTITY_VALUE:
    41214107                {
    4122                     enum XML_Error result = storeEntityValue(parser, enc,
     4108                    XMLERROR result = storeEntityValue(parser, enc,
    41234109                                                     s + enc->minBytesPerChar,
    41244110                                                 next - enc->minBytesPerChar);
     
    41424128                    else
    41434129                        poolDiscard(&dtd.pool);
    4144                     if (result != XML_ERROR_NONE)
     4130                    if (result != ERROR_EXPAT_NONE)
    41454131                        return result;
    41464132                }
     
    41514137                    doctypeSysid = poolStoreString(&tempPool, enc, s + 1, next - 1);
    41524138                    if (!doctypeSysid)
    4153                         return XML_ERROR_NO_MEMORY;
     4139                        return ERROR_EXPAT_NO_MEMORY;
    41544140                    poolFinish(&tempPool);
    41554141                }
     
    41604146                    && notStandaloneHandler
    41614147                    && !notStandaloneHandler(handlerArg))
    4162                     return XML_ERROR_NOT_STANDALONE;
     4148                    return ERROR_EXPAT_NOT_STANDALONE;
    41634149                hadExternalDoctype = 1;
    41644150#ifndef XML_DTD
     
    41724158                    declEntity->publicId = 0;
    41734159                    if (!declEntity)
    4174                         return XML_ERROR_NO_MEMORY;
     4160                        return ERROR_EXPAT_NO_MEMORY;
    41754161                }
    41764162                /* fall through */
     
    41834169                                                 next - enc->minBytesPerChar);
    41844170                    if (!declEntity->systemId)
    4185                         return XML_ERROR_NO_MEMORY;
     4171                        return ERROR_EXPAT_NO_MEMORY;
    41864172                    declEntity->base = curBase;
    41874173                    poolFinish(&dtd.pool);
     
    42064192                    declEntity->notation = poolStoreString(&dtd.pool, enc, s, next);
    42074193                    if (!declEntity->notation)
    4208                         return XML_ERROR_NO_MEMORY;
     4194                        return ERROR_EXPAT_NO_MEMORY;
    42094195                    poolFinish(&dtd.pool);
    42104196                    if (unparsedEntityDeclHandler)
     
    42424228                    name = poolStoreString(&dtd.pool, enc, s, next);
    42434229                    if (!name)
    4244                         return XML_ERROR_NO_MEMORY;
     4230                        return ERROR_EXPAT_NO_MEMORY;
    42454231                    if (dtd.complete)
    42464232                    {
    42474233                        declEntity = (ENTITY*)lookup(&dtd.generalEntities, name, sizeof(ENTITY));
    42484234                        if (!declEntity)
    4249                             return XML_ERROR_NO_MEMORY;
     4235                            return ERROR_EXPAT_NO_MEMORY;
    42504236                        if (declEntity->name != name)
    42514237                        {
     
    42744260
    42754261                    if (!name)
    4276                         return XML_ERROR_NO_MEMORY;
     4262                        return ERROR_EXPAT_NO_MEMORY;
    42774263                    declEntity = (ENTITY*)lookup(&dtd.paramEntities,
    42784264                                                   name, sizeof(ENTITY));
    42794265                    if (!declEntity)
    4280                         return XML_ERROR_NO_MEMORY;
     4266                        return ERROR_EXPAT_NO_MEMORY;
    42814267                    if (declEntity->name != name)
    42824268                    {
     
    43024288                    declNotationName = poolStoreString(&tempPool, enc, s, next);
    43034289                    if (!declNotationName)
    4304                         return XML_ERROR_NO_MEMORY;
     4290                        return ERROR_EXPAT_NO_MEMORY;
    43054291                    poolFinish(&tempPool);
    43064292                }
     
    43084294            case XML_ROLE_NOTATION_PUBLIC_ID:
    43094295                if (!XmlIsPublicId(enc, s, next, eventPP))
    4310                     return XML_ERROR_SYNTAX;
     4296                    return ERROR_EXPAT_SYNTAX;
    43114297                if (declNotationName)
    43124298                {
     
    43174303
    43184304                    if (!tem)
    4319                         return XML_ERROR_NO_MEMORY;
     4305                        return ERROR_EXPAT_NO_MEMORY;
    43204306                    normalizePublicId(tem);
    43214307                    declNotationPublicId = tem;
     
    43324318
    43334319                    if (!systemId)
    4334                         return XML_ERROR_NO_MEMORY;
     4320                        return ERROR_EXPAT_NO_MEMORY;
    43354321                    *eventEndPP = s;
    43364322                    notationDeclHandler(handlerArg,
     
    43584344                {
    43594345                    case XML_TOK_PARAM_ENTITY_REF:
    4360                         return XML_ERROR_PARAM_ENTITY_REF;
     4346                        return ERROR_EXPAT_PARAM_ENTITY_REF;
    43614347                    case XML_TOK_XML_DECL:
    4362                         return XML_ERROR_MISPLACED_XML_PI;
     4348                        return ERROR_EXPAT_MISPLACED_XML_PI;
    43634349                    default:
    4364                         return XML_ERROR_SYNTAX;
     4350                        return ERROR_EXPAT_SYNTAX;
    43654351                }
    43664352#ifdef XML_DTD
    43674353            case XML_ROLE_IGNORE_SECT:
    43684354                {
    4369                     enum XML_Error result;
     4355                    XMLERROR result;
    43704356
    43714357                    if (defaultHandler)
     
    43924378                        groupConnector = (char*)MALLOC(groupSize = 32);
    43934379                    if (!groupConnector)
    4394                         return XML_ERROR_NO_MEMORY;
     4380                        return ERROR_EXPAT_NO_MEMORY;
    43954381                }
    43964382                groupConnector[prologState.level] = 0;
     
    44004386
    44014387                    if (myindex < 0)
    4402                         return XML_ERROR_NO_MEMORY;
     4388                        return ERROR_EXPAT_NO_MEMORY;
    44034389                    dtd.scaffIndex[dtd.scaffLevel] = myindex;
    44044390                    dtd.scaffLevel++;
     
    44084394            case XML_ROLE_GROUP_SEQUENCE:
    44094395                if (groupConnector[prologState.level] == '|')
    4410                     return XML_ERROR_SYNTAX;
     4396                    return ERROR_EXPAT_SYNTAX;
    44114397                groupConnector[prologState.level] = ',';
    44124398                break;
    44134399            case XML_ROLE_GROUP_CHOICE:
    44144400                if (groupConnector[prologState.level] == ',')
    4415                     return XML_ERROR_SYNTAX;
     4401                    return ERROR_EXPAT_SYNTAX;
    44164402                if (dtd.in_eldecl
    44174403                    && !groupConnector[prologState.level]
     
    44364422                                           next - enc->minBytesPerChar);
    44374423                    if (!name)
    4438                         return XML_ERROR_NO_MEMORY;
     4424                        return ERROR_EXPAT_NO_MEMORY;
    44394425                    entity = (ENTITY*)lookup(&dtd.paramEntities, name, 0);
    44404426                    poolDiscard(&dtd.pool);
     
    44424428                    {
    44434429                        /* FIXME what to do if !dtd.complete? */
    4444                         return XML_ERROR_UNDEFINED_ENTITY;
     4430                        return ERROR_EXPAT_UNDEFINED_ENTITY;
    44454431                    }
    44464432                    if (entity->open)
    4447                         return XML_ERROR_RECURSIVE_ENTITY_REF;
     4433                        return ERROR_EXPAT_RECURSIVE_ENTITY_REF;
    44484434                    if (entity->textPtr)
    44494435                    {
    4450                         enum XML_Error result;
     4436                        XMLERROR result;
    44514437
    44524438                        result = processInternalParamEntity(parser, entity);
    4453                         if (result != XML_ERROR_NONE)
     4439                        if (result != ERROR_EXPAT_NONE)
    44544440                            return result;
    44554441                        break;
    44564442                    }
    44574443                    if (role == XML_ROLE_INNER_PARAM_ENTITY_REF)
    4458                         return XML_ERROR_PARAM_ENTITY_REF;
     4444                        return ERROR_EXPAT_PARAM_ENTITY_REF;
    44594445                    if (externalEntityRefHandler)
    44604446                    {
     
    44684454                        {
    44694455                            entity->open = 0;
    4470                             return XML_ERROR_EXTERNAL_ENTITY_HANDLING;
     4456                            return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING;
    44714457                        }
    44724458                        entity->open = 0;
     
    44794465                    && notStandaloneHandler
    44804466                    && !notStandaloneHandler(handlerArg))
    4481                     return XML_ERROR_NOT_STANDALONE;
     4467                    return ERROR_EXPAT_NOT_STANDALONE;
    44824468                dtd.complete = 0;
    44834469                if (defaultHandler)
     
    44924478                    declElementType = getElementType(parser, enc, s, next);
    44934479                    if (!declElementType)
    4494                         return XML_ERROR_NO_MEMORY;
     4480                        return ERROR_EXPAT_NO_MEMORY;
    44954481                    dtd.scaffLevel = 0;
    44964482                    dtd.scaffCount = 0;
     
    45054491                    if (elementDeclHandler)
    45064492                    {
    4507                         XML_Content *content = (XML_Content*)MALLOC(sizeof(XML_Content));
     4493                        XMLCONTENT *content = (XMLCONTENT*)MALLOC(sizeof(XMLCONTENT));
    45084494
    45094495                        if (!content)
    4510                             return XML_ERROR_NO_MEMORY;
     4496                            return ERROR_EXPAT_NO_MEMORY;
    45114497                        content->quant = XML_CQUANT_NONE;
    45124498                        content->name = 0;
     
    45494535
    45504536                    if (myindex < 0)
    4551                         return XML_ERROR_NO_MEMORY;
     4537                        return ERROR_EXPAT_NO_MEMORY;
    45524538                    dtd.scaffold[myindex].type = XML_CTYPE_NAME;
    45534539                    dtd.scaffold[myindex].quant = quant;
    45544540                    el = getElementType(parser, enc, s, nxt);
    45554541                    if (!el)
    4556                         return XML_ERROR_NO_MEMORY;
     4542                        return ERROR_EXPAT_NO_MEMORY;
    45574543                    dtd.scaffold[myindex].name = el->name;
    45584544                    dtd.contentStringLen += nxt - s + 1;
     
    45804566                        if (elementDeclHandler)
    45814567                        {
    4582                             XML_Content *model = build_model(parser);
     4568                            XMLCONTENT *model = build_model(parser);
    45834569
    45844570                            if (!model)
    4585                                 return XML_ERROR_NO_MEMORY;
     4571                                return ERROR_EXPAT_NO_MEMORY;
    45864572                            *eventEndPP = s;
    45874573                            elementDeclHandler(handlerArg, declElementType->name, model);
     
    45994585                    case XML_TOK_PI:
    46004586                        if (!reportProcessingInstruction(parser, enc, s, next))
    4601                             return XML_ERROR_NO_MEMORY;
     4587                            return ERROR_EXPAT_NO_MEMORY;
    46024588                        break;
    46034589                    case XML_TOK_COMMENT:
    46044590                        if (!reportComment(parser, enc, s, next))
    4605                             return XML_ERROR_NO_MEMORY;
     4591                            return ERROR_EXPAT_NO_MEMORY;
    46064592                        break;
    46074593                }
     
    46344620}
    46354621
    4636 static enum XML_Error epilogProcessor(XML_Parser parser,
     4622static XMLERROR epilogProcessor(XML_Parser parser,
    46374623                               const char *s,
    46384624                               const char *end,
     
    46594645                if (nextPtr)
    46604646                    *nextPtr = end;
    4661                 return XML_ERROR_NONE;
     4647                return ERROR_EXPAT_NONE;
    46624648            case XML_TOK_PROLOG_S:
    46634649                if (defaultHandler)
     
    46664652            case XML_TOK_PI:
    46674653                if (!reportProcessingInstruction(parser, encoding, s, next))
    4668                     return XML_ERROR_NO_MEMORY;
     4654                    return ERROR_EXPAT_NO_MEMORY;
    46694655                break;
    46704656            case XML_TOK_COMMENT:
    46714657                if (!reportComment(parser, encoding, s, next))
    4672                     return XML_ERROR_NO_MEMORY;
     4658                    return ERROR_EXPAT_NO_MEMORY;
    46734659                break;
    46744660            case XML_TOK_INVALID:
    46754661                eventPtr = next;
    4676                 return XML_ERROR_INVALID_TOKEN;
     4662                return ERROR_EXPAT_INVALID_TOKEN;
    46774663            case XML_TOK_PARTIAL:
    46784664                if (nextPtr)
    46794665                {
    46804666                    *nextPtr = s;
    4681                     return XML_ERROR_NONE;
    4682                 }
    4683                 return XML_ERROR_UNCLOSED_TOKEN;
     4667                    return ERROR_EXPAT_NONE;
     4668                }
     4669                return ERROR_EXPAT_UNCLOSED_TOKEN;
    46844670            case XML_TOK_PARTIAL_CHAR:
    46854671                if (nextPtr)
    46864672                {
    46874673                    *nextPtr = s;
    4688                     return XML_ERROR_NONE;
    4689                 }
    4690                 return XML_ERROR_PARTIAL_CHAR;
     4674                    return ERROR_EXPAT_NONE;
     4675                }
     4676                return ERROR_EXPAT_PARTIAL_CHAR;
    46914677            default:
    4692                 return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;
     4678                return ERROR_EXPAT_JUNK_AFTER_DOC_ELEMENT;
    46934679        }
    46944680        eventPtr = s = next;
     
    46984684#ifdef XML_DTD
    46994685
    4700 static enum XML_Error processInternalParamEntity(XML_Parser parser, ENTITY * entity)
     4686static XMLERROR processInternalParamEntity(XML_Parser parser, ENTITY * entity)
    47014687{
    47024688    const char *s, *end, *next;
    47034689    int tok;
    4704     enum XML_Error result;
     4690    XMLERROR result;
    47054691    OPEN_INTERNAL_ENTITY openEntity;
    47064692
     
    47224708#endif /* XML_DTD */
    47234709
    4724 static enum XML_Error errorProcessor(XML_Parser parser,
     4710static XMLERROR errorProcessor(XML_Parser parser,
    47254711                              const char *s,
    47264712                              const char *end,
     
    47304716}
    47314717
    4732 static enum XML_Error storeAttributeValue(XML_Parser parser,
     4718static XMLERROR storeAttributeValue(XML_Parser parser,
    47334719                                          const ENCODING * enc,
    47344720                                          int isCdata,
     
    47374723                                          STRING_POOL * pool)
    47384724{
    4739     enum XML_Error result = appendAttributeValue(parser, enc, isCdata, ptr, end, pool);
     4725    XMLERROR result = appendAttributeValue(parser, enc, isCdata, ptr, end, pool);
    47404726
    47414727    if (result)
     
    47444730        poolChop(pool);
    47454731    if (!poolAppendChar(pool, XML_T('\0')))
    4746         return XML_ERROR_NO_MEMORY;
    4747     return XML_ERROR_NONE;
    4748 }
    4749 
    4750 static enum XML_Error appendAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata,
     4732        return ERROR_EXPAT_NO_MEMORY;
     4733    return ERROR_EXPAT_NONE;
     4734}
     4735
     4736static XMLERROR appendAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata,
    47514737                      const char *ptr, const char *end,
    47524738                      STRING_POOL * pool)
     
    47604746        {
    47614747            case XML_TOK_NONE:
    4762                 return XML_ERROR_NONE;
     4748                return ERROR_EXPAT_NONE;
    47634749            case XML_TOK_INVALID:
    47644750                if (enc == encoding)
    47654751                    eventPtr = next;
    4766                 return XML_ERROR_INVALID_TOKEN;
     4752                return ERROR_EXPAT_INVALID_TOKEN;
    47674753            case XML_TOK_PARTIAL:
    47684754                if (enc == encoding)
    47694755                    eventPtr = ptr;
    4770                 return XML_ERROR_INVALID_TOKEN;
     4756                return ERROR_EXPAT_INVALID_TOKEN;
    47714757            case XML_TOK_CHAR_REF:
    47724758                {
     
    47794765                        if (enc == encoding)
    47804766                            eventPtr = ptr;
    4781                         return XML_ERROR_BAD_CHAR_REF;
     4767                        return ERROR_EXPAT_BAD_CHAR_REF;
    47824768                    }
    47834769                    if (!isCdata
     
    47904776                        if (enc == encoding)
    47914777                            eventPtr = ptr;
    4792                         return XML_ERROR_BAD_CHAR_REF;
     4778                        return ERROR_EXPAT_BAD_CHAR_REF;
    47934779                    }
    47944780                    for (i = 0; i < n; i++)
    47954781                    {
    47964782                        if (!poolAppendChar(pool, buf[i]))
    4797                             return XML_ERROR_NO_MEMORY;
     4783                            return ERROR_EXPAT_NO_MEMORY;
    47984784                    }
    47994785                }
     
    48014787            case XML_TOK_DATA_CHARS:
    48024788                if (!poolAppend(pool, enc, ptr, next))
    4803                     return XML_ERROR_NO_MEMORY;
     4789                    return ERROR_EXPAT_NO_MEMORY;
    48044790                break;
    48054791            case XML_TOK_TRAILING_CR:
     
    48114797                    break;
    48124798                if (!poolAppendChar(pool, 0x20))
    4813                     return XML_ERROR_NO_MEMORY;
     4799                    return ERROR_EXPAT_NO_MEMORY;
    48144800                break;
    48154801            case XML_TOK_ENTITY_REF:
     
    48244810                    {
    48254811                        if (!poolAppendChar(pool, ch))
    4826                             return XML_ERROR_NO_MEMORY;
     4812                            return ERROR_EXPAT_NO_MEMORY;
    48274813                        break;
    48284814                    }
     
    48314817                                           next - enc->minBytesPerChar);
    48324818                    if (!name)
    4833                         return XML_ERROR_NO_MEMORY;
     4819                        return ERROR_EXPAT_NO_MEMORY;
    48344820                    entity = (ENTITY*)lookup(&dtd.generalEntities, name, 0);
    48354821                    poolDiscard(&temp2Pool);
     
    48404826                            if (enc == encoding)
    48414827                                eventPtr = ptr;
    4842                             return XML_ERROR_UNDEFINED_ENTITY;
     4828                            return ERROR_EXPAT_UNDEFINED_ENTITY;
    48434829                        }
    48444830                    }
     
    48474833                        if (enc == encoding)
    48484834                            eventPtr = ptr;
    4849                         return XML_ERROR_RECURSIVE_ENTITY_REF;
     4835                        return ERROR_EXPAT_RECURSIVE_ENTITY_REF;
    48504836                    }
    48514837                    else if (entity->notation)
     
    48534839                        if (enc == encoding)
    48544840                            eventPtr = ptr;
    4855                         return XML_ERROR_BINARY_ENTITY_REF;
     4841                        return ERROR_EXPAT_BINARY_ENTITY_REF;
    48564842                    }
    48574843                    else if (!entity->textPtr)
     
    48594845                        if (enc == encoding)
    48604846                            eventPtr = ptr;
    4861                         return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;
     4847                        return ERROR_EXPAT_ATTRIBUTE_EXTERNAL_ENTITY_REF;
    48624848                    }
    48634849                    else
    48644850                    {
    4865                         enum XML_Error result;
     4851                        XMLERROR result;
    48664852                        const XML_Char *textEnd = entity->textPtr + entity->textLen;
    48674853
     
    48774863                if (enc == encoding)
    48784864                    eventPtr = ptr;
    4879                 return XML_ERROR_UNEXPECTED_STATE;
     4865                return ERROR_EXPAT_UNEXPECTED_STATE;
    48804866        }
    48814867        ptr = next;
     
    48844870}
    48854871
    4886 static enum XML_Error storeEntityValue(XML_Parser parser,
     4872static XMLERROR storeEntityValue(XML_Parser parser,
    48874873                                const ENCODING * enc,
    48884874                                const char *entityTextPtr,
     
    49024888                if (parentParser || enc != encoding)
    49034889                {
    4904                     enum XML_Error result;
     4890                    XMLERROR result;
    49054891                    const XML_Char *name;
    49064892                    ENTITY *entity;
     
    49104896                                           next - enc->minBytesPerChar);
    49114897                    if (!name)
    4912                         return XML_ERROR_NO_MEMORY;
     4898                        return ERROR_EXPAT_NO_MEMORY;
    49134899                    entity = (ENTITY*)lookup(&dtd.paramEntities, name, 0);
    49144900                    poolDiscard(&tempPool);
     
    49174903                        if (enc == encoding)
    49184904                            eventPtr = entityTextPtr;
    4919                         return XML_ERROR_UNDEFINED_ENTITY;
     4905                        return ERROR_EXPAT_UNDEFINED_ENTITY;
    49204906                    }
    49214907                    if (entity->open)
     
    49234909                        if (enc == encoding)
    49244910                            eventPtr = entityTextPtr;
    4925                         return XML_ERROR_RECURSIVE_ENTITY_REF;
     4911                        return ERROR_EXPAT_RECURSIVE_ENTITY_REF;
    49264912                    }
    49274913                    if (entity->systemId)
     
    49294915                        if (enc == encoding)
    49304916                            eventPtr = entityTextPtr;
    4931                         return XML_ERROR_PARAM_ENTITY_REF;
     4917                        return ERROR_EXPAT_PARAM_ENTITY_REF;
    49324918                    }
    49334919                    entity->open = 1;
     
    49434929#endif /* XML_DTD */
    49444930                eventPtr = entityTextPtr;
    4945                 return XML_ERROR_SYNTAX;
     4931                return ERROR_EXPAT_SYNTAX;
    49464932            case XML_TOK_NONE:
    4947                 return XML_ERROR_NONE;
     4933                return ERROR_EXPAT_NONE;
    49484934            case XML_TOK_ENTITY_REF:
    49494935            case XML_TOK_DATA_CHARS:
    49504936                if (!poolAppend(pool, enc, entityTextPtr, next))
    4951                     return XML_ERROR_NO_MEMORY;
     4937                    return ERROR_EXPAT_NO_MEMORY;
    49524938                break;
    49534939            case XML_TOK_TRAILING_CR:
     
    49564942            case XML_TOK_DATA_NEWLINE:
    49574943                if (pool->end == pool->ptr && !poolGrow(pool))
    4958                     return XML_ERROR_NO_MEMORY;
     4944                    return ERROR_EXPAT_NO_MEMORY;
    49594945                *(pool->ptr)++ = 0xA;
    49604946                break;
     
    49694955                        if (enc == encoding)
    49704956                            eventPtr = entityTextPtr;
    4971                         return XML_ERROR_BAD_CHAR_REF;
     4957                        return ERROR_EXPAT_BAD_CHAR_REF;
    49724958                    }
    49734959                    n = XmlEncode(n, (ICHAR*)buf);
     
    49764962                        if (enc == encoding)
    49774963                            eventPtr = entityTextPtr;
    4978                         return XML_ERROR_BAD_CHAR_REF;
     4964                        return ERROR_EXPAT_BAD_CHAR_REF;
    49794965                    }
    49804966                    for (i = 0; i < n; i++)
    49814967                    {
    49824968                        if (pool->end == pool->ptr && !poolGrow(pool))
    4983                             return XML_ERROR_NO_MEMORY;
     4969                            return ERROR_EXPAT_NO_MEMORY;
    49844970                        *(pool->ptr)++ = buf[i];
    49854971                    }
     
    49894975                if (enc == encoding)
    49904976                    eventPtr = entityTextPtr;
    4991                 return XML_ERROR_INVALID_TOKEN;
     4977                return ERROR_EXPAT_INVALID_TOKEN;
    49924978            case XML_TOK_INVALID:
    49934979                if (enc == encoding)
    49944980                    eventPtr = next;
    4995                 return XML_ERROR_INVALID_TOKEN;
     4981                return ERROR_EXPAT_INVALID_TOKEN;
    49964982            default:
    49974983                if (enc == encoding)
    49984984                    eventPtr = entityTextPtr;
    4999                 return XML_ERROR_UNEXPECTED_STATE;
     4985                return ERROR_EXPAT_UNEXPECTED_STATE;
    50004986        }
    50014987        entityTextPtr = next;
     
    54865472}
    54875473
    5488 /* Do a deep copy of the DTD.  Return 0 for out of memory; non-zero otherwise.
    5489  * The new DTD has already been initialized. */
     5474/*
     5475 * Do a deep copy of the DTD.  Return 0 for out of memory; non-zero otherwise.
     5476 * The new DTD has already been initialized.
     5477 *
     5478 */
    54905479
    54915480static int dtdCopy(DTD * newDtd, const DTD * oldDtd, XML_Parser parser)
     
    60586047static void build_node(XML_Parser parser,
    60596048            int src_node,
    6060             XML_Content * dest,
    6061             XML_Content ** contpos,
     6049            XMLCONTENT * dest,
     6050            XMLCONTENT ** contpos,
    60626051            char **strpos)
    60636052{
     
    60986087}                               /* End build_node */
    60996088
    6100 static XML_Content * build_model(XML_Parser parser)
    6101 {
    6102     XML_Content *ret;
    6103     XML_Content *cpos;
     6089static XMLCONTENT * build_model(XML_Parser parser)
     6090{
     6091    XMLCONTENT *ret;
     6092    XMLCONTENT *cpos;
    61046093    char *str;
    6105     int allocsize = dtd.scaffCount * sizeof(XML_Content) + dtd.contentStringLen;
    6106 
    6107     ret = (XML_Content*)MALLOC(allocsize);
     6094    int allocsize = dtd.scaffCount * sizeof(XMLCONTENT) + dtd.contentStringLen;
     6095
     6096    ret = (XMLCONTENT*)MALLOC(allocsize);
    61086097    if (!ret)
    61096098        return 0;
  • trunk/src/helpers/xmlrole.c

    r36 r38  
    11
    22/*
    3  *@@sourcefile xmlrole.c
     3 *sourcefile xmlrole.c
    44 *      part of the expat implementation. See xmlparse.c.
    55 *
  • trunk/src/helpers/xmltok.c

    r36 r38  
    11
    22/*
    3  *@@sourcefile xmltok.c
     3 *sourcefile xmltok.c
    44 *      part of the expat implementation. See xmlparse.c.
    55 *
  • trunk/src/helpers/xmltok_impl.c

    r36 r38  
    11
    22/*
    3  *@@sourcefile xmltok_impl.c
     3 *sourcefile xmltok_impl.c
    44 *      part of the expat implementation. See xmlparse.c.
    55 *
  • trunk/src/helpers/xmltok_ns.c

    r36 r38  
    11
    22/*
    3  *@@sourcefile xmltok_ns.c
     3 *sourcefile xmltok_ns.c
    44 *      part of the expat implementation. See xmlparse.c.
    55 *
  • trunk/src/helpers/xstring.c

    r32 r38  
    346346 *
    347347 *@@added V0.9.6 (2000-11-01) [umoeller]
     348 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash
    348349 */
    349350
     
    351352              PSZ pszNew)                   // in: heap PSZ to use
    352353{
     354    if (!pxstr)
     355        return (0);         // V0.9.9 (2001-02-14) [umoeller]
     356
    353357    xstrClear(pxstr);
    354358    pxstr->psz = pszNew;
     
    391395 *@@changed V0.9.7 (2001-01-15) [umoeller]: added ulSourceLength
    392396 *@@changed V0.9.9 (2001-01-28) [lafaix]: fixed memory leak and NULL source behavior
     397 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash
    393398 */
    394399
     
    399404    // xstrClear(pxstr);        NOOOO! this frees the string, we want to keep the memory
    400405
    401     if (pxstr)
    402     {
    403         if (pcszSource)
     406    if (!pxstr)
     407        return (0);         // V0.9.9 (2001-02-14) [umoeller]
     408
     409    if (pcszSource)
     410    {
     411        // source specified:
     412        if (ulSourceLength == 0)
     413            // but not length:
     414            ulSourceLength = strlen(pcszSource);
     415    }
     416    else
     417        ulSourceLength = 0;
     418
     419    if (ulSourceLength)
     420    {
     421        // we do have a source string:
     422        ULONG cbNeeded = ulSourceLength + 1;
     423        if (cbNeeded > pxstr->cbAllocated)
    404424        {
    405             // source specified:
    406             if (ulSourceLength == 0)
    407                 // but not length:
    408                 ulSourceLength = strlen(pcszSource);
     425            // we need more memory than we have previously
     426            // allocated:
     427            if (pxstr->psz)
     428                free(pxstr->psz); // V0.9.9 (2001-01-28) [lafaix]
     429            pxstr->cbAllocated = cbNeeded;
     430            pxstr->psz = (PSZ)malloc(cbNeeded);
    409431        }
    410         else
    411             ulSourceLength = 0;
    412 
    413         if (ulSourceLength)
    414         {
    415             // we do have a source string:
    416             ULONG cbNeeded = ulSourceLength + 1;
    417             if (cbNeeded > pxstr->cbAllocated)
    418             {
    419                 // we need more memory than we have previously
    420                 // allocated:
    421                 if (pxstr->psz)
    422                     free(pxstr->psz); // V0.9.9 (2001-01-28) [lafaix]
    423                 pxstr->cbAllocated = cbNeeded;
    424                 pxstr->psz = (PSZ)malloc(cbNeeded);
    425             }
    426             // else: we have enough memory
    427 
    428             // strcpy(pxstr->psz, pcszSource);
    429             memcpy(pxstr->psz,
    430                    pcszSource,
    431                    ulSourceLength + 1); // V0.9.9 (2001-01-31) [umoeller]
    432         }
    433         else
    434         {
    435             // no source specified or source is empty:
    436             if (pxstr->cbAllocated)
    437                 // we did have a string: set to empty,
    438                 // but leave allocated memory intact
    439                 *(pxstr->psz) = 0;
    440             // else
    441                 // we had no string previously: in that case
    442                 // psz and ulLength and cbAllocated are all still NULL
    443         }
    444 
    445         // in all cases, set new length
    446         pxstr->ulLength = ulSourceLength;
    447     }
     432        // else: we have enough memory
     433
     434        // strcpy(pxstr->psz, pcszSource);
     435        memcpy(pxstr->psz,
     436               pcszSource,
     437               ulSourceLength + 1); // V0.9.9 (2001-01-31) [umoeller]
     438    }
     439    else
     440    {
     441        // no source specified or source is empty:
     442        if (pxstr->cbAllocated)
     443            // we did have a string: set to empty,
     444            // but leave allocated memory intact
     445            *(pxstr->psz) = 0;
     446        // else
     447            // we had no string previously: in that case
     448            // psz and ulLength and cbAllocated are all still NULL
     449    }
     450
     451    // in all cases, set new length
     452    pxstr->ulLength = ulSourceLength;
    448453
    449454    return (pxstr->ulLength);
     455}
     456
     457/*
     458 *@@ xstrcpys:
     459 *      shortcut to xstrcpy if the source is an XSTRING also.
     460 *
     461 *@@added V0.9.9 (2001-02-14) [umoeller]
     462 */
     463
     464ULONG xstrcpys(PXSTRING pxstr,
     465               const XSTRING *pcstrSource)
     466{
     467    if (!pcstrSource)
     468        return (0);
     469
     470    return (xstrcpy(pxstr, pcstrSource->psz, pcstrSource->ulLength));
    450471}
    451472
     
    634655
    635656/*
     657 *@@ xstrcats:
     658 *      shortcut to xstrcat if the source is an XSTRING also.
     659 *
     660 *@@added V0.9.9 (2001-02-14) [umoeller]
     661 */
     662
     663ULONG xstrcats(PXSTRING pxstr,
     664               const XSTRING *pcstrSource)
     665{
     666    if (!pcstrSource)
     667        return (0);
     668
     669    return (xstrcat(pxstr, pcstrSource->psz, pcstrSource->ulLength));
     670}
     671
     672/*
    636673 *@@ xstrrpl:
    637674 *      replaces cReplLen characters in pxstr, starting
     
    666703 *@@added V0.9.7 (2001-01-15) [umoeller]
    667704 *@@changed V0.9.9 (2001-01-29) [lafaix]: fixed unnecessary allocation when pxstr was big enough
     705  *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash
    668706 */
    669707
     
    676714
    677715    // security checks...
    678     if (    (ulFirstReplOfs + cReplLen <= pxstr->ulLength)
     716    if (    (pxstr)         // V0.9.9 (2001-02-14) [umoeller]
     717         && (ulFirstReplOfs + cReplLen <= pxstr->ulLength)
    679718         && (pstrReplaceWith)
    680719         // && (pstrReplaceWith->ulLength)      no, this can be empty
     
    747786            ULONG   cTailLength = pxstr->ulLength - ulFirstReplOfs - cReplLen;
    748787
    749             // first, we move the end to its new location (memmove
    750             // handles overlap if needed)
     788            // first, we move the end to its new location
     789            // (memmove handles overlap if needed)
    751790            memmove(pFound + cReplaceLen,
    752791                    pFound + cReplLen,
     
    787826 *
    788827 *@@added V0.9.6 (2000-11-12) [umoeller]
     828 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL string crashs
    789829 */
    790830
     
    798838{
    799839    PSZ     pReturn = 0;
    800     ULONG   ulFoundLen = pstrFind->ulLength;
    801 
    802     if ((pxstr->ulLength) && (ulFoundLen))
    803     {
    804         const char *p = pxstr->psz + ulOfs;
    805 
    806         do  // while p
     840
     841    if (pxstr && pstrFind)      // V0.9.9 (2001-02-14) [umoeller]
     842    {
     843        ULONG   ulFoundLen = pstrFind->ulLength;
     844
     845        if ((pxstr->ulLength) && (ulFoundLen))
    807846        {
    808             // p = strstr(p, pstrFind->psz);
    809             p = (PSZ)strhmemfind(p,         // in: haystack
    810                                  pxstr->ulLength - (p - pxstr->psz),
    811                                             // remaining length of haystack
    812                                  pstrFind->psz,
    813                                  ulFoundLen,
    814                                  pShiftTable,
    815                                  pfRepeatFind);
    816             if (p)
     847            const char *p = pxstr->psz + ulOfs;
     848
     849            do  // while p
    817850            {
    818                 // string found:
    819                 // check if that's a word
    820 
    821                 if (strhIsWord(pxstr->psz,
    822                                p,
    823                                ulFoundLen,
    824                                pcszBeginChars,
    825                                pcszEndChars))
     851                p = (PSZ)strhmemfind(p,         // in: haystack
     852                                     pxstr->ulLength - (p - pxstr->psz),
     853                                                // remaining length of haystack
     854                                     pstrFind->psz,
     855                                     ulFoundLen,
     856                                     pShiftTable,
     857                                     pfRepeatFind);
     858                if (p)
    826859                {
    827                     // valid end char:
    828                     pReturn = (PSZ)p;
    829                     break;
     860                    // string found:
     861                    // check if that's a word
     862
     863                    if (strhIsWord(pxstr->psz,
     864                                   p,
     865                                   ulFoundLen,
     866                                   pcszBeginChars,
     867                                   pcszEndChars))
     868                    {
     869                        // valid end char:
     870                        pReturn = (PSZ)p;
     871                        break;
     872                    }
     873
     874                    p += ulFoundLen;
    830875                }
    831 
    832                 p += ulFoundLen;
    833             }
    834         } while (p);
    835 
    836     }
     876            } while (p);
     877
     878        }
     879    }
     880
    837881    return (pReturn);
    838882}
Note: See TracChangeset for help on using the changeset viewer.