Changeset 38
- Timestamp:
- Feb 17, 2001, 3:03:14 PM (25 years ago)
- Location:
- trunk
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/expat/expat.h
r36 r38 31 31 typedef char XML_LChar; 32 32 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 33 enum 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 40 41 }; 41 42 42 enum XML_Content_Quant { 43 XML_CQUANT_NONE, 44 XML_CQUANT_OPT, 45 XML_CQUANT_REP, 46 XML_CQUANT_PLUS 43 enum XML_Content_Quant 44 { 45 XML_CQUANT_NONE, 46 XML_CQUANT_OPT, 47 XML_CQUANT_REP, 48 XML_CQUANT_PLUS 47 49 }; 48 50 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 87 typedef 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; 76 114 77 115 … … 82 120 83 121 typedef void (* EXPATENTRY XML_ElementDeclHandler) (void *userData, 84 const XML_Char *name,85 XML_Content*model);122 const XML_Char *name, 123 XMLCONTENT *model); 86 124 87 125 void XMLPARSEAPI XML_SetElementDeclHandler(XML_Parser parser, … … 292 330 have standalone="yes"). If this handler returns 0, then processing 293 331 will not continue, and the parser will return a 294 XML_ERROR_NOT_STANDALONE error. */332 ERROR_EXPAT_NOT_STANDALONE error. */ 295 333 296 334 typedef int (* EXPATENTRY XML_NotStandaloneHandler)(void *userData); … … 316 354 The handler should return 0 if processing should not continue because of 317 355 a fatal error in the handling of the external entity. 318 In this case the calling parser will return an XML_ERROR_EXTERNAL_ENTITY_HANDLING356 In this case the calling parser will return an ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING 319 357 error. 320 358 Note that unlike other handlers the first argument is the parser, not userData. */ … … 406 444 } XML_Encoding; 407 445 408 /* This is called for an encoding that is unknown to the parser.409 The encodingHandlerData argument is that which was passed as the410 second argument to XML_SetUnknownEncodingHandler.411 The name argument gives the name of the encoding as specified in412 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 419 446 typedef int (* EXPATENTRY XML_UnknownEncodingHandler)(void *encodingHandlerData, 420 const XML_Char *name,421 XML_Encoding *info);447 const XML_Char *name, 448 XML_Encoding *info); 422 449 423 450 void XMLPARSEAPI XML_SetElementHandler(XML_Parser parser, 424 XML_StartElementHandler start,425 XML_EndElementHandler end);451 XML_StartElementHandler start, 452 XML_EndElementHandler end); 426 453 427 454 void XMLPARSEAPI XML_SetStartElementHandler(XML_Parser, XML_StartElementHandler); … … 430 457 431 458 void XMLPARSEAPI XML_SetCharacterDataHandler(XML_Parser parser, 432 XML_CharacterDataHandler handler);459 XML_CharacterDataHandler handler); 433 460 434 461 void XMLPARSEAPI XML_SetProcessingInstructionHandler(XML_Parser parser, 435 XML_ProcessingInstructionHandler handler);462 XML_ProcessingInstructionHandler handler); 436 463 void XMLPARSEAPI XML_SetCommentHandler(XML_Parser parser, 437 XML_CommentHandler handler);464 XML_CommentHandler handler); 438 465 439 466 void XMLPARSEAPI XML_SetCdataSectionHandler(XML_Parser parser, 440 XML_StartCdataSectionHandler start,441 XML_EndCdataSectionHandler end);467 XML_StartCdataSectionHandler start, 468 XML_EndCdataSectionHandler end); 442 469 443 470 void XMLPARSEAPI XML_SetStartCdataSectionHandler(XML_Parser parser, … … 594 621 }; 595 622 596 /* Controls parsing of parameter entities (including the external DTD597 subset). If parsing of parameter entities is enabled, then references598 to external parameter entities (including the external DTD subset)599 will be passed to the handler set with600 XML_SetExternalEntityRefHandler. The context passed will be 0.601 Unlike external general entities, external parameter entities can only602 be parsed synchronously. If the external parameter entity is to be603 parsed, it must be parsed during the call to the external entity ref604 handler: the complete sequence of XML_ExternalEntityParserCreate,605 XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during606 this call. After XML_ExternalEntityParserCreate has been called to607 create the parser for the external parameter entity (context must be 0608 for this call), it is illegal to make any calls on the old parser609 until XML_ParserFree has been called on the newly created parser. If610 the library has been compiled without support for parameter entity611 parsing (ie without XML_DTD being defined), then612 XML_SetParamEntityParsing will return 0 if parsing of parameter613 entities is requested; otherwise it will return non-zero. */614 615 623 int 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 630 typedef 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; 644 660 645 661 /* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode 646 662 returns information about the error. */ 647 663 648 enum XML_ErrorXMLPARSEAPI XML_GetErrorCode(XML_Parser parser);664 XMLERROR XMLPARSEAPI XML_GetErrorCode(XML_Parser parser); 649 665 650 666 /* These functions return information about the current parse location. … … 687 703 688 704 /* 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] 690 707 691 708 /* Return a string containing the version number of this expat */ -
trunk/include/expat/expat_setup.h
r36 r38 18 18 #define EXPATENTRY _Optlink 19 19 #endif 20 21 #define XML_DTD 1 22 20 23 #endif 21 24 -
trunk/include/expat/xmlrole.h
r36 r38 6 6 #ifndef XmlRole_INCLUDED 7 7 #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 8 12 9 13 #include "expat\xmltok.h" -
trunk/include/expat/xmltok.h
r36 r38 6 6 #ifndef XmlTok_INCLUDED 7 7 #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 8 12 9 13 #ifdef __cplusplus … … 154 158 const char *); 155 159 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 *); 159 163 int (* EXPATENTRY isPublicId)(const ENCODING *enc, 160 164 const char *ptr, -
trunk/include/helpers/linklist.h
r35 r38 153 153 typedef LSTQUERYFIRSTNODE *PLSTQUERYFIRSTNODE; 154 154 155 PLISTNODE XWPENTRY lstQueryLastNode(PLINKLIST pList); 156 typedef PLISTNODE XWPENTRY LSTQUERYLASTNODE(PLINKLIST pList); 157 typedef LSTQUERYLASTNODE *PLSTQUERYLASTNODE; 158 155 159 PLISTNODE XWPENTRY lstNodeFromIndex(PLINKLIST pList, unsigned long ulIndex); 156 160 typedef PLISTNODE XWPENTRY LSTNODEFROMINDEX(PLINKLIST pList, unsigned long ulIndex); -
trunk/include/helpers/stringh.h
r23 r38 35 35 36 36 PSZ strhdup(const char *pszSource); 37 38 int strhcmp(const char *p1, const char *p2); 37 39 38 40 PSZ strhistr(const char *string1, const char *string2); -
trunk/include/helpers/tree.h
r33 r38 107 107 // -- -1: t1 < t2 108 108 // -- +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); 111 111 112 112 // 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); 114 114 115 115 // Global variables -
trunk/include/helpers/xml.h
r35 r38 8 8 *@@added V0.9.6 (2000-10-29) [umoeller] 9 9 *@@include #include <os2.h> 10 *@@include #include "expat\expat.h" 10 *@@include #include "expat\expat.h" // must come before xml.h 11 11 *@@include #include "helpers\linklist.h" 12 *@@include #include "helpers\tree.h" 12 13 *@@include #include "helpers\xstring.h" 13 14 *@@include #include "helpers\xml.h" … … 36 37 #endif 37 38 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 ********************************************************************/ 65 140 66 141 /* 67 142 *@@ 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. 75 148 * 76 149 * 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: 80 168 + 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 + | | | | 82 206 + 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. 90 215 */ 91 216 92 217 typedef struct _DOMNODE 93 218 { 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 111 223 112 224 struct _DOMNODE *pParentNode; 113 225 // 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 119 239 120 240 } DOMNODE, *PDOMNODE; 121 241 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); 130 296 131 297 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; 132 530 133 531 /* ****************************************************************** … … 141 539 * DOM instance returned by xmlCreateDOM. 142 540 * 143 *@@added V0.9.9 (200 0-02-14) [umoeller]541 *@@added V0.9.9 (2001-02-14) [umoeller] 144 542 */ 145 543 … … 150 548 */ 151 549 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 155 558 const char *pcszErrorDescription; 156 559 ULONG ulErrorLine; 157 560 ULONG ulErrorColumn; 561 PXSTRING pxstrFailingNode; // element or attribute name 158 562 159 563 /* … … 169 573 170 574 PDOMNODE pLastWasTextNode; 575 576 PCMATTRIBUTEDEDECLBASE pAttListDeclCache; 577 // cache for attribute declarations according 578 // to attdecl element name 171 579 } XMLDOM, *PXMLDOM; 580 581 #define DF_PARSECOMMENTS 0x0001 582 #define DF_PARSEDTD 0x0002 172 583 173 584 APIRET xmlCreateDOM(ULONG flParserFlags, … … 181 592 APIRET xmlFreeDOM(PXMLDOM pDom); 182 593 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 183 604 #endif 184 605 -
trunk/include/helpers/xstring.h
r32 r38 86 86 typedef XSTRCPY *PXSTRCPY; 87 87 88 ULONG XWPENTRY xstrcpys(PXSTRING pxstr, const XSTRING *pcstrSource); 89 typedef ULONG XWPENTRY XSTRCPYS(PXSTRING pxstr, const XSTRING *pcstrSource); 90 typedef XSTRCPYS *PXSTRCPYS; 91 88 92 ULONG XWPENTRY xstrcat(PXSTRING pxstr, const char *pcszSource, ULONG ulSourceLength); 89 93 typedef ULONG XWPENTRY XSTRCAT(PXSTRING pxstr, const char *pcszSource, ULONG ulSourceLength); … … 93 97 typedef ULONG XWPENTRY XSTRCATC(PXSTRING pxstr, CHAR c); 94 98 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; 95 103 96 104 /* -
trunk/src/helpers/dosh.c
r33 r38 1828 1828 * 1829 1829 *@@added V0.9.7 (2000-12-02) [umoeller] 1830 *@@changed V0.9.9 (200 0-02-06) [umoeller]: removed disable; this broke the WarpCenter1830 *@@changed V0.9.9 (2001-02-06) [umoeller]: removed disable; this broke the WarpCenter 1831 1831 */ 1832 1832 -
trunk/src/helpers/gpih.c
r29 r38 5 5 * 6 6 * Usage: All PM programs. 7 *8 * A word about GPI rectangles: In general, graphics operations9 * involving device coordinates (such as regions, bit maps and10 * bit blts, and window management) use inclusive-exclusive11 * rectangles. All other graphics operations, such as GPI12 * functions that define paths, use inclusive-inclusive rectangles.13 *14 * This can be a problem with mixing Win and Gpi functions. For15 * example, WinQueryWindowRect returns an inclusive-exclusive16 * rectangle (so that the xRight value is the same as the window17 * width -- tested V0.9.7 (2000-12-20) [umoeller]).18 *19 * WinFillRect expects an inclusive-exclusive rectangle, so it20 * will work with a rectangle from WinQueryWindowRect directly.21 *22 * By contrast, the GpiBox expects an inclusive-inclusive rectangle.23 7 * 24 8 * Function prefixes (new with V0.81): … … 87 71 */ 88 72 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 89 95 /* ****************************************************************** 90 96 * … … 187 193 * 188 194 * 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). 190 197 * 191 198 * This sets the current position to the bottom left corner … … 223 230 * The specified rectangle is inclusive, that is, the top 224 231 * 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). 226 234 * 227 235 * If (lColor != -1), the HPS's current foreground color … … 294 302 * The specified rectangle is inclusive, that is, the top 295 303 * 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). 297 306 * 298 307 * If usWidth > 1, the additional pixels will be drawn towards … … 341 350 * The specified rectangle is inclusive, that is, the top 342 351 * 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). 344 354 * 345 355 * If usWidth > 1, the additional pixels will be drawn towards -
trunk/src/helpers/helpers_post.in
r35 r38 186 186 $(OUTPUTDIR)\xml.obj: $(@B).c $(HLPINC)\$(@B).h \ 187 187 $(PROJECTINC)\setup.h \ 188 $(HLPINC)\ stringh.h188 $(HLPINC)\linklist.h $(HLPINC)\stringh.h $(HLPINC)\tree.h $(HLPINC)\xstring.h 189 189 190 190 $(OUTPUTDIR)\xprf.obj: $(@B).c $(HLPINC)\$(@B).h \ … … 205 205 $(INC)\expat\asciitab.h \ 206 206 $(INC)\expat\expat.h \ 207 $(INC)\expat\expat_setup.h \ 207 208 $(INC)\expat\iasciitab.h \ 208 209 $(INC)\expat\latin1tab.h \ 209 210 $(INC)\expat\nametab.h \ 210 211 $(INC)\expat\utf8tab.h \ 211 $(INC)\expat\winconfig.h \212 212 $(INC)\expat\xmlrole.h \ 213 213 $(INC)\expat\xmltok.h \ -
trunk/src/helpers/linklist.c
r35 r38 373 373 PLISTNODE lstQueryFirstNode(PLINKLIST pList) 374 374 { 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 391 PLISTNODE lstQueryLastNode(PLINKLIST pList) 392 { 393 if ( (pList) 394 && (pList->ulMagic == LINKLISTMAGIC) 395 ) 396 return (pList->pLast); 378 397 379 398 return (0); -
trunk/src/helpers/prfh.c
r33 r38 468 468 * -- PRFERR_WRITE: couldn't write data to target (PrfWriteProfileData error) 469 469 * 470 *@@added V0.9.9 (200 0-02-06) [umoeller]470 *@@added V0.9.9 (2001-02-06) [umoeller] 471 471 */ 472 472 -
trunk/src/helpers/stringh.c
r23 r38 82 82 else 83 83 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 99 int 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); 84 116 } 85 117 -
trunk/src/helpers/threads.c
r33 r38 193 193 *@@changed V0.9.5 (2000-08-26) [umoeller]: now using PTHREADINFO 194 194 *@@changed V0.9.7 (2000-12-18) [lafaix]: THRF_TRANSIENT support added 195 *@@changed V0.9.9 (200 0-02-06) [umoeller]: now returning TID195 *@@changed V0.9.9 (2001-02-06) [umoeller]: now returning TID 196 196 */ 197 197 … … 203 203 ULONG ulData) // in: user data to be stored in THREADINFO 204 204 { 205 ULONG ulrc = 0; // V0.9.9 (200 0-02-06) [umoeller]205 ULONG ulrc = 0; // V0.9.9 (2001-02-06) [umoeller] 206 206 207 207 // (2000-12-18) [lafaix] TRANSIENT -
trunk/src/helpers/tree.c
r33 r38 194 194 * fnCompareIDs: 195 195 * 196 *added V0.9.9 (200 0-02-06) [umoeller]196 *added V0.9.9 (2001-02-06) [umoeller] 197 197 */ 198 198 … … 252 252 * exists. 253 253 * 254 *@@changed V0.9.9 (200 0-02-06) [umoeller]: removed comparison func254 *@@changed V0.9.9 (2001-02-06) [umoeller]: removed comparison func 255 255 */ 256 256 … … 927 927 * -- 1: current node first, then left node, then right node. 928 928 * -- 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. 930 931 */ 931 932 -
trunk/src/helpers/xml.c
r35 r38 7 7 * layers: 8 8 * 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. 11 12 * 12 13 * -- Because expat requires so many callbacks and is non-validating, … … 15 16 * (DOM) standardized by the W3C. That's this file. 16 17 * 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. 35 23 * 36 24 * <B>Document Object Model (DOM)</B> 37 25 * 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. 88 27 * 89 28 * DOM really calls for object oriented programming so the various 90 29 * 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. 94 59 * 95 60 * 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. 108 78 * 109 79 *@@header "helpers\xml.h" … … 141 111 #include "helpers\linklist.h" 142 112 #include "helpers\stringh.h" 113 #include "helpers\tree.h" 143 114 #include "helpers\xstring.h" 144 115 #include "helpers\xml.h" … … 158 129 /* ****************************************************************** 159 130 * 160 * Node management131 * Generic methods 161 132 * 162 133 ********************************************************************/ 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 153 int 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 169 int CompareCMNodeData(TREE *t1, 170 void *pData) 171 { 172 PNODEBASE p1 = (PNODEBASE)t1; 173 return (strhcmp(p1->strNodeName.psz, (const char*)pData)); 174 } 163 175 164 176 /* … … 166 178 * creates a new DOMNODE with the specified 167 179 * 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 200 APIRET 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); 179 233 pNewNode->pParentNode = pParentNode; 234 180 235 if (pParentNode) 181 236 { 182 237 // 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 } 187 272 } 188 273 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); 194 285 } 195 286 196 287 /* 197 288 *@@ xmlDeleteNode: 198 * deletes the specified node. 289 * deletes the specified node and updates the 290 * parent node's children list. 199 291 * 200 292 * If the node has child nodes, all of them are deleted … … 205 297 * child nodes. 206 298 * 207 * Returns:208 * 209 * -- 0: NO_ERROR.210 */ 211 212 ULONGxmlDeleteNode(PDOMNODE pNode)299 * This returns the following errors: 300 * 301 * -- ERROR_DOM_NOT_FOUND 302 */ 303 304 APIRET xmlDeleteNode(PDOMNODE pNode) 213 305 { 214 306 ULONG ulrc = 0; … … 216 308 if (!pNode) 217 309 { 218 ulrc = ERROR_ DOM_NOT_FOUND;310 ulrc = ERROR_INVALID_PARAMETER; 219 311 } 220 312 else 221 313 { 314 PLISTNODE pNodeThis; 315 222 316 // recurse into child nodes 223 PLISTNODE pNodeThis = lstQueryFirstNode(&pNode->llChildNodes); 224 while (pNodeThis) 225 { 317 while (pNodeThis = lstQueryFirstNode(&pNode->llChildren)) 226 318 // recurse!! 227 319 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 241 327 242 328 if (pNode->pParentNode) 243 329 { 244 330 // 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 249 342 pNode->pParentNode = NULL; 250 343 } 251 344 252 xstrClear(&pNode-> strNodeName);253 xstr Clear(&pNode->strNodeValue);254 255 lstClear(&pNode->llChild Nodes);256 lstClear(&pNode->llAttributeNodes);345 xstrClear(&pNode->NodeBase.strNodeName); 346 xstrFree(pNode->pstrNodeValue); 347 348 lstClear(&pNode->llChildren); 349 // lstClear(&pNode->llAttributes); ### 257 350 258 351 free(pNode); … … 262 355 } 263 356 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 366 PDOMNODE 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 384 PDOMNODE 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 403 const 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 461 VOID 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 264 484 /* ****************************************************************** 265 485 * 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 497 APIRET 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 534 APIRET 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 575 APIRET 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 614 APIRET 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 640 APIRET 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 669 APIRET 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 733 PLINKLIST 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 755 APIRET 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 844 APIRET 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 884 PCMELEMENTDECLNODE 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 915 PCMATTRIBUTEDEDECLBASE 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 942 PCMATTRIBUTEDECL 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 995 VOID 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 1077 VOID 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 * 266 1094 * Expat handlers 267 1095 * … … 270 1098 /* 271 1099 *@@ StartElementHandler: 272 * expat handler called when a new element is1100 * @expat handler called when a new element is 273 1101 * found. 274 1102 * … … 279 1107 */ 280 1108 281 void EXPATENTRY StartElementHandler(void * data, // in: our PXMLFILEreally1109 void EXPATENTRY StartElementHandler(void *pUserData, // in: our PXMLDOM really 282 1110 const char *pcszElement, 283 1111 const char **papcszAttribs) 284 1112 { 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 312 1128 { 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) 316 1137 { 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 } 319 1172 } 320 1173 } 321 } 322 323 pDom->pLastWasTextNode = NULL;1174 1175 pDom->pLastWasTextNode = NULL; 1176 } 324 1177 } 325 1178 326 1179 /* 327 1180 *@@ 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 1185 void EXPATENTRY EndElementHandler(void *pUserData, // in: our PXMLDOM really 332 1186 const XML_Char *name) 333 1187 { 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 } 340 1198 } 341 1199 342 1200 /* 343 1201 *@@ 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 1208 void EXPATENTRY CharacterDataHandler(void *pUserData, // in: our PXMLDOM really 348 1209 const XML_Char *s, 349 1210 int len) 350 1211 { 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) 358 1220 { 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 } 364 1243 } 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 1257 void 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 1292 void 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; 365 1307 else 366 1308 { 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 1330 void 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 1360 void 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 1426 int 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 1460 void 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 377 1479 { 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 } 382 1507 } 383 384 pDom->pLastWasTextNode = pNew;385 1508 } 386 1509 } 387 1510 } 388 1511 1512 /* 1513 *@@ AddEnum: 1514 * 1515 *@@added V0.9.9 (2001-02-16) [umoeller] 1516 */ 1517 1518 VOID 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 1562 void 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 1748 void 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 389 1766 /* ****************************************************************** 390 1767 * … … 395 1772 /* 396 1773 *@@ 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. 397 1787 * 398 1788 * Usage: … … 413 1803 * call xmlFreeDOM, which will free all memory. 414 1804 * 415 *@@added V0.9.9 (200 0-02-14) [umoeller]1805 *@@added V0.9.9 (2001-02-14) [umoeller] 416 1806 */ 417 1807 … … 421 1811 APIRET arc = NO_ERROR; 422 1812 423 PXMLDOM pDom = (PXMLDOM)malloc(sizeof( XMLDOM));1813 PXMLDOM pDom = (PXMLDOM)malloc(sizeof(*pDom)); 424 1814 if (!pDom) 425 1815 arc = ERROR_NOT_ENOUGH_MEMORY; 426 1816 else 427 1817 { 1818 PDOMNODE pDocument = NULL; 1819 428 1820 memset(pDom, 0, sizeof(XMLDOM)); 429 1821 … … 432 1824 433 1825 // 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) 440 1831 { 1832 // store the document in the DOM 1833 pDom->pDocumentNode = (PDOMDOCUMENTNODE)pDocument; 1834 441 1835 // push the document on the stack so the handlers 442 1836 // will append to that … … 457 1851 CharacterDataHandler); 458 1852 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 459 1888 // pass the XMLDOM as user data to the handlers 460 1889 XML_SetUserData(pDom->pParser, 461 1890 pDom); 462 463 1891 } 464 1892 } … … 477 1905 * parses another piece of XML data. 478 1906 * 479 * If (fIsLast == TRUE), the internal expat parser1907 * If (fIsLast == TRUE), the internal @expat parser 480 1908 * will be freed, but not the DOM itself. 481 1909 * … … 485 1913 * 486 1914 * 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] 492 1932 */ 493 1933 … … 510 1950 if (!fSuccess) 511 1951 { 512 // e rror: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); 517 1957 518 1958 if (pDom->pDocumentNode) 519 1959 { 520 xmlDeleteNode( pDom->pDocumentNode);1960 xmlDeleteNode((PDOMNODE)pDom->pDocumentNode); 521 1961 pDom->pDocumentNode = NULL; 522 1962 } … … 524 1964 arc = ERROR_DOM_PARSING; 525 1965 } 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) 529 1979 { 530 1980 // last call or error: clean up … … 551 2001 * calling this function. 552 2002 * 553 *@@added V0.9.9 (200 0-02-14) [umoeller]2003 *@@added V0.9.9 (2001-02-14) [umoeller] 554 2004 */ 555 2005 -
trunk/src/helpers/xmldefs.c
r36 r38 22 22 23 23 /* 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. 26 57 */ 27 58 28 59 /* 29 60 *@@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). 37 67 * The document entity serves as the root of the entity tree 38 68 * and a starting-point for an XML processor. Unlike other … … 40 70 * appear on a processor input stream without any identification 41 71 * at all. 72 * 73 * Entities are defined to be either parsed or unparsed. 42 74 * 43 75 * Other than that, there are @internal_entities, … … 119 151 * They must be escaped unless used in a @CDATA section. 120 152 * 121 * -- To allow values in an @attributeto contain both single and double153 * -- To allow values in @attributes to contain both single and double 122 154 * quotes, the apostrophe or single-quote character (') may be 123 155 * represented as "&apos;", and the double-quote character 124 156 * (") as "&quot;". 125 157 * 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. 127 159 * 128 160 * An internal entity is always parsed. … … 210 242 * 211 243 * 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. 214 245 * 215 246 * XML "text" consists of markup and @content. … … 226 257 * or may not be interested in white space. Whitespace 227 258 * 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. 229 260 */ 230 261 … … 291 322 + <P /> <IMG align="left" src="http://www.w3.org/Icons/WWW/w3c_home" /> 292 323 * 293 * An @attribute contains additional an parameter to an element.324 * In addition, @attributes contains extra parameters to elements. 294 325 * If the element has attributes, they must be in the start-tag 295 326 * (or empty-element tag). … … 311 342 312 343 /* 313 *@@gloss: attribute attribute344 *@@gloss: attributes attributes 314 345 * "Attributes" are name-value pairs that have been associated 315 346 * with @elements. Attributes can only appear in start-tags … … 370 401 * document's @content; an XML processor may, but 371 402 * 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). 373 404 * 374 405 * Comments may contain any text except "--" (double-hyphen). … … 464 495 *@@gloss: valid valid 465 496 * 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). 467 500 * 468 501 * Validating processors must report violations of the constraints … … 473 506 * referenced in the document. 474 507 * 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, 479 513 * they are required to process all the declarations they 480 514 * read in the internal DTD subset and in any parameter entity … … 482 516 * entity that they do not read; that is to say, they must 483 517 * use the information in those declarations to normalize 484 * @attribute values, include the replacement text of518 * values of @attributes, include the replacement text of 485 519 * @internal_entities, and supply default attribute values. 486 520 * They must not process entity declarations or attribute-list … … 492 526 /* 493 527 *@@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"?> 501 547 * 502 548 * 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. 504 551 * 505 552 * Entities encoded in UTF-16 must begin with the ZERO WIDTH NO-BREAK … … 508 555 * XML processors must be able to use this character to differentiate 509 556 * between UTF-8 and UTF-16 encoded documents. 510 *511 * See XML_ParserCreate for the encodings directly supported512 * by expat.513 557 */ 514 558 … … 576 620 * nature of their content. They look like this: 577 621 + 578 + <!ELEMENT name content model>622 + <!ELEMENT name contentspec> 579 623 + 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" 581 627 * 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: 607 705 * 608 706 * -- Commas (",") indicate that the elements must appear 609 * in the s ame order.707 * in the specified order ("sequence"). 610 708 * 611 709 * -- 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 * 625 748 */ 626 749 … … 754 877 * in whole or in part within @parameter_entities. 755 878 */ 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 5 5 * SourceForge Oct 22, 2000. 6 6 * 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 8 12 * the underlying XML parser for the open source Mozilla project, 9 13 * perl's XML::Parser, and other open-source XML parsers. … … 18 22 * that comes with expat as an HTML file. I (umoeller) 19 23 * 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. 23 31 * 24 32 *@@added V0.9.9 (2001-02-10) [umoeller] 33 *@@header "expat\expat.h" 25 34 */ 26 35 … … 48 57 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 49 58 * 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. 50 64 */ 51 65 … … 95 109 typedef char ICHAR; 96 110 #endif 97 98 111 99 112 #ifndef XML_NS … … 281 294 } OPEN_INTERNAL_ENTITY, *POPEN_INTERNAL_ENTITY; 282 295 283 typedef enum XML_ErrorProcessor(XML_Parser parser,296 typedef XMLERROR Processor(XML_Parser parser, 284 297 const char *start, 285 298 const char *end, … … 302 315 static Processor externalEntityContentProcessor; 303 316 304 static enum XML_ErrorhandleUnknownEncoding(XML_Parser parser,317 static XMLERROR handleUnknownEncoding(XML_Parser parser, 305 318 const XML_Char * encodingName); 306 static enum XML_ErrorprocessXmlDecl(XML_Parser parser,319 static XMLERROR processXmlDecl(XML_Parser parser, 307 320 int isGeneralTextEntity, 308 321 const char *, 309 322 const char *); 310 static enum XML_ErrorinitializeEncoding(XML_Parser parser);311 static enum XML_ErrordoProlog(XML_Parser parser,323 static XMLERROR initializeEncoding(XML_Parser parser); 324 static XMLERROR doProlog(XML_Parser parser, 312 325 const ENCODING * enc, 313 326 const char *s, … … 316 329 const char *next, 317 330 const char **nextPtr); 318 static enum XML_ErrorprocessInternalParamEntity(XML_Parser parser,331 static XMLERROR processInternalParamEntity(XML_Parser parser, 319 332 ENTITY * entity); 320 static enum XML_ErrordoContent(XML_Parser parser,333 static XMLERROR doContent(XML_Parser parser, 321 334 int startTagLevel, 322 335 const ENCODING * enc, … … 324 337 const char *end, 325 338 const char **endPtr); 326 static enum XML_ErrordoCdataSection(XML_Parser parser,339 static XMLERROR doCdataSection(XML_Parser parser, 327 340 const ENCODING *, 328 341 const char **startPtr, … … 331 344 332 345 #ifdef XML_DTD 333 static enum XML_ErrordoIgnoreSection(XML_Parser parser,346 static XMLERROR doIgnoreSection(XML_Parser parser, 334 347 const ENCODING *, 335 348 const char **startPtr, … … 338 351 #endif /* XML_DTD */ 339 352 340 static enum XML_ErrorstoreAtts(XML_Parser parser,353 static XMLERROR storeAtts(XML_Parser parser, 341 354 const ENCODING *, 342 355 const char *s, … … 356 369 XML_Parser parser); 357 370 358 static enum XML_ErrorstoreAttributeValue(XML_Parser parser,371 static XMLERROR storeAttributeValue(XML_Parser parser, 359 372 const ENCODING *, 360 373 int isCdata, … … 362 375 const char *, 363 376 STRING_POOL *); 364 static enum XML_ErrorappendAttributeValue(XML_Parser parser,377 static XMLERROR appendAttributeValue(XML_Parser parser, 365 378 const ENCODING *, 366 379 int isCdata, … … 373 386 const char *end); 374 387 static int setElementTypePrefix(XML_Parser parser, ELEMENT_TYPE *); 375 static enum XML_ErrorstoreEntityValue(XML_Parser parser,388 static XMLERROR storeEntityValue(XML_Parser parser, 376 389 const ENCODING * enc, 377 390 const char *start, … … 426 439 427 440 static int nextScaffoldPart(XML_Parser parser); 428 static XML _Content*build_model(XML_Parser parser);441 static XMLCONTENT *build_model(XML_Parser parser); 429 442 430 443 static const XML_Char *poolCopyString(STRING_POOL * pool, const XML_Char * s); … … 499 512 PROLOG_STATE m_prologState; 500 513 Processor *m_processor; 501 enum XML_Errorm_errorCode;514 XMLERROR m_errorCode; 502 515 const char *m_eventPtr; 503 516 const char *m_eventEndPtr; … … 631 644 *@@ XML_ParserCreate: 632 645 * constructs a new parser. If encoding is non-null, it specifies 633 * a character encoding to use for the document . This overrides634 * the document encoding declaration.646 * a character encoding to use for the document (see below). 647 * This overrides the document encoding declaration. 635 648 * 636 649 * Expat is a stream-oriented parser. You register callback (or … … 638 651 * the document. As the parser recognizes parts of the document, 639 652 * 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, 641 654 * so you can start parsing before you have all the document. 642 655 * This also allows you to parse really huge documents that won't … … 685 698 * 686 699 * The things you're likely to want to keep on a stack are the 687 * currently opened element and it 's attributes. You push this700 * currently opened element and its attributes. You push this 688 701 * information onto the stack in the start handler and you pop 689 702 * it off in the end handler. 690 703 * 691 704 * 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). 693 706 * The outline program shown above presents one example. Another 694 707 * such task would be skipping over a complete element. When you … … 710 723 * While XML is based on Unicode, and every XML processor is 711 724 * required to recognized UTF-8 and UTF-16 (1 and 2 byte 712 * encodings of Unicode), other encodings may be declared in725 * encodings of Unicode), other @encodings may be declared in 713 726 * XML documents or entities. For the main document, an XML 714 727 * 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. 718 730 * 719 731 * With expat, you may also specify an encoding at the time 720 732 * of creating a parser. This is useful when the encoding 721 733 * 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. 744 738 * 745 739 * One pitfall that novice expat users are likely to fall into is … … 751 745 * <B>Handling External Entity References</B> 752 746 * 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> 761 752 * 762 753 * In order to parse @parameter_entities, before starting the parse, … … 933 924 declNotationPublicId = 0; 934 925 memset(&position, 0, sizeof(POSITION)); 935 errorCode = XML_ERROR_NONE;926 errorCode = ERROR_EXPAT_NONE; 936 927 eventPtr = 0; 937 928 eventEndPtr = 0; … … 1349 1340 * This handler must have the following prototype: 1350 1341 * 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); 1354 1345 + 1355 1346 * "data" is the user data pointer set with XML_SetUserData. … … 1398 1389 * Handler prototype: 1399 1390 + 1400 + void EXPATENTRY (void *userData,1401 + const XML_Char *name);1391 + void EXPATENTRY EndElementHandler(void *pUserData, 1392 + const XML_Char *name); 1402 1393 */ 1403 1394 … … 1410 1401 /* 1411 1402 *@@ XML_SetCharacterDataHandler: 1412 * sets a character data (text ) handler.1403 * sets a character data (text, @content) handler. 1413 1404 * 1414 1405 * Handler prototype: 1415 1406 * 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); 1419 1410 + 1420 1411 * The string your handler receives is NOT zero terminated. … … 1438 1429 * Handler prototype: 1439 1430 * 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); 1443 1434 + 1444 1435 * The target is the first word in the processing instruction. The data … … 1460 1451 * Handler prototype: 1461 1452 * 1462 + void EXPATENTRY CommentHandler(void * userData,1463 + const XML_Char *data);1453 + void EXPATENTRY CommentHandler(void *pUserData, 1454 + const XML_Char *data); 1464 1455 * 1465 1456 */ … … 1492 1483 * Handler prototype: 1493 1484 * 1494 + void EXPATENTRY StartCdataSectionHandler(void * userData);1485 + void EXPATENTRY StartCdataSectionHandler(void *pUserData); 1495 1486 * 1496 1487 */ … … 1509 1500 * Handler prototype: 1510 1501 * 1511 * void EXPATENTRY EndCdataSectionHandler(void * userData);1502 * void EXPATENTRY EndCdataSectionHandler(void *pUserData); 1512 1503 */ 1513 1504 … … 1529 1520 * Handler prototype: 1530 1521 + 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); 1534 1525 * 1535 1526 * The characters are passed exactly as they were in the XML … … 1547 1538 * turning off expansion of references to internally defined 1548 1539 * general entities. Instead these references are passed to 1549 * the default handler. 1540 * the default handler. To avoid that, use XML_SetDefaultHandlerExpand. 1550 1541 */ 1551 1542 … … 1594 1585 * Handler prototype: 1595 1586 * 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_subset1587 + 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" 1603 1594 * will be non-zero if the DOCTYPE declaration has an internal subset. 1604 1595 */ … … 1617 1608 * Handler prototype: 1618 1609 * 1619 + void EXPATENTRY EndDoctypeDeclHandler(void * userData);1610 + void EXPATENTRY EndDoctypeDeclHandler(void *pUserData); 1620 1611 * 1621 1612 */ … … 1651 1642 * Handler prototype: 1652 1643 + 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); 1658 1649 + 1659 1650 */ … … 1689 1680 * Handler prototype: 1690 1681 * 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); 1694 1685 + 1695 1686 */ … … 1710 1701 * Handler prototype: 1711 1702 + 1712 + void EXPATENTRY EndNamespaceDeclHandler )(void *userData,1713 + const XML_Char *prefix);1703 + void EXPATENTRY EndNamespaceDeclHandler(void *pUserData, 1704 + const XML_Char *prefix); 1714 1705 */ 1715 1706 … … 1728 1719 * not have standalone set to "yes" in an XML declaration. 1729 1720 * If this handler returns 0, then the parser will throw an 1730 * XML_ERROR_NOT_STANDALONE error.1721 * ERROR_EXPAT_NOT_STANDALONE error. 1731 1722 * 1732 1723 * Handler prototype: 1733 1724 * 1734 + int EXPATENTRY NotStandaloneHandler(void * userData);1725 + int EXPATENTRY NotStandaloneHandler(void *pUserData); 1735 1726 */ 1736 1727 … … 1743 1734 /* 1744 1735 *@@ 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. 1748 1740 * (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. 1749 1746 * 1750 1747 * Handler prototype: 1751 1748 + 1752 1749 + 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); 1757 1754 + 1758 * The context argument specifies the parsing context in the1755 * The pcszContext argument specifies the parsing context in the 1759 1756 * format expected by the context argument to 1760 * XML_ExternalEntityParserCreate; context is valid only until1757 * XML_ExternalEntityParserCreate; pcszContext is valid only until 1761 1758 * the handler returns, so if the referenced entity is to be 1762 1759 * parsed later, it must be copied. 1763 1760 * 1764 * The base parameter is the base to use for relative system1761 * The pcszBase parameter is the base to use for relative system 1765 1762 * identifiers. It is set by XML_SetBase and may be null. 1766 1763 * 1767 * The p ublicId parameter is the public id given in the entity1764 * The pcszPublicId parameter is the public id given in the entity 1768 1765 * declaration and may be null. 1769 1766 * 1770 * The systemId is the system identifier specified in the1767 * The pcszSystemId is the system identifier specified in the 1771 1768 * entity declaration and is never null. 1772 1769 * … … 1776 1773 * of the external entity reference. Returning a zero indicates 1777 1774 * 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, 1781 1778 * it receives the parser that encountered the entity reference. 1782 1779 * This, along with the context parameter, may be used as … … 1790 1787 * Your handler isn't actually responsible for parsing the entity, 1791 1788 * but it is responsible for creating a subsidiary parser with 1792 * XML_ExternalEntityParserCreate that will do the job. Th isreturns1789 * XML_ExternalEntityParserCreate that will do the job. That returns 1793 1790 * an instance of XML_Parser that has handlers and other data 1794 1791 * structures initialized from the parent parser. You may then use 1795 * XML_Parse or XML_ParseBuffer calls against th isparser. Since1792 * XML_Parse or XML_ParseBuffer calls against that parser. Since 1796 1793 * external entities may refer to other external entities, your 1797 1794 * handler should be prepared to be called recursively. … … 1814 1811 /* 1815 1812 *@@ 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. 1818 1829 * 1819 1830 * Handler prototype: 1820 1831 * 1821 1832 + int EXPATENTRY UnknownEncodingHandler(void *encodingHandlerData, 1822 + const XML_Char *name,1823 + XML_Encoding *info);1833 + const XML_Char *name, 1834 + XML_Encoding *info); 1824 1835 + 1825 1836 * The encodingHandlerData argument is that which was passed as the … … 1843 1854 * 1. Every ASCII character that can appear in a well-formed XML 1844 1855 * document must be represented by a single byte, and that byte 1845 * must correspond to it 's ASCII encoding (except for the1856 * must correspond to its ASCII encoding (except for the 1846 1857 * characters $@\^'{}~). 1847 1858 * … … 1852 1863 * the built-in support for UTF-16 and UTF-8.) 1853 1864 * 1854 * 4. No character may be encoded by more tha tone distinct1865 * 4. No character may be encoded by more than one distinct 1855 1866 * sequence of bytes. 1856 1867 */ … … 1866 1877 /* 1867 1878 *@@ XML_SetElementDeclHandler: 1868 * sets a handler for element declarations in aDTD. The1879 * sets a handler for an @element_declaration in a @DTD. The 1869 1880 * handler gets called with the name of the element in 1870 1881 * the declaration and a pointer to a structure that contains … … 1874 1885 * This handler must have the following prototype: 1875 1886 * 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. 1902 1892 */ 1903 1893 … … 1910 1900 /* 1911 1901 *@@ XML_SetAttlistDeclHandler: 1912 * sets a handler for a ttlist declarations in theDTD.1902 * sets a handler for an @attribute_declaration in the @DTD. 1913 1903 * 1914 1904 * This handler must have the following prototype: 1915 1905 * 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); 1922 1912 * 1923 1913 * This handler is called for each attribute. So a single attlist 1924 1914 * 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. 1939 1933 */ 1940 1934 … … 1951 1945 * Handler prototype: 1952 1946 * 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); 1962 1956 + 1963 * The is_parameter_entity argument will be non-zero in the case1957 * The fIsParameterEntity argument will be non-zero in the case 1964 1958 * of parameter entities and zero otherwise. 1965 1959 * 1966 * For internal entities (<!ENTITY foo "bar">), value will be1967 * non-NULL and systemId, publicId, and notationName will all1968 * be NULL. The value string is not NULL terminated; the length1969 * is provided in the value_length parameter. Do not use1970 * value_length to test for internal entities, since it is legal1960 * 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 1971 1965 * 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 for1975 * unparsed entity declarations.1966 * pcszValue is NULL. 1967 * 1968 * The pcszNotationName argument will have a non-NULL value only 1969 * for unparsed entity declarations. 1976 1970 */ 1977 1971 … … 1989 1983 * Handler prototype: 1990 1984 * 1991 + void EXPATENTRY XmlDeclHandler(void *userData,1992 + const XML_Char *version,1993 + const XML_Char *encoding,1994 + intstandalone);1985 + void EXPATENTRY XmlDeclHandler(void *pUserData, 1986 + const XML_Char *pcszVersion, 1987 + const XML_Char *pcszEncoding, 1988 + int standalone); 1995 1989 * 1996 1990 * The way to distinguish is that the version parameter will … … 2010 2004 /* 2011 2005 *@@ 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: 2015 2036 * 2016 2037 * -- 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. 2018 2040 * 2019 2041 * -- XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE: 2020 * Parse parameter entit es and the external subset unless2042 * Parse parameter entities and the external subset unless 2021 2043 * standalone was set to "yes" in the XML declaration. 2022 2044 * … … 2067 2089 return 1; 2068 2090 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) 2071 2096 return 1; 2072 2097 eventEndPtr = eventPtr; … … 2084 2109 if (isFinal) 2085 2110 { 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) 2088 2116 return 1; 2089 2117 eventEndPtr = eventPtr; … … 2092 2120 } 2093 2121 errorCode = processor(parser, s, parseEndPtr = s + len, &end); 2094 if (errorCode != XML_ERROR_NONE)2122 if (errorCode != ERROR_EXPAT_NONE) 2095 2123 { 2096 2124 eventEndPtr = eventPtr; … … 2109 2137 if (!buffer) 2110 2138 { 2111 errorCode = XML_ERROR_NO_MEMORY;2139 errorCode = ERROR_EXPAT_NO_MEMORY; 2112 2140 eventPtr = eventEndPtr = 0; 2113 2141 processor = errorProcessor; … … 2147 2175 errorCode = processor(parser, start, parseEndPtr = bufferEnd, 2148 2176 isFinal ? (const char **)0 : &bufferPtr); 2149 if (errorCode == XML_ERROR_NONE)2177 if (errorCode == ERROR_EXPAT_NONE) 2150 2178 { 2151 2179 if (!isFinal) … … 2236 2264 if (newBuf == 0) 2237 2265 { 2238 errorCode = XML_ERROR_NO_MEMORY;2266 errorCode = ERROR_EXPAT_NO_MEMORY; 2239 2267 return 0; 2240 2268 } … … 2289 2317 */ 2290 2318 2291 enum XML_ErrorXML_GetErrorCode(XML_Parser parser)2319 XMLERROR XML_GetErrorCode(XML_Parser parser) 2292 2320 { 2293 2321 return errorCode; … … 2357 2385 * returns the line number of the position. 2358 2386 * 2359 * Tobe called on parser errors. See XML_GetErrorCode.2387 * Can be called on parser errors. See XML_GetErrorCode. 2360 2388 */ 2361 2389 … … 2375 2403 * line, of the position. 2376 2404 * 2377 * Tobe called on parser errors. See XML_GetErrorCode.2405 * Can be called on parser errors. See XML_GetErrorCode. 2378 2406 */ 2379 2407 … … 2408 2436 2409 2437 /* 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 from2413 * 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 /*2452 2438 *@@ XML_ExpatVersion: 2453 2439 * returns the library version string (e.g. "expat_1.95.1"). … … 2459 2445 } 2460 2446 2461 static enum XML_ErrorcontentProcessor(XML_Parser parser,2447 static XMLERROR contentProcessor(XML_Parser parser, 2462 2448 const char *start, 2463 2449 const char *end, … … 2467 2453 } 2468 2454 2469 static enum XML_ErrorexternalEntityInitProcessor(XML_Parser parser,2455 static XMLERROR externalEntityInitProcessor(XML_Parser parser, 2470 2456 const char *start, 2471 2457 const char *end, 2472 2458 const char **endPtr) 2473 2459 { 2474 enum XML_Errorresult = initializeEncoding(parser);2475 2476 if (result != XML_ERROR_NONE)2460 XMLERROR result = initializeEncoding(parser); 2461 2462 if (result != ERROR_EXPAT_NONE) 2477 2463 return result; 2478 2464 processor = externalEntityInitProcessor2; … … 2480 2466 } 2481 2467 2482 static enum XML_ErrorexternalEntityInitProcessor2(XML_Parser parser,2468 static XMLERROR externalEntityInitProcessor2(XML_Parser parser, 2483 2469 const char *start, 2484 2470 const char *end, … … 2497 2483 { 2498 2484 *endPtr = start; 2499 return XML_ERROR_NONE;2485 return ERROR_EXPAT_NONE; 2500 2486 } 2501 2487 eventPtr = start; 2502 return XML_ERROR_UNCLOSED_TOKEN;2488 return ERROR_EXPAT_UNCLOSED_TOKEN; 2503 2489 case XML_TOK_PARTIAL_CHAR: 2504 2490 if (endPtr) 2505 2491 { 2506 2492 *endPtr = start; 2507 return XML_ERROR_NONE;2493 return ERROR_EXPAT_NONE; 2508 2494 } 2509 2495 eventPtr = start; 2510 return XML_ERROR_PARTIAL_CHAR;2496 return ERROR_EXPAT_PARTIAL_CHAR; 2511 2497 } 2512 2498 processor = externalEntityInitProcessor3; … … 2514 2500 } 2515 2501 2516 static enum XML_ErrorexternalEntityInitProcessor3(XML_Parser parser,2502 static XMLERROR externalEntityInitProcessor3(XML_Parser parser, 2517 2503 const char *start, 2518 2504 const char *end, … … 2526 2512 case XML_TOK_XML_DECL: 2527 2513 { 2528 enum XML_Errorresult = 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) 2531 2517 return result; 2532 2518 start = next; … … 2537 2523 { 2538 2524 *endPtr = start; 2539 return XML_ERROR_NONE;2525 return ERROR_EXPAT_NONE; 2540 2526 } 2541 2527 eventPtr = start; 2542 return XML_ERROR_UNCLOSED_TOKEN;2528 return ERROR_EXPAT_UNCLOSED_TOKEN; 2543 2529 case XML_TOK_PARTIAL_CHAR: 2544 2530 if (endPtr) 2545 2531 { 2546 2532 *endPtr = start; 2547 return XML_ERROR_NONE;2533 return ERROR_EXPAT_NONE; 2548 2534 } 2549 2535 eventPtr = start; 2550 return XML_ERROR_PARTIAL_CHAR;2536 return ERROR_EXPAT_PARTIAL_CHAR; 2551 2537 } 2552 2538 processor = externalEntityContentProcessor; … … 2555 2541 } 2556 2542 2557 static enum XML_ErrorexternalEntityContentProcessor(XML_Parser parser,2543 static XMLERROR externalEntityContentProcessor(XML_Parser parser, 2558 2544 const char *start, 2559 2545 const char *end, … … 2563 2549 } 2564 2550 2565 static enum XML_Error2551 static XMLERROR 2566 2552 doContent(XML_Parser parser, 2567 2553 int startTagLevel, … … 2597 2583 { 2598 2584 *nextPtr = s; 2599 return XML_ERROR_NONE;2585 return ERROR_EXPAT_NONE; 2600 2586 } 2601 2587 *eventEndPP = end; … … 2609 2595 reportDefault(parser, enc, s, end); 2610 2596 if (startTagLevel == 0) 2611 return XML_ERROR_NO_ELEMENTS;2597 return ERROR_EXPAT_NO_ELEMENTS; 2612 2598 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; 2615 2601 case XML_TOK_NONE: 2616 2602 if (nextPtr) 2617 2603 { 2618 2604 *nextPtr = s; 2619 return XML_ERROR_NONE;2605 return ERROR_EXPAT_NONE; 2620 2606 } 2621 2607 if (startTagLevel > 0) 2622 2608 { 2623 2609 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; 2628 2614 case XML_TOK_INVALID: 2629 2615 *eventPP = next; 2630 return XML_ERROR_INVALID_TOKEN;2616 return ERROR_EXPAT_INVALID_TOKEN; 2631 2617 case XML_TOK_PARTIAL: 2632 2618 if (nextPtr) 2633 2619 { 2634 2620 *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; 2638 2624 case XML_TOK_PARTIAL_CHAR: 2639 2625 if (nextPtr) 2640 2626 { 2641 2627 *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; 2645 2631 case XML_TOK_ENTITY_REF: 2646 2632 { … … 2663 2649 next - enc->minBytesPerChar); 2664 2650 if (!name) 2665 return XML_ERROR_NO_MEMORY;2651 return ERROR_EXPAT_NO_MEMORY; 2666 2652 entity = (ENTITY*)lookup(&dtd.generalEntities, name, 0); 2667 2653 poolDiscard(&dtd.pool); … … 2669 2655 { 2670 2656 if (dtd.complete || dtd.standalone) 2671 return XML_ERROR_UNDEFINED_ENTITY;2657 return ERROR_EXPAT_UNDEFINED_ENTITY; 2672 2658 if (defaultHandler) 2673 2659 reportDefault(parser, enc, s, next); … … 2675 2661 } 2676 2662 if (entity->open) 2677 return XML_ERROR_RECURSIVE_ENTITY_REF;2663 return ERROR_EXPAT_RECURSIVE_ENTITY_REF; 2678 2664 if (entity->notation) 2679 return XML_ERROR_BINARY_ENTITY_REF;2665 return ERROR_EXPAT_BINARY_ENTITY_REF; 2680 2666 if (entity) 2681 2667 { 2682 2668 if (entity->textPtr) 2683 2669 { 2684 enum XML_Errorresult;2670 XMLERROR result; 2685 2671 OPEN_INTERNAL_ENTITY openEntity; 2686 2672 … … 2715 2701 entity->open = 0; 2716 2702 if (!context) 2717 return XML_ERROR_NO_MEMORY;2703 return ERROR_EXPAT_NO_MEMORY; 2718 2704 if (!externalEntityRefHandler(externalEntityRefHandlerArg, 2719 2705 context, … … 2721 2707 entity->systemId, 2722 2708 entity->publicId)) 2723 return XML_ERROR_EXTERNAL_ENTITY_HANDLING;2709 return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING; 2724 2710 poolDiscard(&tempPool); 2725 2711 } … … 2732 2718 if (!startElementHandler) 2733 2719 { 2734 enum XML_Errorresult = storeAtts(parser, enc, s, 0, 0);2720 XMLERROR result = storeAtts(parser, enc, s, 0, 0); 2735 2721 2736 2722 if (result) … … 2751 2737 tag = (TAG*)MALLOC(sizeof(TAG)); 2752 2738 if (!tag) 2753 return XML_ERROR_NO_MEMORY;2739 return ERROR_EXPAT_NO_MEMORY; 2754 2740 tag->buf = (char*)MALLOC(INIT_TAG_BUF_SIZE); 2755 2741 if (!tag->buf) 2756 return XML_ERROR_NO_MEMORY;2742 return ERROR_EXPAT_NO_MEMORY; 2757 2743 tag->bufEnd = tag->buf + INIT_TAG_BUF_SIZE; 2758 2744 } … … 2774 2760 tag->buf = (char*)REALLOC(tag->buf, bufSize); 2775 2761 if (!tag->buf) 2776 return XML_ERROR_NO_MEMORY;2762 return ERROR_EXPAT_NO_MEMORY; 2777 2763 tag->bufEnd = tag->buf + bufSize; 2778 2764 } … … 2783 2769 if (startElementHandler) 2784 2770 { 2785 enum XML_Errorresult;2771 XMLERROR result; 2786 2772 XML_Char *toPtr; 2787 2773 … … 2805 2791 tag->buf = (char*)REALLOC(tag->buf, bufSize); 2806 2792 if (!tag->buf) 2807 return XML_ERROR_NO_MEMORY;2793 return ERROR_EXPAT_NO_MEMORY; 2808 2794 tag->bufEnd = tag->buf + bufSize; 2809 2795 if (nextPtr) … … 2828 2814 if (!startElementHandler) 2829 2815 { 2830 enum XML_Errorresult = storeAtts(parser, enc, s, 0, 0);2816 XMLERROR result = storeAtts(parser, enc, s, 0, 0); 2831 2817 2832 2818 if (result) … … 2838 2824 { 2839 2825 const char *rawName = s + enc->minBytesPerChar; 2840 enum XML_Errorresult;2826 XMLERROR result; 2841 2827 BINDING *bindings = 0; 2842 2828 TAG_NAME name; … … 2845 2831 rawName + XmlNameLength(enc, rawName)); 2846 2832 if (!name.str) 2847 return XML_ERROR_NO_MEMORY;2833 return ERROR_EXPAT_NO_MEMORY; 2848 2834 poolFinish(&tempPool); 2849 2835 result = storeAtts(parser, enc, s, &name, &bindings); … … 2879 2865 case XML_TOK_END_TAG: 2880 2866 if (tagLevel == startTagLevel) 2881 return XML_ERROR_ASYNC_ENTITY;2867 return ERROR_EXPAT_ASYNC_ENTITY; 2882 2868 else 2883 2869 { … … 2895 2881 { 2896 2882 *eventPP = rawName; 2897 return XML_ERROR_TAG_MISMATCH;2883 return ERROR_EXPAT_TAG_MISMATCH; 2898 2884 } 2899 2885 --tagLevel; … … 2932 2918 2933 2919 if (n < 0) 2934 return XML_ERROR_BAD_CHAR_REF;2920 return ERROR_EXPAT_BAD_CHAR_REF; 2935 2921 if (characterDataHandler) 2936 2922 { … … 2944 2930 break; 2945 2931 case XML_TOK_XML_DECL: 2946 return XML_ERROR_MISPLACED_XML_PI;2932 return ERROR_EXPAT_MISPLACED_XML_PI; 2947 2933 case XML_TOK_DATA_NEWLINE: 2948 2934 if (characterDataHandler) … … 2957 2943 case XML_TOK_CDATA_SECT_OPEN: 2958 2944 { 2959 enum XML_Errorresult;2945 XMLERROR result; 2960 2946 2961 2947 if (startCdataSectionHandler) … … 2990 2976 { 2991 2977 *nextPtr = s; 2992 return XML_ERROR_NONE;2978 return ERROR_EXPAT_NONE; 2993 2979 } 2994 2980 if (characterDataHandler) … … 3011 2997 { 3012 2998 *eventPP = end; 3013 return XML_ERROR_NO_ELEMENTS;2999 return ERROR_EXPAT_NO_ELEMENTS; 3014 3000 } 3015 3001 if (tagLevel != startTagLevel) 3016 3002 { 3017 3003 *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; 3021 3007 case XML_TOK_DATA_CHARS: 3022 3008 if (characterDataHandler) … … 3046 3032 case XML_TOK_PI: 3047 3033 if (!reportProcessingInstruction(parser, enc, s, next)) 3048 return XML_ERROR_NO_MEMORY;3034 return ERROR_EXPAT_NO_MEMORY; 3049 3035 break; 3050 3036 case XML_TOK_COMMENT: 3051 3037 if (!reportComment(parser, enc, s, next)) 3052 return XML_ERROR_NO_MEMORY;3038 return ERROR_EXPAT_NO_MEMORY; 3053 3039 break; 3054 3040 default: … … 3065 3051 * otherwise just check the attributes for well-formedness. */ 3066 3052 3067 static enum XML_ErrorstoreAtts(XML_Parser parser,3053 static XMLERROR storeAtts(XML_Parser parser, 3068 3054 const ENCODING * enc, 3069 3055 const char *attStr, … … 3089 3075 tagNamePtr->str = poolCopyString(&dtd.pool, tagNamePtr->str); 3090 3076 if (!tagNamePtr->str) 3091 return XML_ERROR_NO_MEMORY;3077 return ERROR_EXPAT_NO_MEMORY; 3092 3078 elementType = (ELEMENT_TYPE*)lookup(&dtd.elementTypes, tagNamePtr->str, sizeof(ELEMENT_TYPE)); 3093 3079 if (!elementType) 3094 return XML_ERROR_NO_MEMORY;3080 return ERROR_EXPAT_NO_MEMORY; 3095 3081 if (ns && !setElementTypePrefix(parser, elementType)) 3096 return XML_ERROR_NO_MEMORY;3082 return ERROR_EXPAT_NO_MEMORY; 3097 3083 } 3098 3084 nDefaultAtts = elementType->nDefaultAtts; … … 3107 3093 atts = (PATTRIBUTE)REALLOC((void *)atts, attsSize * sizeof(ATTRIBUTE)); 3108 3094 if (!atts) 3109 return XML_ERROR_NO_MEMORY;3095 return ERROR_EXPAT_NO_MEMORY; 3110 3096 if (n > oldAttsSize) 3111 3097 XmlGetAttributes(enc, attStr, n, atts); … … 3120 3106 3121 3107 if (!attId) 3122 return XML_ERROR_NO_MEMORY;3108 return ERROR_EXPAT_NO_MEMORY; 3123 3109 /* detect duplicate attributes */ 3124 3110 if ((attId->name)[-1]) … … 3126 3112 if (enc == encoding) 3127 3113 eventPtr = atts[i].name; 3128 return XML_ERROR_DUPLICATE_ATTRIBUTE;3114 return ERROR_EXPAT_DUPLICATE_ATTRIBUTE; 3129 3115 } 3130 3116 (attId->name)[-1] = 1; … … 3132 3118 if (!atts[i].normalized) 3133 3119 { 3134 enum XML_Errorresult;3120 XMLERROR result; 3135 3121 int isCdata = 1; 3136 3122 … … 3169 3155 appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr, atts[i].valueEnd); 3170 3156 if (appAtts[attIndex] == 0) 3171 return XML_ERROR_NO_MEMORY;3157 return ERROR_EXPAT_NO_MEMORY; 3172 3158 poolFinish(&tempPool); 3173 3159 } … … 3179 3165 /* deal with namespace declarations here */ 3180 3166 if (!addBinding(parser, attId->prefix, attId, appAtts[attIndex], bindingsPtr)) 3181 return XML_ERROR_NO_MEMORY;3167 return ERROR_EXPAT_NO_MEMORY; 3182 3168 --attIndex; 3183 3169 } … … 3221 3207 { 3222 3208 if (!addBinding(parser, da->id->prefix, da->id, da->value, bindingsPtr)) 3223 return XML_ERROR_NO_MEMORY;3209 return ERROR_EXPAT_NO_MEMORY; 3224 3210 } 3225 3211 else … … 3262 3248 { 3263 3249 if (!poolAppendChar(&tempPool, b->uri[j])) 3264 return XML_ERROR_NO_MEMORY;3250 return ERROR_EXPAT_NO_MEMORY; 3265 3251 } 3266 3252 while (*s++ != ':') … … 3269 3255 { 3270 3256 if (!poolAppendChar(&tempPool, *s)) 3271 return XML_ERROR_NO_MEMORY;3257 return ERROR_EXPAT_NO_MEMORY; 3272 3258 } 3273 3259 while (*s++); … … 3279 3265 { 3280 3266 if (!poolAppendChar(&tempPool, *s)) 3281 return XML_ERROR_NO_MEMORY;3267 return ERROR_EXPAT_NO_MEMORY; 3282 3268 } 3283 3269 while (*s++); … … 3298 3284 ((XML_Char*)(appAtts[i]))[-1] = 0; 3299 3285 if (!tagNamePtr) 3300 return XML_ERROR_NONE;3286 return ERROR_EXPAT_NONE; 3301 3287 for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding) 3302 3288 binding->attId->name[-1] = 0; … … 3306 3292 binding = elementType->prefix->binding; 3307 3293 if (!binding) 3308 return XML_ERROR_NONE;3294 return ERROR_EXPAT_NONE; 3309 3295 localPart = tagNamePtr->str; 3310 3296 while (*localPart++ != XML_T(':')) … … 3317 3303 } 3318 3304 else 3319 return XML_ERROR_NONE;3305 return ERROR_EXPAT_NONE; 3320 3306 tagNamePtr->localPart = localPart; 3321 3307 tagNamePtr->uriLen = binding->uriLen; … … 3329 3315 3330 3316 if (!uri) 3331 return XML_ERROR_NO_MEMORY;3317 return ERROR_EXPAT_NO_MEMORY; 3332 3318 binding->uriAlloc = n + EXPAND_SPARE; 3333 3319 memcpy(uri, binding->uri, binding->uriLen * sizeof(XML_Char)); … … 3340 3326 memcpy(binding->uri + binding->uriLen, localPart, i * sizeof(XML_Char)); 3341 3327 tagNamePtr->str = binding->uri; 3342 return XML_ERROR_NONE;3328 return ERROR_EXPAT_NONE; 3343 3329 } 3344 3330 … … 3399 3385 * the whole file is parsed with one call. */ 3400 3386 3401 static enum XML_ErrorcdataSectionProcessor(XML_Parser parser,3387 static XMLERROR cdataSectionProcessor(XML_Parser parser, 3402 3388 const char *start, 3403 3389 const char *end, 3404 3390 const char **endPtr) 3405 3391 { 3406 enum XML_Errorresult = doCdataSection(parser, encoding, &start, end, endPtr);3392 XMLERROR result = doCdataSection(parser, encoding, &start, end, endPtr); 3407 3393 3408 3394 if (start) … … 3417 3403 * the section is not yet closed. */ 3418 3404 3419 static enum XML_ErrordoCdataSection(XML_Parser parser,3405 static XMLERROR doCdataSection(XML_Parser parser, 3420 3406 const ENCODING * enc, 3421 3407 const char **startPtr, … … 3459 3445 reportDefault(parser, enc, s, next); 3460 3446 *startPtr = next; 3461 return XML_ERROR_NONE;3447 return ERROR_EXPAT_NONE; 3462 3448 case XML_TOK_DATA_NEWLINE: 3463 3449 if (characterDataHandler) … … 3497 3483 case XML_TOK_INVALID: 3498 3484 *eventPP = next; 3499 return XML_ERROR_INVALID_TOKEN;3485 return ERROR_EXPAT_INVALID_TOKEN; 3500 3486 case XML_TOK_PARTIAL_CHAR: 3501 3487 if (nextPtr) 3502 3488 { 3503 3489 *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; 3507 3493 case XML_TOK_PARTIAL: 3508 3494 case XML_TOK_NONE: … … 3510 3496 { 3511 3497 *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; 3515 3501 default: 3516 3502 *eventPP = next; 3517 return XML_ERROR_UNEXPECTED_STATE;3503 return ERROR_EXPAT_UNEXPECTED_STATE; 3518 3504 } 3519 3505 *eventPP = s = next; … … 3527 3513 * the whole file is parsed with one call. */ 3528 3514 3529 static enum XML_ErrorignoreSectionProcessor(XML_Parser parser,3515 static XMLERROR ignoreSectionProcessor(XML_Parser parser, 3530 3516 const char *start, 3531 3517 const char *end, 3532 3518 const char **endPtr) 3533 3519 { 3534 enum XML_Errorresult = doIgnoreSection(parser, encoding, &start, end, endPtr);3520 XMLERROR result = doIgnoreSection(parser, encoding, &start, end, endPtr); 3535 3521 3536 3522 if (start) … … 3545 3531 * the section is not yet closed. */ 3546 3532 3547 static enum XML_ErrordoIgnoreSection(XML_Parser parser,3533 static XMLERROR doIgnoreSection(XML_Parser parser, 3548 3534 const ENCODING * enc, 3549 3535 const char **startPtr, … … 3578 3564 reportDefault(parser, enc, s, next); 3579 3565 *startPtr = next; 3580 return XML_ERROR_NONE;3566 return ERROR_EXPAT_NONE; 3581 3567 case XML_TOK_INVALID: 3582 3568 *eventPP = next; 3583 return XML_ERROR_INVALID_TOKEN;3569 return ERROR_EXPAT_INVALID_TOKEN; 3584 3570 case XML_TOK_PARTIAL_CHAR: 3585 3571 if (nextPtr) 3586 3572 { 3587 3573 *nextPtr = s; 3588 return XML_ERROR_NONE;3574 return ERROR_EXPAT_NONE; 3589 3575 } 3590 return XML_ERROR_PARTIAL_CHAR;3576 return ERROR_EXPAT_PARTIAL_CHAR; 3591 3577 case XML_TOK_PARTIAL: 3592 3578 case XML_TOK_NONE: … … 3594 3580 { 3595 3581 *nextPtr = s; 3596 return XML_ERROR_NONE;3582 return ERROR_EXPAT_NONE; 3597 3583 } 3598 return XML_ERROR_SYNTAX; /* XML_ERROR_UNCLOSED_IGNORE_SECTION */3584 return ERROR_EXPAT_SYNTAX; /* ERROR_EXPAT_UNCLOSED_IGNORE_SECTION */ 3599 3585 default: 3600 3586 *eventPP = next; 3601 return XML_ERROR_UNEXPECTED_STATE;3587 return ERROR_EXPAT_UNEXPECTED_STATE; 3602 3588 } 3603 3589 /* not reached */ … … 3606 3592 #endif /* XML_DTD */ 3607 3593 3608 static enum XML_ErrorinitializeEncoding(XML_Parser parser)3594 static XMLERROR initializeEncoding(XML_Parser parser) 3609 3595 { 3610 3596 const char *s; … … 3636 3622 #endif 3637 3623 if ((ns ? XmlInitEncodingNS : XmlInitEncoding) (&initEncoding, &encoding, s)) 3638 return XML_ERROR_NONE;3624 return ERROR_EXPAT_NONE; 3639 3625 return handleUnknownEncoding(parser, protocolEncodingName); 3640 3626 } 3641 3627 3642 static enum XML_ErrorprocessXmlDecl(XML_Parser parser, int isGeneralTextEntity,3628 static XMLERROR processXmlDecl(XML_Parser parser, int isGeneralTextEntity, 3643 3629 const char *s, const char *next) 3644 3630 { … … 3663 3649 &newEncoding, 3664 3650 &standalone)) 3665 return XML_ERROR_SYNTAX;3651 return ERROR_EXPAT_SYNTAX; 3666 3652 if (!isGeneralTextEntity && standalone == 1) 3667 3653 { … … 3682 3668 + XmlNameLength(encoding, encodingName)); 3683 3669 if (!storedEncName) 3684 return XML_ERROR_NO_MEMORY;3670 return ERROR_EXPAT_NO_MEMORY; 3685 3671 poolFinish(&temp2Pool); 3686 3672 } … … 3692 3678 versionend - encoding->minBytesPerChar); 3693 3679 if (!storedversion) 3694 return XML_ERROR_NO_MEMORY;3680 return ERROR_EXPAT_NO_MEMORY; 3695 3681 } 3696 3682 xmlDeclHandler(handlerArg, storedversion, storedEncName, standalone); … … 3705 3691 { 3706 3692 eventPtr = encodingName; 3707 return XML_ERROR_INCORRECT_ENCODING;3693 return ERROR_EXPAT_INCORRECT_ENCODING; 3708 3694 } 3709 3695 encoding = newEncoding; … … 3711 3697 else if (encodingName) 3712 3698 { 3713 enum XML_Errorresult;3699 XMLERROR result; 3714 3700 3715 3701 if (!storedEncName) … … 3721 3707 + XmlNameLength(encoding, encodingName)); 3722 3708 if (!storedEncName) 3723 return XML_ERROR_NO_MEMORY;3709 return ERROR_EXPAT_NO_MEMORY; 3724 3710 } 3725 3711 result = handleUnknownEncoding(parser, storedEncName); 3726 3712 poolClear(&tempPool); 3727 if (result == XML_ERROR_UNKNOWN_ENCODING)3713 if (result == ERROR_EXPAT_UNKNOWN_ENCODING) 3728 3714 eventPtr = encodingName; 3729 3715 return result; … … 3734 3720 poolClear(&temp2Pool); 3735 3721 3736 return XML_ERROR_NONE;3737 } 3738 3739 static enum XML_ErrorhandleUnknownEncoding(XML_Parser parser,3722 return ERROR_EXPAT_NONE; 3723 } 3724 3725 static XMLERROR handleUnknownEncoding(XML_Parser parser, 3740 3726 const XML_Char* encodingName) 3741 3727 { … … 3761 3747 if (info.release) 3762 3748 info.release(info.data); 3763 return XML_ERROR_NO_MEMORY;3749 return ERROR_EXPAT_NO_MEMORY; 3764 3750 } 3765 3751 enc = (ns … … 3774 3760 unknownEncodingRelease = info.release; 3775 3761 encoding = enc; 3776 return XML_ERROR_NONE;3762 return ERROR_EXPAT_NONE; 3777 3763 } 3778 3764 } … … 3780 3766 info.release(info.data); 3781 3767 } 3782 return XML_ERROR_UNKNOWN_ENCODING;3783 } 3784 3785 static enum XML_ErrorprologInitProcessor(XML_Parser parser,3768 return ERROR_EXPAT_UNKNOWN_ENCODING; 3769 } 3770 3771 static XMLERROR prologInitProcessor(XML_Parser parser, 3786 3772 const char *s, 3787 3773 const char *end, 3788 3774 const char **nextPtr) 3789 3775 { 3790 enum XML_Errorresult = initializeEncoding(parser);3791 3792 if (result != XML_ERROR_NONE)3776 XMLERROR result = initializeEncoding(parser); 3777 3778 if (result != ERROR_EXPAT_NONE) 3793 3779 return result; 3794 3780 processor = prologProcessor; … … 3796 3782 } 3797 3783 3798 static enum XML_ErrorprologProcessor(XML_Parser parser,3784 static XMLERROR prologProcessor(XML_Parser parser, 3799 3785 const char *s, 3800 3786 const char *end, … … 3807 3793 } 3808 3794 3809 static enum XML_ErrordoProlog(XML_Parser parser,3795 static XMLERROR doProlog(XML_Parser parser, 3810 3796 const ENCODING * enc, 3811 3797 const char *s, … … 3846 3832 { 3847 3833 *nextPtr = s; 3848 return XML_ERROR_NONE;3834 return ERROR_EXPAT_NONE; 3849 3835 } 3850 3836 switch (tok) … … 3852 3838 case XML_TOK_INVALID: 3853 3839 *eventPP = next; 3854 return XML_ERROR_INVALID_TOKEN;3840 return ERROR_EXPAT_INVALID_TOKEN; 3855 3841 case XML_TOK_PARTIAL: 3856 return XML_ERROR_UNCLOSED_TOKEN;3842 return ERROR_EXPAT_UNCLOSED_TOKEN; 3857 3843 case XML_TOK_PARTIAL_CHAR: 3858 return XML_ERROR_PARTIAL_CHAR;3844 return ERROR_EXPAT_PARTIAL_CHAR; 3859 3845 case XML_TOK_NONE: 3860 3846 #ifdef XML_DTD 3861 3847 if (enc != encoding) 3862 return XML_ERROR_NONE;3848 return ERROR_EXPAT_NONE; 3863 3849 if (parentParser) 3864 3850 { 3865 3851 if (XmlTokenRole(&prologState, XML_TOK_NONE, end, end, enc) 3866 3852 == XML_ROLE_ERROR) 3867 return XML_ERROR_SYNTAX;3853 return ERROR_EXPAT_SYNTAX; 3868 3854 hadExternalDoctype = 0; 3869 return XML_ERROR_NONE;3855 return ERROR_EXPAT_NONE; 3870 3856 } 3871 3857 #endif /* XML_DTD */ 3872 return XML_ERROR_NO_ELEMENTS;3858 return ERROR_EXPAT_NO_ELEMENTS; 3873 3859 default: 3874 3860 tok = -tok; … … 3882 3868 case XML_ROLE_XML_DECL: 3883 3869 { 3884 enum XML_Errorresult = 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) 3887 3873 return result; 3888 3874 enc = encoding; … … 3894 3880 doctypeName = poolStoreString(&tempPool, enc, s, next); 3895 3881 if (!doctypeName) 3896 return XML_ERROR_NO_MEMORY;3882 return ERROR_EXPAT_NO_MEMORY; 3897 3883 poolFinish(&tempPool); 3898 3884 doctypeSysid = 0; … … 3912 3898 case XML_ROLE_TEXT_DECL: 3913 3899 { 3914 enum XML_Errorresult = 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) 3917 3903 return result; 3918 3904 enc = encoding; … … 3925 3911 doctypePubid = poolStoreString(&tempPool, enc, s + 1, next - 1); 3926 3912 if (!doctypePubid) 3927 return XML_ERROR_NO_MEMORY;3913 return ERROR_EXPAT_NO_MEMORY; 3928 3914 poolFinish(&tempPool); 3929 3915 } … … 3933 3919 sizeof(ENTITY)); 3934 3920 if (!declEntity) 3935 return XML_ERROR_NO_MEMORY;3921 return ERROR_EXPAT_NO_MEMORY; 3936 3922 #endif /* XML_DTD */ 3937 3923 /* fall through */ 3938 3924 case XML_ROLE_ENTITY_PUBLIC_ID: 3939 3925 if (!XmlIsPublicId(enc, s, next, eventPP)) 3940 return XML_ERROR_SYNTAX;3926 return ERROR_EXPAT_SYNTAX; 3941 3927 if (declEntity) 3942 3928 { … … 3947 3933 3948 3934 if (!tem) 3949 return XML_ERROR_NO_MEMORY;3935 return ERROR_EXPAT_NO_MEMORY; 3950 3936 normalizePublicId(tem); 3951 3937 declEntity->publicId = tem; … … 3975 3961 entity->systemId, 3976 3962 entity->publicId)) 3977 return XML_ERROR_EXTERNAL_ENTITY_HANDLING;3963 return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING; 3978 3964 } 3979 3965 #endif /* XML_DTD */ … … 3982 3968 && notStandaloneHandler 3983 3969 && !notStandaloneHandler(handlerArg)) 3984 return XML_ERROR_NOT_STANDALONE;3970 return ERROR_EXPAT_NOT_STANDALONE; 3985 3971 } 3986 3972 if (endDoctypeDeclHandler) … … 3993 3979 declElementType = getElementType(parser, enc, s, next); 3994 3980 if (!declElementType) 3995 return XML_ERROR_NO_MEMORY;3981 return ERROR_EXPAT_NO_MEMORY; 3996 3982 break; 3997 3983 case XML_ROLE_ATTRIBUTE_NAME: 3998 3984 declAttributeId = getAttributeId(parser, enc, s, next); 3999 3985 if (!declAttributeId) 4000 return XML_ERROR_NO_MEMORY;3986 return ERROR_EXPAT_NO_MEMORY; 4001 3987 declAttributeIsCdata = 0; 4002 3988 declAttributeType = 0; … … 4047 4033 } 4048 4034 if (!poolAppendString(&tempPool, prefix)) 4049 return XML_ERROR_NO_MEMORY;4035 return ERROR_EXPAT_NO_MEMORY; 4050 4036 if (!poolAppend(&tempPool, enc, s, next)) 4051 return XML_ERROR_NO_MEMORY;4037 return ERROR_EXPAT_NO_MEMORY; 4052 4038 declAttributeType = tempPool.start; 4053 4039 } … … 4059 4045 declAttributeIsCdata, declAttributeIsId, 0, 4060 4046 parser)) 4061 return XML_ERROR_NO_MEMORY;4047 return ERROR_EXPAT_NO_MEMORY; 4062 4048 if (attlistDeclHandler && declAttributeType) 4063 4049 { … … 4068 4054 if (!poolAppendChar(&tempPool, ')') 4069 4055 || !poolAppendChar(&tempPool, '\0')) 4070 return XML_ERROR_NO_MEMORY;4056 return ERROR_EXPAT_NO_MEMORY; 4071 4057 declAttributeType = tempPool.start; 4072 4058 poolFinish(&tempPool); … … 4083 4069 { 4084 4070 const XML_Char *attVal; 4085 enum XML_Errorresult4071 XMLERROR result 4086 4072 = storeAttributeValue(parser, enc, declAttributeIsCdata, 4087 4073 s + enc->minBytesPerChar, … … 4096 4082 /* ID attributes aren't allowed to have a default */ 4097 4083 && !defineAttribute(declElementType, declAttributeId, declAttributeIsCdata, 0, attVal, parser)) 4098 return XML_ERROR_NO_MEMORY;4084 return ERROR_EXPAT_NO_MEMORY; 4099 4085 if (attlistDeclHandler && declAttributeType) 4100 4086 { … … 4105 4091 if (!poolAppendChar(&tempPool, ')') 4106 4092 || !poolAppendChar(&tempPool, '\0')) 4107 return XML_ERROR_NO_MEMORY;4093 return ERROR_EXPAT_NO_MEMORY; 4108 4094 declAttributeType = tempPool.start; 4109 4095 poolFinish(&tempPool); … … 4120 4106 case XML_ROLE_ENTITY_VALUE: 4121 4107 { 4122 enum XML_Errorresult = storeEntityValue(parser, enc,4108 XMLERROR result = storeEntityValue(parser, enc, 4123 4109 s + enc->minBytesPerChar, 4124 4110 next - enc->minBytesPerChar); … … 4142 4128 else 4143 4129 poolDiscard(&dtd.pool); 4144 if (result != XML_ERROR_NONE)4130 if (result != ERROR_EXPAT_NONE) 4145 4131 return result; 4146 4132 } … … 4151 4137 doctypeSysid = poolStoreString(&tempPool, enc, s + 1, next - 1); 4152 4138 if (!doctypeSysid) 4153 return XML_ERROR_NO_MEMORY;4139 return ERROR_EXPAT_NO_MEMORY; 4154 4140 poolFinish(&tempPool); 4155 4141 } … … 4160 4146 && notStandaloneHandler 4161 4147 && !notStandaloneHandler(handlerArg)) 4162 return XML_ERROR_NOT_STANDALONE;4148 return ERROR_EXPAT_NOT_STANDALONE; 4163 4149 hadExternalDoctype = 1; 4164 4150 #ifndef XML_DTD … … 4172 4158 declEntity->publicId = 0; 4173 4159 if (!declEntity) 4174 return XML_ERROR_NO_MEMORY;4160 return ERROR_EXPAT_NO_MEMORY; 4175 4161 } 4176 4162 /* fall through */ … … 4183 4169 next - enc->minBytesPerChar); 4184 4170 if (!declEntity->systemId) 4185 return XML_ERROR_NO_MEMORY;4171 return ERROR_EXPAT_NO_MEMORY; 4186 4172 declEntity->base = curBase; 4187 4173 poolFinish(&dtd.pool); … … 4206 4192 declEntity->notation = poolStoreString(&dtd.pool, enc, s, next); 4207 4193 if (!declEntity->notation) 4208 return XML_ERROR_NO_MEMORY;4194 return ERROR_EXPAT_NO_MEMORY; 4209 4195 poolFinish(&dtd.pool); 4210 4196 if (unparsedEntityDeclHandler) … … 4242 4228 name = poolStoreString(&dtd.pool, enc, s, next); 4243 4229 if (!name) 4244 return XML_ERROR_NO_MEMORY;4230 return ERROR_EXPAT_NO_MEMORY; 4245 4231 if (dtd.complete) 4246 4232 { 4247 4233 declEntity = (ENTITY*)lookup(&dtd.generalEntities, name, sizeof(ENTITY)); 4248 4234 if (!declEntity) 4249 return XML_ERROR_NO_MEMORY;4235 return ERROR_EXPAT_NO_MEMORY; 4250 4236 if (declEntity->name != name) 4251 4237 { … … 4274 4260 4275 4261 if (!name) 4276 return XML_ERROR_NO_MEMORY;4262 return ERROR_EXPAT_NO_MEMORY; 4277 4263 declEntity = (ENTITY*)lookup(&dtd.paramEntities, 4278 4264 name, sizeof(ENTITY)); 4279 4265 if (!declEntity) 4280 return XML_ERROR_NO_MEMORY;4266 return ERROR_EXPAT_NO_MEMORY; 4281 4267 if (declEntity->name != name) 4282 4268 { … … 4302 4288 declNotationName = poolStoreString(&tempPool, enc, s, next); 4303 4289 if (!declNotationName) 4304 return XML_ERROR_NO_MEMORY;4290 return ERROR_EXPAT_NO_MEMORY; 4305 4291 poolFinish(&tempPool); 4306 4292 } … … 4308 4294 case XML_ROLE_NOTATION_PUBLIC_ID: 4309 4295 if (!XmlIsPublicId(enc, s, next, eventPP)) 4310 return XML_ERROR_SYNTAX;4296 return ERROR_EXPAT_SYNTAX; 4311 4297 if (declNotationName) 4312 4298 { … … 4317 4303 4318 4304 if (!tem) 4319 return XML_ERROR_NO_MEMORY;4305 return ERROR_EXPAT_NO_MEMORY; 4320 4306 normalizePublicId(tem); 4321 4307 declNotationPublicId = tem; … … 4332 4318 4333 4319 if (!systemId) 4334 return XML_ERROR_NO_MEMORY;4320 return ERROR_EXPAT_NO_MEMORY; 4335 4321 *eventEndPP = s; 4336 4322 notationDeclHandler(handlerArg, … … 4358 4344 { 4359 4345 case XML_TOK_PARAM_ENTITY_REF: 4360 return XML_ERROR_PARAM_ENTITY_REF;4346 return ERROR_EXPAT_PARAM_ENTITY_REF; 4361 4347 case XML_TOK_XML_DECL: 4362 return XML_ERROR_MISPLACED_XML_PI;4348 return ERROR_EXPAT_MISPLACED_XML_PI; 4363 4349 default: 4364 return XML_ERROR_SYNTAX;4350 return ERROR_EXPAT_SYNTAX; 4365 4351 } 4366 4352 #ifdef XML_DTD 4367 4353 case XML_ROLE_IGNORE_SECT: 4368 4354 { 4369 enum XML_Errorresult;4355 XMLERROR result; 4370 4356 4371 4357 if (defaultHandler) … … 4392 4378 groupConnector = (char*)MALLOC(groupSize = 32); 4393 4379 if (!groupConnector) 4394 return XML_ERROR_NO_MEMORY;4380 return ERROR_EXPAT_NO_MEMORY; 4395 4381 } 4396 4382 groupConnector[prologState.level] = 0; … … 4400 4386 4401 4387 if (myindex < 0) 4402 return XML_ERROR_NO_MEMORY;4388 return ERROR_EXPAT_NO_MEMORY; 4403 4389 dtd.scaffIndex[dtd.scaffLevel] = myindex; 4404 4390 dtd.scaffLevel++; … … 4408 4394 case XML_ROLE_GROUP_SEQUENCE: 4409 4395 if (groupConnector[prologState.level] == '|') 4410 return XML_ERROR_SYNTAX;4396 return ERROR_EXPAT_SYNTAX; 4411 4397 groupConnector[prologState.level] = ','; 4412 4398 break; 4413 4399 case XML_ROLE_GROUP_CHOICE: 4414 4400 if (groupConnector[prologState.level] == ',') 4415 return XML_ERROR_SYNTAX;4401 return ERROR_EXPAT_SYNTAX; 4416 4402 if (dtd.in_eldecl 4417 4403 && !groupConnector[prologState.level] … … 4436 4422 next - enc->minBytesPerChar); 4437 4423 if (!name) 4438 return XML_ERROR_NO_MEMORY;4424 return ERROR_EXPAT_NO_MEMORY; 4439 4425 entity = (ENTITY*)lookup(&dtd.paramEntities, name, 0); 4440 4426 poolDiscard(&dtd.pool); … … 4442 4428 { 4443 4429 /* FIXME what to do if !dtd.complete? */ 4444 return XML_ERROR_UNDEFINED_ENTITY;4430 return ERROR_EXPAT_UNDEFINED_ENTITY; 4445 4431 } 4446 4432 if (entity->open) 4447 return XML_ERROR_RECURSIVE_ENTITY_REF;4433 return ERROR_EXPAT_RECURSIVE_ENTITY_REF; 4448 4434 if (entity->textPtr) 4449 4435 { 4450 enum XML_Errorresult;4436 XMLERROR result; 4451 4437 4452 4438 result = processInternalParamEntity(parser, entity); 4453 if (result != XML_ERROR_NONE)4439 if (result != ERROR_EXPAT_NONE) 4454 4440 return result; 4455 4441 break; 4456 4442 } 4457 4443 if (role == XML_ROLE_INNER_PARAM_ENTITY_REF) 4458 return XML_ERROR_PARAM_ENTITY_REF;4444 return ERROR_EXPAT_PARAM_ENTITY_REF; 4459 4445 if (externalEntityRefHandler) 4460 4446 { … … 4468 4454 { 4469 4455 entity->open = 0; 4470 return XML_ERROR_EXTERNAL_ENTITY_HANDLING;4456 return ERROR_EXPAT_EXTERNAL_ENTITY_HANDLING; 4471 4457 } 4472 4458 entity->open = 0; … … 4479 4465 && notStandaloneHandler 4480 4466 && !notStandaloneHandler(handlerArg)) 4481 return XML_ERROR_NOT_STANDALONE;4467 return ERROR_EXPAT_NOT_STANDALONE; 4482 4468 dtd.complete = 0; 4483 4469 if (defaultHandler) … … 4492 4478 declElementType = getElementType(parser, enc, s, next); 4493 4479 if (!declElementType) 4494 return XML_ERROR_NO_MEMORY;4480 return ERROR_EXPAT_NO_MEMORY; 4495 4481 dtd.scaffLevel = 0; 4496 4482 dtd.scaffCount = 0; … … 4505 4491 if (elementDeclHandler) 4506 4492 { 4507 XML _Content *content = (XML_Content*)MALLOC(sizeof(XML_Content));4493 XMLCONTENT *content = (XMLCONTENT*)MALLOC(sizeof(XMLCONTENT)); 4508 4494 4509 4495 if (!content) 4510 return XML_ERROR_NO_MEMORY;4496 return ERROR_EXPAT_NO_MEMORY; 4511 4497 content->quant = XML_CQUANT_NONE; 4512 4498 content->name = 0; … … 4549 4535 4550 4536 if (myindex < 0) 4551 return XML_ERROR_NO_MEMORY;4537 return ERROR_EXPAT_NO_MEMORY; 4552 4538 dtd.scaffold[myindex].type = XML_CTYPE_NAME; 4553 4539 dtd.scaffold[myindex].quant = quant; 4554 4540 el = getElementType(parser, enc, s, nxt); 4555 4541 if (!el) 4556 return XML_ERROR_NO_MEMORY;4542 return ERROR_EXPAT_NO_MEMORY; 4557 4543 dtd.scaffold[myindex].name = el->name; 4558 4544 dtd.contentStringLen += nxt - s + 1; … … 4580 4566 if (elementDeclHandler) 4581 4567 { 4582 XML _Content*model = build_model(parser);4568 XMLCONTENT *model = build_model(parser); 4583 4569 4584 4570 if (!model) 4585 return XML_ERROR_NO_MEMORY;4571 return ERROR_EXPAT_NO_MEMORY; 4586 4572 *eventEndPP = s; 4587 4573 elementDeclHandler(handlerArg, declElementType->name, model); … … 4599 4585 case XML_TOK_PI: 4600 4586 if (!reportProcessingInstruction(parser, enc, s, next)) 4601 return XML_ERROR_NO_MEMORY;4587 return ERROR_EXPAT_NO_MEMORY; 4602 4588 break; 4603 4589 case XML_TOK_COMMENT: 4604 4590 if (!reportComment(parser, enc, s, next)) 4605 return XML_ERROR_NO_MEMORY;4591 return ERROR_EXPAT_NO_MEMORY; 4606 4592 break; 4607 4593 } … … 4634 4620 } 4635 4621 4636 static enum XML_ErrorepilogProcessor(XML_Parser parser,4622 static XMLERROR epilogProcessor(XML_Parser parser, 4637 4623 const char *s, 4638 4624 const char *end, … … 4659 4645 if (nextPtr) 4660 4646 *nextPtr = end; 4661 return XML_ERROR_NONE;4647 return ERROR_EXPAT_NONE; 4662 4648 case XML_TOK_PROLOG_S: 4663 4649 if (defaultHandler) … … 4666 4652 case XML_TOK_PI: 4667 4653 if (!reportProcessingInstruction(parser, encoding, s, next)) 4668 return XML_ERROR_NO_MEMORY;4654 return ERROR_EXPAT_NO_MEMORY; 4669 4655 break; 4670 4656 case XML_TOK_COMMENT: 4671 4657 if (!reportComment(parser, encoding, s, next)) 4672 return XML_ERROR_NO_MEMORY;4658 return ERROR_EXPAT_NO_MEMORY; 4673 4659 break; 4674 4660 case XML_TOK_INVALID: 4675 4661 eventPtr = next; 4676 return XML_ERROR_INVALID_TOKEN;4662 return ERROR_EXPAT_INVALID_TOKEN; 4677 4663 case XML_TOK_PARTIAL: 4678 4664 if (nextPtr) 4679 4665 { 4680 4666 *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; 4684 4670 case XML_TOK_PARTIAL_CHAR: 4685 4671 if (nextPtr) 4686 4672 { 4687 4673 *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; 4691 4677 default: 4692 return XML_ERROR_JUNK_AFTER_DOC_ELEMENT;4678 return ERROR_EXPAT_JUNK_AFTER_DOC_ELEMENT; 4693 4679 } 4694 4680 eventPtr = s = next; … … 4698 4684 #ifdef XML_DTD 4699 4685 4700 static enum XML_ErrorprocessInternalParamEntity(XML_Parser parser, ENTITY * entity)4686 static XMLERROR processInternalParamEntity(XML_Parser parser, ENTITY * entity) 4701 4687 { 4702 4688 const char *s, *end, *next; 4703 4689 int tok; 4704 enum XML_Errorresult;4690 XMLERROR result; 4705 4691 OPEN_INTERNAL_ENTITY openEntity; 4706 4692 … … 4722 4708 #endif /* XML_DTD */ 4723 4709 4724 static enum XML_ErrorerrorProcessor(XML_Parser parser,4710 static XMLERROR errorProcessor(XML_Parser parser, 4725 4711 const char *s, 4726 4712 const char *end, … … 4730 4716 } 4731 4717 4732 static enum XML_ErrorstoreAttributeValue(XML_Parser parser,4718 static XMLERROR storeAttributeValue(XML_Parser parser, 4733 4719 const ENCODING * enc, 4734 4720 int isCdata, … … 4737 4723 STRING_POOL * pool) 4738 4724 { 4739 enum XML_Errorresult = appendAttributeValue(parser, enc, isCdata, ptr, end, pool);4725 XMLERROR result = appendAttributeValue(parser, enc, isCdata, ptr, end, pool); 4740 4726 4741 4727 if (result) … … 4744 4730 poolChop(pool); 4745 4731 if (!poolAppendChar(pool, XML_T('\0'))) 4746 return XML_ERROR_NO_MEMORY;4747 return XML_ERROR_NONE;4748 } 4749 4750 static enum XML_ErrorappendAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata,4732 return ERROR_EXPAT_NO_MEMORY; 4733 return ERROR_EXPAT_NONE; 4734 } 4735 4736 static XMLERROR appendAttributeValue(XML_Parser parser, const ENCODING * enc, int isCdata, 4751 4737 const char *ptr, const char *end, 4752 4738 STRING_POOL * pool) … … 4760 4746 { 4761 4747 case XML_TOK_NONE: 4762 return XML_ERROR_NONE;4748 return ERROR_EXPAT_NONE; 4763 4749 case XML_TOK_INVALID: 4764 4750 if (enc == encoding) 4765 4751 eventPtr = next; 4766 return XML_ERROR_INVALID_TOKEN;4752 return ERROR_EXPAT_INVALID_TOKEN; 4767 4753 case XML_TOK_PARTIAL: 4768 4754 if (enc == encoding) 4769 4755 eventPtr = ptr; 4770 return XML_ERROR_INVALID_TOKEN;4756 return ERROR_EXPAT_INVALID_TOKEN; 4771 4757 case XML_TOK_CHAR_REF: 4772 4758 { … … 4779 4765 if (enc == encoding) 4780 4766 eventPtr = ptr; 4781 return XML_ERROR_BAD_CHAR_REF;4767 return ERROR_EXPAT_BAD_CHAR_REF; 4782 4768 } 4783 4769 if (!isCdata … … 4790 4776 if (enc == encoding) 4791 4777 eventPtr = ptr; 4792 return XML_ERROR_BAD_CHAR_REF;4778 return ERROR_EXPAT_BAD_CHAR_REF; 4793 4779 } 4794 4780 for (i = 0; i < n; i++) 4795 4781 { 4796 4782 if (!poolAppendChar(pool, buf[i])) 4797 return XML_ERROR_NO_MEMORY;4783 return ERROR_EXPAT_NO_MEMORY; 4798 4784 } 4799 4785 } … … 4801 4787 case XML_TOK_DATA_CHARS: 4802 4788 if (!poolAppend(pool, enc, ptr, next)) 4803 return XML_ERROR_NO_MEMORY;4789 return ERROR_EXPAT_NO_MEMORY; 4804 4790 break; 4805 4791 case XML_TOK_TRAILING_CR: … … 4811 4797 break; 4812 4798 if (!poolAppendChar(pool, 0x20)) 4813 return XML_ERROR_NO_MEMORY;4799 return ERROR_EXPAT_NO_MEMORY; 4814 4800 break; 4815 4801 case XML_TOK_ENTITY_REF: … … 4824 4810 { 4825 4811 if (!poolAppendChar(pool, ch)) 4826 return XML_ERROR_NO_MEMORY;4812 return ERROR_EXPAT_NO_MEMORY; 4827 4813 break; 4828 4814 } … … 4831 4817 next - enc->minBytesPerChar); 4832 4818 if (!name) 4833 return XML_ERROR_NO_MEMORY;4819 return ERROR_EXPAT_NO_MEMORY; 4834 4820 entity = (ENTITY*)lookup(&dtd.generalEntities, name, 0); 4835 4821 poolDiscard(&temp2Pool); … … 4840 4826 if (enc == encoding) 4841 4827 eventPtr = ptr; 4842 return XML_ERROR_UNDEFINED_ENTITY;4828 return ERROR_EXPAT_UNDEFINED_ENTITY; 4843 4829 } 4844 4830 } … … 4847 4833 if (enc == encoding) 4848 4834 eventPtr = ptr; 4849 return XML_ERROR_RECURSIVE_ENTITY_REF;4835 return ERROR_EXPAT_RECURSIVE_ENTITY_REF; 4850 4836 } 4851 4837 else if (entity->notation) … … 4853 4839 if (enc == encoding) 4854 4840 eventPtr = ptr; 4855 return XML_ERROR_BINARY_ENTITY_REF;4841 return ERROR_EXPAT_BINARY_ENTITY_REF; 4856 4842 } 4857 4843 else if (!entity->textPtr) … … 4859 4845 if (enc == encoding) 4860 4846 eventPtr = ptr; 4861 return XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF;4847 return ERROR_EXPAT_ATTRIBUTE_EXTERNAL_ENTITY_REF; 4862 4848 } 4863 4849 else 4864 4850 { 4865 enum XML_Errorresult;4851 XMLERROR result; 4866 4852 const XML_Char *textEnd = entity->textPtr + entity->textLen; 4867 4853 … … 4877 4863 if (enc == encoding) 4878 4864 eventPtr = ptr; 4879 return XML_ERROR_UNEXPECTED_STATE;4865 return ERROR_EXPAT_UNEXPECTED_STATE; 4880 4866 } 4881 4867 ptr = next; … … 4884 4870 } 4885 4871 4886 static enum XML_ErrorstoreEntityValue(XML_Parser parser,4872 static XMLERROR storeEntityValue(XML_Parser parser, 4887 4873 const ENCODING * enc, 4888 4874 const char *entityTextPtr, … … 4902 4888 if (parentParser || enc != encoding) 4903 4889 { 4904 enum XML_Errorresult;4890 XMLERROR result; 4905 4891 const XML_Char *name; 4906 4892 ENTITY *entity; … … 4910 4896 next - enc->minBytesPerChar); 4911 4897 if (!name) 4912 return XML_ERROR_NO_MEMORY;4898 return ERROR_EXPAT_NO_MEMORY; 4913 4899 entity = (ENTITY*)lookup(&dtd.paramEntities, name, 0); 4914 4900 poolDiscard(&tempPool); … … 4917 4903 if (enc == encoding) 4918 4904 eventPtr = entityTextPtr; 4919 return XML_ERROR_UNDEFINED_ENTITY;4905 return ERROR_EXPAT_UNDEFINED_ENTITY; 4920 4906 } 4921 4907 if (entity->open) … … 4923 4909 if (enc == encoding) 4924 4910 eventPtr = entityTextPtr; 4925 return XML_ERROR_RECURSIVE_ENTITY_REF;4911 return ERROR_EXPAT_RECURSIVE_ENTITY_REF; 4926 4912 } 4927 4913 if (entity->systemId) … … 4929 4915 if (enc == encoding) 4930 4916 eventPtr = entityTextPtr; 4931 return XML_ERROR_PARAM_ENTITY_REF;4917 return ERROR_EXPAT_PARAM_ENTITY_REF; 4932 4918 } 4933 4919 entity->open = 1; … … 4943 4929 #endif /* XML_DTD */ 4944 4930 eventPtr = entityTextPtr; 4945 return XML_ERROR_SYNTAX;4931 return ERROR_EXPAT_SYNTAX; 4946 4932 case XML_TOK_NONE: 4947 return XML_ERROR_NONE;4933 return ERROR_EXPAT_NONE; 4948 4934 case XML_TOK_ENTITY_REF: 4949 4935 case XML_TOK_DATA_CHARS: 4950 4936 if (!poolAppend(pool, enc, entityTextPtr, next)) 4951 return XML_ERROR_NO_MEMORY;4937 return ERROR_EXPAT_NO_MEMORY; 4952 4938 break; 4953 4939 case XML_TOK_TRAILING_CR: … … 4956 4942 case XML_TOK_DATA_NEWLINE: 4957 4943 if (pool->end == pool->ptr && !poolGrow(pool)) 4958 return XML_ERROR_NO_MEMORY;4944 return ERROR_EXPAT_NO_MEMORY; 4959 4945 *(pool->ptr)++ = 0xA; 4960 4946 break; … … 4969 4955 if (enc == encoding) 4970 4956 eventPtr = entityTextPtr; 4971 return XML_ERROR_BAD_CHAR_REF;4957 return ERROR_EXPAT_BAD_CHAR_REF; 4972 4958 } 4973 4959 n = XmlEncode(n, (ICHAR*)buf); … … 4976 4962 if (enc == encoding) 4977 4963 eventPtr = entityTextPtr; 4978 return XML_ERROR_BAD_CHAR_REF;4964 return ERROR_EXPAT_BAD_CHAR_REF; 4979 4965 } 4980 4966 for (i = 0; i < n; i++) 4981 4967 { 4982 4968 if (pool->end == pool->ptr && !poolGrow(pool)) 4983 return XML_ERROR_NO_MEMORY;4969 return ERROR_EXPAT_NO_MEMORY; 4984 4970 *(pool->ptr)++ = buf[i]; 4985 4971 } … … 4989 4975 if (enc == encoding) 4990 4976 eventPtr = entityTextPtr; 4991 return XML_ERROR_INVALID_TOKEN;4977 return ERROR_EXPAT_INVALID_TOKEN; 4992 4978 case XML_TOK_INVALID: 4993 4979 if (enc == encoding) 4994 4980 eventPtr = next; 4995 return XML_ERROR_INVALID_TOKEN;4981 return ERROR_EXPAT_INVALID_TOKEN; 4996 4982 default: 4997 4983 if (enc == encoding) 4998 4984 eventPtr = entityTextPtr; 4999 return XML_ERROR_UNEXPECTED_STATE;4985 return ERROR_EXPAT_UNEXPECTED_STATE; 5000 4986 } 5001 4987 entityTextPtr = next; … … 5486 5472 } 5487 5473 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 */ 5490 5479 5491 5480 static int dtdCopy(DTD * newDtd, const DTD * oldDtd, XML_Parser parser) … … 6058 6047 static void build_node(XML_Parser parser, 6059 6048 int src_node, 6060 XML _Content* dest,6061 XML _Content** contpos,6049 XMLCONTENT * dest, 6050 XMLCONTENT ** contpos, 6062 6051 char **strpos) 6063 6052 { … … 6098 6087 } /* End build_node */ 6099 6088 6100 static XML _Content* build_model(XML_Parser parser)6101 { 6102 XML _Content*ret;6103 XML _Content*cpos;6089 static XMLCONTENT * build_model(XML_Parser parser) 6090 { 6091 XMLCONTENT *ret; 6092 XMLCONTENT *cpos; 6104 6093 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); 6108 6097 if (!ret) 6109 6098 return 0; -
trunk/src/helpers/xmlrole.c
r36 r38 1 1 2 2 /* 3 * @@sourcefile xmlrole.c3 *sourcefile xmlrole.c 4 4 * part of the expat implementation. See xmlparse.c. 5 5 * -
trunk/src/helpers/xmltok.c
r36 r38 1 1 2 2 /* 3 * @@sourcefile xmltok.c3 *sourcefile xmltok.c 4 4 * part of the expat implementation. See xmlparse.c. 5 5 * -
trunk/src/helpers/xmltok_impl.c
r36 r38 1 1 2 2 /* 3 * @@sourcefile xmltok_impl.c3 *sourcefile xmltok_impl.c 4 4 * part of the expat implementation. See xmlparse.c. 5 5 * -
trunk/src/helpers/xmltok_ns.c
r36 r38 1 1 2 2 /* 3 * @@sourcefile xmltok_ns.c3 *sourcefile xmltok_ns.c 4 4 * part of the expat implementation. See xmlparse.c. 5 5 * -
trunk/src/helpers/xstring.c
r32 r38 346 346 * 347 347 *@@added V0.9.6 (2000-11-01) [umoeller] 348 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL target crash 348 349 */ 349 350 … … 351 352 PSZ pszNew) // in: heap PSZ to use 352 353 { 354 if (!pxstr) 355 return (0); // V0.9.9 (2001-02-14) [umoeller] 356 353 357 xstrClear(pxstr); 354 358 pxstr->psz = pszNew; … … 391 395 *@@changed V0.9.7 (2001-01-15) [umoeller]: added ulSourceLength 392 396 *@@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 393 398 */ 394 399 … … 399 404 // xstrClear(pxstr); NOOOO! this frees the string, we want to keep the memory 400 405 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) 404 424 { 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); 409 431 } 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; 448 453 449 454 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 464 ULONG xstrcpys(PXSTRING pxstr, 465 const XSTRING *pcstrSource) 466 { 467 if (!pcstrSource) 468 return (0); 469 470 return (xstrcpy(pxstr, pcstrSource->psz, pcstrSource->ulLength)); 450 471 } 451 472 … … 634 655 635 656 /* 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 663 ULONG 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 /* 636 673 *@@ xstrrpl: 637 674 * replaces cReplLen characters in pxstr, starting … … 666 703 *@@added V0.9.7 (2001-01-15) [umoeller] 667 704 *@@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 668 706 */ 669 707 … … 676 714 677 715 // security checks... 678 if ( (ulFirstReplOfs + cReplLen <= pxstr->ulLength) 716 if ( (pxstr) // V0.9.9 (2001-02-14) [umoeller] 717 && (ulFirstReplOfs + cReplLen <= pxstr->ulLength) 679 718 && (pstrReplaceWith) 680 719 // && (pstrReplaceWith->ulLength) no, this can be empty … … 747 786 ULONG cTailLength = pxstr->ulLength - ulFirstReplOfs - cReplLen; 748 787 749 // first, we move the end to its new location (memmove750 // handles overlap if needed)788 // first, we move the end to its new location 789 // (memmove handles overlap if needed) 751 790 memmove(pFound + cReplaceLen, 752 791 pFound + cReplLen, … … 787 826 * 788 827 *@@added V0.9.6 (2000-11-12) [umoeller] 828 *@@changed V0.9.9 (2001-02-14) [umoeller]: fixed NULL string crashs 789 829 */ 790 830 … … 798 838 { 799 839 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)) 807 846 { 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 817 850 { 818 // string found:819 // check if that's a word820 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) 826 859 { 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; 830 875 } 831 832 p += ulFoundLen; 833 } 834 } while (p); 835 836 } 876 } while (p); 877 878 } 879 } 880 837 881 return (pReturn); 838 882 }
Note:
See TracChangeset
for help on using the changeset viewer.