]> code.citadel.org Git - citadel.git/blobdiff - webcit/subst.c
* migrate message creation to templates (citing still missing)
[citadel.git] / webcit / subst.c
index d5297d14c89f88a1c12b37ffff965adcae5ddf36..690a21f7a8da58548b6b79125d73b0516027d3c6 100644 (file)
@@ -505,6 +505,14 @@ void print_value_of(StrBuf *Target, WCTemplateToken *Token, void *Context, int C
                        StrBufAppendPrintf(Target, "<pre>WARNING: \ninvalid value in SV-Hash at %s!\n</pre>", Token->pName);
                }
        }
+       else
+               lprintf(1, "didn't find Handler [%s] (in '%s' line %ld); "
+                       " [%s]\n", 
+                       Token->pName,
+                       ChrPtr(Token->FileName),
+                       Token->Line,
+                       ChrPtr(Token->FlatToken));
+
 }
 
 int CompareSubstToToken(TemplateParam *ParamToCompare, TemplateParam *ParamToLookup)
@@ -696,6 +704,7 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf,
        TemplateParam *Param;
        WCTemplateToken *NewToken = (WCTemplateToken*)malloc(sizeof(WCTemplateToken));
 
+       NewToken->FileName = pTmpl->FileName; /* to print meaningfull log messages... */
        NewToken->Flags = 0;
        NewToken->Line = Line + 1;
        NewToken->pTokenStart = pTmplStart;
@@ -815,6 +824,7 @@ int EvaluateConditional(StrBuf *Target, WCTemplateToken *Token, WCTemplate *pTmp
                        ChrPtr(pTmpl->FileName),
                        Token->Line,
                        ChrPtr(Token->FlatToken));
+               return 0;
        }
            
        Cond = (ConditionalStruct *) vConditional;
@@ -1150,7 +1160,7 @@ const char* PrintTemplate(void *vSubst)
  * \brief Display a variable-substituted template
  * \param templatename template file to load
  */
