richter     00/07/26 00:33:37

  Modified:    .        Tag: Embperl2 epcomp.c epdat.h
  Log:
  Embperl 2
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.42  +375 -212  embperl/Attic/epcomp.c
  
  Index: epcomp.c
  ===================================================================
  RCS file: /home/cvs/embperl/Attic/epcomp.c,v
  retrieving revision 1.1.2.41
  retrieving revision 1.1.2.42
  diff -u -r1.1.2.41 -r1.1.2.42
  --- epcomp.c  2000/07/07 10:07:57     1.1.2.41
  +++ epcomp.c  2000/07/26 07:33:36     1.1.2.42
  @@ -17,9 +17,10 @@
   
   struct tEmbperlCmd
       {
  -    const char * *  sPerlCode ;
  -    const char * *  sCompileTimePerlCode ;
  -    const char *    sPerlCodeEnd ;
  +    int             bValid ;
  +    const char * *  sPerlCode ;             /* perl code that should be inserted 
(maybe an array) */
  +    const char * *  sCompileTimePerlCode ;  /* perl code that should be directly 
executed (maybe an array) */
  +    const char *    sPerlCodeEnd ;          /* perl code that should be inserted at 
the end tag  */
       const char *    sStackName ;
       const char *    sPushStack ;
       const char *    sMatchStack ;
  @@ -33,6 +34,7 @@
       int                  nNodeType ;
       int                  nSwitchCodeType ;
       const char *    sMayJump ;
  +    struct tEmbperlCmd * pNext ;
       } ;
   
   typedef struct tEmbperlCmd tEmbperlCmd ;
  @@ -81,11 +83,25 @@
       {
       SV * * ppSV ;
       AV * pAV ;
  +    tEmbperlCmd *  pCmd ;
       
  -    
  +
       ArraySet (&pEmbperlCmds, nNodeName) ;
       if (nMaxEmbperlCmd < nNodeName) 
        nMaxEmbperlCmd = nNodeName ;
  +    pCmd = &pEmbperlCmds[nNodeName] ;
  +
  +    if (pCmd -> bValid)
  +        {
  +        tEmbperlCmd * pNewCmd ;
  +        while (pCmd -> pNext)
  +            pCmd = pCmd -> pNext ;
  +        
  +        pNewCmd = malloc (sizeof (*pNewCmd)) ;
  +        pCmd -> pNext = pNewCmd ;
  +        pCmd = pNewCmd ;
  +        }
  +    pCmd -> bValid = 1 ;
   
       ppSV = hv_fetch(pHash, "perlcode", 8, 0) ;  
       if (ppSV != NULL && *ppSV != NULL && 
  @@ -96,16 +112,16 @@
           STRLEN l ;
           char * s ;
   
  -        pEmbperlCmds[nNodeName].sPerlCode = malloc (f * sizeof (char *)) ;
  -        pEmbperlCmds[nNodeName].numPerlCode = f ;
  +        pCmd -> sPerlCode = malloc (f * sizeof (char *)) ;
  +        pCmd -> numPerlCode = f ;
   
           for (i = 0; i < f; i++)
            {
            ppSV = av_fetch (pAV, i, 0) ;
            if (ppSV && *ppSV)
  -             pEmbperlCmds[nNodeName].sPerlCode[i] = strdup (SvPV (*ppSV, l)) ;
  +             pCmd -> sPerlCode[i] = strdup (SvPV (*ppSV, l)) ;
               else
  -             pEmbperlCmds[nNodeName].sPerlCode[i] = NULL ;
  +             pCmd -> sPerlCode[i] = NULL ;
               }
           }
       else
  @@ -114,9 +130,9 @@
               {
               STRLEN  l ; 
               
  -            pEmbperlCmds[nNodeName].sPerlCode = malloc (sizeof (char *)) ;
  -            pEmbperlCmds[nNodeName].numPerlCode = 1 ;
  -            pEmbperlCmds[nNodeName].sPerlCode[0] = sstrdup (SvPV (*ppSV, l)) ;
  +            pCmd -> sPerlCode = malloc (sizeof (char *)) ;
  +            pCmd -> numPerlCode = 1 ;
  +            pCmd -> sPerlCode[0] = sstrdup (SvPV (*ppSV, l)) ;
               }
           }
       
  @@ -130,16 +146,16 @@
           STRLEN l ;
           char * s ;
   
  -        pEmbperlCmds[nNodeName].sCompileTimePerlCode = malloc (f * sizeof (char *)) 
