fio: allow arithmetic expressions to be used in job files
[fio.git] / exp / test-expression-parser.c
CommitLineData
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
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
25#include "y.tab.h"
26
27int main(int argc, char *argv[])
28{
29 int rc, has_error, bye = 0;
30 long long result;
31 double dresult;
32 char buffer[100];
33
34 do {
35 if (fgets(buffer, 90, stdin) == NULL)
36 break;
37 rc = strlen(buffer);
38 if (rc > 0 && buffer[rc - 1] == '\n')
39 buffer[rc - 1] = '\0';
40 rc = evaluate_arithmetic_expression(buffer, &result, &dresult);
41 if (!rc) {
42 printf("%lld (%lf)\n", result, dresult);
43 } else {
44 result = 0;
45 dresult = 0;
46 }
47 } while (!bye);
48 return 0;
49}
50