X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=exp%2Fexpression-parser.y;h=d664b8edd310d3ab36c8b5880158ded0c5507c32;hb=79baf7f48a6e680e1e746e150b60c165542fdf6c;hp=af726a66b4d92293fa3c56b83d531bbacff30c3b;hpb=5fe4c88681360025fa4662c3898edd33f0d7585c;p=fio.git diff --git a/exp/expression-parser.y b/exp/expression-parser.y index af726a66..d664b8ed 100644 --- a/exp/expression-parser.y +++ b/exp/expression-parser.y @@ -21,6 +21,7 @@ #include #include #include + struct parser_value_type { double dval; long long ival; @@ -37,10 +38,12 @@ typedef union valtype { int yyerror(__attribute__((unused)) long long *result, __attribute__((unused)) double *dresult, __attribute__((unused)) int *has_error, - __attribute__((unused)) int *bye, const char *msg); + __attribute__((unused)) int *units_specified, + __attribute__((unused)) const char *msg); extern int yylex(void); extern void yyrestart(FILE *file); +extern int lexer_value_is_time; %} @@ -57,6 +60,7 @@ extern void yyrestart(FILE *file); %token BYE %token SUFFIX %left '-' '+' +%right SUFFIX %left '*' '/' %right '^' %left '%' @@ -64,7 +68,7 @@ extern void yyrestart(FILE *file); %parse-param { long long *result } %parse-param { double *dresult } %parse-param { int *has_error } -%parse-param { int *bye } +%parse-param { int *units_specified } %type expression %% @@ -132,6 +136,7 @@ expression: expression '+' expression { else $$.dval = $1.ival * $2.ival; $$.has_error = $1.has_error || $2.has_error; + *units_specified = 1; } | expression '%' expression { if ($1.has_dval || $3.has_dval) @@ -175,8 +180,7 @@ expression: expression '+' expression { $$.ival = (long long) $$.dval; } } - | NUMBER { $$ = $1; } - | BYE { $$ = $1; *bye = 1; }; + | NUMBER { $$ = $1; }; %% #include @@ -184,7 +188,7 @@ expression: expression '+' expression { static int lexer_read_offset = 0; static char lexer_input_buffer[1000]; -int lexer_input(char* buffer, int *bytes_read, int bytes_requested) +int lexer_input(char* buffer, unsigned int *bytes_read, int bytes_requested) { int bytes_left = strlen(lexer_input_buffer) - lexer_read_offset; @@ -210,27 +214,34 @@ static void setup_to_parse_string(const char *string) lexer_read_offset = 0; } -int evaluate_arithmetic_expression(const char *buffer, long long *ival, double *dval) +int evaluate_arithmetic_expression(const char *buffer, long long *ival, double *dval, + double implied_units, int is_time) { - int rc, bye = 0, has_error = 0; + int rc, units_specified = 0, has_error = 0; + lexer_value_is_time = is_time; setup_to_parse_string(buffer); - rc = yyparse(ival, dval, &has_error, &bye); + rc = yyparse(ival, dval, &has_error, &units_specified); yyrestart(NULL); - if (rc || bye || has_error) { + if (rc || has_error) { *ival = 0; *dval = 0; has_error = 1; } + if (!units_specified) { + *ival = (int) ((double) *ival * implied_units); + *dval = *dval * implied_units; + } return has_error; } int yyerror(__attribute__((unused)) long long *result, __attribute__((unused)) double *dresult, __attribute__((unused)) int *has_error, - __attribute__((unused)) int *bye, const char *msg) + __attribute__((unused)) int *units_specified, + __attribute__((unused)) const char *msg) { - fprintf(stderr, "%s\n", msg); + /* We do not need to do anything here. */ return 0; }