source: trunk/minix/commands/elle/eesite.c@ 11

Last change on this file since 11 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 9.6 KB
Line 
1/* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
2 * This software is quasi-public; it may be used freely with
3 * like software, but may NOT be sold or made part of licensed
4 * products without permission of the author.
5 */
6/* EESITE Site dependent frobs
7 * Primarily TS_ routines for TTY control. Most site-dependent
8 * routine is TS_INP for detection of TTY input.
9 */
10
11#include "elle.h"
12
13#if !(V6)
14#include <signal.h> /* For SIGTSTP in ts_pause */
15#else
16#include "eesigs.h"
17#endif
18
19int tsf_pause = 0; /* Set if ts_pause works. Ref'd by equit in e_main */
20
21#if !(SYSV || BBN) /* SYSV and BBN have weird tty calls */
22
23#if MINIX
24#include <termios.h>
25struct termios origterm, newterm;
26#else
27#if V6
28 /* Normal V6 declarations, must provide explicitly */
29struct sgttyb {
30 char sg_ispeed;
31 char sg_ospeed;
32 char sg_erase;
33 char sg_kill;
34 int sg_flags;
35};
36#define ECHO (010)
37#define CRMOD (020)
38#define RAW (040)
39#else
40 /* Normal V7 UNIX declarations, can use include file */
41#include <sgtty.h>
42#endif
43
44struct sgttyb nstate; /* Both V6 and V7 */
45struct sgttyb ostate; /* Both V6 and V7 */
46#endif /*!(SYSV || BBN)*/
47#endif /*!MINIX*/
48
49
50#if BBN /* BBN system frobs */
51#include "/sys/sys/h/modtty.h"
52struct modes nstate;
53struct modes ostate;
54#endif /*BBN*/
55
56#if DNTTY /* DN TTY frobs */
57#include <tty.h>
58char partab[2]; /* to satisfy obscene ref in tty.h */
59#endif /*DNTTY*/
60
61
62#if (UCB || TOPS20) /* UCB, TOPS20 additional frobs */
63#include <sys/ioctl.h> /* For ts_inp() and tldisc */
64#if IMAGEN
65struct tchars otchars, ntchars; /* Original and new tchars */
66#endif /*IMAGEN*/
67#endif /*(UCB || TOPS20)*/
68
69#if SYSV /* System V (and PC/IX) crocks */
70#include <termio.h>
71#include <sys/ioctl.h>
72
73struct termio /* terminal i/o status flags */
74 origterm, /* status of terminal at start of ELLE */
75 newterm; /* status of terminal when using ELLE */
76#endif /*SYSV*/
77
78/* TS_INP
79 * Ask system if terminal input is available (on file descriptor 0).
80 * Returns non-zero if so, else returns zero.
81 * Very important that this call NOT hang or block in any way,
82 * because it is used to detect type-ahead by the user;
83 * return should be immediate whether or not input is waiting.
84 */
85ts_inp()
86{
87#if BBN /* Idiosyncratic */
88 int cap_buf[2];
89 capac (0, &cap_buf[0], 4);
90 return (cap_buf[0]);
91#endif /*BBN*/
92
93#if (DNTTY || ONYX) /* Have "empty()" syscall */
94 return(empty(0) ? 0 : 1);
95#endif /*DNTTY || ONYX*/
96#if (UCB || TOPS20) /* Have FIONREAD ioctl */
97 long retval;
98 if(ioctl(0,FIONREAD,&retval)) /* If this call fails, */
99 return(0); /* assume no input waiting */
100 return((retval ? 1 : 0));
101#endif /*UCB || TOPS20*/
102#if COHERENT
103 int retval;
104 ioctl(0, TIOCQUERY, &retval);
105 return((retval ? 1 : 0));
106#endif /*COHERENT*/
107#if VENIX86
108 struct sgttyb iocbuf;
109 ioctl(0, TIOCQCNT, &iocbuf);
110 return(iocbuf.sg_ispeed != 0 );
111#endif /*VENIX86*/
112
113#if !(BBN||COHERENT||DNTTY||ONYX||TOPS20||UCB||VENIX86)
114 return(0); /* Default - never any type-ahead, sigh */
115#endif
116}
117
118
119/* TS_INIT()
120 * Get terminal information from system, initialize things for
121 * ts_enter and ts_exit. This is called before t_init.
122 * Must set "trm_ospeed".
123 */
124ts_init()
125{
126#if DNTTY
127 signal(16,1); /* DN peculiar - turn off ctl-A */
128#endif /*DNTTY*/
129
130#if !(MINIX || SYSV || BBN) /* Normal UNIX stuff */
131 ioctl(1, TIOCGETP, &ostate); /* Remember old state */
132 nstate = ostate; /* Set up edit-mode state vars */
133 nstate.sg_flags |= RAW; /* We'll want raw mode */
134 nstate.sg_flags &= ~(ECHO|CRMOD); /* with no echoing */
135 trm_ospeed = ostate.sg_ospeed;
136
137#if (IMAGEN && UCB)
138 /* Get around 4.1+ remote/local flow control bug (from Gosmacs) */
139 ioctl(0, TIOCGETC, &otchars); /* Save original tchars */
140 ntchars = otchars;
141 ntchars.t_startc = -1; /* Kill start/stop */
142 ntchars.t_stopc = -1;
143 ioctl(0, TIOCSETC, &ntchars);
144#endif /*IMAGEN && UCB*/
145#endif /*!(SYSV || BBN)*/
146
147#if BBN
148 modtty(1, M_GET | M_MODES, &ostate, sizeof(ostate)); /* Save old */
149 modtty(1, M_GET | M_MODES, &nstate, sizeof(nstate)); /* Setup new */
150 nstate.t_erase = nstate.t_kill = nstate.t_intr = nstate.t_esc =
151 nstate.t_eof = nstate.t_replay = 0377;
152 nstate.t_quit = BELL; /* ^G */
153 nstate.t_breaks = TB_ALL; /* break on all */
154 nstate.t_iflags &= ~TI_ECHO & ~TI_NOSPCL & ~TI_CRMOD;
155 /* no echos, specials on, no CR -> LF*/
156 nstate.t_iflags |= TI_CLR_MSB; /* ignore parity */
157 nstate.t_oflags &= ~TO_CRMOD & ~TO_AUTONL; /* no CR -> NL */
158 if (trm_flags & NOXONOFF)
159 nstate.t_oflags &= ~TO_XONXOFF;
160 else
161 nstate.t_oflags |= TO_XONXOFF;
162
163 nstate.t_oflags |= TO_CLR_MSB; /* no special high bits */
164 nstate.t_pagelen = 0; /* no paging of output */
165 trm_ospeed = ostate.t_ospeed;
166#endif /*BBN*/
167
168#if MINIX
169 tcgetattr(0, &origterm); /* How things are now */
170 newterm = origterm; /* Save them for restore on exit */
171
172 /* input flags */
173 newterm.c_iflag |= IGNBRK; /* Ignore break conditions.*/
174 newterm.c_iflag &= ~INLCR; /* Don't map NL to CR on input */
175 newterm.c_iflag &= ~ICRNL; /* Don't map CR to NL on input */
176 newterm.c_iflag &= ~BRKINT; /* Do not signal on break.*/
177 newterm.c_iflag &= ~IXON; /* Disable start/stop output control.*/
178 newterm.c_iflag &= ~IXOFF; /* Disable start/stop input control.*/
179
180 /* output flags */
181 newterm.c_oflag &= ~OPOST; /* Disable output processing */
182
183 /* line discipline */
184 newterm.c_lflag &= ~ISIG; /* Disable signals.*/
185 newterm.c_lflag &= ~ICANON; /* Want to disable canonical I/O */
186 newterm.c_lflag &= ~ECHO; /* Disable echo.*/
187 newterm.c_lflag &= ~ECHONL; /* Disable separate NL echo.*/
188 newterm.c_lflag &= ~IEXTEN; /* Disable input extensions.*/
189
190 newterm.c_cc[VMIN] = 1; /* Min. chars. on input (immed) */
191 newterm.c_cc[VTIME] = 0; /* Min. time delay on input (immed) */
192
193 /* Make it stick */
194 tcsetattr(0, TCSANOW, &newterm);
195#endif /*MINIX*/
196
197#if SYSV
198 ioctl(0, TCGETA, &origterm); /* How things are now */
199 newterm = origterm; /* Save them for restore on exit */
200
201 /* input flags */
202 newterm.c_iflag |= IGNBRK; /* Ignore break conditions.*/
203 newterm.c_iflag &= ~INLCR; /* Don't map NL to CR on input */
204 newterm.c_iflag &= ~ICRNL; /* Don't map CR to NL on input */
205 newterm.c_iflag &= ~BRKINT; /* Do not signal on break.*/
206 newterm.c_iflag &= ~IXON; /* Disable start/stop output control.*/
207 newterm.c_iflag &= ~IXOFF; /* Disable start/stop input control.*/
208
209 /* line discipline */
210 newterm.c_lflag &= ~ISIG; /* Disable signals.*/
211 newterm.c_lflag &= ~ICANON; /* Want to disable canonical I/O */
212 newterm.c_lflag &= ~ECHO; /* Disable echo.*/
213
214 newterm.c_cc[4] = 1; /* Min. chars. on input (immed) */
215 newterm.c_cc[5] = 1; /* Min. time delay on input (immed) */
216
217 /* Make it stick */
218 ioctl(0, TCSETA, &newterm);
219#endif /*SYSV*/
220
221#if (UCB || TOPS20)
222 { int tldisc;
223 ioctl(0, TIOCGETD, &tldisc); /* Find line discipline */
224
225/* The flag IGN_JOB_CONTROL has been introduced to allow job control haters
226 * to simply ignore the whole thing. When ELLE is compiled with
227 * -DIGN_JOB_CONTROL, it will exit properly when the Return to Superior
228 * command is executed.
229*/
230#if SIGTSTP
231#ifndef IGN_JOB_CONTROL
232 if(tldisc == NTTYDISC) tsf_pause = 1;
233#endif
234#endif /*SIGTSTP*/
235
236 }
237#endif /*UCB || TOPS20*/
238}
239
240/* TS_ENTER()
241 * Tell system to enter right terminal mode for editing.
242 * This is called before t_enter.
243 */
244ts_enter()
245{
246#if !(MINIX || SYSV || BBN)
247 ioctl(1, TIOCSETP, &nstate);
248#if IMAGEN && UCB
249 ioctl(0, TIOCSETC, &ntchars); /* Restore new tchars */
250#endif /*IMAGEN && UCB*/
251#endif /*!(SYSV||BBN)*/
252
253#if BBN
254 modtty (1, M_SET | M_MODES, &nstate, sizeof (nstate));
255#endif /*BBN*/
256
257#if MINIX
258 /* Make it behave as previously defined in ts_init */
259 tcsetattr(0, TCSANOW, &newterm);
260#endif /*SYSV*/
261
262#if SYSV
263 /* Make it behave as previously defined in ts_init */
264 ioctl(0, TCSETA, &newterm);
265#endif /*SYSV*/
266
267#if DNTTY /* DN hackery! Enable 8-bit input so as to read meta bit. */
268 if(dbg_isw)
269 { tpoke(TH_CSET,T_2FLGS2,EEI); /* Enable ints */
270 tpoke(TH_CSETB,T_QUIT, 0377); /* Turn off QUIT intrpt */
271 }
272 else if(trm_flags & TF_METAKEY)
273 tpoke(TH_CSET,T_2FLGS2,T2_LITIN); /* Turn on 8-bit input! */
274#endif /*DNTTY*/
275}
276
277/* TS_EXIT
278 * Tell system to restore old terminal mode (we are leaving edit mode).
279 * This is called after t_exit.
280 */
281ts_exit()
282{
283#if DNTTY
284 if(dbg_isw)
285 tpoke(TH_CCLR,T_2FLGS2,EEI); /* Turn off EEI bit */
286 else if(trm_flags & TF_METAKEY)
287 tpoke(TH_CCLR,T_2FLGS2,T2_LITIN); /* Turn off 8-bit input */
288#endif /*DNTTY*/
289
290#if !(MINIX || SYSV || BBN)
291 ioctl(1, TIOCSETP, &ostate); /* SYSV and BBN don't use stty */
292#if IMAGEN && UCB
293 ioctl(0, TIOCSETC, &otchars); /* Restore original tchars */
294#endif /*IMAGEN && UCB*/
295#endif /*!(SYSV || BBN)*/
296
297#if BBN
298 modtty (1, M_SET | M_MODES, &ostate, sizeof (ostate));
299#endif /*BBN*/
300
301#if MINIX
302 tcsetattr(0, TCSANOW, &origterm);
303#endif /*MINIX*/
304
305#if SYSV
306 ioctl(0, TCSETA, &origterm);
307#endif /*SYSV*/
308}
309
310#if DNTTY
311int thkcmd[] { 0, 0, -1 };
312tpoke(cmd,bn,val)
313int cmd, bn, val;
314{
315 thkcmd[0] = cmd|bn;
316 thkcmd[1] = val;
317 if(ttyhak(0,&thkcmd) < 0)
318 return(-1);
319 else return(thkcmd[1]);
320}
321#endif /*DNTTY*/
322
323
324/* TS_PAUSE - Stop process and return control of TTY to superior.
325 * There is also a flag variable, TSF_PAUSE, which indicates
326 * whether or not this routine will actually do anything.
327 */
328#if TOPS20
329#include <jsys.h>
330#endif
331
332ts_pause()
333{
334#if TOPS20
335 int acs[5];
336 jsys(HALTF, acs);
337#endif
338
339#if UCB
340#if SIGTSTP
341 signal(SIGTSTP, SIG_DFL);
342#if BSD4_2
343#define mask(s) (1 << ((s)-1))
344 sigsetmask(sigblock(0) &~ mask(SIGTSTP));
345#endif /*BSD4_2*/
346 kill(0, SIGTSTP);
347#if BSD4_2
348 sigblock(mask(SIGTSTP));
349#endif /*BSD4_2*/
350#endif /*SIGTSTP*/
351#endif /*UCB*/
352}
353
354ts_winsize()
355{
356#ifdef TIOCGWINSZ
357 struct winsize winsize;
358
359 if (ioctl(1, TIOCGWINSZ, &winsize) == 0) {
360 if (winsize.ws_row != 0) scr_ht = winsize.ws_row;
361 if (winsize.ws_col != 0) scr_wid = winsize.ws_col;
362 }
363#endif
364}
Note: See TracBrowser for help on using the repository browser.