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