aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Jones <thj@FreeBSD.org>2022-08-02 13:29:38 +0000
committerTom Jones <thj@FreeBSD.org>2022-08-02 13:37:05 +0000
commitc0e6ccb12ab930b122dc18b6079b563bd347155f (patch)
tree7c2ca4888a6162631a794e471a55eaac387b61f5
parent264a559ac827d0bf81986cd5758594fc687d5bd5 (diff)
downloadsrc-c0e6ccb12ab930b122dc18b6079b563bd347155f.tar.gz
src-c0e6ccb12ab930b122dc18b6079b563bd347155f.zip
diff3: Use ranges for the old and new diffedits in A scripts
This makes the output logic easier to read. No functional change intended. Sponsored by: Klara, Inc.
-rw-r--r--usr.bin/diff3/diff3.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/usr.bin/diff3/diff3.c b/usr.bin/diff3/diff3.c
index 37a98a635742..fa0aeb11d008 100644
--- a/usr.bin/diff3/diff3.c
+++ b/usr.bin/diff3/diff3.c
@@ -714,51 +714,54 @@ Ascript(int n)
static void
mergescript(int i)
{
- struct range r;
+ struct range r, *new, *old;
int n;
r.from = 1;
r.to = 1;
for (n = 1; n < i+1; n++) {
+ new = &de[n].new;
+ old = &de[n].old;
+
/* print any lines leading up to here */
- r.to = de[n].old.from;
+ r.to = old->from;
printrange(fp[0], &r);
if (de[n].type == DIFF_TYPE2) {
printf("%s %s\n", oldmark, f2mark);
- printrange(fp[1], &de[n].old);
+ printrange(fp[1], old);
printf("%s\n", divider);
- printrange(fp[2], &de[n].new);
+ printrange(fp[2], new);
printf("%s %s\n", newmark, f3mark);
} else if (de[n].type == DIFF_TYPE3) {
if (!oflag || !overlap[n]) {
- printrange(fp[2], &de[n].new);
+ printrange(fp[2], new);
} else {
printf("%s %s\n", oldmark, f1mark);
- printrange(fp[0], &de[n].old);
+ printrange(fp[0], old);
printf("%s %s\n", orgmark, f2mark);
- if (de[n].old.from == de[n].old.to) {
+ if (old->from == old->to) {
struct range or;
- or.from = de[n].old.from -1;
- or.to = de[n].new.to;
+ or.from = old->from - 1;
+ or.to = new->to;
printrange(fp[1], &or);
} 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);
printf("%s %s\n", newmark, f3mark);
}
}
- if (de[n].old.from == de[n].old.to)
- r.from = de[n].new.to;
+ if (old->from == old->to)
+ r.from = new->to;
else
- r.from = de[n].old.to;
+ r.from = old->to;
}
/*
* Print from the final range to the end of 'myfile'. Any deletions or
@@ -768,11 +771,13 @@ mergescript(int i)
* If the new range is 0 length (from == to), we need to use the old
* range.
*/
- if ((de[n-1].old.from == de[n-1].new.from) &&
- (de[n-1].old.to == de[n-1].new.to))
+ new = &de[n-1].new;
+ old = &de[n-1].old;
+ if ((old->from == new->from) &&
+ (old->to == new->to))
r.from--;
- else if (de[n-1].new.from == de[n-1].new.to)
- r.from = de[n-1].old.from;
+ else if (new->from == new->to)
+ r.from = old->from;
/*
* If the range is a 3 way merge then we need to skip a line in the