install approved copyright notice
[unix-history] / usr / src / usr.bin / tset / tset.c
index 7e44cb1..0e9372a 100644 (file)
@@ -1,29 +1,40 @@
 /*
  * Copyright (c) 1980 Regents of the University of California.
 /*
  * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
 char copyright[] =
 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  All rights reserved.\n";
  */
 
 #ifndef lint
 char copyright[] =
 "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)tset.c     5.2 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)tset.c     5.11 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
 **  TSET -- set terminal modes
 **
 **     This program does sophisticated terminal initialization.
 
 /*
 **  TSET -- set terminal modes
 **
 **     This program does sophisticated terminal initialization.
-**     I recommend that you include it in your .start_up or .login
+**     I recommend that you include it in your .profile or .login
 **     file to initialize whatever terminal you are on.
 **
 **     There are several features:
 **
 **     file to initialize whatever terminal you are on.
 **
 **     There are several features:
 **
-**     A special file or sequence (as controlled by the ttycap file)
+**     A special file or sequence (as controlled by the termcap file)
 **     is sent to the terminal.
 **
 **     Mode bits are set on a per-terminal_type basis (much better
 **     is sent to the terminal.
 **
 **     Mode bits are set on a per-terminal_type basis (much better
@@ -45,12 +56,10 @@ static char sccsid[] = "@(#)tset.c  5.2 (Berkeley) %G%";
 **     to be -- if you reply with just a newline, it will default
 **     to the type given.
 **
 **     to be -- if you reply with just a newline, it will default
 **     to the type given.
 **
-**     The htmp file, used by ex, etc., can be updated.
-**
 **     The current terminal type can be queried.
 **
 **     Usage:
 **     The current terminal type can be queried.
 **
 **     Usage:
-**             tset [-] [-EC] [-eC] [-kC] [-s] [-h] [-u] [-r]
+**             tset [-] [-EC] [-eC] [-kC] [-iC] [-s] [-h] [-u] [-r]
 **                     [-m [ident] [test baudrate] :type]
 **                     [-Q] [-I] [-S] [type]
 **
 **                     [-m [ident] [test baudrate] :type]
 **                     [-Q] [-I] [-S] [type]
 **
@@ -84,18 +93,21 @@ static char sccsid[] = "@(#)tset.c  5.2 (Berkeley) %G%";
 **                     except those which cannot backspace (e.g.,
 **                     a TTY 33).  C defaults to control-H.
 **             -eC -- set the erase character to C on all terminals.
 **                     except those which cannot backspace (e.g.,
 **                     a TTY 33).  C defaults to control-H.
 **             -eC -- set the erase character to C on all terminals.
-**                     C defaults to control-H.  If neither -E or -e
-**                     are specified, the erase character is set to
-**                     control-H if the terminal can both backspace
-**                     and not overstrike (e.g., a CRT).  If the erase
-**                     character is NULL (zero byte), it will be reset
-**                     to '#' if nothing else is specified.
+**                     C defaults to control-H.  If not specified,
+**                     the erase character is untouched; however, if
+**                     not specified and the erase character is NULL
+**                     (zero byte), the erase character  is set to delete.
 **             -kC -- set the kill character to C on all terminals.
 **                     Default for C is control-X.  If not specified,
 **                     the kill character is untouched; however, if
 **                     not specified and the kill character is NULL
 **             -kC -- set the kill character to C on all terminals.
 **                     Default for C is control-X.  If not specified,
 **                     the kill character is untouched; however, if
 **                     not specified and the kill character is NULL
-**                     (zero byte), the kill character is set to '@'.
-**             -iC -- reserved for setable interrupt character.
+**                     (zero byte), the kill character is set to control-U.
+**             -iC -- set the interrupt character to C on all terminals.
+**                     Default for C is control-C.  If not specified, the
+**                     interrupt character is untouched; however, if
+**                     not specified and the interrupt character is NULL
+**                     (zero byte), the interrupt character is set to
+**                     control-C.
 **             -qC -- reserved for setable quit character.
 **             -m -- map the system identified type to some user
 **                     specified type. The mapping can be baud rate
 **             -qC -- reserved for setable quit character.
 **             -m -- map the system identified type to some user
 **                     specified type. The mapping can be baud rate
@@ -166,7 +178,7 @@ static char sccsid[] = "@(#)tset.c  5.2 (Berkeley) %G%";
 **             PLUGBOARD -- the type code for a plugboard port.
 **             ARPANET -- the type code for an arpanet port.
 **             BACKSPACE -- control-H, the default for -e.
 **             PLUGBOARD -- the type code for a plugboard port.
 **             ARPANET -- the type code for an arpanet port.
 **             BACKSPACE -- control-H, the default for -e.
-**             CTRL('X') -- control-X, the default for -k.
+**             CNTL('X') -- control-X, the default for -k.
 **             OLDERASE -- the system default erase character.
 **             OLDKILL -- the system default kill character.
 **             FILEDES -- the file descriptor to do the operation
 **             OLDERASE -- the system default erase character.
 **             OLDKILL -- the system default kill character.
 **             FILEDES -- the file descriptor to do the operation
@@ -265,18 +277,24 @@ static char sccsid[] = "@(#)tset.c        5.2 (Berkeley) %G%";
 **             10/77 -- Written.
 */
 
 **             10/77 -- Written.
 */
 
