xref: /original-bsd/contrib/sc/sc.h (revision c8df706a)
1 /*	SC	A Table Calculator
2  *		Common definitions
3  *
4  *		original by James Gosling, September 1982
5  *		modified by Mark Weiser and Bruce Israel,
6  *			University of Maryland
7  *		R. Bond  12/86
8  *		More mods by Alan Silverstein, 3-4/88, see list of changes.
9  *		$Revision: 6.8 $
10  *
11  */
12 
13 #define	ATBL(tbl, row, col)	(*(tbl + row) + (col))
14 
15 #define MINROWS 40	/* minimum size at startup */
16 #define MINCOLS 20
17 #define	ABSMAXCOLS 702	/* absolute cols: ZZ (base 26) */
18 #define RESCOL 4	/* columns reserved for row numbers */
19 #define RESROW 3 /* rows reserved for prompt, error, and column numbers */
20 #define DEFWIDTH 10	/* Default column width and precision */
21 #define DEFPREC   2
22 #define HISTLEN  10	/* Number of history entries for vi emulation */
23 #define error (void)move(1,0), (void)clrtoeol(), (void) printw
24 #define	FBUFLEN	1024	/* buffer size for a single field */
25 #define	PATHLEN	1024	/* maximum path length */
26 
27 #ifndef A_CHARTEXT	/* Should be defined in curses.h */
28 #ifdef INTERNATIONAL
29 #define A_CHARTEXT 0xff
30 #else
31 #define A_CHARTEXT 0x7f
32 #endif
33 #endif
34 
35 #if (defined(BSD42) || defined(BSD43)) && !defined(strrchr)
36 #define strrchr rindex
37 #endif
38 
39 struct ent_ptr {
40     int vf;
41     struct ent *vp;
42 };
43 
44 struct range_s {
45 	struct ent_ptr left, right;
46 };
47 
48 /*
49  * Some not too obvious things about the flags:
50  *    is_valid means there is a valid number in v.
51  *    label set means it points to a valid constant string.
52  *    is_strexpr set means expr yields a string expression.
53  *    If is_strexpr is not set, and expr points to an expression tree, the
54  *        expression yields a numeric expression.
55  *    So, either v or label can be set to a constant.
56  *        Either (but not both at the same time) can be set from an expression.
57  */
58 
59 #define VALID_CELL(p, r, c) ((p = *ATBL(tbl, r, c)) && \
60 			     ((p->flags & is_valid) || p->label))
61 
62 struct ent {
63     double v;
64     char *label;
65     struct enode *expr;
66     short flags;
67     short row, col;
68     struct ent *next;		/* next deleted ent */
69     struct ent *evnext;		/* next ent w/ a object to eval */
70     struct ent *evprev;		/* prev ent w/ a object to eval */
71 };
72 
73 struct range {
74     struct ent_ptr r_left, r_right;
75     char *r_name;
76     struct range *r_next, *r_prev;
77     int r_is_range;
78 };
79 
80 #define FIX_ROW 1
81 #define FIX_COL 2
82 
83 struct enode {
84     int op;
85     union {
86 	double k;
87 	struct ent_ptr v;
88 	struct range_s r;
89 	char *s;
90 	struct {
91 	    struct enode *left, *right;
92 	} o;
93     } e;
94 };
95 
96 /* op values */
97 #define O_VAR 'v'
98 #define O_CONST 'k'
99 #define O_SCONST '$'
100 #define REDUCE 0200	/* Or'ed into OP if operand is a range */
101 
102 #define OP_BASE 256
103 #define ACOS OP_BASE + 0
104 #define ASIN OP_BASE + 1
105 #define ATAN OP_BASE + 2
106 #define CEIL OP_BASE + 3
107 #define COS OP_BASE + 4
108 #define EXP OP_BASE + 5
109 #define FABS OP_BASE + 6
110 #define FLOOR OP_BASE + 7
111 #define HYPOT OP_BASE + 8
112 #define LOG OP_BASE + 9
113 #define LOG10 OP_BASE + 10
114 #define POW OP_BASE + 11
115 #define SIN OP_BASE + 12
116 #define SQRT OP_BASE + 13
117 #define TAN OP_BASE + 14
118 #define DTR OP_BASE + 15
119 #define RTD OP_BASE + 16
120 #define MIN OP_BASE + 17
121 #define MAX OP_BASE + 18
122 #define RND OP_BASE + 19
123 #define HOUR OP_BASE + 20
124 #define MINUTE OP_BASE + 21
125 #define SECOND OP_BASE + 22
126 #define MONTH OP_BASE + 23
127 #define DAY OP_BASE + 24
128 #define YEAR OP_BASE + 25
129 #define NOW OP_BASE + 26
130 #define DATE OP_BASE + 27
131 #define FMT OP_BASE + 28
132 #define SUBSTR OP_BASE + 29
133 #define STON OP_BASE + 30
134 #define EQS OP_BASE + 31
135 #define EXT OP_BASE + 32
136 #define ELIST OP_BASE + 33	/* List of expressions */
137 #define LMAX  OP_BASE + 34
138 #define LMIN  OP_BASE + 35
139 #define NVAL OP_BASE + 36
140 #define SVAL OP_BASE + 37
141 #define PV OP_BASE + 38
142 #define FV OP_BASE + 39
143 #define PMT OP_BASE + 40
144 #define STINDEX OP_BASE + 41
145 #define LOOKUP OP_BASE + 42
146 #define ATAN2 OP_BASE + 43
147 #define INDEX OP_BASE + 44
148 #define DTS OP_BASE + 45
149 #define TTS OP_BASE + 46
150 #define ABS OP_BASE + 47
151 #define HLOOKUP OP_BASE + 48
152 #define VLOOKUP OP_BASE + 49
153 #define ROUND OP_BASE + 50
154 #define IF OP_BASE + 51
155 
156 /* flag values */
157 #define is_valid     0001
158 #define is_changed   0002
159 #define is_strexpr   0004
160 #define is_leftflush 0010
161 #define is_deleted   0020
162 
163 #define ctl(c) ((c)&037)
164 #define ESC 033
165 #define DEL 0177
166 
167 #define BYCOLS 1
168 #define BYROWS 2
169 #define BYGRAPH 4		/* Future */
170 
171 #define	TBL	1		/* tblprint style output for 'tbl' */
172 #define	LATEX	2		/* tblprint style output for 'LaTeX' */
173 #define	TEX	3		/* tblprint style output for 'TeX' */
174 
175 /* Types for etype() */
176 
177 #define NUM	1
178 #define STR	2
179 
180 #define	GROWAMT	10	/* default minimum amount to grow */
181 
182 #define	GROWNEW		1	/* first time table */
183 #define	GROWROW		2	/* add rows */
184 #define	GROWCOL		3
185 #define	GROWBOTH	4
186 extern	struct ent ***tbl;
187 
188 extern	char curfile[];
189 extern	int strow, stcol;
190 extern	int currow, curcol;
191 extern	int savedrow, savedcol;
192 extern	int FullUpdate;
193 extern	int maxrow, maxcol;
194 extern	int maxrows, maxcols;	/* # cells currently allocated */
195 extern	int *fwidth;
196 extern	int *precision;
197 extern	char *col_hidden;
198 extern	char *row_hidden;
199 extern	char line[FBUFLEN];
200 extern	int linelim;
201 extern	int changed;
202 extern	struct ent *to_fix;
203 extern	int showsc, showsr;
204 
205 extern	FILE *openout();
206 extern	char *coltoa();
207 extern	char *findhome();
208 extern	char *r_name();
209 extern	char *seval();
210 extern	char *strrchr();
211 extern	char *v_name();
212 extern	char *xmalloc();
213 extern	double dolookup();
214 extern	double eval();
215 extern	int RealEvalAll();
216 extern	int are_ranges();
217 extern	int atocol();
218 extern	int constant();
219 extern	int etype();
220 extern	int fork();
221 extern	int get_rcqual();
222 extern	int growtbl();
223 extern	int nmgetch();
224 extern	int writefile();
225 extern	int xfree();
226 extern	int yn_ask();
227 extern	struct enode *copye();
228 extern	struct enode *new();
229 extern	struct enode *new_const();
230 extern	struct enode *new_range();
231 extern	struct enode *new_str();
232 extern	struct enode *new_var();
233 extern	struct ent *lookat();
234 extern	struct range *find_range();
235 extern	void EvalAll();
236 extern	void Evalall();
237 extern	void RealEvalOne();
238 extern	void backcol();
239 extern	void backrow();
240 extern	void checkbounds();
241 extern	void clearent();
242 extern	void closecol();
243 extern	void closeout();
244 extern	void closerow();
245 extern	void colshow_op();
246 extern	void colvalueize();
247 extern	void colvalueize();
248 extern	void copy();
249 extern	void copyent();
250 extern	void copyrtv();
251 extern	void decompile();
252 extern	void deletecol();
253 extern	void deleterow();
254 extern	void deraw();
255 extern	void doend();
256 extern	void doformat();
257 extern	void dupcol();
258 extern	void duprow();
259 extern	void editexp();
260 extern	void edits();
261 extern	void editv();
262 extern	void efree();
263 extern	void erase_area();
264 extern	void erasedb();
265 extern	void eraser();
266 extern	void fill();
267 extern	void flush_saved();
268 extern	void forwcol();
269 extern	void forwrow();
270 extern	void free_ent();
271 extern	void go_last();
272 extern	void goraw();
273 extern	void help();
274 extern	void hide_col();
275 extern	void hide_row();
276 extern	void hidecol();
277 extern	void hiderow();
278 extern	void index_arg();
279 extern	void ins_string();
280 extern	void insert_mode();
281 extern	void insertcol();
282 extern	void insertrow();
283 extern	void kbd_again();
284 extern	void label();
285 extern	void let();
286 extern	void list_arg();
287 extern	void list_range();
288 extern	void moveto();
289 extern	void num_search();
290 extern	void one_arg();
291 extern	void opencol();
292 extern	void openrow();
293 extern	void printfile();
294 extern	void pullcells();
295 extern	void range_arg();
296 extern	void readfile();
297 extern	void repaint();
298 extern	void resetkbd();
299 extern	void rowshow_op();
300 extern	void rowvalueize();
301 extern	void setauto();
302 extern	void setiterations();
303 extern	void setorder();
304 extern	void showcol();
305 extern	void showdr();
306 extern	void showrow();
307 extern	void showstring();
308 extern	void signals();
309 extern	void slet();
310 extern	void startshow();
311 extern	void str_search();
312 extern	void sync_refs();
313 extern	void syncref();
314 extern	void tblprintfile();
315 extern	void three_arg();
316 extern	void two_arg();
317 extern	void two_arg_index();
318 extern	void update();
319 extern	void valueize_area();
320 extern	void write_fd();
321 extern	void write_line();
322 extern	void yyerror();
323 #ifdef DOBACKUPS
324 extern	int backup_file();
325 #endif
326 
327 extern	int modflg;
328 extern	int Crypt;
329 extern	char *mdir;
330 extern	double prescale;
331 extern	int extfunc;
332 extern	int propagation;
333 extern	int calc_order;
334 extern	int autocalc;
335 extern	int numeric;
336 extern	int showcell;
337 extern	int showtop;
338 extern	int loading;
339 extern	int getrcqual;
340 extern	int tbl_style;
341 extern	char *progname;
342 
343 #if BSD42 || SYSIII
344 
345 #ifndef cbreak
346 #define	cbreak		crmode
347 #define	nocbreak	nocrmode
348 #endif
349 
350 #endif
351