Ignore:
Timestamp:
Nov 24, 2001, 2:54:10 PM (24 years ago)
Author:
umoeller
Message:

Tons of changes.

File:
1 edited

Legend:

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

    r113 r117  
    680680{
    681681    PDOMNODE pNew = NULL;
    682     APIRET arc = xmlCreateDomNode(pParent,
    683                                   DOMNODE_ELEMENT,
    684                                   pcszElement,
    685                                   0,
    686                                   &pNew);
    687 
    688     if (arc == NO_ERROR)
     682    APIRET arc;
     683
     684    if (!(arc = xmlCreateDomNode(pParent,
     685                                 DOMNODE_ELEMENT,
     686                                 pcszElement,
     687                                 0,
     688                                 &pNew)))
    689689        *ppNew = pNew;
    690690
     
    717717    APIRET arc = NO_ERROR;
    718718
    719     if (    !pElement
    720          || pElement->NodeBase.ulNodeType != DOMNODE_ELEMENT
     719    if (    (!pElement)
     720         || (pElement->NodeBase.ulNodeType != DOMNODE_ELEMENT)
    721721       )
    722722        arc = ERROR_DOM_NO_ELEMENT;
     
    724724    {
    725725        PDOMNODE pNew = NULL;
    726         arc = xmlCreateDomNode(pElement,          // this takes care of adding to the list
    727                             DOMNODE_ATTRIBUTE,
    728                             pcszName,
    729                             0,
    730                             &pNew);
    731         if (arc == NO_ERROR)
     726        if (!(arc = xmlCreateDomNode(pElement,          // this takes care of adding to the list
     727                                     DOMNODE_ATTRIBUTE,
     728                                     pcszName,
     729                                     0,
     730                                     &pNew)))
    732731        {
    733732            pNew->pstrNodeValue = xstrCreate(0);
     
    758757{
    759758    PDOMNODE pNew = NULL;
    760     APIRET arc = xmlCreateDomNode(pParent,
    761                                   DOMNODE_TEXT,
    762                                   NULL,
    763                                   0,
    764                                   &pNew);
    765     if (arc == NO_ERROR)
    766     {
    767         PSZ pszNodeValue = (PSZ)malloc(ulLength + 1);
    768         if (!pszNodeValue)
    769         {
    770             arc = ERROR_NOT_ENOUGH_MEMORY;
    771             xmlDeleteNode((PNODEBASE)pNew);
    772         }
    773         else
     759    APIRET arc;
     760
     761    if (!(arc = xmlCreateDomNode(pParent,
     762                                 DOMNODE_TEXT,
     763                                 NULL,
     764                                 0,
     765                                 &pNew)))
     766    {
     767        PSZ pszNodeValue;
     768        if (pszNodeValue = (PSZ)malloc(ulLength + 1))
    774769        {
    775770            memcpy(pszNodeValue, pcszText, ulLength);
     
    780775            *ppNew = pNew;
    781776        }
     777        else
     778        {
     779            arc = ERROR_NOT_ENOUGH_MEMORY;
     780            xmlDeleteNode((PNODEBASE)pNew);
     781        }
    782782    }
    783783
     
    798798{
    799799    PDOMNODE pNew = NULL;
    800     APIRET arc = xmlCreateDomNode(pParent,
    801                                   DOMNODE_COMMENT,
    802                                   NULL,
    803                                   0,
    804                                   &pNew);
    805     if (arc == NO_ERROR)
     800    APIRET arc;
     801    if (!(arc = xmlCreateDomNode(pParent,
     802                                 DOMNODE_COMMENT,
     803                                 NULL,
     804                                 0,
     805                                 &pNew)))
    806806    {
    807807        pNew->pstrNodeValue = xstrCreate(0);
     
    827827{
    828828    PDOMNODE pNew = NULL;
    829     APIRET arc = xmlCreateDomNode(pParent,
    830                                DOMNODE_PROCESSING_INSTRUCTION,
    831                                pcszTarget,
    832                                0,
    833                                &pNew);
    834     if (arc == NO_ERROR)
     829    APIRET arc;
     830
     831    if (!(arc = xmlCreateDomNode(pParent,
     832                                 DOMNODE_PROCESSING_INSTRUCTION,
     833                                 pcszTarget,
     834                                 0,
     835                                 &pNew)))
    835836    {
    836837        pNew->pstrNodeValue = xstrCreate(0);
     
    867868        // create doctype node
    868869        PDOMDOCTYPENODE pNew = NULL;
    869         arc = xmlCreateDomNode((PDOMNODE)pDocumentNode,
    870                                DOMNODE_DOCUMENT_TYPE,
    871                                pcszDoctypeName,
    872                                0,
    873                                (PDOMNODE*)&pNew);
    874 
    875         if (!arc)
     870        if (!(arc = xmlCreateDomNode((PDOMNODE)pDocumentNode,
     871                                     DOMNODE_DOCUMENT_TYPE,
     872                                     pcszDoctypeName,
     873                                     0,
     874                                     (PDOMNODE*)&pNew)))
    876875        {
    877876            // the node has already been added to the children
     
    963962            PXMLCONTENT pSubModel = &pModel->children[ul];
    964963            PCMELEMENTPARTICLE pSubNew = NULL;
    965             arc = xmlCreateNodeBase(TYPE_UNKNOWN, //       node type... for now
    966                                     sizeof(CMELEMENTPARTICLE),
    967                                     0,
    968                                     0,
    969                                     (PNODEBASE*)&pSubNew);
    970             if (!arc)
     964            if (!(arc = xmlCreateNodeBase(TYPE_UNKNOWN, //       node type... for now
     965                                          sizeof(CMELEMENTPARTICLE),
     966                                          0,
     967                                          0,
     968                                          (PNODEBASE*)&pSubNew)))
    971969            {
    972                 arc = SetupParticleAndSubs(pSubNew,
    973                                            pSubModel,
    974                                            ppElementNamesTree);
    975 
    976                 if (!arc)
     970                if (!(arc = SetupParticleAndSubs(pSubNew,
     971                                                 pSubModel,
     972                                                 ppElementNamesTree)))
    977973                {
    978974                    // no error: append sub-particle to this particle's
     
    10151011    PCMELEMENTDECLNODE pNew = NULL;
    10161012
    1017     arc = xmlCreateNodeBase(TYPE_UNKNOWN,      // for now
    1018                             sizeof(CMELEMENTDECLNODE),
    1019                             pcszName,
    1020                             0,
    1021                             (PNODEBASE*)&pNew);
    1022 
    1023     if (!arc)
     1013    if (!(arc = xmlCreateNodeBase(TYPE_UNKNOWN,      // for now
     1014                                  sizeof(CMELEMENTDECLNODE),
     1015                                  pcszName,
     1016                                  0,
     1017                                  (PNODEBASE*)&pNew)))
    10241018    {
    10251019        treeInit(&pNew->ParticleNamesTree, NULL);
    10261020
    10271021        // set up the "particle" member and recurse into sub-particles
    1028         arc = SetupParticleAndSubs(&pNew->Particle,
    1029                                    pModel,
    1030                                    &pNew->ParticleNamesTree);
    1031 
    1032         if (!arc)
     1022        if (!(arc = SetupParticleAndSubs(&pNew->Particle,
     1023                                         pModel,
     1024                                         &pNew->ParticleNamesTree)))
    10331025            *ppNew = pNew;
    10341026        else
     
    15211513                        pNew = NULL;
    15221514
    1523             pDom->arcDOM = xmlCreateElementNode(pParent,
    1524                                                 pcszElement,
    1525                                                 &pNew);
    1526 
    1527             if (!pDom->arcDOM)
     1515            if (!(pDom->arcDOM = xmlCreateElementNode(pParent,
     1516                                                      pcszElement,
     1517                                                      &pNew)))
    15281518                // OK, node is valid:
    15291519                // push this on the stack so we can add child elements
     
    15561546                {
    15571547                    PDOMNODE pAttrib;
    1558                     pDom->arcDOM = xmlCreateAttributeNode(pNew,                    // element,
    1559                                                           papcszAttribs[i],        // attr name
    1560                                                           papcszAttribs[i + 1],    // attr value
    1561                                                           &pAttrib);
    1562 
    1563                     if (pDom->arcDOM)
    1564                         xmlSetError(pDom,
    1565                                     pDom->arcDOM,
    1566                                     papcszAttribs[i],
    1567                                     TRUE);      // validation
    1568                     else
     1548                    if (!(pDom->arcDOM = xmlCreateAttributeNode(pNew,                  // element,
     1549                                                                papcszAttribs[i],      // attr name
     1550                                                                papcszAttribs[i + 1],  // attr value
     1551                                                                &pAttrib)))
    15691552                        // shall we validate?
    15701553                        if (pDom->pDocTypeNode)
     
    15721555                                                  pAttrib,
    15731556                                                  &pAttribDeclBase);
     1557                    else
     1558                    {
     1559                        xmlSetError(pDom,
     1560                                    pDom->arcDOM,
     1561                                    papcszAttribs[i],
     1562                                    TRUE);      // validation
     1563                        break;
     1564                    }
    15741565                }
    15751566
     
    16401631
    16411632    // continue parsing only if we had no errors so far
    1642     if (!pDom->arcDOM)
    1643     {
    1644         if (len)
    1645         {
    1646             // we need a new text node:
    1647             PDOMSTACKITEM pSI = PopElementStack(pDom,
    1648                                                 NULL);     // no free
    1649             if (!pDom->arcDOM)
     1633    if (    (!pDom->arcDOM)
     1634         && (len)
     1635       )
     1636    {
     1637        // we need a new text node:
     1638        PDOMSTACKITEM pSI = PopElementStack(pDom,
     1639                                            NULL);     // no free
     1640        if (!pDom->arcDOM)
     1641        {
     1642            PDOMNODE    pParent = pSI->pDomNode;
     1643                        // pNew = NULL;
     1644
     1645            BOOL fIsWhitespace = FALSE;
     1646
     1647            // shall we validate?
     1648            if (pDom->pDocTypeNode)
    16501649            {
    1651                 PDOMNODE    pParent = pSI->pDomNode;
    1652                             // pNew = NULL;
    1653 
    1654                 BOOL fIsWhitespace = FALSE;
    1655 
    1656                 // shall we validate?
    1657                 if (pDom->pDocTypeNode)
     1650                // yes: check if the parent element allows
     1651                // for content at all (must be "mixed" model)
     1652
     1653                // get the element decl from the tree
     1654                PCMELEMENTDECLNODE pElementDecl;
     1655                if (pElementDecl = pSI->pElementDecl)
    16581656                {
    1659                     // yes: check if the parent element allows
    1660                     // for content at all (must be "mixed" model)
    1661 
    1662                     // get the element decl from the tree
    1663                     PCMELEMENTDECLNODE pElementDecl = pSI->pElementDecl;
    1664 
    1665                     if (pElementDecl)
     1657                    switch (pElementDecl->Particle.NodeBase.ulNodeType)
    16661658                    {
    1667                         switch (pElementDecl->Particle.NodeBase.ulNodeType)
     1659                        case ELEMENTPARTICLE_ANY:
     1660                        case ELEMENTPARTICLE_MIXED:
     1661                            // those two are okay
     1662                        break;
     1663
     1664                        case ELEMENTPARTICLE_EMPTY:
     1665                            // that's an error for sure
     1666                            pDom->arcDOM = ERROR_ELEMENT_CANNOT_HAVE_CONTENT;
     1667                        break;
     1668
     1669                        default:
    16681670                        {
    1669                             case ELEMENTPARTICLE_ANY:
    1670                             case ELEMENTPARTICLE_MIXED:
    1671                                 // those two are okay
    1672                             break;
    1673 
    1674                             case ELEMENTPARTICLE_EMPTY:
    1675                                 // that's an error for sure
    1676                                 pDom->arcDOM = ERROR_ELEMENT_CANNOT_HAVE_CONTENT;
    1677                             break;
    1678 
    1679                             default:
    1680                             {
    1681                                 // ELEMENTPARTICLE_CHOICE:
    1682                                 // ELEMENTPARTICLE_SEQ:
    1683                                 // with these two, we accept whitespace, but nothing
    1684                                 // else... so if we have characters other than
    1685                                 // whitespace, terminate
    1686                                 ULONG ul;
    1687                                 const char *p = s;
    1688 
    1689                                 if (pDom->flParserFlags & DF_DROP_WHITESPACE)
    1690                                     fIsWhitespace = TRUE;
    1691 
    1692                                 for (ul = 0;
    1693                                      ul < len;
    1694                                      ul++, p++)
    1695                                     if (!strchr("\r\n\t ", *p))
    1696                                     {
    1697                                         // other character:
    1698                                         xmlSetError(pDom,
    1699                                                     ERROR_ELEMENT_CANNOT_HAVE_CONTENT,
    1700                                                     pParent->NodeBase.strNodeName.psz,
    1701                                                     TRUE);
    1702                                         fIsWhitespace = FALSE;
    1703                                         break;
    1704                                     }
    1705                             }
     1671                            // ELEMENTPARTICLE_CHOICE:
     1672                            // ELEMENTPARTICLE_SEQ:
     1673                            // with these two, we accept whitespace, but nothing
     1674                            // else... so if we have characters other than
     1675                            // whitespace, terminate
     1676                            ULONG ul;
     1677                            const char *p = s;
     1678
     1679                            if (pDom->flParserFlags & DF_DROP_WHITESPACE)
     1680                                fIsWhitespace = TRUE;
     1681
     1682                            for (ul = 0;
     1683                                 ul < len;
     1684                                 ul++, p++)
     1685                                if (!strchr("\r\n\t ", *p))
     1686                                {
     1687                                    // other character:
     1688                                    xmlSetError(pDom,
     1689                                                ERROR_ELEMENT_CANNOT_HAVE_CONTENT,
     1690                                                pParent->NodeBase.strNodeName.psz,
     1691                                                TRUE);
     1692                                    fIsWhitespace = FALSE;
     1693                                    break;
     1694                                }
    17061695                        }
    17071696                    }
    1708 
    1709                 } // end if (pDom->pDocTypeNode)
    1710 
    1711                 if (!fIsWhitespace)
    1712                     // this is false if any of the following
    1713                     // is true:
    1714                     // --  we are not validating at all
    1715                     // --  we are validating, but the the element
    1716                     //     can have mixed content
    1717                     // --  we are validating and the element does
    1718                     //     _not_ have mixed content and DF_DROP_WHITESPACE
    1719                     //     is set, but the string is whitespace only
    1720                     //     --> drop it then
    1721 
    1722                 if (pDom->pLastWasTextNode)
    1723                 {
    1724                     // we had a text node, and no elements or other
    1725                     // stuff in between:
    1726                     xstrcat(pDom->pLastWasTextNode->pstrNodeValue,
    1727                             s,
    1728                             len);
    17291697                }
    1730                 else
    1731                 {
    1732                     pDom->arcDOM = xmlCreateTextNode(pParent,
    1733                                                      s,
    1734                                                      len,
    1735                                                      &pDom->pLastWasTextNode);
    1736                 }
    1737             }
     1698
     1699            } // end if (pDom->pDocTypeNode)
     1700
     1701            if (!fIsWhitespace)
     1702                // this is false if any of the following
     1703                // is true:
     1704                // --  we are not validating at all
     1705                // --  we are validating, but the the element
     1706                //     can have mixed content
     1707                // --  we are validating and the element does
     1708                //     _not_ have mixed content and DF_DROP_WHITESPACE
     1709                //     is set, but the string is whitespace only
     1710                //     --> drop it then
     1711
     1712            if (pDom->pLastWasTextNode)
     1713                // we had a text node, and no elements or other
     1714                // stuff in between:
     1715                xstrcat(pDom->pLastWasTextNode->pstrNodeValue,
     1716                        s,
     1717                        len);
     1718            else
     1719                pDom->arcDOM = xmlCreateTextNode(pParent,
     1720                                                 s,
     1721                                                 len,
     1722                                                 &pDom->pLastWasTextNode);
    17381723        }
    17391724    }
     
    18061791                pDom->arcDOM = ERROR_DOM_DUPLICATE_DOCTYPE;
    18071792            else
    1808             {
    18091793                pDom->arcDOM = xmlCreateDocumentTypeNode(pDocumentNode,
    18101794                                                         pcszDoctypeName,
     
    18131797                                                         fHasInternalSubset,
    18141798                                                         &pDom->pDocTypeNode);
    1815             }
    18161799        }
    18171800    }
     
    20212004            // declarations tree
    20222005            PCMELEMENTDECLNODE pNew = NULL;
    2023             pDom->arcDOM = xmlCreateElementDecl(pcszName,
    2024                                                 pModel,
    2025                                                 &pNew);
     2006            if (!(pDom->arcDOM = xmlCreateElementDecl(pcszName,
     2007                                                      pModel,
     2008                                                      &pNew)))
    20262009                                    // this recurses!!
    20272010                                    // after this, pModel is invalid
    2028 
    2029             if (pDom->arcDOM == NO_ERROR)
    20302011            {
    20312012                // add this to the doctype's declarations tree
     
    20582039    // PSZ pszType = strhSubstr(p, pNext);
    20592040    PNODEBASE pNew = NULL;
    2060     APIRET arc = xmlCreateNodeBase(ATTRIBUTE_DECLARATION_ENUM,
    2061                                    sizeof(NODEBASE),
    2062                                    p,
    2063                                    (pNext - p),
    2064                                    &pNew);
    2065     if (!arc)
     2041    APIRET arc;
     2042
     2043    if (!(arc = xmlCreateNodeBase(ATTRIBUTE_DECLARATION_ENUM,
     2044                                  sizeof(NODEBASE),
     2045                                  p,
     2046                                  (pNext - p),
     2047                                  &pNew)))
    20662048        treeInsert(&pDecl->ValuesTree,
    20672049                   NULL,
     
    21752157                // add a new attribute def (CMATTRIBUTEDEDECL) to that
    21762158                PCMATTRIBUTEDECL  pNew = NULL;
    2177                 pDom->arcDOM = xmlCreateNodeBase(ATTRIBUTE_DECLARATION,
    2178                                                  sizeof(CMATTRIBUTEDECL),
    2179                                                  pcszAttribName,
    2180                                                  0,
    2181                                                  (PNODEBASE*)&pNew);
    2182                 if (!pDom->arcDOM)
     2159                if (!(pDom->arcDOM = xmlCreateNodeBase(ATTRIBUTE_DECLARATION,
     2160                                                       sizeof(CMATTRIBUTEDECL),
     2161                                                       pcszAttribName,
     2162                                                       0,
     2163                                                       (PNODEBASE*)&pNew)))
    21832164                {
    21842165                    treeInit(&pNew->ValuesTree, NULL);
     
    23682349 *          document if the "encoding" attribute of the
    23692350 *          XML @text_declaration starts with "cp" (e.g.
    2370  *          "cp850") and will then receives the following
     2351 *          "cp850") and will then receive the following
    23712352 *          parameters:
    23722353 *
Note: See TracChangeset for help on using the changeset viewer.