Fix for a crash which happened when a document couldn't be opened.
[AROS-Contrib.git] / fish / eval / eval.h
blob5e7c71540207ec7efa6faf22f557ae1ee684c236
1 /*
2 **
3 ** EVAL.H Master include file for Eval.
4 ** Contains function definitions and global definitions
5 ** and typecasts
6 **
7 ** originally written 5/89
8 **
9 ** Eval is a floating point expression evaluator.
10 ** This is version 1.12
11 ** Copyright (C) 1993 Will Menninger
13 ** This program is free software; you can redistribute it and/or modify it
14 ** under the terms of the GNU General Public License as published by the
15 ** Free Software Foundation; either version 2 of the License, or any
16 ** later version.
18 ** This program is distributed in the hope that it will be useful, but
19 ** WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ** General Public License for more details.
23 ** You should have received a copy of the GNU General Public License along
24 ** with this program; if not, write to the Free Software Foundation, Inc.,
25 ** 675 Mass Ave, Cambridge, MA 02139, USA.
27 ** The author until 9/93 can be contacted at:
28 ** e-mail: willus@ilm.pfc.mit.edu
29 ** U.S. mail: Will Menninger, 45 River St., #2, Boston, MA 02108-1124
33 /* Global includes */
35 #include <stdio.h>
36 #include <math.h>
37 #include <string.h>
38 #include <ctype.h>
39 #include <stdlib.h>
40 #include <float.h>
42 /* For math functions */
43 #define SGN(x) ((x)<0 ? -1 : ((x)>0 ? 1 : 0))
44 #define ABS(x) ((x)<0 ? -(x) : (x))
45 #define SWAP(a,b) {float temp=(a);(a)=(b);(b)=temp;}
48 /* Global definitions */
49 #define VERSION "1.12"
50 #define TRUE 1
51 #define FALSE 0
52 #define MAXC 56
53 #define MAXV 100
54 #define MAXNAMELEN 16
55 #define MAXINPUT 160
56 #define NUMFUNCS 30
57 #define MAXFLEN 6
58 #define SCRWIDTH 80
59 #define MAXARGS 10
60 #define EOS '\0'
61 #define NLINES 21
62 #define PROMPT "Ex>"
64 #define MAXOUTLEN 1100
65 /* I removed the original definition of MAXOUTLEN because it was
66 too big on some compilers */
68 #define MAXOUTLEN (DBL_MAX_EXP+100)
71 /* types of tokens */
72 #define BINARY 1
73 #define UNARY 2
74 #define FUNCTION 3
75 #define VARIABLE 4
76 #define NUMBER 5
77 #define LEFT_PAREN 6
78 #define RIGHT_PAREN 7
79 #define COMMA 8
80 #define ILLEGAL 9
81 #define CONSTANT 10
82 #define VOID 11
83 #define QUOTE 12
85 /* binary operators */
86 #define ADD 1
87 #define SUBTRACT 2
88 #define MULTIPLY 3
89 #define DIVIDE 4
90 #define POWER 5
91 #define AND 6
92 #define OR 7
93 #define XOR 8
94 #define MOD 9
95 #define SHLEFT 10
96 #define SHRIGHT 11
97 #define BSTRING "+-*/^&|?%"
99 /* unary operators */
100 #define POSITIVE 1
101 #define NEGATIVE 2
102 #define NOT 3
103 #define USTRING "+-~"
106 /* Global typecasts */
108 typedef int BOOLEAN;
109 typedef struct {
110 char name[MAXNAMELEN+1];
111 double value;
112 } VAR, *VARPTR;
113 typedef struct {
114 double value;
115 char type;
116 int code;
117 } TOKEN, *TOKENPTR;
119 /* Function definitions */
121 /* ----- EVAL.C functions ---------------------------------------------- */
123 BOOLEAN insert_var (VARPTR new,VARPTR vlist);
124 BOOLEAN search_varlist (VARPTR var,VARPTR vlist,int *n,int max);
125 void fixup (char *s);
127 /* ----- FUNCS.C functions --------------------------------------------- */
129 int func_code (char *);
130 BOOLEAN func_eval (int,double *,double *);
131 char *func_name (int);
132 int func_nargs (int);
133 int print_funclist (FILE *s,char *input,int d);
135 /* ----- PARSE.C functions -------------------------------------------- */
137 void evaluate (char *,int,VARPTR,VARPTR);
138 BOOLEAN eerror (char *message);
139 void tokcpy (TOKENPTR dest,TOKENPTR source);
141 /* ----- ESTACK.C functions ------------------------------------------- */
143 void clear_stack (void);
144 BOOLEAN pop_token (TOKENPTR);
145 BOOLEAN push_token (TOKENPTR);
146 BOOLEAN top_of_stack (TOKENPTR);
148 /* ----- ETABLE.C functions ------------------------------------------- */
150 BOOLEAN add_token (TOKENPTR);
151 void clear_table (void);
152 BOOLEAN result (int,int,double *,double *);
153 BOOLEAN table_value (double *);
155 /* ----- BASE.C functions --------------------------------------------- */
157 void baseconv (double val,char *buf);
158 void set_scinote (int val);
159 void set_sigfig (int val);
160 void set_dplace (int val);
161 void set_maxexp (int val);
162 void set_fix (int val);
163 void setobase (int base);
164 void setibase (int base);
165 int getobase (void);
166 int getibase (void);
167 int get_scinote (void);
168 int get_fix (void);
169 int precision (int base);
170 void print_outtype (void);
171 double asciiconv (int base,char *s);
173 /* ----- BITWISE.C functions --------------------------------------------- */
175 double not (double val);
176 double or (double val1,double val2);
177 double and (double val1,double val2);
178 double xor (double val1,double val2);
180 /* ----- EMATH.C functions ----------------------------------------------- */
182 double bessi (int,double);
183 double bessj (int,double);
184 double bessk (int,double);
185 double dbessi (int,double);
186 double dbessj (int,double);
187 double dbessk (int,double);
188 double jroot (int,int);
189 double djroot (int,int);
190 double factorial (int);
191 double root (double(*F)(double),double,double,double,int *);
192 double root2 (double(*F)(int,double),int,double,double,double,
193 int *);
194 double atanh (double x);
195 double asinh (double x);
196 double acosh (double x);