X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=exp%2Fexpression-parser.l;h=692c6cc37d9bbac5873d8dee9b58c72def1d17eb;hp=388515e2c4722bea9c83de692479dd436fe15074;hb=fa07eaa6913d7171c4259b3b0cd76dae3e76ca00;hpb=b470a02cade02049509d22442addfbc88d10116e diff --git a/exp/expression-parser.l b/exp/expression-parser.l index 388515e2..692c6cc3 100644 --- a/exp/expression-parser.l +++ b/exp/expression-parser.l @@ -14,7 +14,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ @@ -24,27 +24,109 @@ #define YYSTYPE PARSER_VALUE_TYPE -extern int lexer_input(char* buffer, int *nbytes, int buffersize); +extern int lexer_input(char *buffer, unsigned int *nbytes, int buffersize); #undef YY_INPUT -#define YY_INPUT(buffer, bytes_read, bytes_requested) \ - lexer_input((buffer), &(bytes_read), (bytes_requested)) +#define YY_INPUT(buffer, bytes_read, bytes_requested) \ +({ \ + int __ret; \ + unsigned int __bread = bytes_read; \ + __ret = lexer_input((buffer), &__bread, (bytes_requested)); \ + bytes_read = __bread; \ + __ret; \ +}) extern int yyerror(long long *result, double *dresult, - int *has_error, int *bye, const char *msg); + int *has_error, int *units_specified, const char *msg); -static void __attribute__((unused)) yyunput(int c,char *buf_ptr); +static void __attribute__((unused)) yyunput(int c, char *buf_ptr); static int __attribute__((unused)) input(void); +/* set by parser -- this is another thing which makes the parser thread-unsafe :(. */ +int lexer_value_is_time = 0; /* for determining if "m" suffix means mega- or minutes */ + +#define set_suffix_value(yylval, i_val, d_val, has_d_val) \ + (yylval).v.dval = (d_val); \ + (yylval).v.ival = (i_val); \ + (yylval).v.has_dval = (has_d_val); \ + (yylval).v.has_error = 0; + %} %% -bye return BYE; +[kK]|[kK][bB] { + set_suffix_value(yylval, 1024, 1024.0, 0); + return SUFFIX; + } +[Mm][bB] { + set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0); + return SUFFIX; + } +[mM][sS] { + set_suffix_value(yylval, 1000, 1000.0, 1); + return SUFFIX; + } +[uU][sS] { + set_suffix_value(yylval, 1, 1.0, 1); + return SUFFIX; + } +[gG]|[Gg][Bb] { + set_suffix_value(yylval, 1024LL * 1024 * 1024, 1024.0 * 1024.0 * 1024, 0); + return SUFFIX; + } +[tT]|[tT][bB] { + set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024, + 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024, 0); + return SUFFIX; + } +[pP]|[pP][bB] { + set_suffix_value(yylval, 1024LL * 1024 * 1024 * 1024 * 1024, + 1024.0 * 1024.0 * 1024.0 * 1024.0 * 1024.0, 0); + return SUFFIX; + } +[kK][iI][Bb] { + set_suffix_value(yylval, 1000LL, 1000.0, 0); + return SUFFIX; + } +[mM][Ii][bB] { + set_suffix_value(yylval, 1000000LL, 1000000.0 , 0); + return SUFFIX; + } +[gG][iI][Bb] { + set_suffix_value(yylval, 1000000000LL, 1000000000.0 , 0); + return SUFFIX; + } +[pP][iI][Bb] { + set_suffix_value(yylval, 1000000000000LL, 1000000000000.0 , 0); + return SUFFIX; + } +[sS] { + set_suffix_value(yylval, 1000000LL, 1000000.0 , 0); + return SUFFIX; + } +[mM] { + if (!lexer_value_is_time) { + set_suffix_value(yylval, 1024 * 1024, 1024.0 * 1024.0, 0); + } else { + set_suffix_value(yylval, 60LL * 1000000LL, 60.0 * 1000000.0, 0); + } + return SUFFIX; + } +[dD] { + set_suffix_value(yylval, 60LL * 60LL * 24LL * 1000000LL, + 60.0 * 60.0 * 24.0 * 1000000.0, 0); + return SUFFIX; + } +[hH] { + set_suffix_value(yylval, 60LL * 60LL * 1000000LL, + 60.0 * 60.0 * 1000000.0, 0); + return SUFFIX; + } [ \t] ; /* ignore whitespace */ -#.+ ; /* ignore comments */ -[0-9]*[.][0-9]+ { +[#:,].* ; /* ignore comments, and everything after colons and commas */ +[0-9]*[.][0-9]+|[0-9]*[.]?[0-9]+[eE][-+]*[0-9]+ { int rc; double dval; @@ -92,7 +174,8 @@ bye return BYE; } } \n return 0; -[+-/*()] return yytext[0]; +[+-/*()^%] return yytext[0]; + . { yylval.v.has_error = 1; return NUMBER;