Changeset 83 for trunk/src/helpers/xml.c
- Timestamp:
- Jun 28, 2001, 7:13:56 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/xml.c
r74 r83 276 276 277 277 /* 278 *@@ Compare NodeBaseNodes:278 *@@ CompareXStrings: 279 279 * tree comparison func for NodeBases. 280 280 * This works for all trees which contain structures … … 293 293 */ 294 294 295 int TREEENTRY CompareNodeBaseNodes(TREE *t1, 296 TREE *t2) 297 { 298 PNODEBASE p1 = (PNODEBASE)t1, 299 p2 = (PNODEBASE)t2; 300 return (strhcmp(p1->strNodeName.psz, p2->strNodeName.psz)); 301 } 302 303 /* 304 *@@ CompareNodeBaseNodes: 305 * tree comparison func for element declarations. 306 * Used to find nodes in _DOMDOCTYPENODE.ElementDeclsTree. 307 * 308 *@@added V0.9.9 (2001-02-16) [umoeller] 309 */ 310 311 int TREEENTRY CompareNodeBaseData(TREE *t1, 312 void *pData) 313 { 314 PNODEBASE p1 = (PNODEBASE)t1; 315 return (strhcmp(p1->strNodeName.psz, (const char*)pData)); 295 int TREEENTRY CompareXStrings(ULONG ul1, 296 ULONG ul2) 297 { 298 return (strhcmp(((PXSTRING)ul1)->psz, 299 ((PXSTRING)ul1)->psz)); 316 300 } 317 301 … … 343 327 pNewNode->ulNodeType = ulNodeType; 344 328 329 pNewNode->Tree.ulKey = (ULONG)&pNewNode->strNodeName; 330 345 331 xstrInit(&pNewNode->strNodeName, 0); 346 332 if (pcszNodeName) 333 { 347 334 xstrcpy(&pNewNode->strNodeName, 348 335 pcszNodeName, 349 ulNodeNameLength); // if 0, xstrcpy will do strlen()350 336 ulNodeNameLength); 337 } 351 338 352 339 *ppNew = pNewNode; … … 514 501 lstClear(&llDeleteNodes); 515 502 516 xstr Clear(&pNode->strNodeName);503 xstrFree(((PXSTRING*)&pNode->Tree.ulKey)); 517 504 free(pNode); 518 505 } … … 587 574 // attribute: 588 575 // add to parent's attributes list 589 if (treeInsertNode(&pParentNode->AttributesMap, 590 &pNewNode->NodeBase.Tree, 591 CompareNodeBaseNodes, 592 FALSE) // no duplicates 593 == TREE_DUPLICATE) 576 if (treeInsert(&pParentNode->AttributesMap, 577 &pNewNode->NodeBase.Tree, 578 CompareXStrings)) 594 579 arc = ERROR_DOM_DUPLICATE_ATTRIBUTE; 595 580 // shouldn't happen, because expat takes care of this … … 837 822 PDOMDOCTYPENODE pNew = NULL; 838 823 arc = xmlCreateDomNode((PDOMNODE)pDocumentNode, 839 DOMNODE_DOCUMENT_TYPE,840 NULL,841 0,842 (PDOMNODE*)&pNew);824 DOMNODE_DOCUMENT_TYPE, 825 pcszDoctypeName, 826 0, 827 (PDOMNODE*)&pNew); 843 828 844 829 if (!arc) … … 854 839 pNew->fHasInternalSubset = fHasInternalSubset; 855 840 856 if (pcszDoctypeName)857 {858 ULONG ul = strlen(pcszDoctypeName);859 if (ul)860 {861 xstrcpy(&pDocumentNode->DomNode.NodeBase.strNodeName,862 pcszDoctypeName,863 ul);864 }865 }866 867 841 treeInit(&pNew->ElementDeclsTree); 868 842 treeInit(&pNew->AttribDeclBasesTree); … … 909 883 case XML_CTYPE_NAME: // that's easy 910 884 pParticle->NodeBase.ulNodeType = ELEMENTPARTICLE_NAME; 911 xstrInitCopy(&pParticle->NodeBase.strNodeName, pModel->name, 0); 912 treeInsertNode(ppElementNamesTree, 913 &pParticle->NodeBase.Tree, 914 CompareNodeBaseNodes, 915 TRUE); // allow duplicates here 885 xstrcpy(&pParticle->NodeBase.strNodeName, pModel->name, 0); 886 treeInsert(ppElementNamesTree, 887 &pParticle->NodeBase.Tree, 888 CompareXStrings); 916 889 break; 917 890 … … 1097 1070 case ELEMENTPARTICLE_SEQ: 1098 1071 { 1099 const char *pcszNewElementName1100 = pNewElement->NodeBase.strNodeName.psz;1072 PXSTRING pstrNewElementName 1073 = &pNewElement->NodeBase.strNodeName; 1101 1074 1102 1075 // for all these, we first need to check if 1103 1076 // the element is allowed at all 1104 1077 PCMELEMENTPARTICLE pParticle 1105 = (PCMELEMENTPARTICLE)treeFind EQData(1106 &pParentElementDecl->ParticleNamesTree,1107 ( void*)pcszNewElementName,1108 Compare NodeBaseData);1078 = (PCMELEMENTPARTICLE)treeFind( 1079 pParentElementDecl->ParticleNamesTree, 1080 (ULONG)pstrNewElementName, 1081 CompareXStrings); 1109 1082 if (!pParticle) 1110 1083 // not found: then this element is not allowed within this … … 1112 1085 xmlSetError(pDom, 1113 1086 ERROR_DOM_INVALID_SUBELEMENT, 1114 p cszNewElementName,1087 pstrNewElementName->psz, 1115 1088 TRUE); 1116 1089 else … … 1249 1222 // enumeration: then check if it has one of the 1250 1223 // allowed values 1251 PNODEBASE pValue = (PNODEBASE)treeFind EQData(1252 &pAttribDecl->ValuesTree,1253 ( void*)pAttrib->pstrNodeValue->psz,1254 Compare NodeBaseData);1224 PNODEBASE pValue = (PNODEBASE)treeFind( 1225 pAttribDecl->ValuesTree, 1226 (ULONG)pAttrib->pstrNodeValue, 1227 CompareXStrings); 1255 1228 if (!pValue) 1256 1229 xmlSetError(pDom, … … 1297 1270 { 1298 1271 // for all others , we need to find the attribute 1299 P SZ pszAttrNameThis = pDeclThis->NodeBase.strNodeName.psz;1300 PDOMNODE pAttrNode = (PDOMNODE)treeFind EQData(1301 &pNewElement->AttributesMap,1302 ( void*)pszAttrNameThis,1303 Compare NodeBaseData);1272 PXSTRING pstrAttrNameThis = &pDeclThis->NodeBase.strNodeName; 1273 PDOMNODE pAttrNode = (PDOMNODE)treeFind( 1274 pNewElement->AttributesMap, 1275 (ULONG)pstrAttrNameThis, 1276 CompareXStrings); 1304 1277 1305 1278 // now switch again … … 1311 1284 xmlSetError(pDom, 1312 1285 ERROR_DOM_REQUIRED_ATTRIBUTE_MISSING, 1313 ps zAttrNameThis,1286 pstrAttrNameThis->psz, 1314 1287 TRUE); 1315 1288 break; … … 1871 1844 { 1872 1845 // add this to the doctype's declarations tree 1873 if (treeInsertNode(&pDocType->ElementDeclsTree, 1874 (TREE*)pNew, 1875 CompareNodeBaseNodes, 1876 FALSE) 1877 == TREE_DUPLICATE) 1846 if (treeInsert(&pDocType->ElementDeclsTree, 1847 (TREE*)pNew, 1848 CompareXStrings)) 1878 1849 // element already declared: 1879 1850 // according to the XML specs, this is a validity … … 1906 1877 &pNew); 1907 1878 if (!arc) 1908 treeInsertNode(&pDecl->ValuesTree, 1909 (TREE*)pNew, 1910 CompareNodeBaseNodes, 1911 FALSE); 1879 treeInsert(&pDecl->ValuesTree, 1880 (TREE*)pNew, 1881 CompareXStrings); 1912 1882 1913 1883 return (arc); … … 1978 1948 if (!pThis) 1979 1949 { 1980 // cache didn't match: look up attributes tree then 1981 pThis = (PCMATTRIBUTEDECLBASE)treeFindEQData( 1982 &pDocType->AttribDeclBasesTree, 1983 (void*)pcszElementName, 1984 CompareNodeBaseData); 1950 // cache didn't match: look up attributes tree then... 1951 // note: cheap trick, we need an XSTRING for treeFind 1952 // but don't want malloc, so we use xstrInitSet 1953 XSTRING strElementName; 1954 xstrInitSet(&strElementName, (PSZ)pcszElementName); 1955 pThis = (PCMATTRIBUTEDECLBASE)treeFind( 1956 pDocType->AttribDeclBasesTree, 1957 (ULONG)&strElementName, 1958 CompareXStrings); 1985 1959 1986 1960 if (!pThis) … … 1990 1964 pDom->arcDOM = xmlCreateNodeBase(ATTRIBUTE_DECLARATION_BASE, 1991 1965 sizeof(CMATTRIBUTEDECLBASE), 1992 pcszElementName,1993 0,1966 strElementName.psz, 1967 strElementName.ulLength, 1994 1968 (PNODEBASE*)&pThis); 1995 1969 if (!pDom->arcDOM) … … 1998 1972 treeInit(&pThis->AttribDeclsTree); 1999 1973 2000 treeInsertNode(&pDocType->AttribDeclBasesTree, 2001 (TREE*)pThis, 2002 CompareNodeBaseNodes, 2003 FALSE); 1974 treeInsert(&pDocType->AttribDeclBasesTree, 1975 (TREE*)pThis, 1976 CompareXStrings); 2004 1977 } 2005 1978 } … … 2085 2058 pNew->ulConstraint = CMAT_IMPLIED; 2086 2059 2087 if (treeInsertNode(&pThis->AttribDeclsTree, 2088 (TREE*)pNew, 2089 CompareNodeBaseNodes, 2090 FALSE) 2091 == TREE_DUPLICATE) 2060 if (treeInsert(&pThis->AttribDeclsTree, 2061 (TREE*)pNew, 2062 CompareXStrings)) 2092 2063 xmlSetError(pDom, 2093 2064 ERROR_DOM_DUPLICATE_ATTRIBUTE_DECL, … … 2431 2402 2432 2403 PCMELEMENTDECLNODE xmlFindElementDecl(PXMLDOM pDom, 2433 const XSTRING *p strElementName)2404 const XSTRING *pcstrElementName) 2434 2405 { 2435 2406 PCMELEMENTDECLNODE pElementDecl = NULL; 2436 2407 2408 PDOMDOCTYPENODE pDocTypeNode = pDom->pDocTypeNode; 2409 if ( (pDocTypeNode) 2410 && (pcstrElementName) 2411 && (pcstrElementName->ulLength) 2412 ) 2413 { 2414 pElementDecl = (PCMELEMENTDECLNODE)treeFind( 2415 pDocTypeNode->ElementDeclsTree, 2416 (ULONG)pcstrElementName, 2417 CompareXStrings); 2418 } 2419 2420 return (pElementDecl); 2421 } 2422 2423 /* 2424 *@@ xmlFindAttribDeclBase: 2425 * returns the _CMATTRIBUTEDECLBASE for the specified 2426 * element name, or NULL if none exists. 2427 * 2428 * To find a specific attribute declaration from both 2429 * an element and an attribute name, use xmlFindAttribDecl 2430 * instead. 2431 * 2432 *@@added V0.9.9 (2001-02-16) [umoeller] 2433 */ 2434 2435 PCMATTRIBUTEDECLBASE xmlFindAttribDeclBase(PXMLDOM pDom, 2436 const XSTRING *pstrElementName) 2437 { 2437 2438 PDOMDOCTYPENODE pDocTypeNode = pDom->pDocTypeNode; 2438 2439 if ( (pDocTypeNode) … … 2441 2442 ) 2442 2443 { 2443 pElementDecl = (PCMELEMENTDECLNODE)treeFindEQData( 2444 &pDocTypeNode->ElementDeclsTree, 2445 (void*)pstrElementName->psz, 2446 CompareNodeBaseData); 2447 } 2448 2449 return (pElementDecl); 2450 } 2451 2452 /* 2453 *@@ xmlFindAttribDeclBase: 2454 * returns the _CMATTRIBUTEDECLBASE for the specified 2455 * element name, or NULL if none exists. 2456 * 2457 * To find a specific attribute declaration from both 2458 * an element and an attribute name, use xmlFindAttribDecl 2459 * instead. 2460 * 2461 *@@added V0.9.9 (2001-02-16) [umoeller] 2462 */ 2463 2464 PCMATTRIBUTEDECLBASE xmlFindAttribDeclBase(PXMLDOM pDom, 2465 const XSTRING *pstrElementName) 2466 { 2467 PCMATTRIBUTEDECLBASE pAttribDeclBase = NULL; 2468 2469 PDOMDOCTYPENODE pDocTypeNode = pDom->pDocTypeNode; 2470 if ( (pDocTypeNode) 2471 && (pstrElementName) 2472 && (pstrElementName->ulLength) 2473 ) 2474 { 2475 pAttribDeclBase = (PCMATTRIBUTEDECLBASE)treeFindEQData( 2476 &pDocTypeNode->AttribDeclBasesTree, 2477 (void*)pstrElementName->psz, 2478 CompareNodeBaseData); 2479 } 2480 2481 return (pAttribDeclBase); 2444 return ((PCMATTRIBUTEDECLBASE)treeFind( 2445 pDocTypeNode->AttribDeclBasesTree, 2446 (ULONG)pstrElementName, 2447 CompareXStrings)); 2448 } 2449 2450 return (NULL); 2482 2451 } 2483 2452 … … 2498 2467 // must be NULL on the first call 2499 2468 { 2500 PCMATTRIBUTEDECL pAttribDecl = NULL;2501 2469 if (pstrElementName && pstrAttribName) 2502 2470 { … … 2507 2475 if (*ppAttribDeclBase) 2508 2476 { 2509 pAttribDecl = (PCMATTRIBUTEDECL)treeFindEQData(2510 &((**ppAttribDeclBase).AttribDeclsTree),2511 ( void*)pstrAttribName->psz,2512 Compare NodeBaseData);2513 } 2514 } 2515 2516 return ( pAttribDecl);2477 return ((PCMATTRIBUTEDECL)treeFind( 2478 ((**ppAttribDeclBase).AttribDeclsTree), 2479 (ULONG)pstrAttribName, 2480 CompareXStrings)); 2481 } 2482 } 2483 2484 return (NULL); 2517 2485 } 2518 2486 … … 2671 2639 const char *pcszAttribName) 2672 2640 { 2673 PDOMNODE pAttrNode = (PDOMNODE)treeFindEQData(&pElement->AttributesMap, 2674 (void*)pcszAttribName, 2675 CompareNodeBaseData); 2641 XSTRING str; 2642 PDOMNODE pAttrNode; 2643 xstrInitSet(&str, (PSZ)pcszAttribName); 2644 // note, cheap trick: no malloc here, but we need 2645 // an XSTRING for treeFind 2646 pAttrNode = (PDOMNODE)treeFind(pElement->AttributesMap, 2647 (ULONG)&str, 2648 CompareXStrings); 2676 2649 if (pAttrNode) 2677 2650 return (pAttrNode->pstrNodeValue);
Note:
See TracChangeset
for help on using the changeset viewer.