summaryrefslogtreecommitdiff
path: root/misc/fep/patches/patch-aj
blob: caaafaa43a489501de3d19de0608307e55fc2bc9 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
$NetBSD: patch-aj,v 1.1 2000/02/07 03:18:13 christos Exp $

--- fep_main.c.orig	Wed Jun  9 22:53:06 1993
+++ fep_main.c	Sun Feb  6 22:00:22 2000
@@ -10,8 +10,17 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
-#include <sys/file.h>
+#ifdef TERMIOS
+#include <termios.h>
+#ifdef __linux__
+#ifndef _POSIX_VDISABLE
+#define _POSIX_VDISABLE '\0'
+#endif
+#endif
+#else
 #include <sgtty.h>
+#endif
+#include <sys/file.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/errno.h>
@@ -38,9 +47,9 @@
 					/* delimiter characters */
 int	master;				/* file discriptor for pty master */
 int	slave;				/* file discriptor for pty slave */
-int	mastermask;			/* 1<<master */
-int	stdinmask;			/* 1<<fileno(stdin) */
-int	selectmask;			/* stdinmask | mastermask */
+fd_set	mastermask;			/* 1<<master */
+fd_set	stdinmask;			/* 1<<fileno(stdin) */
+fd_set	selectmask;			/* stdinmask | mastermask */
 int	selectnfds;			/* max (fileno(stdin), master) + 1*/
 int	child_pid;			/* child pid */
 int	ptyflag = ON;			/* flag to use pty or not */
@@ -48,21 +57,28 @@
 int	debug = OFF;			/* debug switch */
 int	auto_tty_fix = ON;		/* fix tty mode automaticaly */
 FILE	*script_fp = NULL;		/* script file pointer */
-int	catchsig();			/* function take care SIGCHILD */
+void	catchsig __P((int));		/* function take care SIGCHILD */
 
-struct	sgttyb initial_ttymode;		/* initial tty mode */
-struct	sgttyb master_ttymode;		/* master tty mode */
-struct	sgttyb slave_ttymode;		/* slave tty mode */
+#ifdef TERMIOS
+#define ttystruct termios
+#elif defined(TIOCSETN)
+#define ttystruct sgttyb
+#endif
+struct	ttystruct initial_ttymode;		/* initial tty mode */
+struct	ttystruct master_ttymode;		/* master tty mode */
+struct	ttystruct slave_ttymode;		/* slave tty mode */
 
 int	lines;				/* terminal line size */
 int	columns;			/* terminal coulumn size */
 char	*term_clear;			/* terminal clear code */
 
-void	(*sighup)(), (*sigchld)(), (*sigtstp)();
+void	(*sighup) __P((int)), (*sigchld) __P((int)), (*sigtstp) __P((int));
 					/* function buffer for signal */
 
+#ifdef TIOCSETN
 struct	tchars tchars_buf;		/* tty characters */
 struct	ltchars ltchars_buf;		/* tty characters */
+#endif
 int	lmode_buf;			/* local mode */
 int	line_desc;			/* line descipline */
 #ifdef KANJI
@@ -112,6 +128,10 @@
 
     myself = argv[0];
 
+    setvbuf(stdin, NULL, _IONBF, 0);
+    setvbuf(stdout, NULL, _IONBF, 0);
+    setvbuf(stderr, NULL, _IONBF, 0);
+
     /*
      * Initialize binding table
      */
@@ -276,7 +296,7 @@
 fix_signal ()
 {
 #ifdef SIGWINCH
-    int sigwinch();
+    void sigwinch __P((int));
 #endif
 
     sighup = signal (SIGHUP, terminate);
@@ -336,7 +356,7 @@
 	if (Through == OFF && Transparency == OFF && script_fp)
 	    fwrite (inputline, sizeof(CHAR), strlen (inputline), script_fp);
     }
-    terminate ();
+    terminate (0);
 }
 
 #define INPUT_BUFFER_SIZE 1024
