compress 4.1 file deletion fixes
David J. MacKenzie
djm at eng.umd.edu
Sat Jun 29 05:23:09 AEST 1991
> Pardon the ignorance, but what kind of diff format is the one above?
> Larry Wall's patch doesn't seem to recognise it.
Sorry, I forgot to mention it. It's a unified diff, produced by GNU
diff 1.15. It's like context format except that it omits duplicate
context lines to save space. If you can anonymous ftp,
prep.ai.mit.edu:pub/gnu/patch-2.0.12u4.tar.Z is a version of patch
that recognizes unified diffs. If not, here is a short program called
unipatch that converts unified diffs to context diffs. It came from
comp.sources.misc "v14i070: Unified context diff tools" plus a patch
in comp.sources.bugs. You'll likely be seeing more unified diffs on
the net as time goes on, so it's worth while having programs that can
deal with them.
/*
A filter to turn a unidiff into a degenerate context diff (no '!'s)
for patch. Author: davison at dri.com (uunet!drivax!davison).
*/
#include <stdio.h>
#define ERR(a) {fputs(a,stderr);exit(1);}
struct Ln {
struct Ln *lk;
char t;
char s[1];
} r,*h,*ln;
char *malloc();
main()
{
char bf[2048],*cp,ch;
long os,ol,ns,nl,ne,lncnt=0;
for(;;){
for(;;){
if(!fgets(bf,sizeof bf,stdin)) exit(0);
lncnt++;
if(!strncmp(bf,"@@ -",4)) break;
if(!strncmp(bf,"+++ ",4)) printf("***%s",bf+3);
else fputs(bf,stdout);
}
if(sscanf(bf+4,"%ld,%ld +%ld,%ld %c",&os,&ol,&ns,&nl,&ch)!=5||ch!='@')
goto bad;
r.lk=0, h= &r, ne=ns+nl-1;
printf("***************\n*** %ld,%ld ****\n",os,os+ol-(os>0));
while(ol||nl){
if(!fgets(bf,sizeof bf,stdin)){
if(nl>2) ERR("Unexpected end of file.\n");
strcpy(bf," \n");
}
lncnt++;
if(*bf=='\t'||*bf=='\n')
ch=' ', cp=bf;
else
ch= *bf, cp=bf+1;
switch(ch){
case'-':if(!ol--) goto bad;
printf("- %s",cp);
break;
case'=':ch=' ';
case' ':if(!ol--) goto bad;
printf(" %s",cp);
case'+':if(!nl--) goto bad;
ln = (struct Ln*)malloc(sizeof(*ln)+strlen(cp));
if(!ln) ERR("Out of memory!\n");
ln->lk=0, ln->t=ch, strcpy(ln->s,cp);
h->lk=ln, h=ln;
break;
default:
bad: fprintf(stderr,"Malformed unidiff at line %ld: ",lncnt);
ERR(bf);
}
}
printf("--- %ld,%ld ----\n",ns,ne);
for(ln=r.lk;ln;ln=h){
printf("%c %s",ln->t,ln->s);
h=ln->lk;
free(ln);
}
}
}
--
David J. MacKenzie <djm at eng.umd.edu> <djm at ai.mit.edu>
More information about the Alt.sources.patches
mailing list