#include "m.h" #include #include #include #include #include #define bsizBy 512 static b32 * fb, Much; static int zoc1, zoc2; b32 GBlc=0; static b32 zap_count=0; static b32 IGBl; static FILE * in; static b32 grunge[4]; static long W; static b32 bgary[8]/* .... */; sx * LM; static void (* rlm)(b32, b32); //static b32 e(char C * C m, b32 C v){static int fuse = 30000; // if(Do) {if(!--fuse) bitch("Too much!"); // fprintf(out, "X:%s, %08lx\n", m, v);} return v;} #define s (B/8-15) static uchar buf[s]; static b32 y, z, a, b; static void zreg(){{int j; for(j=0; j> (L?0:24) ^ c; a = (a SA 8 | b LA 24) ^ tail[d].l; b = (b SA 8 | (b32)buf[bx] << (L?24:0)) ^ (tail[d].r&~(255L<<(L?24:0))); buf[bx] = y >> (L?0:24); if (++bx==s) bx = 0; return tail[d].r >> (L?24:0);}} static int bi; int ret(int C i){if(constant) exit(-99); return i;} /* Get Another Word: gaw */ /* This routine returns smeared data ad-infinitum by zero padding the file. */ #define zo 1 /* zo should be 0 for simple version and 1 for "Zero Optimization". The effects of scan do not depend on zo. Imagine zo to be zero before studying the case where zo is 1. With this optimization we get a speed factor of about 100 for long streches of zero as in some core files.*/ void finit(){fb = (b32 *)core(bsizBy, "File buffer"); LM = (sx *)core((size_t)LM_siz*sizeof(sx), "Mark store");} static b32 min(b32 C a, b32 C b){return a>8 | z>>24; bgary[bi&7] = z; while(j--) z = z SA 8 | (b32)X8(z >> (L?0:24))<<(L?24:0); grunge[bi&3] = z; return z;}} static b32 max(long x, long y){return xB) {long p = IGBl+((wh-B)>>12); if(j==target) {{int j; for(j=0; j<8; ++j) fprintf(out, "%08lx ", bgary[j]);} fprintf(out,"\n Target found at bit 0x%08lx, blk=0x%lx, bi=%d\n", wh, p, bi);} fprintf(out,cen("L:%08lx, %08lx, %ld\n"), j, wh, p); {LM[mcnt].sig = j; LM[mcnt].Bl = p; #if Lbug LM[mcnt].inode = inode; #endif if(++mcnt == LM_siz-1) bitch("Exhausted reserved mark space!");}}} static int Shadow; static void so(b32 Z){while(Z) {b32 z = L ? Z&-Z : Z; int y=0; if(!(z&0xffff0000)) {y+=16; z<<=16;} if(!(z&0xff000000)) {y+= 8; z<<=8;} if(!(z&0xf0000000)) {y+= 4; z<<=4;} if(!(z&0xc0000000)) {y+= 2; z<<=2;} if(!(z&0x80000000)) {y+= 1; } if(0){int x; for(x=0; x<4; ++x) fprintf(out,"%08lx ", grunge[x]);} if(L) y = 31-y; (* rlm)(32*W+y, y<=24 ? y==24 ? grunge[(W+2)&3] : grunge[(W+1)&3] SA (8+y) | grunge[(W+2)&3] LA (24-y) : grunge[(W+2)&3] SA (y-24) | grunge[(W+3)&3] LA (56-y)); if(Shadow) break; Z &= ~(1L<<(L?y:(31-y)));} ++W;} static void scan(b32 C much, int C shadow){Much=much; bi = bsizBy/4; W=0; zreg(); zoc1=zoc2=0; Shadow = shadow; if(in) {b32 C Ax = gaw(), Bx = gaw(), Cx = gaw(); b32 Dx = gaw(), Ay = Ax & (Ax SA 4 | Bx LA 28), By = Bx & (Bx SA 4 | Cx LA 28), Cy = Cx & (Cx SA 4 | Dx LA 28), Az = Ay & (Ay SA 2 | By LA 30), Bz = By & (By SA 2 | Cy LA 30); so(Az & (Az SA 1 | Bz LA 31)); while(W=B) { where = w; longjmp(env, 1);}} int vernier(fport * C p, b32 C bn, fport C * C dp) {rlm = sm; OBi = dp && p->giBlc == dp->giBlc ? dp->offsetBi - (bn<<12): -1; if(p->sig == target) fprintf(out, "ver: bn=%ld, OBi=0x%lx\n", bn, OBi); if(setjmp(env)) goto got; sought = p->sig; assert(in = p->in); if(fseek(p->in, bn*bsizBy, 0)) {fprintf(out,"Error seeking in file %s, at block %ld.\n", qs(p->name), bn); return ret(0);} if(0)fprintf(out,"Scanning file %s at block %ld\n", qs(p->name), bn); scan(bsizBy/4 + (B+P)/32, 0); fprintf(out,cen("Vernier fault, file: %s, sig=%08lx, bn=%ld\n"), qs(p->name), p->sig, bn); return ret(0); got: p->offsetBi = 8*(bn*bsizBy) + where; return 1;} static int sc(C void * a, C void * b) {if(Ebug) {b32 C x = rW(((sx *)a)->sig), y = rW(((sx *)b)->sig); return xsig < ((sx *)b)->sig ? -1 : ((sx *)b)->sig < ((sx *)a)->sig ? 1 : 0;} static b32 startBl, stopBl, startBi, stopBi; static void forget_sam(b32 C w, b32 C m){if(startBi < w && w < stopBi) {sx * hp = (sx *)bsearch((void *)&m, (void *)(LM+1), mcnt-2, sizeof(sx), sc); if(m==target) fprintf(out,"forget_sam at w=0x%08lx, m=0x%08lx, hp=%p\n", w, m, hp); if(hp){sx * lp = hp; int cn = 0; while((lp-1)->sig == m) --lp; while((hp+1)->sig == m && (hp+1)->Bl != -5) ++hp; while(hp->Bl == -5 && hp->sig == m) --hp; if(m==target) fprintf(out,"base range=%d:%d, scope=[%ld,%ld]\n", lp-LM, hp-LM, startBl, stopBl); for(; lp<= hp; ++lp) {while(startBl <= lp->Bl && lp->Bl <= stopBl) {++cn; if(m==target)fprintf(out,"Zapping LM[%d] = {0x%08lx,%08lx}\n", lp-LM, lp->sig, lp->Bl); *lp = *hp; hp->Bl = -5; --hp; ++zap_count;}}} else fprintf(out,cen("Could not find mark %08lx in base from position %lx.\n") ,m,w);}} void forget(fport C * p, b32 C startBy, b32 C stopBy) {b32 C Rstart = max(startBy-B/8, 0); rlm = forget_sam; assert(in = p->in); if(0)fprintf(out,"forgetting in file %s between bytes %08lx and %08lx.\n", qs(p->name), Rstart, stopBy); startBl = (max(0,startBy-B/8)>>9)+p->giBlc; stopBl = 1+(stopBy>>9)+p->giBlc; startBi = (startBy - Rstart)<<(3-1); stopBi = (stopBy - Rstart)<<(3+1); if(fseek(p->in, Rstart, 0)) {perror("Seeking2"); exit(-1);} scan(((stopBy-startBy+B/8)>>2) + 5, 0); if(work && LM[work].Bl != -5){assert(!fseek(p->in, 0, 0)); scan(1L<<30, 0); printf("After entire rescan LM[%ld] is {0x%08lx,%ld}\n", work, LM[work].sig, LM[work].Bl);}} void X8pr(){int i; zreg(); for(i=0; i