1 /****************************************************************************
2 * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
35 * tset.c - terminal initialization utility
37 * This code was mostly swiped from 4.4BSD tset, with some obsolescent
38 * cruft removed and substantial portions rewritten. A Regents of the
39 * University of California copyright applies to some portions of the
40 * code, and is reproduced below:
43 * Copyright (c) 1980, 1991, 1993
44 * The Regents of the University of California. All rights reserved.
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75 #define __INTERNAL_CAPS_VISIBLE /* we need to see has_hardware_tabs */
76 #include <progs.priv.h>
83 #if HAVE_GETTTYNAM && HAVE_TTYENT_H
87 char *ttyname(int fd);
90 /* this is just to stifle a missing-prototype warning */
92 # include <sys/ioctl.h>
96 /* they neglected to define struct winsize in termios.h -- it's only
98 #include <sys/stream.h>
102 #include <curses.h> /* for bool typedef */
103 #include <dump_entry.h>
105 MODULE_ID("$Id: tset.c,v 0.41 2000/03/12 00:03:00 tom Exp $")
107 extern char **environ;
110 #define CTRL(x) ((x) & 0x1f)
112 const char *_nc_progname = "tset";
114 static TTY mode, oldmode;
116 static int terasechar = -1; /* new erase character */
117 static int intrchar = -1; /* new interrupt character */
118 static int isreset; /* invoked as reset */
119 static int tkillchar = -1; /* new kill character */
120 static int tlines, tcolumns; /* window size */
122 #define LOWERCASE(c) ((isalpha(c) && isupper(c)) ? tolower(c) : (c))
125 CaselessCmp(const char *a, const char *b)
126 { /* strcasecmp isn't portable */
128 int cmp = LOWERCASE(*a) - LOWERCASE(*b);
133 return LOWERCASE(*a) - LOWERCASE(*b);
137 err(const char *fmt,...)
141 (void) fprintf(stderr, "tset: ");
142 (void) vfprintf(stderr, fmt, ap);
144 (void) fprintf(stderr, "\n");
150 failed(const char *msg)
153 perror(strncat(strcpy(temp, "tset: "), msg, sizeof(temp) - 10));
161 register int fd, nr, nw;
164 if ((fd = open(file, O_RDONLY, 0)) < 0)
167 while ((nr = read(fd, buf, sizeof(buf))) > 0)
168 if ((nw = write(STDERR_FILENO, buf, (size_t) nr)) == -1)
169 failed("write to stderr");
178 return putc(c, stderr);
181 /* Prompt the user for a terminal type. */
183 askuser(const char *dflt)
185 static char answer[256];
188 /* We can get recalled; if so, don't continue uselessly. */
189 if (feof(stdin) || ferror(stdin)) {
190 (void) fprintf(stderr, "\n");
195 (void) fprintf(stderr, "Terminal type? [%s] ", dflt);
197 (void) fprintf(stderr, "Terminal type? ");
198 (void) fflush(stderr);
200 if (fgets(answer, sizeof(answer), stdin) == 0) {
202 (void) fprintf(stderr, "\n");
208 if ((p = strchr(answer, '\n')) != 0)
217 /**************************************************************************
219 * Mapping logic begins here
221 **************************************************************************/
223 /* Baud rate conditionals for mapping. */
232 struct map *next; /* Linked list of maps. */
233 const char *porttype; /* Port type, or "" for any. */
234 const char *type; /* Terminal type to select. */
235 int conditional; /* Baud rate conditionals bitmask. */
236 speed_t speed; /* Baud rate to compare against. */
239 static MAP *cur, *maplist;
241 typedef struct speeds {
246 static const SPEEDS speeds[] =
297 tbaudrate(char *rate)
302 /* The baudrate number can be preceded by a 'B', which is ignored. */
306 for (sp = speeds; sp->string; ++sp) {
307 if (!CaselessCmp(rate, sp->string)) {
313 err("unknown baud rate %s", rate);
319 * [port-type][test baudrate]:terminal-type
320 * The baud rate tests are: >, <, @, =, !
323 add_mapping(const char *port, char *arg)
331 mapp = malloc(sizeof(MAP));
332 if (copy == 0 || mapp == 0)
336 cur = maplist = mapp;
342 mapp->porttype = arg;
343 mapp->conditional = 0;
345 arg = strpbrk(arg, "><@=!:");
347 if (arg == 0) { /* [?]term */
348 mapp->type = mapp->porttype;
353 if (arg == mapp->porttype) /* [><@=! baud]:term */
354 termp = mapp->porttype = 0;
358 for (;; ++arg) { /* Optional conditionals. */
361 if (mapp->conditional & GT)
363 mapp->conditional |= LT;
366 if (mapp->conditional & LT)
368 mapp->conditional |= GT;
371 case '=': /* Not documented. */
372 mapp->conditional |= EQ;
375 mapp->conditional |= NOT;
384 if (mapp->conditional)
387 } else { /* Optional baudrate. */
388 arg = strchr(p = arg, ':');
392 mapp->speed = tbaudrate(p);
395 if (arg == (char *) 0) /* Non-optional type. */
400 /* Terminate porttype, if specified. */
404 /* If a NOT conditional, reverse the test. */
405 if (mapp->conditional & NOT)
406 mapp->conditional = ~mapp->conditional & (EQ | GT | LT);
408 /* If user specified a port with an option flag, set it. */
411 badmopt:err("illegal -m option format: %s", copy);
412 mapp->porttype = port;
415 (void) printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY");
416 (void) printf("type: %s\n", mapp->type);
417 (void) printf("conditional: ");
419 if (mapp->conditional & GT) {
423 if (mapp->conditional & EQ) {
424 (void) printf("%sEQ", p);
427 if (mapp->conditional & LT)
428 (void) printf("%sLT", p);
429 (void) printf("\nspeed: %d\n", mapp->speed);
434 * Return the type of terminal to use for a port of type 'type', as specified
435 * by the first applicable mapping in 'map'. If no mappings apply, return
439 mapped(const char *type)
444 for (mapp = maplist; mapp; mapp = mapp->next)
445 if (mapp->porttype == 0 || !strcmp(mapp->porttype, type)) {
446 switch (mapp->conditional) {
447 case 0: /* No test specified. */
451 match = (ospeed == mapp->speed);
454 match = (ospeed >= mapp->speed);
457 match = (ospeed > mapp->speed);
460 match = (ospeed <= mapp->speed);
463 match = (ospeed < mapp->speed);
471 /* No match found; return given type. */
475 /**************************************************************************
479 **************************************************************************/
482 * Figure out what kind of terminal we're dealing with, and then read in
486 get_termcap_entry(char *userarg)
503 /* Try the environment. */
504 if ((ttype = getenv("TERM")) != 0)
507 if ((ttypath = ttyname(STDERR_FILENO)) != 0) {
508 if ((p = strrchr(ttypath, '/')) != 0)
514 * We have the 4.3BSD library call getttynam(3); that means
515 * there's an /etc/ttys to look up device-to-type mappings in.
516 * Try ttyname(3); check for dialup or other mapping.
518 if ((t = getttynam(p))) {
523 if ((fp = fopen("/etc/ttytype", "r")) != 0
524 || (fp = fopen("/etc/ttys", "r")) != 0) {
528 while (fgets(buffer, sizeof(buffer) - 1, fp) != 0) {
529 for (s = buffer, t = d = 0; *s; s++) {
534 else if (d == 0 && s != buffer && s[-1] == '\0')
537 if (t != 0 && d != 0 && !strcmp(d, p)) {
545 #endif /* HAVE_GETTTYNAM */
548 /* If still undefined, use "unknown". */
551 map:ttype = mapped(ttype);
554 * If not a path, remove TERMCAP from the environment so we get a
555 * real entry from /etc/termcap. This prevents us from being fooled
556 * by out of date stuff in the environment.
558 found:if ((p = getenv("TERMCAP")) != 0 && *p != '/') {
559 /* 'unsetenv("TERMCAP")' is not portable.
560 * The 'environ' array is better.
563 for (n = 0; environ[n] != 0; n++) {
564 if (!strncmp("TERMCAP=", environ[n], 8)) {
565 while ((environ[n] = environ[n + 1]) != 0) {
574 * ttype now contains a pointer to the type of the terminal.
575 * If the first character is '?', ask the user.
577 if (ttype[0] == '?') {
578 if (ttype[1] != '\0')
579 ttype = askuser(ttype + 1);
583 /* Find the terminfo entry. If it doesn't exist, ask the user. */
584 while ((rval = setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO,
587 (void) fprintf(stderr, "tset: unknown terminal type %s\n",
591 (void) fprintf(stderr,
592 "tset: can't initialize terminal type %s (error %d)\n",
596 ttype = askuser(ttype);
599 tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */
604 /**************************************************************************
608 **************************************************************************/
610 /* some BSD systems have these built in, some systems are missing
611 * one or more definitions. The safest solution is to override.
624 /* control-character defaults */
625 #define CEOF CTRL('D')
626 #define CERASE CTRL('H')
627 #define CINTR 127 /* ^? */
628 #define CKILL CTRL('U')
629 #define CLNEXT CTRL('v')
630 #define CRPRNT CTRL('r')
631 #define CQUIT CTRL('\\')
632 #define CSTART CTRL('Q')
633 #define CSTOP CTRL('S')
634 #define CSUSP CTRL('Z')
636 #define CHK(val, dft) ((int)val <= 0 ? dft : val)
638 static bool set_tabs(void);
641 * Reset the terminal mode bits to a sensible state. Very useful after
642 * a child program dies in raw mode.
648 tcgetattr(STDERR_FILENO, &mode);
650 stty(STDERR_FILENO, &mode);
654 #if defined(VDISCARD) && defined(CDISCARD)
655 mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD);
657 mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF);
658 mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE);
659 #if defined(VFLUSH) && defined(CFLUSH)
660 mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH);
662 mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR);
663 mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL);
664 #if defined(VLNEXT) && defined(CLNEXT)
665 mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT);
667 mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT);
668 #if defined(VREPRINT) && defined(CRPRNT)
669 mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT);
671 #if defined(VSTART) && defined(CSTART)
672 mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART);
674 #if defined(VSTOP) && defined(CSTOP)
675 mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP);
677 #if defined(VSUSP) && defined(CSUSP)
678 mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP);
680 #if defined(VWERASE) && defined(CWERASE)
681 mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE);
684 mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
693 mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON
719 | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY
723 mode.c_oflag |= (OPOST
729 mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL);
730 mode.c_cflag |= (CS8 | CREAD);
731 mode.c_lflag &= ~(ECHONL | NOFLSH
743 mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK
754 tcsetattr(STDERR_FILENO, TCSADRAIN, &mode);
756 stty(STDERR_FILENO, &mode);
761 * Returns a "good" value for the erase character. This is loosely based on
770 && key_backspace != 0
771 && strlen(key_backspace) == 1)
772 result = key_backspace[0];
780 * Update the values of the erase, interrupt, and kill characters in 'mode'.
782 * SVr4 tset (e.g., Solaris 2.5) only modifies the intr, quit or erase
783 * characters if they're unset, or if we specify them as options. This differs
784 * from BSD 4.4 tset, which always sets erase.
787 set_control_chars(void)
790 if (mode.c_cc[VERASE] == 0 || terasechar >= 0)
791 mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase();
793 if (mode.c_cc[VINTR] == 0 || intrchar >= 0)
794 mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR;
796 if (mode.c_cc[VKILL] == 0 || tkillchar >= 0)
797 mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL;
802 * Set up various conversions in 'mode', including parity, tabs, returns,
803 * echo, and case, according to the termcap entry. If the program we're
804 * running was named with a leading upper-case character, map external
805 * uppercase to internal lowercase.
808 set_conversions(void)
812 * Conversion logic for some *really* ancient terminal glitches,
813 * not supported in terminfo. Left here for succeeding generations
816 if (tgetflag("UC")) {
818 mode.c_iflag |= IUCLC;
819 mode.c_oflag |= OLCUC;
821 } else if (tgetflag("LC")) {
823 mode.c_iflag &= ~IUCLC;
824 mode.c_oflag &= ~OLCUC;
827 mode.c_iflag &= ~(PARMRK | INPCK);
828 mode.c_lflag |= ICANON;
829 if (tgetflag("EP")) {
830 mode.c_cflag |= PARENB;
831 mode.c_cflag &= ~PARODD;
833 if (tgetflag("OP")) {
834 mode.c_cflag |= PARENB;
835 mode.c_cflag |= PARODD;
837 #endif /* __OBSOLETE__ */
841 mode.c_oflag |= ONLCR;
843 mode.c_iflag |= ICRNL;
844 mode.c_lflag |= ECHO;
846 mode.c_oflag |= OXTABS;
849 /* test used to be tgetflag("NL") */
850 if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) {
851 /* Newline, not linefeed. */
853 mode.c_oflag &= ~ONLCR;
855 mode.c_iflag &= ~ICRNL;
858 if (tgetflag("HD")) /* Half duplex. */
859 mode.c_lflag &= ~ECHO;
860 #endif /* __OBSOLETE__ */
862 /* test used to be tgetflag("pt") */
863 if (has_hardware_tabs) /* Print tabs. */
864 mode.c_oflag &= ~OXTABS;
866 mode.c_lflag |= (ECHOE | ECHOK);
870 /* Output startup string. */
878 if (pad_char != (char *) 0) /* Get/set pad character. */
880 #endif /* OBSOLETE */
883 if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) {
884 oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET);
885 tcsetattr(STDERR_FILENO, TCSADRAIN, &oldmode);
891 if ((p = reset_1string) != 0) {
895 if ((p = reset_2string) != 0) {
899 /* What about rf, rs3, as per terminfo man page? */
900 /* also might be nice to send rmacs, rmul, rmm */
901 if ((p = reset_file) != 0
902 || (p = init_file) != 0) {
909 (void) putc('\r', stderr);
910 (void) fflush(stderr);
911 (void) napms(1000); /* Settle the terminal. */
916 * Set the hardware tabs on the terminal, using the ct (clear all tabs),
917 * st (set one tab) and ch (horizontal cursor addressing) capabilities.
918 * This is done before if and is, so they can patch in case we blow this.
919 * Return TRUE if we set any tab stops, FALSE if not.
924 if (set_tab && clear_all_tabs) {
927 (void) putc('\r', stderr); /* Force to left margin. */
928 tputs(clear_all_tabs, 0, outc);
930 for (c = 8; c < tcolumns; c += 8) {
931 /* Get to the right column. In BSD tset, this
932 * used to try a bunch of half-clever things
933 * with cup and hpa, for an average saving of
934 * somewhat less than two character times per
935 * tab stop, less that .01 sec at 2400cps. We
936 * lost all this cruft because it seemed to be
937 * introducing some odd bugs.
938 * ----------12345678----------- */
939 (void) fputs(" ", stderr);
940 tputs(set_tab, 0, outc);
948 /**************************************************************************
952 **************************************************************************/
955 * Tell the user if a control key has been changed from the default value.
958 report(const char *name, int which, unsigned def)
961 unsigned older, newer;
964 newer = mode.c_cc[which];
965 older = oldmode.c_cc[which];
967 if (older == newer && older == def)
970 (void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to");
973 * Check 'delete' before 'backspace', since the key_backspace value
977 (void) fprintf(stderr, "delete.\n");
978 else if ((p = key_backspace) != 0
979 && newer == (unsigned char) p[0]
981 (void) fprintf(stderr, "backspace.\n");
982 else if (newer < 040) {
984 (void) fprintf(stderr, "control-%c (^%c).\n", newer, newer);
986 (void) fprintf(stderr, "%c.\n", newer);
991 * Convert the obsolete argument forms into something that getopt can handle.
992 * This means that -e, -i and -k get default arguments supplied for them.
995 obsolete(char **argv)
997 for (; *argv; ++argv) {
998 char *parm = argv[0];
1000 if (parm[0] == '-' && parm[1] == '\0') {
1001 argv[0] = strdup("-q");
1005 if ((parm[0] != '-')
1006 || (argv[1] && argv[1][0] != '-')
1007 || (parm[1] != 'e' && parm[1] != 'i' && parm[1] != 'k')
1008 || (parm[2] != '\0'))
1010 switch (argv[0][1]) {
1012 argv[0] = strdup("-e^H");
1015 argv[0] = strdup("-i^C");
1018 argv[0] = strdup("-k^U");
1025 usage(const char *pname)
1027 (void) fprintf(stderr,
1028 "usage: %s [-IQrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]\n", pname);
1035 return (optarg[0] == '^' && optarg[1] != '\0')
1036 ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1]))
1041 main(int argc, char **argv)
1043 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1046 int ch, noinit, noset, quiet, Sflag, sflag, showterm;
1051 if (tcgetattr(STDERR_FILENO, &mode) < 0)
1052 failed("standard error");
1055 ospeed = cfgetospeed(&mode);
1057 if (gtty(STDERR_FILENO, &mode) < 0)
1058 failed("standard error");
1061 ospeed = mode.sg_ospeed;
1064 if ((p = strrchr(*argv, '/')) != 0)
1068 if (!CaselessCmp(p, "reset")) {
1074 noinit = noset = quiet = Sflag = sflag = showterm = 0;
1075 while ((ch = getopt(argc, argv, "a:d:e:Ii:k:m:np:qQSrs")) != EOF) {
1077 case 'q': /* display term only */
1080 case 'a': /* OBSOLETE: map identifier to type */
1081 add_mapping("arpanet", optarg);
1083 case 'd': /* OBSOLETE: map identifier to type */
1084 add_mapping("dialup", optarg);
1086 case 'e': /* erase character */
1087 terasechar = arg_to_char();
1089 case 'I': /* no initialization strings */
1092 case 'i': /* interrupt character */
1093 intrchar = arg_to_char();
1095 case 'k': /* kill character */
1096 tkillchar = arg_to_char();
1098 case 'm': /* map identifier to type */
1099 add_mapping(0, optarg);
1101 case 'n': /* OBSOLETE: set new tty driver */
1103 case 'p': /* OBSOLETE: map identifier to type */
1104 add_mapping("plugboard", optarg);
1106 case 'Q': /* don't output control key settings */
1109 case 'S': /* OBSOLETE: output TERM & TERMCAP */
1112 case 'r': /* display term on stderr */
1115 case 's': /* output TERM set command */
1129 ttype = get_termcap_entry(*argv);
1135 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1136 /* Set window size */
1137 (void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win);
1138 if (win.ws_row == 0 && win.ws_col == 0 &&
1139 tlines > 0 && tcolumns > 0) {
1140 win.ws_row = tlines;
1141 win.ws_col = tcolumns;
1142 (void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win);
1145 set_control_chars();
1151 /* Set the modes if they've changed. */
1152 if (memcmp(&mode, &oldmode, sizeof(mode))) {
1154 tcsetattr(STDERR_FILENO, TCSADRAIN, &mode);
1156 stty(STDERR_FILENO, &mode);
1161 /* Get the terminal name from the entry. */
1162 ttype = _nc_first_name(cur_term->type.term_names);
1165 (void) printf("%s\n", ttype);
1168 (void) fprintf(stderr, "Terminal type is %s.\n", ttype);
1170 * If erase, kill and interrupt characters could have been
1171 * modified and not -Q, display the changes.
1174 report("Erase", VERASE, CERASE);
1175 report("Kill", VKILL, CINTR);
1176 report("Interrupt", VINTR, CKILL);
1181 err("The -S option is not supported under terminfo.");
1185 * Figure out what shell we're using. A hack, we look for an
1186 * environmental variable SHELL ending in "csh".
1188 if ((p = getenv("SHELL")) != 0
1189 && !strcmp(p + strlen(p) - 3, "csh"))
1190 p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n";
1193 (void) printf(p, ttype);
1196 return EXIT_SUCCESS;
1199 /* tset.c ends here */