+#define UCB_NTTY
+
 # ifdef USG
 #  define index strchr
 #  define rindex strrchr
 #  define curerase mode.c_cc[VERASE]
 #  define curkill mode.c_cc[VKILL]
 # ifdef USG
 #  define index strchr
 #  define rindex strrchr
 #  define curerase mode.c_cc[VERASE]
 #  define curkill mode.c_cc[VKILL]
+#  define curintr mode.c_cc[VINTR]
 #  define olderase oldmode.c_cc[VERASE]
 #  define oldkill oldmode.c_cc[VKILL]
 #  define olderase oldmode.c_cc[VERASE]
 #  define oldkill oldmode.c_cc[VKILL]
+#  define oldintr oldmode.c_cc[VINTR]
 # else
 #  define curerase mode.sg_erase
 #  define curkill mode.sg_kill
 # else
 #  define curerase mode.sg_erase
 #  define curkill mode.sg_kill
+#  define curintr tchar.t_intrc
 #  define olderase oldmode.sg_erase
 #  define oldkill oldmode.sg_kill
 #  define olderase oldmode.sg_erase
 #  define oldkill oldmode.sg_kill
+#  define oldintr oldtchar.t_intrc
 # endif
 
 # ifndef V6
 # endif
 
 # ifndef V6
@@ -298,14 +316,40 @@ static char sccsid[] = "@(#)tset.c        5.2 (Berkeley) %G%";
 
 # define       YES             1
 # define       NO              0
 
 # define       YES             1
 # define       NO              0
-#undef CTRL
-# define       CTRL(x)         (x ^ 0100)
-# define       BACKSPACE       (CTRL('H'))
+#undef CNTL
+# define       CNTL(c)         ((c)&037)
+# define       BACKSPACE       (CNTL('H'))
 # define       CHK(val, dft)   (val<=0 ? dft : val)
 # define       isdigit(c)      (c >= '0' && c <= '9')
 # define       CHK(val, dft)   (val<=0 ? dft : val)
 # define       isdigit(c)      (c >= '0' && c <= '9')
-# define       isalnum(c)      (c > ' ' && !(index("<@=>!:|\177", c)) )
+# define       isalnum(c)      (c > ' ' && (index("<@=>!:|\177", c) == NULL))
 # define       OLDERASE        '#'
 # define       OLDKILL         '@'
 # define       OLDERASE        '#'
 # define       OLDKILL         '@'
+# define       OLDINTR         '\177'  /* del */
+
+/* default special characters */
+#ifndef CERASE
+#define        CERASE  '\177'
+#endif
+#ifndef CKILL
+#define        CKILL   CNTL('U')
+#endif
+#ifndef CINTR
+#define        CINTR   CNTL('C')
+#endif
+#ifndef CDSUSP
+#define        CQUIT   034             /* FS, ^\ */
+#define        CSTART  CNTL('Q')
+#define        CSTOP   CNTL('S')
+#define        CEOF    CNTL('D')
+#define        CEOT    CEOF
+#define        CBRK    0377
+#define        CSUSP   CNTL('Z')
+#define        CDSUSP  CNTL('Y')
+#define        CRPRNT  CNTL('R')
+#define        CFLUSH  CNTL('O')
+#define        CWERASE CNTL('W')
+#define        CLNEXT  CNTL('V')
+#endif
 
 # define       FILEDES         2       /* do gtty/stty on this descriptor */
 # define       STDOUT          1       /* output of -s/-S to this descriptor */
 
 # define       FILEDES         2       /* do gtty/stty on this descriptor */
 # define       STDOUT          1       /* output of -s/-S to this descriptor */
@@ -317,9 +361,9 @@ static char sccsid[] = "@(#)tset.c  5.2 (Berkeley) %G%";
 # endif
 
 # ifdef UCB_NTTY
 # endif
 
 # ifdef UCB_NTTY
-# define       USAGE   "usage: tset [-] [-nrsIQS] [-eC] [-kC] [-m [ident][test speed]:type] [type]\n"
+# define       USAGE   "usage: tset [-] [-nrsIQS] [-eC] [-kC] [-iC] [-m [ident][test speed]:type] [type]\n"
 # else
 # else
-# define       USAGE   "usage: tset [-] [-rsIQS] [-eC] [-kC] [-m [ident][test speed]:type] [type]\n"
+# define       USAGE   "usage: tset [-] [-rsIQS] [-eC] [-kC] [-iC] [-m [ident][test speed]:type] [type]\n"
 # endif
 
 # define       OLDFLAGS
 # endif
 
 # define       OLDFLAGS
