00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "elle.h"
00012
00013 #if !(V6)
00014 #include <signal.h>
00015 #else
00016 #include "eesigs.h"
00017 #endif
00018
00019 int tsf_pause = 0;
00020
00021 #if !(SYSV || BBN)
00022
00023 #if MINIX
00024 #include <termios.h>
00025 struct termios origterm, newterm;
00026 #else
00027 #if V6
00028
00029 struct sgttyb {
00030 char sg_ispeed;
00031 char sg_ospeed;
00032 char sg_erase;
00033 char sg_kill;
00034 int sg_flags;
00035 };
00036 #define ECHO (010)
00037 #define CRMOD (020)
00038 #define RAW (040)
00039 #else
00040
00041 #include <sgtty.h>
00042 #endif
00043
00044 struct sgttyb nstate;
00045 struct sgttyb ostate;
00046 #endif
00047 #endif
00050 #if BBN
00051 #include "/sys/sys/h/modtty.h"
00052 struct modes nstate;
00053 struct modes ostate;
00054 #endif
00055
00056 #if DNTTY
00057 #include <tty.h>
00058 char partab[2];
00059 #endif
00060
00061
00062 #if (UCB || TOPS20)
00063 #include <sys/ioctl.h>
00064 #if IMAGEN
00065 struct tchars otchars, ntchars;
00066 #endif
00067 #endif
00068
00069 #if SYSV
00070 #include <termio.h>
00071 #include <sys/ioctl.h>
00072
00073 struct termio
00074 origterm,
00075 newterm;
00076 #endif
00077
00078
00079
00080
00081
00082
00083
00084
00085 ts_inp()
00086 {
00087 #if BBN
00088 int cap_buf[2];
00089 capac (0, &cap_buf[0], 4);
00090 return (cap_buf[0]);
00091 #endif
00092
00093 #if (DNTTY || ONYX)
00094 return(empty(0) ? 0 : 1);
00095 #endif
00096 #if (UCB || TOPS20)
00097 long retval;
00098 if(ioctl(0,FIONREAD,&retval))
00099 return(0);
00100 return((retval ? 1 : 0));
00101 #endif
00102 #if COHERENT
00103 int retval;
00104 ioctl(0, TIOCQUERY, &retval);
00105 return((retval ? 1 : 0));
00106 #endif
00107 #if VENIX86
00108 struct sgttyb iocbuf;
00109 ioctl(0, TIOCQCNT, &iocbuf);
00110 return(iocbuf.sg_ispeed != 0 );
00111 #endif
00112
00113 #if !(BBN||COHERENT||DNTTY||ONYX||TOPS20||UCB||VENIX86)
00114 return(0);
00115 #endif
00116 }
00117
00118
00119
00120
00121
00122
00123
00124 ts_init()
00125 {
00126 #if DNTTY
00127 signal(16,1);
00128 #endif
00129
00130 #if !(MINIX || SYSV || BBN)
00131 ioctl(1, TIOCGETP, &ostate);
00132 nstate = ostate;
00133 nstate.sg_flags |= RAW;
00134 nstate.sg_flags &= ~(ECHO|CRMOD);
00135 trm_ospeed = ostate.sg_ospeed;
00136
00137 #if (IMAGEN && UCB)
00138
00139 ioctl(0, TIOCGETC, &otchars);
00140 ntchars = otchars;
00141 ntchars.t_startc = -1;
00142 ntchars.t_stopc = -1;
00143 ioctl(0, TIOCSETC, &ntchars);
00144 #endif
00145 #endif
00147 #if BBN
00148 modtty(1, M_GET | M_MODES, &ostate, sizeof(ostate));
00149 modtty(1, M_GET | M_MODES, &nstate, sizeof(nstate));
00150 nstate.t_erase = nstate.t_kill = nstate.t_intr = nstate.t_esc =
00151 nstate.t_eof = nstate.t_replay = 0377;
00152 nstate.t_quit = BELL;
00153 nstate.t_breaks = TB_ALL;
00154 nstate.t_iflags &= ~TI_ECHO & ~TI_NOSPCL & ~TI_CRMOD;
00155
00156 nstate.t_iflags |= TI_CLR_MSB;
00157 nstate.t_oflags &= ~TO_CRMOD & ~TO_AUTONL;
00158 if (trm_flags & NOXONOFF)
00159 nstate.t_oflags &= ~TO_XONXOFF;
00160 else
00161 nstate.t_oflags |= TO_XONXOFF;
00162
00163 nstate.t_oflags |= TO_CLR_MSB;
00164 nstate.t_pagelen = 0;
00165 trm_ospeed = ostate.t_ospeed;
00166 #endif
00167
00168 #if MINIX
00169 tcgetattr(0, &origterm);
00170 newterm = origterm;
00171
00172
00173 newterm.c_iflag |= IGNBRK;
00174 newterm.c_iflag &= ~INLCR;
00175 newterm.c_iflag &= ~ICRNL;
00176 newterm.c_iflag &= ~BRKINT;
00177 newterm.c_iflag &= ~IXON;
00178 newterm.c_iflag &= ~IXOFF;
00179
00180
00181 newterm.c_oflag &= ~OPOST;
00182
00183
00184 newterm.c_lflag &= ~ISIG;
00185 newterm.c_lflag &= ~ICANON;
00186 newterm.c_lflag &= ~ECHO;
00187 newterm.c_lflag &= ~ECHONL;
00188 newterm.c_lflag &= ~IEXTEN;
00189
00190 newterm.c_cc[VMIN] = 1;
00191 newterm.c_cc[VTIME] = 0;
00192
00193
00194 tcsetattr(0, TCSANOW, &newterm);
00195 #endif
00196
00197 #if SYSV
00198 ioctl(0, TCGETA, &origterm);
00199 newterm = origterm;
00200
00201
00202 newterm.c_iflag |= IGNBRK;
00203 newterm.c_iflag &= ~INLCR;
00204 newterm.c_iflag &= ~ICRNL;
00205 newterm.c_iflag &= ~BRKINT;
00206 newterm.c_iflag &= ~IXON;
00207 newterm.c_iflag &= ~IXOFF;
00208
00209
00210 newterm.c_lflag &= ~ISIG;
00211 newterm.c_lflag &= ~ICANON;
00212 newterm.c_lflag &= ~ECHO;
00213
00214 newterm.c_cc[4] = 1;
00215 newterm.c_cc[5] = 1;
00216
00217
00218 ioctl(0, TCSETA, &newterm);
00219 #endif
00220
00221 #if (UCB || TOPS20)
00222 { int tldisc;
00223 ioctl(0, TIOCGETD, &tldisc);
00224
00225
00226
00227
00228
00229
00230 #if SIGTSTP
00231 #ifndef IGN_JOB_CONTROL
00232 if(tldisc == NTTYDISC) tsf_pause = 1;
00233 #endif
00234 #endif
00235
00236 }
00237 #endif
00238 }
00239
00240
00241
00242
00243
00244 ts_enter()
00245 {
00246 #if !(MINIX || SYSV || BBN)
00247 ioctl(1, TIOCSETP, &nstate);
00248 #if IMAGEN && UCB
00249 ioctl(0, TIOCSETC, &ntchars);
00250 #endif
00251 #endif
00253 #if BBN
00254 modtty (1, M_SET | M_MODES, &nstate, sizeof (nstate));
00255 #endif
00256
00257 #if MINIX
00258
00259 tcsetattr(0, TCSANOW, &newterm);
00260 #endif
00261
00262 #if SYSV
00263
00264 ioctl(0, TCSETA, &newterm);
00265 #endif
00266
00267 #if DNTTY
00268 if(dbg_isw)
00269 { tpoke(TH_CSET,T_2FLGS2,EEI);
00270 tpoke(TH_CSETB,T_QUIT, 0377);
00271 }
00272 else if(trm_flags & TF_METAKEY)
00273 tpoke(TH_CSET,T_2FLGS2,T2_LITIN);
00274 #endif
00275 }
00276
00277
00278
00279
00280
00281 ts_exit()
00282 {
00283 #if DNTTY
00284 if(dbg_isw)
00285 tpoke(TH_CCLR,T_2FLGS2,EEI);
00286 else if(trm_flags & TF_METAKEY)
00287 tpoke(TH_CCLR,T_2FLGS2,T2_LITIN);
00288 #endif
00289
00290 #if !(MINIX || SYSV || BBN)
00291 ioctl(1, TIOCSETP, &ostate);
00292 #if IMAGEN && UCB
00293 ioctl(0, TIOCSETC, &otchars);
00294 #endif
00295 #endif
00297 #if BBN
00298 modtty (1, M_SET | M_MODES, &ostate, sizeof (ostate));
00299 #endif
00300
00301 #if MINIX
00302 tcsetattr(0, TCSANOW, &origterm);
00303 #endif
00304
00305 #if SYSV
00306 ioctl(0, TCSETA, &origterm);
00307 #endif
00308 }
00309
00310 #if DNTTY
00311 int thkcmd[] { 0, 0, -1 };
00312 tpoke(cmd,bn,val)
00313 int cmd, bn, val;
00314 {
00315 thkcmd[0] = cmd|bn;
00316 thkcmd[1] = val;
00317 if(ttyhak(0,&thkcmd) < 0)
00318 return(-1);
00319 else return(thkcmd[1]);
00320 }
00321 #endif
00322
00323
00324
00325
00326
00327
00328 #if TOPS20
00329 #include <jsys.h>
00330 #endif
00331
00332 ts_pause()
00333 {
00334 #if TOPS20
00335 int acs[5];
00336 jsys(HALTF, acs);
00337 #endif
00338
00339 #if UCB
00340 #if SIGTSTP
00341 signal(SIGTSTP, SIG_DFL);
00342 #if BSD4_2
00343 #define mask(s) (1 << ((s)-1))
00344 sigsetmask(sigblock(0) &~ mask(SIGTSTP));
00345 #endif
00346 kill(0, SIGTSTP);
00347 #if BSD4_2
00348 sigblock(mask(SIGTSTP));
00349 #endif
00350 #endif
00351 #endif
00352 }
00353
00354 ts_winsize()
00355 {
00356 #ifdef TIOCGWINSZ
00357 struct winsize winsize;
00358
00359 if (ioctl(1, TIOCGWINSZ, &winsize) == 0) {
00360 if (winsize.ws_row != 0) scr_ht = winsize.ws_row;
00361 if (winsize.ws_col != 0) scr_wid = winsize.ws_col;
00362 }
00363 #endif
00364 }