Repository navigation
Expand file tree
/
Copy patheesite.c
More file actions
executable file
·364 lines (311 loc) · 9.57 KB
/
Copy patheesite.c
File metadata and controls
executable file
·364 lines (311 loc) · 9.57 KB
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
* This software is quasi-public; it may be used freely with
* like software, but may NOT be sold or made part of licensed
* products without permission of the author.
*/
/* EESITE Site dependent frobs
* Primarily TS_ routines for TTY control. Most site-dependent
* routine is TS_INP for detection of TTY input.
*/
#include "elle.h"
#if !(V6)
#include <signal.h> /* For SIGTSTP in ts_pause */
#else
#include "eesigs.h"
#endif
int tsf_pause = 0; /* Set if ts_pause works. Ref'd by equit in e_main */
#if !(SYSV || BBN) /* SYSV and BBN have weird tty calls */
#if MINIX
#include <termios.h>
struct termios origterm, newterm;
#else
#if V6
/* Normal V6 declarations, must provide explicitly */
struct sgttyb {
char sg_ispeed;
char sg_ospeed;
char sg_erase;
char sg_kill;
int sg_flags;
};
#define ECHO (010)
#define CRMOD (020)
#define RAW (040)
#else
/* Normal V7 UNIX declarations, can use include file */
#include <sgtty.h>
#endif
struct sgttyb nstate; /* Both V6 and V7 */
struct sgttyb ostate; /* Both V6 and V7 */
#endif /*!(SYSV || BBN)*/
#endif /*!MINIX*/
#if BBN /* BBN system frobs */
#include "/sys/sys/h/modtty.h"
struct modes nstate;
struct modes ostate;
#endif /*BBN*/
#if DNTTY /* DN TTY frobs */
#include <tty.h>
char partab[2]; /* to satisfy obscene ref in tty.h */
#endif /*DNTTY*/
#if (UCB || TOPS20) /* UCB, TOPS20 additional frobs */
#include <sys/ioctl.h> /* For ts_inp() and tldisc */
#if IMAGEN
struct tchars otchars, ntchars; /* Original and new tchars */
#endif /*IMAGEN*/
#endif /*(UCB || TOPS20)*/
#if SYSV /* System V (and PC/IX) crocks */
#include <termio.h>
#include <sys/ioctl.h>
struct termio /* terminal i/o status flags */
origterm, /* status of terminal at start of ELLE */
newterm; /* status of terminal when using ELLE */
#endif /*SYSV*/
/* TS_INP
* Ask system if terminal input is available (on file descriptor 0).
* Returns non-zero if so, else returns zero.
* Very important that this call NOT hang or block in any way,
* because it is used to detect type-ahead by the user;
* return should be immediate whether or not input is waiting.
*/
ts_inp()
{
#if BBN /* Idiosyncratic */
int cap_buf[2];
capac (0, &cap_buf[0], 4);
return (cap_buf[0]);
#endif /*BBN*/
#if (DNTTY || ONYX) /* Have "empty()" syscall */
return(empty(0) ? 0 : 1);
#endif /*DNTTY || ONYX*/
#if (UCB || TOPS20) /* Have FIONREAD ioctl */
long retval;
if(ioctl(0,FIONREAD,&retval)) /* If this call fails, */
return(0); /* assume no input waiting */
return((retval ? 1 : 0));
#endif /*UCB || TOPS20*/
#if COHERENT
int retval;
ioctl(0, TIOCQUERY, &retval);
return((retval ? 1 : 0));
#endif /*COHERENT*/
#if VENIX86
struct sgttyb iocbuf;
ioctl(0, TIOCQCNT, &iocbuf);
return(iocbuf.sg_ispeed != 0 );
#endif /*VENIX86*/
#if !(BBN||COHERENT||DNTTY||ONYX||TOPS20||UCB||VENIX86)
return(0); /* Default - never any type-ahead, sigh */
#endif
}
/* TS_INIT()
* Get terminal information from system, initialize things for
* ts_enter and ts_exit. This is called before t_init.
* Must set "trm_ospeed".
*/
ts_init()
{
#if DNTTY
signal(16,1); /* DN peculiar - turn off ctl-A */
#endif /*DNTTY*/
#if !(MINIX || SYSV || BBN) /* Normal UNIX stuff */
ioctl(1, TIOCGETP, &ostate); /* Remember old state */
nstate = ostate; /* Set up edit-mode state vars */
nstate.sg_flags |= RAW; /* We'll want raw mode */
nstate.sg_flags &= ~(ECHO|CRMOD); /* with no echoing */
trm_ospeed = ostate.sg_ospeed;
#if (IMAGEN && UCB)
/* Get around 4.1+ remote/local flow control bug (from Gosmacs) */
ioctl(0, TIOCGETC, &otchars); /* Save original tchars */
ntchars = otchars;
ntchars.t_startc = -1; /* Kill start/stop */
ntchars.t_stopc = -1;
ioctl(0, TIOCSETC, &ntchars);
#endif /*IMAGEN && UCB*/
#endif /*!(SYSV || BBN)*/
#if BBN
modtty(1, M_GET | M_MODES, &ostate, sizeof(ostate)); /* Save old */
modtty(1, M_GET | M_MODES, &nstate, sizeof(nstate)); /* Setup new */
nstate.t_erase = nstate.t_kill = nstate.t_intr = nstate.t_esc =
nstate.t_eof = nstate.t_replay = 0377;
nstate.t_quit = BELL; /* ^G */
nstate.t_breaks = TB_ALL; /* break on all */
nstate.t_iflags &= ~TI_ECHO & ~TI_NOSPCL & ~TI_CRMOD;
/* no echos, specials on, no CR -> LF*/
nstate.t_iflags |= TI_CLR_MSB; /* ignore parity */
nstate.t_oflags &= ~TO_CRMOD & ~TO_AUTONL; /* no CR -> NL */
if (trm_flags & NOXONOFF)
nstate.t_oflags &= ~TO_XONXOFF;
else
nstate.t_oflags |= TO_XONXOFF;
nstate.t_oflags |= TO_CLR_MSB; /* no special high bits */
nstate.t_pagelen = 0; /* no paging of output */
trm_ospeed = ostate.t_ospeed;
#endif /*BBN*/
#if MINIX
tcgetattr(0, &origterm); /* How things are now */
newterm = origterm; /* Save them for restore on exit */
/* input flags */
newterm.c_iflag |= IGNBRK; /* Ignore break conditions.*/
newterm.c_iflag &= ~INLCR; /* Don't map NL to CR on input */
newterm.c_iflag &= ~ICRNL; /* Don't map CR to NL on input */
newterm.c_iflag &= ~BRKINT; /* Do not signal on break.*/
newterm.c_iflag &= ~IXON; /* Disable start/stop output control.*/
newterm.c_iflag &= ~IXOFF; /* Disable start/stop input control.*/
/* output flags */
newterm.c_oflag &= ~OPOST; /* Disable output processing */
/* line discipline */
newterm.c_lflag &= ~ISIG; /* Disable signals.*/
newterm.c_lflag &= ~ICANON; /* Want to disable canonical I/O */
newterm.c_lflag &= ~ECHO; /* Disable echo.*/
newterm.c_lflag &= ~ECHONL; /* Disable separate NL echo.*/
newterm.c_lflag &= ~IEXTEN; /* Disable input extensions.*/
newterm.c_cc[VMIN] = 1; /* Min. chars. on input (immed) */
ne
8000
wterm.c_cc[VTIME] = 0; /* Min. time delay on input (immed) */
/* Make it stick */
tcsetattr(0, TCSANOW, &newterm);
#endif /*MINIX*/
#if SYSV
ioctl(0, TCGETA, &origterm); /* How things are now */
newterm = origterm; /* Save them for restore on exit */
/* input flags */
newterm.c_iflag |= IGNBRK; /* Ignore break conditions.*/
newterm.c_iflag &= ~INLCR; /* Don't map NL to CR on input */
newterm.c_iflag &= ~ICRNL; /* Don't map CR to NL on input */
newterm.c_iflag &= ~BRKINT; /* Do not signal on break.*/
newterm.c_iflag &= ~IXON; /* Disable start/stop output control.*/
newterm.c_iflag &= ~IXOFF; /* Disable start/stop input control.*/
/* line discipline */
newterm.c_lflag &= ~ISIG; /* Disable signals.*/
newterm.c_lflag &= ~ICANON; /* Want to disable canonical I/O */
newterm.c_lflag &= ~ECHO; /* Disable echo.*/
newterm.c_cc[4] = 1; /* Min. chars. on input (immed) */
newterm.c_cc[5] = 1; /* Min. time delay on input (immed) */
/* Make it stick */
ioctl(0, TCSETA, &newterm);
#endif /*SYSV*/
#if (UCB || TOPS20)
{ int tldisc;
ioctl(0, TIOCGETD, &tldisc); /* Find line discipline */
/* The flag IGN_JOB_CONTROL has been introduced to allow job control haters
* to simply ignore the whole thing. When ELLE is compiled with
* -DIGN_JOB_CONTROL, it will exit properly when the Return to Superior
* command is executed.
*/
#if SIGTSTP
#ifndef IGN_JOB_CONTROL
if(tldisc == NTTYDISC) tsf_pause = 1;
#endif
#endif /*SIGTSTP*/
}
#endif /*UCB || TOPS20*/
}
/* TS_ENTER()
* Tell system to enter right terminal mode for editing.
* This is called before t_enter.
*/
ts_enter()
{
#if !(MINIX || SYSV || BBN)
ioctl(1, TIOCSETP, &nstate);
#if IMAGEN && UCB
ioctl(0, TIOCSETC, &ntchars); /* Restore new tchars */
#endif /*IMAGEN && UCB*/
#endif /*!(SYSV||BBN)*/
#if BBN
modtty (1, M_SET | M_MODES, &nstate, sizeof (nstate));
#endif /*BBN*/
#if MINIX
/* Make it behave as previously defined in ts_init */
tcsetattr(0, TCSANOW, &newterm);
#endif /*SYSV*/
#if SYSV
/* Make it behave as previously defined in ts_init */
ioctl(0, TCSETA, &newterm);
#endif /*SYSV*/
#if DNTTY /* DN hackery! Enable 8-bit input so as to read meta bit. */
if(dbg_isw)
{ tpoke(TH_CSET,T_2FLGS2,EEI); /* Enable ints */
tpoke(TH_CSETB,T_QUIT, 0377); /* Turn off QUIT intrpt */
}
else if(trm_flags & TF_METAKEY)
tpoke(TH_CSET,T_2FLGS2,T2_LITIN); /* Turn on 8-bit input! */
#endif /*DNTTY*/
}
/* TS_EXIT
* Tell system to restore old terminal mode (we are leaving edit mode).
* This is called after t_exit.
*/
ts_exit()
{
#if DNTTY
if(dbg_isw)
tpoke(TH_CCLR,T_2FLGS2,EEI); /* Turn off EEI bit */
else if(trm_flags & TF_METAKEY)
tpoke(TH_CCLR,T_2FLGS2,T2_LITIN); /* Turn off 8-bit input */
#endif /*DNTTY*/
#if !(MINIX || SYSV || BBN)
ioctl(1, TIOCSETP, &ostate); /* SYSV and BBN don't use stty */
#if IMAGEN && UCB
ioctl(0, TIOCSETC, &otchars); /* Restore original tchars */
#endif /*IMAGEN && UCB*/
#endif /*!(SYSV || BBN)*/
#if BBN
modtty (1, M_SET | M_MODES, &ostate, sizeof (ostate));
#endif /*BBN*/
#if MINIX
tcsetattr(0, TCSANOW, &origterm);
#endif /*MINIX*/
#if SYSV
ioctl(0, TCSETA, &origterm);
#endif /*SYSV*/
}
#if DNTTY
int thkcmd[] { 0, 0, -1 };
tpoke(cmd,bn,val)
int cmd, bn, val;
{
thkcmd[0] = cmd|bn;
thkcmd[1] = val;
if(ttyhak(0,&thkcmd) < 0)
return(-1);
else return(thkcmd[1]);
}
#endif /*DNTTY*/
/* TS_PAUSE - Stop process and return control of TTY to superior.
* There is also a flag variable, TSF_PAUSE, which indicates
* whether or not this routine will actually do anything.
*/
#if TOPS20
#include <jsys.h>
#endif
ts_pause()
{
#if TOPS20
int acs[5];
jsys(HALTF, acs);
#endif
#if UCB
#if SIGTSTP
signal(SIGTSTP, SIG_DFL);
#if BSD4_2
#define mask(s) (1 << ((s)-1))
sigsetmask(sigblock(0) &~ mask(SIGTSTP));
#endif /*BSD4_2*/
kill(0, SIGTSTP);
#if BSD4_2
sigblock(mask(SIGTSTP));
#endif /*BSD4_2*/
#endif /*SIGTSTP*/
#endif /*UCB*/
}
ts_winsize()
{
#ifdef TIOCGWINSZ
struct winsize winsize;
if (ioctl(1, TIOCGWINSZ, &winsize) == 0) {
if (winsize.ws_row != 0) scr_ht = winsize.ws_row;
if (winsize.ws_col != 0) scr_wid = winsize.ws_col;
}
#endif
}