blob: bf3fb3edff889909e3093f60dd9008d4041ea420 [file] [log] [blame]
Stephen M. Cameron88b635b2014-09-29 12:10:49 -06001/*
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 Axboee27dadc2014-09-29 14:58:21 -060025#include "../y.tab.h"
26
27extern int evaluate_arithmetic_expression(const char *buffer, long long *ival,
Stephen M. Cameron79dc9142014-11-10 20:31:26 -070028 double *dval, double implied_units, int is_time);
Stephen M. Cameron88b635b2014-09-29 12:10:49 -060029
30int main(int argc, char *argv[])
31{
Jens Axboee27dadc2014-09-29 14:58:21 -060032 int rc, bye = 0;
Stephen M. Cameron88b635b2014-09-29 12:10:49 -060033 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. Cameron79dc9142014-11-10 20:31:26 -070043 rc = evaluate_arithmetic_expression(buffer, &result, &dresult, 1.0, 0);
Stephen M. Cameron88b635b2014-09-29 12:10:49 -060044 if (!rc) {
Stephen M. Cameronc3805eb2014-09-29 12:15:35 -060045 printf("%lld (%20.20lf)\n", result, dresult);
Stephen M. Cameron88b635b2014-09-29 12:10:49 -060046 } else {
Stephen M. Cameron7ab38ba2014-09-30 09:31:04 -050047 fprintf(stderr, "Syntax error\n");
Stephen M. Cameron88b635b2014-09-29 12:10:49 -060048 result = 0;
49 dresult = 0;
50 }
51 } while (!bye);
52 return 0;
53}
54