-.\" $OpenBSD: diff.1,v 1.43 2014/02/13 14:52:53 jmc Exp $
+.\" $OpenBSD: diff.1,v 1.44 2015/10/05 20:15:00 millert Exp $
.\"
.\" Copyright (c) 1980, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" @(#)diff.1 8.1 (Berkeley) 6/30/93
.\"
-.Dd $Mdocdate: February 13 2014 $
+.Dd $Mdocdate: October 5 2015 $
.Dt DIFF 1
.Os
.Sh NAME
.Nd differential file and directory comparator
.Sh SYNOPSIS
.Nm diff
-.Op Fl abdilpTtw
+.Op Fl abdipTtw
.Oo
.Fl c | e | f |
.Fl n | q | u
.Ar label
instead of the first (and second, if this option is specified twice)
file name and time in the context or unified diff header.
-.It Fl l
-Long output format; each text file
-.Nm diff Ns \'d
-is piped through
-.Xr pr 1
-to paginate it;
-other differences are remembered and summarized
-after all text file differences are reported.
.It Fl p
With unified and context diffs, show with each change
the first 40 characters of the last line before the context beginning
-/* $OpenBSD: diff.c,v 1.61 2015/10/05 15:42:54 semarie Exp $ */
+/* $OpenBSD: diff.c,v 1.62 2015/10/05 20:15:00 millert Exp $ */
/*
* Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
#include <err.h>
#include <errno.h>
#include <getopt.h>
-#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "diff.h"
#include "xmalloc.h"
-int lflag, Nflag, Pflag, rflag, sflag, Tflag;
+int Nflag, Pflag, rflag, sflag, Tflag;
int diff_format, diff_context, status;
char *start, *ifdefname, *diffargs, *label[2], *ignore_pats;
struct stat stb1, stb2;
{ "forward-ed", no_argument, 0, 'f' },
{ "ignore-matching-lines", required_argument, 0, 'I' },
{ "ignore-case", no_argument, 0, 'i' },
- { "paginate", no_argument, 0, 'l' },
{ "label", required_argument, 0, 'L' },
{ "new-file", no_argument, 0, 'N' },
{ "rcs", no_argument, 0, 'n' },
else
usage();
break;
- case 'l':
- lflag = 1;
- signal(SIGPIPE, SIG_IGN);
- break;
case 'N':
Nflag = 1;
break;
argc -= optind;
argv += optind;
- if (lflag == 0) {
- if (getenv("TMPDIR")) {
- if (tame("stdio rpath wpath cpath", NULL) == -1)
- err(1, "tame");
- } else {
- if (tame("stdio rpath tmppath", NULL) == -1)
- err(1, "tame");
- }
+ if (getenv("TMPDIR")) {
+ if (tame("stdio rpath wpath cpath", NULL) == -1)
+ err(1, "tame");
+ } else {
+ if (tame("stdio rpath tmppath", NULL) == -1)
+ err(1, "tame");
}
+
/*
* Do sanity checks, fill in stb1 and stb2 and call the appropriate
* driver routine. Both drivers use the contents of stb1 and stb2.
print_status(int val, char *path1, char *path2, char *entry)
{
switch (val) {
- case D_ONLY:
- print_only(path1, strlen(path1), entry);
- break;
- case D_COMMON:
- printf("Common subdirectories: %s%s and %s%s\n",
- path1, entry, path2, entry);
- break;
case D_BINARY:
printf("Binary files %s%s and %s%s differ\n",
path1, entry, path2, entry);
usage(void)
{
(void)fprintf(stderr,
- "usage: diff [-abdilpTtw] [-c | -e | -f | -n | -q | -u] [-I pattern] [-L label]\n"
+ "usage: diff [-abdipTtw] [-c | -e | -f | -n | -q | -u] [-I pattern] [-L label]\n"
" file1 file2\n"
- " diff [-abdilpTtw] [-I pattern] [-L label] -C number file1 file2\n"
- " diff [-abdiltw] [-I pattern] -D string file1 file2\n"
- " diff [-abdilpTtw] [-I pattern] [-L label] -U number file1 file2\n"
- " diff [-abdilNPprsTtw] [-c | -e | -f | -n | -q | -u] [-I pattern]\n"
+ " diff [-abdipTtw] [-I pattern] [-L label] -C number file1 file2\n"
+ " diff [-abditw] [-I pattern] -D string file1 file2\n"
+ " diff [-abdipTtw] [-I pattern] [-L label] -U number file1 file2\n"
+ " diff [-abdiNPprsTtw] [-c | -e | -f | -n | -q | -u] [-I pattern]\n"
" [-L label] [-S name] [-X file] [-x pattern] dir1 dir2\n");
exit(2);
-/* $OpenBSD: diff.h,v 1.32 2009/06/07 08:39:13 ray Exp $ */
-/*-
+
+/*ROR
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
#define D_SAME 0 /* Files are the same */
#define D_DIFFER 1 /* Files are different */
#define D_BINARY 2 /* Binary files are different */
-#define D_COMMON 3 /* Subdirectory common to both dirs */
-#define D_ONLY 4 /* Only exists in one directory */
-#define D_MISMATCH1 5 /* path1 was a dir, path2 a file */
-#define D_MISMATCH2 6 /* path1 was a file, path2 a dir */
-#define D_ERROR 7 /* An error occurred */
-#define D_SKIPPED1 8 /* path1 was a special file */
-#define D_SKIPPED2 9 /* path2 was a special file */
+#define D_MISMATCH1 3 /* path1 was a dir, path2 a file */
+#define D_MISMATCH2 4 /* path1 was a file, path2 a dir */
+#define D_SKIPPED1 5 /* path1 was a special file */
+#define D_SKIPPED2 6 /* path2 was a special file */
struct excludes {
char *pattern;
struct excludes *next;
};
-extern int lflag, Nflag, Pflag, rflag, sflag, Tflag;
+extern int Nflag, Pflag, rflag, sflag, Tflag;
extern int diff_format, diff_context, status;
extern char *start, *ifdefname, *diffargs, *label[2], *ignore_pats;
extern struct stat stb1, stb2;
-/* $OpenBSD: diffdir.c,v 1.44 2015/09/25 16:16:26 tedu Exp $ */
+/* $OpenBSD: diffdir.c,v 1.45 2015/10/05 20:15:00 millert Exp $ */
/*
* Copyright (c) 2003, 2010 Todd C. Miller <Todd.Miller@courtesan.com>
if (Nflag)
diffit(dent1, path1, dirlen1, path2, dirlen2,
flags);
- else if (lflag)
- dent1->d_status |= D_ONLY;
else
print_only(path1, dirlen1, dent1->d_name);
dp1++;
if (Nflag || Pflag)
diffit(dent2, path1, dirlen1, path2, dirlen2,
flags);
- else if (lflag)
- dent2->d_status |= D_ONLY;
else
print_only(path2, dirlen2, dent2->d_name);
dp2++;
}
}
- if (lflag) {
- path1[dirlen1] = '\0';
- path2[dirlen2] = '\0';
- for (dp1 = dirp1; (dent1 = *dp1) != NULL; dp1++) {
- print_status(dent1->d_status, path1, path2,
- dent1->d_name);
- }
- for (dp2 = dirp2; (dent2 = *dp2) != NULL; dp2++) {
- if (dent2->d_status == D_ONLY)
- print_status(dent2->d_status, path2, NULL,
- dent2->d_name);
- }
- }
closem:
if (dirp1 != NULL) {
if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) {
if (rflag)
diffdir(path1, path2, flags);
- else if (lflag)
- dp->d_status |= D_COMMON;
else
printf("Common subdirectories: %s and %s\n",
path1, path2);
dp->d_status = D_SKIPPED2;
else
dp->d_status = diffreg(path1, path2, flags);
- if (!lflag)
- print_status(dp->d_status, path1, path2, "");
+ print_status(dp->d_status, path1, path2, "");
}
/*
-/* $OpenBSD: diffreg.c,v 1.87 2015/09/25 16:16:26 tedu Exp $ */
+/* $OpenBSD: diffreg.c,v 1.88 2015/10/05 20:15:00 millert Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <paths.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <limits.h>
#include "diff.h"
-#include "pathnames.h"
#include "xmalloc.h"
#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
diffreg(char *file1, char *file2, int flags)
{
FILE *f1, *f2;
- int i, rval, ostdout = -1;
- pid_t pid = -1;
+ int i, rval;
f1 = f2 = NULL;
rval = D_SAME;
status |= 1;
goto closem;
}
- if (lflag) {
- /* redirect stdout to pr */
- int pfd[2];
- char *header;
- char *prargv[] = { "pr", "-h", NULL, "-f", NULL };
-
- xasprintf(&header, "%s %s %s", diffargs, file1, file2);
- prargv[2] = header;
- fflush(stdout);
- rewind(stdout);
- pipe(pfd);
- switch ((pid = fork())) {
- case -1:
- warnx("No more processes");
- status |= 2;
- free(header);
- rval = D_ERROR;
- goto closem;
- case 0:
- /* child */
- if (pfd[0] != STDIN_FILENO) {
- dup2(pfd[0], STDIN_FILENO);
- close(pfd[0]);
- }
- close(pfd[1]);
- execv(_PATH_PR, prargv);
- _exit(127);
- default:
- /* parent */
- if (pfd[1] != STDOUT_FILENO) {
- ostdout = dup(STDOUT_FILENO);
- dup2(pfd[1], STDOUT_FILENO);
- close(pfd[1]);
- }
- close(pfd[0]);
- rewind(stdout);
- free(header);
- }
- }
prepare(0, f1, stb1.st_size, flags);
prepare(1, f2, stb2.st_size, flags);
ixnew = xreallocarray(ixnew, len[1] + 2, sizeof(*ixnew));
check(f1, f2, flags);
output(file1, f1, file2, f2, flags);
- if (ostdout != -1) {
- int wstatus;
-
- /* close the pipe to pr and restore stdout */
- fflush(stdout);
- rewind(stdout);
- if (ostdout != STDOUT_FILENO) {
- close(STDOUT_FILENO);
- dup2(ostdout, STDOUT_FILENO);
- close(ostdout);
- }
- waitpid(pid, &wstatus, 0);
- }
closem:
if (anychange) {
status |= 1;
+++ /dev/null
-/* $OpenBSD: pathnames.h,v 1.10 2003/07/09 00:07:44 millert Exp $ */
-
-/*
- * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Sponsored in part by the Defense Advanced Research Projects
- * Agency (DARPA) and Air Force Research Laboratory, Air Force
- * Materiel Command, USAF, under agreement number F39502-99-1-0512.
- */
-
-#include <paths.h>
-
-#define _PATH_PR "/usr/bin/pr"