-void DoTemplate(const char *templatename, long len, void *Context, StrBuf *Target, int ContextType) 
+void DoTemplate(const char *templatename, long len, StrBuf *Target, void *Context, int ContextType) 
 {
        HashList *Static;
        HashList *StaticLocal;
@@ -1311,6 +1321,7 @@ typedef struct _HashIterator {
        HashList *StaticList;
        int AdditionalParams;
        int ContextType;
+       int XPectContextType;
        RetrieveHashlistFunc GetHash;
        HashDestructorFunc Destructor;
        SubTemplFunc DoSubTemplate;
@@ -1332,16 +1343,18 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
                     Tokens->Params[0]->Start,
                     Tokens->Params[0]->len,
                     &vIt)) {
-               lprintf(1, "unknown Iterator [%s] (in line %ld); "
+               lprintf(1, "unknown Iterator [%s] (in '%s' line %ld); "
                        " [%s]\n", 
                        Tokens->Params[0]->Start,
+                       ChrPtr(Tokens->FileName),
                        Tokens->Line,
                        ChrPtr(Tokens->FlatToken));
                StrBufAppendPrintf(
                        Target,
-                       "<pre>\nunknown Iterator [%s] (in line %ld); \n"
+                       "<pre>\nunknown Iterator [%s] (in '%s' line %ld); \n"
                        " [%s]\n</pre>", 
                        Tokens->Params[0]->Start,
+                       ChrPtr(Tokens->FileName),
                        Tokens->Line,
                        ChrPtr(Tokens->FlatToken));
                return;
@@ -1350,25 +1363,54 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
        It = (HashIterator*) vIt;
 
        if (Tokens->nParameters < It->AdditionalParams + 2) {
-               lprintf(1, "Iterator [%s] (in line %ld); "
+               lprintf(1, "Iterator [%s] (in '%s' line %ld); "
                        "doesn't work with %ld params [%s]\n", 
                        Tokens->Params[0]->Start,
+                       ChrPtr(Tokens->FileName),
                        Tokens->Line,
                        Tokens->nParameters, 
                        ChrPtr(Tokens->FlatToken));
                StrBufAppendPrintf(
                        Target,
-                       "<pre>Iterator [%s] \n(in line %ld);\n"
+                       "<pre>Iterator [%s] \n(in '%s' line %ld);\n"
                        "doesn't work with %ld params \n[%s]\n</pre>", 
                        Tokens->Params[0]->Start,
+                       ChrPtr(Tokens->FileName),
                        Tokens->Line,
                        Tokens->nParameters, 
                        ChrPtr(Tokens->FlatToken));
                return;
        }
 
+       if ((It->XPectContextType != CTX_NONE) &&
+           (It->XPectContextType != ContextType)) {
+               lprintf(1, "Iterator [%s] (in '%s' line %ld); "
+                       "requires context of type %ld, have %ld [%s]\n", 
+                       Tokens->pName,
+                       ChrPtr(Tokens->FileName),
+                       Tokens->Line,
+                       It->XPectContextType, 
+                       ContextType,
+                       ChrPtr(Tokens->FlatToken));
+               StrBufAppendPrintf(
+                       Target, 
+                       "<pre>\nIterator [%s] (in '%s' line %ld);"
+                       " requires context of type %ld, have %ld!\n[%s]\n</pre>\n", 
+                       Tokens->pName,
+                       ChrPtr(Tokens->FileName),
+                       Tokens->Line,
+                       It->XPectContextType, 
+                       ContextType,
+                       ChrPtr(Tokens->FlatToken));
+               return ;
+               
+       }
+
+
+
+
        if (It->StaticList == NULL)
-               List = It->GetHash(Tokens);
+               List = It->GetHash(Target, nArgs, Tokens, Context, ContextType);
        else
                List = It->StaticList;
 
@@ -1383,7 +1425,7 @@ void tmpl_iterate_subtmpl(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
                        It->DoSubTemplate(SubBuf, vContext, Tokens);
                DoTemplate(Tokens->Params[1]->Start,
                           Tokens->Params[1]->len,
-                          vContext, SubBuf, 
+                          SubBuf, vContext,
                           It->ContextType);
                        
                StrBufAppendBuf(Target, SubBuf, 0);
@@ -1442,7 +1484,8 @@ void RegisterITERATOR(const char *Name, long len,
                      RetrieveHashlistFunc GetHash, 
                      SubTemplFunc DoSubTempl,
                      HashDestructorFunc Destructor,
-                     int ContextType)
+                     int ContextType, 
+                     int XPectContextType)
 {
        HashIterator *It = (HashIterator*)malloc(sizeof(HashIterator));
        It->StaticList = StaticList;
@@ -1451,6 +1494,7 @@ void RegisterITERATOR(const char *Name, long len,
        It->DoSubTemplate = DoSubTempl;
        It->Destructor = Destructor;
        It->ContextType = ContextType;
+       It->XPectContextType = XPectContextType;
        Put(Iterators, Name, len, It, NULL);
 }
 
@@ -1472,19 +1516,19 @@ void tmpl_do_boxed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Con
                StrBuf *Headline = NewStrBuf();
                DoTemplate(Tokens->Params[1]->Start, 
                           Tokens->Params[1]->len,
-                          Context, 
                           Headline, 
+                          Context, 
                           ContextType);
                SVPutBuf("BOXTITLE", Headline, 0);
        }
        
-       DoTemplate(HKEY("beginbox"), Context, Target, ContextType);
+       DoTemplate(HKEY("beginbox"), Target, Context, ContextType);
        DoTemplate(Tokens->Params[0]->Start, 
                   Tokens->Params[0]->len,
-                  Context, 
                   Target, 
+                  Context, 
                   ContextType);
-       DoTemplate(HKEY("endbox"), Context, Target, ContextType);
+       DoTemplate(HKEY("endbox"), Target, Context, ContextType);
 }
 
 void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
@@ -1500,8 +1544,8 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
                if (Tokens->Params[i * 2]->len > 0) {
                        DoTemplate(Tokens->Params[i * 2]->Start, 
                                   Tokens->Params[i * 2]->len,
-                                  Context,
                                   TabNames[i],
+                                  Context,
                                   ContextType);
                }
                else { 
@@ -1516,8 +1560,8 @@ void tmpl_do_tabbed(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Co
 
                DoTemplate(Tokens->Params[i * 2 + 1]->Start, 
                           Tokens->Params[i * 2 + 1]->len,
-                          Context, 
                           Target,
+                          Context, 
                           ContextType);
                StrEndTab(Target, i, nTabs);
        }