richter 00/12/05 23:37:20
Modified: . Tag: Embperl2c epdom.c epdom.h
Log:
Embperl 2 - DOM
Revision Changes Path
No revision
No revision
1.4.2.10 +34 -37 embperl/Attic/epdom.c
Index: epdom.c
===================================================================
RCS file: /home/cvs/embperl/Attic/epdom.c,v
retrieving revision 1.4.2.9
retrieving revision 1.4.2.10
diff -u -r1.4.2.9 -r1.4.2.10
--- epdom.c 2000/12/05 20:15:25 1.4.2.9
+++ epdom.c 2000/12/06 07:37:17 1.4.2.10
@@ -1267,7 +1267,7 @@
-tNode Node_appendChild (/*in*/ tDomTree * pDomTree,
+tNode Node_appendChild (/*in*/ tDomTree * pDomTree,
/*in*/ tNodeType nType,
/*in*/ int bForceAttrValue,
/*in*/ const char * sText,
@@ -1278,44 +1278,31 @@
{
tNodeData * pParent;
- tNodePad * pPad ;
tIndex xText ;
- pPad = Node_condClonePad (pDomTree, xParent) ;
pParent = Node_self (pDomTree, xParent) ;
if (nType == ntypAttr)
- {
- tNodePad * pPad = Node_selfPad (pParent) ;
+ { /* add new attribute to node */
struct tAttrData * pNew ;
tIndex xNdx ;
pNew = ((struct tAttrData * )(pParent + 1)) + pParent -> numAttr ;
- if (((tUInt8 *)pNew) - ((tUInt8 *)pPad) != pPad -> nFill)
- { /* not last child in pad -> move following node to new pad */
- NodePad_splitPad (pDomTree, pPad, (tNodeData *)pNew, 0) ;
- }
- if (((tUInt8 *)pNew) - ((tUInt8 *)pPad) + sizeof (struct tAttrData) > pPad ->
nMax)
- { /* pad full -> move into new pad */
- pPad = NodePad_splitPad (pDomTree, pPad, pParent, ((tUInt8 *)pNew) -
((tUInt8 *)pParent) + sizeof (struct tAttrData)) ;
- pParent = NodePad_selfFirstChild (pDomTree, pPad) ;
- pNew = ((struct tAttrData * )(pParent + 1)) + pParent -> numAttr ;
- }
+ pParent = dom_realloc (pParent, sizeof (tNodeData) + (pParent -> numAttr + 1)
* sizeof (tAttrData)) ;
+ pDomTree -> pLookup[pParent -> xNdx] = pParent ;
xNdx = ArrayAdd (&pDomTree -> pLookup, 1) ;
pDomTree -> pLookup[xNdx] = (struct tNodeData *)pNew ;
- /* is NoInc ok ????? */
- pNew -> xName = sText?String2NdxNoInc (sText, nTextLen):nTextLen ;
+ pNew -> xName = sText?String2NdxNoInc (sText, nTextLen):nTextLen ;
NdxStringRefcntInc (pNew -> xName) ;
- pNew -> xValue = 0 ;
- pNew -> bFlags = aflgOK ;
- pNew -> nType = nType ;
- pNew -> xNdx = xNdx ;
+ pNew -> xValue = 0 ;
+ pNew -> bFlags = aflgOK ;
+ pNew -> nType = nType ;
+ pNew -> xNdx = xNdx ;
pNew -> nNodeOffset = ((tUInt8 *)pNew) - ((tUInt8 *)pParent) ;
pParent -> numAttr++ ;
- pPad -> nFill += sizeof (struct tAttrData) ;
numAttr++ ;
if (pCurrReq -> bDebug & dbgParse)
@@ -1325,13 +1312,20 @@
return xNdx ;
}
- if ((bForceAttrValue || nType == ntypAttrValue) && (pParent -> nType !=
ntypAttr || (pParent -> bFlags & aflgAttrChilds) == 0))
- {
+ if ((bForceAttrValue || nType == ntypAttrValue) &&
+ (pParent -> nType != ntypAttr || (pParent -> bFlags & aflgAttrChilds) == 0))
+ {
+ /* --- add value of attribute, to non attribute parent node */
+ /* first add dummy attribute to parent with xNoName as name index */
+ /* if this attribute already exist, append the new value as new _child_ */
+ /* to that attribute. This means, that an attribute can have multiple */
+ /* child(values), in which case we set the aflgAttrChilds flag */
+
struct tAttrData * pNew = (struct tAttrData * )pParent ;
int bAddChild = 0 ;
if (pNew -> nType != ntypAttr)
- {
+ { /* --- parent is not a attribute --- */
if (nType == ntypAttrValue)
{
int i ;
@@ -1346,16 +1340,16 @@
return 1 ; /* do not add only spaces as cdata inside a tag */
}
- pNew = ((tAttrData *)(pParent + 1)) + pParent -> numAttr - 1 ;
+ pNew = ((tAttrData *)(pParent + 1)) + pParent -> numAttr - 1 ; /* get last
attribute of node */
if (pParent -> numAttr == 0 || pNew -> xName != xNoName || bForceAttrValue
> 1)
- {
+ { /* --- add dummy attribute --- */
if (!(xParent = Node_appendChild (pDomTree, ntypAttr, 0, NULL,
xNoName, xParent, nLevel, nLinenumber)))
return 0 ;
nLevel++ ;
- pNew = (struct tAttrData * )pDomTree -> pLookup[xParent] ;
+ pNew = (struct tAttrData * )pDomTree -> pLookup[xParent] ;
}
else
- {
+ { /* --- dummy attribute already exist, reuse it --- */
xParent = pNew -> xNdx ;
bAddChild = 1 ;
nLevel++ ;
@@ -1364,7 +1358,7 @@
if (!bAddChild && !bForceAttrValue)
- {
+ { /* we have an simple attribute, now put the value into it */
pNew -> xValue = sText?String2NdxNoInc (sText, nTextLen):nTextLen ;
NdxStringRefcntInc (pNew -> xValue) ;
if (pCurrReq -> bDebug & dbgParse)
@@ -1375,25 +1369,28 @@
return xParent ;
}
else
- pParent = (tNodeData *)pNew ;
+ /* --- we have to add a new child to the attribute, so set the attribute
as parent --- */
+ pParent = (tNodeData *)pNew ;
}
-
+ /* --- if come to here we have add a new child node --- */
+
{
- struct tNodePad * pChilds ;
+ struct tNodeData * pChilds ;
struct tNodeData * pNew ;
tIndex xNdx ;
if (pParent && pParent -> nType == ntypAttr)
- {
+ { /* --- we add a new child to an attribute --- */
tIndex xOldValue = 0 ;
if (((tAttrData *)pParent) -> bFlags & aflgAttrChilds)
- pChilds = NodePad_self (pDomTree, ((tAttrData *)pParent) -> xValue)
;
+ /* --- attribute has already childs, get the first one --- */
+ pChilds = Node_self (pDomTree, ((tAttrData *)pParent) -> xValue) ;
else
- pChilds = NewPad (pDomTree, xParent, 0) ;
- /* lprintf (pCurrReq, "[%d]PARSE: NewPad NewAttrChild: %d -> %d\n",
pCurrReq -> nPid, xParent, pChilds -> xNdx) ; */
+ /* --- attribute has no childs, get a new one --- */
+ pChilds = NewNode (pDomTree, xParent, 0) ;
if (((tAttrData *)pParent) -> bFlags & aflgAttrValue)
{
1.4.2.7 +7 -2 embperl/Attic/epdom.h
Index: epdom.h
===================================================================
RCS file: /home/cvs/embperl/Attic/epdom.h,v
retrieving revision 1.4.2.6
retrieving revision 1.4.2.7
diff -u -r1.4.2.6 -r1.4.2.7
--- epdom.h 2000/12/05 04:45:21 1.4.2.6
+++ epdom.h 2000/12/06 07:37:17 1.4.2.7
@@ -31,6 +31,7 @@
typedef signed long tSInt32 ;
typedef tSInt32 tIndex ;
+typedef tSInt16 tIndexShort ;
typedef tIndex tStringIndex ;
typedef tUInt8 tNodeType ;
@@ -59,10 +60,14 @@
{
tNodeType nType ;
tUInt8 bFlags ;
- tUInt16 nPadOffset ;
+ tIndexShort xDomTree ;
tIndex xNdx ;
+ tNode xPrev ;
+ tNode xNext ;
+ tNode xParent ;
+ tNode xChilds ;
+ tNode xLastChild ;
tStringIndex nText ;
- tIndex xChilds ;
tUInt16 numAttr ;
tUInt16 nLinenumber ;
} ;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]