]> code.citadel.org Git - citadel.git/blobdiff - webcit/subst.c
* print name of context instead of number into the error message.
[citadel.git] / webcit / subst.c
index ee0e324e726bafe5cd84db4083d9f5ff5f72b6b1..1807211afc3278154c21e25a97615bebf1b068a2 100644 (file)
@@ -34,7 +34,7 @@ HashList *Defines;
 
 int DumpTemplateI18NStrings = 0;
 int LoadTemplates = 0;
-int dbg_bactrace_template_errors = 0;
+int dbg_backtrace_template_errors = 0;
 WCTemplputParams NoCtx;
 StrBuf *I18nDump = NULL;
 
@@ -112,6 +112,7 @@ const char *CtxNames[]  = {
        "Context ITERATE",
        "Context ICAL",
        "Context DavNamespace",
+       "Context TAB",
        "Context UNKNOWN"
 };
 
@@ -237,7 +238,7 @@ void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplpu
        FreeStrBuf(&Info);
        FreeStrBuf(&Error);
 /*
-       if (dbg_bactrace_template_errors)
+       if (dbg_backtrace_template_errors)
                wc_backtrace(); 
 */
 }
@@ -272,7 +273,7 @@ void LogError (StrBuf *Target, const char *Type, const char *Format, ...)
        FreeStrBuf(&Info);
        FreeStrBuf(&Error);
 /*
-       if (dbg_bactrace_template_errors)
+       if (dbg_backtrace_template_errors)
                wc_backtrace(); 
 */
 }
@@ -2165,6 +2166,24 @@ const StrBuf *DoTemplate(const char *templatename, long len, StrBuf *Target, WCT
 
 }
 
+
+void tmplput_Comment(StrBuf *Target, WCTemplputParams *TP)
+{
+       if (LoadTemplates != 0)
+       {
+               StrBuf *Comment;
+               const char *pch;
+               long len;
+
+               GetTemplateTokenString(Target, TP, 0, &pch, &len);
+               Comment = NewStrBufPlain(pch, len);
+               StrBufAppendBufPlain(Target, HKEY("<!--"), 0);
+               StrBufAppendTemplate(Target, TP, Comment, 1);
+               StrBufAppendBufPlain(Target, HKEY("-->"), 0);
+               FreeStrBuf(&Comment);
+       }
+}
+
 /*-----------------------------------------------------------------------------
  *                      Iterators
  */
@@ -2297,9 +2316,9 @@ void tmpl_iterate_subtmpl(StrBuf *Target, WCTemplputParams *TP)
            (It->XPectContextType != TP->Filter.ContextType)) {
                LogTemplateError(
                        Target, "Iterator", ERR_PARM1, TP,
-                       "requires context of type %d, have %d", 
-                       It->XPectContextType
-                       TP->Filter.ContextType);
+                       "requires context of type %s, have %s", 
+                       ContextName(It->XPectContextType)
+                       ContextName(TP->Filter.ContextType));
                return ;
                
        }
@@ -2645,6 +2664,12 @@ void tmpl_do_boxed(StrBuf *Target, WCTemplputParams *TP)
 /*-----------------------------------------------------------------------------
  *                      Tabbed-API
  */
+
+typedef struct _tab_struct {
+       long CurrentTab;
+       StrBuf *TabTitle;
+} tab_struct;
+
 int preeval_do_tabbed(WCTemplateToken *Token)
 {
        WCTemplputParams TPP;
@@ -2712,6 +2737,11 @@ void tmpl_do_tabbed(StrBuf *Target, WCTemplputParams *TP)
 {
        StrBuf **TabNames;
        int i, ntabs, nTabs;
+       tab_struct TS;
+       WCTemplputParams SubTP;
+
+       memset(&TS, 0, sizeof(tab_struct));
+       memcpy (&SubTP, &TP, sizeof(WCTemplputParams));
 
        nTabs = ntabs = TP->Tokens->nParameters / 2;
        TabNames = (StrBuf **) malloc(ntabs * sizeof(StrBuf*));
@@ -2738,17 +2768,35 @@ void tmpl_do_tabbed(StrBuf *Target, WCTemplputParams *TP)
                        nTabs --;
                }
        }
+       memcpy (&SubTP, TP, sizeof(WCTemplputParams));
+       SubTP.Filter.ControlContextType = CTX_TAB;
+       SubTP.ControlContext = &TS;
 
        StrTabbedDialog(Target, nTabs, TabNames);
        for (i = 0; i < ntabs; i++) {
-               StrBeginTab(Target, i, nTabs);
-               DoTemplate(TKEY(i * 2 + 1), Target, TP);
+               memset(&TS, 0, sizeof(tab_struct));
+               TS.CurrentTab = i;
+               TS.TabTitle = TabNames[i];
+               StrBeginTab(Target, i, nTabs, TabNames);
+               DoTemplate(TKEY(i * 2 + 1), Target, &SubTP);
                StrEndTab(Target, i, nTabs);
        }
        for (i = 0; i < ntabs; i++) 
                FreeStrBuf(&TabNames[i]);
 }
 
+void tmplput_TAB_N(StrBuf *Target, WCTemplputParams *TP)
+{
+       tab_struct *Ctx = CCTX;
+
+       StrBufAppendPrintf(Target, "%d", Ctx->CurrentTab);
+}
+
+void tmplput_TAB_TITLE(StrBuf *Target, WCTemplputParams *TP)
+{
+       tab_struct *Ctx = CCTX;
+       StrBufAppendTemplate(Target, TP, Ctx->TabTitle, 0);
+}
 
 /*-----------------------------------------------------------------------------
  *                      Sorting-API
@@ -3119,6 +3167,7 @@ InitModule_SUBST
 (void)
 {
        memset(&NoCtx, 0, sizeof(WCTemplputParams));
+       RegisterNamespace("--", 0, 2, tmplput_Comment, NULL, CTX_NONE);
        RegisterNamespace("SORT:ICON", 1, 2, tmplput_SORT_ICON, NULL, CTX_NONE);
        RegisterNamespace("SORT:ORDER", 1, 2, tmplput_SORT_ORDER, NULL, CTX_NONE);
        RegisterNamespace("SORT:NEXT", 1, 2, tmplput_SORT_NEXT, NULL, CTX_NONE);
@@ -3127,6 +3176,10 @@ InitModule_SUBST
        RegisterNamespace("ITERATE", 2, 100, tmpl_iterate_subtmpl, preeval_iterate, CTX_NONE);
        RegisterNamespace("DOBOXED", 1, 2, tmpl_do_boxed, NULL, CTX_NONE);
        RegisterNamespace("DOTABBED", 2, 100, tmpl_do_tabbed, preeval_do_tabbed, CTX_NONE);
+       RegisterControlNS(HKEY("TAB:N"), 0, 0, tmplput_TAB_N, CTX_TAB);
+       RegisterControlNS(HKEY("TAB:SUBJECT"), 0, 1, tmplput_TAB_TITLE, CTX_TAB);
+
+
        RegisterNamespace("LONGVECTOR", 1, 1, tmplput_long_vector, NULL, CTX_LONGVECTOR);