;
  -        pEmbperlCmds[nNodeName].numCompileTimePerlCode = f ;
  +        pCmd -> sCompileTimePerlCode = malloc (f * sizeof (char *)) ;
  +        pCmd -> numCompileTimePerlCode = f ;
   
           for (i = 0; i < f; i++)
            {
            ppSV = av_fetch (pAV, i, 0) ;
            if (ppSV && *ppSV)
  -             pEmbperlCmds[nNodeName].sCompileTimePerlCode[i] = strdup (SvPV (*ppSV, 
l)) ;
  +             pCmd -> sCompileTimePerlCode[i] = strdup (SvPV (*ppSV, l)) ;
               else
  -             pEmbperlCmds[nNodeName].sCompileTimePerlCode[i] = NULL ;
  +             pCmd -> sCompileTimePerlCode[i] = NULL ;
               }
           }
       else
  @@ -148,35 +164,42 @@
               {
               STRLEN  l ; 
               
  -            pEmbperlCmds[nNodeName].sCompileTimePerlCode = malloc (sizeof (char *)) 
;
  -            pEmbperlCmds[nNodeName].numCompileTimePerlCode = 1 ;
  -            pEmbperlCmds[nNodeName].sCompileTimePerlCode[0] = sstrdup (SvPV (*ppSV, 
l)) ;
  +            pCmd -> sCompileTimePerlCode = malloc (sizeof (char *)) ;
  +            pCmd -> numCompileTimePerlCode = 1 ;
  +            pCmd -> sCompileTimePerlCode[0] = sstrdup (SvPV (*ppSV, l)) ;
               }
           }
       
       
       
       
  -    pEmbperlCmds[nNodeName].sPerlCodeEnd = GetHashValueStrDup  (pHash, 
"perlcodeend", NULL) ;
  -    pEmbperlCmds[nNodeName].sStackName   = GetHashValueStrDup  (pHash, "stackname", 
NULL) ;
  -    pEmbperlCmds[nNodeName].sPushStack   = GetHashValueStrDup  (pHash, "push", 
NULL) ;
  -    pEmbperlCmds[nNodeName].sMatchStack   = GetHashValueStrDup  (pHash, 
"stackmatch", NULL) ;
  -    pEmbperlCmds[nNodeName].sStackName2   = GetHashValueStrDup (pHash, 
"stackname2", NULL) ;
  -    pEmbperlCmds[nNodeName].sPushStack2   = GetHashValueStrDup (pHash, "push2", 
NULL) ;
  -    pEmbperlCmds[nNodeName].bRemoveNode  = GetHashValueInt     (pHash, 
"removenode", 0) ;
  -    pEmbperlCmds[nNodeName].sMayJump     = GetHashValueStrDup  (pHash, "mayjump", 
NULL) ;
  -    pEmbperlCmds[nNodeName].bPerlCodeRemove  = GetHashValueInt (pHash, 
"perlcoderemove", 0) ;
  -    pEmbperlCmds[nNodeName].bCompileChilds  = GetHashValueInt  (pHash, 
"compilechilds", 1) ;
  -    pEmbperlCmds[nNodeName].nSwitchCodeType  = GetHashValueInt  (pHash, 
"switchcodetype", 0) ;
  -    pEmbperlCmds[nNodeName].nNodeType  = nNodeType ;
  +    pCmd -> sPerlCodeEnd = GetHashValueStrDup  (pHash, "perlcodeend", NULL) ;
  +    pCmd -> sStackName   = GetHashValueStrDup  (pHash, "stackname", NULL) ;
  +    pCmd -> sPushStack   = GetHashValueStrDup  (pHash, "push", NULL) ;
  +    pCmd -> sMatchStack   = GetHashValueStrDup  (pHash, "stackmatch", NULL) ;
  +    pCmd -> sStackName2   = GetHashValueStrDup (pHash, "stackname2", NULL) ;
  +    pCmd -> sPushStack2   = GetHashValueStrDup (pHash, "push2", NULL) ;
  +    pCmd -> bRemoveNode  = GetHashValueInt     (pHash, "removenode", 0) ;
  +    pCmd -> sMayJump     = GetHashValueStrDup  (pHash, "mayjump", NULL) ;
  +    pCmd -> bPerlCodeRemove  = GetHashValueInt (pHash, "perlcoderemove", 0) ;
  +    pCmd -> bCompileChilds  = GetHashValueInt  (pHash, "compilechilds", 1) ;
  +    pCmd -> nSwitchCodeType  = GetHashValueInt  (pHash, "switchcodetype", 0) ;
  +    pCmd -> nNodeType  = nNodeType ;
  +    pCmd -> pNext  = NULL ;
  +
  +    pEmbperlCmds[nNodeName].bRemoveNode |= pCmd -> bRemoveNode ;
  +    pEmbperlCmds[nNodeName].bPerlCodeRemove |= pCmd -> bPerlCodeRemove ;
  +    if (pCmd -> nSwitchCodeType)
  +     pEmbperlCmds[nNodeName].nSwitchCodeType = pCmd -> nSwitchCodeType ;
  +    if (pCmd -> sMayJump && !pEmbperlCmds[nNodeName].sMayJump)
  +     pEmbperlCmds[nNodeName].sMayJump = pCmd -> sMayJump ;
   
  -
       if (r -> bDebug & dbgParse)
           lprintf (r, "[%d]EPCOMP: InitItem %s (#%d) perlcode=%s (num=%d) 
perlcodeend=%s\n", 
                          r -> nPid, Ndx2String(nNodeName), nNodeName, 
  -                       
pEmbperlCmds[nNodeName].sPerlCode?pEmbperlCmds[nNodeName].sPerlCode[0]:"", 
  -                       pEmbperlCmds[nNodeName].numPerlCode, 
  -                       
pEmbperlCmds[nNodeName].sPerlCodeEnd?pEmbperlCmds[nNodeName].sPerlCodeEnd:"<undef>") ; 
  +                       pCmd -> sPerlCode?pCmd -> sPerlCode[0]:"", 
  +                       pCmd -> numPerlCode, 
  +                       pCmd -> sPerlCodeEnd?pCmd -> sPerlCodeEnd:"<undef>") ; 
   
       }
   
  @@ -733,229 +756,218 @@
       }
   
   
  +
   /* ------------------------------------------------------------------------ */
   /*                                                                          */
  -/* embperl_CompileNode                                                      */
  +/* embperl_CompileCmd                                                            */
   /*                                                                          */
  -/* Compile one node and his childs                                          */
  +/* Compile one cmd of one node                                                   */
   /*                                                                          */
   /* ------------------------------------------------------------------------ */
   
   
  -int embperl_CompileNode (/*in*/  tReq *         r,
  +static int embperl_CompileCmd  (/*in*/       tReq *         r,
                         /*in*/  tDomTree *     pDomTree,
  -                      /*in*/  tNode          xNode,
  -                      /*i/o*/ int *          bCheckpointPending)
  +                      /*in*/  tNodeData *    pNode,
  +                      /*in*/  tEmbperlCmd *  pCmd,
  +                      /*out*/ int *          nStartCodeOffset)
   
   
       {
       int rc ;
  -    tNode           xChildNode  ;
  -    tStringIndex    nNdx  ;
  -    tEmbperlCmd *   pCmd  ;
  -    tNodeData *     pNode = Node_self (pDomTree, xNode) ;
  -    tAttrData *     pAttr ;
  -    int             nAttr = 0 ;
       char *          pCode = NULL ; 
  -    char *          sStackValue = NULL ;
  -    int                  nStartCodeOffset = 0 ;               
  -    int                  nCheckpointCodeOffset = 0 ;               
       char *          sSourcefile ;
       int             nSourcefile ;
  +    int i ;
   
       Ndx2StringLen (pDomTree -> xFilename, sSourcefile, nSourcefile) ;
   
  -    if (pCurrReq -> bDebug & dbgParse)
  -     lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d -------> parent=%d node=%d type=%d 
text=%s\n", pCurrReq -> nPid, pNode -> xNdx, pNode -> nLinenumber, Node_parentNode 
(pDomTree, pNode -> xNdx), pNode -> xNdx, pNode -> nType, Node_selfNodeName(pNode)) 
  +    if (pCmd -> nNodeType != pNode -> nType)
  +     return ok ;
   
  -; 
  -    
  -    //if (*bCheckpointPending && (pNode -> nType == ntypText || pNode -> nType == 