@@ -388,6 +432,7 @@ struct
        "2400", B2400,  2400,
        "4800", B4800,  4800,
        "9600", B9600,  9600,
        "2400", B2400,  2400,
        "4800", B4800,  4800,
        "9600", B9600,  9600,
+       "19200",EXTA,   19200,
        "exta", EXTA,   19200,
        "extb", EXTB,   38400,
        0,
        "exta", EXTA,   19200,
        "extb", EXTB,   38400,
        0,
@@ -421,10 +466,12 @@ struct vterm {
 };
 
 int VirTermNo = -2;
 };
 
 int VirTermNo = -2;
+int    HasAM;                  /* True if terminal has automatic margins */
 # endif CBVIRTTERM
 
 char   Erase_char;             /* new erase character */
 char   Kill_char;              /* new kill character */
 # endif CBVIRTTERM
 
 char   Erase_char;             /* new erase character */
 char   Kill_char;              /* new kill character */
+char   Intr_char;              /* new interrupt character */
 char   Specialerase;           /* set => Erase_char only on terminals with backspace */
 
 # ifdef        GTTYN
 char   Specialerase;           /* set => Erase_char only on terminals with backspace */
 
 # ifdef        GTTYN
@@ -448,8 +495,6 @@ int RepOnly;                /* report only */
 int    CmndLine;               /* output full command lines (-s option) */
 int    Ask;                    /* ask user for termtype */
 int    DoVirtTerm = YES;       /* Set up a virtual terminal */
 int    CmndLine;               /* output full command lines (-s option) */
 int    Ask;                    /* ask user for termtype */
 int    DoVirtTerm = YES;       /* Set up a virtual terminal */
-int    New = NO;               /* use new tty discipline */
-int    HasAM;                  /* True if terminal has automatic margins */
 int    PadBaud;                /* Min rate of padding needed */
 int    lines, columns;
 
 int    PadBaud;                /* Min rate of padding needed */
 int    lines, columns;
 
@@ -460,6 +505,11 @@ char       *Ttycap;                /* termcap line from termcap or environ */
 char   Aliasbuf[128];
 char   *Alias[16];
 
 char   Aliasbuf[128];
 char   *Alias[16];
 
