Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F164241683
D31626.id93986.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D31626.id93986.diff
View Options
Index: usr.bin/diff3/diff3.1
===================================================================
--- usr.bin/diff3/diff3.1
+++ usr.bin/diff3/diff3.1
@@ -38,7 +38,11 @@
.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 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 +64,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 +82,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 +104,27 @@
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.
.El
.Pp
The
Index: usr.bin/diff3/diff3.c
===================================================================
--- usr.bin/diff3/diff3.c
+++ usr.bin/diff3/diff3.c
@@ -170,9 +170,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 +186,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 +196,7 @@
}
kind = *p++;
c = d = (int)strtoimax(p, &p, 10);
- if (*p==',') {
+ if (*p == ',') {
p++;
d = (int)strtoimax(p, &p, 10);
}
@@ -212,8 +212,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 +222,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 +396,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 +433,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 +455,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 +482,7 @@
for (i = 0; i < 2; i++)
(void)fseek(fp[i], (long)-nchar, SEEK_CUR);
}
+
/*
* collect an editing script for later regurgitation
*/
@@ -512,7 +515,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 +530,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 +568,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));
@@ -750,7 +761,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
Details
Attached
Mime Type
text/plain
Expires
Fri, Jul 31, 12:42 AM (3 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35759615
Default Alt Text
D31626.id93986.diff (5 KB)
Attached To
Mode
D31626: diff3: preliminary cleanup
Attached
Detach File
Event Timeline
Log In to Comment