#include #include #include #include #define C 3 #define RANGE 30 #define LEN 255 #define INF 16384 char *text[2][RANGE]; long lineno[2] = {1, 1}; /*no. of 1st stored line in each file*/ int ntext[2]; /*number of stored lines in each*/ long n0,n1; /*scan pointer in each*/ int bflag; int debug = 0; FILE *file[2]; /* return pointer to line n of file f*/ char *getl(f,n) long n; { register char *t; char *malloc(); register delta, nt; again: delta = n - lineno[f]; nt = ntext[f]; if(delta<0) progerr("1"); if(deltant) progerr("2"); if(nt>=RANGE) progerr("3"); if(feof(file[f])) return(NULL); t = text[f][nt]; if(t==0) { t = text[f][nt] = malloc(LEN+1); if(t==NULL) if(hardsynch()) goto again; else progerr("5"); } t = fgets(t,LEN,file[f]); if(t!=NULL) ntext[f]++; return(t); } /*remove thru line n of file f from storage*/ clrl(f,n) long n; { register i,j; j = n-lineno[f]+1; for(i=0;i+j=0&&b>=0) printf("---\n"); for(i=0;i<=b;i++) { s = getl(1,n1+i); if(s==NULL) break; printf("> %s",s); clrl(1,n1+i); } n1 += i-1; return(1); } change(a,b,c,d,s) long a,c; char *s; { range(a,b); printf("%s",s); range(c,d); printf("\n"); } range(a,b) long a; { if(b==INF) printf("%ld,$",a); else if(b==0) printf("%ld",a); else printf("%ld,%ld",a,a+b); } cmp(s,t) char *s,*t; { if(debug) printf("%s:%s\n",s,t); for(;;){ if(bflag&&isspace(*s)&&isspace(*t)) { while(isspace(*++s)) ; while(isspace(*++t)) ; } if(*s!=*t||*s==0) break; s++; t++; } return(*s-*t); } FILE *dopen(f1,f2) char *f1,*f2; { FILE *f; char b[100],*bptr,*eptr; struct stat statbuf; if(cmp(f1,"-")==0) if(cmp(f2,"-")==0) error("can't do - -",""); else return(stdin); if(stat(f1,&statbuf)==-1) error("can't access ",f1); if((statbuf.st_mode&S_IFMT)==S_IFDIR) { for(bptr=b;*bptr= *f1++;bptr++) ; *bptr++ = '/'; for(eptr=f2;*eptr;eptr++) if(*eptr=='/'&&eptr[1]!=0&&eptr[1]!='/') f2 = eptr+1; while(*bptr++= *f2++) ; f1 = b; } f = fopen(f1,"r"); if(f==NULL) error("can't open",f1); return(f); } progerr(s) char *s; { error("program error ",s); } error(s,t) char *s,*t; { fprintf(stderr,"diffh: %s%s\n",s,t); exit(1); } /*stub for resychronization beyond limits of text buf*/ hardsynch() { change(n0,INF,n1,INF,"c"); printf("---change record omitted\n"); error("can't resynchronize",""); return(0); }