-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.c
227 lines (177 loc) · 4.91 KB
/
test1.c
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define LUA_LIB
#define LUA_SC "SC210968*"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "rpsc.h"
#include "xlsx.h"
#include "Parser.h"
#include "Lexer.h"
#include "sheet.h"
int growtbl(struct Sheet * sh,int rowcol, int toprow, int topcol);
// reference a sheet in a formula
int main () {
// this could serve to load default functions (AVG, COUNT) from a lua script
lua_State *L;
struct Ent *e1;
L = luaL_newstate();
int a;
slab_allocator_init();
ExpressionInit();
init_lib();
init_plugin();
load_plugin("html");
load_plugin("xlsx");
struct roman * p = (struct roman *) malloc(sizeof(struct roman));
struct Ent *tl;
read_plugin(p,"test.html","html");
read_plugin(p,"example/test.xlsx","xlsx");
/*
p->name=NULL;
p->open=0; // we are not loading a file here..
p->first_sh=p->last_sh=p->cur_sh=0;
p->cache=0;
p->cache_nr=0;
// create a sheet
struct Sheet * sh = new_sheet(p, "sales 1");
growtbl(sh, GROWNEW, 0, 0);
p->cur_sh = sh;
// set a value of a cell
struct Ent * t = lookat(p->cur_sh, 0, 0);
t->flag |= VAL;
t->val = 4;
// create a sheet
struct Sheet * sh1 = new_sheet(p, "sales 2");
growtbl(sh1, GROWNEW, 0, 0);
p->cur_sh = sh1;
// set a value of a cell
struct Ent * tl = lookat(p->cur_sh, 0, 0);
tl->flag |= VAL;
tl->val = 5;
// add a formula to other cell
t = lookat(p->cur_sh, 1, 0);
t->formula= "'sales 1'!A0 + 'sales 2'!A0 + 2 + 1";
char * ptr = t->formula;
t->exp = getAST(ptr, p);
t->flag |= VAL | RP_FORMULA;
t->val = t->exp->value;
*/
//open_xlsx(p, "example/test.xlsx","");
char **names;
int cnt;
Get_sheets(p,&cnt,&names);
for(a=0;a<1000000;a++)
{
// calc
recalc(p);
tl= lookat(p->cur_sh,2,0);
tl->val=(double)a;
// show results
//struct Ent * e1 = lookat(sh1, 1, 0);
//e1 = lookat(Search_sheet(p, "Roman"), 14, 0);
}
e1 = lookat(Search_sheet(p, "Roman"), 14, 0);
printf("result :: %f !!\n", e1->val);
e1 = lookat(Search_sheet(p, "Roman"), 13, 2);
printf("result :: %f !!\n", e1->val);
write_plugin(p,"test123.html","html");
p->open=0;
delete_sheet(p,Search_sheet(p,"Roman"));
return 0;
}
// simple formula
/*
int main () {
// this will serve to load with lua default operations
lua_State *L;
L = luaL_newstate();
int a;
struct roman * p = (struct roman *) malloc(sizeof(struct roman));
p->name=NULL;
p->open=0; // we are not loading a file here..
p->first_sh=p->last_sh=p->cur_sh=0;
p->cache=0;
p->cache_nr=0;
struct Sheet * sh = new_sheet(p, "Sheet 1");
growtbl(sh, GROWNEW, 0, 0);
p->cur_sh = sh;
struct Ent * t = lookat(p->cur_sh, 0, 0);
t->flag |= VAL;
t->val = 1;
t = lookat(p->cur_sh, 1, 0);
t->flag |= VAL;
t->val = 2;
// add a formula
t = lookat(p->cur_sh, 2, 0);
t->formula= "A0+A1";
char * ptr = t->formula;
t->exp=getAST(ptr, p);
t->flag |= VAL | RP_FORMULA;
t->val=t->exp->value;
recalc(p);
struct Ent * e1 = lookat(p->cur_sh, 0, 0);
printf("value A0: %f !!\n", e1->val);
struct Ent * e2 = lookat(p->cur_sh, 1, 0);
printf("value A1: %f !!\n", e2->val);
struct Ent * e3 = lookat(p->cur_sh, 2, 0);
printf("value A2: %f !!\n", e3->val);
p->open=0;
return 0;
}
*/
/* test main
// loading test.xlsx
int main () {
lua_State *L;
L = luaL_newstate();
const char *filename = "test.xlsx";
struct roman *p = (struct roman *)lua_newuserdata(L, sizeof(struct roman));
luaL_setmetatable(L, LUA_SC);
p->name=strdup(filename);
p->open=1;
p->first_sh=p->last_sh=p->cur_sh=0;
p->cache=0;
p->cache_nr=0;
printf("%s %s %d\n", __FUNCTION__, p->name, p->open);
struct Sheet *sh;
char * name = "Tabelle1";
//p= ((struct roman *)luaL_checkudata(L, 1, LUA_SC));
printf("%s %s %s\n", __FUNCTION__, p->name, name);
open_xlsx(p, filename, "");
int i=1;
//p= ((struct roman *)luaL_checkudata(L, 1, LUA_SC));
printf("%s %s\n",__FUNCTION__,p->name);
if(p->first_sh == 0) {
lua_pushnil(L);
lua_pushstring(L, "No Sheets");
return 2;
}
lua_newtable(L);
for(sh=p->first_sh;sh !=0; sh=sh->next) {
lua_pushnumber(L, i++);
lua_pushstring(L, sh->name);
lua_settable(L, -3);
}
//name = luaL_checkstring(L, 2);
//p= ((struct roman *)luaL_checkudata(L, 1, LUA_SC));
printf("3:%s %s %s\n",__FUNCTION__,p->name,name);
sh=Search_sheet(p, name);
p->cur_sh=sh;
recalc(p);
int r = 4, c = 0;
struct Ent ** pp = ATBL(p->cur_sh,p->cur_sh->tbl, r, c);
struct Ent * e = *pp;
if (e == 0) printf("null?! \n");
printf("getnum2\n", e->val);
if (e->flag & VAL) {
printf("value: %f !!\n", e->val);
}
p->open=0;
return 0;
}
*/