X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fsubst.c;h=4b85aa1066a7fe639db69ad3e1f4d5cd96e49fce;hb=d3e0ff340e0904aa1dd02c40e3c971f4ca4794c6;hp=90243de86e93009ce1589a33efd3dbcd0b95561a;hpb=696b9fde636d88d10868395be37f443ea9bc497b;p=citadel.git diff --git a/webcit/subst.c b/webcit/subst.c index 90243de86..4b85aa106 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -25,6 +25,7 @@ HashList *GlobalNS; HashList *Iterators; HashList *Conditionals; HashList *SortHash; +HashList *Defines; int DumpTemplateI18NStrings = 0; int LoadTemplates = 0; @@ -780,6 +781,7 @@ void GetTemplateTokenString(StrBuf *Target, switch (TP->Tokens->Params[N]->Type) { + case TYPE_INTDEFINE: case TYPE_STR: *Value = TP->Tokens->Params[N]->Start; *len = TP->Tokens->Params[N]->len; @@ -890,7 +892,8 @@ long GetTemplateTokenNumber(StrBuf *Target, WCTemplputParams *TP, int N, long df } if (get_PREF_LONG(TKEY(N), &Ret, dflt)) return Ret; - return 0; + return 0; + case TYPE_INTDEFINE: case TYPE_LONG: return TP->Tokens->Params[N]->lvalue; case TYPE_PREFINT: @@ -1111,7 +1114,12 @@ void PutNewToken(WCTemplate *Template, WCTemplateToken *NewToken) Template->Tokens[(Template->nTokensUsed)++] = NewToken; } -TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe, WCTemplateToken *Tokens, WCTemplate *pTmpl) +TemplateParam *GetNextParameter(StrBuf *Buf, + const char **pCh, + const char *pe, + WCTemplateToken *Tokens, + WCTemplate *pTmpl, + WCTemplputParams *TP) { const char *pch = *pCh; const char *pchs, *pche; @@ -1145,6 +1153,10 @@ TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe, W ParamBrace = 1; } } + else if (*pch == '#') { + Parm->Type = TYPE_INTDEFINE; + pch ++; + } else if (*pch == '_') { Parm->Type = TYPE_GETTEXT; pch ++; @@ -1249,6 +1261,25 @@ TemplateParam *GetNextParameter(StrBuf *Buf, const char **pCh, const char *pe, W if (DumpTemplateI18NStrings && (Parm->Type == TYPE_GETTEXT)) { StrBufAppendPrintf(I18nDump, "_(\"%s\");\n", Parm->Start); } + if (Parm->Type == TYPE_INTDEFINE) + { + void *vPVal; + + if (GetHash(Defines, Parm->Start, Parm->len, &vPVal) && + (vPVal != NULL)) + { + long *PVal; + PVal = (long*) vPVal; + + Parm->lvalue = *PVal; + } + else + { + LogTemplateError(NULL, "Define", ERR_PARM1, TP, + "%s isn't known!!", + Parm->Start); + } + } *pCh = pch; return Parm; } @@ -1299,7 +1330,7 @@ WCTemplateToken *NewTemplateSubstitute(StrBuf *Buf, "Warning, Non welformed Token; missing right parenthesis"); } while (pch < pTmplEnd - 1) { - Param = GetNextParameter(Buf, &pch, pTmplEnd - 1, NewToken, pTmpl); + Param = GetNextParameter(Buf, &pch, pTmplEnd - 1, NewToken, pTmpl, &TP); if (Param != NULL) { NewToken->HaveParameters = 1; if (NewToken->nParameters > MAXPARAM) { @@ -2174,6 +2205,18 @@ void RegisterControlConditional(const char *Name, long len, Put(Conditionals, Name, len, Cond, NULL); } +void RegisterTokenParamDefine(const char *Name, long len, + long Value) +{ + long *PVal; + + PVal = (long*)malloc(sizeof(long)); + *PVal = Value; + Put(Defines, Name, len, PVal, NULL); +} + +HashList *Defines; + /*----------------------------------------------------------------------------- * Context Strings */ @@ -2681,6 +2724,7 @@ ServerStartModule_SUBST Iterators = NewHash(1, NULL); Conditionals = NewHash(1, NULL); SortHash = NewHash(1, NULL); + Defines = NewHash(1, NULL); } void @@ -2703,7 +2747,7 @@ ServerShutdownModule_SUBST DeleteHash(&Iterators); DeleteHash(&Conditionals); DeleteHash(&SortHash); - + DeleteHash(&Defines); }