richter 00/12/07 01:35:26
Modified: . Tag: Embperl2c epcomp.c epdom.c epdom.h
Log:
Revision Changes Path
No revision
No revision
1.4.2.22 +6 -3 embperl/Attic/epcomp.c
Index: epcomp.c
===================================================================
RCS file: /home/cvs/embperl/Attic/epcomp.c,v
retrieving revision 1.4.2.21
retrieving revision 1.4.2.22
diff -u -r1.4.2.21 -r1.4.2.22
--- epcomp.c 2000/12/05 20:15:24 1.4.2.21
+++ epcomp.c 2000/12/07 09:35:23 1.4.2.22
@@ -911,7 +911,7 @@
}
if (pCmd -> bRemoveNode & 1)
- Node_selfRemoveChild(pDomTree, -1, pNode) ;
+ pNode -> bFlags = 0 ;
else if (pCmd -> bRemoveNode & 8)
pNode -> bFlags |= nflgIgnore ;
@@ -1182,8 +1182,11 @@
if ((rc = embperl_CompileNode (r, pDomTree, xChildNode,
bCheckpointPending)) != ok)
return rc ;
- xChildNode = Node_nextSibling (pDomTree, xChildNode) ;
- }
+ pNode = Node_self (pDomTree, xChildNode) ;
+ xChildNode = Node_nextSibling (pDomTree, xChildNode) ;
+ if (pNode -> bFlags == 0)
+ Node_selfRemoveChild(pDomTree, -1, pNode) ;
+ }
}
1.4.2.11 +278 -404 embperl/Attic/epdom.c
Index: epdom.c
===================================================================
RCS file: /home/cvs/embperl/Attic/epdom.c,v
retrieving revision 1.4.2.10
retrieving revision 1.4.2.11
diff -u -r1.4.2.10 -r1.4.2.11
--- epdom.c 2000/12/06 07:37:17 1.4.2.10
+++ epdom.c 2000/12/07 09:35:23 1.4.2.11
@@ -647,7 +647,7 @@
static int DomTree_dodelete (tDomTree * pDomTree)
{
- tNodePad * * pLookup = (tNodePad * *)pDomTree -> pLookup ;
+ // tNodePad * * pLookup = (tNodePad * *)pDomTree -> pLookup ;
int numLookup ;
tIndex xDomTree = pDomTree -> xNdx ;
tIndex xNdx ;
@@ -662,6 +662,7 @@
return ok ;
}
+#if 0 // ??? still todo
numLookup = ArrayGetSize (pLookup) ;
pLookup += numLookup - 1 ;
while (numLookup-- > 0)
@@ -707,7 +708,9 @@
pLookup-- ;
}
+#endif
+
ArrayFree (&pDomTree -> pLookup) ;
ArrayFree (&pDomTree -> pOrder) ;
@@ -992,268 +995,91 @@
*/
-/* ------------------------------------------------------------------------ */
-/* */
-/* NewPad */
-/* */
-/* Create a new pad for storing nodes */
-/* */
-/* ------------------------------------------------------------------------ */
-
-
-static struct tNodePad * NewPad (/*in*/ tDomTree * pDomTree,
- /*in*/ tIndex xParent,
- /*in*/ int nSize)
-
- {
- tIndex xNdx = ArrayAdd (&pDomTree -> pLookup, 1) ;
- struct tNodePad * pChilds ;
- if (nSize == 0)
- nSize = nInitialNodePadSize ;
- else
- nSize = ((nSize + sizeof (struct tNodePad)) / nInitialNodePadSize + 1) *
nInitialNodePadSize ;
-
- if ((pDomTree -> pLookup[xNdx] = pChilds = dom_malloc (nSize)) == NULL)
- return NULL ;
-
- pChilds -> nType = ntypPad ;
- pChilds -> nFill = sizeof (struct tNodePad) ;
- pChilds -> nMax = nInitialNodePadSize ;
- pChilds -> numChilds = 0 ;
- pChilds -> xParent = xParent ;
- pChilds -> xNdx = xNdx ;
- pChilds -> xFirst = xNdx ;
- pChilds -> xNext = 0 ;
- pChilds -> xPrev = 0 ;
- pChilds -> xLast = 0 ;
- pChilds -> xDomTree = pDomTree -> xNdx ;
-
-
- numPads++ ;
- return pChilds ;
- }
/* ------------------------------------------------------------------------ */
/* */
-/* NodePad_appendChild */
+/* Node_newAndAppend */
/* */
-/* Append a child node to a pad */
+/* Create new node and append it to parent */
/* */
/* ------------------------------------------------------------------------ */
-tNodeData * NodePad_appendChild (/*in*/ tDomTree * pDomTree,
- /*in*/ tNodePad * * ppPad,
- /*in*/ tNodeType nType,
- /*in*/ tIndex xText,
- /*in*/ int nLinenumber)
- {
- tNodePad * pPad = *ppPad ;
- tNodeData * pNew ;
- tNode xNdx ;
-
- if (pPad -> xLast && pPad -> xFirst == pPad -> xNdx)
- pPad = NodePad_self (pDomTree, pPad -> xLast) ;
-
- if (pPad -> nFill + sizeof (struct tNodeData) > pPad -> nMax)
- { /* pad full -> make room */
- struct tNodePad * pNext = NewPad (pDomTree, pPad -> xParent, 0) ;
- struct tNodePad * pFirst = NodePad_self (pDomTree, pPad -> xFirst) ;
-
- pNext -> xPrev = pPad -> xNdx ;
- pPad -> xNext = pNext -> xNdx ;
- pNext -> xFirst = pFirst -> xFirst ;
- if (pFirst -> xLast == pPad -> xNdx || pFirst -> xLast == 0)
- pFirst -> xLast = pNext -> xNdx ;
-
- *ppPad = pPad = pNext ;
- }
- pNew = (struct tNodeData *)(((tUInt8 *)pPad) + pPad -> nFill) ;
- xNdx = ArrayAdd (&pDomTree -> pLookup, 1) ;
-
- pDomTree -> pLookup[xNdx] = pNew ;
-
- pNew -> nText = xText ;
- pNew -> nType = nType ;
- pNew -> numAttr = 0 ;
- pNew -> xNdx = xNdx ;
- pNew -> xChilds = 0 ;
- pNew -> bFlags = nflgOK ;
- pNew -> nPadOffset = pPad -> nFill ;
- pNew -> nLinenumber = nLinenumber ;
-
- pPad -> numChilds++ ;
- pPad -> nFill += sizeof (struct tNodeData) ;
- numNodes++ ;
+tNodeData * Node_newAndAppend (/*in*/ tDomTree * pDomTree,
+ /*in*/ tIndex xParent,
+ /*in*/ tIndex * pxChilds,
+ /*in*/ tSInt32 nLinenumber,
+ /*in*/ tSInt32 nSize)
- return pNew ;
- }
-
-
-/* ------------------------------------------------------------------------ */
-/* */
-/* NodePad_splitPad */
-/* */
-/* Split a pad into two */
-/* */
-/* ------------------------------------------------------------------------ */
-
-tNodePad * NodePad_splitPad (/*in*/ tDomTree * pDomTree,
- /*in*/ tNodePad * pPad,
- /*in*/ tNodeData * pNewFirstNode,
- /*in*/ int nNewNodeSize)
-
{
- struct tNodePad * pFirst;
- struct tNodePad * pNext = NewPad (pDomTree, pPad -> xParent,
nNewNodeSize) ;
- struct tNodeData * pNewNode = NodePad_selfFirstChild (pDomTree, pNext) ;
- int nCopySize ;
- int nOffset ;
- void * * pLookup ;
+ tIndex xChilds = pxChilds?*pxChilds:0 ;
+ tNodeData * pNewChild ;
+ tIndex xNdx = ArrayAdd (&pDomTree -> pLookup, 1) ;
-
- if (pPad -> numChilds == 1)
- {
- pNext -> xPrev = pPad -> xPrev ;
- pNext -> xNext = pPad -> xNext ;
- pNext -> xFirst = pPad -> xFirst ;
- pNext -> xLast = pPad -> xLast ;
- pNext -> xNdx = pPad -> xNdx ;
- ArraySetSize (&pDomTree -> pLookup, ArrayGetSize (pDomTree -> pLookup) - 1) ;
- pDomTree -> pLookup[pNext -> xNdx] = pNext ;
- }
- else
- {
- pNext -> xPrev = pPad -> xNdx ;
- pNext -> xNext = pPad -> xNext ;
- pNext -> xFirst = pPad -> xFirst ;
-
- pFirst = NodePad_self (pDomTree, pPad -> xFirst) ;
- if (pFirst -> xLast == pPad -> xNdx || pFirst -> xLast == 0)
- pFirst -> xLast = pNext -> xNdx ;
-
- pPad -> xNext = pNext -> xNdx ;
- }
-
- nCopySize = pPad -> nFill - pNewFirstNode -> nPadOffset ;
- memcpy (pNewNode, pNewFirstNode, nCopySize) ;
- pPad -> nFill -= nCopySize ;
- pNext -> nFill += nCopySize ;
-
- pLookup = pDomTree -> pLookup ;
- while (pNewNode)
- {
- int n = pNewNode -> numAttr ;
- tAttrData * pAttr = Node_selfFirstAttr(pNewNode) ;
+ if (nSize == 0)
+ nSize = sizeof (tNodeData) ;
- while (n--)
- {
- pLookup[pAttr -> xNdx] = pAttr ;
- pAttr++ ;
- }
+ if ((pDomTree -> pLookup[xNdx] = pNewChild = dom_malloc (nSize)) == NULL)
+ return NULL ;
- pNewNode -> nPadOffset = ((tUInt8 *)pNewNode) - ((tUInt8 *)pNext) ;
- pLookup[pNewNode -> xNdx] = pNewNode ;
- pPad -> numChilds-- ;
- pNext -> numChilds++ ;
- nOffset = sizeof (struct tNodeData) + sizeof (struct tAttrData) * pNewNode ->
numAttr ;
- if (pNext -> nFill <= pNewNode -> nPadOffset + nOffset)
- break ;
- pNewNode = (struct tNodeData *)(((tUInt8 *)pNewNode) + nOffset) ;
- }
+ memset (pNewChild, 0, nSize) ;
+ pNewChild -> xParent = xParent ;
+ pNewChild -> xNdx = xNdx ;
+ pNewChild -> nLinenumber = nLinenumber ;
+ pNewChild -> bFlags = nflgOK ;
+
+ if (xChilds)
+ { /* --- attribute has already childs, get the first and last one --- */
+ tNodeData * pFirstChild = Node_self (pDomTree, xChilds) ;
+ tNodeData * pLastChild = Node_self (pDomTree, pFirstChild -> xPrev) ;
+
+ pNewChild -> xNext = pFirstChild -> xNdx ;
+ pNewChild -> xPrev = pLastChild -> xNdx ;
+ pFirstChild -> xPrev = xNdx ;
+ pLastChild -> xNext = xNdx ;
+ }
+ else
+ /* --- attribute has no childs, get a new one --- */
+ {
+ pNewChild -> xPrev = xNdx ;
+ pNewChild -> xNext = xNdx ;
+ if (pxChilds)
+ *pxChilds = xNdx ;
+ }
- if (pPad -> numChilds == 0)
- {
- dom_free (pPad) ;
- }
+ numNodes++ ;
- return pNext ;
+ return pNewChild ;
}
/* ------------------------------------------------------------------------ */
/* */
-/* NodePad_clonePad */
+/* Node_selfExpand */
/* */
-/* clone a pad */
+/* Create new node and append it to parent */
/* */
/* ------------------------------------------------------------------------ */
-tNodePad * NodePad_clonePad (/*in*/ tDomTree * pDomTree,
- /*in*/ tNodePad * pPad)
-
- {
- tNodePad * pNewPad ;
- tIndex xNdx = pPad -> xNdx ;
- tNodeData * pNewNode ;
- int nOffset ;
- void * * pLookup = pDomTree -> pLookup ;
-
- if ((pLookup[xNdx] = pNewPad = dom_malloc (pPad -> nMax)) == NULL)
- return NULL ;
-
- memcpy (pNewPad, pPad, pPad -> nMax) ;
- pNewPad -> xDomTree = pDomTree -> xNdx ;
- pNewNode = NodePad_selfFirstChild (pDomTree, pNewPad) ;
+tNodeData * Node_selfExpand (/*in*/ tDomTree * pDomTree,
+ /*in*/ tNodeData * pNode,
+ /*in*/ tSInt32 nSize)
- while (pNewNode)
- {
- int n = pNewNode -> numAttr ;
- tAttrData * pAttr = Node_selfFirstAttr(pNewNode) ;
-
- if (pNewNode -> nText)
- NdxStringRefcntInc (pNewNode -> nText) ;
- while (n--)
- {
- pLookup[pAttr -> xNdx] = pAttr ;
- if (pAttr -> xName)
- NdxStringRefcntInc (pAttr -> xName) ;
- if (pAttr -> xValue && (pAttr -> bFlags & aflgAttrValue))
- NdxStringRefcntInc (pAttr -> xValue) ;
- pAttr++ ;
- }
-
- pLookup[pNewNode -> xNdx] = pNewNode ;
- nOffset = sizeof (struct tNodeData) + sizeof (struct tAttrData) * pNewNode ->
numAttr ;
- if (pNewPad -> nFill <= pNewNode -> nPadOffset + nOffset)
- break ;
- pNewNode = (struct tNodeData *)(((tUInt8 *)pNewNode) + nOffset) ;
- }
-
- return pNewPad ;
- }
-
-/* ------------------------------------------------------------------------ */
-/* */
-/* Node_condClonePad */
-/* */
-/* clone the pad pointed to by node if it lives in another DomTree */
-/* */
-/* ------------------------------------------------------------------------ */
-
-tNodePad * Node_condClonePad (/*in*/ tDomTree * pDomTree,
- /*in*/ tNode xNode)
-
{
- tNodeData * pNode = Node_self (pDomTree, xNode) ;
- tNodePad * pPad = NULL ;
+ tNodeData * pNewChild ;
- if (pNode)
- {
- if (pNode -> nType == ntypAttr)
- pPad = Node_selfPad (Attr_selfNode(((tAttrData *)pNode))) ;
- else
- pPad = Node_selfPad (pNode) ;
+ if (nSize == 0)
+ nSize = sizeof (tNodeData) ;
- if (pPad -> xDomTree != pDomTree -> xNdx)
- NodePad_clonePad (pDomTree, pPad) ;
- }
-
- return pPad ;
+ if ((pDomTree -> pLookup[pNode -> xNdx] = pNewChild = dom_realloc (pNode,
nSize)) == NULL)
+ return NULL ;
+
+
+ return pNewChild ;
}
@@ -1374,51 +1200,37 @@
}
- /* --- if come to here we have add a new child node --- */
+ /* --- if we come we here we have add a new child node --- */
{
struct tNodeData * pChilds ;
struct tNodeData * pNew ;
tIndex xNdx ;
+ tIndex xOldValue = 0 ;
if (pParent && pParent -> nType == ntypAttr)
{ /* --- we add a new child to an attribute --- */
- tIndex xOldValue = 0 ;
-
- if (((tAttrData *)pParent) -> bFlags & aflgAttrChilds)
- /* --- attribute has already childs, get the first one --- */
- pChilds = Node_self (pDomTree, ((tAttrData *)pParent) -> xValue) ;
- else
- /* --- attribute has no childs, get a new one --- */
- pChilds = NewNode (pDomTree, xParent, 0) ;
-
if (((tAttrData *)pParent) -> bFlags & aflgAttrValue)
{
xOldValue = ((tAttrData *)pParent) -> xValue ;
+ ((tAttrData *)pParent) -> xValue = 0 ;
((tAttrData *)pParent) -> bFlags &= ~aflgAttrValue ;
+ ((tAttrData *)pParent) -> bFlags |= aflgAttrChilds ;
+
+ pNew = Node_newAndAppend (pDomTree, xParent, &(((tAttrData
*)pParent) -> xValue), nLinenumber, 0) ;
+ pNew -> nText = ntypAttrValue ;
+ pNew -> nText = xOldValue ;
}
+ pNew = Node_newAndAppend (pDomTree, xParent, &(((tAttrData *)pParent)
-> xValue), nLinenumber, 0) ;
- ((tAttrData *)pParent) -> xValue = pChilds -> xNdx ;
- ((tAttrData *)pParent) -> bFlags |= aflgAttrChilds ;
- if (xOldValue)
- NodePad_appendChild (pDomTree, &pChilds, ntypAttrValue, xOldValue,
nLinenumber) ;
-
- }
- else if (!pParent || !pParent -> xChilds)
- {
- pChilds = NewPad (pDomTree, xParent, 0) ;
- /* lprintf (pCurrReq, "[%d]PARSE: NewPad NewChild: %d -> %d\n", pCurrReq
-> nPid, xParent, pChilds -> xNdx) ; */
-
- if (pParent)
- pParent -> xChilds = pChilds -> xNdx ;
- }
- else
- {
- pChilds = NodePad_self (pDomTree, pParent -> xChilds) ;
- }
-
+ }
+ else
+ {
+ pNew = Node_newAndAppend (pDomTree, xParent, pParent?&(pParent ->
xChilds):NULL, nLinenumber, 0) ;
+ }
+
if (sText)
xText = String2Ndx (sText, nTextLen) ;
else
@@ -1426,7 +1238,8 @@
NdxStringRefcntInc(nTextLen) ;
xText = nTextLen ;
}
- pNew = NodePad_appendChild (pDomTree, &pChilds, nType, xText, nLinenumber) ;
+ pNew -> nType = nType ;
+ pNew -> nText = xText ;
if (pCurrReq -> bDebug & dbgParse)
lprintf (pCurrReq, "[%d]PARSE: AddNode: +%02d %*s Element parent=%d
node=%d type=%d text=%*.*s (#%d)\n", pCurrReq -> nPid, nLevel, nLevel * 2, "",
xParent, pNew -> xNdx, nType, nTextLen, nTextLen, sText?sText:"<null>",
@@ -1447,28 +1260,40 @@
-tNode Node_removeChild (/*in*/ tDomTree * pDomTree,
- /*in*/ tNode xNode,
- /*in*/ tNode xChild)
+tNodeData * Node_selfRemoveChild (/*in*/ tDomTree * pDomTree,
+ /*in*/ tNode xParent,
+ /*in*/ tNodeData * pChild)
{
- struct tNodeData * pChild = Node_self (pDomTree, xChild) ;
+ struct tNodeData * pParent = Node_self (pDomTree, pChild -> xParent) ;
- pChild -> bFlags = nflgDeleted ;
-
- if (pChild -> nType != ntypAttr)
+ if (pChild -> xNext == pChild -> xNdx)
+ { /* --- the only child --- */
+ pParent -> xChilds = 0 ;
+ }
+ else
{
- struct tNodePad * pPad = (struct tNodePad * )(((tUInt8 *)pChild) -
pChild -> nPadOffset) ;
+ tNodeData * pPrev = Node_self (pDomTree, pChild -> xPrev) ;
+ tNodeData * pNext = Node_self (pDomTree, pChild -> xNext) ;
- if (xNode != -1 && pPad -> xParent != xNode)
- return 0 ;
+ if (pParent -> xChilds == pChild -> xNdx)
+ { /* --- the first child --- */
+ pParent -> xChilds = pChild -> xNext ;
+ }
- /* pPad -> numChilds-- ; */
+ pPrev -> xNext = pNext -> xNdx ;
+ pNext -> xPrev = pPrev -> xNdx ;
}
+
+
+ pDomTree -> pLookup[pChild -> xNdx] = NULL ;
+ dom_free (pChild) ;
+ numNodes-- ;
- return xChild ;
+ return NULL ;
}
+
/* ------------------------------------------------------------------------ */
/* */
/* Node_removeChild */
@@ -1479,29 +1304,24 @@
-struct tNodeData * Node_selfRemoveChild (/*in*/ tDomTree * pDomTree,
- /*in*/ tNode xNode,
- /*in*/ struct tNodeData * pChild)
+tNode Node_removeChild (/*in*/ tDomTree * pDomTree,
+ /*in*/ tNode xParent,
+ /*in*/ tNode xChild)
{
- tNodePad * pPad = Node_condClonePad (pDomTree, pChild -> xNdx) ;
-
- if (xNode != -1 && pPad -> xParent != xNode)
- return 0 ;
-
- /* relookup in case Pad has cloned */
- pChild = Node_self (pDomTree, pChild -> xNdx) ;
- pChild -> bFlags = nflgDeleted ;
- /* pPad -> numChilds-- ; */
-
- return pChild ;
+ Node_selfRemoveChild (pDomTree, xParent, Node_self (pDomTree, xChild)) ;
+ return 0 ;
}
+
/* ------------------------------------------------------------------------ */
/* */
-/* Node_replaceChild */
+/* Node_cloneNode */
/* */
-/* Replace child node */
+/* clone a node */
+/* bDeep = 1 clone childs also */
+/* bDeep = 0 clone no childs */
+/* bDeep = -1 clone no attributes and no childs */
/* */
/* ------------------------------------------------------------------------ */
@@ -1512,24 +1332,18 @@
{
int len = sizeof (tNodeData) + (bDeep == -1?0:pNode -> numAttr *
sizeof (tAttrData)) ;
- tNode xParent = xNode_selfParentNode (pNode) ;
- tNodePad * pPad = NewPad (pDomTree, xParent, len) ;
- tNodeData * pNew = NodePad_selfFirstChild (pDomTree,pPad) ;
- tNode xNewNode ;
+ tNode xNewNode ;
+ tNodeData * pNew = Node_newAndAppend (pDomTree, pNode -> xParent, NULL, 0, len)
;
+
memcpy (pNew, pNode, len) ;
-
xNewNode = ArrayAdd (&pDomTree -> pLookup, 1) ;
pDomTree -> pLookup[xNewNode] = pNew ;
pNew -> xNdx = xNewNode ;
- pNew -> nPadOffset = pPad -> nFill ;
+
if (pNew -> nText)
NdxStringRefcntInc (pNew -> nText) ;
-
- pPad -> numChilds++ ;
- pPad -> nFill += len ;
- numNodes++ ;
-
+
if (bDeep == -1)
pNew -> numAttr = 0 ;
else
@@ -1572,6 +1386,59 @@
return 0 ;
}
+/* ------------------------------------------------------------------------ */
+/* */
+/* Node_selfCondCloneNode */
+/* */
+/* clone a node if it's part of a different DomTree in preparation for */
+/* a change */
+/* */
+/* ------------------------------------------------------------------------ */
+
+
+tNodeData * Node_selfCondCloneNode (/*in*/ tDomTree * pDomTree,
+ /*in*/ tNodeData * pNode)
+
+ {
+ int len ;
+ tNodeData * pNew ;
+ tAttrData * pAttr ;
+ int n ;
+
+
+ if (pNode -> xDomTree == pDomTree -> xNdx)
+ return pNode ;
+
+
+ len = sizeof (tNodeData) + pNode -> numAttr * sizeof (tAttrData) ;
+
+ pNew = Node_newAndAppend (pDomTree, pNode -> xParent, NULL, 0, len) ;
+
+ memcpy (pNew, pNode, len) ;
+ pDomTree -> pLookup[pNode -> xNdx] = pNew ;
+
+ if (pNew -> nText)
+ NdxStringRefcntInc (pNew -> nText) ;
+
+ pAttr = (tAttrData * )(pNew + 1) ;
+ n = pNew -> numAttr ;
+
+ while (n)
+ {
+ pDomTree -> pLookup[pAttr -> xNdx] = pAttr ;
+ if (pAttr -> xName)
+ NdxStringRefcntInc (pAttr -> xName) ;
+ if (pAttr -> xValue && (pAttr -> bFlags & aflgAttrValue))
+ NdxStringRefcntInc (pAttr -> xValue) ;
+ n-- ;
+ pAttr++ ;
+ }
+
+ return pNew ;
+ }
+
+
+
/* ------------------------------------------------------------------------ */
/* */
@@ -1595,8 +1462,7 @@
tNodeData * pNode = Node_self (pDomTree, xNode) ;
tNodeData * pOldChild ;
- Node_condClonePad (pOldChildDomTree, xOldChild) ;
- pOldChild = Node_self (pOldChildDomTree, xOldChild) ;
+ pOldChild = Node_selfCondCloneNode (pOldChildDomTree, Node_self
(pOldChildDomTree, xOldChild)) ;
if (pOldChild -> bFlags & nflgModified)
{
@@ -1612,28 +1478,9 @@
tAttrData * pAttr ;
int n ;
- if (pNode -> numAttr > pOldChild -> numAttr)
- {
- tAttrData * pNew = ((struct tAttrData * )(pOldChild + 1)) + pOldChild ->
numAttr ;
- tNodePad * pPad = Node_selfPad (pOldChild) ;
-
-
- if (((tUInt8 *)pNew) - ((tUInt8 *)pPad) != pPad -> nFill)
- { /* not last child in pad -> move following node to new pad */
- NodePad_splitPad (pOldChildDomTree, pPad, (tNodeData *)pNew, 0) ;
- }
-
- if (((tUInt8 *)pOldChild) - ((tUInt8 *)pPad) + len > pPad -> nMax)
- { /* pad full -> move into new pad */
- pPad = NodePad_splitPad (pOldChildDomTree, pPad, pOldChild, len) ;
- pOldChild = NodePad_selfFirstChild (pOldChildDomTree, pPad) ;
- }
-
- }
- nOffset = pOldChild -> nPadOffset ;
- xOldChild = pOldChild -> xNdx ;
-
+ pOldChild = Node_selfExpand (pOldChildDomTree, pOldChild, len) ;
+
if (pOldChild -> nText)
NdxStringFree (pOldChild -> nText) ;
@@ -1656,7 +1503,7 @@
NdxStringRefcntInc (pOldChild -> nText) ;
- pOldChild -> nPadOffset = nOffset ;
+ pOldChild -> xDomTree = pDomTree -> xNdx ;
pOldChild -> xNdx = xOldChild ;
pOldChild -> bFlags |= bFlags ;
@@ -1723,8 +1570,7 @@
/* *** lprintf (pCurrReq, "rp1--> SVs=%d %s DomTree Old=%d\n", sv_count,
sText?sText:"<null>", Node_selfDomTree (Node_self (pDomTree, xOldChild))) ; */
- Node_condClonePad (pDomTree, xOldChild) ;
- pOldChild = Node_self (pDomTree, xOldChild) ;
+ pOldChild = Node_selfCondCloneNode (pDomTree, Node_self (pDomTree, xOldChild))
;
xCheckpointCache[nCheckpointCache++] = xOldChild ;
@@ -1764,6 +1610,7 @@
}
+#if 0 /* macro in epdom.h */
/* ------------------------------------------------------------------------ */
/* */
@@ -1800,6 +1647,8 @@
return Node_self (pDomTree, pPad -> xParent) ;
}
+
+
/* ------------------------------------------------------------------------ */
/* */
/* Node_selfParentNode */
@@ -1867,6 +1716,9 @@
return pChildNode ;
}
+#endif
+
+
/* ------------------------------------------------------------------------ */
/* */
/* Node_selfLastChild */
@@ -1880,37 +1732,10 @@
/*in*/ tNodeData * pNode)
{
- struct tNodePad * pPad = NodePad_self (pDomTree, pNode -> xChilds) ;
- tNodeData * pChildNode ;
- tNodeData * pLastChild ;
- if (pPad == NULL)
- return NULL ;
-
- if (pPad -> xLast && pPad -> xLast != pPad -> xNdx)
- pPad = NodePad_self (pDomTree, pPad -> xLast) ;
+ if (pNode -> xChilds)
+ return Node_self (pDomTree, Node_selfFirstChild (pDomTree, pNode) -> xPrev)
;
- pLastChild = NULL ;
- do
- {
- pChildNode = ((tNodeData *)(pPad + 1)) ;
-
- while (pChildNode)
- {
- pLastChild = pChildNode ;
- pChildNode = Node_selfNextSibling (pDomTree, pChildNode) ;
- }
-
- if (!pLastChild)
- {
- if (pPad -> xPrev)
- pPad = NodePad_self (pDomTree, pPad -> xPrev) ;
- else
- return NULL ;
- }
- }
- while (!pLastChild) ;
-
- return pLastChild ;
+ return 0 ;
}
@@ -1918,7 +1743,7 @@
/* */
/* Node_selfNthChild (pNode, nChildNo) ; */
/* */
-/* Get first child node */
+/* Get nth child node */
/* */
/* ------------------------------------------------------------------------ */
@@ -1928,35 +1753,31 @@
/*in*/ int nChildNo)
{
- struct tNodePad * pPad = pDomTree -> pLookup[pNode -> xChilds] ;
- struct tNodeData * pChildNode ;
-
- if (pPad == NULL)
- return 0 ;
-
- while (nChildNo >= pPad -> numChilds && pPad -> xNext)
- {
- nChildNo -= pPad -> numChilds ;
- pPad = pDomTree -> pLookup[pPad -> xNext] ;
- }
+ if (pNode -> xChilds)
+ {
+ tNodeData * pChild ;
+ tNodeData * pFirstChild = Node_selfFirstChild (pDomTree, pNode) ;
- if (nChildNo < 0)
- return NULL ;
+ if (nChildNo == 0)
+ return pFirstChild ;
+
+
+ pChild = pFirstChild ;
-
- pChildNode = ((struct tNodeData *)(pPad + 1)) ;
- while (nChildNo > 0)
- {
- if (pChildNode -> bFlags)
- nChildNo-- ;
- pChildNode = (struct tNodeData *)(((tUInt8 *)pChildNode) + sizeof (struct
tNodeData) + sizeof (struct tAttrData) * pChildNode -> numAttr) ;
- }
+ do
+ {
+ pChild = Node_self (pDomTree, pChild -> xNext) ;
+ if (nChildNo-- < 2)
+ return pChild ;
+ }
+ while (nChildNo > 1 && pChild != pFirstChild) ;
+ }
-
- return pChildNode ;
+ return 0 ;
}
+
/* ------------------------------------------------------------------------ */
/* */
/* Node_nextSibling (xNode) ; */
@@ -1970,25 +1791,16 @@
/*in*/ tNodeData * pNode)
{
- struct tNodePad * pPad = (struct tNodePad * )(((tUInt8 *)pNode) -
pNode -> nPadOffset) ;
+ tNodeData * pParent ;
- do
- {
- int nOffset = sizeof (struct tNodeData) + sizeof (struct tAttrData) * pNode ->
numAttr ;
- if (pPad -> nFill <= pNode -> nPadOffset + nOffset || pPad -> numChilds == 0)
- { /* next pad */
- if (!pPad -> xNext)
- return 0 ;
-
- pPad = pDomTree -> pLookup[pPad -> xNext] ;
- pNode = ((struct tNodeData *)(pPad + 1)) ;
- }
- else
- pNode = (struct tNodeData *)(((tUInt8 *)pNode) + nOffset) ;
- }
- while (!pNode -> bFlags) ;
-
- return pNode ;
+ if (pNode -> xNext == pNode -> xNdx)
+ return NULL ;
+
+ pParent = Node_self (pDomTree, pNode -> xParent) ;
+ if (pParent -> xChilds == pNode -> xNext)
+ return NULL ;
+
+ return Node_self (pDomTree, pNode -> xNext) ;
}
@@ -2007,13 +1819,76 @@
{
tNodeData * pNode = Node_self (pDomTree, xNode) ;
- tNodeData * pNext = Node_selfNextSibling(pDomTree, pNode) ;
+ tNodeData * pParent ;
- return pNext?pNext -> xNdx:0 ;
+ if (pNode -> xNext == pNode -> xNdx)
+ return NULL ;
+
+ pParent = Node_self (pDomTree, pNode -> xParent) ;
+ if (pParent -> xChilds == pNode -> xNext)
+ return NULL ;
+
+ return pNode -> xNext ;
}
+
/* ------------------------------------------------------------------------ */
/* */
+/* Node_previousSibling (xNode) ; */
+/* */
+/* Get previous sibling node */
+/* */
+/* ------------------------------------------------------------------------ */
+
+
+tNodeData * Node_selfPreviousSibling (/*in*/ tDomTree * pDomTree,
+ /*in*/ tNodeData * pNode)
+
+ {
+ tNodeData * pParent ;
+
+ if (pNode -> xPrev == pNode -> xNdx)
+ return NULL ;
+
+ pParent = Node_self (pDomTree, pNode -> xParent) ;
+ if (pParent -> xChilds == pNode -> xPrev)
+ return NULL ;
+
+ return Node_self (pDomTree, pNode -> xPrev) ;
+ }
+
+
+/* ------------------------------------------------------------------------ */
+/* */
+/* Node_previousSibling (xNode) ; */
+/* */
+/* Get previous sibling node */
+/* */
+/* ------------------------------------------------------------------------ */
+
+
+tNode Node_previousSibling (/*in*/ tDomTree * pDomTree,
+ /*in*/ tNode xNode)
+
+
+ {
+ tNodeData * pNode = Node_self (pDomTree, xNode) ;
+ tNodeData * pParent ;
+
+ if (pNode -> xPrev == pNode -> xNdx)
+ return NULL ;
+
+ pParent = Node_self (pDomTree, pNode -> xParent) ;
+ if (pParent -> xChilds == pNode -> xPrev)
+ return NULL ;
+
+ return pNode -> xPrev ;
+ }
+
+
+
+/* ------------------------------------------------------------------------ */
+/* */
/* Node_toString */
/* */
/* */
@@ -2425,8 +2300,7 @@
tNode xAttr ;
tNodeData * pNewNode ;
- Node_condClonePad (pDomTree, pNode -> xNdx) ;
- pNode = Node_self (pDomTree, pNode -> xNdx) ;
+ pNode = Node_selfCondCloneNode (pDomTree, pNode) ;
pAttr = Element_selfGetAttribut (pDomTree, pNode, sAttrName, nAttrNameLen) ;
if (pAttr)
@@ -2493,7 +2367,7 @@
tAttrData * pAttr ;
tNodeData * pNewNode ;
- Node_condClonePad (pDomTree, pNode -> xNdx) ;
+ Node_selfCondCloneNode (pDomTree, pNode) ;
pNode = Node_self (pDomTree, pNode -> xNdx) ;
pAttr = Element_selfGetAttribut (pDomTree, pNode, sAttrName, nAttrNameLen) ;
@@ -2589,7 +2463,7 @@
if (!(pAttr -> bFlags & aflgAttrChilds))
return Ndx2String (pAttr -> xValue) ;
- pNode = NodePad_selfFirstChild (pDomTree, NodePad_self(pDomTree, pAttr ->
xValue)) ;
+ pNode = Node_self (pDomTree, pAttr -> xValue) ;
StringNew (ppAttr, 512) ;
1.4.2.8 +24 -12 embperl/Attic/epdom.h
Index: epdom.h
===================================================================
RCS file: /home/cvs/embperl/Attic/epdom.h,v
retrieving revision 1.4.2.7
retrieving revision 1.4.2.8
diff -u -r1.4.2.7 -r1.4.2.8
--- epdom.h 2000/12/06 07:37:17 1.4.2.7
+++ epdom.h 2000/12/07 09:35:23 1.4.2.8
@@ -38,6 +38,7 @@
typedef tIndex tNode ;
typedef tIndex tAttr ;
+#if 0
struct tNodePad
{
@@ -56,32 +57,33 @@
typedef struct tNodePad tNodePad ;
+#endif
+
struct tNodeData
{
tNodeType nType ;
tUInt8 bFlags ;
tIndexShort xDomTree ;
tIndex xNdx ;
- tNode xPrev ;
- tNode xNext ;
- tNode xParent ;
- tNode xChilds ;
- tNode xLastChild ;
tStringIndex nText ;
+ tNode xChilds ;
tUInt16 numAttr ;
tUInt16 nLinenumber ;
+ tNode xPrev ;
+ tNode xNext ;
+ tNode xParent ;
} ;
typedef struct tNodeData tNodeData ;
struct tAttrData
{
- tNodeType nType ;
+ tNodeType nType ; /* must be at the same offset as
tNodeData.nType ! */
tUInt8 bFlags ;
tUInt16 nNodeOffset ;
- tIndex xNdx ;
+ tIndex xNdx ; /* must be at the same offset as tNodeData.xNdx !
*/
tIndex xName ;
- tIndex xValue ;
+ tIndex xValue ; /* must be at the same offset as
tNodeData.xChilds ! */
} ;
typedef struct tAttrData tAttrData ;
@@ -278,6 +280,8 @@
/*in*/ int nLinenumber) ;
+#if 0
+
tNode Node_parentNode (/*in*/ tDomTree * pDomTree,
/*in*/ tNode xNode) ;
@@ -291,6 +295,7 @@
tNodeData * Node_selfFirstChild (/*in*/ tDomTree * pDomTree,
/*in*/ tNodeData * pNode) ;
+#endif
tNodeData * Node_selfNthChild (/*in*/ tDomTree * pDomTree,
/*in*/ struct tNodeData * pNode,
@@ -311,13 +316,20 @@
#define NodePad_selfFirstChild(pDomTree,pNodePad) ((tNodeData *)(pNodePad +
1))
#define Node_self(pDomTree,xNode) ((struct tNodeData *)(pDomTree ->
pLookup[xNode]))
+
+#define Node_parentNode(pDomTree,xNode)
(Node_self(pDomTree,xNode)->xParent)
+#define Node_selfParentNode(pDomTree,pNode) (Node_self(pDomTree,(pNode)->xParent))
+#define xNode_selfParentNode(pDomTree,pNode) ((pNode)->xParent)
+
+#define Node_firstChild(pDomTree,xNode)
(Node_self(pDomTree,xNode)->xChilds)
+#define Node_selfFirstChild(pDomTree,pNode) (Node_self(pDomTree,(pNode)->xChilds))
-#define Node_selfNodeNameNdx(pNode) (pNode -> nText) ;
-#define Node_selfNodeName(pNode) (Ndx2String (pNode -> nText))
+#define Node_selfNodeNameNdx(pNode) ((pNode) -> nText) ;
+#define Node_selfNodeName(pNode) (Ndx2String ((pNode) -> nText))
#define Node_nodeName(pDomTree,pNode) (Ndx2String (Node_self
(pDomTree,xNode) -> nText))
-#define Node_selfPad(pNode) ((struct tNodePad * )(((tUInt8 *)pNode) - pNode
-> nPadOffset))
+#define Node_selfPad(pNode) ((struct tNodePad * )(((tUInt8 *)(pNode)) -
(pNode) -> nPadOffset))
#define Node_selfDomTree(pNode) NodePad_selfDomTree
(Node_selfPad(pNode))
-#define Node_selfFirstAttr(pNode) ((tAttrData *)(pNode + 1))
+#define Node_selfFirstAttr(pNode) ((tAttrData *)((pNode) + 1))
tNodeData * Node_selfCloneNode (/*in*/ tDomTree * pDomTree,
/*in*/ tNodeData * pNode,
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]