diff options
author | 2003-07-06 22:02:36 +0000 | |
---|---|---|
committer | 2003-07-06 22:02:36 +0000 | |
commit | aeb82612035e635c909e64ee78ff8209bfb3bf4a (patch) | |
tree | 5657e05479560713723d58644c28619a4cab42a8 | |
parent | knf (cedric did not do it right) (diff) | |
download | wireguard-openbsd-aeb82612035e635c909e64ee78ff8209bfb3bf4a.tar.xz wireguard-openbsd-aeb82612035e635c909e64ee78ff8209bfb3bf4a.zip |
Implement -P from GNU diff (like -N but only for files that are missing
from dir1).
-rw-r--r-- | usr.bin/diff/diff.1 | 8 | ||||
-rw-r--r-- | usr.bin/diff/diff.c | 14 | ||||
-rw-r--r-- | usr.bin/diff/diff.h | 4 | ||||
-rw-r--r-- | usr.bin/diff/diffdir.c | 28 |
4 files changed, 32 insertions, 22 deletions
diff --git a/usr.bin/diff/diff.1 b/usr.bin/diff/diff.1 index c555da5ddd0..4fb97ccb52b 100644 --- a/usr.bin/diff/diff.1 +++ b/usr.bin/diff/diff.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: diff.1,v 1.11 2003/07/06 20:48:59 millert Exp $ +.\" $OpenBSD: diff.1,v 1.12 2003/07/06 22:02:36 millert Exp $ .\" .\" Copyright (c) 1980, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -204,6 +204,12 @@ Directory comparison options: .It Fl N If a file is found in only one directory, act as if it was found in the other directory too but was of zero size. +.It Fl P +If a file is found only in +.Ar dir2 , +act as if it was found in +.Ar dir1 +too but was of zero size. .It Fl r Causes application of .Nm diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 6c570cc98e4..eaaf15c629e 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.23 2003/07/06 20:48:59 millert Exp $ */ +/* $OpenBSD: diff.c,v 1.24 2003/07/06 22:02:36 millert Exp $ */ /* * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -21,7 +21,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diff.c,v 1.23 2003/07/06 20:48:59 millert Exp $"; +static const char rcsid[] = "$OpenBSD: diff.c,v 1.24 2003/07/06 22:02:36 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -38,13 +38,13 @@ static const char rcsid[] = "$OpenBSD: diff.c,v 1.23 2003/07/06 20:48:59 millert #include "diff.h" -int aflag, bflag, iflag, Nflag, rflag, sflag, tflag, wflag; +int aflag, bflag, iflag, Nflag, Pflag, rflag, sflag, tflag, wflag; int format, context, status; char *start, *ifdefname, *diffargs; struct stat stb1, stb2; struct excludes *excludes_list; -#define OPTIONS "abC:cD:efhinNrS:stU:uwX:x:" +#define OPTIONS "abC:cD:efhinNPrS:stU:uwX:x:" static struct option longopts[] = { { "text", no_argument, 0, 'a' }, { "ignore-space-change", no_argument, 0, 'b' }, @@ -55,6 +55,7 @@ static struct option longopts[] = { { "ignore-case", no_argument, 0, 'i' }, { "new-file", no_argument, 0, 'N' }, { "rcs", no_argument, 0, 'n' }, + { "unidirectional-new-file", no_argument, 0, 'P' }, { "recursive", no_argument, 0, 'r' }, { "report-identical-files", no_argument, 0, 's' }, { "starting-file", required_argument, 0, 'S' }, @@ -121,6 +122,9 @@ main(int argc, char **argv) case 'n': format = D_NREVERSE; break; + case 'P': + Pflag = 1; + break; case 'r': rflag = 1; break; @@ -314,7 +318,7 @@ usage(void) " diff [-bitw] -C number file1 file2\n" " diff [-bitw] -D string file1 file2\n" " diff [-bitw] -U number file1 file2\n" - " diff [-biNwt] [-c | -e | -f | -n | -u ] [-r] [-s] [-S name]" + " diff [-biNPwt] [-c | -e | -f | -n | -u ] [-r] [-s] [-S name]" " [-X file]\n [-x pattern] dir1 dir2\n"); exit(2); diff --git a/usr.bin/diff/diff.h b/usr.bin/diff/diff.h index 276660f5954..0264115269d 100644 --- a/usr.bin/diff/diff.h +++ b/usr.bin/diff/diff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.h,v 1.15 2003/07/06 20:48:59 millert Exp $ */ +/* $OpenBSD: diff.h,v 1.16 2003/07/06 22:02:36 millert Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -55,7 +55,7 @@ struct excludes { struct excludes *next; }; -extern int aflag, bflag, iflag, Nflag, rflag, sflag, tflag, wflag; +extern int aflag, bflag, iflag, Nflag, Pflag, rflag, sflag, tflag, wflag; extern char *start, *ifdefname; extern int format, context, status, anychange; extern char *tempfiles[], *diffargs; diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c index 6b3ebd01864..659d0346a73 100644 --- a/usr.bin/diff/diffdir.c +++ b/usr.bin/diff/diffdir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffdir.c,v 1.19 2003/07/06 20:48:59 millert Exp $ */ +/* $OpenBSD: diffdir.c,v 1.20 2003/07/06 22:02:36 millert Exp $ */ /* * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -21,7 +21,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.19 2003/07/06 20:48:59 millert Exp $"; +static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.20 2003/07/06 22:02:36 millert Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -42,7 +42,7 @@ static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.19 2003/07/06 20:48:59 mill static int dircompare(const void *, const void *); static int excluded(const char *); -static struct dirent **slurpdir(char *, char **); +static struct dirent **slurpdir(char *, char **, int); static void diffit(struct dirent *, char *, size_t, char *, size_t); /* @@ -80,8 +80,8 @@ diffdir(char *p1, char *p2) } /* get a list of the entries in each directory */ - dp1 = dirp1 = slurpdir(path1, &dirbuf1); - dp2 = dirp2 = slurpdir(path2, &dirbuf2); + dp1 = dirp1 = slurpdir(path1, &dirbuf1, Nflag + Pflag); + dp2 = dirp2 = slurpdir(path2, &dirbuf2, Nflag); if (dirp1 == NULL || dirp2 == NULL) return; @@ -120,8 +120,8 @@ diffdir(char *p1, char *p2) path1, dent1->d_name); dp1++; } else { - /* file only in second dir, only diff if -N */ - if (Nflag) + /* file only in second dir, only diff if -N or -P */ + if (Nflag || Pflag) diffit(dent2, path1, dirlen1, path2, dirlen2); else if (format == D_NORMAL || format == D_CONTEXT || format == D_UNIFIED) @@ -149,7 +149,7 @@ diffdir(char *p1, char *p2) * returned via bufp. Caller is responsible for free()ing both of these. */ static struct dirent ** -slurpdir(char *path, char **bufp) +slurpdir(char *path, char **bufp, int enoentok) { char *buf, *ebuf, *cp; size_t bufsize; @@ -162,7 +162,7 @@ slurpdir(char *path, char **bufp) if ((fd = open(path, O_RDONLY, 0644)) == -1) { static struct dirent *dummy; - if (!Nflag) { + if (!enoentok || errno != ENOENT) { warn("%s", path); return (NULL); } @@ -237,7 +237,7 @@ diffit(struct dirent *dp, char *path1, size_t plen1, char *path2, size_t plen2) strlcpy(path1 + plen1, dp->d_name, MAXPATHLEN - plen1); if (stat(path1, &stb1) != 0) { - if (!Nflag || errno != ENOENT) { + if (!(Nflag || Pflag) || errno != ENOENT) { warn("%s", path1); return; } @@ -259,12 +259,12 @@ diffit(struct dirent *dp, char *path1, size_t plen1, char *path2, size_t plen2) stb1.st_mode = stb2.st_mode; if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { - /* XXX GNU diff always prints this for dirs XXX */ - if (format != D_EDIT) - printf("Common subdirectories: %s and %s\n", - path1, path2); if (rflag) diffdir(path1, path2); + else if (format != D_EDIT) + /* XXX GNU diff always prints this for dirs XXX */ + printf("Common subdirectories: %s and %s\n", + path1, path2); return; } diffreg(path1, path2, flags); |