modified: SpatialOmicsCoord.py
[GalaxyCodeBases.git] / c_cpp / etc / calc / calc.h
blob06238e0cefe7616818485b6714d8bd541a34a7c9
1 /*
2 * calc - definitions for calculator program
4 * Copyright (C) 1999-2007 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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * @(#) $Revision: 30.3 $
21 * @(#) $Id: calc.h,v 30.3 2013/08/11 08:41:38 chongo Exp $
22 * @(#) $Source: /usr/local/src/bin/calc/RCS/calc.h,v $
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__)
32 #define __CALC_H__
34 #include <setjmp.h>
35 #if defined(CALC_SRC) /* if we are building from the calc source tree */
36 # include "decl.h"
37 # include "value.h"
38 # include "have_const.h"
39 #else
40 # include <calc/decl.h>
41 # include <calc/value.h>
42 # include <calc/have_const.h>
43 #endif
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 */
65 #else
66 #define LISTCHAR ':' /* char which separates paths in a list */
67 #endif
68 #define MAXCMD 16384 /* maximum length of command invocation */
70 #define SYMBOLSIZE 256 /* maximum symbol name size */
71 #define MAXLABELS 100 /* maximum number of user labels in function */
72 #define MAXSTRING 1024 /* maximum size of string constant */
73 #define MAXSTACK 2048 /* maximum depth of evaluation stack */
74 #define MAXFILES 20 /* maximum number of opened files */
75 #define PROMPT1 "> " /* default normal prompt*/
76 #define PROMPT2 ">> " /* default prompt inside multi-line input */
79 #define TRACE_NORMAL 0x00 /* normal trace flags */
80 #define TRACE_OPCODES 0x01 /* trace every opcode */
81 #define TRACE_NODEBUG 0x02 /* suppress debugging opcodes */
82 #define TRACE_LINKS 0x04 /* display links for real and complex numbers */
83 #define TRACE_FNCODES 0x08 /* display code for newly defined function */
84 #define TRACE_MAX 0x0f /* maximum value for trace flag */
86 #define ABORT_NONE 0 /* abort not needed yet */
87 #define ABORT_STATEMENT 1 /* abort on statement boundary */
88 #define ABORT_OPCODE 2 /* abort on any opcode boundary */
89 #define ABORT_MATH 3 /* abort on any math operation */
90 #define ABORT_NOW 4 /* abort right away */
92 #define ERRMAX 20 /* default errmax value */
93 #define E_OK 0 /* no error */
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) /* must be < 0 */
104 * File I/O routines.
106 E_FUNC FILEID openid(char *name, char *mode);
107 E_FUNC FILEID openpathid(char *name, char *mode, char *pathlist);
108 E_FUNC FILEID indexid(long index);
109 E_FUNC BOOL validid(FILEID id);
110 E_FUNC BOOL errorid(FILEID id);
111 E_FUNC BOOL eofid(FILEID id);
112 E_FUNC int closeid(FILEID id);
113 E_FUNC int getcharid(FILEID id);
114 E_FUNC int idprintf(FILEID id, char *fmt, int count, VALUE **vals);
115 E_FUNC int idfputc(FILEID id, int ch);
116 E_FUNC int idfputs(FILEID id, STRING *str);
117 E_FUNC int printid(FILEID id, int flags);
118 E_FUNC int flushid(FILEID id);
119 E_FUNC int readid(FILEID id, int flags, STRING **retptr);
120 E_FUNC int getloc(FILEID id, ZVALUE *loc);
121 E_FUNC int setloc(FILEID id, ZVALUE zpos);
122 E_FUNC int getsize(FILEID id, ZVALUE *size);
123 E_FUNC int get_device(FILEID id, ZVALUE *dev);
124 E_FUNC int get_inode(FILEID id, ZVALUE *ino);
125 E_FUNC FILEID reopenid(FILEID id, char *mode, char *name);
126 E_FUNC int closeall(void);
128 #if !defined(_WIN32)
129 E_FUNC int flushall(void);
130 #endif
132 E_FUNC int idfputstr(FILEID id, char *str);
133 E_FUNC int rewindid(FILEID id);
134 E_FUNC void rewindall(void);
135 E_FUNC ZVALUE zfilesize(FILEID id);
136 E_FUNC void showfiles(void);
137 E_FUNC int fscanfid(FILEID id, char *fmt, int count, VALUE **vals);
138 E_FUNC int scanfstr(char *str, char *fmt, int count, VALUE **vals);
139 E_FUNC int ftellid(FILEID id, ZVALUE *res);
140 E_FUNC int fseekid(FILEID id, ZVALUE offset, int whence);
141 E_FUNC int isattyid(FILEID id);
142 E_FUNC int fsearch(FILEID id, char *str, ZVALUE start, ZVALUE end, ZVALUE *res);
143 E_FUNC int frsearch(FILEID id, char *str, ZVALUE first, ZVALUE last,
144 ZVALUE *res);
145 E_FUNC void showconstants(void);
146 E_FUNC void freeconstant(unsigned long);
147 E_FUNC void freestringconstant(long);
148 E_FUNC void trimconstants(void);
151 * Input routines.
153 E_FUNC int openstring(char *str, size_t num);
154 E_FUNC int openterminal(void);
155 E_FUNC int opensearchfile(char *name, char *pathlist, char *exten,
156 int reopen_ok);
157 E_FUNC char *nextline(void);
158 E_FUNC int nextchar(void);
159 E_FUNC void reread(void);
160 E_FUNC void resetinput(void);
161 E_FUNC void setprompt(char *);
162 E_FUNC BOOL inputisterminal(void);
163 E_FUNC int inputlevel(void);
164 E_FUNC long calclevel(void);
165 E_FUNC char *inputname(void);
166 E_FUNC long linenumber(void);
167 E_FUNC void runrcfiles(void);
168 E_FUNC void closeinput(void);
171 * Other routines.
173 E_FUNC NUMBER *constvalue(unsigned long index);
174 E_FUNC long addnumber(char *str);
175 E_FUNC long addqconstant(NUMBER *q);
176 E_FUNC void initstack(void);
177 E_FUNC void getcommands(BOOL toplevel);
178 E_FUNC void givehelp(char *type);
179 E_FUNC void libcalc_call_me_first(void);
180 E_FUNC void libcalc_call_me_last(void);
181 E_FUNC BOOL calc_tty(int fd);
182 E_FUNC BOOL orig_tty(int fd);
183 E_FUNC void showerrors(void);
184 E_FUNC char *calc_strdup(CONST char *);
187 * Initialization
189 E_FUNC void initialize(void);
190 E_FUNC void reinitialize(void);
191 #if !defined (_WIN32)
192 E_FUNC int isatty(int tty); /* TRUE if fd is a tty */
193 #endif
194 E_FUNC char *version(void); /* return version string */
197 * global flags and definitions
199 EXTERN int abortlevel; /* current level of aborts */
200 EXTERN BOOL inputwait; /* TRUE if in a terminal input wait */
202 EXTERN int p_flag; /* TRUE => pipe mode */
203 EXTERN int q_flag; /* TRUE => don't execute rc files */
204 EXTERN int u_flag; /* TRUE => unbuffer stdin and stdout */
205 EXTERN int d_flag; /* TRUE => disable heading, resource_debug */
206 EXTERN int c_flag; /* TRUE => continue after error if permitted */
207 EXTERN int i_flag; /* TRUE => try to go interactive after error */
208 E_FUNC int s_flag; /* TRUE => keep args as strings for argv() */
209 EXTERN long stoponerror; /* >0 => stop, <0 => continue, ==0 => use -c */
210 EXTERN BOOL abort_now; /* TRUE => try to go interactive */
212 E_FUNC int argc_value; /* count of argv[] strings for argv() builtin */
213 E_FUNC char **argv_value; /* argv[] strings for argv() builtin */
215 EXTERN char *pager; /* $PAGER or default */
216 EXTERN int stdin_tty; /* TRUE if stdin is a tty */
217 EXTERN int havecommands; /* TRUE if have cmd args) */
218 EXTERN char *program; /* our name */
219 EXTERN char *base_name; /* basename of our name */
220 EXTERN char cmdbuf[]; /* command line expression */
222 EXTERN int abortlevel; /* current level of aborts */
223 EXTERN BOOL inputwait; /* TRUE if in a terminal input wait */
224 EXTERN VALUE *stack; /* execution stack */
225 EXTERN int dumpnames; /* TRUE => dump names rather than indices */
227 EXTERN char *calcpath; /* $CALCPATH or default */
228 EXTERN char *calcrc; /* $CALCRC or default */
229 EXTERN char *calcbindings; /* $CALCBINDINGS or default */
230 EXTERN char *home; /* $HOME or default */
231 EXTERN char *shell; /* $SHELL or default */
233 EXTERN int no_env; /* TRUE (-e) => ignore env vars on startup */
234 EXTERN long errmax; /* if >= 0, error when errcount exceeds errmax */
235 EXTERN int use_old_std; /* TRUE (-O) => use classic configuration */
237 EXTERN int allow_read; /* FALSE => dont open any files for reading */
238 EXTERN int allow_write; /* FALSE => dont open any files for writing */
239 EXTERN int allow_exec; /* FALSE => may not execute any commands */
242 * calc startup and run state
244 typedef enum {
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 */
254 } run;
255 EXTERN run run_state;
256 E_FUNC 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 E_FUNC char *version(void);
270 #endif /* !__CALC_H__ */