#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
static void vlogSignature(unsigned char *p, int n, char *zCksum){
unsigned int s0 = 0, s1 = 0;
unsigned int *pI;
int i;
if( n<=16 ){
for(i=0; i<n; i++) sprintf(zCksum+i*2, "%02x", p[i]);
}else{
pI = (unsigned int*)p;
for(i=0; i<n-7; i+=8){
s0 += pI[0] + s1;
s1 += pI[1] + s0;
pI += 2;
}
for(i=0; i<8; i++) sprintf(zCksum+i*2, "%02x", p[i]);
sprintf(zCksum+i*2, "-%08x%08x", s0, s1);
}
}
static void computeSigs(const char *zFilename){
FILE *in = fopen(zFilename, "rb");
unsigned pgsz;
size_t got;
unsigned n;
unsigned char aBuf[50];
unsigned char aPage[65536];
if( in==0 ){
fprintf(stderr, "cannot open \"%s\"\n", zFilename);
return;
}
got = fread(aBuf, 1, sizeof(aBuf), in);
if( got!=sizeof(aBuf) ){
goto endComputeSigs;
}
pgsz = aBuf[16]*256 + aBuf[17];
if( pgsz==1 ) pgsz = 65536;
if( (pgsz & (pgsz-1))!=0 ){
fprintf(stderr, "invalid page size: %02x%02x\n", aBuf[16], aBuf[17]);
goto endComputeSigs;
}
rewind(in);
for(n=1; (got=fread(aPage, 1, pgsz, in))==pgsz; n++){
vlogSignature(aPage, pgsz, aBuf);
printf("%4d: %s\n", n, aBuf);
}
endComputeSigs:
fclose(in);
}
int main(int argc, char **argv){
int i;
for(i=1; i<argc; i++) computeSigs(argv[i]);
return 0;
}