diff3: improve style
This commit is contained in:
parent
7f7b03f389
commit
702dda4368
@ -126,7 +126,7 @@ static int cline[3]; /* # of the last-read line in each file (0-2) */
|
||||
*/
|
||||
static int last[4];
|
||||
static int Aflag, eflag, iflag, mflag, Tflag;
|
||||
static int oflag; /* indicates whether to mark overlaps (-E or -X)*/
|
||||
static int oflag; /* indicates whether to mark overlaps (-E or -X) */
|
||||
static int strip_cr;
|
||||
static char *f1mark, *f2mark, *f3mark;
|
||||
|
||||
@ -170,9 +170,9 @@ static struct option longopts[] = {
|
||||
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 @@ readin(int fd, struct diff **dd)
|
||||
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 @@ readin(int fd, struct diff **dd)
|
||||
}
|
||||
kind = *p++;
|
||||
c = d = (int)strtoimax(p, &p, 10);
|
||||
if (*p==',') {
|
||||
if (*p == ',') {
|
||||
p++;
|
||||
d = (int)strtoimax(p, &p, 10);
|
||||
}
|
||||
@ -212,8 +212,8 @@ readin(int fd, struct diff **dd)
|
||||
(*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 @@ readin(int fd, struct diff **dd)
|
||||
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 @@ prange(struct range *rold)
|
||||
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 @@ skip(int i, int from, const char *pr)
|
||||
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,13 +455,13 @@ duplicate(struct range *r1, struct range *r2)
|
||||
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)
|
||||
break;
|
||||
if (c == -1 || d== -1)
|
||||
if (c == -1 || d == -1)
|
||||
errx(EXIT_FAILURE, "logic error");
|
||||
nchar++;
|
||||
if (c != d) {
|
||||
@ -482,6 +482,7 @@ repos(int nchar)
|
||||
for (i = 0; i < 2; i++)
|
||||
(void)fseek(fp[i], (long)-nchar, SEEK_CUR);
|
||||
}
|
||||
|
||||
/*
|
||||
* collect an editing script for later regurgitation
|
||||
*/
|
||||
@ -514,7 +515,7 @@ edscript(int n)
|
||||
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);
|
||||
@ -529,8 +530,9 @@ edscript(int n)
|
||||
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;
|
||||
r = fread(block, 1, j, fp[2]);
|
||||
if (r == 0) {
|
||||
@ -759,7 +761,7 @@ main(int argc, char **argv)
|
||||
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));
|
||||
|
Loading…
Reference in New Issue
Block a user