diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -112,6 +112,11 @@ struct range new; }; +#define EFLAG_NONE 0 +#define EFLAG_OVERLAP 1 +#define EFLAG_NOOVERLAP 2 +#define EFLAG_UNMERGED 3 + static size_t szchanges; static struct diff *d13; @@ -313,7 +318,7 @@ /* first file is different from the others */ if (!t2 || (t1 && d1->new.to < d2->new.from)) { /* stuff peculiar to 1st file */ - if (eflag == 0) { + if (eflag == EFLAG_NONE) { printf("====1\n"); change(1, &d1->old, false); keep(2, &d1->new); @@ -324,7 +329,7 @@ } /* second file is different from others */ if (!t1 || (t2 && d2->new.to < d1->new.from)) { - if (eflag == 0) { + if (eflag == EFLAG_NONE) { printf("====2\n"); keep(1, &d2->new); change(3, &d2->new, false); @@ -361,7 +366,7 @@ * dup = 0 means all files differ * dup = 1 means files 1 and 2 identical */ - if (eflag == 0) { + if (eflag == EFLAG_NONE) { printf("====%s\n", dup ? "3" : ""); change(1, &d1->old, dup); change(2, &d2->old, false); @@ -530,9 +535,11 @@ static int edit(struct diff *diff, bool dup, int j, int difftype) { - - if (((dup + 1) & eflag) == 0) + if (!(eflag == EFLAG_UNMERGED || + (!dup && eflag == EFLAG_OVERLAP ) || + (dup && eflag == EFLAG_NOOVERLAP))) { return (j); + } j++; overlap[j] = !dup; if (!dup) @@ -607,7 +614,7 @@ if (iflag) printf("w\nq\n"); - exit(eflag == 0 ? overlapcnt : 0); + exit(eflag == EFLAG_NONE ? overlapcnt : 0); } /* @@ -825,13 +832,13 @@ struct kevent *e; nblabels = 0; - eflag = 0; + eflag = EFLAG_NONE; oflag = 0; diffargv[diffargc++] = __DECONST(char *, diffprog); while ((ch = getopt_long(argc, argv, OPTIONS, longopts, NULL)) != -1) { switch (ch) { case '3': - eflag = 2; + eflag = EFLAG_NOOVERLAP; break; case 'a': diffargv[diffargc++] = __DECONST(char *, "-a"); @@ -840,10 +847,10 @@ Aflag = 1; break; case 'e': - eflag = 3; + eflag = EFLAG_UNMERGED; break; case 'E': - eflag = 3; + eflag = EFLAG_UNMERGED; oflag = 1; break; case 'i': @@ -864,11 +871,11 @@ Tflag = 1; break; case 'x': - eflag = 1; + eflag = EFLAG_OVERLAP; break; case 'X': oflag = 1; - eflag = 1; + eflag = EFLAG_OVERLAP; break; case DIFFPROG_OPT: diffprog = optarg; @@ -889,7 +896,7 @@ argv += optind; if (Aflag) { - eflag = 3; + eflag = EFLAG_UNMERGED; oflag = 1; }