more ui tidyup
[gcalctool.git] / gcalctool / ce_parser.c
blobcc66a60da3ea1075af9b7f1369ab6d42295c1c47
2 /* $Header$
4 * Copyright (C) 2004-2007 Sami Pietila
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
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
19 * 02111-1307, USA.
22 #include "ce_parser.h"
23 #include "limits.h"
24 #include "calctool.h"
25 #include "functions.h" /* FIXME: Needed for gc_strdup() */
27 /* TODO: This file is almost identical to lr-parser. */
29 int
30 ce_parse_(char *expression, int result[MP_SIZE], int flags)
32 int ret = 0;
34 if (!(expression && result)) {
35 return(-EINVAL);
38 memset(&parser_state, 0, sizeof(struct parser_state));
40 if (strlen(expression)) {
41 parser_state.i = 0;
42 parser_state.buff = gc_strdup(expression);
43 v->math_error = 0;
44 ret = ceparse();
45 free(parser_state.buff);
48 ret = (parser_state.error) ? parser_state.error : ret;
50 if (ret) {
51 return(ret);
52 } else {
53 if ((flags & ANS) != (parser_state.flags & ANS)) {
54 return -EINVAL;
57 if (v->math_error) {
58 return v->math_error;
61 if (flags & ANS) {
62 memcpy(result, parser_state.ret, sizeof(int)*MP_SIZE);
65 return 0;
70 int
71 ce_parse(char *expression, int result[MP_SIZE])
73 return(ce_parse_(expression, result, ANS));
77 int
78 ce_udf_parse(char *expression)
80 int dummy[MP_SIZE];
82 return(ce_parse_(expression, dummy, 0));