[exim-dev] modulo

Startseite
Nachricht löschen
Nachricht beantworten
Autor: Jakob Hirsch
Datum:  
To: exim-dev
Betreff: [exim-dev] modulo
Hi,

attached is a small patch to add the modulo operator % to eval. Can be
used as a very poor man's random_with_range (e.g. $tod_epoch%$pid%10,
though nhash might be better for that), but may also be handy for other
things.
A "real" random operator could be nice.
--- exim-snapshot-20050802.orig/src/expand.c    2005-08-02 17:23:40 +0200
+++ exim-snapshot-20050802.jh1/src/expand.c    2005-08-22 10:54:50 +0200
@@ -2746,12 +2746,14 @@
 int x = eval_term(&s, decimal, error);
 if (*error == NULL)
   {
-  while (*s == '*' || *s == '/')
+  while (*s == '*' || *s == '/' || *s == '%')
     {
     int op = *s++;
     int y = eval_term(&s, decimal, error);
     if (*error != NULL) break;
-    if (op == '*') x *= y; else x /= y;
+    if (op == '*') x *= y;
+    else if (op == '/') x /= y;
+    else x %= y;
     }
   }
 *sptr = s;