#include #include #include #include "m.h" b32 chr_cnt=0, mcnt=1; b32 fcnt=0; int Eof; b32 saved = 0, total = 0; b32 work = 0; void Stat(){static double ot = 0; C double t = fcnt + chr_cnt/20000.; if(t-ot>100){ot=t; fprintf(out,cen("P: %ld marks in %ldK char from %ld files\n"), mcnt, chr_cnt>>10, fcnt);}} void zacc(b32 * C x){int i; for(i=0; ia[i]=0;} void sla(acc ac, int C c){int i; for(i=0; i> 31; ac[i] <<= 1;}} void sl(str * x){sla(x->a, ss);} void ex(int C d){exit(-3);} void bitch(char C * C s){ex(fprintf(out,"%s: Bye.\n", s));} void * core(size_t m, char * who){void * C p = malloc(m); if(p) return p; fprintf(out,"%s exhausted memory!\n", who); exit(-1);} C char * cen(char C * C s){static C char * empty = ""; return strchr(suppr, s[0]) ? empty : s;} /* The routine sb Searches Backwards for the first difference between two files. Argument diff is a difference in bits between the string addresses that have produced matching signatures. diff is not negative. wn is the word number in file x where the match was discovered. The matching part from file y is at least as large an address. sb returns the byte offset within file x of the byte before which the files differ. */ static b32 sb(sstream * C x, sstream * C y, b32 C diff, b32 C wn) {uchar a[512], b[512]; long vbn = wn>>7, indx = wn&(128-1); while(vbn>=0){sread(a, x, vbn<<12); sread(b, y, (vbn<<12) + diff); {int j; for(j=indx; j>=0; --j) if(((b32 *)a)[j] != ((b32 *)b)[j]) break; if(j>=0) {j =4*j+3; while(a[j] == b[j]) --j; return (vbn<<9)+j+1;} --vbn;} indx = 128-1;} return 0;} static int span(fport C * C X, fport C * C Y, sstream * C x, sstream * C y) {if(X->offsetBi == Y->offsetBi && X->giBlc == Y->giBlc) {fprintf(out, "Comparing point 0x%08lx in file %s with itself. (sig=%08lx)\n", X->offsetBi, qs(X->name), X->sig); exit(-22);} {b32 C d = Y->offsetBi - X->offsetBi; b32 C startBy = sb(x, y, d, X->offsetBi>>5); b32 stopBy = X->offsetBi>>3; {uchar a[512], b[512]; b32 r = 0; Eof=0; while(!Eof){sread(a, x, X->offsetBi + r); sread(b, y, Y->offsetBi + r); {int k; for(k=0; k<128; ++k) if(((b32 *)a)[k] != ((b32 *)b)[k]) break; if(k<128) {k=4*k; while (a[k] == b[k]) ++k; stopBy += k; break;}} r += 4096;} stopBy += r>>3; if(stopBy>startBy+20){ fprintf(out,"File: %s at 0X%lX,\nfile: %s at 0X%lX", qs((uchar *)x->name), startBy, qs((uchar *)y->name), startBy + d/8); if(d&7) fprintf(out," plus %ld bits", d&7); fprintf(out," for 0X%lX bytes.\n", stopBy-startBy+1); forget(X, startBy, stopBy); saved += stopBy-startBy; return 1;} else return 0;}}} static void ze(b32 C k, int C noise) {b32 j = k; if(constant && !noise){printf("Things are changing!!\n"); exit(0);} while(LM[j+1].sig == LM[k].sig && LM[j+1].Bl != -5) ++j; LM[k].Bl = LM[j].Bl; LM[j].Bl = -5;} void find_match(){fport a, b; b32 k; for(k=1; k