ntypCDATA) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0)
  -    if (*bCheckpointPending && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 
0)
  +    for (i = 0; i < pCmd -> numCompileTimePerlCode; i++)
        {
  -     int l ;
  -     char buf [80] ;
  -     
  -     pNode -> bFlags |= nflgCheckpoint ;
  -     l = sprintf (buf, " _ep_cp($_ep_DomTree,%d) ;\n", *bCheckpointPending<0?pNode 
-> xNdx:*bCheckpointPending) ;
  -     nCheckpointCodeOffset = StringAdd (pProg, buf,  l) ; 
  -     *bCheckpointPending = 0 ;
  +     if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> 
sCompileTimePerlCode[i], &pCode))
  +         {
  +         SV * pSV ;
  +         int   rc ;
   
  -     if (pCurrReq -> bDebug & dbgParse)
  -         lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Checkpoint\n", pCurrReq -> nPid, 
pNode -> xNdx, pNode -> nLinenumber) ; 
  -     
  +         if (pCode)
  +             {
  +             int l = ArrayGetSize (pCode) ;
  +             if (pCurrReq -> bDebug & dbgParse)
  +                 lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d CompileTimeCode:    
%*.*s\n", pCurrReq -> nPid, pNode -> xNdx, pNode -> nLinenumber, l, l, pCode) ;
  +
  +             pSV = newSVpvf("package %s ; \n#line %d \"%s\"\n%*.*s",
  +                     pCurrReq -> Buf.sEvalPackage, pNode ->  nLinenumber, 
sSourcefile, l,l, pCode) ;
  +             if ((rc = EvalDirect (pCurrReq, pSV)) != ok)
  +                 LogError (pCurrReq, rc) ;
  +             SvREFCNT_dec(pSV);
  +             }
  +         break ;
  +         }
        }
  +    for (i = 0; i < pCmd -> numPerlCode; i++)
  +     {
  +     if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sPerlCode[i], &pCode))
  +         {
  +         if (pCode)
  +             {
  +             int l = ArrayGetSize (pCode) ;
   
  -    pCmd = NULL ;
  -    
  -    nNdx = Node_selfNodeNameNdx (pNode) ;
  +             if (l)
  +                 {
  +                 char buf [32] ;
   
  -    if (nNdx <= nMaxEmbperlCmd)
  -     {
  -     pCmd = &pEmbperlCmds[nNdx] ;
  -     if (pCmd -> nNodeType != pNode -> nType)
  -          pCmd = NULL ;
  +                 if (pNode ->  nLinenumber)
  +                     {
  +                     int l2 = sprintf (buf, "#line %d \"", pNode ->  nLinenumber) ;
  +
  +                     StringAdd (pProg, buf, l2) ;
  +                     StringAdd (pProg, sSourcefile, nSourcefile) ;
  +                     StringAdd (pProg, "\"\n", 2) ;
  +                     }
  +
  +                 if (pCmd -> bPerlCodeRemove)
  +                     *nStartCodeOffset = StringAdd (pProg, " ", 1) ;
  +                 StringAdd (pProg, pCode, l) ;
  +                 StringAdd (pProg, "\n",  1) ;
  +                 if (pCurrReq -> bDebug & dbgParse)
  +                     lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Code:    %*.*s\n", 
pCurrReq -> nPid, pNode -> xNdx, pNode -> nLinenumber, l, l, pCode) ;
  +                 }
  +             }
  +         break ;
  +         }
        }
  -    else
  -     pCmd = NULL ;
  -    
  -    if (pCmd && pCmd -> nSwitchCodeType == 2)
  -     pProg = &pProgDef ;
   
  -     
  -    if (pCmd == NULL || (pCmd -> bRemoveNode & 8) == 0)
  -        { /* calculate attributes before tag, but not when tag should be ignored in 
output stream */
  -        while (pAttr = Element_selfGetNthAttribut (pDomTree, pNode, nAttr++))
  -         {
  -            if (pAttr -> bFlags & aflgAttrChilds)
  -                {
  -                tNodeData * pChild = Node_selfFirstChild (pDomTree, (tNodeData 
*)pAttr) ;
  +    StringFree (&pCode) ;
   
  -                while (pChild)
  -                    {
  -                    embperl_CompileNode (r, pDomTree, pChild -> xNdx, 
bCheckpointPending) ;
  -                    pChild = Node_selfNextSibling (pDomTree, pChild) ;
  -                    }
  -                }                
  +    return ok ;
  +    }
   
  -         }
  -        }            
  -    
  -    if (pCmd)
  -        {
  -        int i ;
   
  -        for (i = 0; i < pCmd -> numCompileTimePerlCode; i++)
  -            {
  -            if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> 
sCompileTimePerlCode[i], &pCode))
  -                {
  -                SV * pSV ;
  -             int   rc ;
   
  -             if (pCode)
  -                    {
  -                 int l = ArrayGetSize (pCode) ;
  -                 if (pCurrReq -> bDebug & dbgParse)
  -                     lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d CompileTimeCode:    
%*.*s\n", pCurrReq -> nPid, pNode -> xNdx, pNode -> nLinenumber, l, l, pCode) ; 
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
  +/* embperl_CompilePostProcess                                                    */
  +/*                                                                          */
  +/* Do some postprocessing after compiling                                */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
   
  -                 pSV = newSVpvf("package %s ; \n#line %d \"%s\"\n%*.*s",
  -                         pCurrReq -> Buf.sEvalPackage, pNode ->  nLinenumber, 
sSourcefile, l,l, pCode) ;
  -                 if ((rc = EvalDirect (pCurrReq, pSV)) != ok)
  -                     LogError (pCurrReq, rc) ;
  -                 SvREFCNT_dec(pSV);
  -                 }
  -                break ;
  -                }
  -            }
  -        for (i = 0; i < pCmd -> numPerlCode; i++)
  -            {
  -            if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sPerlCode[i], 
&pCode))
  -                {
  -                if (pCode)
  -                    {
  -                 int l = ArrayGetSize (pCode) ;
   
  -                    if (l)
  -                        {
  -                        char buf [32] ;
  -
  -                        if (pNode ->  nLinenumber)
  -                            {
  -                            int l2 = sprintf (buf, "#line %d \"", pNode ->  
nLinenumber) ;
  -
  -                            StringAdd (pProg, buf, l2) ;
  -                            StringAdd (pProg, sSourcefile, nSourcefile) ;
  -                            StringAdd (pProg, "\"\n", 2) ;
  -                            }                        
  -                    
  -                        if (pCmd -> bPerlCodeRemove)
  -                            nStartCodeOffset = StringAdd (pProg, " ", 1) ;
  -                        StringAdd (pProg, pCode, l) ;
  -                     StringAdd (pProg, "\n",  1) ; 
  -                     if (pCurrReq -> bDebug & dbgParse)
  -                         lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Code:    %*.*s\n", 
pCurrReq -> nPid, pNode -> xNdx, pNode -> nLinenumber, l, l, pCode) ; 
  -                        }
  -                 }
  -                break ;
  -                }
  -            }
  +static int embperl_CompilePostProcess  (/*in*/       tReq *         r,
  +                      /*in*/  tDomTree *     pDomTree,
  +                      /*in*/  tNodeData *    pNode,
  +                      /*in*/  tEmbperlCmd *  pCmd,
  +                      /*in*/  int            nCheckpointCodeOffset,
  +                      /*i/o*/ int *          bCheckpointPending)
   
  -     embperl_CompileCleanupSpaces (r, pDomTree, pNode, pCmd) ;
  -        
  -        if (pCmd -> sMayJump)
  -            if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sMayJump, 
