1 /****************************************************************************
2 * Copyright (c) 1998-2001,2002 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>
104 #include <transform.h>
106 MODULE_ID("$Id: tset.c,v 0.53 2002/08/24 23:18:16 tom Exp $")
108 extern char **environ;
111 #define CTRL(x) ((x) & 0x1f)
113 const char *_nc_progname = "tset";
115 static TTY mode, oldmode, original;
117 static bool can_restore = FALSE;
118 static bool isreset = FALSE; /* invoked as reset */
119 static int terasechar = -1; /* new erase character */
120 static int intrchar = -1; /* new interrupt character */
121 static int tkillchar = -1; /* new kill character */
122 static int tlines, tcolumns; /* window size */
124 #define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
127 CaselessCmp(const char *a, const char *b)
128 { /* strcasecmp isn't portable */
130 int cmp = LOWERCASE(*a) - LOWERCASE(*b);
135 return LOWERCASE(*a) - LOWERCASE(*b);
142 SET_TTY(STDERR_FILENO, &original);
143 (void) fprintf(stderr, "\n");
150 err(const char *fmt,...)
154 (void) fprintf(stderr, "tset: ");
155 (void) vfprintf(stderr, fmt, ap);
162 failed(const char *msg)
165 perror(strncat(strcpy(temp, "tset: "), msg, sizeof(temp) - 10));
177 if ((fp = fopen(file, "r")) == 0)
180 while ((nr = fread(buf, sizeof(char), sizeof(buf), fp)) != 0)
181 if (fwrite(buf, sizeof(char), nr, stderr) != nr)
182 failed("write to stderr");
189 return putc(c, stderr);
192 /* Prompt the user for a terminal type. */
194 askuser(const char *dflt)
196 static char answer[256];
199 /* We can get recalled; if so, don't continue uselessly. */
201 if (feof(stdin) || ferror(stdin)) {
202 (void) fprintf(stderr, "\n");
208 (void) fprintf(stderr, "Terminal type? [%s] ", dflt);
210 (void) fprintf(stderr, "Terminal type? ");
211 (void) fflush(stderr);
213 if (fgets(answer, sizeof(answer), stdin) == 0) {
221 if ((p = strchr(answer, '\n')) != 0)
230 /**************************************************************************
232 * Mapping logic begins here
234 **************************************************************************/
236 /* Baud rate conditionals for mapping. */
245 struct map *next; /* Linked list of maps. */
246 const char *porttype; /* Port type, or "" for any. */
247 const char *type; /* Terminal type to select. */
248 int conditional; /* Baud rate conditionals bitmask. */
249 int speed; /* Baud rate to compare against. */
252 static MAP *cur, *maplist;
254 typedef struct speeds {
259 static const SPEEDS speeds[] =
276 /* sgttyb may define up to this point */
319 tbaudrate(char *rate)
324 /* The baudrate number can be preceded by a 'B', which is ignored. */
328 for (sp = speeds; sp->string; ++sp) {
329 if (!CaselessCmp(rate, sp->string)) {
335 err("unknown baud rate %s", rate);
341 * [port-type][test baudrate]:terminal-type
342 * The baud rate tests are: >, <, @, =, !
345 add_mapping(const char *port, char *arg)
353 mapp = malloc(sizeof(MAP));
354 if (copy == 0 || mapp == 0)
358 cur = maplist = mapp;
364 mapp->porttype = arg;
365 mapp->conditional = 0;
367 arg = strpbrk(arg, "><@=!:");
369 if (arg == 0) { /* [?]term */
370 mapp->type = mapp->porttype;
375 if (arg == mapp->porttype) /* [><@=! baud]:term */
376 termp = mapp->porttype = 0;
380 for (;; ++arg) { /* Optional conditionals. */
383 if (mapp->conditional & GT)
385 mapp->conditional |= LT;
388 if (mapp->conditional & LT)
390 mapp->conditional |= GT;
393 case '=': /* Not documented. */
394 mapp->conditional |= EQ;
397 mapp->conditional |= NOT;
406 if (mapp->conditional)
409 } else { /* Optional baudrate. */
410 arg = strchr(p = arg, ':');
414 mapp->speed = tbaudrate(p);
417 if (arg == (char *) 0) /* Non-optional type. */
422 /* Terminate porttype, if specified. */
426 /* If a NOT conditional, reverse the test. */
427 if (mapp->conditional & NOT)
428 mapp->conditional = ~mapp->conditional & (EQ | GT | LT);
430 /* If user specified a port with an option flag, set it. */
433 badmopt:err("illegal -m option format: %s", copy);
434 mapp->porttype = port;
437 (void) printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY");
438 (void) printf("type: %s\n", mapp->type);
439 (void) printf("conditional: ");
441 if (mapp->conditional & GT) {
445 if (mapp->conditional & EQ) {
446 (void) printf("%sEQ", p);
449 if (mapp->conditional & LT)
450 (void) printf("%sLT", p);
451 (void) printf("\nspeed: %d\n", mapp->speed);
456 * Return the type of terminal to use for a port of type 'type', as specified
457 * by the first applicable mapping in 'map'. If no mappings apply, return
461 mapped(const char *type)
466 for (mapp = maplist; mapp; mapp = mapp->next)
467 if (mapp->porttype == 0 || !strcmp(mapp->porttype, type)) {
468 switch (mapp->conditional) {
469 case 0: /* No test specified. */
473 match = (ospeed == mapp->speed);
476 match = (ospeed >= mapp->speed);
479 match = (ospeed > mapp->speed);
482 match = (ospeed <= mapp->speed);
485 match = (ospeed < mapp->speed);
493 /* No match found; return given type. */
497 /**************************************************************************
501 **************************************************************************/
504 * Figure out what kind of terminal we're dealing with, and then read in
508 get_termcap_entry(char *userarg)
525 /* Try the environment. */
526 if ((ttype = getenv("TERM")) != 0)
529 if ((ttypath = ttyname(STDERR_FILENO)) != 0) {
530 p = _nc_basename(ttypath);
533 * We have the 4.3BSD library call getttynam(3); that means
534 * there's an /etc/ttys to look up device-to-type mappings in.
535 * Try ttyname(3); check for dialup or other mapping.
537 if ((t = getttynam(p))) {
542 if ((fp = fopen("/etc/ttytype", "r")) != 0
543 || (fp = fopen("/etc/ttys", "r")) != 0) {
547 while (fgets(buffer, sizeof(buffer) - 1, fp) != 0) {
548 for (s = buffer, t = d = 0; *s; s++) {
549 if (isspace(UChar(*s)))
553 else if (d == 0 && s != buffer && s[-1] == '\0')
556 if (t != 0 && d != 0 && !strcmp(d, p)) {
564 #endif /* HAVE_GETTTYNAM */
567 /* If still undefined, use "unknown". */
570 map:ttype = mapped(ttype);
573 * If not a path, remove TERMCAP from the environment so we get a
574 * real entry from /etc/termcap. This prevents us from being fooled
575 * by out of date stuff in the environment.
577 found:if ((p = getenv("TERMCAP")) != 0 && *p != '/') {
578 /* 'unsetenv("TERMCAP")' is not portable.
579 * The 'environ' array is better.
582 for (n = 0; environ[n] != 0; n++) {
583 if (!strncmp("TERMCAP=", environ[n], 8)) {
584 while ((environ[n] = environ[n + 1]) != 0) {
593 * ttype now contains a pointer to the type of the terminal.
594 * If the first character is '?', ask the user.
596 if (ttype[0] == '?') {
597 if (ttype[1] != '\0')
598 ttype = askuser(ttype + 1);
602 /* Find the terminfo entry. If it doesn't exist, ask the user. */
603 while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret)
606 (void) fprintf(stderr, "tset: unknown terminal type %s\n",
610 (void) fprintf(stderr,
611 "tset: can't initialize terminal type %s (error %d)\n",
615 ttype = askuser(ttype);
618 tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */
623 /**************************************************************************
627 **************************************************************************/
629 /* some BSD systems have these built in, some systems are missing
630 * one or more definitions. The safest solution is to override.
643 /* control-character defaults */
644 #define CEOF CTRL('D')
645 #define CERASE CTRL('H')
646 #define CINTR 127 /* ^? */
647 #define CKILL CTRL('U')
648 #define CLNEXT CTRL('v')
649 #define CRPRNT CTRL('r')
650 #define CQUIT CTRL('\\')
651 #define CSTART CTRL('Q')
652 #define CSTOP CTRL('S')
653 #define CSUSP CTRL('Z')
655 #define CHK(val, dft) ((int)val <= 0 ? dft : val)
657 static bool set_tabs(void);
660 * Reset the terminal mode bits to a sensible state. Very useful after
661 * a child program dies in raw mode.
667 tcgetattr(STDERR_FILENO, &mode);
669 stty(STDERR_FILENO, &mode);
673 #if defined(VDISCARD) && defined(CDISCARD)
674 mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD);
676 mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF);
677 mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE);
678 #if defined(VFLUSH) && defined(CFLUSH)
679 mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH);
681 mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR);
682 mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL);
683 #if defined(VLNEXT) && defined(CLNEXT)
684 mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT);
686 mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT);
687 #if defined(VREPRINT) && defined(CRPRNT)
688 mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT);
690 #if defined(VSTART) && defined(CSTART)
691 mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART);
693 #if defined(VSTOP) && defined(CSTOP)
694 mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP);
696 #if defined(VSUSP) && defined(CSUSP)
697 mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP);
699 #if defined(VWERASE) && defined(CWERASE)
700 mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE);
703 mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
712 mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON
738 | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY
742 mode.c_oflag |= (OPOST
748 mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL);
749 mode.c_cflag |= (CS8 | CREAD);
750 mode.c_lflag &= ~(ECHONL | NOFLSH
762 mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK
772 SET_TTY(STDERR_FILENO, &mode);
776 * Returns a "good" value for the erase character. This is loosely based on
786 && key_backspace != 0
787 && strlen(key_backspace) == 1)
788 result = key_backspace[0];
797 * Update the values of the erase, interrupt, and kill characters in 'mode'.
799 * SVr4 tset (e.g., Solaris 2.5) only modifies the intr, quit or erase
800 * characters if they're unset, or if we specify them as options. This differs
801 * from BSD 4.4 tset, which always sets erase.
804 set_control_chars(void)
807 if (mode.c_cc[VERASE] == 0 || terasechar >= 0)
808 mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase();
810 if (mode.c_cc[VINTR] == 0 || intrchar >= 0)
811 mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR;
813 if (mode.c_cc[VKILL] == 0 || tkillchar >= 0)
814 mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL;
819 * Set up various conversions in 'mode', including parity, tabs, returns,
820 * echo, and case, according to the termcap entry. If the program we're
821 * running was named with a leading upper-case character, map external
822 * uppercase to internal lowercase.
825 set_conversions(void)
829 * Conversion logic for some *really* ancient terminal glitches,
830 * not supported in terminfo. Left here for succeeding generations
833 if (tgetflag("UC")) {
835 mode.c_iflag |= IUCLC;
836 mode.c_oflag |= OLCUC;
838 } else if (tgetflag("LC")) {
840 mode.c_iflag &= ~IUCLC;
841 mode.c_oflag &= ~OLCUC;
844 mode.c_iflag &= ~(PARMRK | INPCK);
845 mode.c_lflag |= ICANON;
846 if (tgetflag("EP")) {
847 mode.c_cflag |= PARENB;
848 mode.c_cflag &= ~PARODD;
850 if (tgetflag("OP")) {
851 mode.c_cflag |= PARENB;
852 mode.c_cflag |= PARODD;
854 #endif /* __OBSOLETE__ */
858 mode.c_oflag |= ONLCR;
860 mode.c_iflag |= ICRNL;
861 mode.c_lflag |= ECHO;
863 mode.c_oflag |= OXTABS;
866 /* test used to be tgetflag("NL") */
867 if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) {
868 /* Newline, not linefeed. */
870 mode.c_oflag &= ~ONLCR;
872 mode.c_iflag &= ~ICRNL;
875 if (tgetflag("HD")) /* Half duplex. */
876 mode.c_lflag &= ~ECHO;
877 #endif /* __OBSOLETE__ */
879 /* test used to be tgetflag("pt") */
880 if (has_hardware_tabs) /* Print tabs. */
881 mode.c_oflag &= ~OXTABS;
883 mode.c_lflag |= (ECHOE | ECHOK);
887 /* Output startup string. */
895 if (pad_char != (char *) 0) /* Get/set pad character. */
897 #endif /* OBSOLETE */
900 if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) {
901 oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET);
902 SET_TTY(STDERR_FILENO, &oldmode);
908 if ((p = reset_1string) != 0) {
912 if ((p = reset_2string) != 0) {
916 /* What about rf, rs3, as per terminfo man page? */
917 /* also might be nice to send rmacs, rmul, rmm */
918 if ((p = reset_file) != 0
919 || (p = init_file) != 0) {
926 (void) putc('\r', stderr);
927 (void) fflush(stderr);
928 (void) napms(1000); /* Settle the terminal. */
933 * Set the hardware tabs on the terminal, using the ct (clear all tabs),
934 * st (set one tab) and ch (horizontal cursor addressing) capabilities.
935 * This is done before if and is, so they can patch in case we blow this.
936 * Return TRUE if we set any tab stops, FALSE if not.
941 if (set_tab && clear_all_tabs) {
944 (void) putc('\r', stderr); /* Force to left margin. */
945 tputs(clear_all_tabs, 0, outc);
947 for (c = 8; c < tcolumns; c += 8) {
948 /* Get to the right column. In BSD tset, this
949 * used to try a bunch of half-clever things
950 * with cup and hpa, for an average saving of
951 * somewhat less than two character times per
952 * tab stop, less that .01 sec at 2400cps. We
953 * lost all this cruft because it seemed to be
954 * introducing some odd bugs.
955 * ----------12345678----------- */
956 (void) fputs(" ", stderr);
957 tputs(set_tab, 0, outc);
965 /**************************************************************************
969 **************************************************************************/
972 * Tell the user if a control key has been changed from the default value.
976 report(const char *name, int which, unsigned def)
978 unsigned older, newer;
981 newer = mode.c_cc[which];
982 older = oldmode.c_cc[which];
984 if (older == newer && older == def)
987 (void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to");
990 * Check 'delete' before 'backspace', since the key_backspace value
994 (void) fprintf(stderr, "delete.\n");
995 else if ((p = key_backspace) != 0
996 && newer == (unsigned char) p[0]
998 (void) fprintf(stderr, "backspace.\n");
999 else if (newer < 040) {
1001 (void) fprintf(stderr, "control-%c (^%c).\n", newer, newer);
1003 (void) fprintf(stderr, "%c.\n", newer);
1008 * Convert the obsolete argument forms into something that getopt can handle.
1009 * This means that -e, -i and -k get default arguments supplied for them.
1012 obsolete(char **argv)
1014 for (; *argv; ++argv) {
1015 char *parm = argv[0];
1017 if (parm[0] == '-' && parm[1] == '\0') {
1018 argv[0] = strdup("-q");
1022 if ((parm[0] != '-')
1023 || (argv[1] && argv[1][0] != '-')
1024 || (parm[1] != 'e' && parm[1] != 'i' && parm[1] != 'k')
1025 || (parm[2] != '\0'))
1027 switch (argv[0][1]) {
1029 argv[0] = strdup("-e^H");
1032 argv[0] = strdup("-i^C");
1035 argv[0] = strdup("-k^U");
1042 usage(const char *pname)
1044 (void) fprintf(stderr,
1045 "usage: %s [-IQVrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]", pname);
1053 return (optarg[0] == '^' && optarg[1] != '\0')
1054 ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1]))
1059 main(int argc, char **argv)
1061 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1064 int ch, noinit, noset, quiet, Sflag, sflag, showterm;
1068 if (GET_TTY(STDERR_FILENO, &mode) < 0)
1069 failed("standard error");
1071 original = oldmode = mode;
1073 ospeed = cfgetospeed(&mode);
1075 ospeed = mode.sg_ospeed;
1078 p = _nc_rootname(*argv);
1079 if (!strcmp(p, PROG_RESET)) {
1085 noinit = noset = quiet = Sflag = sflag = showterm = 0;
1086 while ((ch = getopt(argc, argv, "a:d:e:Ii:k:m:np:qQSrsV")) != EOF) {
1088 case 'q': /* display term only */
1091 case 'a': /* OBSOLETE: map identifier to type */
1092 add_mapping("arpanet", optarg);
1094 case 'd': /* OBSOLETE: map identifier to type */
1095 add_mapping("dialup", optarg);
1097 case 'e': /* erase character */
1098 terasechar = arg_to_char();
1100 case 'I': /* no initialization strings */
1103 case 'i': /* interrupt character */
1104 intrchar = arg_to_char();
1106 case 'k': /* kill character */
1107 tkillchar = arg_to_char();
1109 case 'm': /* map identifier to type */
1110 add_mapping(0, optarg);
1112 case 'n': /* OBSOLETE: set new tty driver */
1114 case 'p': /* OBSOLETE: map identifier to type */
1115 add_mapping("plugboard", optarg);
1117 case 'Q': /* don't output control key settings */
1120 case 'S': /* OBSOLETE: output TERM & TERMCAP */
1123 case 'r': /* display term on stderr */
1126 case 's': /* output TERM set command */
1130 puts(curses_version());
1131 return EXIT_SUCCESS;
1143 ttype = get_termcap_entry(*argv);
1149 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1150 /* Set window size */
1151 (void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win);
1152 if (win.ws_row == 0 && win.ws_col == 0 &&
1153 tlines > 0 && tcolumns > 0) {
1154 win.ws_row = tlines;
1155 win.ws_col = tcolumns;
1156 (void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win);
1159 set_control_chars();
1165 /* Set the modes if they've changed. */
1166 if (memcmp(&mode, &oldmode, sizeof(mode))) {
1167 SET_TTY(STDERR_FILENO, &mode);
1171 /* Get the terminal name from the entry. */
1172 ttype = _nc_first_name(cur_term->type.term_names);
1175 (void) printf("%s\n", ttype);
1178 (void) fprintf(stderr, "Terminal type is %s.\n", ttype);
1180 * If erase, kill and interrupt characters could have been
1181 * modified and not -Q, display the changes.
1185 report("Erase", VERASE, CERASE);
1186 report("Kill", VKILL, CINTR);
1187 report("Interrupt", VINTR, CKILL);
1193 err("The -S option is not supported under terminfo.");
1197 * Figure out what shell we're using. A hack, we look for an
1198 * environmental variable SHELL ending in "csh".
1200 if ((p = getenv("SHELL")) != 0
1201 && !strcmp(p + strlen(p) - 3, "csh"))
1202 p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n";
1205 (void) printf(p, ttype);
1208 return EXIT_SUCCESS;
1211 /* tset.c ends here */