Index: usr.bin/diff3/diff3.c =================================================================== --- usr.bin/diff3/diff3.c +++ usr.bin/diff3/diff3.c @@ -112,6 +112,11 @@ struct range new; }; +#define NOEFLAG 0 +#define EFLAG_OVERLAP 1 +#define EFLAG_NOOVERLAP 2 +#define EFLAG_UNMERGED 3 + static size_t szchanges; static struct diff *d13; @@ -314,7 +319,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 == NOEFLAG) { printf("====1\n"); change(1, &d1->old, false); keep(2, &d1->new); @@ -325,7 +330,7 @@ } /* second file is different from others */ if (!t1 || (t2 && d2->new.to < d1->new.from)) { - if (eflag == 0) { + if (eflag == NOEFLAG) { printf("====2\n"); keep(1, &d2->new); change(3, &d2->new, false); @@ -362,7 +367,7 @@ * dup = 0 means all files differ * dup = 1 means files 1 and 2 identical */ - if (eflag == 0) { + if (eflag == NOEFLAG) { printf("====%s\n", dup ? "3" : ""); change(1, &d1->old, dup); change(2, &d2->old, false); @@ -532,7 +537,15 @@ static int edit(struct diff *diff, bool dup, int j, int difftype) { - + /* + * dup is promoted here to an integer and evaluates to 2 if dup was + * true or 1 if dup was false and then compared against the eflag mode, + * don't take the edit if: + * - EFLAG_OVERLAP (01): if we are printing overlaps and this was not + * dup'd (i.e. in both and overlapping) + * - EFLAG_NOOVERLAP (10): if we are not printing overlaps and this is + * dup'd (i.e. in both) + */ if (((dup + 1) & eflag) == 0) return (j); j++; @@ -609,7 +622,7 @@ if (iflag) printf("w\nq\n"); - exit(eflag == 0 ? overlapcnt : 0); + exit(eflag == NOEFLAG ? overlapcnt : 0); } /* @@ -827,13 +840,13 @@ struct kevent *e; nblabels = 0; - eflag = 0; + eflag = NOEFLAG; 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"); @@ -842,10 +855,10 @@ Aflag = 1; break; case 'e': - eflag = 3; + eflag = EFLAG_UNMERGED; break; case 'E': - eflag = 3; + eflag = EFLAG_UNMERGED; oflag = 1; break; case 'i': @@ -866,11 +879,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; @@ -891,7 +904,7 @@ argv += optind; if (Aflag) { - eflag = 3; + eflag = EFLAG_UNMERGED; oflag = 1; }