@@ -384,7 +404,8 @@
 {
     char c;
     int n;
-    int nfound, readfd, writefd = 0, execptfd = 0;
+    int nfound;
+    fd_set readfd, writefd, exceptfd;
 #ifdef USE_TIMEOUT
     struct timeval **timeout = auto_tty_fix ? timeout_list : notimeout;
 #else
@@ -396,9 +417,8 @@
     /*
      * Sorry, this cording depends to an implementation of getc().
      */
-#   define CHAR_IN_BUFFER (stdin->_cnt)
-    if (CHAR_IN_BUFFER)
-	goto RETURNCHAR;
+    FD_ZERO(&writefd);
+    FD_ZERO(&exceptfd);
 
 RETRY:
     readfd = selectmask;
@@ -409,13 +429,13 @@
     while ((nfound = select (selectnfds, &readfd, 0, 0, *timeout)) < 0)
 	if (errno != EINTR) {
 		perror ("select");
-		terminate();
+		terminate(0);
 	}
 
     /*
      * Found output from pty.
      */
-    if (readfd & mastermask) {
+    if (FD_ISSET(master, &readfd)) {
 	int nbyte;
 
 	/*
@@ -451,7 +471,7 @@
     /*
      * Found input from terminal
      */
-    if (CHAR_IN_BUFFER || readfd & stdinmask) {
+    if (FD_ISSET(fileno(stdin), &readfd)) {
 
 #ifndef USE_TIMEOUT
 	/*
@@ -468,7 +488,7 @@
 	if ((c = getc (stdin)) == EOF) {
 	    if (debug)
 		printf ("EOF chatched\n");
-	    terminate ();
+	    terminate (0);
 	}
 	else
 	    return (c & CHARMASK);
@@ -596,7 +616,7 @@
 
 swallow_output()
 {
-    int readfd = mastermask;
+    fd_set readfd = mastermask;
     int r;
     int nbyte;
     int ncount = 10;
@@ -604,7 +624,7 @@
     while (
 	ncount-- &&
 	select (selectnfds, &readfd, 0, 0, TIMEOUT_NOBLOCK) > 0 &&
-	readfd & mastermask
+	FD_ISSET(master, &mastermask)
     ) {
 	nbyte = buf_read (master, output_buffer);
 	if (nbyte > 0) {
@@ -636,9 +656,11 @@
 #include <sys/m_wait.h>
 #endif
 
-catchsig()
+void
+catchsig(n)
+    int n;
 {
-    union wait status;
+    int status;
     struct rusage   ru;
 
     if (wait3 (&status, WNOHANG | WUNTRACED, &ru) != child_pid)
@@ -650,7 +672,7 @@
 	suspend ();
 	return;
     }
-    terminate ();
+    terminate (0);
 }
 
 exec_to_command(argv)
@@ -675,13 +697,37 @@
     dup2 (slave, 2);
     (void) close (slave);
 
+#ifdef TERMIOS
+    tcsetattr(0, TCSANOW, &slave_ttymode);
+#elif defined(TIOCSETN)
     ioctl (0, TIOCSETN, (char *) & slave_ttymode);
-
+#endif
     execvp (*argv, argv, 0);
     perror (*argv);
     exit (1);
 }
 
+#ifdef TERMIOS
+fix_tty()
+{
+    int i;
+    master_ttymode = initial_ttymode;
+    slave_ttymode = initial_ttymode;
+    master_ttymode.c_lflag &= ~(ECHO|ECHOE|ECHOK|ICANON);
+
+    for (i = 0; i < NCCS; i++)
+	master_ttymode.c_cc[i] = _POSIX_VDISABLE;
+
+    master_ttymode.c_cc[VMIN] = 1;
+    master_ttymode.c_cc[VTIME] = 0;
+    slave_ttymode.c_lflag &= ~(ECHO|ECHOE|ECHOK);
+    slave_ttymode.c_iflag &= ~(ICRNL);
+    slave_ttymode.c_oflag &= ~(ONLCR);
+    tcsetattr(0, TCSANOW, &master_ttymode);
+}
+
+#elif defined(TIOCSETN)
+
 fix_tty()
 {
     struct tchars tcbuf;
@@ -719,6 +765,7 @@
     ioctl (0, TIOCSETC, (char *) & tcbuf);
     ioctl (0, TIOCSLTC, (char *) & lcbuf);
 }
+#endif
 
 kill_process()
 {
@@ -727,7 +774,9 @@
 	(void) killpg (child_pid, SIGTERM);
 }
 
-terminate()
+void
+terminate(n)
+    int n;
 {
     extern int errno;
 
@@ -759,9 +808,13 @@
 	    if (killpg (child_pid, SIGKILL) < 0)
 		perror ("kill");
 
+#ifdef TERMIOS
+    tcsetattr(0, TCSANOW, &initial_ttymode);
+#elif defined(TIOCSETN)
     ioctl (0, TIOCSETN, (char *) & initial_ttymode);
     ioctl (0, TIOCSETC, (char *) & tchars_buf);
     ioctl (0, TIOCSLTC, (char *) & ltchars_buf);
+#endif
     exit (0);
 }
 
@@ -796,11 +849,15 @@
     }
 
  FOUND:
+#ifdef TERMIOS
+    tcgetattr(0, &initial_ttymode);
+#elif defined(TIOCSETN)
     ioctl (0, TIOCGETP, (char *) &initial_ttymode);
     ioctl (0, TIOCGETC, (char *) &tchars_buf);
     ioctl (0, TIOCGETD, (char *) &line_desc);
     ioctl (0, TIOCGLTC, (char *) &ltchars_buf);
     ioctl (0, TIOCLGET, (char *) &lmode_buf);
+#endif
 
 #ifdef TIOCGWINSZ
     {
@@ -822,9 +879,13 @@
 # endif
 #endif KANJI
 
-    stdinmask = 1 << fileno (stdin);
-    mastermask = 1 << master;
-    selectmask = stdinmask | mastermask;
+    FD_ZERO(&stdinmask);
+    FD_ZERO(&mastermask);
+    FD_ZERO(&selectmask);
+    FD_SET(fileno(stdin), &stdinmask);
+    FD_SET(master, &mastermask);
+    FD_SET(fileno(stdin), &selectmask);
+    FD_SET(master, &selectmask);
     selectnfds = max (fileno(stdin), master) + 1;
 
     return;
@@ -838,11 +899,15 @@
 	perror (slave_tty);
 	exit (1);
     }
+#ifdef TERMIOS
+    tcsetattr(slave, TCSANOW, &initial_ttymode);
+#elif defined(TIOCSETN)
     ioctl (slave, TIOCSETN, (char *) &initial_ttymode);
     ioctl (slave, TIOCSETC, (char *) &tchars_buf);
     ioctl (slave, TIOCSLTC, (char *) &ltchars_buf);
     ioctl (slave, TIOCLSET, (char *) &lmode_buf);
     ioctl (slave, TIOCSETD, (char *) &line_desc);
+#endif
 
 #ifdef KANJI
 # if defined(TIOCKGET) && defined(TIOCKSET)
@@ -866,16 +931,19 @@
 
 recover_tty()
 {
-
+#ifdef TERMIOS
+    tcsetattr(0, TCSANOW, &initial_ttymode);
+#elif defined(TIOCSETN)
     ioctl (0, TIOCSETN, (char *) & initial_ttymode);
     ioctl (0, TIOCSETC, (char *) & tchars_buf);
     ioctl (0, TIOCSLTC, (char *) & ltchars_buf);
+#endif
 }
 
 suspend()
 {
     long	pid;
-    void	(*func) ();
+    void	(*func) __P((int));
     int		omask;
     extern int	errno;
 
@@ -890,7 +958,7 @@
 
     if (kill (child_pid, SIGCONT) < 0 && errno == ESRCH) {
 	printf ("Where my child has gone?!\n");
-	terminate ();
+	terminate (0);
     }
     killpg (child_pid, SIGCONT);
     kill (0, SIGCONT);