t/dedupe: avoid div-by-zero for all identical chunks
[fio.git] / exp / expression-parser.l
index 388515e2c4722bea9c83de692479dd436fe15074..7d5e787dd9748bceebaa747ffcbe4edc37f9c2fc 100644 (file)
@@ -31,20 +31,85 @@ extern int lexer_input(char* buffer, int *nbytes, int buffersize);
                lexer_input((buffer), &(bytes_read), (bytes_requested))
 
 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 int __attribute__((unused)) input(void);
 
+#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]|[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;
+               }
+[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 +157,8 @@ bye  return BYE;
                }
        }
 \n     return 0;
-[+-/*()]       return yytext[0];
+[+-/*()^%]     return yytext[0];
+
 .      {
                yylval.v.has_error = 1;
                return NUMBER;