Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2014, Stephen M. Cameron. |
| 3 | * |
| 4 | * The license below covers all files distributed with fio unless otherwise |
| 5 | * noted in the file itself. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <string.h> |
| 24 | |
Jens Axboe | e27dadc | 2014-09-29 14:58:21 -0600 | [diff] [blame] | 25 | #include "../y.tab.h" |
| 26 | |
| 27 | extern int evaluate_arithmetic_expression(const char *buffer, long long *ival, |
Stephen M. Cameron | 79dc914 | 2014-11-10 20:31:26 -0700 | [diff] [blame] | 28 | double *dval, double implied_units, int is_time); |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 29 | |
| 30 | int main(int argc, char *argv[]) |
| 31 | { |
Jens Axboe | e27dadc | 2014-09-29 14:58:21 -0600 | [diff] [blame] | 32 | int rc, bye = 0; |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 33 | long long result; |
| 34 | double dresult; |
| 35 | char buffer[100]; |
| 36 | |
| 37 | do { |
| 38 | if (fgets(buffer, 90, stdin) == NULL) |
| 39 | break; |
| 40 | rc = strlen(buffer); |
| 41 | if (rc > 0 && buffer[rc - 1] == '\n') |
| 42 | buffer[rc - 1] = '\0'; |
Stephen M. Cameron | 79dc914 | 2014-11-10 20:31:26 -0700 | [diff] [blame] | 43 | rc = evaluate_arithmetic_expression(buffer, &result, &dresult, 1.0, 0); |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 44 | if (!rc) { |
Stephen M. Cameron | c3805eb | 2014-09-29 12:15:35 -0600 | [diff] [blame] | 45 | printf("%lld (%20.20lf)\n", result, dresult); |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 46 | } else { |
Stephen M. Cameron | 7ab38ba | 2014-09-30 09:31:04 -0500 | [diff] [blame] | 47 | fprintf(stderr, "Syntax error\n"); |
Stephen M. Cameron | 88b635b | 2014-09-29 12:10:49 -0600 | [diff] [blame] | 48 | result = 0; |
| 49 | dresult = 0; |
| 50 | } |
| 51 | } while (!bye); |
| 52 | return 0; |
| 53 | } |
| 54 | |