Adjusted paramhandling to accept parameters with empty values (which is legal)
[citadel.git] / webcit / subst.h
index 75bbf3e33d7d4346f8f9b322f5238550e84820cd..bd6f8318d97d1d0202c8a93de535c546a64bb3a6 100644 (file)
@@ -1,5 +1,15 @@
-/**
- * @defgroup subst Template processing functions
+/*
+ * Copyright (c) 1996-2013 by the citadel.org team
+ *
+ * This program is open source software.  You can redistribute it and/or
+ * modify it under the terms of the GNU General Public License, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * subst template processing functions
  */
 
 extern HashList *Conditionals;
@@ -14,11 +24,12 @@ extern HashList *LocalTemplateCache;
 #define TYPE_STR   1
 #define TYPE_LONG  2
 #define TYPE_PREFSTR 3
-#define TYPE_PREFINT 4
-#define TYPE_GETTEXT 5
-#define TYPE_BSTR 6
-#define TYPE_SUBTEMPLATE 7
-#define TYPE_INTDEFINE 8
+#define TYPE_ROOMPREFSTR 4
+#define TYPE_PREFINT 5
+#define TYPE_GETTEXT 6
+#define TYPE_BSTR 7
+#define TYPE_SUBTEMPLATE 8
+#define TYPE_INTDEFINE 9
 #define MAXPARAM  25
 
 #define IS_NUMBER(a) ((a == TYPE_LONG) || (a == TYPE_PREFINT) || (a == TYPE_INTDEFINE))
@@ -152,6 +163,8 @@ struct WCTemplputParams {
        int nArgs;
        WCTemplateToken *Tokens;
        WCTemplputParams *Sub, *Super;
+       WCConditionalFunc ExitCtx;
+        long ExitCTXID;
 };
 
 
@@ -160,6 +173,7 @@ typedef struct _ConditionalStruct {
        ContextFilter Filter;
        const char *PlainName;
        WCConditionalFunc CondF;
+       WCConditionalFunc CondExitCtx;
 } ConditionalStruct;
 
 
@@ -267,6 +281,11 @@ void StrBufAppendTemplate(StrBuf *Target,
                          const StrBuf *Source, 
                          int FormatTypeIndex);
 
+void StrBufAppendTemplateStr(StrBuf *Target, 
+                            WCTemplputParams *TP,
+                            const char *Source, 
+                            int FormatTypeIndex);
+
 
 #define RegisterNamespace(a, b, c, d, e, f) RegisterNS(a, sizeof(a)-1, b, c, d, e, f)
 /**
@@ -296,12 +315,21 @@ void RegisterNS(const char *NSName, long len,
  * @param len the token length so we don't have to measure it.
  * @param nParams how many parameters does your conditional need on top of the default conditional parameters
  * @param CondF your Callback to be called when the template is evaluated at runtime; return 0 or 1 to us please.
+ * @param ExitCtxCond if non-NULL, will be called after the area of the conditional is left behind.
  * @param ContextRequired if your token requires a specific context, else say CTX_NONE here.
  */
-void RegisterConditional(const char *Name, long len, 
-                        int nParams,
-                        WCConditionalFunc CondF, 
-                        int ContextRequired);
+void RegisterContextConditional(const char *Name, long len, 
+                               int nParams,
+                               WCConditionalFunc CondF, 
+                               WCConditionalFunc ExitCtxCond,
+                               int ContextRequired);
+
+#define RegisterCtxConditional(Name, nParams, CondF, ExitCtxCond, ContextRequired) \
+       RegisterContextConditional(Name, sizeof(Name) -1, nParams, CondF, ExitCtxCond, ContextRequired)
+
+#define RegisterConditional(Name, nParams, CondF, ContextRequired) \
+       RegisterContextConditional(Name, sizeof(Name) -1, nParams, CondF, NULL, ContextRequired)
+
 
 /**
  * @ingroup subst
@@ -347,12 +375,18 @@ void RegisterITERATOR(const char *Name, long len, /* Our identifier */
 
 
 
-void StackContext(WCTemplputParams *Super, 
-                 WCTemplputParams *Sub, 
-                 void *Context,
-                 CtxType ContextType,
-                 int nArgs,
-                 WCTemplateToken *Tokens);
+void StackDynamicContext(WCTemplputParams *Super, 
+                        WCTemplputParams *Sub, 
+                        void *Context,
+                        CtxType ContextType,
+                        int nArgs,
+                        WCTemplateToken *Tokens, 
+                        WCConditionalFunc ExitCtx,
+                        long ExitCTXID);
+
+#define StackContext(Super, Sub, Context, ContextType, nArgs, Tokens) \
+       StackDynamicContext(Super, Sub, Context, ContextType, nArgs, Tokens, NULL, 0)
+
 
 void UnStackContext(WCTemplputParams *Sub);