+extern char *strcpy();
+extern char *index();
+extern char *tgetstr();
+extern int prc();
+
 struct delay
 {
        int     d_delay;
 struct delay
 {
        int     d_delay;
@@ -471,6 +521,8 @@ struct delay
 # ifndef USG
 struct sgttyb  mode;
 struct sgttyb  oldmode;
 # ifndef USG
 struct sgttyb  mode;
 struct sgttyb  oldmode;
+struct tchars  tchar;
+struct tchars  oldtchar;
 # else
 struct termio  mode;
 struct termio  oldmode;
 # else
 struct termio  mode;
 struct termio  oldmode;
@@ -490,7 +542,9 @@ char        *argv[];
        register char   *p;
        char            *command;
        register int    i;
        register char   *p;
        char            *command;
        register int    i;
+# ifdef CBVIRTTERM
        int             j;
        int             j;
+# endif CBVIRTTERM
        int             Break;
        int             Not;
        char            *nextarg();
        int             Break;
        int             Not;
        char            *nextarg();
@@ -505,13 +559,11 @@ char      *argv[];
 # ifdef GTTYN
        char            *stypeof();
        extern char     *ttyname();
 # ifdef GTTYN
        char            *stypeof();
        extern char     *ttyname();
-       extern char     *tgetstr();
 # endif
        char            bs_char;
        int             csh;
        int             settle;
        int             setmode();
 # endif
        char            bs_char;
        int             csh;
        int             settle;
        int             setmode();
-       extern          prc();
        extern char     PC;
 # ifdef        V6
        extern int      ospeed;
        extern char     PC;
 # ifdef        V6
        extern int      ospeed;
@@ -522,28 +574,32 @@ char      *argv[];
        int             lmode;
        int             ldisc;
 
        int             lmode;
        int             ldisc;
 
-       ioctl(FILEDES, TIOCLGET, &lmode);
-       ioctl(FILEDES, TIOCGETD, &ldisc);
+       (void) ioctl(FILEDES, TIOCLGET, (char *)&lmode);
+       (void) ioctl(FILEDES, TIOCGETD, (char *)&ldisc);
 # endif
 
 # ifndef USG
        if (gtty(FILEDES, &mode) < 0)
 # else
 # endif
 
 # ifndef USG
        if (gtty(FILEDES, &mode) < 0)
 # else
-       if (ioctl(FILEDES, TCGETA, &mode) < 0)
+       if (ioctl(FILEDES, TCGETA, (char *)&mode) < 0)
 # endif
        {
                prs("Not a terminal\n");
                exit(1);
        }
 # endif
        {
                prs("Not a terminal\n");
                exit(1);
        }
-       bmove(&mode, &oldmode, sizeof mode);
+       bmove((char *)&mode, (char *)&oldmode, sizeof mode);
+# ifdef TIOCGETC
+       (void) ioctl(FILEDES, TIOCGETC, (char *)&tchar);
+       bmove((char *)&tchar, (char *)&oldtchar, sizeof tchar);
+# endif
 # ifndef USG
        ospeed = mode.sg_ospeed & 017;
 # else
        ospeed = mode.c_cflag & CBAUD;
 # endif
 # ifndef USG
        ospeed = mode.sg_ospeed & 017;
 # else
        ospeed = mode.c_cflag & CBAUD;
 # endif
-       signal(SIGINT, setmode);
-       signal(SIGQUIT, setmode);
-       signal(SIGTERM, setmode);
+       (void) signal(SIGINT, setmode);
+       (void) signal(SIGQUIT, setmode);
+       (void) signal(SIGTERM, setmode);
 
        if (command = rindex(argv[0], '/'))
                command++;
 
        if (command = rindex(argv[0], '/'))
                command++;
@@ -557,34 +613,30 @@ char      *argv[];
         * Very useful after crapping out in raw.
         */
 # ifndef V6
         * Very useful after crapping out in raw.
         */
 # ifndef V6
-#  ifdef TIOCGETC
-               struct tchars tbuf;
-#  endif TIOCGETC
 #  ifdef UCB_NTTY
                struct ltchars ltc;
 
                if (ldisc == NTTYDISC)
                {
 #  ifdef UCB_NTTY
                struct ltchars ltc;
 
                if (ldisc == NTTYDISC)
                {
-                       ioctl(FILEDES, TIOCGLTC, &ltc);
-                       ltc.t_suspc = CHK(ltc.t_suspc, CTRL('Z'));
-                       ltc.t_dsuspc = CHK(ltc.t_dsuspc, CTRL('Y'));
-                       ltc.t_rprntc = CHK(ltc.t_rprntc, CTRL('R'));
-                       ltc.t_flushc = CHK(ltc.t_flushc, CTRL('O'));
-                       ltc.t_werasc = CHK(ltc.t_werasc, CTRL('W'));
-                       ltc.t_lnextc = CHK(ltc.t_lnextc, CTRL('V'));
-                       ioctl(FILEDES, TIOCSLTC, &ltc);
+                       (void) ioctl(FILEDES, TIOCGLTC, (char *)&ltc);
+                       ltc.t_suspc = CHK(ltc.t_suspc, CSUSP);
+                       ltc.t_dsuspc = CHK(ltc.t_dsuspc, CDSUSP);
+                       ltc.t_rprntc = CHK(ltc.t_rprntc, CRPRNT);
+                       ltc.t_flushc = CHK(ltc.t_flushc, CFLUSH);
+                       ltc.t_werasc = CHK(ltc.t_werasc, CWERASE);
+                       ltc.t_lnextc = CHK(ltc.t_lnextc, CLNEXT);
+                       (void) ioctl(FILEDES, TIOCSLTC, (char *)&ltc);
                }
 #  endif UCB_NTTY
 #  ifndef USG
 #   ifdef TIOCGETC
                }
 #  endif UCB_NTTY
 #  ifndef USG
 #   ifdef TIOCGETC
-               ioctl(FILEDES, TIOCGETC, &tbuf);
-               tbuf.t_intrc = CHK(tbuf.t_intrc, CTRL('?'));
-               tbuf.t_quitc = CHK(tbuf.t_quitc, CTRL('\\'));
-               tbuf.t_startc = CHK(tbuf.t_startc, CTRL('Q'));
-               tbuf.t_stopc = CHK(tbuf.t_stopc, CTRL('S'));
-               tbuf.t_eofc = CHK(tbuf.t_eofc, CTRL('D'));
+               tchar.t_intrc = CHK(tchar.t_intrc, CINTR);
+               tchar.t_quitc = CHK(tchar.t_quitc, CQUIT);
+               tchar.t_startc = CHK(tchar.t_startc, CSTART);
+               tchar.t_stopc = CHK(tchar.t_stopc, CSTOP);
+               tchar.t_eofc = CHK(tchar.t_eofc, CEOF);
                /* brkc is left alone */
                /* brkc is left alone */
-               ioctl(FILEDES, TIOCSETC, &tbuf);
+               (void) ioctl(FILEDES, TIOCSETC, (char *)&tchar);
 #   endif TIOCGETC
                mode.sg_flags &= ~(RAW
 #   ifdef CBREAK
 #   endif TIOCGETC
                mode.sg_flags &= ~(RAW
 #   ifdef CBREAK
@@ -592,15 +644,16 @@ char      *argv[];
 #   endif CBREAK
                                                |VTDELAY|ALLDELAY);
                mode.sg_flags |= XTABS|ECHO|CRMOD|ANYP;
 #   endif CBREAK
                                                |VTDELAY|ALLDELAY);
                mode.sg_flags |= XTABS|ECHO|CRMOD|ANYP;
-               curerase = CHK(curerase, OLDERASE);
-               curkill = CHK(curkill, OLDKILL);
+               curerase = CHK(curerase, CERASE);
+               curkill = CHK(curkill, CKILL);
+               curintr = CHK(curintr, CINTR);
 #  else USG
 #  else USG
-               ioctl(FILEDES, TCGETA, &mode);
+               (void) ioctl(FILEDES, TCGETA, (char *)&mode);
                curerase = CHK(curerase, OLDERASE);
                curkill = CHK(curkill, OLDKILL);
                curerase = CHK(curerase, OLDERASE);
                curkill = CHK(curkill, OLDKILL);
-               mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CTRL('?'));
-               mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CTRL('\\'));
-               mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CTRL('D'));
+               curintr = CHK(curintr, OLDINTR);
+               mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT);
+               mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF);
 
                mode.c_iflag |= (BRKINT|ISTRIP|ICRNL|IXON);
                mode.c_iflag &= ~(IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF);
 
                mode.c_iflag |= (BRKINT|ISTRIP|ICRNL|IXON);
                mode.c_iflag &= ~(IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF);
