From 8f51718ae84400812262403e4065ff4e1a6d5f0b Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Mon, 1 Aug 2011 23:10:00 +0000 Subject: [PATCH] after reading a template sanity check conditionals whether they're paired --- webcit/subst.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/webcit/subst.c b/webcit/subst.c index 907e1a34f..9a0be445f 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -1193,6 +1193,45 @@ void *duplicate_template(WCTemplate *OldTemplate) return NewTemplate; } + +void SanityCheckTemplate(WCTemplate *CheckMe) +{ + int i = 0; + int j; + int FoundConditionalEnd; + + for (i = 0; i < CheckMe->nTokensUsed; i++) + { + switch(CheckMe->Tokens[i]->Flags) + { + case SV_CONDITIONAL: + case SV_NEG_CONDITIONAL: + FoundConditionalEnd = 0; + if ((CheckMe->Tokens[i]->Params[0]->len == 1) && + (CheckMe->Tokens[i]->Params[0]->Start[0] == 'X')) + break; + for (j = i + 1; j < CheckMe->nTokensUsed; j++) + { + if (((CheckMe->Tokens[j]->Flags == SV_CONDITIONAL) || + (CheckMe->Tokens[j]->Flags == SV_NEG_CONDITIONAL)) && + (CheckMe->Tokens[i]->Params[1]->lvalue == + CheckMe->Tokens[j]->Params[1]->lvalue)) + { + FoundConditionalEnd = 1; + break; + } + + } + if (!FoundConditionalEnd) + { + syslog(1, "ERROR: Conditional without Endconditional: '%s'\n", + ChrPtr(CheckMe->Tokens[i]->FlatToken)); + } + break; + } + } +} + /** * \brief Display a variable-substituted template * \param templatename template file to load @@ -1282,6 +1321,8 @@ void *load_template(WCTemplate *NewTemplate) pch ++; } } + + SanityCheckTemplate(NewTemplate); return NewTemplate; } -- 2.30.2