2 #pragma ident "%Z%%M% %I% %E% SMI"
5 ** A utility for printing an SQLite database journal.
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 read(db
, aData
, pagesize
);
31 fprintf(stdout
, "Page %d:\n", iPg
);
32 for(i
=0; i
<pagesize
; i
+= 16){
33 fprintf(stdout
, " %03x: ",i
);
35 fprintf(stdout
,"%02x ", aData
[i
+j
]);
38 fprintf(stdout
,"%c", isprint(aData
[i
+j
]) ? aData
[i
+j
] : '.');
45 int main(int argc
, char **argv
){
49 unsigned char zBuf
[10];
50 unsigned char zBuf2
[sizeof(u
)];
52 fprintf(stderr
,"Usage: %s FILENAME\n", argv
[0]);
55 db
= open(argv
[1], O_RDONLY
);
57 fprintf(stderr
,"%s: can't open %s\n", argv
[0], argv
[1]);
62 read(db
, &u
, sizeof(u
));
63 printf("Records in Journal: %u\n", u
);
64 read(db
, &u
, sizeof(u
));
65 printf("Magic Number: 0x%08x\n", u
);
67 read(db
, zBuf2
, sizeof(zBuf2
));
68 u
= zBuf2
[0]<<24 | zBuf2
[1]<<16 | zBuf2
[2]<<8 | zBuf2
[3];
69 printf("Database Size: %u\n", u
);
70 while( read(db
, zBuf2
, sizeof(zBuf2
))==sizeof(zBuf2
) ){
71 u
= zBuf2
[0]<<24 | zBuf2
[1]<<16 | zBuf2
[2]<<8 | zBuf2
[3];
74 read(db
, &u
, sizeof(u
));
75 printf("Checksum: 0x%08x\n", u
);