@@ -611,7 +664,7 @@ char        *argv[];
                mode.c_cflag &= ~(CSIZE|PARODD|CLOCAL);
                mode.c_lflag |= (ISIG|ICANON|ECHO|ECHOK);
                mode.c_lflag &= ~(XCASE|ECHONL|NOFLSH);
                mode.c_cflag &= ~(CSIZE|PARODD|CLOCAL);
                mode.c_lflag |= (ISIG|ICANON|ECHO|ECHOK);
                mode.c_lflag &= ~(XCASE|ECHONL|NOFLSH);
-               ioctl(FILEDES, TCSETAW, &mode);
+               (void) ioctl(FILEDES, TCSETAW, (char *)&mode);
 #  endif USG
 # endif V6
                Dash_u = YES;
 #  endif USG
 # endif V6
                Dash_u = YES;
@@ -639,7 +692,7 @@ char        *argv[];
 # ifdef UCB_NTTY
                          case 'n':
                                ldisc = NTTYDISC;
 # ifdef UCB_NTTY
                          case 'n':
                                ldisc = NTTYDISC;
-                               if (ioctl(FILEDES, TIOCSETD, &ldisc)<0)
+                               if (ioctl(FILEDES, TIOCSETD, (char *)&ldisc)<0)
                                        fatal("ioctl ", "new");
                                continue;
 # endif
                                        fatal("ioctl ", "new");
                                continue;
 # endif
@@ -658,20 +711,44 @@ char      *argv[];
                                else
                                {
                                        if (*p == '^' && p[1] != NULL)
                                else
                                {
                                        if (*p == '^' && p[1] != NULL)
-                                               Erase_char = CTRL(*++p);
+                                               if (*++p == '?')
+                                                       Erase_char = '\177';
+                                               else
+                                                       Erase_char = CNTL(*p);
                                        else
                                                Erase_char = *p;
                                        p++;
                                }
                                continue;
 
                                        else
                                                Erase_char = *p;
                                        p++;
                                }
                                continue;
 
+# if defined(USG) || defined(TIOCGETC)
+                         case 'i':     /* interrupt character */
+                               if (*p == NULL)
+                                       Intr_char = CNTL('C');
+                               else
+                               {
+                                       if (*p == '^' && p[1] != NULL)
+                                               if (*++p == '?')
+                                                       Intr_char = '\177';
+                                               else
+                                                       Intr_char = CNTL(*p);
+                                       else
+                                               Intr_char = *p;
+                                       p++;
+                               }
+                               continue;
+# endif
+
                          case 'k':     /* kill character */
                                if (*p == NULL)
                          case 'k':     /* kill character */
                                if (*p == NULL)
