CompareFunc Reverse;
CompareFunc GroupChange;
- long ContextType;
+ CtxType ContextType;
}SortStruct;
-const char *CtxNames[] = {
- "Context NONE",
- "Context SITECFG",
- "Context SESSION",
- "Context INETCFG",
- "Context VNOTE",
- "Context WHO",
- "Context PREF",
- "Context NODECONF",
- "Context USERLIST",
- "Context MAILSUM",
- "Context MIME_ATACH",
- "Context FILELIST",
- "Context STRBUF",
- "Context STRBUFARR",
- "Context LONGVECTOR",
- "Context ROOMS",
- "Context FLOORS",
- "Context ITERATE",
- "Context ICAL",
- "Context DavNamespace",
- "Context TAB",
- "Context VCARD",
- "Context SIEVE List",
- "Context SIEVE Script",
- "Context MailQ-Item",
- "Context MailQ-Recipient",
- "Context ServLogStatus",
- "Context UNKNOWN"
-};
+HashList *CtxList = NULL;
+
+static CtxType CtxCounter = CTX_NONE;
+
+CtxType CTX_STRBUF = CTX_NONE;
+CtxType CTX_STRBUFARR = CTX_NONE;
+CtxType CTX_LONGVECTOR = CTX_NONE;
+
+CtxType CTX_ITERATE = CTX_NONE;
+CtxType CTX_TAB = CTX_NONE;
+
+void HFreeContextType(void *pCtx)
+{
+ CtxTypeStruct *FreeStruct = (CtxTypeStruct *) pCtx;
+ FreeStrBuf(&FreeStruct->Name);
+ free(FreeStruct);
+}
+void PutContextType(const char *name, long len, CtxType TheCtx)
+{
+ CtxTypeStruct *NewStruct;
+
+ NewStruct = (CtxTypeStruct*) malloc(sizeof(CtxTypeStruct));
+ NewStruct->Name = NewStrBufPlain(name, len);
+ NewStruct->Type = TheCtx;
+
+ Put(CtxList, IKEY(NewStruct->Type), NewStruct, HFreeContextType);
+}
+void RegisterContextType(const char *name, long len, CtxType *TheCtx)
+{
+ if (*TheCtx != CTX_NONE)
+ return;
+
+ *TheCtx = ++CtxCounter;
+ PutContextType(name, len, *TheCtx);
+}
+
+CtxTypeStruct *GetContextType(CtxType Type)
+{
+ void *pv = NULL;
+ GetHash(CtxList, IKEY(Type), &pv);
+ return pv;
+}
+
+const char *UnknownContext = "CTX_UNKNOWN";
+
+const char *ContextName(CtxType ContextType)
+{
+ CtxTypeStruct *pCtx;
+
+ pCtx = GetContextType(ContextType);
+
+ if (pCtx != NULL)
+ return ChrPtr(pCtx->Name);
+ else
+ return UnknownContext;
+}
void StackContext(WCTemplputParams *Super,
WCTemplputParams *Sub,
void *Context,
- int ContextType,
+ CtxType ContextType,
int nArgs,
WCTemplateToken *Tokens)
{
}
}
-void *GetContextPayload(WCTemplputParams *TP, int ContextType)
+void *GetContextPayload(WCTemplputParams *TP, CtxType ContextType)
{
WCTemplputParams *whichTP = TP;
free (Sort);
}
-const char *ContextName(int ContextType)
-{
- if (ContextType < CTX_UNKNOWN)
- return CtxNames[ContextType];
- else
- return CtxNames[CTX_UNKNOWN];
-}
void LogTemplateError (StrBuf *Target, const char *Type, int ErrorPos, WCTemplputParams *TP, const char *Format, ...)
{
int nMaxArgs,
WCHandlerFunc HandlerFunc,
WCPreevalFunc PreevalFunc,
- int ContextRequired)
+ CtxType ContextRequired)
{
HashHandler *NewHandler;
} else {
LogTemplateError(
NULL, "Token ", ERR_NAME, &TP,
- " isn't known to us.",
- NULL);
+ " isn't known to us.");
}
break;
case SV_GETTEXT:
typedef struct _HashIterator {
HashList *StaticList;
int AdditionalParams;
- int ContextType;
- int XPectContextType;
+ CtxType ContextType;
+ CtxType XPectContextType;
int Flags;
RetrieveHashlistFunc GetHash;
HashDestructorFunc Destructor;
RetrieveHashlistFunc GetHash,
SubTemplFunc DoSubTempl,
HashDestructorFunc Destructor,
- int ContextType,
- int XPectContextType,
+ CtxType ContextType,
+ CtxType XPectContextType,
int Flags)
{
HashIterator *It;
CompareFunc Forward,
CompareFunc Reverse,
CompareFunc GroupChange,
- long ContextType)
+ CtxType ContextType)
{
SortStruct *NewSort;
InitModule_SUBST
(void)
{
+ RegisterCTX(CTX_TAB);
+ RegisterCTX(CTX_ITERATE);
+
memset(&NoCtx, 0, sizeof(WCTemplputParams));
RegisterNamespace("--", 0, 2, tmplput_Comment, NULL, CTX_NONE);
RegisterNamespace("SORT:ICON", 1, 2, tmplput_SORT_ICON, NULL, CTX_NONE);
Conditionals = NewHash(1, NULL);
SortHash = NewHash(1, NULL);
Defines = NewHash(1, NULL);
+ CtxList = NewHash(1, NULL);
+
+ PutContextType(HKEY("CTX_NONE"), 0);
+
+ RegisterCTX(CTX_STRBUF);
+ RegisterCTX(CTX_STRBUFARR);
+ RegisterCTX(CTX_LONGVECTOR);
}
void
DeleteHash(&Conditionals);
DeleteHash(&SortHash);
DeleteHash(&Defines);
+ DeleteHash(&CtxList);
}