Commit | Line | Data |
---|---|---|
b470a02c SC |
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 | |
fa07eaa6 | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
b470a02c SC |
19 | * |
20 | */ | |
21 | ||
22 | #include <stdio.h> | |
23 | #include <string.h> | |
24 | ||
c879ba67 JA |
25 | #include "../y.tab.h" |
26 | ||
27 | extern int evaluate_arithmetic_expression(const char *buffer, long long *ival, | |
88038bc7 | 28 | double *dval, double implied_units, int is_time); |
b470a02c SC |
29 | |
30 | int main(int argc, char *argv[]) | |
31 | { | |
c879ba67 | 32 | int rc, bye = 0; |
b470a02c SC |
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'; | |
88038bc7 | 43 | rc = evaluate_arithmetic_expression(buffer, &result, &dresult, 1.0, 0); |
b470a02c | 44 | if (!rc) { |
18722a18 | 45 | printf("%lld (%20.20lf)\n", result, dresult); |
b470a02c | 46 | } else { |
7ff01fbe | 47 | fprintf(stderr, "Syntax error\n"); |
b470a02c SC |
48 | result = 0; |
49 | dresult = 0; | |
50 | } | |
51 | } while (!bye); | |
52 | return 0; | |
53 | } | |
54 |