2 #pragma ident "%Z%%M% %I% %E% SMI"
5 ** A utility for printing all or part of an SQLite database file.
16 static int pagesize
= 1024;
18 static int mxPage
= 0;
20 static void out_of_memory(void){
21 fprintf(stderr
,"Out of memory...\n");
25 static print_page(int iPg
){
28 aData
= malloc(pagesize
);
29 if( aData
==0 ) out_of_memory();
30 lseek(db
, (iPg
-1)*pagesize
, SEEK_SET
);
31 read(db
, aData
, pagesize
);
32 fprintf(stdout
, "Page %d:\n", iPg
);
33 for(i
=0; i
<pagesize
; i
+= 16){
34 fprintf(stdout
, " %03x: ",i
);
36 fprintf(stdout
,"%02x ", aData
[i
+j
]);
39 fprintf(stdout
,"%c", isprint(aData
[i
+j
]) ? aData
[i
+j
] : '.');
46 int main(int argc
, char **argv
){
49 fprintf(stderr
,"Usage: %s FILENAME ?PAGE? ...\n", argv
[0]);
52 db
= open(argv
[1], O_RDONLY
);
54 fprintf(stderr
,"%s: can't open %s\n", argv
[0], argv
[1]);
58 mxPage
= sbuf
.st_size
/pagesize
+ 1;
61 for(i
=1; i
<=mxPage
; i
++) print_page(i
);
64 for(i
=2; i
<argc
; i
++){
67 iStart
= strtol(argv
[i
], &zLeft
, 0);
68 if( zLeft
&& strcmp(zLeft
,"..end")==0 ){
70 }else if( zLeft
&& zLeft
[0]=='.' && zLeft
[1]=='.' ){
71 iEnd
= strtol(&zLeft
[2], 0, 0);
75 if( iStart
<1 || iEnd
<iStart
|| iEnd
>mxPage
){
77 "Page argument should be LOWER?..UPPER?. Range 1 to %d\n",
81 while( iStart
<=iEnd
){