negative boolean config expressions patch

From: Nikolai Gorchilov <niki_at_x3me.net>
Date: Fri, 7 Mar 2014 20:04:39 +0200

Dear Squid Devs,

In order to simplify an already complicated squid config I needed a
negative boolean check like this:
if ${process_number} != 1
 ... do something in case this is NOT kid1
endif

Here's the patch, in case you find it interesting for inclusion in the trunk:
===[cut]===
--- src/cache_cf.cc 2014-03-07 18:18:30.041298048 +0200
+++ src/cache_cf.cc 2014-03-07 18:19:48.773297871 +0200
@@ -429,9 +429,10 @@
     } else if (strcmp(expr, "false") == 0) {
         return false;
     } else if (const char* equation = strchr(expr, '=')) {
+ int positive = (int) expr[equation - expr - 1] != '!';
         const char* rvalue = skip_ws(equation + 1);
- char* lvalue = (char*)xmalloc(equation - expr + 1);
- xstrncpy(lvalue, expr, equation - expr + 1);
+ char* lvalue = (char*)xmalloc(equation - expr + positive);
+ xstrncpy(lvalue, expr, equation - expr + positive);
         trim_trailing_ws(lvalue);

         long number1;
@@ -442,7 +443,7 @@
             fatalf("String is not a integer number: '%s'\n", rvalue);

         xfree(lvalue);
- return number1 == number2;
+ return positive == 1 ? number1 == number2 : number1 != number2;
     }
     fatalf("Unable to evaluate expression '%s'\n", expr);
     return false; // this place cannot be reached
===[cut]===

Hope this helps.

Best,
Niki

P.S. Pls. excuse my coding style, I didn't do any c++ since early 90s
:) I don't mind if you rewrite it completely :)
Received on Fri Mar 07 2014 - 18:05:27 MST

This archive was generated by hypermail 2.2.0 : Sat Mar 08 2014 - 12:00:11 MST