-                                       Kill_char = CTRL('X');
+                                       Kill_char = CNTL('X');
                                else
                                {
                                        if (*p == '^' && p[1] != NULL)
                                else
                                {
                                        if (*p == '^' && p[1] != NULL)
-                                               Kill_char = CTRL(*++p);
+                                               if (*++p == '?')
+                                                       Kill_char = '\177';
+                                               else
+                                                       Kill_char = CNTL(*p);
                                        else
                                                Kill_char = *p;
                                        p++;
                                        else
                                                Kill_char = *p;
                                        p++;
@@ -856,7 +933,7 @@ mapold:                             Map->Ident = NewType;
         */
        bufp = getenv("TERMCAP");
        if (bufp && *bufp != '/')
         */
        bufp = getenv("TERMCAP");
        if (bufp && *bufp != '/')
-               strcpy(bufp-8, "NOTHING");      /* overwrite only "TERMCAP" */
+               (void) strcpy(bufp-8, "NOTHING"); /* overwrite only "TERMCAP" */
        /* get current idea of terminal type from environment */
        if (!Dash_h && TtyType == 0)
                TtyType = getenv("TERM");
        /* get current idea of terminal type from environment */
        if (!Dash_h && TtyType == 0)
                TtyType = getenv("TERM");
@@ -991,12 +1068,17 @@ ask:
                        Erase_char = (bs_char != 0) ? bs_char : BACKSPACE;
 
                if (curerase == 0)
                        Erase_char = (bs_char != 0) ? bs_char : BACKSPACE;
 
                if (curerase == 0)
-                       curerase = OLDERASE;
+                       curerase = CERASE;
                if (Erase_char != 0)
                        curerase = Erase_char;
 
                if (Erase_char != 0)
                        curerase = Erase_char;
 
+               if (curintr == 0)
+                       curintr = CINTR;
+               if (Intr_char != 0)
+                       curintr = Intr_char;
+
                if (curkill == 0)
                if (curkill == 0)
-                       curkill = OLDKILL;
+                       curkill = CKILL;
                if (Kill_char != 0)
                        curkill = Kill_char;
 
                if (Kill_char != 0)
                        curkill = Kill_char;
 
@@ -1099,7 +1181,9 @@ ask:
                                }
                        }
                }
                                }
                        }
                }
-               ioctl(FILEDES, TIOCLSET, &lmode);
+               if (IsReset)
+                       lmode &= ~(LMDMBUF|LLITOUT|LPASS8);
+               (void) ioctl(FILEDES, TIOCLSET, (char *)&lmode);
 # endif
 
                /* get pad character */
 # endif
 
                /* get pad character */
@@ -1111,13 +1195,12 @@ ask:
                lines = tgetnum("li");
 
                /* Set window size */
                lines = tgetnum("li");
 
                /* Set window size */
-               if (DoSetenv) {
-                       ioctl(FILEDES, TIOCGWINSZ, &win);
-                       if (win.ws_row == 0 && win.ws_col == 0) {
-                               win.ws_row = lines;
-                               win.ws_col = columns;
-                               ioctl(FILEDES, TIOCSWINSZ, &win);
-                       }
+               (void) ioctl(FILEDES, TIOCGWINSZ, (char *)&win);
+               if (win.ws_row == 0 && win.ws_col == 0 &&
+                   lines > 0 && columns > 0) {
+                       win.ws_row = lines;
+                       win.ws_col = columns;
+                       (void) ioctl(FILEDES, TIOCSWINSZ, (char *)&win);
                }
                /* output startup string */
                if (!NoInit)
                }
                /* output startup string */
                if (!NoInit)
@@ -1137,21 +1220,23 @@ ask:
 # endif
 # ifdef CBVIRTTERM
                        block.st_termt = 0;
 # endif
 # ifdef CBVIRTTERM
                        block.st_termt = 0;
-                       ioctl(FILEDES, LDSETT, &block);
+                       (void) ioctl(FILEDES, LDSETT, (char *)&block);
 # endif CBVIRTTERM
                        if (settabs()) {
                                settle = YES;
                                flush();
                        }
                        bufp = buf;
 # endif CBVIRTTERM
                        if (settabs()) {
                                settle = YES;
                                flush();
                        }
                        bufp = buf;
-                       if (tgetstr(IsReset? "rs" : "is", &bufp) != 0)
+                       if (IsReset && tgetstr("rs", &bufp) != 0 || 
+                           tgetstr("is", &bufp) != 0)
                        {
                                tputs(buf, 0, prc);
                                settle = YES;
                                flush();
                        }
                        bufp = buf;
                        {
                                tputs(buf, 0, prc);
                                settle = YES;
                                flush();
                        }
                        bufp = buf;
-                       if (tgetstr(IsReset? "rf" : "if", &bufp) != 0)
+                       if (IsReset && tgetstr("rf", &bufp) != 0 ||
+                           tgetstr("if", &bufp) != 0)
                        {
                                cat(buf);
                                settle = YES;
                        {
                                cat(buf);
                                settle = YES;
@@ -1188,13 +1273,13 @@ ask:
 
                        if ((sh = getenv("SHELL")) && (i = strlen(sh)) >= 3)
                        {
 
                        if ((sh = getenv("SHELL")) && (i = strlen(sh)) >= 3)
                        {
-                               if ((csh = sequal(&sh[i-3], "csh")) && CmndLine)
-                                       write(STDOUT, "set noglob;\n", 12);
+                           if ((csh = sequal(&sh[i-3], "csh")) && CmndLine)
+                               (void) write(STDOUT, "set noglob;\n", 12);
                        }
                        if (!csh)
 # endif
                        }
                        if (!csh)
 # endif
-                               /* running Bourne shell */
-                               write(STDOUT, "export TERMCAP TERM;\n", 21);
+                           /* running Bourne shell */
+                           (void) write(STDOUT, "export TERMCAP TERM;\n", 21);
                }
        }
 
                }
        }
 
