summaryrefslogtreecommitdiff
path: root/devel/idiff/patches/patch-aa
blob: 6286bf23b1e92fb50394ccf43a146113bf8eb591 (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
$NetBSD: patch-aa,v 1.2 2001/05/29 08:16:05 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)

--- idiff.c.orig	Wed Sep 16 20:58:16 1998
+++ idiff.c	Tue May 29 09:11:44 2001
@@ -1,5 +1,7 @@
 /* idiff:  interactive diff */
 
+#include <sys/param.h>
+
 #include <stdio.h>
 #include <ctype.h>
 char	*progname;
@@ -11,6 +13,7 @@
 {
 	FILE *fin, *fout, *f1, *f2, *efopen();
 	char buf[BUFSIZ], *mktemp();
+	char	realdiffname[MAXPATHLEN];
 	char *diffout = "idiff.XXXXXX";
 
 	progname = argv[0];
@@ -21,6 +24,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);
@@ -34,11 +39,15 @@
 idiff(f1, f2, fin, fout)	/* process diffs */
 	FILE *f1, *f2, *fin, *fout;
 {
+	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 +85,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);