Changeset 83 for trunk/src/helpers/xml.c


Ignore:
Timestamp:
Jun 28, 2001, 7:13:56 PM (24 years ago)
Author:
umoeller
Message:

Many misc updates.

File:
1 edited

Legend:

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

    r74 r83  
    276276
    277277/*
    278  *@@ CompareNodeBaseNodes:
     278 *@@ CompareXStrings:
    279279 *      tree comparison func for NodeBases.
    280280 *      This works for all trees which contain structures
     
    293293 */
    294294
    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));
     295int TREEENTRY CompareXStrings(ULONG ul1,
     296                              ULONG ul2)
     297{
     298    return (strhcmp(((PXSTRING)ul1)->psz,
     299                    ((PXSTRING)ul1)->psz));
    316300}
    317301
     
    343327        pNewNode->ulNodeType = ulNodeType;
    344328
     329        pNewNode->Tree.ulKey = (ULONG)&pNewNode->strNodeName;
     330
    345331        xstrInit(&pNewNode->strNodeName, 0);
    346332        if (pcszNodeName)
     333        {
    347334            xstrcpy(&pNewNode->strNodeName,
    348335                    pcszNodeName,
    349                     ulNodeNameLength);  // if 0, xstrcpy will do strlen()
    350 
     336                    ulNodeNameLength);
     337        }
    351338
    352339        *ppNew = pNewNode;
     
    514501        lstClear(&llDeleteNodes);
    515502
    516         xstrClear(&pNode->strNodeName);
     503        xstrFree(((PXSTRING*)&pNode->Tree.ulKey));
    517504        free(pNode);
    518505    }
     
    587574                // attribute:
    588575                // 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))
    594579                    arc = ERROR_DOM_DUPLICATE_ATTRIBUTE;
    595580                                // shouldn't happen, because expat takes care of this
     
    837822        PDOMDOCTYPENODE pNew = NULL;
    838823        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);
    843828
    844829        if (!arc)
     
    854839            pNew->fHasInternalSubset = fHasInternalSubset;
    855840
    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 
    867841            treeInit(&pNew->ElementDeclsTree);
    868842            treeInit(&pNew->AttribDeclBasesTree);
     
    909883        case XML_CTYPE_NAME:   // that's easy
    910884            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);
    916889        break;
    917890
     
    10971070                case ELEMENTPARTICLE_SEQ:
    10981071                {
    1099                     const char *pcszNewElementName
    1100                         = pNewElement->NodeBase.strNodeName.psz;
     1072                    PXSTRING pstrNewElementName
     1073                        = &pNewElement->NodeBase.strNodeName;
    11011074
    11021075                    // for all these, we first need to check if
    11031076                    // the element is allowed at all
    11041077                    PCMELEMENTPARTICLE pParticle
    1105                         = (PCMELEMENTPARTICLE)treeFindEQData(
    1106                                          &pParentElementDecl->ParticleNamesTree,
    1107                                          (void*)pcszNewElementName,
    1108                                          CompareNodeBaseData);
     1078                        = (PCMELEMENTPARTICLE)treeFind(
     1079                                         pParentElementDecl->ParticleNamesTree,
     1080                                         (ULONG)pstrNewElementName,
     1081                                         CompareXStrings);
    11091082                    if (!pParticle)
    11101083                        // not found: then this element is not allowed within this
     
    11121085                        xmlSetError(pDom,
    11131086                                    ERROR_DOM_INVALID_SUBELEMENT,
    1114                                     pcszNewElementName,
     1087                                    pstrNewElementName->psz,
    11151088                                    TRUE);
    11161089                    else
     
    12491222                // enumeration: then check if it has one of the
    12501223                // allowed values
    1251                 PNODEBASE pValue = (PNODEBASE)treeFindEQData(
    1252                                                 &pAttribDecl->ValuesTree,
    1253                                                 (void*)pAttrib->pstrNodeValue->psz,
    1254                                                 CompareNodeBaseData);
     1224                PNODEBASE pValue = (PNODEBASE)treeFind(
     1225                                                pAttribDecl->ValuesTree,
     1226                                                (ULONG)pAttrib->pstrNodeValue,
     1227                                                CompareXStrings);
    12551228                if (!pValue)
    12561229                    xmlSetError(pDom,
     
    12971270        {
    12981271            // for all others , we need to find the attribute
    1299             PSZ pszAttrNameThis = pDeclThis->NodeBase.strNodeName.psz;
    1300             PDOMNODE pAttrNode = (PDOMNODE)treeFindEQData(
    1301                                             &pNewElement->AttributesMap,
    1302                                             (void*)pszAttrNameThis,
    1303                                             CompareNodeBaseData);
     1272            PXSTRING pstrAttrNameThis = &pDeclThis->NodeBase.strNodeName;
     1273            PDOMNODE pAttrNode = (PDOMNODE)treeFind(
     1274                                            pNewElement->AttributesMap,
     1275                                            (ULONG)pstrAttrNameThis,
     1276                                            CompareXStrings);
    13041277
    13051278            // now switch again
     
    13111284                        xmlSetError(pDom,
    13121285                                    ERROR_DOM_REQUIRED_ATTRIBUTE_MISSING,
    1313                                     pszAttrNameThis,
     1286                                    pstrAttrNameThis->psz,
    13141287                                    TRUE);
    13151288                break;
     
    18711844            {
    18721845                // 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))
    18781849                    // element already declared:
    18791850                    // according to the XML specs, this is a validity
     
    19061877                                   &pNew);
    19071878    if (!arc)
    1908         treeInsertNode(&pDecl->ValuesTree,
    1909                        (TREE*)pNew,
    1910                        CompareNodeBaseNodes,
    1911                        FALSE);
     1879        treeInsert(&pDecl->ValuesTree,
     1880                   (TREE*)pNew,
     1881                   CompareXStrings);
    19121882
    19131883    return (arc);
     
    19781948            if (!pThis)
    19791949            {
    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);
    19851959
    19861960                if (!pThis)
     
    19901964                    pDom->arcDOM = xmlCreateNodeBase(ATTRIBUTE_DECLARATION_BASE,
    19911965                                                     sizeof(CMATTRIBUTEDECLBASE),
    1992                                                      pcszElementName,
    1993                                                      0,
     1966                                                     strElementName.psz,
     1967                                                     strElementName.ulLength,
    19941968                                                     (PNODEBASE*)&pThis);
    19951969                    if (!pDom->arcDOM)
     
    19981972                        treeInit(&pThis->AttribDeclsTree);
    19991973
    2000                         treeInsertNode(&pDocType->AttribDeclBasesTree,
    2001                                        (TREE*)pThis,
    2002                                        CompareNodeBaseNodes,
    2003                                        FALSE);
     1974                        treeInsert(&pDocType->AttribDeclBasesTree,
     1975                                   (TREE*)pThis,
     1976                                   CompareXStrings);
    20041977                    }
    20051978                }
     
    20852058                                pNew->ulConstraint = CMAT_IMPLIED;
    20862059
    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))
    20922063                            xmlSetError(pDom,
    20932064                                        ERROR_DOM_DUPLICATE_ATTRIBUTE_DECL,
     
    24312402
    24322403PCMELEMENTDECLNODE xmlFindElementDecl(PXMLDOM pDom,
    2433                                       const XSTRING *pstrElementName)
     2404                                      const XSTRING *pcstrElementName)
    24342405{
    24352406    PCMELEMENTDECLNODE pElementDecl = NULL;
    24362407
     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
     2435PCMATTRIBUTEDECLBASE xmlFindAttribDeclBase(PXMLDOM pDom,
     2436                                           const XSTRING *pstrElementName)
     2437{
    24372438    PDOMDOCTYPENODE pDocTypeNode = pDom->pDocTypeNode;
    24382439    if (    (pDocTypeNode)
     
    24412442       )
    24422443    {
    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);
    24822451}
    24832452
     
    24982467                                            // must be NULL on the first call
    24992468{
    2500     PCMATTRIBUTEDECL pAttribDecl = NULL;
    25012469    if (pstrElementName && pstrAttribName)
    25022470    {
     
    25072475        if (*ppAttribDeclBase)
    25082476        {
    2509             pAttribDecl = (PCMATTRIBUTEDECL)treeFindEQData(
    2510                                          &((**ppAttribDeclBase).AttribDeclsTree),
    2511                                          (void*)pstrAttribName->psz,
    2512                                          CompareNodeBaseData);
    2513         }
    2514     }
    2515 
    2516     return (pAttribDecl);
     2477            return ((PCMATTRIBUTEDECL)treeFind(
     2478                                         ((**ppAttribDeclBase).AttribDeclsTree),
     2479                                         (ULONG)pstrAttribName,
     2480                                         CompareXStrings));
     2481        }
     2482    }
     2483
     2484    return (NULL);
    25172485}
    25182486
     
    26712639                               const char *pcszAttribName)
    26722640{
    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);
    26762649    if (pAttrNode)
    26772650        return (pAttrNode->pstrNodeValue);
Note: See TracChangeset for help on using the changeset viewer.