&sStackValue))
  -             {
  -             *bCheckpointPending = -1 ;
  -             if (pCurrReq -> bDebug & dbgParse)
  -                 lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Set Checkpoint pending\n", 
pCurrReq -> nPid, pNode -> xNdx, pNode -> nLinenumber) ; 
  -             }
  +
  +    {
  +    int rc ;
  +    char *          pCode = NULL ; 
  +    char *          sStackValue = NULL ;
  +    int i ;
  +
   
  -     if (pCmd -> bRemoveNode & 1)
  -         Node_selfRemoveChild(pDomTree, -1, pNode) ;
  -        else if (pCmd -> bRemoveNode & 8)
  -         pNode -> bFlags |= nflgIgnore ;
  +    embperl_CompileCleanupSpaces (r, pDomTree, pNode, pCmd) ;
   
  -     if (nCheckpointCodeOffset && (pNode -> bFlags == 0 || (pNode -> bFlags & 
nflgIgnore)))
  +    if (pCmd -> sMayJump)
  +     if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sMayJump, 
&sStackValue))
            {
  -         (*pProg)[nCheckpointCodeOffset] = '#' ;
  +         *bCheckpointPending = -1 ;
            if (pCurrReq -> bDebug & dbgParse)
  -             lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Remove Checkpoint\n", pCurrReq 
-> nPid, pNode -> xNdx, pNode -> nLinenumber) ; 
  -         nCheckpointCodeOffset = 0 ;
  +             lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Set Checkpoint pending\n", 
