-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpsc.h
183 lines (142 loc) · 4.16 KB
/
rpsc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include "expr.h"
#include "queue.h"
#include "slab.h"
#define NEW 1
#define HASH_NR 64
struct Ent {
double val;
char * label;
char * formula;
SExpression * exp;
short flag;
short col;
short row;
struct Ent *n_hash;
};
#define RP_FORMULA 1
#define VAL 2
#define RP_LABEL 4
struct Sheet {
struct Ent *** tbl;
void **hash;
int nr_hash;
char * name;
int col, row;
int ccol , crow;
short flags;
int maxcol, maxrow;
struct Sheet * next;
struct Sheet * prev;
struct Objs_cache cache_ent;
};
#define HASH(row,col) (((row*65537)+col) % HASH_NR)
struct roman
{
char * name;
int open;
struct Sheet * first_sh;
struct Sheet * last_sh;
struct Sheet * cur_sh;
struct Ent ** cache;
int cache_nr;
int id; //session_id
struct roman * next; // to chain to other roman structs..
};
#define PLUG_IN 1
#define PLUG_OUT 2
#define PLUG_FUNC 2
struct plugin
{
char *name; //plugin name
int type; //Plugin Type can be ored
char **ending; //for auto detection of file .xlsx .html .sc
struct plugin *next;
int (*init)(struct plugin *); // called when plugin loaded, for example to initial function calls
int (*read)(struct roman *, char *); //
int (*write)(struct roman *, char *); //
struct Ent* (*lookat)(struct Sheet * , int , int );
struct Sheet* (*new_sheet) (struct roman * , char * );
struct Sheet * (*search_sheet)(struct roman *doc, char *name);
SExpression * (*getAST)(const char * expr, struct roman * p) ;
void (*deleteExpression)(SExpression *b);
};
#define FUNC_RANGE 1 /* Range Function */
#define FUNC_MATH1 2 /* Math function 1 arg */
#define FUNC_MATH2 3 /* Math function 2 arg */
#define FUNC_STR 4 /* String function */
struct Functions {
const char * name;
double (*func) (struct roman * p, int argc, const char ** argv);
int type;
struct Functions * next;
};
#if OLD
#define ATBL(sh, tbl, row, col) (*(tbl + row) + (col))
#else
#define ATBL(sh,tbl,row,col) atbl(sh,tbl,row,col)
struct Ent ** atbl(struct Sheet *sh, struct Ent ***tbl, int row, int col) ;
#endif
#define GROWNEW 1 /* first time table */
#define GROWROW 2 /* add rows */
#define GROWCOL 3 /* add columns */
#define GROWBOTH 4 /* grow both */
#define LINES 16384
#define RESROW 1
#define MINROWS 2024
#define COLS 1024
#define MINCOLS 2024
#define DEFWIDTH 8
#define GROWAMT 16
#define ABSMAXCOLS 8192
#define rescol 1
#define TRUE 1
#define FALSE 0
#ifndef NULL
#define NULL (0)
#endif
#define BOOL int
#define INSERT(NEW, FIRST,LAST,NEXT,PREV) \
do { \
if(FIRST == 0) FIRST=LAST=NEW; \
else { \
NEW->PREV=LAST; \
NEW->NEXT=LAST->NEXT; \
LAST->NEXT=NEW; \
if(NEW->NEXT !=NULL) NEW->NEXT->PREV=NEW; \
LAST=NEW; \
}\
} while(0)
#define INSERT_BEFORE(NEW, FIRST,LAST,NEXT,PREV) \
do { \
if(FIRST == 0) FIRST=LAST=NEW; \
else { \
NEW->NEXT=FIRST; \
NEW->PREV=FIRST->PREV;\
FIRST->PREV=NEW; \
FIRST=NEW; \
}\
} while(0)
#define REMOVE(ELEM,FIRST,LAST,NEXT,PREV) \
do { \
if(ELEM==FIRST) { \
FIRST=ELEM->NEXT; \
if (FIRST == 0) LAST=0; \
else ELEM->NEXT->PREV=0; \
} else { \
ELEM->PREV->NEXT=ELEM->NEXT; \
if (ELEM->NEXT ==0) LAST=ELEM->PREV; \
else ELEM->NEXT->PREV=ELEM->PREV; } \
} while(0)
void add_function(char * name, double (*funct) (struct roman *, int, char **), int type);
void * search_func(char * name,int * type);
extern struct Ent * lookat(struct Sheet * sh, int row, int col);
extern struct Sheet * new_sheet(struct roman * doc , char * name);
extern struct Sheet * Search_sheet(struct roman * doc, char * name);
extern int Get_sheets( struct roman *doc, int *len, char **name);
extern void recalc();
extern void export(struct roman * p, FILE *pt ,char * start, char * end, char * start_col, char * end_col, char * start_row, char * end_row);
SExpression * parse(char ** ptr);
SExpression * getAST(const char * expr, struct roman * p);