2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
|
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
case OP_CONTROL: if(i==control_class) goto found; break;
}
continue;
found: classes[i]->order=j; break;
}
}
}
static int level_table_code(int ptr,Hash*hash) {
int flowdepth=0;
Uint16 flowptr[64];
int x;
for(;;) {
if(ptr>=0xFFFA) ParseError("Out of memory\n");
nxttok();
if(Tokenf(TF_MACRO)) ParseError("Unexpected macro\n");
if(tokent==TF_CLOSE) {
ll_code[ptr++]=OP_RET;
return ptr;
} else if(Tokenf(TF_NAME)) {
switch(tokenv) {
case OP_IF:
if(flowdepth==64) ParseError("Too much flow control nesting\n");
ll_code[ptr++]=OP_IF;
flowptr[flowdepth++]=ptr++;
break;
case OP_ELSE:
if(!flowdepth) ParseError("Flow control mismatch\n");
ll_code[flowptr[flowdepth-1]]=ptr+2;
ll_code[ptr++]=OP_GOTO;
flowptr[flowdepth-1]=ptr++;
break;
case OP_THEN:
if(!flowdepth) ParseError("Flow control mismatch\n");
ll_code[flowptr[--flowdepth]]=ptr;
break;
case OP_STRING:
ll_code[ptr++]=OP_STRING;
ll_code[ptr++]=pool_string(tokenstr);
break;
case OP_LOCAL:
x=look_hash(hash,LOCAL_HASH_SIZE,0x200,0x23F,ll_naggregate+0x200,"aggregates")?:(ll_naggregate++)+0x200;
ll_code[ptr++]=OP_LOCAL;
ll_code[ptr++]=x-0x200;
break;
case OP_USERFLAG:
if(Tokenf(TF_COMMA|TF_EQUAL)) ParseError("Invalid instruction token\n");
x=look_hash(glohash,HASH_SIZE,0x1000,0x10FF,0,"user flags");
if(!x) ParseError("User flag ^%s not defined\n",tokenstr);
ll_code[ptr++]=OP_USERFLAG;
ll_code[ptr++]=x;
break;
default:
if(Tokenf(TF_ABNORMAL)) ParseError("Invalid instruction token\n");
ll_code[ptr++]=tokenv;
}
} else {
ParseError("Invalid instruction token\n");
}
}
}
static void level_table_definition(void) {
sqlite3_str*str=sqlite3_str_new(0);
unsigned char buf[0x2000];
Hash*hash=calloc(LOCAL_HASH_SIZE,sizeof(Hash));
DataColumn*datac=calloc(0x41,sizeof(DataColumn));
DataColumn*aggrc=calloc(0x41,sizeof(DataColumn));
DisplayColumn*dispc=calloc(0x41,sizeof(DisplayColumn));
int ptr=0;
int last=0;
int i;
if(ll_naggregate || ll_ndata || ll_ndisp || ll_head || ll_code) ParseError("LevelTable block is already defined\n");
ll_code=malloc(0x10000*sizeof(Uint16));
if(!hash || !ll_code || !datac || !aggrc || !dispc) fatal("Allocation failed\n");
sqlite3_str_appendchar(str,1,0xB3);
for(;;) {
nxttok();
if(tokent==TF_EOF) ParseError("Unexpected end of file\n");
if(tokent==TF_CLOSE) break;
if(tokent!=TF_OPEN) ParseError("Expected ( or )\n");
nxttok();
if(!Tokenf(TF_NAME)) ParseError("Unexpected token in (LevelTable) block\n");
switch(tokenv) {
case OP_LABEL:
i=look_hash(hash,LOCAL_HASH_SIZE,0x100,0x13F,ll_ndata+0x100,"data columns")?:(ll_ndata++)+0x100;
i-=0x100;
if(datac[i].name) ParseError("Duplicate definition\n");
datac[i].name=strdup(tokenstr);
if(datac[i].name) fatal("Allocation failed\n");
datac[i].ptr=ptr;
ptr=level_table_code(ptr,hash);
break;
case OP_STRING:
if(last) ParseError("Extra columns after fill column\n");
for(i=0;tokenstr[i];i++) if(!(tokenstr[i]&~31)) ParseError("Improper column heading\n");
strcpy(buf,tokenstr);
// Data
nxttok();
if(Tokenf(TF_NAME) && tokenv==OP_LABEL) {
i=look_hash(hash,LOCAL_HASH_SIZE,0x100,0x13F,ll_ndata+0x100,"display columns")?:(ll_ndata++)+0x100;
dispc[ll_ndisp].data=i-0x100;
} else {
ParseError("Syntax error\n");
}
// Width
nxttok();
if(tokent==TF_INT && tokenv>0 && tokenv<=255) {
dispc[ll_ndisp].width=tokenv;
} else if(Tokenf(TF_NAME) && tokenv==OP_MUL) {
dispc[ll_ndisp].width=255;
dispc[ll_ndisp].flag|=1;
} else {
ParseError("Syntax error\n");
}
// Format
nxttok();
if(!Tokenf(TF_NAME) || tokenv!=OP_STRING || !*tokenstr) ParseError("Syntax error\n");
if(*tokenstr<32 || *tokenstr>126) ParseError("Syntax error\n");
if(tokenstr[1]>0 && tokenstr[1]<31) ParseError("Syntax error\n");
if(tokenstr[1]==31) tokenstr[1]=tokenstr[2],tokenstr[2]=tokenstr[3];
if(tokenstr[1] && tokenstr[2]) ParseError("Syntax error\n");
memcpy(dispc[ll_ndisp].form,tokenstr,2);
// Colour
nxttok();
if(tokent==TF_INT) {
if(tokenv&~255) ParseError("Color out of range\n");
dispc[ll_ndisp].color=tokenv;
nxttok();
if(tokent!=TF_CLOSE) ParseError("Syntax error\n");
} else if(tokent==TF_OPEN) {
dispc[ll_ndisp].flag|=2;
dispc[ll_ndisp].ptr=ptr;
for(;;) {
if(++dispc[ll_ndisp].color==255) ParseError("Too many colors\n");
nxttok();
if(tokent!=TF_INT) ParseError("Number expected\n");
i=tokenv;
if(i<-127 || i>127) ParseError("Number out of range\n");
nxttok();
if(tokent!=TF_INT) ParseError("Number expected\n");
if(ptr>=0xFFFE) ParseError("Out of memory\n");
if(tokenv&~255) ParseError("Color out of range\n");
ll_code[ptr++]=tokenv|((i+128)<<8);
nxttok();
if(tokent!=TF_CLOSE) ParseError("Close parenthesis expected\n");
nxttok();
if(tokent==TF_CLOSE) break;
if(tokent!=TF_OPEN) ParseError("Syntax error\n");
};
} else if(tokent==TF_CLOSE) {
dispc[ll_ndisp].color=0xFF;
}
// End
if(dispc[ll_ndisp].flag&1) {
last=1;
sqlite3_str_appendall(str,buf);
} else {
i=dispc[ll_ndisp].width;
sqlite3_str_appendf(str,"%-*.*s\xB3",i,i,buf);
}
ll_ndisp++;
break;
case OP_LOCAL:
i=look_hash(hash,LOCAL_HASH_SIZE,0x200,0x23F,ll_naggregate+0x200,"aggregates")?:(ll_naggregate++)+0x200;
i-=0x200;
if(aggrc[i].ag) ParseError("Duplicate definition\n");
nxttok();
if(!Tokenf(TF_NAME)) ParseError("Improper aggregate\n");
switch(tokenv) {
case OP_ADD: aggrc[i].ag=1; break;
case OP_MIN: aggrc[i].ag=2; break;
case OP_MAX: aggrc[i].ag=3; break;
case OP_MIN_C: aggrc[i].ag=4; break;
case OP_MAX_C: aggrc[i].ag=5; break;
default: ParseError("Improper aggregate\n");
}
aggrc[i].ptr=ptr;
ptr=level_table_code(ptr,hash);
break;
default: ParseError("Unexpected token in (LevelTable) block\n");
}
}
ll_head=sqlite3_str_finish(str);
if(!ll_head) fatal("Allocation failed\n");
for(i=0;i<ll_ndata;i++) if(!datac[i].name) ParseError("Undefined data column\n");
for(i=0;i<ll_naggregate;i++) if(!aggrc[i].ag) ParseError("Undefined aggregate\n");
ll_data=realloc(datac,(ll_ndata+ll_naggregate)*sizeof(DataColumn));
if(!ll_data) fatal("Allocation failed\n");
for(i=0;i<ll_naggregate;i++) ll_data[i+ll_ndata]=aggrc[i];
free(aggrc);
// The next line will result in an invalid pointer if ptr is zero,
// but this is harmless, since ll_code is never accessed if ptr is zero.
ll_code=realloc(ll_code,ptr*sizeof(Uint16))?:ll_code;
for(i=0;i<LOCAL_HASH_SIZE;i++) free(hash[i].txt);
free(hash);
}
void load_classes(void) {
int i;
int gloptr=0;
Hash*glolocalhash;
char*nam=sqlite3_mprintf("%s.class",basefilename);
sqlite3_stmt*vst=0;
|
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
|
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
|
+
+
+
|
case OP_CONTROL:
if(control_class) ParseError("Extra (Control) block\n");
strcpy(tokenstr,"(Control)");
control_class=look_class_name();
if(!(classes[control_class]->cflags&CF_NOCLASS1)) ParseError("Conflicting definition of (Control) class\n");
class_definition(control_class,vst);
break;
case OP_LEVELTABLE:
level_table_definition();
break;
default:
ParseError("Invalid top level definition: %s\n",tokenstr);
}
} else {
ParseError("Invalid top level definition\n");
}
}
|