pCurrReq -> nPid, pNode -> xNdx, pNode -> nLinenumber) ;
            }
  -    
  -     if (*bCheckpointPending && (pNode -> bFlags & nflgIgnore))
  -         {
  -         int l ;
  -         char buf [80] ;
  -         
  -         pNode -> bFlags |= nflgCheckpoint ;
  -         l = sprintf (buf, " _ep_cp($_ep_DomTree,%d) ;\n", 
*bCheckpointPending<0?pNode -> xNdx:*bCheckpointPending) ;
  -         nCheckpointCodeOffset = StringAdd (pProg, buf,  l) ; 
  -         *bCheckpointPending = 0 ;
   
  -         if (pCurrReq -> bDebug & dbgParse)
  -             lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Checkpoint\n", pCurrReq -> 
nPid, pNode -> xNdx, pNode -> nLinenumber) ; 
  -         
  -         }
  +    if (pCmd -> bRemoveNode & 1)
  +     Node_selfRemoveChild(pDomTree, -1, pNode) ;
  +    else if (pCmd -> bRemoveNode & 8)
  +     pNode -> bFlags |= nflgIgnore ;
  +
  +    if (nCheckpointCodeOffset && (pNode -> bFlags == 0 || (pNode -> bFlags & 
nflgIgnore)))
  +     {
  +     (*pProg)[nCheckpointCodeOffset] = '#' ;
  +     if (pCurrReq -> bDebug & dbgParse)
  +         lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Remove Checkpoint\n", pCurrReq -> 
nPid, pNode -> xNdx, pNode -> nLinenumber) ;
  +     nCheckpointCodeOffset = 0 ;
  +     }
   
  -     if (pCmd -> sStackName)
  +    if (*bCheckpointPending && (pNode -> bFlags & nflgIgnore))
  +     {
  +     int l ;
  +     char buf [80] ;
  +
  +     pNode -> bFlags |= nflgCheckpoint ;
  +     l = sprintf (buf, " _ep_cp($_ep_DomTree,%d) ;\n", *bCheckpointPending<0?pNode 
-> xNdx:*bCheckpointPending) ;
  +     nCheckpointCodeOffset = StringAdd (pProg, buf,  l) ;
  +     *bCheckpointPending = 0 ;
  +
  +     if (pCurrReq -> bDebug & dbgParse)
  +         lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Checkpoint\n", pCurrReq -> nPid, 
pNode -> xNdx, pNode -> nLinenumber) ;
  +
  +     }
  +
  +    if (pCmd -> sStackName)
  +     {
  +     if (pCmd -> sMatchStack && pNode -> nType != ntypStartTag && pNode -> nType != 
ntypDocument && pNode -> nType != ntypDocumentFraq)
            {
  -         if (pCmd -> sMatchStack && pNode -> nType != ntypStartTag && pNode -> 
nType != ntypDocument && pNode -> nType != ntypDocumentFraq)
  -             {
  -             if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sMatchStack, 
&sStackValue))
  -                 if ((rc = embperl_CompileMatchStack (pDomTree, pNode, pCmd -> 
sStackName, sStackValue)) != ok)
  -                     return rc ;
  -             }
  -         if (pCmd -> sPushStack)
  -             {
  -             if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sPushStack, 
&sStackValue))
  -                 embperl_CompilePushStack (pDomTree, pCmd -> sStackName, 
sStackValue) ;
  -             }
  +         if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sMatchStack, 
