fio: support modulus for the arithmetic parser
authorJens Axboe <axboe@fb.com>
Mon, 29 Sep 2014 19:20:40 +0000 (13:20 -0600)
committerJens Axboe <axboe@fb.com>
Mon, 29 Sep 2014 19:20:40 +0000 (13:20 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
exp/expression-parser.l
exp/expression-parser.y
fio.1

index a0c6b24d362ed59d6fc991d81f993477055c935f..bb80553ee40349a1ec596f0c7c66142c4b2e365c 100644 (file)
@@ -158,7 +158,7 @@ bye         return BYE;
                }
        }
 \n     return 0;
-[+-/*()^     return yytext[0];
+[+-/*()^%]     return yytext[0];
 
 .      {
                yylval.v.has_error = 1;
index f5a7981f2fbfa8eb6bdacc61d5d99c6e81c9e1f5..fa19a51ad68268571d96eb723de2b15d0dafac86 100644 (file)
@@ -59,6 +59,7 @@ extern void yyrestart(FILE *file);
 %left '-' '+'
 %left '*' '/'
 %right '^'
+%left '%'
 %nonassoc UMINUS
 %parse-param { long long *result }
 %parse-param { double *dresult }
@@ -132,6 +133,15 @@ expression:        expression '+' expression {
                                $$.dval = $1.ival * $2.ival;
                        $$.has_error = $1.has_error || $2.has_error;
                }
+       |       expression '%' expression {
+                       if ($1.has_dval || $3.has_dval)
+                               yyerror(0, 0, 0, 0, "modulo on floats");
+                       if ($3.ival == 0)
+                               yyerror(0, 0, 0, 0, "divide by zero");
+                       else
+                               $$.ival = $1.ival % $3.ival;
+                       $$.has_error = $1.has_error || $3.has_error;
+               }
        |       expression '^' expression {
                        $$.has_error = $1.has_error || $3.has_error;
                        if (!$1.has_dval && !$3.has_dval) {
diff --git a/fio.1 b/fio.1
index 66c9cb03b42a3a9d712e9f5e58054a30627edb56..01c7cec03b5b345b3ac135608c5846844d145980 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -119,7 +119,7 @@ Some parameters may take arguments of a specific type.
 Anywhere a numeric value is required, an arithmetic expression may be used,
 provided it is surrounded by parentheses.
 Supported operators are
-addition, subtraction, multiplication, division and exponentiation.
+addition, subtraction, multiplication, division, modulus, and exponentiation.
 For time values in expressions
 units are microseconds by default.  This is different than for time
 values not in expressions (not enclosed in parentheses).