Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!elroy!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.sources.bugs Subject: cdiff 1.1 patch #4 Summary: This is an official patch for cdiff 1.1. Please apply it. Message-ID: <3843@jpl-devvax.JPL.NASA.GOV> Date: 6 Jan 89 20:37:36 GMT Organization: Jet Propulsion Laboratory Lines: 182 System: cdiff version 1.1 Patch #: 4 Priority: LOW Subject: now passes diff switches through Subject: handles directories better Subject: now quotes filenames passed to subshell From: Amos Shapir and Francois Pinard Description: cdiff didn't pass diff switches through. Now it does. Now one or the other of the filenames can be a directory holding a different version by the same name. The filenames passed to diff are now quoted to prevent interpretation of shell metacharacters (in particular, #). Fix: From rn, say "| patch -p -N -d DIR", where DIR is your cdiff source directory. Outside of rn, say "cd DIR; patch -p -N #define PATCHLEVEL 4 Index: cdiff.c Prereq: 1.1.1.3 *** cdiff.c.old Fri Jan 6 12:31:52 1989 --- cdiff.c Fri Jan 6 12:31:53 1989 *************** *** 1,10 **** ! static char rcsid[] = "$Header: cdiff.c,v 1.1.1.3 88/08/04 16:08:18 lwall Exp $"; /* cdiff - turns a regular diff into a new-style context diff * * Usage: cdiff file1 file2 * * $Log: cdiff.c,v $ * Revision 1.1.1.3 88/08/04 16:08:18 lwall * patch3: include => * --- 1,15 ---- ! static char rcsid[] = "$Header: cdiff.c,v 1.1.1.4 89/01/06 12:31:41 lwall Locked $"; /* cdiff - turns a regular diff into a new-style context diff * * Usage: cdiff file1 file2 * * $Log: cdiff.c,v $ + * Revision 1.1.1.4 89/01/06 12:31:41 lwall + * patch4: now passes diff switches through + * patch4: handles directories better + * patch4: now quotes filenames passed to subshell + * * Revision 1.1.1.3 88/08/04 16:08:18 lwall * patch3: include => * *************** *** 25,31 **** #include #include ! char buf[512]; FILE *inputfp, *oldfp, *newfp; --- 30,36 ---- #include #include ! char buf[512] = "diff "; FILE *inputfp, *oldfp, *newfp; *************** *** 77,82 **** --- 82,89 ---- } if (argv[0][1] == 'c') context = atoi(argv[0]+2); + else + sprintf(buf+strlen(buf), "%s ", argv[0]); } if (argc != 2) { *************** *** 87,113 **** old = argv[0]; new = argv[1]; ! sprintf(buf,"diff %s %s", old, new); inputfp = popen(buf, "r"); if (!inputfp) { ! fprintf(stderr, "Can't execute diff %s %s\n", old, new); exit(1); } oldfp = fopen(old,"r"); if (!oldfp) { fprintf(stderr, "Can't open %s\n", old); exit(1); } newfp = fopen(new,"r"); if (!newfp) { fprintf(stderr, "Can't open %s\n", new); exit(1); } - - fstat(fileno(oldfp),&statbuf); - printf("*** %s\t%s", old, ctime(&statbuf.st_mtime)); - fstat(fileno(newfp),&statbuf); printf("--- %s\t%s", new, ctime(&statbuf.st_mtime)); preoldend = -1000; --- 94,130 ---- old = argv[0]; new = argv[1]; ! sprintf(buf+strlen(buf), "'%s' '%s'", old, new); inputfp = popen(buf, "r"); if (!inputfp) { ! fprintf(stderr, "Can't execute %s\n", buf); exit(1); } + stat(old,&statbuf); + if((statbuf.st_mode&S_IFMT) == S_IFDIR) { + sprintf(buf, "%s/%s", old, new); + old = buf; + stat(old,&statbuf); + } oldfp = fopen(old,"r"); if (!oldfp) { fprintf(stderr, "Can't open %s\n", old); exit(1); } + printf("*** %s\t%s", old, ctime(&statbuf.st_mtime)); + + stat(new,&statbuf); + if((statbuf.st_mode&S_IFMT) == S_IFDIR) { + sprintf(buf, "%s/%s", new, old); + new = buf; + stat(new,&statbuf); + } newfp = fopen(new,"r"); if (!newfp) { fprintf(stderr, "Can't open %s\n", new); exit(1); } printf("--- %s\t%s", new, ctime(&statbuf.st_mtime)); preoldend = -1000;