2 * calc - definitions for calculator program
4 * Copyright (C) 1999 David I. Bell
6 * Calc is open software; you can redistribute it and/or modify it under
7 * the terms of the version 2.1 of the GNU Lesser General Public License
8 * as published by the Free Software Foundation.
10 * Calc is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
13 * Public License for more details.
15 * A copy of version 2.1 of the GNU Lesser General Public License is
16 * distributed with calc under the filename COPYING-LGPL. You should have
17 * received a copy with calc; if not, write to Free Software Foundation, Inc.
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
24 * Under source code control: 1990/02/15 01:48:31
25 * File existed as early as: before 1990
27 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
31 #if !defined(__CALC_H__)
35 #if defined(CALC_SRC) /* if we are building from the calc source tree */
36 # include "calc/win32dll.h"
37 # include "calc/value.h"
38 # include "calc/have_const.h"
40 # include <calc/win32dll.h>
41 # include <calc/value.h>
42 # include <calc/have_const.h>
47 * Configuration definitions
49 #define CALCPATH "CALCPATH" /* environment variable for files */
50 #define CALCRC "CALCRC" /* environment variable for startup */
51 #define CALCBINDINGS "CALCBINDINGS" /* env variable for hist bindings */
52 #define HOME "HOME" /* environment variable for home dir */
53 #define PAGER "PAGER" /* environment variable for help */
54 #define SHELL "SHELL" /* environment variable for shell */
55 #define DEFAULTCALCBINDINGS "bindings" /* default calc bindings file */
56 #define DEFAULTCALCHELP "help" /* help file that -h prints */
57 #define DEFAULTSHELL "sh" /* default shell to use */
58 #define CALCEXT ".cal" /* extension for files read in */
59 #define MAX_CALCRC 1024 /* maximum length of $CALCRC */
60 #define HOMECHAR '~' /* char which indicates home directory */
61 #define DOTCHAR '.' /* char which indicates current directory */
62 #define PATHCHAR '/' /* char which separates path components */
63 #if defined(__MSDOS__) || defined(__WIN32)
64 #define LISTCHAR ';' /* char which separates paths in a list */
66 #define LISTCHAR ':' /* char which separates paths in a list */
68 #define MAXCMD 16384 /* maximum length of command invocation */
69 #define MAXERROR 512 /* maximum length of error message string */
71 #define SYMBOLSIZE 256 /* maximum symbol name size */
72 #define MAXLABELS 100 /* maximum number of user labels in function */
73 #define MAXSTRING 1024 /* maximum size of string constant */
74 #define MAXSTACK 2048 /* maximum depth of evaluation stack */
75 #define MAXFILES 20 /* maximum number of opened files */
76 #define PROMPT1 "> " /* default normal prompt*/
77 #define PROMPT2 ">> " /* default prompt inside multi-line input */
80 #define TRACE_NORMAL 0x00 /* normal trace flags */
81 #define TRACE_OPCODES 0x01 /* trace every opcode */
82 #define TRACE_NODEBUG 0x02 /* suppress debugging opcodes */
83 #define TRACE_LINKS 0x04 /* display links for real and complex numbers */
84 #define TRACE_FNCODES 0x08 /* display code for newly defined function */
85 #define TRACE_MAX 0x0f /* maximum value for trace flag */
87 #define ABORT_NONE 0 /* abort not needed yet */
88 #define ABORT_STATEMENT 1 /* abort on statement boundary */
89 #define ABORT_OPCODE 2 /* abort on any opcode boundary */
90 #define ABORT_MATH 3 /* abort on any math operation */
91 #define ABORT_NOW 4 /* abort right away */
93 #define ERRMAX 20 /* default errmax value */
96 * File ids corresponding to standard in, out, error, and when not in use.
98 #define FILEID_STDIN ((FILEID) 0)
99 #define FILEID_STDOUT ((FILEID) 1)
100 #define FILEID_STDERR ((FILEID) 2)
101 #define FILEID_NONE ((FILEID) -1)
106 extern DLL FILEID openid(char *name, char *mode);
107 extern DLL FILEID indexid(long index);
108 extern DLL BOOL validid(FILEID id);
109 extern DLL BOOL errorid(FILEID id);
110 extern DLL BOOL eofid(FILEID id);
111 extern DLL int closeid(FILEID id);
112 extern DLL int getcharid(FILEID id);
113 extern DLL int idprintf(FILEID id, char *fmt, int count, VALUE **vals);
114 extern DLL int idfputc(FILEID id, int ch);
115 extern DLL int idfputs(FILEID id, char *str);
116 extern DLL int printid(FILEID id, int flags);
117 extern DLL int flushid(FILEID id);
118 extern DLL int readid(FILEID id, int flags, char **retptr);
119 extern DLL int getloc(FILEID id, ZVALUE *loc);
120 extern DLL int setloc(FILEID id, ZVALUE zpos);
121 extern DLL int getsize(FILEID id, ZVALUE *size);
122 extern DLL int get_device(FILEID id, ZVALUE *dev);
123 extern DLL int get_inode(FILEID id, ZVALUE *ino);
124 extern DLL FILEID reopenid(FILEID id, char *mode, char *name);
125 extern DLL int closeall(void);
128 extern DLL int flushall(void);
131 extern DLL int idfputstr(FILEID id, char *str);
132 extern DLL int rewindid(FILEID id);
133 extern DLL void rewindall(void);
134 extern DLL ZVALUE zfilesize(FILEID id);
135 extern DLL void showfiles(void);
136 extern DLL int fscanfid(FILEID id, char *fmt, int count, VALUE **vals);
137 extern DLL int scanfstr(char *str, char *fmt, int count, VALUE **vals);
138 extern DLL int ftellid(FILEID id, ZVALUE *res);
139 extern DLL int fseekid(FILEID id, ZVALUE offset, int whence);
140 extern DLL int isattyid(FILEID id);
141 extern DLL int fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res);
142 extern DLL int frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last, ZVALUE *res);
143 extern DLL void showconstants(void);
144 extern DLL void freeconstant(unsigned long);
145 extern DLL void freestringconstant(long);
146 extern DLL void trimconstants(void);
151 extern DLL int openstring(char *str, long num);
152 extern DLL int openterminal(void);
153 extern DLL int opensearchfile(char *name, char *pathlist, char *exten, int reopen_ok);
154 extern DLL char *nextline(void);
155 extern DLL int nextchar(void);
156 extern DLL void reread(void);
157 extern DLL void resetinput(void);
158 extern DLL void setprompt(char *);
159 extern DLL BOOL inputisterminal(void);
160 extern DLL int inputlevel(void);
161 extern DLL long calclevel(void);
162 extern DLL char *inputname(void);
163 extern DLL long linenumber(void);
164 extern DLL void runrcfiles(void);
165 extern DLL void closeinput(void);
170 extern DLL NUMBER *constvalue(unsigned long index);
171 extern DLL long addnumber(char *str);
172 extern DLL long addqconstant(NUMBER *q);
173 extern DLL void initstack(void);
174 extern DLL void getcommands(BOOL toplevel);
175 extern DLL void givehelp(char *type);
176 extern DLL void libcalc_call_me_first(void);
177 extern DLL void libcalc_call_me_last(void);
178 extern DLL BOOL calc_tty(int fd);
179 extern DLL BOOL orig_tty(int fd);
180 extern DLL void showerrors(void);
181 extern DLL char *calc_strdup(CONST char *);
186 extern DLL void initialize(void);
187 extern DLL void reinitialize(void);
188 #if !defined (_WIN32)
189 extern DLL int isatty(int tty); /* TRUE if fd is a tty */
191 extern DLL char *version(void); /* return version string */
192 extern DLL int post_init; /* TRUE => math_error setjmp is ready */
195 * global flags and definitions
197 extern DLL int abortlevel; /* current level of aborts */
198 extern DLL BOOL inputwait; /* TRUE if in a terminal input wait */
199 extern DLL jmp_buf jmpbuf; /* for errors */
201 extern DLL int p_flag; /* TRUE => pipe mode */
202 extern DLL int q_flag; /* TRUE => don't execute rc files */
203 extern DLL int u_flag; /* TRUE => unbuffer stdin and stdout */
204 extern DLL int d_flag; /* TRUE => disable heading, resource_debug */
205 extern DLL int c_flag; /* TRUE => continue after error if permitted */
206 extern DLL int i_flag; /* TRUE => try to go interactive after error */
207 extern DLL int s_flag; /* TRUE => keep args as strings for argv() */
208 extern DLL int stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */
209 extern DLL BOOL abort_now; /* TRUE => try to go interactive */
211 extern DLL int argc_value; /* count of argv[] strings for argv() builtin */
212 extern DLL char **argv_value; /* argv[] strings for argv() builtin */
214 extern DLL char *pager; /* $PAGER or default */
215 extern DLL int stdin_tty; /* TRUE if stdin is a tty */
216 extern DLL int havecommands; /* TRUE if have cmd args) */
217 extern DLL char *program; /* our name */
218 extern DLL char *base_name; /* basename of our name */
219 extern DLL char cmdbuf[]; /* command line expression */
221 extern DLL int abortlevel; /* current level of aborts */
222 extern DLL BOOL inputwait; /* TRUE if in a terminal input wait */
223 extern DLL VALUE *stack; /* execution stack */
224 extern DLL int dumpnames; /* TRUE => dump names rather than indices */
226 extern DLL char *calcpath; /* $CALCPATH or default */
227 extern DLL char *calcrc; /* $CALCRC or default */
228 extern DLL char *calcbindings; /* $CALCBINDINGS or default */
229 extern DLL char *home; /* $HOME or default */
230 extern DLL char *shell; /* $SHELL or default */
231 extern DLL char *program; /* our name (argv[0]) */
233 extern DLL int no_env; /* TRUE (-e) => ignore env vars on startup */
234 extern DLL int errmax; /* if >= 0, error when errcount exceeds errmax */
235 extern DLL int use_old_std; /* TRUE (-O) => use classic configuration */
237 extern DLL int allow_read; /* FALSE => dont open any files for reading */
238 extern DLL int allow_write; /* FALSE => dont open any files for writing */
239 extern DLL int allow_exec; /* FALSE => may not execute any commands */
242 * calc startup and run state
245 RUN_ZERO, /* unknown or unset start state */
246 RUN_BEGIN, /* calc execution starts */
247 RUN_RCFILES, /* rc files being evaluated */
248 RUN_PRE_CMD_ARGS, /* prepare to evaluate cmd args */
249 RUN_CMD_ARGS, /* cmd args being evaluated */
250 RUN_PRE_TOP_LEVEL, /* prepare to start top level activity */
251 RUN_TOP_LEVEL, /* running at top level */
252 RUN_EXIT, /* normal exit from calc */
253 RUN_EXIT_WITH_ERROR /* exit with error */
255 extern DLL run run_state;
256 extern DLL char *run_state_name(run state);
259 * calc version information
261 #define CALC_TITLE "C-style arbitrary precision calculator"
262 extern int calc_major_ver;
263 extern int calc_minor_ver;
264 extern int calc_major_patch;
265 extern int calc_minor_patch;
266 extern char *Copyright;
267 extern DLL char *version(void);
270 #endif /* !__CALC_H__ */