summaryrefslogtreecommitdiff
path: root/devel/idiff/patches/patch-aa
blob: ae7e8d70e52b65bba5c9a13714e19df73d476576 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
$NetBSD: patch-aa,v 1.3 2011/12/05 02:14:40 agc Exp $

Don't overwrite read-only strings, so they can be placed in the text
segment by a decent optimising compiler.

Honour the VISUAL and EDITOR settings in the environment before
using ed(1)

Use c89 function defs
Use correct header files

--- idiff.c.orig	1998-09-16 12:58:16.000000000 -0700
+++ idiff.c	2011-12-04 16:38:16.000000000 -0800
@@ -1,16 +1,21 @@
 /* idiff:  interactive diff */
 
-#include <stdio.h>
+#include <sys/param.h>
+
 #include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
 char	*progname;
-#define	HUGE	10000	/* large number of lines */
+#define	HUGE	100000	/* large number of lines */
 
-main(argc, argv)
-	int argc;
-	char *argv[];
+int
+main(int argc, char **argv)
 {
 	FILE *fin, *fout, *f1, *f2, *efopen();
 	char buf[BUFSIZ], *mktemp();
+	char	realdiffname[MAXPATHLEN];
 	char *diffout = "idiff.XXXXXX";
 
 	progname = argv[0];
@@ -21,6 +26,8 @@
 	f1 = efopen(argv[1], "r");
 	f2 = efopen(argv[2], "r");
 	fout = efopen("idiff.out", "w");
+	(void) strcpy(realdiffname, diffout);
+	diffout = realdiffname;
 	mktemp(diffout);
 	sprintf(buf,"diff %s %s >%s",argv[1],argv[2],diffout);
 	system(buf);
@@ -31,14 +38,18 @@
 	exit(0);
 }
 
-idiff(f1, f2, fin, fout)	/* process diffs */
-	FILE *f1, *f2, *fin, *fout;
+void
+idiff(FILE *f1, FILE *f2, FILE *fin, FILE *fout)	/* process diffs */
 {
+	char	realtempfile[MAXPATHLEN];
 	char *tempfile = "idiff.XXXXXX";
 	char buf[BUFSIZ], buf2[BUFSIZ], *mktemp();
 	FILE *ft, *efopen();
 	int cmd, n, from1, to1, from2, to2, nf1, nf2;
+	char *ed;
 
+	(void) strcpy(realtempfile, tempfile);
+	tempfile = realtempfile;
 	mktemp(tempfile);
 	nf1 = nf2 = 0;
 	while (fgets(buf, sizeof buf, fin) != NULL) {
@@ -76,7 +87,11 @@
 				fprintf(ft, "---\n");
 				ncopy(f2, to2+1-from2, ft);
 				fclose(ft);
-				sprintf(buf2, "ed %s", tempfile);	
+				if ((ed = getenv("VISUAL")) == NULL &&
+				    (ed = getenv("EDITOR")) == NULL) {
+					ed = "/bin/ed";
+				}
+				snprintf(buf2, sizeof(buf2), "%s %s", ed, tempfile);	
 				system(buf2);
 				ft = efopen(tempfile, "r");
 				ncopy(ft, HUGE, fout);
@@ -98,9 +113,8 @@
 	unlink(tempfile);
 }
 
-parse(s, pfrom1, pto1, pcmd, pfrom2, pto2)
-	char *s;
-	int *pcmd, *pfrom1, *pto1, *pfrom2, *pto2;
+void
+parse(char *s, int *pfrom1, int *pto1, int *pcmd, int *pfrom2, int *pto2)
 {
 #define a2i(p) while (isdigit(*s)) p = 10*(p) + *s++ - '0'
 
@@ -120,8 +134,8 @@
 		*pto2 = *pfrom2;
 }
 
-nskip(fin, n)	/* skip n lines of file fin */
-	FILE *fin;
+void
+nskip(FILE *fin, int n)	/* skip n lines of file fin */
 {
 	char buf[BUFSIZ];
 
@@ -129,8 +143,8 @@
 		fgets(buf, sizeof buf, fin);
 }
 
-ncopy(fin, n, fout)	/* copy n lines from fin to fout */
-	FILE *fin, *fout;
+void
+ncopy(FILE *fin, int n, FILE *fout)	/* copy n lines from fin to fout */
 {
 	char buf[BUFSIZ];