Bugfixing / debugging in templating
authorWilfried Goesgens <dothebart@citadel.org>
Tue, 11 Jan 2011 22:23:18 +0000 (23:23 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 13:55:57 +0000 (13:55 +0000)
  - fix crash; check for non-parseable tokens so we don't struggle over NULL-Pointers later on.
  - -T6 now barfs the results of conditionals.

webcit/subst.c

index bec748d833ee4fb9b81f22774f62f615038fb432..3fa878a5efe63dc2a11c55c89ff9d44024d9ffed 100644 (file)
@@ -1239,6 +1239,7 @@ void *load_template(WCTemplate *NewTemplate)
                const char *pts, *pte;
                int InQuotes = 0;
                int InDoubleQuotes = 0;
+               void *pv;
 
                /** Find one <? > */
                pos = (-1);
@@ -1270,9 +1271,11 @@ void *load_template(WCTemplate *NewTemplate)
                if (pch + 1 > pE)
                        continue;
                pte = pch;
-               PutNewToken(NewTemplate, 
-                           NewTemplateSubstitute(NewTemplate->Data, pS, pts, pte, Line, NewTemplate));
-               pch ++;
+               pv = NewTemplateSubstitute(NewTemplate->Data, pS, pts, pte, Line, NewTemplate);
+               if (pv != NULL) {
+                       PutNewToken(NewTemplate, pv);
+                       pch ++;
+               }
        }
        return NewTemplate;
 }
@@ -1976,6 +1979,8 @@ int conditional_ITERATE_LASTN(StrBuf *Target, WCTemplputParams *TP)
 int EvaluateConditional(StrBuf *Target, int Neg, int state, WCTemplputParams *TP)
 {
        ConditionalStruct *Cond;
+       int rc = 0;
+       int res;
 
        if ((TP->Tokens->Params[0]->len == 1) &&
            (TP->Tokens->Params[0]->Start[0] == 'X'))
@@ -1992,10 +1997,14 @@ int EvaluateConditional(StrBuf *Target, int Neg, int state, WCTemplputParams *TP
        if (!CheckContext(Target, &Cond->Filter, TP, "Conditional")) {
                return 0;
        }
-
-       if (Cond->CondF(Target, TP) == Neg)
-               return TP->Tokens->Params[1]->lvalue;
-       return 0;
+       res = Cond->CondF(Target, TP);
+       if (res == Neg)
+               rc = TP->Tokens->Params[1]->lvalue;
+       if (LoadTemplates > 5) 
+               lprintf(1, "<%s> : %d %d==%d\n", 
+                       ChrPtr(TP->Tokens->FlatToken), 
+                       rc, res, Neg);
+       return rc;
 }
 
 void RegisterConditional(const char *Name, long len,