@@ -1212,23 +1297,23 @@ ask:
                        if (csh)
                        {
                                if (CmndLine)
                        if (csh)
                        {
                                if (CmndLine)
-                                       write(STDOUT, "setenv TERM ", 12);
-                               write(STDOUT, TtyType, strlen(TtyType));
-                               write(STDOUT, " ", 1);
+                                   (void) write(STDOUT, "setenv TERM ", 12);
+                               (void) write(STDOUT, TtyType, strlen(TtyType));
+                               (void) write(STDOUT, " ", 1);
                                if (CmndLine)
                                if (CmndLine)
-                                       write(STDOUT, ";\n", 2);
+                                   (void) write(STDOUT, ";\n", 2);
                        }
                        else
                        {
                        }
                        else
                        {
-                               write(STDOUT, "TERM=", 5);
-                               write(STDOUT, TtyType, strlen(TtyType));
-                               write(STDOUT, ";\n", 2);
+                               (void) write(STDOUT, "TERM=", 5);
+                               (void) write(STDOUT, TtyType, strlen(TtyType));
+                               (void) write(STDOUT, ";\n", 2);
                        }
                }
                else if (Report)
                {
                        }
                }
                else if (Report)
                {
-                       write(STDOUT, TtyType, strlen(TtyType));
-                       write(STDOUT, "\n", 1);
+                       (void) write(STDOUT, TtyType, strlen(TtyType));
+                       (void) write(STDOUT, "\n", 1);
                }
                if (Ureport)
                {
                }
                if (Ureport)
                {
@@ -1242,31 +1327,32 @@ ask:
                {
                        if (csh)
                        {
                {
                        if (csh)
                        {
-                               if (CmndLine)
-                                       write(STDOUT, "setenv TERMCAP '", 16);
+                           if (CmndLine)
+                               (void) write(STDOUT, "setenv TERMCAP '", 16);
                        }
                        else
                        }
                        else
-                               write(STDOUT, "TERMCAP='", 9);
+                           (void) write(STDOUT, "TERMCAP='", 9);
                        wrtermcap(Ttycap);
                        if (csh)
                        {
                                if (CmndLine)
                                {
                        wrtermcap(Ttycap);
                        if (csh)
                        {
                                if (CmndLine)
                                {
-                                       write(STDOUT, "';\n", 3);
-                                       write(STDOUT, "unset noglob;\n", 14);
+                                   (void) write(STDOUT, "';\n", 3);
+                                   (void) write(STDOUT, "unset noglob;\n", 14);
                                }
                        }
                        else
                                }
                        }
                        else
-                               write(STDOUT, "';\n", 3);
+                               (void) write(STDOUT, "';\n", 3);
                }
        }
 
        if (RepOnly)
                exit(0);
 
                }
        }
 
        if (RepOnly)
                exit(0);
 
-       /* tell about changing erase and kill characters */
+       /* tell about changing erase, kill and interrupt characters */
        reportek("Erase", curerase, olderase, OLDERASE);
        reportek("Kill", curkill, oldkill, OLDKILL);
        reportek("Erase", curerase, olderase, OLDERASE);
        reportek("Kill", curkill, oldkill, OLDKILL);
+       reportek("Interrupt", curintr, oldintr, OLDINTR);
 
 # ifdef V6
        /* update htmp */
 
 # ifdef V6
        /* update htmp */
@@ -1353,36 +1439,55 @@ int     flag;
 # else
        struct termio *ttymode;
 # endif
 # else
        struct termio *ttymode;
 # endif
+# ifdef TIOCGETC
+       struct tchars *ttytchars;
+# endif
 
 
-       if (flag < 0)   /* unconditionally reset oldmode (called from init) */
+       if (flag < 0) { /* unconditionally reset oldmode (called from init) */
                ttymode = &oldmode;
                ttymode = &oldmode;
-       else if (!bequal(&mode, &oldmode, sizeof mode))
+# ifdef TIOCGETC
+               ttytchars = &oldtchar;
+# endif
+       } else if (!bequal((char *)&mode, (char *)&oldmode, sizeof mode)) {
                ttymode = &mode;
                ttymode = &mode;
-       else            /* don't need it */
+# ifdef TIOCGETC
+               ttytchars = &tchar;
+# endif
+       } else  {       /* don't need it */
 # ifndef USG
        ttymode = (struct sgttyb *)0;
 # else
        ttymode = (struct termio *)0;
 # endif
 # ifndef USG
        ttymode = (struct sgttyb *)0;
 # else
        ttymode = (struct termio *)0;
 # endif
+# ifdef TIOCGETC
+       ttytchars = (struct tchars *)0;
+# endif
+       }
        
        if (ttymode)
        {
 # ifdef USG
        
        if (ttymode)
        {
 # ifdef USG
-               ioctl(FILEDES, TCSETAW, ttymode);
+               (void) ioctl(FILEDES, TCSETAW, (char *)ttymode);
 # else
 #  ifndef V6
 # else
 #  ifndef V6
-               ioctl(FILEDES, TIOCSETN, ttymode);     /* don't flush */
+               /* don't flush */
+               (void) ioctl(FILEDES, TIOCSETN, (char *)ttymode);
 #  else
                stty(FILEDES, ttymode);
 #  endif
 # endif
        }
 #  else
                stty(FILEDES, ttymode);
 #  endif
 # endif
        }
