Always use display cursor (Bug #488796)
[gcalctool.git] / gcalctool / parser.c
blob98a50db3eba90203e5d7ecc7d6e7ab63c47d56f8
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 <assert.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <ctype.h>
27 #include "parser.h"
28 #include "calctool.h"
30 struct parser_state parser_state;
33 void
34 cp(int s[MP_SIZE], int t[MP_SIZE])
36 memcpy(t, s, sizeof(int)*MP_SIZE);
40 void
41 ret(int s[MP_SIZE]) /* Copy result value. */
43 memcpy(parser_state.ret, s, sizeof(int)*MP_SIZE);
44 parser_state.flags |= ANS;
47 void
48 check_numbase(char *num)
50 int i;
52 for (i = 0; num[i]; i++) {
53 char l = num[i];
55 if (l == '.' ||
56 l == ',' ||
57 l == 'e' ||
58 l == '+' ||
59 l == ' ') continue;
61 switch (v->base) {
62 case BIN:
63 if ((l < '0') || (l > '1')) {
64 parser_state.error = -PARSER_ERR_INVALID_BASE;
65 return;
67 break;
68 case OCT:
69 if ((l < '0') || (l > '7')) {
70 parser_state.error = -PARSER_ERR_INVALID_BASE;
71 return;
73 break;
74 case DEC:
75 if (!isdigit(l)) {
76 parser_state.error = -PARSER_ERR_INVALID_BASE;
77 return;
80 break;
81 case HEX:
82 if (!isxdigit(l)) {
83 parser_state.error = -PARSER_ERR_INVALID_BASE;
84 return;
86 break;
87 default:
88 assert(0); /* unknown base. */