207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
-
+
|
while(j=fgetc(fp)) {
if(j==EOF) goto done;
if(i<255) nam[i++]=j;
}
nam[i]=0;
sqlite3_reset(st);
sqlite3_bind_text(st,1,nam,i,SQLITE_TRANSIENT);
if(i>4) j=(!memcmp(".IMG",nam+i-4,4)?1:!memcmp(".DEP",nam+i-4,4)?2:0); else j=0;
if(i>4) j=(!memcmp(".IMG",nam+i-4,4)?1:!memcmp(".DEP",nam+i-4,4)?2:!memcmp(".MUL",nam+i-4,4)?3:0); else j=0;
sqlite3_bind_int(st,2,j);
if(j) r++;
i=fgetc(fp)<<16;
i|=fgetc(fp)<<24;
i|=fgetc(fp)<<0;
i|=fgetc(fp)<<8;
if(!i) continue;
|
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
|
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
|
+
-
+
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
-
+
-
+
+
+
+
|
}
static int add_picture(int t) {
sqlite3_stmt*st;
const char*s=screen_prompt("Enter name of new picture:");
int i;
if(!s || !*s) return 0;
if(*s=='+' && s[1]) t=3,s++;
if(sqlite3_prepare_v2(userdb,"INSERT INTO `PICEDIT`(`NAME`,`TYPE`,`DATA`) SELECT VALID_NAME(?1)||CASE ?2 WHEN 1 THEN '.IMG' ELSE '.DEP' END,?2,X'';",-1,&st,0)) {
if(sqlite3_prepare_v2(userdb,"INSERT INTO `PICEDIT`(`NAME`,`TYPE`,`DATA`) SELECT VALID_NAME(?1)||CASE ?2 WHEN 1 THEN '.IMG' WHEN 2 THEN '.DEP' ELSE '.MUL' END,?2,X'';",-1,&st,0)) {
screen_message(sqlite3_errmsg(userdb));
return 0;
}
sqlite3_bind_text(st,1,s,-1,0);
sqlite3_bind_int(st,2,t);
i=sqlite3_step(st);
sqlite3_finalize(st);
if(i!=SQLITE_DONE) {
screen_message(sqlite3_errmsg(userdb));
return 0;
}
edit_picture(sqlite3_last_insert_rowid(userdb));
return 1;
}
static int delete_picture(void) {
sqlite3_stmt*st;
const char*s=screen_prompt("Enter name of picture to delete:");
int i;
if(!s || !*s) return 0;
if(sqlite3_prepare_v2(userdb,"DELETE FROM `PICEDIT` WHERE `NAME`=?1||'.IMG' OR `NAME`=?1||'.DEP';",-1,&st,0)) {
if(sqlite3_prepare_v2(userdb,"DELETE FROM `PICEDIT` WHERE `NAME`=?1||'.IMG' OR `NAME`=?1||'.DEP' OR (SUBSTR(?1,1,1)='+' AND `NAME`=SUBSTR(?1,2)||'.MUL');",-1,&st,0)) {
screen_message(sqlite3_errmsg(userdb));
return 0;
}
sqlite3_bind_text(st,1,s,-1,0);
i=sqlite3_step(st);
sqlite3_finalize(st);
if(i!=SQLITE_DONE) {
screen_message(sqlite3_errmsg(userdb));
return 0;
}
return 1;
}
static void rename_picture(void) {
sqlite3_stmt*st;
const char*s=screen_prompt("Old name:");
int i;
if(!s || !*s) return;
if(*s=='+' && s[1]) {
i=1;
if(sqlite3_prepare_v2(userdb,"UPDATE `PICEDIT` SET `NAME`=VALID_NAME(?2)||'.MUL' WHERE `NAME`=?1||'.MUL';",-1,&st,0)) {
screen_message(sqlite3_errmsg(userdb));
return;
}
} else {
i=0;
if(sqlite3_prepare_v2(userdb,"UPDATE `PICEDIT` SET `NAME`=VALID_NAME(?2)||SUBSTR(`NAME`,-4) WHERE `NAME`=?1||'.IMG' OR `NAME`=?1||'.DEP';",-1,&st,0)) {
screen_message(sqlite3_errmsg(userdb));
return;
}
sqlite3_bind_text(st,1,s,-1,SQLITE_TRANSIENT);
if(sqlite3_prepare_v2(userdb,"UPDATE `PICEDIT` SET `NAME`=VALID_NAME(?2)||SUBSTR(`NAME`,-4) WHERE `NAME`=?1||'.IMG' OR `NAME`=?1||'.DEP';",-1,&st,0)) {
screen_message(sqlite3_errmsg(userdb));
return;
}
}
sqlite3_bind_text(st,1,s+i,-1,SQLITE_TRANSIENT);
s=screen_prompt("New name:");
if(!s || !*s) {
sqlite3_finalize(st);
return;
}
if(i && *s=='+') s++;
sqlite3_bind_text(st,2,s,-1,SQLITE_TRANSIENT);
i=sqlite3_step(st);
sqlite3_finalize(st);
if(i!=SQLITE_DONE) screen_message(sqlite3_errmsg(userdb));
}
static sqlite3_int64 copy_picture(void) {
sqlite3_stmt*st;
const char*s=screen_prompt("Copy from:");
int i;
int i=0;
sqlite3_set_last_insert_rowid(userdb,0);
if(!s || !*s) return 0;
if(sqlite3_prepare_v2(userdb,"INSERT INTO `PICEDIT`(`NAME`,`TYPE`,`DATA`) SELECT VALID_NAME(?2)||SUBSTR(`NAME`,-4),`TYPE`,`DATA` "
"FROM `PICEDIT` WHERE SUBSTR(`NAME`,1,LENGTH(`NAME`)-4)=?1 AND `TYPE`<>0;",-1,&st,0)) {
"FROM `PICEDIT` WHERE SUBSTR(`NAME`,1,LENGTH(`NAME`)-4)=?1 AND IIF(?3,`TYPE`=3,`TYPE`<>0 AND `TYPE`<>3);",-1,&st,0)) {
screen_message(sqlite3_errmsg(userdb));
return 0;
}
if(*s=='+' && s[1]) s++,i=1;
sqlite3_bind_text(st,1,s,-1,SQLITE_TRANSIENT);
s=screen_prompt("Copy to:");
if(!s || !*s) {
sqlite3_finalize(st);
return 0;
}
if(i && *s=='+') s++;
sqlite3_bind_text(st,2,s,-1,SQLITE_TRANSIENT);
sqlite3_bind_int(st,3,i);
i=sqlite3_step(st);
sqlite3_finalize(st);
if(i==SQLITE_DONE) {
return sqlite3_last_insert_rowid(userdb);
} else {
screen_message(sqlite3_errmsg(userdb));
return 0;
|
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
|
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
|
+
-
+
+
|
SDL_LockSurface(screen);
r.x=r.y=0; r.w=screen->w; r.h=screen->h;
SDL_FillRect(screen,&r,0xF0);
draw_text(0,0,"<ESC> Save/Quit <F1> Add <F2> Delete <F3> Edit <F4> Rename <F5> AddDependent <F6> Config <F7> Copy",0xF0,0xFB);
n=0;
while((i=sqlite3_step(st))==SQLITE_ROW) {
ids[n++]=sqlite3_column_int64(st,0);
i=sqlite3_column_int(st,2);
draw_text(16,8*n,sqlite3_column_text(st,1),0xF0,sqlite3_column_int(st,2)==1?0xF7:0xF2);
draw_text(i==3?24:16,8*n,sqlite3_column_text(st,1),0xF0,"\xF7\xF2\xF6"[i-1]);
if(i==3) draw_text(16,8*n,"+",0xF0,0xFC);
if(8*n+8>screen->h-8) break;
}
SDL_UnlockSurface(screen);
sqlite3_reset(st);
r.y=8; r.h-=8;
scrollbar(&sc,r.h/8,max,0,&r);
SDL_Flip(screen);
|