Page MenuHomeFreeBSD

D31626.id93987.diff
No OneTemporary

D31626.id93987.diff

Index: usr.bin/diff3/diff3.1
===================================================================
--- usr.bin/diff3/diff3.1
+++ usr.bin/diff3/diff3.1
@@ -38,7 +38,12 @@
.Nd 3-way differential file comparison
.Sh SYNOPSIS
.Nm diff3
-.Op Fl 3aEeXx
+.Op Fl 3aEeiXx
+.Op Fl Fl diff-program Ar program
+.Op Fl Fl strip-trailing-cr
+.Op Fl L | Fl Fl label Ar label1
+.Op Fl L | Fl Fl label Ar label2
+.Op Fl L | Fl Fl label Ar label3
.Ar file1 file2 file3
.Sh DESCRIPTION
The
@@ -60,15 +65,16 @@
.Pp
The options are as follows:
.Bl -tag -width "-E, -X"
-.It Fl 3
+.It Fl 3 , Fl Fl easy-only
Produces an output script suitable for
.Xr ed 1
with changes
specific only to
.Ar file3 .
-.It Fl a
+.It Fl a , Fl Fl text
Treat all files as ASCII.
-.It Fl E , X
+.It Fl E , Fl Fl show-overlap
+.It Fl X
Similar to
.Fl e
and
@@ -77,7 +83,7 @@
be noted with ==== in the normal listing) differently.
The overlapping lines from both files will be inserted by the edit script,
bracketed by "<<<<<<" and ">>>>>>" lines.
-.It Fl e
+.It Fl e , Fl Fl ed
Produces output in a form suitable as an input script for the
.Xr ed 1
utility.
@@ -99,11 +105,29 @@
It is useful for backing out changes specific to
.Ar file2
only.
-.It Fl x
+.It Fl i
+Appends 'w' and 'q'
+.Xr ed 1
+commands.
+.It Fl L , Fl Fl label
+Defines labels to print instead of file names
+.Ar file1 ,
+.Ar file2
+and
+.Ar file3 .
+.It Fl x, Fl Fl overlap-only
Produces an output script suitable for
.Xr ed 1
with changes
specific only to all three versions.
+.It Fl Fl diff-program Ar program
+Use
+.Ar program
+instead of the default
+.Xr diff 1
+to compare files.
+.It Fl Fl strip-trailing-cr
+Strip trailing carriage return on input files.
.El
.Pp
The
Index: usr.bin/diff3/diff3.c
===================================================================
--- usr.bin/diff3/diff3.c
+++ usr.bin/diff3/diff3.c
@@ -127,7 +127,6 @@
static int last[4];
static int Aflag, eflag, iflag, mflag, Tflag;
static int oflag; /* indicates whether to mark overlaps (-E or -X)*/
-static int strip_cr;
static char *f1mark, *f2mark, *f3mark;
static bool duplicate(struct range *, struct range *);
@@ -170,9 +169,9 @@
static void
usage(void)
{
- fprintf(stderr, "usage: diff3 [-3aAeEimTxX] [-L lable1] [-L label2] "
- "[ -L label3] file1 file2 file3\n");
- exit (2);
+ fprintf(stderr, "usage: diff3 [-3aAeEimTxX] [-L label1] [-L label2] "
+ "[-L label3] file1 file2 file3\n");
+ exit(2);
}
static int
@@ -186,7 +185,7 @@
f = fdopen(fd, "r");
if (f == NULL)
err(2, "fdopen");
- for (i=0; (p = getchange(f)); i++) {
+ for (i = 0; (p = getchange(f)); i++) {
if (i >= szchanges - 1)
increase();
a = b = (int)strtoimax(p, &p, 10);
@@ -196,7 +195,7 @@
}
kind = *p++;
c = d = (int)strtoimax(p, &p, 10);
- if (*p==',') {
+ if (*p == ',') {
p++;
d = (int)strtoimax(p, &p, 10);
}
@@ -212,8 +211,8 @@
(*dd)[i].new.to = d;
}
if (i) {
- (*dd)[i].old.from = (*dd)[i-1].old.to;
- (*dd)[i].new.from = (*dd)[i-1].new.to;
+ (*dd)[i].old.from = (*dd)[i - 1].old.to;
+ (*dd)[i].new.from = (*dd)[i - 1].new.to;
}
fclose(f);
return (i);
@@ -222,9 +221,9 @@
static int
diffexec(const char *diffprog, char **diffargv, int fd[])
{
- int pid, pd;
+ int pd;
- switch (pid = pdfork(&pd, PD_CLOEXEC)) {
+ switch (pdfork(&pd, PD_CLOEXEC)) {
case 0:
close(fd[0]);
if (dup2(fd[1], STDOUT_FILENO) == -1)
@@ -396,7 +395,7 @@
printf("%da\n", rold->from - 1);
else {
printf("%d", rold->from);
- if (rold->to > rold->from+1)
+ if (rold->to > rold->from + 1)
printf(",%d", rold->to - 1);
printf("c\n");
}
@@ -433,7 +432,7 @@
if ((line = get_line(fp[i], &j)) == NULL)
errx(EXIT_FAILURE, "logic error");
if (pr != NULL)
- printf("%s%s", Tflag == 1? "\t" : pr, line);
+ printf("%s%s", Tflag == 1 ? "\t" : pr, line);
cline[i]++;
}
return ((int) n);
@@ -455,11 +454,13 @@
skip(0, r1->from, NULL);
skip(1, r2->from, NULL);
nchar = 0;
- for (nline=0; nline < r1->to - r1->from; nline++) {
+ for (nline = 0; nline < r1->to - r1->from; nline++) {
do {
c = getc(fp[0]);
d = getc(fp[1]);
- if (c == -1 || d== -1)
+ if (c == -1 && d == -1)
+ break;
+ if (c == -1 || d == -1)
errx(EXIT_FAILURE, "logic error");
nchar++;
if (c != d) {
@@ -480,6 +481,7 @@
for (i = 0; i < 2; i++)
(void)fseek(fp[i], (long)-nchar, SEEK_CUR);
}
+
/*
* collect an editing script for later regurgitation
*/
@@ -512,7 +514,7 @@
if (!oflag || !overlap[n]) {
prange(&de[n].old);
} else {
- printf("%da\n", de[n].old.to -1);
+ printf("%da\n", de[n].old.to - 1);
if (Aflag) {
printf("%s\n", f2mark);
fseek(fp[1], de[n].old.from, SEEK_SET);
@@ -527,11 +529,19 @@
printf("=======\n");
}
fseek(fp[2], (long)de[n].new.from, SEEK_SET);
- for (k = de[n].new.to - de[n].new.from; k > 0; k-= j) {
+ for (k = de[n].new.to - de[n].new.from; k > 0; k -= j) {
+ size_t r;
+
j = k > BUFSIZ ? BUFSIZ : k;
- if (fread(block, 1, j, fp[2]) != j)
+ r = fread(block, 1, j, fp[2]);
+ if (r == 0) {
+ if (feof(fp[2]))
+ break;
errx(2, "logic error");
- fwrite(block, 1, j, stdout);
+ }
+ if (r != j)
+ j = r;
+ (void)fwrite(block, 1, j, stdout);
}
if (!oflag || !overlap[n])
printf(".\n");
@@ -557,22 +567,22 @@
newsz = szchanges == 0 ? 64 : 2 * szchanges;
incr = newsz - szchanges;
- p = realloc(d13, newsz * sizeof(struct diff));
+ p = reallocarray(d13, newsz, sizeof(struct diff));
if (p == NULL)
err(1, NULL);
memset(p + szchanges, 0, incr * sizeof(struct diff));
d13 = p;
- p = realloc(d23, newsz * sizeof(struct diff));
+ p = reallocarray(d23, newsz, sizeof(struct diff));
if (p == NULL)
err(1, NULL);
memset(p + szchanges, 0, incr * sizeof(struct diff));
d23 = p;
- p = realloc(de, newsz * sizeof(struct diff));
+ p = reallocarray(de, newsz, sizeof(struct diff));
if (p == NULL)
err(1, NULL);
memset(p + szchanges, 0, incr * sizeof(struct diff));
de = p;
- q = realloc(overlap, newsz * sizeof(char));
+ q = reallocarray(overlap, newsz, sizeof(char));
if (q == NULL)
err(1, NULL);
memset(q + szchanges, 0, incr * sizeof(char));
@@ -645,7 +655,7 @@
diffprog = optarg;
break;
case STRIPCR_OPT:
- strip_cr = 1;
+ diffargv[diffargc++] = __DECONST(char *, "--strip-trailing-cr");
break;
}
}
@@ -750,7 +760,7 @@
for (i = 0; i < nke; i++) {
status = e[i].data;
if (WIFEXITED(status) && WEXITSTATUS(status) >= 2)
- errx(2, "diff exited abormally");
+ errx(2, "diff exited abnormally");
else if (WIFSIGNALED(status))
errx(2, "diff killed by signal %d",
WTERMSIG(status));

File Metadata

Mime Type
text/plain
Expires
Fri, Jul 31, 5:19 AM (11 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35769552
Default Alt Text
D31626.id93987.diff (6 KB)

Event Timeline