perl-embperl-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rich...@locus.apache.org
Subject cvs commit: embperl/Embperl Tokens.pm
Date Fri, 12 May 2000 21:09:05 GMT
richter     00/05/12 14:09:04

  Modified:    .        Tag: Embperl2 Embperl.xs epcomp.c epdom.c epdom.h
               Embperl  Tag: Embperl2 Tokens.pm
  Log:
  Embperl 2 - Dom & Compile
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.26.2.1  +36 -0     embperl/Embperl.xs
  
  Index: Embperl.xs
  ===================================================================
  RCS file: /home/cvs/embperl/Embperl.xs,v
  retrieving revision 1.26
  retrieving revision 1.26.2.1
  diff -u -r1.26 -r1.26.2.1
  --- Embperl.xs	2000/03/28 19:46:04	1.26
  +++ Embperl.xs	2000/05/12 21:09:02	1.26.2.1
  @@ -597,3 +597,39 @@
       tReq * r
   CODE:
       FreeRequest(r) ; 
  +
  +
  +
  +
  +################################################################################
  +
  +MODULE = HTML::Embperl      PACKAGE = HTML::Embperl::DOM     PREFIX = embperl_
  +
  +
  +void
  +embperl_Node_replaceChildWithCDATA (xOldChild,sText)
  +    int xOldChild
  +    SV * sText
  +CODE:
  +    IV l ;
  +    char * s = SvPV (sText, l) ;
  +    Node_replaceChildWithCDATA (-1, xOldChild, s, l) ;
  +
  +
  +void
  +embperl_Node_removeChild (xChild)
  +    int xChild
  +CODE:
  +    Node_removeChild (-1, xChild) ;
  +
  +
  +void
  +Node_parentNode (xChild)
  +    int xChild
  +
  +void
  +Node_firstChild (xChild)
  +    int xChild
  +
  +
  +
  
  
  
  1.1.2.4   +42 -6     embperl/Attic/epcomp.c
  
  Index: epcomp.c
  ===================================================================
  RCS file: /home/cvs/embperl/Attic/epcomp.c,v
  retrieving revision 1.1.2.3
  retrieving revision 1.1.2.4
  diff -u -r1.1.2.3 -r1.1.2.4
  --- epcomp.c	2000/05/11 07:27:54	1.1.2.3
  +++ epcomp.c	2000/05/12 21:09:02	1.1.2.4
  @@ -21,8 +21,8 @@
       const char *    sPerlCode ;
       } ;
   
  +char * pCode = NULL ;
   
  -
   tStringIndex nMaxEmbperlCmd ;
   struct tEmbperlCmd * pEmbperlCmds ;
   
  @@ -88,6 +88,7 @@
       {
       tNode xChildNode  ;
   
  +    int    valid = 1 ;
       struct tNodeData * pNode = Node_self (xNode) ;
       tStringIndex nNdx = Node_selfNodeNameNdx (pNode) ;
   
  @@ -102,11 +103,13 @@
   
   	    if ((sPerlCode = pCmd -> sPerlCode))
   		{
  +		StringNew (&pCode, 512) ;
   		p = strchr (sPerlCode, '%') ;	
   		while (p)
   		    {
   		    int n = p - sPerlCode ;
  -		    printf ("%*.*s", n, n, sPerlCode) ;
  +		    if (n)
  +			StringAdd (&pCode, sPerlCode, n) ;
   		    q = strchr (p+1, '%') ;	
   		    if (q)
   			{
  @@ -116,15 +119,43 @@
   			    struct tNodeData * pChildNode = Node_selfNthChild (pNode, nChildNo) ;
   
   			    if (pChildNode)
  -				puts (Node_selfNodeName(pChildNode)) ;
  +				StringAdd (&pCode, Node_selfNodeName(pChildNode), 0) ;
   			    else
   				mydie ("missing child") ;			    
   			    }
  +			else if (p[1] == '$')
  +			    {
  +			    if (p[2] == 'n')
  +				{
  +				char s [20] ;
  +				int  l = sprintf (s, "%u", pNode -> xNdx) ;
  +				StringAdd (&pCode, s, l) ; 
  +				}
  +			    }
   			else
   			    {
  -			    const char * sVal = Element_selfGetAttribut (pNode, p + 1, q - p - 1) ;
  +			    const char * sVal ;
  +
  +			    if (p[1] == '!' || p[1] == '*')
  +				{
  +				sVal = Element_selfGetAttribut (pNode, p + 2, q - p - 2) ;
  +				if ((sVal && p[1] == '!') || (!sVal && p[1] == '*') )
  +				    {
  +				    valid = 0 ;
  +				    break ;
  +				    }
  +				}
  +			    else
  +				sVal = Element_selfGetAttribut (pNode, p + 1, q - p - 1) ;
   			    
  -			    puts (sVal?sVal:"") ;
  +			    if (sVal)
  +				{
  +				StringAdd (&pCode, "'",  1) ; 
  +				StringAdd (&pCode, sVal, 0) ; 
  +				StringAdd (&pCode, "'",  1) ; 
  +				}
  +			    else if (p[1] != '!') 
  +				StringAdd (&pCode, "''", 2) ; 
   			    }
   
   			sPerlCode = q + 1 ;
  @@ -135,8 +166,13 @@
   			sPerlCode = p ;
   			p = NULL ; 
   			}
  +		    }
  +		if (valid)
  +		    {
  +		    StringAdd (&pCode, sPerlCode,  0) ; 
  +		    StringAdd (&pCode, "\0",  1) ; 
  +		    lprintf (pCurrReq, "%s\n", pCode) ;
   		    }
  -		puts (sPerlCode) ;
   		}
   	    }
   	}
  
  
  
  1.1.2.8   +241 -40   embperl/Attic/epdom.c
  
  Index: epdom.c
  ===================================================================
  RCS file: /home/cvs/embperl/Attic/epdom.c,v
  retrieving revision 1.1.2.7
  retrieving revision 1.1.2.8
  diff -u -r1.1.2.7 -r1.1.2.8
  --- epdom.c	2000/05/12 14:13:44	1.1.2.7
  +++ epdom.c	2000/05/12 21:09:02	1.1.2.8
  @@ -23,7 +23,7 @@
   struct tNodeData * * pNodeLookup ;
   struct tNodePad * * pPadLookup ;
   
  -int nInitialNodePadSize = 64 ;
  +int nInitialNodePadSize = 128 ;
   
   int nMemUsage = 0 ;
   int numNodes  = 0 ;
  @@ -136,6 +136,81 @@
       return numElements ;
       }
   
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
  +/* ArraySetSize                                                             */
  +/*                                                                          */
  +/* Make space for exact numElements in the Array			    */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
  +
  +
  +int ArraySetSize (/*in*/ const tArray * pArray,
  +	          /*in*/ int	numElements)
  +
  +    {
  +    struct tArrayCtrl * pCtrl = ((struct tArrayCtrl *)(*(void * *)pArray)) - 1 ;
  +    int	         nNdx ;
  +    char *       p ;
  +
  +    
  +    if (numElements > pCtrl -> nMax)
  +	ArraySet (pArray, numElements) ;
  +    
  +    pCtrl -> nFill = numElements ;
  +
  +    return numElements ;
  +    }
  +
  +
  +
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
  +/* StringNew                                                                */
  +/*                                                                          */
  +/* create a new string                                                      */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
  +
  +
  +void StringNew (/*in*/ char * * pArray,
  +	      /*in*/ int	nAdd)
  +
  +    {	      
  +    if ((*(void * *)pArray) == NULL)
  +	ArrayNew (pArray, nAdd, sizeof (char)) ;
  +    else
  +	ArraySetSize (pArray, 0);
  +    }
  +
  +
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
  +/* StringAdd                                                                */
  +/*                                                                          */
  +/* append to string                                                         */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
  +
  +
  +void StringAdd (/*in*/ char * *	   pArray,
  +	       /*in*/ const char * sAdd,
  +	       /*in*/ int 	   nLen)
  +
  +    {	      
  +    int nIndex ;
  +    
  +    if (nLen == 0)
  +	nLen = strlen (sAdd) ;
  +
  +    nIndex = ArrayAdd (pArray, nLen) ;
  +
  +    memcpy ((*pArray)+nIndex, sAdd, nLen) ;
  +    
  +    }
  +
  +
  +
   
   /* ------------------------------------------------------------------------ */
   /*                                                                          */
  @@ -209,10 +284,10 @@
       ArrayNew (&pStringTableArray, 128, sizeof (char *)) ; 
       String2Ndx ("", 0) ;
   
  -    ArrayNew (&pNodeLookup, 4096, sizeof (struct tNodeData *)) ; 
  +    ArrayNew (&pNodeLookup, 128, sizeof (struct tNodeData *)) ; 
       ArrayAdd (&pNodeLookup, 1) ;
       pNodeLookup[0] = NULL ;
  -    ArrayNew (&pPadLookup, 256, sizeof (struct tNodePad *)) ; 
  +    ArrayNew (&pPadLookup, 128, sizeof (struct tNodePad *)) ; 
       ArrayAdd (&pPadLookup, 1) ;
       pPadLookup[0] = NULL ;
       }
  @@ -229,46 +304,63 @@
   
   interface Node {
     // NodeType
  -  const unsigned short      ELEMENT_NODE       = 1;
  -  const unsigned short      ATTRIBUTE_NODE     = 2;
  -  const unsigned short      TEXT_NODE          = 3;
  -  const unsigned short      CDATA_SECTION_NODE = 4;
  -  const unsigned short      ENTITY_REFERENCE_NODE = 5;
  -  const unsigned short      ENTITY_NODE        = 6;
  -  const unsigned short      PROCESSING_INSTRUCTION_NODE = 7;
  -  const unsigned short      COMMENT_NODE       = 8;
  -  const unsigned short      DOCUMENT_NODE      = 9;
  -  const unsigned short      DOCUMENT_TYPE_NODE = 10;
  -  const unsigned short      DOCUMENT_FRAGMENT_NODE = 11;
  -  const unsigned short      NOTATION_NODE      = 12;
  -
  -  readonly attribute  DOMString            nodeName;
  -           attribute  DOMString            nodeValue;
  -                                                 // raises(DOMException) on setting
  -                                                 // raises(DOMException) on retrieval
  -  readonly attribute  unsigned short       nodeType;
  -  readonly attribute  Node                 parentNode;
  -  readonly attribute  NodeList             childNodes;
  -  readonly attribute  Node                 firstChild;
  -  readonly attribute  Node                 lastChild;
  -  readonly attribute  Node                 previousSibling;
  -  readonly attribute  Node                 nextSibling;
  -  readonly attribute  NamedNodeMap         attributes;
  -  readonly attribute  Document             ownerDocument;
  -  Node                      insertBefore(in Node newChild, 
  -                                         in Node refChild)
  -                                         raises(DOMException);
  -  Node                      replaceChild(in Node newChild, 
  -                                         in Node oldChild)
  -                                         raises(DOMException);
  -  Node                      removeChild(in Node oldChild)
  +  const unsigned short      ELEMENT_NODE                   = 1;
  +  const unsigned short      ATTRIBUTE_NODE                 = 2;
  +  const unsigned short      TEXT_NODE                      = 3;
  +  const unsigned short      CDATA_SECTION_NODE             = 4;
  +  const unsigned short      ENTITY_REFERENCE_NODE          = 5;
  +  const unsigned short      ENTITY_NODE                    = 6;
  +  const unsigned short      PROCESSING_INSTRUCTION_NODE    = 7;
  +  const unsigned short      COMMENT_NODE                   = 8;
  +  const unsigned short      DOCUMENT_NODE                  = 9;
  +  const unsigned short      DOCUMENT_TYPE_NODE             = 10;
  +  const unsigned short      DOCUMENT_FRAGMENT_NODE         = 11;
  +  const unsigned short      NOTATION_NODE                  = 12;
  +
  +  readonly attribute DOMString        nodeName;
  +           attribute DOMString        nodeValue;
  +                                        // raises(DOMException) on setting
  +                                        // raises(DOMException) on retrieval
  +
  +  readonly attribute unsigned short   nodeType;
  +  readonly attribute Node             parentNode;
  +  readonly attribute NodeList         childNodes;
  +  readonly attribute Node             firstChild;
  +  readonly attribute Node             lastChild;
  +  readonly attribute Node             previousSibling;
  +  readonly attribute Node             nextSibling;
  +  readonly attribute NamedNodeMap     attributes;
  +  // Modified in DOM Level 2:
  +  readonly attribute Document         ownerDocument;
  +  Node               insertBefore(in Node newChild, 
  +                                  in Node refChild)
                                           raises(DOMException);
  -  Node                      appendChild(in Node newChild)
  +  Node               replaceChild(in Node newChild, 
  +                                  in Node oldChild)
                                           raises(DOMException);
  -  boolean                   hasChildNodes();
  -  Node                      cloneNode(in boolean deep);
  +  Node               removeChild(in Node oldChild)
  +                                        raises(DOMException);
  +  Node               appendChild(in Node newChild)
  +                                        raises(DOMException);
  +  boolean            hasChildNodes();
  +  Node               cloneNode(in boolean deep);
  +  // Introduced in DOM Level 2:
  +  void               normalize();
  +  // Introduced in DOM Level 2:
  +  boolean            supports(in DOMString feature, 
  +                              in DOMString version);
  +  // Introduced in DOM Level 2:
  +  readonly attribute DOMString        namespaceURI;
  +  // Introduced in DOM Level 2:
  +           attribute DOMString        prefix;
  +                                        // raises(DOMException) on setting
  +
  +  // Introduced in DOM Level 2:
  +  readonly attribute DOMString        localName;
   };
   
  +
  +
   */
   
   /* ------------------------------------------------------------------------ */
  @@ -348,6 +440,9 @@
   	    struct tNodeData * pNewParent = (struct tNodeData * )(pNext + 1) ;
   	    lprintf (r, "[%d]PARSE: NewPad Extent Attr: %d -> %d\n", r -> nPid, pPad ->
xParent, pNext -> xNdx) ; 
   
  +	    if (nNodeSize + sizeof (struct tNodePad) >= nInitialNodePadSize)
  +		mydie ("pad too small for attr -> make room") ;
  +	    
   	    pNext -> xPrev = pPad -> xNdx ;
   	    pPad  -> xNext = pNext -> xNdx ;
   	    pPadLookup[pPad->xFirst] -> xLast = pNext -> xNdx ;
  @@ -432,6 +527,7 @@
   	pNew -> numAttr = 0 ;
   	pNew -> xNdx	= xNdx ;
   	pNew -> xChilds = 0 ;
  +	pNew -> bFlags  = 1 ;
   	pNew -> nPadOffset = pChilds -> nFill ;
   
   	pChilds -> numChilds++ ;
  @@ -441,6 +537,61 @@
   	}
       }
   
  +
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
  +/* Node_removeChild                                                         */
  +/*                                                                          */
  +/* Remove a child node                                                      */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
  +
  +
  +
  +tNode Node_removeChild (/*in*/ tNode	    xNode,
  +			/*in*/ tNode	    xChild)
  +
  +    {
  +    struct tNodeData *	pChild  = pNodeLookup [xChild] ;
  +    struct tNodePad *	pPad	= (struct tNodePad * )(((tUInt8 *)pChild) - pChild -> nPadOffset)
;
  +
  +    if (xNode != -1 && pPad -> xParent != xNode)
  +	return 0 ;
  +
  +    pChild -> bFlags = 0 ;
  +    pPad   -> numChilds-- ;
  +
  +    return xChild ;
  +    }
  +
  +
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
  +/* Node_replaceChild                                                        */
  +/*                                                                          */
  +/* Replace child node                                                       */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
  +
  +
  +
  +tNode Node_replaceChildWithCDATA (/*in*/ tNode		 xNode,
  +				  /*in*/ tNode		 xOldChild,
  +			          /*in*/ const char *	 sText,
  +				  /*in*/ int		 nTextLen)
  +
  +    {
  +    struct tNodeData *	pOldChild  = pNodeLookup [xOldChild] ;
  +    
  +    pOldChild -> nType = ntypCDATA ;
  +    pOldChild -> nText = String2Ndx(sText, nTextLen) ;
  +    pOldChild -> xChilds = 0 ;
  +
  +    return xOldChild ;
  +    }
  +
  +
  +
   /* ------------------------------------------------------------------------ */
   /*                                                                          */
   /* Node_parentNode                                                          */
  @@ -511,7 +662,8 @@
       pChildNode = ((struct tNodeData *)(pPad + 1)) ;
       while (nChildNo > 0)
   	{
  -	nChildNo-- ;
  +	if (pChildNode -> bFlags)
  +	    nChildNo-- ;
   	pChildNode = (struct tNodeData *)(((tUInt8 *)pChildNode) + sizeof (struct tNodeData) +
sizeof (struct tAttrData) * pChildNode -> numAttr) ;
   	}
   
  @@ -547,9 +699,58 @@
   	}
       
       pNode = (struct tNodeData *)(((tUInt8 *)pNode) + nOffset) ;
  +    if (!pNode -> bFlags) 
  +	return Node_nextSibling (pNode -> xNdx) ;
  +        
       return pNode -> xNdx ;
       }
   
  +/* ------------------------------------------------------------------------
  +
  +interface Element : Node {
  +  readonly attribute DOMString        tagName;
  +  DOMString          getAttribute(in DOMString name);
  +  void               setAttribute(in DOMString name, 
  +                                  in DOMString value)
  +                                        raises(DOMException);
  +  void               removeAttribute(in DOMString name)
  +                                        raises(DOMException);
  +  Attr               getAttributeNode(in DOMString name);
  +  Attr               setAttributeNode(in Attr newAttr)
  +                                        raises(DOMException);
  +  Attr               removeAttributeNode(in Attr oldAttr)
  +                                        raises(DOMException);
  +  NodeList           getElementsByTagName(in DOMString name);
  +  // Introduced in DOM Level 2:
  +  DOMString          getAttributeNS(in DOMString namespaceURI, 
  +                                    in DOMString localName);
  +  // Introduced in DOM Level 2:
  +  void               setAttributeNS(in DOMString namespaceURI, 
  +                                    in DOMString qualifiedName, 
  +                                    in DOMString value)
  +                                        raises(DOMException);
  +  // Introduced in DOM Level 2:
  +  void               removeAttributeNS(in DOMString namespaceURI, 
  +                                       in DOMString localName)
  +                                        raises(DOMException);
  +  // Introduced in DOM Level 2:
  +  Attr               getAttributeNodeNS(in DOMString namespaceURI, 
  +                                        in DOMString localName);
  +  // Introduced in DOM Level 2:
  +  Attr               setAttributeNodeNS(in Attr newAttr)
  +                                        raises(DOMException);
  +  // Introduced in DOM Level 2:
  +  NodeList           getElementsByTagNameNS(in DOMString namespaceURI, 
  +                                            in DOMString localName);
  +  // Introduced in DOM Level 2:
  +  boolean            hasAttribute(in DOMString name);
  +  // Introduced in DOM Level 2:
  +  boolean            hasAttributeNS(in DOMString namespaceURI, 
  +                                    in DOMString localName);
  +};
  +
  +
  +------------------------------------------------------------------------- */
   
   /* ------------------------------------------------------------------------ */
   /*                                                                          */
  
  
  
  1.1.2.5   +4 -2      embperl/Attic/epdom.h
  
  Index: epdom.h
  ===================================================================
  RCS file: /home/cvs/embperl/Attic/epdom.h,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- epdom.h	2000/05/12 14:13:44	1.1.2.4
  +++ epdom.h	2000/05/12 21:09:03	1.1.2.5
  @@ -35,14 +35,15 @@
   
   typedef tUInt8          tNodeType ;
   typedef tIndex		tNode	 ;
  +typedef tIndex		tAttr	 ;
   
   
   
   struct tNodePad
       {
       tNodeType		nType ;
  -    tIndex		xParent ;
       tIndex		xNdx ;
  +    tIndex		xParent ;
       tIndex		xPrev ;
       tIndex		xNext ;
       tIndex		xLast ;
  @@ -56,11 +57,12 @@
   struct tNodeData
       {
       tNodeType		nType ;
  +    tUInt8		bFlags ;
       tUInt16		nPadOffset ;
       tIndex		xNdx ;
       tStringIndex        nText ;
  -    tUInt16		numAttr ;
       tIndex		xChilds ;
  +    tUInt16		numAttr ;
       } ;
   
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.7   +9 -3      embperl/Embperl/Attic/Tokens.pm
  
  Index: Tokens.pm
  ===================================================================
  RCS file: /home/cvs/embperl/Embperl/Attic/Tokens.pm,v
  retrieving revision 1.1.2.6
  retrieving revision 1.1.2.7
  diff -u -r1.1.2.6 -r1.1.2.7
  --- Tokens.pm	2000/05/11 07:28:12	1.1.2.6
  +++ Tokens.pm	2000/05/12 21:09:04	1.1.2.7
  @@ -57,7 +57,7 @@
               'value' => { 'text' => 'value', 'nodename' => 'value', follow =>
\%AssignAttr },
               },
           'procinfo' => {
  -            embperl => { perlcode => 'Input (%type%, %name%, %value%) ;' }
  +            embperl => { perlcode => 'Input (%$n%, %*type%, %*name% %!value%) ;'
}
               },
            },
       'tr' => {
  @@ -196,23 +196,29 @@
           'text' => '[+',
           'end'  => '+]',
           'procinfo' => {
  -            embperl => { perlcode => 'Output (%#0%) ; ' }
  +            embperl => { perlcode => 'Output (%$n%, do { %#0% }) ; ' }
               },
           },
        'Embperl code' => {
           'text' => '[-',
           'end'  => '-]',
           'procinfo' => {
  -            embperl => { perlcode => '%#0% ; ' }
  +            embperl => { perlcode => '%#0% ; Remove (%$n%) ; ' }
               },
           },
        'Embperl startup code' => {
           'text' => '[!',
           'end'  => '!]',
  +        'procinfo' => {
  +            embperl => { perlcode => 'if (!$first++) { %#0% } ; Remove (%$n%) ; '
}
  +            },
           },
        'Embperl comment' => {
           'text' => '[#',
           'end'  => '#]',
  +        'procinfo' => {
  +            embperl => { perlcode => 'Remove (%$n%) ; ' }
  +            },
           },
         ) ;  
      
  
  
  

Mime
View raw message