git: 2c4276aaa2d0 - main - diff3: Use variables for old and new in A scripts
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 01 Aug 2022 13:56:47 UTC
The branch main has been updated by thj: URL: https://cgit.FreeBSD.org/src/commit/?id=2c4276aaa2d03217b9c1797196864bbbe4f2d8ea commit 2c4276aaa2d03217b9c1797196864bbbe4f2d8ea Author: Tom Jones <thj@FreeBSD.org> AuthorDate: 2022-08-01 13:48:35 +0000 Commit: Tom Jones <thj@FreeBSD.org> CommitDate: 2022-08-01 13:54:20 +0000 diff3: Use variables for old and new in A scripts This makes the code easier to follow, no functional changes intended Sponsored by: Klara, Inc. --- usr.bin/diff3/diff3.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c index 7adb9b5c5043..ff8d03007e4e 100644 --- a/usr.bin/diff3/diff3.c +++ b/usr.bin/diff3/diff3.c @@ -631,19 +631,21 @@ Ascript(int n) bool deletenew; bool deleteold; - for (; n > 0; n--) { + struct range *new, *old; - deletenew = (de[n].new.from == de[n].new.to); - deleteold = (de[n].old.from == de[n].old.to); - startmark = de[n].old.from + (de[n].old.to - de[n].old.from) - 1; + for (; n > 0; n--) { + new = &de[n].new; + old = &de[n].old; + deletenew = (new->from == new->to); + deleteold = (old->from == old->to); + startmark = old->from + (old->to - old->from) - 1; if (de[n].type == DIFF_TYPE2) { if (!oflag || !overlap[n]) { - prange(&de[n].old, deletenew); - printrange(fp[2], &de[n].new); + prange(old, deletenew); + printrange(fp[2], new); } else { - startmark = de[n].new.from + - (de[n].new.to - de[n].new.from); + startmark = new->from + (new->to - new->from); if (!deletenew) startmark--; @@ -654,31 +656,31 @@ Ascript(int n) printf(".\n"); printf("%da\n", startmark - - (de[n].new.to - de[n].new.from)); + (new->to - new->from)); printf("%s %s\n", oldmark, f2mark); if (!deleteold) - printrange(fp[1], &de[n].old); + printrange(fp[1], old); printf("%s\n.\n", divider); } } else if (de[n].type == DIFF_TYPE3) { if (!oflag || !overlap[n]) { - prange(&de[n].old, deletenew); - printrange(fp[2], &de[n].new); + prange(old, deletenew); + printrange(fp[2], new); } else { printf("%da\n", startmark); printf("%s %s\n", orgmark, f2mark); if (deleteold) { struct range r; - r.from = de[n].old.from-1; - r.to = de[n].new.to; + r.from = old->from-1; + r.to = new->to; printrange(fp[1], &r); } else - printrange(fp[1], &de[n].old); + printrange(fp[1], old); printf("%s\n", divider); - printrange(fp[2], &de[n].new); + printrange(fp[2], new); } if (!oflag || !overlap[n]) { @@ -692,7 +694,7 @@ Ascript(int n) * file and append lines */ printf("%da\n%s %s\n.\n", - startmark - (de[n].old.to - de[n].old.from), + startmark - (old->to - old->from), oldmark, f1mark); } }