eesite.c

Go to the documentation of this file.
00001 /* ELLE - Copyright 1982, 1984, 1987 by Ken Harrenstien, SRI International
00002  *      This software is quasi-public; it may be used freely with
00003  *      like software, but may NOT be sold or made part of licensed
00004  *      products without permission of the author.
00005  */
00006 /* EESITE       Site dependent frobs
00007  *      Primarily TS_ routines for TTY control.  Most site-dependent
00008  *      routine is TS_INP for detection of TTY input.
00009  */
00010 
00011 #include "elle.h"
00012 
00013 #if !(V6)
00014 #include <signal.h>     /* For SIGTSTP in ts_pause */
00015 #else
00016 #include "eesigs.h"
00017 #endif
00018 
00019 int tsf_pause = 0;      /* Set if ts_pause works.  Ref'd by equit in e_main */
00020 
00021 #if !(SYSV || BBN)      /* SYSV and BBN have weird tty calls */
00022 
00023 #if MINIX
00024 #include <termios.h>
00025 struct termios origterm, newterm;
00026 #else
00027 #if V6
00028         /* Normal V6 declarations, must provide explicitly */
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         /* Normal V7 UNIX declarations, can use include file */
00041 #include <sgtty.h>
00042 #endif
00043 
00044 struct sgttyb nstate;   /* Both V6 and V7 */
00045 struct sgttyb ostate;   /* Both V6 and V7 */
00046 #endif 
00047 #endif 
00050 #if BBN         /* BBN system frobs */
00051 #include "/sys/sys/h/modtty.h"
00052 struct modes  nstate;
00053 struct modes  ostate;
00054 #endif /*BBN*/
00055 
00056 #if DNTTY               /* DN TTY frobs */
00057 #include <tty.h>
00058 char partab[2];         /* to satisfy obscene ref in tty.h */
00059 #endif /*DNTTY*/
00060 
00061 
00062 #if (UCB || TOPS20)             /* UCB, TOPS20 additional frobs */
00063 #include <sys/ioctl.h>          /* For ts_inp() and tldisc */
00064 #if IMAGEN
00065 struct tchars otchars, ntchars; /* Original and new tchars */
00066 #endif /*IMAGEN*/
00067 #endif /*(UCB || TOPS20)*/
00068 
00069 #if SYSV                /* System V (and PC/IX) crocks */
00070 #include <termio.h>
00071 #include <sys/ioctl.h>
00072 
00073 struct termio   /* terminal i/o status flags */
00074         origterm,       /* status of terminal at start of ELLE */
00075         newterm;        /* status of terminal when using ELLE */
00076 #endif /*SYSV*/
00077 
00078 /* TS_INP
00079  *      Ask system if terminal input is available (on file descriptor 0).
00080  *      Returns non-zero if so, else returns zero.
00081  *      Very important that this call NOT hang or block in any way,
00082  *      because it is used to detect type-ahead by the user;
00083  *      return should be immediate whether or not input is waiting.
00084  */
00085 ts_inp()
00086 {
00087 #if BBN                         /* Idiosyncratic */
00088         int   cap_buf[2];
00089         capac (0, &cap_buf[0], 4);
00090         return (cap_buf[0]);
00091 #endif /*BBN*/
00092 
00093 #if (DNTTY || ONYX)             /* Have "empty()" syscall */
00094         return(empty(0) ? 0 : 1);
00095 #endif /*DNTTY || ONYX*/
00096 #if (UCB || TOPS20)             /* Have FIONREAD ioctl */
00097         long retval;
00098         if(ioctl(0,FIONREAD,&retval))   /* If this call fails, */
00099                 return(0);              /* assume no input waiting */
00100         return((retval ? 1 : 0));
00101 #endif /*UCB || TOPS20*/
00102 #if COHERENT
00103         int retval;
00104         ioctl(0, TIOCQUERY, &retval);
00105         return((retval ? 1 : 0));
00106 #endif /*COHERENT*/
00107 #if VENIX86
00108         struct sgttyb iocbuf;
00109         ioctl(0, TIOCQCNT, &iocbuf);
00110         return(iocbuf.sg_ispeed != 0 );
00111 #endif /*VENIX86*/
00112 
00113 #if !(BBN||COHERENT||DNTTY||ONYX||TOPS20||UCB||VENIX86)
00114         return(0);              /* Default - never any type-ahead, sigh */
00115 #endif
00116 }
00117 
00118 
00119 /* TS_INIT()
00120  *      Get terminal information from system, initialize things for
00121  *      ts_enter and ts_exit.  This is called before t_init.
00122  *      Must set "trm_ospeed".
00123  */
00124 ts_init()
00125 {
00126 #if DNTTY
00127         signal(16,1);           /* DN peculiar - turn off ctl-A */
00128 #endif /*DNTTY*/
00129 
00130 #if !(MINIX || SYSV || BBN)             /* Normal UNIX stuff */
00131         ioctl(1, TIOCGETP, &ostate);    /* Remember old state */
00132         nstate = ostate;                /* Set up edit-mode state vars */
00133         nstate.sg_flags |= RAW;                 /* We'll want raw mode */
00134         nstate.sg_flags &= ~(ECHO|CRMOD);       /* with no echoing */
00135         trm_ospeed = ostate.sg_ospeed;
00136 
00137 #if (IMAGEN && UCB)
00138         /* Get around 4.1+ remote/local flow control bug (from Gosmacs) */
00139         ioctl(0, TIOCGETC, &otchars);  /* Save original tchars */
00140         ntchars = otchars;
00141         ntchars.t_startc = -1;          /* Kill start/stop */
00142         ntchars.t_stopc  = -1;
00143         ioctl(0, TIOCSETC, &ntchars);
00144 #endif /*IMAGEN && UCB*/
00145 #endif 
00147 #if BBN
00148         modtty(1, M_GET | M_MODES, &ostate, sizeof(ostate));    /* Save old */
00149         modtty(1, M_GET | M_MODES, &nstate, sizeof(nstate));    /* Setup new */
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;                   /* ^G */
00153         nstate.t_breaks = TB_ALL;               /* break on all */
00154         nstate.t_iflags &= ~TI_ECHO & ~TI_NOSPCL & ~TI_CRMOD;
00155                                 /* no echos, specials on, no CR -> LF*/
00156         nstate.t_iflags |= TI_CLR_MSB;                  /* ignore parity */
00157         nstate.t_oflags &= ~TO_CRMOD & ~TO_AUTONL;      /* no CR -> NL */
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;          /* no special high bits */
00164         nstate.t_pagelen = 0;                   /* no paging of output */
00165         trm_ospeed = ostate.t_ospeed;
00166 #endif /*BBN*/
00167 
00168 #if MINIX
00169         tcgetattr(0, &origterm);        /* How things are now */
00170         newterm = origterm;             /* Save them for restore on exit */
00171 
00172         /* input flags */
00173         newterm.c_iflag |= IGNBRK;      /* Ignore break conditions.*/
00174         newterm.c_iflag &= ~INLCR;      /* Don't map NL to CR on input */
00175         newterm.c_iflag &= ~ICRNL;      /* Don't map CR to NL on input */
00176         newterm.c_iflag &= ~BRKINT;     /* Do not signal on break.*/
00177         newterm.c_iflag &= ~IXON;       /* Disable start/stop output control.*/
00178         newterm.c_iflag &= ~IXOFF;      /* Disable start/stop input control.*/
00179 
00180         /* output flags */
00181         newterm.c_oflag &= ~OPOST;      /* Disable output processing */
00182 
00183         /* line discipline */
00184         newterm.c_lflag &= ~ISIG;       /* Disable signals.*/
00185         newterm.c_lflag &= ~ICANON;     /* Want to disable canonical I/O */
00186         newterm.c_lflag &= ~ECHO;       /* Disable echo.*/
00187         newterm.c_lflag &= ~ECHONL;     /* Disable separate NL echo.*/
00188         newterm.c_lflag &= ~IEXTEN;     /* Disable input extensions.*/
00189 
00190         newterm.c_cc[VMIN] = 1;         /* Min. chars. on input (immed) */
00191         newterm.c_cc[VTIME] = 0;        /* Min. time delay on input (immed) */
00192 
00193         /* Make it stick */
00194         tcsetattr(0, TCSANOW, &newterm);
00195 #endif /*MINIX*/
00196 
00197 #if SYSV
00198         ioctl(0, TCGETA, &origterm);    /* How things are now */
00199         newterm = origterm;             /* Save them for restore on exit */
00200 
00201         /* input flags */
00202         newterm.c_iflag |= IGNBRK;      /* Ignore break conditions.*/
00203         newterm.c_iflag &= ~INLCR;      /* Don't map NL to CR on input */
00204         newterm.c_iflag &= ~ICRNL;      /* Don't map CR to NL on input */
00205         newterm.c_iflag &= ~BRKINT;     /* Do not signal on break.*/
00206         newterm.c_iflag &= ~IXON;       /* Disable start/stop output control.*/
00207         newterm.c_iflag &= ~IXOFF;      /* Disable start/stop input control.*/
00208 
00209         /* line discipline */
00210         newterm.c_lflag &= ~ISIG;       /* Disable signals.*/
00211         newterm.c_lflag &= ~ICANON;     /* Want to disable canonical I/O */
00212         newterm.c_lflag &= ~ECHO;       /* Disable echo.*/
00213 
00214         newterm.c_cc[4] = 1;            /* Min. chars. on input (immed) */
00215         newterm.c_cc[5] = 1;            /* Min. time delay on input (immed) */
00216 
00217         /* Make it stick */
00218         ioctl(0, TCSETA, &newterm);
00219 #endif /*SYSV*/
00220 
00221 #if (UCB || TOPS20)
00222         {       int tldisc;
00223                 ioctl(0, TIOCGETD, &tldisc);    /* Find line discipline */
00224 
00225 /* The flag IGN_JOB_CONTROL has been introduced to allow job control haters
00226  * to simply ignore the whole thing.  When ELLE is compiled with
00227  * -DIGN_JOB_CONTROL, it will exit properly when the Return to Superior
00228  * command is executed.
00229 */
00230 #if SIGTSTP
00231 #ifndef IGN_JOB_CONTROL
00232                 if(tldisc == NTTYDISC) tsf_pause = 1;
00233 #endif
00234 #endif /*SIGTSTP*/
00235 
00236         }
00237 #endif /*UCB || TOPS20*/
00238 }
00239 
00240 /* TS_ENTER()
00241  *      Tell system to enter right terminal mode for editing.
00242  *      This is called before t_enter.
00243  */
00244 ts_enter()
00245 {
00246 #if !(MINIX || SYSV || BBN)
00247         ioctl(1, TIOCSETP, &nstate);
00248 #if IMAGEN && UCB
00249         ioctl(0, TIOCSETC, &ntchars);   /* Restore new tchars */
00250 #endif /*IMAGEN && UCB*/
00251 #endif 
00253 #if BBN
00254         modtty (1, M_SET | M_MODES, &nstate, sizeof (nstate));
00255 #endif /*BBN*/
00256 
00257 #if MINIX
00258         /* Make it behave as previously defined in ts_init */
00259         tcsetattr(0, TCSANOW, &newterm);
00260 #endif /*SYSV*/
00261 
00262 #if SYSV
00263         /* Make it behave as previously defined in ts_init */
00264         ioctl(0, TCSETA, &newterm);
00265 #endif /*SYSV*/
00266 
00267 #if DNTTY       /* DN hackery!  Enable 8-bit input so as to read meta bit. */
00268         if(dbg_isw)
00269           {     tpoke(TH_CSET,T_2FLGS2,EEI);    /* Enable ints */
00270                 tpoke(TH_CSETB,T_QUIT, 0377);   /* Turn off QUIT intrpt */
00271           }
00272         else if(trm_flags & TF_METAKEY)
00273                 tpoke(TH_CSET,T_2FLGS2,T2_LITIN); /* Turn on 8-bit input! */
00274 #endif /*DNTTY*/
00275 }
00276 
00277 /* TS_EXIT
00278  *      Tell system to restore old terminal mode (we are leaving edit mode).
00279  *      This is called after t_exit.
00280  */
00281 ts_exit()
00282 {
00283 #if DNTTY
00284         if(dbg_isw)
00285                 tpoke(TH_CCLR,T_2FLGS2,EEI);    /* Turn off EEI bit */
00286         else if(trm_flags & TF_METAKEY)
00287                 tpoke(TH_CCLR,T_2FLGS2,T2_LITIN); /* Turn off 8-bit input */
00288 #endif /*DNTTY*/
00289 
00290 #if !(MINIX || SYSV || BBN)
00291         ioctl(1, TIOCSETP, &ostate);    /* SYSV and BBN don't use stty */
00292 #if IMAGEN && UCB
00293         ioctl(0, TIOCSETC, &otchars);   /* Restore original tchars */
00294 #endif /*IMAGEN && UCB*/
00295 #endif 
00297 #if BBN
00298         modtty (1, M_SET | M_MODES, &ostate, sizeof (ostate));
00299 #endif /*BBN*/
00300 
00301 #if MINIX
00302         tcsetattr(0, TCSANOW, &origterm);
00303 #endif /*MINIX*/
00304 
00305 #if SYSV
00306         ioctl(0, TCSETA, &origterm);
00307 #endif /*SYSV*/
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 /*DNTTY*/
00322 
00323 
00324 /* TS_PAUSE - Stop process and return control of TTY to superior.
00325  *      There is also a flag variable, TSF_PAUSE, which indicates
00326  *      whether or not this routine will actually do anything.
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 /*BSD4_2*/
00346         kill(0, SIGTSTP);
00347 #if BSD4_2
00348         sigblock(mask(SIGTSTP));
00349 #endif /*BSD4_2*/
00350 #endif /*SIGTSTP*/
00351 #endif /*UCB*/
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 }

Generated on Fri Apr 14 22:56:50 2006 for minix by  doxygen 1.4.6