From 886e5ecd1a9adef9bac150c8c87acc2ce5b974b9 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 29 Sep 2014 13:20:40 -0600 Subject: [PATCH] fio: support modulus for the arithmetic parser Signed-off-by: Jens Axboe --- exp/expression-parser.l | 2 +- exp/expression-parser.y | 10 ++++++++++ fio.1 | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/exp/expression-parser.l b/exp/expression-parser.l index a0c6b24d..bb80553e 100644 --- a/exp/expression-parser.l +++ b/exp/expression-parser.l @@ -158,7 +158,7 @@ bye return BYE; } } \n return 0; -[+-/*()^] return yytext[0]; +[+-/*()^%] return yytext[0]; . { yylval.v.has_error = 1; diff --git a/exp/expression-parser.y b/exp/expression-parser.y index f5a7981f..fa19a51a 100644 --- a/exp/expression-parser.y +++ b/exp/expression-parser.y @@ -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 66c9cb03..01c7cec0 100644 --- 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). -- 2.25.1