Overview
Comment: | Corrections and completions of class loading; implement -x switch; correction to schema |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
08625cbba04d3b06e09fe724188f8902 |
User & Date: | user on 2018-06-10 05:27:55 |
Other Links: | manifest | tags |
Context
2018-06-10
| ||
06:10 | Move around some BEGIN and COMMIT commands to avoid misnested transactions in some cases check-in: b4a4337c4a user: user tags: trunk | |
05:27 | Corrections and completions of class loading; implement -x switch; correction to schema check-in: 08625cbba0 user: user tags: trunk | |
2018-06-09
| ||
00:42 | Add the write_lump() function (uses upsert, which SQLite recently added) check-in: a55e51e100 user: user tags: trunk | |
Changes
Modified class.c from [620e67e86b] to [2ba6e49ee7].
︙ | ︙ | |||
245 246 247 248 249 250 251 | Uint16 get_message_ptr(int c,int m) { if(!classes[c]) return 0xFFFF; if(classes[c]->nmsg<=m) return 0xFFFF; return classes[c]->messages[m]; } static void set_message_ptr(int c,int m,int p) { | | | | 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | Uint16 get_message_ptr(int c,int m) { if(!classes[c]) return 0xFFFF; if(classes[c]->nmsg<=m) return 0xFFFF; return classes[c]->messages[m]; } static void set_message_ptr(int c,int m,int p) { if(m>=classes[c]->nmsg) { classes[c]->messages=realloc(classes[c]->messages,(m+1)*sizeof(Uint16)); if(!classes[c]->messages) fatal("Allocation failed\n"); while(m>=classes[c]->nmsg) classes[c]->messages[classes[c]->nmsg++]=0xFFFF; } classes[c]->messages[m]=p; } static int look_class_name(void) { int i; int u=undef_class; |
︙ | ︙ | |||
900 901 902 903 904 905 906 | cl->codes=realloc(cl->codes,0x10000*sizeof(Uint16)); if(!cl->codes) fatal("Allocation failed\n"); for(;;) { nxttok(); if(Tokenf(TF_MACRO)) ParseError("Unexpected macro\n"); if(Tokenf(TF_INT)) { numeric: | | | | | 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 | cl->codes=realloc(cl->codes,0x10000*sizeof(Uint16)); if(!cl->codes) fatal("Allocation failed\n"); for(;;) { nxttok(); if(Tokenf(TF_MACRO)) ParseError("Unexpected macro\n"); if(Tokenf(TF_INT)) { numeric: if(!(tokenv&~0xFFL)) AddInst(tokenv); else if(!((tokenv-1)&tokenv)) AddInst(0x87E0+__builtin_ctz(tokenv)); else if(!(tokenv&~0xFFFFL)) AddInst2(OP_INT16,tokenv); else if((tokenv&0x80000000L) && -256<(Sint32)tokenv) AddInst(tokenv&0x01FF); else AddInst(OP_INT32),AddInst2(tokenv>>16,tokenv); } else if(Tokenf(TF_NAME)) { switch(tokenv) { AbbrevOp(OP_ADD,0x00); AbbrevOp(OP_SUB,0x08); AbbrevOp(OP_MUL,0x10); AbbrevOp(OP_DIV,0x18); |
︙ | ︙ | |||
1028 1029 1030 1031 1032 1033 1034 | break; case OP_NEXT: FlowPop(OP_FOR); AddInst(OP_NEXT); cl->codes[flowptr[flowdepth]]=ptr; break; case OP_STRING: | | | 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 | break; case OP_NEXT: FlowPop(OP_FOR); AddInst(OP_NEXT); cl->codes[flowptr[flowdepth]]=ptr; break; case OP_STRING: AddInst2(OP_STRING,pool_string(tokenstr)); break; default: if(Tokenf(TF_ABNORMAL)) ParseError("Invalid instruction token\n"); if(compat && Tokenf(TF_COMPAT)) ++tokenv; AddInstF(tokenv,tokent); } } else if(Tokenf(TF_FUNCTION)) { |
︙ | ︙ | |||
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | tokenv=x; goto numeric; default: ParseError("Invalid parenthesized instruction\n"); } } else if(tokent==TF_CLOSE) { if(peep<ptr && cl->codes[ptr-1]==OP_RET) break; if(Inst8bit()) ChangeInst(+=0x1E00); else AddInst(OP_RET); break; } else if(Tokenf(TF_EOF)) { ParseError("Unexpected end of file\n"); } else { ParseError("Invalid instruction token\n"); | > | 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | tokenv=x; goto numeric; default: ParseError("Invalid parenthesized instruction\n"); } } else if(tokent==TF_CLOSE) { if(peep<ptr && cl->codes[ptr-1]==OP_RET) break; if(peep<ptr && (cl->codes[ptr-1]&0xFF00)==0x1E00) break; if(Inst8bit()) ChangeInst(+=0x1E00); else AddInst(OP_RET); break; } else if(Tokenf(TF_EOF)) { ParseError("Unexpected end of file\n"); } else { ParseError("Invalid instruction token\n"); |
︙ | ︙ | |||
1117 1118 1119 1120 1121 1122 1123 | if(hash && cl->uservars) { printf(" Variables:\n"); for(i=0;i<LOCAL_HASH_SIZE;i++) { if(hash[i].id>=0x2000 && hash[i].id<0x3000) printf(" %%%s = 0x%04X\n",hash[i].txt,hash[i].id); } } if(endptr && cl->codes) { | | | | 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 | if(hash && cl->uservars) { printf(" Variables:\n"); for(i=0;i<LOCAL_HASH_SIZE;i++) { if(hash[i].id>=0x2000 && hash[i].id<0x3000) printf(" %%%s = 0x%04X\n",hash[i].txt,hash[i].id); } } if(endptr && cl->codes) { printf(" Codes:"); for(i=0;i<endptr;i++) { if(!(i&15)) printf("\n [%04X]",i); printf(" %04X",cl->codes[i]); } putchar('\n'); } printf("---\n\n"); } |
︙ | ︙ | |||
1164 1165 1166 1167 1168 1169 1170 | nxttok(); if(Tokenf(TF_NAME) && tokenv==OP_INPLACE) { nxttok(); if(tokent!=TF_CLOSE) ParseError("Close parentheses expected\n"); return 1<<12; } for(i=0;i<25;i++) { | < < | > | > > > > > > > | > > > > > | | > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 | nxttok(); if(Tokenf(TF_NAME) && tokenv==OP_INPLACE) { nxttok(); if(tokent!=TF_CLOSE) ParseError("Close parentheses expected\n"); return 1<<12; } for(i=0;i<25;i++) { if(!Tokenf(TF_INT) || (tokenv&~1)) ParseError("Expected 0 or 1\n"); if(tokenv) n|=1<<(i+4-2*(i%5)); nxttok(); } if(tokent!=TF_CLOSE) ParseError("Close parentheses expected\n"); return n; } static void class_def_hard(Uint16*data) { int i; for(;;) { nxttok(); if(tokent==TF_CLOSE) { return; } else if(tokent==TF_OPEN) { nxttok(); if(!Tokenf(TF_DIR) || tokenv>7 || (tokenv&1)) ParseError("Expected even absolute direction\n"); i=tokenv>>1; nxttok(); if(tokent!=TF_INT || (tokenv&~0xFFFF)) ParseError("Hardness/sharpness must be a 16-bit number\n"); data[i]=tokenv; nxttok(); if(tokent!=TF_CLOSE) ParseError("Close parentheses expected\n"); } else if(tokent==TF_INT) { if(tokenv&~0xFFFF) ParseError("Hardness/sharpness must be a 16-bit number\n"); data[0]=data[1]=data[2]=data[3]=tokenv; } else { ParseError("Expected ( or ) or number\n"); } } } static inline Uint8 class_def_shovable(void) { Uint8 n=0; nxttok(); if(tokent==TF_INT) { n=tokenv; nxttok(); if(tokent!=TF_CLOSE) ParseError("Close parentheses expected\n"); return n; } for(;;) { if(tokent==TF_CLOSE) return n; if(!Tokenf(TF_DIR) || tokenv>7 || (tokenv&1)) ParseError("Expected even absolute direction\n"); n|=1<<tokenv; nxttok(); } } static inline Uint8 class_def_shape(void) { Uint8 n=0; int i; for(;;) { nxttok(); if(tokent==TF_CLOSE) { return n; } else if(tokent==TF_OPEN) { nxttok(); if(!Tokenf(TF_DIR) || tokenv>7 || (tokenv&1)) ParseError("Expected even absolute direction\n"); i=tokenv; n&=~(3<<i); nxttok(); if(tokent!=TF_INT || (tokenv&~3)) ParseError("Shape must be 0, 1, 2, or 3\n"); n|=tokenv<<i; nxttok(); if(tokent!=TF_CLOSE) ParseError("Close parentheses expected\n"); } else if(tokent==TF_INT) { if(tokenv&~3) ParseError("Shape must be 0, 1, 2, or 3\n"); n=tokenv*0x55; } else { ParseError("Expected ( or ) or number\n"); } } } static char*class_def_help(void) { char*txt=malloc(0x3000); int n=0; int i; for(;;) { nxttok(); if(tokent==TF_CLOSE) break; if(!Tokenf(TF_NAME) || tokenv!=OP_STRING) ParseError("String expected\n"); i=strlen(tokenstr); if(i+n>=0x2FFD) ParseError("Help text is too long\n"); strcpy(txt+n,tokenstr); n+=i; } if(!n) { free(txt); return 0; } txt[n]=0; return realloc(txt,n+1)?:txt; } static void class_def_image(int cla) { Class*cl=classes[cla]; Uint16*img=malloc(256*sizeof(Uint16)); sqlite3_stmt*st; if(cl->nimages || cl->images) ParseError("Duplicate (Image) block\n"); if(!img) fatal("Allocation failed\n"); if(userdb && sqlite3_prepare_v2(userdb,"SELECT `ID` FROM `PICTURES` WHERE `NAME` = ?1;",-1,&st,0)) fatal("SQL error: %s\n",sqlite3_errmsg(userdb)); for(;;) { nxttok(); if(tokent==TF_CLOSE) break; if(cl->nimages==255) ParseError("Too many images in class\n"); if(!Tokenf(TF_NAME) || tokenv!=OP_STRING) ParseError("String expected\n"); if(userdb) { sqlite3_bind_text(st,1,tokenstr,-1,0); if(sqlite3_step(st)==SQLITE_ROW) { img[cl->nimages++]=sqlite3_column_int(st,0)|0x8000; } else { ParseError("A picture named \"%s\" does not exist\n",tokenstr); } sqlite3_reset(st); sqlite3_clear_bindings(st); } else { img[cl->nimages++]=0; } } if(userdb) sqlite3_finalize(st); if(!cl->nimages) { free(img); return; } cl->images=realloc(img,cl->nimages*sizeof(Uint16))?:img; } static void class_def_defaultimage(int cla) { Class*cl=classes[cla]; int i; for(i=0;i<cl->nimages;i++) cl->images[i]&=0x7FFF; for(;;) { nxttok(); if(tokent==TF_OPEN) { nxttok(); if(tokent==TF_INT) { if(tokenv<0 || tokenv>=cl->nimages) ParseError("Image number out of range\n"); i=tokenv; nxttok(); if(tokent!=TF_INT) ParseError("Number expected\n"); if(tokenv<i) ParseError("Backward range in (DefaultImage) block\n"); if(tokenv>=cl->nimages) ParseError("Image number out of range\n"); while(i<=tokenv) cl->images[i++]|=0x8000; } else if(tokent!=TF_CLOSE) { ParseError("Number expected\n"); } } else if(tokent==TF_CLOSE) { break; } else if(tokent==TF_INT) { if(tokenv<0 || tokenv>=cl->nimages) ParseError("Image number out of range\n"); cl->images[tokenv]|=0x8000; } else { ParseError("Expected ( or ) or number\n"); } } } static void class_definition(int cla) { Hash*hash=calloc(LOCAL_HASH_SIZE,sizeof(Hash)); Class*cl=classes[cla]; int ptr=0; int compat=0; |
︙ | ︙ | |||
1230 1231 1232 1233 1234 1235 1236 | } else if(Tokenf(TF_MACRO)) { ParseError("Unexpected macro token\n"); } else if(Tokenf(TF_OPEN)) { nxttok(); if(Tokenf(TF_NAME)) { switch(tokenv) { case OP_IMAGE: | | | | > | > | 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 | } else if(Tokenf(TF_MACRO)) { ParseError("Unexpected macro token\n"); } else if(Tokenf(TF_OPEN)) { nxttok(); if(Tokenf(TF_NAME)) { switch(tokenv) { case OP_IMAGE: class_def_image(cla); break; case OP_DEFAULTIMAGE: class_def_defaultimage(cla); break; case OP_HELP: if(cl->gamehelp) ParseError("Duplicate (Help) block\n"); cl->gamehelp=class_def_help(); break; case OP_EDITORHELP: if(cl->edithelp) ParseError("Duplicate (EditorHelp) block\n"); cl->edithelp=class_def_help(); break; case OP_HEIGHT: cl->height=class_def_number(); break; case OP_WEIGHT: cl->weight=class_def_number(); break; |
︙ | ︙ | |||
1332 1333 1334 1335 1336 1337 1338 | } } else if(Tokenf(TF_CLOSE)) { break; } else { ParseError("Invalid directly inside of a class definition\n"); } } | | | 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 | } } else if(Tokenf(TF_CLOSE)) { break; } else { ParseError("Invalid directly inside of a class definition\n"); } } end_label_stack(cl->codes,hash); if(!cl->nimages) cl->oflags|=OF_INVISIBLE; if(main_options['C']) dump_class(cla,ptr,hash); if(main_options['H']) { for(i=0;i<LOCAL_HASH_SIZE;i++) if(hash[i].id) printf(" \"%s\": %04X\n",hash[i].txt,hash[i].id); } for(i=0;i<LOCAL_HASH_SIZE;i++) free(hash[i].txt); free(hash); |
︙ | ︙ |
Modified compile from [ab1f577adf] to [4085df24bd].
1 2 3 4 5 6 7 8 | #!/bin/bash -- test "x$EXE" = "x" && EXE=~/bin/heromesh test instruc -nt instruc.h && node instruc.js > instruc.h test instruc.js -nt instruc.h && node instruc.js > instruc.h test names.js -nt names.h && node names.js > names.h test quarks -nt quarks.h && node quarks.js > quarks.h test quarks.js -nt quarks.h && node quarks.js > quarks.h test heromesh.h -nt "$EXE" && rm bindings.o class.o picture.o | > > > | 1 2 3 4 5 6 7 8 9 10 11 | #!/bin/bash -- test -f CFLAGS || echo xxx > CFLAGS test "xx$CFLAGS" = "x`cat CFLAGS`" || rm bindings.o class.o picture.o echo "x$CFLAGS" > CFLAGS test "x$EXE" = "x" && EXE=~/bin/heromesh test instruc -nt instruc.h && node instruc.js > instruc.h test instruc.js -nt instruc.h && node instruc.js > instruc.h test names.js -nt names.h && node names.js > names.h test quarks -nt quarks.h && node quarks.js > quarks.h test quarks.js -nt quarks.h && node quarks.js > quarks.h test heromesh.h -nt "$EXE" && rm bindings.o class.o picture.o |
︙ | ︙ |
Modified instruc from [0dc50cbad6] to [c6fac498bb].
︙ | ︙ | |||
197 198 199 200 201 202 203 | .,Destroy FlushClass FlushObj GetInventory HeightAt IgnoreKey .,IntMove ; move without initializing Inertia | | | 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | .,Destroy FlushClass FlushObj GetInventory HeightAt IgnoreKey .,IntMove ; move without initializing Inertia .,JumpTo ,Loc ; same as: Xloc Yloc LocateMe LoseLevel MaxInventory ; error if more than that many slots in inventory .,Move .,MovePlus "Move+" ; obj.Inertia+=Strength instead of obj.Inertia=Strength .,MoveTo ; the internal MoveTo() function |
︙ | ︙ |
Modified instruc.h from [834265d374] to [a4453a3ab4].
︙ | ︙ | |||
287 288 289 290 291 292 293 294 295 296 297 298 299 300 | #define OP_IGNOREKEY 32900 #define OP_INTMOVE 32901 #define OP_INTMOVE_C 34949 #define OP_INTMOVE_D 41093 #define OP_INTMOVE_CD 43141 #define OP_JUMPTO 32902 #define OP_JUMPTO_C 34950 #define OP_LOC 32903 #define OP_LOC_C 34951 #define OP_LOCATEME 32904 #define OP_LOSELEVEL 32905 #define OP_MAXINVENTORY 32906 #define OP_MOVE 32907 #define OP_MOVE_C 34955 | > > | 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | #define OP_IGNOREKEY 32900 #define OP_INTMOVE 32901 #define OP_INTMOVE_C 34949 #define OP_INTMOVE_D 41093 #define OP_INTMOVE_CD 43141 #define OP_JUMPTO 32902 #define OP_JUMPTO_C 34950 #define OP_JUMPTO_D 41094 #define OP_JUMPTO_CD 43142 #define OP_LOC 32903 #define OP_LOC_C 34951 #define OP_LOCATEME 32904 #define OP_LOSELEVEL 32905 #define OP_MAXINVENTORY 32906 #define OP_MOVE 32907 #define OP_MOVE_C 34955 |
︙ | ︙ | |||
436 437 438 439 440 441 442 | {"InPlace",8683632}, {"Inertia",9142323}, {"Input",8683630}, {"IntMove",10584197}, {"Invisible",8618074}, {"JAYAYAYNG",8389416}, {"JUMPED",8389128}, | | | 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | {"InPlace",8683632}, {"Inertia",9142323}, {"Input",8683630}, {"IntMove",10584197}, {"Invisible",8618074}, {"JAYAYAYNG",8389416}, {"JUMPED",8389128}, {"JumpTo",10584198}, {"KEWEL",8389422}, {"KEY",8389129}, {"KLECK",8389387}, {"KLINKK",8389385}, {"Key",8421484}, {"KeyCleared",8618075}, {"L",9437194}, |
︙ | ︙ |
Modified main.c from [af17e022b5] to [4a37978eeb].
︙ | ︙ | |||
26 27 28 29 30 31 32 | #include "heromesh.h" static const char schema[]= "BEGIN;" "PRAGMA APPLICATION_ID(1296388936);" "PRAGMA RECURSIVE_TRIGGERS(1);" "CREATE TABLE IF NOT EXISTS `USERCACHEINDEX`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `TIME` INT);" | | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include "heromesh.h" static const char schema[]= "BEGIN;" "PRAGMA APPLICATION_ID(1296388936);" "PRAGMA RECURSIVE_TRIGGERS(1);" "CREATE TABLE IF NOT EXISTS `USERCACHEINDEX`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT, `TIME` INT);" "CREATE TABLE IF NOT EXISTS `USERCACHEDATA`(`ID` INTEGER PRIMARY KEY, `FILE` INT, `LEVEL` INT, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT, `DATA` BLOB, `USERSTATE` BLOB);" "CREATE UNIQUE INDEX IF NOT EXISTS `USERCACHEDATA_I1` ON `USERCACHEDATA`(`FILE`, `LEVEL`);" "CREATE TEMPORARY TABLE `PICTURES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT COLLATE NOCASE, `OFFSET` INT);" "CREATE TEMPORARY TABLE `VARIABLES`(`ID` INTEGER PRIMARY KEY, `NAME` TEXT);" "COMMIT;" ; sqlite3*userdb; xrm_db*resourcedb; const char*basefilename; |
︙ | ︙ | |||
187 188 189 190 191 192 193 194 195 196 197 198 199 200 | sqlite3_bind_int(st,2,lvl); sqlite3_bind_text(st,3,lvl==LUMP_CLASS_DEF?"CLASS.DEF":lvl==LUMP_LEVEL_IDX?"LEVEL.IDX":sol?".SOL":".LVL",-1,SQLITE_STATIC); sqlite3_bind_blob64(st,4,data,sz,0); while((e=sqlite3_step(st))==SQLITE_ROW); if(e!=SQLITE_DONE) fatal("SQL error (%d): %s\n",e,sqlite3_errmsg(userdb)); sqlite3_finalize(st); } static void init_usercache(void) { sqlite3_stmt*st; int z; sqlite3_int64 t1,t2; char*nam1; char*nam2; | > > > > | 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | sqlite3_bind_int(st,2,lvl); sqlite3_bind_text(st,3,lvl==LUMP_CLASS_DEF?"CLASS.DEF":lvl==LUMP_LEVEL_IDX?"LEVEL.IDX":sol?".SOL":".LVL",-1,SQLITE_STATIC); sqlite3_bind_blob64(st,4,data,sz,0); while((e=sqlite3_step(st))==SQLITE_ROW); if(e!=SQLITE_DONE) fatal("SQL error (%d): %s\n",e,sqlite3_errmsg(userdb)); sqlite3_finalize(st); } static void flush_usercache(void) { } static void init_usercache(void) { sqlite3_stmt*st; int z; sqlite3_int64 t1,t2; char*nam1; char*nam2; |
︙ | ︙ | |||
440 441 442 443 444 445 446 447 448 449 450 451 452 453 | } break; case SDL_QUIT: exit(0); break; } } int main(int argc,char**argv) { int optind=1; while(argc>optind && argv[optind][0]=='-') { int i; const char*s=argv[optind++]; if(s[1]=='-' && !s[2]) break; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | } break; case SDL_QUIT: exit(0); break; } } static void do_sql_mode(void) { int m=sqlite3_limit(userdb,SQLITE_LIMIT_SQL_LENGTH,-1); char*txt=malloc(m); int n=0; int c; int bail=1; if(m>1000000) m=1000000; txt=malloc(m+2); if(!txt) fatal("Allocation failed\n"); for(;;) { c=fgetc(stdin); if(c=='\n' || c==EOF) { if(!n) continue; if(*txt=='#') { n=0; } else if(*txt=='.') { txt[n]=0; n=0; switch(txt[1]) { case 'b': bail=strtol(txt+2,0,0); break; case 'f': sqlite3_db_cacheflush(userdb); sqlite3_db_release_memory(userdb); break; case 'i': puts(sqlite3_db_filename(userdb,"main")); break; case 'q': exit(0); break; case 'u': flush_usercache(); break; case 'x': sqlite3_enable_load_extension(userdb,strtol(txt+2,0,0)); break; default: fatal("Invalid dot command .%c\n",txt[1]); } } else { txt[n]=0; if(sqlite3_complete(txt)) { n=sqlite3_exec(userdb,txt,test_sql_callback,0,0); if(bail && n) fatal("SQL error (%d): %s\n",n,sqlite3_errmsg(userdb)); n=0; } else { txt[n++]='\n'; } } if(c==EOF) break; } else { txt[n++]=c; } if(n>=m) fatal("Too long SQL statement\n"); } if(n) fatal("Unterminated SQL statement\n"); free(txt); } int main(int argc,char**argv) { int optind=1; while(argc>optind && argv[optind][0]=='-') { int i; const char*s=argv[optind++]; if(s[1]=='-' && !s[2]) break; |
︙ | ︙ | |||
479 480 481 482 483 484 485 486 487 488 | load_pictures(); if(main_options['T']) { test_mode(); return 0; } init_usercache(); load_classes(); return 0; } | > > > > > | 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | load_pictures(); if(main_options['T']) { test_mode(); return 0; } init_usercache(); load_classes(); if(main_options['x']) { fprintf(stderr,"Ready for executing SQL statements.\n"); do_sql_mode(); return 0; } return 0; } |
Modified picture.c from [2270c225a7] to [95be04510a].
︙ | ︙ | |||
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | rewind(fp); for(i=255;i;--i) if(havesize[i]) { curpic=malloc(i*i); break; } if(!curpic) fatal("Allocation failed\n"); picture_size=decide_picture_size(nwantsize,wantsize,havesize,n); if(sqlite3_prepare_v2(userdb,"SELECT `ID`, `OFFSET` FROM `PICTURES`;",-1,&st,0)) fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb)); optionquery[1]=Q_screenFlags; v=xrm_get_resource(resourcedb,optionquery,optionquery,2); i=v&&strchr(v,'h'); picts=SDL_CreateRGBSurface((i?SDL_HWSURFACE:SDL_SWSURFACE)|SDL_SRCCOLORKEY,picture_size<<4,picture_size*((n+15)>>4),8,0,0,0,0); if(!picts) fatal("Error allocating surface for pictures: %s\n",SDL_GetError()); init_palette(); for(i=0;i<n;i++) { if((j=sqlite3_step(st))!=SQLITE_ROW) fatal("SQL error (%d): %s\n",j,j==SQLITE_DONE?"Incorrect number of rows in a temporary table":sqlite3_errmsg(userdb)); fseek(fp,sqlite3_column_int64(st,1),SEEK_SET); load_one_picture(fp,sqlite3_column_int(st,0),altImage); } sqlite3_finalize(st); fclose(fp); sqlite3_exec(userdb,"COMMIT;",0,0,0); SDL_SetColorKey(picts,SDL_SRCCOLORKEY|SDL_RLEACCEL,0); fprintf(stderr,"Done\n"); } void init_screen(void) { const char*v; int w,h,i; optionquery[1]=Q_screenWidth; w=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"800",0,10); optionquery[1]=Q_screenHeight; h=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"600",0,10); optionquery[1]=Q_screenFlags; v=xrm_get_resource(resourcedb,optionquery,optionquery,2)?:""; if(SDL_Init(SDL_INIT_VIDEO|(strchr(v,'z')?SDL_INIT_NOPARACHUTE:0))) fatal("Error initializing SDL: %s\n",SDL_GetError()); | > > > | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | rewind(fp); for(i=255;i;--i) if(havesize[i]) { curpic=malloc(i*i); break; } if(!curpic) fatal("Allocation failed\n"); picture_size=decide_picture_size(nwantsize,wantsize,havesize,n); if(main_options['x']) goto done; if(sqlite3_prepare_v2(userdb,"SELECT `ID`, `OFFSET` FROM `PICTURES`;",-1,&st,0)) fatal("Unable to prepare SQL statement while loading pictures: %s\n",sqlite3_errmsg(userdb)); optionquery[1]=Q_screenFlags; v=xrm_get_resource(resourcedb,optionquery,optionquery,2); i=v&&strchr(v,'h'); picts=SDL_CreateRGBSurface((i?SDL_HWSURFACE:SDL_SWSURFACE)|SDL_SRCCOLORKEY,picture_size<<4,picture_size*((n+15)>>4),8,0,0,0,0); if(!picts) fatal("Error allocating surface for pictures: %s\n",SDL_GetError()); init_palette(); for(i=0;i<n;i++) { if((j=sqlite3_step(st))!=SQLITE_ROW) fatal("SQL error (%d): %s\n",j,j==SQLITE_DONE?"Incorrect number of rows in a temporary table":sqlite3_errmsg(userdb)); fseek(fp,sqlite3_column_int64(st,1),SEEK_SET); load_one_picture(fp,sqlite3_column_int(st,0),altImage); } sqlite3_finalize(st); fclose(fp); sqlite3_exec(userdb,"COMMIT;",0,0,0); SDL_SetColorKey(picts,SDL_SRCCOLORKEY|SDL_RLEACCEL,0); done: fprintf(stderr,"Done\n"); } void init_screen(void) { const char*v; int w,h,i; if(main_options['x']) return; optionquery[1]=Q_screenWidth; w=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"800",0,10); optionquery[1]=Q_screenHeight; h=strtol(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"600",0,10); optionquery[1]=Q_screenFlags; v=xrm_get_resource(resourcedb,optionquery,optionquery,2)?:""; if(SDL_Init(SDL_INIT_VIDEO|(strchr(v,'z')?SDL_INIT_NOPARACHUTE:0))) fatal("Error initializing SDL: %s\n",SDL_GetError()); |
︙ | ︙ |