Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162635612
D55517.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D55517.diff
View Options
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
@@ -62,19 +62,20 @@
* SUCH DAMAGE.
*/
+#include <sys/types.h>
#include <sys/capsicum.h>
#include <sys/procdesc.h>
-#include <sys/types.h>
#include <sys/wait.h>
+#include <assert.h>
#include <capsicum_helpers.h>
#include <ctype.h>
#include <err.h>
#include <getopt.h>
+#include <inttypes.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
-#include <limits.h>
-#include <inttypes.h>
#include <string.h>
#include <unistd.h>
@@ -87,14 +88,15 @@
int to;
};
+enum difftype {
+ DIFF_NONE,
+ DIFF_TYPE1,
+ DIFF_TYPE2,
+ DIFF_TYPE3,
+};
+
struct diff {
-#define DIFF_TYPE1 1
-#define DIFF_TYPE2 2
-#define DIFF_TYPE3 3
- int type;
-#if DEBUG
- char *line;
-#endif /* DEBUG */
+ enum difftype type;
/* Ranges as lines */
struct range old;
@@ -137,7 +139,7 @@
static const char *divider = "=======";
static bool duplicate(struct range *, struct range *);
-static int edit(struct diff *, bool, int, int);
+static int edit(struct diff *, bool, int, enum difftype);
static char *getchange(FILE *);
static char *get_line(FILE *, size_t *);
static int readin(int fd, struct diff **);
@@ -256,9 +258,6 @@
for (i = 0; (p = getchange(f)) != NULL; i++) {
if ((size_t)i >= szchanges - 1)
increase();
-#if DEBUG
- (*dd)[i].line = strdup(p);
-#endif /* DEBUG */
a = b = strtoi(p, &p);
if (*p == ',')
@@ -565,7 +564,7 @@
for (n = 0; cline[i] < from - 1; n += j) {
if ((line = get_line(fp[i], &j)) == NULL)
- errx(EXIT_FAILURE, "logic error");
+ errx(1, "logic error");
if (pr != NULL)
printf("%s%s", Tflag == 1 ? "\t" : pr, line);
cline[i]++;
@@ -596,7 +595,7 @@
if (c == -1 && d == -1)
break;
if (c == -1 || d == -1)
- errx(EXIT_FAILURE, "logic error");
+ errx(1, "logic error");
nchar++;
if (c != d) {
repos(nchar);
@@ -621,7 +620,7 @@
* collect an editing script for later regurgitation
*/
static int
-edit(struct diff *diff, bool dup, int j, int difftype)
+edit(struct diff *diff, bool dup, int j, enum difftype difftype)
{
if (!(eflag == EFLAG_UNMERGED ||
(!dup && eflag == EFLAG_OVERLAP ) ||
@@ -634,10 +633,6 @@
overlapcnt++;
de[j].type = difftype;
-#if DEBUG
- de[j].line = strdup(diff->line);
-#endif /* DEBUG */
-
de[j].old.from = diff->old.from;
de[j].old.to = diff->old.to;
de[j].new.from = diff->new.from;
@@ -657,7 +652,7 @@
return;
if (r->from > r->to)
- errx(EXIT_FAILURE, "invalid print range");
+ errx(1, "invalid print range");
/*
* XXX-THJ: We read through all of the file for each range printed.
@@ -872,8 +867,7 @@
}
break;
default:
- printf("Error: Unhandled diff type - exiting\n");
- exit(EXIT_FAILURE);
+ __assert_unreachable();
}
if (de[n].type == DIFF_TYPE2)
@@ -886,11 +880,7 @@
* Print from the final range to the end of 'myfile'. Any deletions or
* additions to this file should have been handled by now.
*/
- new = &de[n-1].new;
- old = &de[n-1].old;
-
r.from -= f1f3delta;
-
r.to = INT_MAX;
printrange(fp[2], &r);
exit(overlapcnt > 0);
@@ -1109,5 +1099,5 @@
merge(m, n);
- return (EXIT_SUCCESS);
+ exit(0);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jul 16, 7:10 AM (19 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
35128656
Default Alt Text
D55517.diff (3 KB)
Attached To
Mode
D55517: diff3: Code cleanup
Attached
Detach File
Event Timeline
Log In to Comment