&sStackValue))
  +             if ((rc = embperl_CompileMatchStack (pDomTree, pNode, pCmd -> 
sStackName, sStackValue)) != ok)
  +                 return rc ;
            }
  -     if (pCmd -> sStackName2 && pCmd -> sPushStack2)
  -            {
  -            if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sPushStack2, 
&sStackValue))
  -             {
  -                embperl_CompilePushStack (pDomTree, pCmd -> sStackName2, 
sStackValue) ;
  -             }
  -            }
  -        }
  +     if (pCmd -> sPushStack)
  +         {
  +         if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sPushStack, 
&sStackValue))
  +             embperl_CompilePushStack (pDomTree, pCmd -> sStackName, sStackValue) ;
  +         }
  +     }
  +    if (pCmd -> sStackName2 && pCmd -> sPushStack2)
  +     {
  +     if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sPushStack2, 
&sStackValue))
  +         {
  +         embperl_CompilePushStack (pDomTree, pCmd -> sStackName2, sStackValue) ;
  +         }
  +     }
  +
  +    StringFree (&sStackValue) ;
  +    StringFree (&pCode) ;
  +
  +    return ok ;
  +    }
       
       
   
  -    if (pCmd == NULL || pCmd -> bCompileChilds)
  -     {
  -     xChildNode = pNode -> bFlags?Node_firstChild (pDomTree, xNode):0 ;
   
  -     while (xChildNode)
  -         {
  -         if ((rc = embperl_CompileNode (r, pDomTree, xChildNode, 
bCheckpointPending)) != ok)
  -             return rc ;
   
  -         xChildNode  = Node_nextSibling (pDomTree, xChildNode) ;
  -         }
  -     }
  -         
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
  +/* embperl_CompileCmdEnd                                                */
  +/*                                                                          */
  +/* Compile the end of the node                                                   */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
  +
  +
  +static int embperl_CompileCmdEnd (/*in*/  tReq *      r,
  +                      /*in*/  tDomTree *     pDomTree,
  +                      /*in*/  tNodeData *    pNode,
  +                      /*in*/  tEmbperlCmd *  pCmd,
  +                      /*in*/  int            nStartCodeOffset)
  +
  +
  +    {
  +    int rc ;
  +    char *          pCode = NULL ; 
  +    char *          sStackValue = NULL ;
  +    int i ;
  +
  +
  +    if (pCmd -> nNodeType != pNode -> nType)
  +     return ok ;
  +
  +
       if (pCmd)
        {
           if (embperl_CompileToPerlCode (pDomTree, pNode, pCmd -> sPerlCodeEnd, 
&pCode))
  @@ -1016,8 +1028,160 @@
       return ok ;
       }
   
  +
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
  +/* embperl_CompileNode                                                      */
  +/*                                                                          */
  +/* Compile one node and his childs                                          */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
  +
  +
  +int embperl_CompileNode (/*in*/  tReq *         r,
  +                      /*in*/  tDomTree *     pDomTree,
  +                      /*in*/  tNode          xNode,
  +                      /*i/o*/ int *          bCheckpointPending)
  +
  +
  +    {
  +    int rc ;
  +    tNode           xChildNode  ;
  +    tStringIndex    nNdx  ;
  +    tEmbperlCmd *   pCmd  ;
  +    tNodeData *     pNode = Node_self (pDomTree, xNode) ;
  +    tAttrData *     pAttr ;
  +    int             nAttr = 0 ;
  +    int                  nStartCodeOffset = 0 ;               
  +    int                  nCheckpointCodeOffset = 0 ;               
  +
  +
  +    if (pCurrReq -> bDebug & dbgParse)
  +     lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d -------> parent=%d node=%d type=%d 
text=%s\n", pCurrReq -> nPid, pNode -> xNdx, pNode -> nLinenumber, Node_parentNode 
(pDomTree, pNode -> xNdx), pNode -> xNdx,
  +                  pNode -> nType, Node_selfNodeName(pNode)) ;
  +    
  +    //if (*bCheckpointPending && (pNode -> nType == ntypText || pNode -> nType == 
ntypCDATA) && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 0)
  +    if (*bCheckpointPending && pNode -> bFlags && (pNode -> bFlags & nflgIgnore) == 
0)
  +     {
  +     int l ;
  +     char buf [80] ;
  +     
  +     pNode -> bFlags |= nflgCheckpoint ;
  +     l = sprintf (buf, " _ep_cp($_ep_DomTree,%d) ;\n", *bCheckpointPending<0?pNode 
-> xNdx:*bCheckpointPending) ;
  +     nCheckpointCodeOffset = StringAdd (pProg, buf,  l) ; 
  +     *bCheckpointPending = 0 ;
  +
  +     if (pCurrReq -> bDebug & dbgParse)
  +         lprintf (pCurrReq, "[%d]EPCOMP: #%d L%d Checkpoint\n", pCurrReq -> nPid, 
pNode -> xNdx, pNode -> nLinenumber) ; 
  +     
  +     }
  +
  +    pCmd = NULL ;
  +    
  +    nNdx = Node_selfNodeNameNdx (pNode) ;
  +
  +    if (nNdx <= nMaxEmbperlCmd)
  +     {
  +     pCmd = pCmdHead = &pEmbperlCmds[nNdx] ;
  +     //??if (pCmd -> nNodeType != pNode -> nType)
  +     //       pCmd = NULL ;
  +     }
  +    else
  +     pCmd = NULL ;
  +    
  +    if (pCmd && pCmd -> nSwitchCodeType == 2)
  +     pProg = &pProgDef ;
  +
  +     
  +    if (pCmd == NULL || (pCmd -> bRemoveNode & 8) == 0)
  +        { /* calculate attributes before tag, but not when tag should be ignored in 
output stream */
  +        while (pAttr = Element_selfGetNthAttribut (pDomTree, pNode, nAttr++))
  +         {
  +            if (pAttr -> bFlags & aflgAttrChilds)
  +                {
  +                tNodeData * pChild = Node_selfFirstChild (pDomTree, (tNodeData 
*)pAttr) ;
  +
  +                while (pChild)
  +                    {
  +                    embperl_CompileNode (r, pDomTree, pChild -> xNdx, 
bCheckpointPending) ;
  +                    pChild = Node_selfNextSibling (pDomTree, pChild) ;
  +                    }
  +                }                
  +
  +         }
  +        }            
  +    
  +
  +    while (pCmd)
  +     {
  +     if ((rc = embperl_compileCmd (r, pDomTree, pNode, pCmd, nStartCodeOffset, 
bCheckPointPending) != ok)
  +         return rc ;
  +     pCmd = pCmd -> pNext ;
  +     }
  +
  +    pCmd = pCmdHead ;
  +    if ((rc = embperl_compilePostProcess (r, pDomTree, pNode, pCmd, 
nCheckPointCodeOffset, bCheckPointPending) != ok)
  +     return rc ;
  +
  +
  +    if (pCmd == NULL || pCmd -> bCompileChilds)
  +     {
  +     xChildNode = pNode -> bFlags?Node_firstChild (pDomTree, xNode):0 ;
  +
  +     while (xChildNode)
  +         {
  +         if ((rc = embperl_CompileNode (r, pDomTree, xChildNode, 
bCheckpointPending)) != ok)
  +             return rc ;
  +
  +         xChildNode  = Node_nextSibling (pDomTree, xChildNode) ;
  +         }
  +     }
  +         
  +
  +    while (pCmd)
  +     {
  +     if ((rc = embperl_compileCmdEnd (r, pDomTree, pNode, pCmd, nStartCodeOffset, 
bCheckPointPending) != ok)
  +         return rc ;
  +     pCmd = pCmd -> pNext ;
  +     }
  +
  +
  +
  +    return ok ;
  +    }
  +
  +
  +
   /* ------------------------------------------------------------------------ */
   /*                                                                          */
  +/* embperl_CompileDomTree                                                */
  +/*                                                                          */
  +/* Compile root node and his childs                                      */
  +/*                                                                          */
  +/* ------------------------------------------------------------------------ */
  +
  +
  +static int embperl_CompileDomTree (/*in*/  tReq *      r,
  +                                /*in*/  tProcessor *   pProcessor,
  +                                /*in*/  tDomTree *     pDomTree)
  +
  +
  +
  +    {
  +    int rc ;
  +    int         bCheckpointPending = 0 ;
  +
  +
  +    if ((rc = embperl_CompileNode (r, pDomTree, pDomTree -> xDocument, 
&bCheckpointPending)) != ok)
  +     return rc ;
  +
  +    return ok ;
  +    }
  +
  +
  +
  +/* ------------------------------------------------------------------------ */
  +/*                                                                          */
   /* embperl_CompileDocument                                                  */
   /*                                                                          */
   /* Compile the whole document                                               */
  @@ -1039,7 +1203,6 @@
       clock_t  cl2  ;
       clock_t  cl3  ;
       clock_t  cl4  ;
  -    int         bCheckpointPending = 0 ;
       STRLEN      l ;
   
   
  @@ -1112,7 +1275,7 @@
           pDomTree -> pSV = (SV *)newHV () ;
        nLabelCnt = 1 ;
        
  -     if ((rc = embperl_CompileNode (r, pDomTree, r -> xDocument, 
&bCheckpointPending)) != ok)
  +     if ((rc = embperl_CompileDomTree (r, pProcessor, pDomTree)) != ok)
            {
            *ppSV = newSVpvf ("%s\t%s", r -> errdat1, r -> errdat2) ;
            SvUPGRADE (*ppSV, SVt_PVIV) ;
  
  
  
  1.17.2.7  +16 -4     embperl/epdat.h
  
  Index: epdat.h
  ===================================================================
  RCS file: /home/cvs/embperl/epdat.h,v
  retrieving revision 1.17.2.6
  retrieving revision 1.17.2.7
  diff -u -r1.17.2.6 -r1.17.2.7
  --- epdat.h   2000/07/04 21:37:31     1.17.2.6
  +++ epdat.h   2000/07/26 07:33:36     1.17.2.7
  @@ -1,6 +1,6 @@
   
/*###################################################################################
   #
  -#   Embperl - Copyright (c) 1997-1999 Gerald Richter / ECOS
  +#   Embperl - Copyright (c) 1997-2000 Gerald Richter / ECOS
   #
   #   You may distribute under the terms of either the GNU General Public
   #   License or the Artistic License, as specified in the Perl README file.
  @@ -13,6 +13,17 @@
   
###################################################################################*/
   
   
  +/*-----------------------------------------------------------------*/
  +/*                                                              */
  +/*  Processor                                                           */
  +/*                                                              */
  +/*-----------------------------------------------------------------*/
  +
  +
  +typedef struct tProc
  +    {
  +    int     (* pCompiler)(tReq *, tDomTree *, tNode)
  +
   
   
   /*-----------------------------------------------------------------*/
  @@ -39,9 +50,10 @@
       char *  pOpenBracket  ;
       char *  pCloseBracket ;
       bool    bEP1Compat ;    /* run in Embperl 1.x compatible mode */
  -    char *  sExpiresKey ;   /* Key used to store expires setting */
  -    double  nExpiresAt ;   /* Data expiers at */
  -    SV *    pExpiresCV ;    /* sub that is called to determinate expiration */
  +    tProc ** pProcessor ;   /* [array] processors used to process the file */
  +    char **  sExpiresKey ;  /* [array] Key used to store expires setting */
  +    double * nExpiresAt ;   /* [array] Data expiers at */
  +    SV **    pExpiresCV ;   /* [array] sub that is called to determinate expiration 
*/
       } tConf ;
   
   /*-----------------------------------------------------------------*/
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to