+# ifdef TIOCGETC
+       if (ttytchars) {
+               (void) ioctl(FILEDES, TIOCSETC, (char *)ttytchars);
+       }
+# endif
 # ifdef CBVIRTTERM
        if (VirTermNo != -2) {
                int r1, r2;
                extern int errno;
 
 # ifdef CBVIRTTERM
        if (VirTermNo != -2) {
                int r1, r2;
                extern int errno;
 
-               r1 = ioctl(FILEDES, LDGETT, &block);
+               r1 = ioctl(FILEDES, LDGETT, (char *)&block);
                block.st_flgs |= TM_SET;
                block.st_termt = VirTermNo;
                if (block.st_termt < 0)
                block.st_flgs |= TM_SET;
                block.st_termt = VirTermNo;
                if (block.st_termt < 0)
@@ -1391,7 +1496,7 @@ int       flag;
                        block.st_flgs |= TM_ANL;
                else
                        block.st_flgs &= ~TM_ANL;
                        block.st_flgs |= TM_ANL;
                else
                        block.st_flgs &= ~TM_ANL;
-               r2 = ioctl(FILEDES, LDSETT, &block);
+               r2 = ioctl(FILEDES, LDSETT, (char *)&block);
        }
 # endif
 
        }
 # endif
 
@@ -1507,7 +1612,7 @@ char      c;
 flush()
 {
        if (OutPtr > 0)
 flush()
 {
        if (OutPtr > 0)
-               write(2, OutBuf, OutPtr);
+               (void) write(2, OutBuf, OutPtr);
        OutPtr = 0;
 }
 
        OutPtr = 0;
 }
 
@@ -1530,9 +1635,9 @@ char      *file;
        }
 
        while ((i = read(fd, buf, BUFSIZ)) > 0)
        }
 
        while ((i = read(fd, buf, BUFSIZ)) > 0)
-               write(FILEDES, buf, i);
+               (void) write(FILEDES, buf, i);
 
 
-       close(fd);
+       (void) close(fd);
 }
 
 
 }
 
 
@@ -1633,7 +1738,6 @@ stypeof(ttyid)
 char   *ttyid;
 {
        register char   *PortType;
 char   *ttyid;
 {
        register char   *PortType;
-       register char   *PortName;
        register char   *TtyId;
        struct ttyent *t;
 
        register char   *TtyId;
        struct ttyent *t;
 
@@ -1673,11 +1777,13 @@ wrtermcap(bp)
 char *bp;
 {
        char buf[CAPBUFSIZ];
 char *bp;
 {
        char buf[CAPBUFSIZ];
-       register int i;
        char *p = buf;
        char *tp;
        char *putbuf();
        int space, empty;
        char *p = buf;
        char *tp;
        char *putbuf();
        int space, empty;
+# ifdef CBVIRTTERM
+       register int i;
+# endif CBVIRTTERM
 
        /* discard names with blanks */
 /** May not be desireable ? **/
 
        /* discard names with blanks */
 /** May not be desireable ? **/
@@ -1797,10 +1903,12 @@ char *bp;
 # endif CBVIRTTERM
                }
                *p++ = *bp++;
 # endif CBVIRTTERM
                }
                *p++ = *bp++;
+# ifdef CBVIRTTERM
 contin:                ;
 contin:                ;
+# endif CBVIRTTERM
        }
        *p++ = ':';     /* we skipped the last : with the : lookahead hack */
        }
        *p++ = ':';     /* we skipped the last : with the : lookahead hack */
-       write (STDOUT, buf, p-buf);
+       (void) write (STDOUT, buf, p-buf);
 }
 
 cancelled(cap)
 }
 
 cancelled(cap)
@@ -1835,7 +1943,7 @@ char      *str;
                        break;
                default:
                        if (*str <= ' ') {
                        break;
                default:
                        if (*str <= ' ') {
-                               sprintf(buf, "\\%03o", *str);
+                               (void) sprintf(buf, "\\%03o", *str);
                                ptr = putbuf(ptr, buf);
                                str++;
                        } else
                                ptr = putbuf(ptr, buf);
                                str++;
                        } else