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