436
437
438
439
440
441
442
443
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
|
436
437
438
439
440
441
442
443
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
|
-
+
-
+
+
-
+
-
+
|
char*nam3;
struct stat fst;
fprintf(stderr,"Initializing user cache...\n");
if(z=sqlite3_exec(userdb,"BEGIN;",0,0,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
if(z=sqlite3_prepare_v2(userdb,"SELECT `ID`, `TIME` FROM `USERCACHEINDEX` WHERE `NAME` = ?1;",-1,&st,0)) fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
nam1=sqlite3_mprintf("%s.level",basefilename);
if(!nam1) fatal("Allocation failed\n");
nam2=realpath(nam1,0);
nam2=main_options['n']?strdup(nam1):realpath(nam1,0);
if(!nam2) fatal("Cannot find real path of '%s': %m\n",nam1);
levelfp=fopen(nam2,main_options['r']?"r":"r+");
levelfp=fopen(nam2,main_options['n']?"w+x":main_options['r']?"r":"r+");
if(!levelfp) fatal("Cannot open '%s' for reading%s: %m\n",nam2,main_options['r']?"":"/writing");
sqlite3_free(nam1);
sqlite3_bind_text(st,1,nam2,-1,0);
z=sqlite3_step(st);
if(z==SQLITE_ROW) {
leveluc=sqlite3_column_int64(st,0);
t1=sqlite3_column_int64(st,1);
} else if(z==SQLITE_DONE) {
leveluc=t1=-1;
} else {
fatal("SQL error (%d): %s\n",z,sqlite3_errmsg(userdb));
}
sqlite3_reset(st);
if(main_options['n']) write_empty_level_set(levelfp);
nam1=sqlite3_mprintf("%s.solution",basefilename);
if(!nam1) fatal("Allocation failed\n");
nam3=realpath(nam1,0);
nam3=main_options['n']?strdup(nam1):realpath(nam1,0);
if(!nam3) fatal("Cannot find real path of '%s': %m\n",nam1);
if(!strcmp(nam2,nam3)) fatal("Level and solution files seem to be the same file\n");
solutionfp=fopen(nam3,main_options['r']?"r":"r+");
solutionfp=fopen(nam3,main_options['n']?"w+x":main_options['r']?"r":"r+");
if(!solutionfp) fatal("Cannot open '%s' for reading%s: %m\n",nam3,main_options['r']?"":"/writing");
sqlite3_free(nam1);
sqlite3_bind_text(st,1,nam3,-1,0);
z=sqlite3_step(st);
if(z==SQLITE_ROW) {
solutionuc=sqlite3_column_int64(st,0);
t2=sqlite3_column_int64(st,1);
|
827
828
829
830
831
832
833
834
835
836
837
838
839
840
|
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
|
+
+
+
+
|
if(!resourcedb) fatal("Allocation of resource database failed\n");
basefilename=argv[optind++];
if(argc>optind && argv[1][0]=='=') {
globalclassname=argv[optind++]+1;
} else if(find_globalclassname()) {
globalclassname=strrchr(basefilename,'/');
globalclassname=globalclassname?globalclassname+1:basefilename;
}
if(main_options['n']) {
if(main_options['r']) fatal("Switches -r and -n are conflicting\n");
main_options['x']=1;
}
if(!main_options['c']) load_options();
if(argc>optind) read_options(argc-optind,argv+optind);
*optionquery=xrm_make_quark(globalclassname,0)?:xrm_anyq;
#ifdef __GNUC__
stack_protect_mark=__builtin_frame_address(0);
set_stack_protection();
|
848
849
850
851
852
853
854
855
856
857
858
859
860
861
|
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
|
+
|
init_screen();
load_pictures();
if(main_options['T']) {
test_mode();
return 0;
}
init_usercache();
if(main_options['n']) return 0;
load_classes();
load_level_index();
optionquery[1]=Q_maxObjects;
max_objects=strtoll(xrm_get_resource(resourcedb,optionquery,optionquery,2)?:"",0,0)?:0xFFFF0000L;
set_tracing();
annihilate();
optionquery[1]=Q_level;
|