1 #ifndef SHEET_H
2 #define SHEET_H
3 
4 #include "scanner.h"
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 #define SHEET(s,x,y,z) (*(s->sheet+(x)*s->dimz*s->dimy+(y)*s->dimz+(z)))
11 
12 typedef enum { LEFT=0, RIGHT=1, CENTER=2, AUTOADJUST=3 } Adjust;
13 
14 typedef enum { IN_X, IN_Y, IN_Z } Direction;
15 
16 /* must be a prime */
17 #define LABEL_CACHE 29
18 
19 #define ASCENDING  001
20 
21 typedef struct
22 {
23   int x;
24   int y;
25   int z;
26   int sortkey; /* OR-ed value of the above constants */
27 } Sortkey;
28 
29 typedef struct
30 {
31   Token **contents;
32   Token **ccontents;
33   char *label;
34   Token value;
35   Token resvalue;
36   Adjust adjust;
37   int precision;
38   unsigned int updated:1;
39   unsigned int shadowed:1;
40   unsigned int scientific:1;
41   unsigned int locked:1;
42   unsigned int transparent:1;
43   unsigned int ignored:1;
44   unsigned int clock_t0:1;
45   unsigned int clock_t1:1;
46   unsigned int clock_t2:1;
47   unsigned int bold:1;
48   unsigned int underline:1;
49 } Cell;
50 
51 struct Label
52 {
53   const char *label;
54   int x,y,z;
55   struct Label *next;
56 };
57 
58 typedef struct
59 {
60   struct Label *labelcache[LABEL_CACHE];
61   int curx, cury, curz;
62   int mark1x, mark1y, mark1z;
63   int mark2x, mark2y, mark2z;
64   int marking;
65   int offx, offy;
66   Cell **sheet;
67   int *column;
68   int dimx, dimy, dimz;
69   int orix, oriy, maxx, maxy;
70   int width;
71   char *name;
72   unsigned int changed:1;
73   unsigned int moveonly:1;
74   unsigned int clk:1;
75   void *display;
76 } Sheet;
77 
78 extern Sheet *upd_sheet;
79 extern int upd_x;
80 extern int upd_y;
81 extern int upd_z;
82 extern int max_eval;
83 
84 void resize(Sheet *sheet, int x, int y, int z);
85 void initcell(Sheet *sheet, int x, int y, int z);
86 void cachelabels(Sheet *sheet);
87 void freesheet(Sheet *sheet, int all);
88 void forceupdate(Sheet *sheet);
89 void freecell(Sheet *sheet, int x, int y, int z);
90 int columnwidth(Sheet *sheet, int x, int z);
91 void setwidth(Sheet *sheet, int x, int z, int width);
92 int cellwidth(Sheet *sheet, int x, int y, int z);
93 void putcont(Sheet *sheet, int x, int y, int z, Token **t, int c);
94 Token **getcont(Sheet *sheet, int x, int y, int z, int c);
95 Token getvalue(Sheet *sheet, int x, int y, int z);
96 void update(Sheet *sheet);
97 char *geterror(Sheet *sheet, int x, int y, int z);
98 void printvalue(char *s, size_t size, size_t chars, int quote, int scientific, int precision, Sheet *sheet, int x, int y, int z);
99 Adjust getadjust(Sheet *sheet, int x, int y, int z);
100 void setadjust(Sheet *sheet, int x, int y, int z, Adjust adjust);
101 void shadow(Sheet *sheet, int x, int y, int z, int yep);
102 int shadowed(Sheet *sheet, int x, int y, int z);
103 void bold(Sheet *sheet, int x, int y, int z, int yep);
104 int isbold(Sheet *sheet, int x, int y, int z);
105 void underline(Sheet *sheet, int x, int y, int z, int yep);
106 int underlined(Sheet *sheet, int x, int y, int z);
107 void lockcell(Sheet *sheet, int x, int y, int z, int yep);
108 int locked(Sheet *sheet, int x, int y, int z);
109 int transparent(Sheet *sheet, int x, int y, int z);
110 void maketrans(Sheet *sheet, int x, int y, int z, int yep);
111 void igncell(Sheet *sheet, int x, int y, int z, int yep);
112 int ignored(Sheet *sheet, int x, int y, int z);
113 void clk(Sheet *sheet, int x, int y, int z);
114 void setscientific(Sheet *sheet, int x, int y, int z, int yep);
115 int getscientific(Sheet *sheet, int x, int y, int z);
116 void setprecision(Sheet *sheet, int x, int y, int z, int precision);
117 int getprecision(Sheet *sheet, int x, int y, int z);
118 const char *getlabel(Sheet *sheet, int x, int y, int z);
119 void setlabel(Sheet *sheet, int x, int y, int z, const char *buf, int update);
120 Token findlabel(Sheet *sheet, const char *label);
121 void relabel(Sheet *sheet, const char *oldlabel, const char *newlabel, int x, int y, int z);
122 const char *savexdr(Sheet *sheet, const char *name, unsigned int *count);
123 const char *savetbl(Sheet *sheet, const char *name, int body, int x1, int y1, int z1, int x2, int y2, int z2, unsigned int *count);
124 const char *savetext(Sheet *sheet, const char *name, int x1, int y1, int z1, int x2, int y2, int z2, unsigned int *count);
125 const char *savecsv(Sheet *sheet, const char *name, char sep, int x1, int y1, int z1, int x2, int y2, int z2, unsigned int *count);
126 const char *saveport(Sheet *sheet, const char *name, unsigned int *count);
127 const char *loadxdr(Sheet *sheet, const char *name);
128 const char *loadport(Sheet *sheet, const char *name);
129 const char *loadcsv(Sheet *sheet, const char *name);
130 void insertcube(Sheet *sheet, int x1, int y1, int z1, int x2, int y2, int z2, Direction ins);
131 void deletecube(Sheet *sheet, int x1, int y1, int z1, int x2, int y2, int z2, Direction ins);
132 void moveblock(Sheet *sheet, int x1, int y1, int z1, int x2, int y2, int z2, int x3, int y3, int z3, int copy);
133 const char *sortblock(Sheet *sheet, int x1, int y1, int z1, int x2, int y2, int z2, Direction dir, Sortkey *sk, size_t sklen);
134 void mirrorblock(Sheet *sheet, int x1, int y1, int z1, int x2, int y2, int z2, Direction dir);
135 
136 #ifdef __cplusplus
137 }
138 #endif
139 
140 #endif
141