1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 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 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
36 * tset.c - terminal initialization utility
38 * This code was mostly swiped from 4.4BSD tset, with some obsolescent
39 * cruft removed and substantial portions rewritten. A Regents of the
40 * University of California copyright applies to some portions of the
41 * code, and is reproduced below:
44 * Copyright (c) 1980, 1991, 1993
45 * The Regents of the University of California. All rights reserved.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. All advertising materials mentioning features or use of this software
56 * must display the following acknowledgement:
57 * This product includes software developed by the University of
58 * California, Berkeley and its contributors.
59 * 4. Neither the name of the University nor the names of its contributors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
63 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
76 #define __INTERNAL_CAPS_VISIBLE /* we need to see has_hardware_tabs */
77 #include <progs.priv.h>
84 #if HAVE_GETTTYNAM && HAVE_TTYENT_H
88 char *ttyname(int fd);
91 /* this is just to stifle a missing-prototype warning */
93 # include <sys/ioctl.h>
97 /* they neglected to define struct winsize in termios.h -- it's only
99 #include <sys/stream.h>
100 #include <sys/ptem.h>
103 #include <dump_entry.h>
104 #include <transform.h>
106 MODULE_ID("$Id: tset.c,v 1.69 2007/09/29 15:51:35 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 opt_c; /* set control-chars */
118 static bool opt_w; /* set window-size */
120 static bool can_restore = FALSE;
121 static bool isreset = FALSE; /* invoked as reset */
122 static int terasechar = -1; /* new erase character */
123 static int intrchar = -1; /* new interrupt character */
124 static int tkillchar = -1; /* new kill character */
125 static int tlines, tcolumns; /* window size */
127 #define LOWERCASE(c) ((isalpha(UChar(c)) && isupper(UChar(c))) ? tolower(UChar(c)) : (c))
130 CaselessCmp(const char *a, const char *b)
131 { /* strcasecmp isn't portable */
133 int cmp = LOWERCASE(*a) - LOWERCASE(*b);
138 return LOWERCASE(*a) - LOWERCASE(*b);
145 SET_TTY(STDERR_FILENO, &original);
146 (void) fprintf(stderr, "\n");
148 ExitProgram(EXIT_FAILURE);
153 err(const char *fmt,...)
157 (void) fprintf(stderr, "%s: ", _nc_progname);
158 (void) vfprintf(stderr, fmt, ap);
165 failed(const char *msg)
168 unsigned len = strlen(_nc_progname) + 2;
170 if (len < sizeof(temp) - 12) {
171 strcpy(temp, _nc_progname);
174 strcpy(temp, "tset: ");
176 perror(strncat(temp, msg, sizeof(temp) - strlen(temp) - 2));
188 if ((fp = fopen(file, "r")) == 0)
191 while ((nr = fread(buf, sizeof(char), sizeof(buf), fp)) != 0)
192 if (fwrite(buf, sizeof(char), nr, stderr) != nr)
193 failed("write to stderr");
200 return putc(c, stderr);
203 /* Prompt the user for a terminal type. */
205 askuser(const char *dflt)
207 static char answer[256];
210 /* We can get recalled; if so, don't continue uselessly. */
212 if (feof(stdin) || ferror(stdin)) {
213 (void) fprintf(stderr, "\n");
219 (void) fprintf(stderr, "Terminal type? [%s] ", dflt);
221 (void) fprintf(stderr, "Terminal type? ");
222 (void) fflush(stderr);
224 if (fgets(answer, sizeof(answer), stdin) == 0) {
232 if ((p = strchr(answer, '\n')) != 0)
241 /**************************************************************************
243 * Mapping logic begins here
245 **************************************************************************/
247 /* Baud rate conditionals for mapping. */
256 struct map *next; /* Linked list of maps. */
257 const char *porttype; /* Port type, or "" for any. */
258 const char *type; /* Terminal type to select. */
259 int conditional; /* Baud rate conditionals bitmask. */
260 int speed; /* Baud rate to compare against. */
263 static MAP *cur, *maplist;
265 typedef struct speeds {
270 static const SPEEDS speeds[] =
287 /* sgttyb may define up to this point */
330 tbaudrate(char *rate)
335 /* The baudrate number can be preceded by a 'B', which is ignored. */
339 for (sp = speeds; sp->string; ++sp) {
340 if (!CaselessCmp(rate, sp->string)) {
346 err("unknown baud rate %s", rate);
352 * [port-type][test baudrate]:terminal-type
353 * The baud rate tests are: >, <, @, =, !
356 add_mapping(const char *port, char *arg)
364 mapp = (MAP *) malloc(sizeof(MAP));
365 if (copy == 0 || mapp == 0)
369 cur = maplist = mapp;
375 mapp->porttype = arg;
376 mapp->conditional = 0;
378 arg = strpbrk(arg, "><@=!:");
380 if (arg == 0) { /* [?]term */
381 mapp->type = mapp->porttype;
386 if (arg == mapp->porttype) /* [><@=! baud]:term */
387 termp = mapp->porttype = 0;
391 for (;; ++arg) { /* Optional conditionals. */
394 if (mapp->conditional & GT)
396 mapp->conditional |= LT;
399 if (mapp->conditional & LT)
401 mapp->conditional |= GT;
404 case '=': /* Not documented. */
405 mapp->conditional |= EQ;
408 mapp->conditional |= NOT;
417 if (mapp->conditional)
420 } else { /* Optional baudrate. */
421 arg = strchr(p = arg, ':');
425 mapp->speed = tbaudrate(p);
428 if (arg == (char *) 0) /* Non-optional type. */
433 /* Terminate porttype, if specified. */
437 /* If a NOT conditional, reverse the test. */
438 if (mapp->conditional & NOT)
439 mapp->conditional = ~mapp->conditional & (EQ | GT | LT);
441 /* If user specified a port with an option flag, set it. */
444 badmopt:err("illegal -m option format: %s", copy);
445 mapp->porttype = port;
448 (void) printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY");
449 (void) printf("type: %s\n", mapp->type);
450 (void) printf("conditional: ");
452 if (mapp->conditional & GT) {
456 if (mapp->conditional & EQ) {
457 (void) printf("%sEQ", p);
460 if (mapp->conditional & LT)
461 (void) printf("%sLT", p);
462 (void) printf("\nspeed: %d\n", mapp->speed);
467 * Return the type of terminal to use for a port of type 'type', as specified
468 * by the first applicable mapping in 'map'. If no mappings apply, return
472 mapped(const char *type)
477 for (mapp = maplist; mapp; mapp = mapp->next)
478 if (mapp->porttype == 0 || !strcmp(mapp->porttype, type)) {
479 switch (mapp->conditional) {
480 case 0: /* No test specified. */
484 match = (ospeed == mapp->speed);
487 match = (ospeed >= mapp->speed);
490 match = (ospeed > mapp->speed);
493 match = (ospeed <= mapp->speed);
496 match = (ospeed < mapp->speed);
504 /* No match found; return given type. */
508 /**************************************************************************
512 **************************************************************************/
515 * Figure out what kind of terminal we're dealing with, and then read in
519 get_termcap_entry(char *userarg)
536 /* Try the environment. */
537 if ((ttype = getenv("TERM")) != 0)
540 if ((ttypath = ttyname(STDERR_FILENO)) != 0) {
541 p = _nc_basename(ttypath);
544 * We have the 4.3BSD library call getttynam(3); that means
545 * there's an /etc/ttys to look up device-to-type mappings in.
546 * Try ttyname(3); check for dialup or other mapping.
548 if ((t = getttynam(p))) {
553 if ((fp = fopen("/etc/ttytype", "r")) != 0
554 || (fp = fopen("/etc/ttys", "r")) != 0) {
558 while (fgets(buffer, sizeof(buffer) - 1, fp) != 0) {
559 for (s = buffer, t = d = 0; *s; s++) {
560 if (isspace(UChar(*s)))
564 else if (d == 0 && s != buffer && s[-1] == '\0')
567 if (t != 0 && d != 0 && !strcmp(d, p)) {
575 #endif /* HAVE_GETTTYNAM */
578 /* If still undefined, use "unknown". */
581 map:ttype = mapped(ttype);
584 * If not a path, remove TERMCAP from the environment so we get a
585 * real entry from /etc/termcap. This prevents us from being fooled
586 * by out of date stuff in the environment.
588 found:if ((p = getenv("TERMCAP")) != 0 && !_nc_is_abs_path(p)) {
589 /* 'unsetenv("TERMCAP")' is not portable.
590 * The 'environ' array is better.
593 for (n = 0; environ[n] != 0; n++) {
594 if (!strncmp("TERMCAP=", environ[n], 8)) {
595 while ((environ[n] = environ[n + 1]) != 0) {
604 * ttype now contains a pointer to the type of the terminal.
605 * If the first character is '?', ask the user.
607 if (ttype[0] == '?') {
608 if (ttype[1] != '\0')
609 ttype = askuser(ttype + 1);
613 /* Find the terminfo entry. If it doesn't exist, ask the user. */
614 while (setupterm((NCURSES_CONST char *) ttype, STDOUT_FILENO, &errret)
617 (void) fprintf(stderr, "%s: unknown terminal type %s\n",
618 _nc_progname, ttype);
621 (void) fprintf(stderr,
622 "%s: can't initialize terminal type %s (error %d)\n",
623 _nc_progname, ttype, errret);
626 ttype = askuser(ttype);
629 tgetflag("am"); /* force lib_termcap.o to be linked for 'ospeed' */
634 /**************************************************************************
638 **************************************************************************/
640 /* some BSD systems have these built in, some systems are missing
641 * one or more definitions. The safest solution is to override unless the
642 * commonly-altered ones are defined.
644 #if !(defined(CERASE) && defined(CINTR) && defined(CKILL) && defined(CQUIT))
657 /* control-character defaults */
659 #define CEOF CTRL('D')
662 #define CERASE CTRL('H')
665 #define CINTR 127 /* ^? */
668 #define CKILL CTRL('U')
671 #define CLNEXT CTRL('v')
674 #define CRPRNT CTRL('r')
677 #define CQUIT CTRL('\\')
680 #define CSTART CTRL('Q')
683 #define CSTOP CTRL('S')
686 #define CSUSP CTRL('Z')
689 #if defined(_POSIX_VDISABLE)
690 #define DISABLED(val) (((_POSIX_VDISABLE != -1) \
691 && ((val) == _POSIX_VDISABLE)) \
694 #define DISABLED(val) ((int)(val) <= 0)
697 #define CHK(val, dft) (DISABLED(val) ? dft : val)
699 static bool set_tabs(void);
702 * Reset the terminal mode bits to a sensible state. Very useful after
703 * a child program dies in raw mode.
709 tcgetattr(STDERR_FILENO, &mode);
711 stty(STDERR_FILENO, &mode);
715 #if defined(VDISCARD) && defined(CDISCARD)
716 mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD);
718 mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF);
719 mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE);
720 #if defined(VFLUSH) && defined(CFLUSH)
721 mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH);
723 mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR);
724 mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL);
725 #if defined(VLNEXT) && defined(CLNEXT)
726 mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT);
728 mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT);
729 #if defined(VREPRINT) && defined(CRPRNT)
730 mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT);
732 #if defined(VSTART) && defined(CSTART)
733 mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART);
735 #if defined(VSTOP) && defined(CSTOP)
736 mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP);
738 #if defined(VSUSP) && defined(CSUSP)
739 mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP);
741 #if defined(VWERASE) && defined(CWERASE)
742 mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE);
745 mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
754 mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON
799 mode.c_oflag |= (OPOST
805 mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL);
806 mode.c_cflag |= (CS8 | CREAD);
807 mode.c_lflag &= ~(ECHONL | NOFLSH
819 mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK
829 SET_TTY(STDERR_FILENO, &mode);
833 * Returns a "good" value for the erase character. This is loosely based on
843 && key_backspace != 0
844 && strlen(key_backspace) == 1)
845 result = key_backspace[0];
854 * Update the values of the erase, interrupt, and kill characters in 'mode'.
856 * SVr4 tset (e.g., Solaris 2.5) only modifies the intr, quit or erase
857 * characters if they're unset, or if we specify them as options. This differs
858 * from BSD 4.4 tset, which always sets erase.
861 set_control_chars(void)
864 if (DISABLED(mode.c_cc[VERASE]) || terasechar >= 0)
865 mode.c_cc[VERASE] = terasechar >= 0 ? terasechar : default_erase();
867 if (DISABLED(mode.c_cc[VINTR]) || intrchar >= 0)
868 mode.c_cc[VINTR] = intrchar >= 0 ? intrchar : CINTR;
870 if (DISABLED(mode.c_cc[VKILL]) || tkillchar >= 0)
871 mode.c_cc[VKILL] = tkillchar >= 0 ? tkillchar : CKILL;
876 * Set up various conversions in 'mode', including parity, tabs, returns,
877 * echo, and case, according to the termcap entry. If the program we're
878 * running was named with a leading upper-case character, map external
879 * uppercase to internal lowercase.
882 set_conversions(void)
886 * Conversion logic for some *really* ancient terminal glitches,
887 * not supported in terminfo. Left here for succeeding generations
890 if (tgetflag("UC")) {
892 mode.c_iflag |= IUCLC;
893 mode.c_oflag |= OLCUC;
895 } else if (tgetflag("LC")) {
897 mode.c_iflag &= ~IUCLC;
898 mode.c_oflag &= ~OLCUC;
901 mode.c_iflag &= ~(PARMRK | INPCK);
902 mode.c_lflag |= ICANON;
903 if (tgetflag("EP")) {
904 mode.c_cflag |= PARENB;
905 mode.c_cflag &= ~PARODD;
907 if (tgetflag("OP")) {
908 mode.c_cflag |= PARENB;
909 mode.c_cflag |= PARODD;
911 #endif /* __OBSOLETE__ */
915 mode.c_oflag |= ONLCR;
917 mode.c_iflag |= ICRNL;
918 mode.c_lflag |= ECHO;
920 mode.c_oflag |= OXTABS;
923 /* test used to be tgetflag("NL") */
924 if (newline != (char *) 0 && newline[0] == '\n' && !newline[1]) {
925 /* Newline, not linefeed. */
927 mode.c_oflag &= ~ONLCR;
929 mode.c_iflag &= ~ICRNL;
932 if (tgetflag("HD")) /* Half duplex. */
933 mode.c_lflag &= ~ECHO;
934 #endif /* __OBSOLETE__ */
936 /* test used to be tgetflag("pt") */
937 if (has_hardware_tabs) /* Print tabs. */
938 mode.c_oflag &= ~OXTABS;
940 mode.c_lflag |= (ECHOE | ECHOK);
944 /* Output startup string. */
952 if (pad_char != (char *) 0) /* Get/set pad character. */
954 #endif /* OBSOLETE */
957 if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) {
958 oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET);
959 SET_TTY(STDERR_FILENO, &oldmode);
965 if ((p = reset_1string) != 0) {
969 if ((p = reset_2string) != 0) {
973 /* What about rf, rs3, as per terminfo man page? */
974 /* also might be nice to send rmacs, rmul, rmm */
975 if ((p = reset_file) != 0
976 || (p = init_file) != 0) {
983 (void) putc('\r', stderr);
984 (void) fflush(stderr);
985 (void) napms(1000); /* Settle the terminal. */
990 * Set the hardware tabs on the terminal, using the ct (clear all tabs),
991 * st (set one tab) and ch (horizontal cursor addressing) capabilities.
992 * This is done before if and is, so they can patch in case we blow this.
993 * Return TRUE if we set any tab stops, FALSE if not.
998 if (set_tab && clear_all_tabs) {
1001 (void) putc('\r', stderr); /* Force to left margin. */
1002 tputs(clear_all_tabs, 0, outc);
1004 for (c = 8; c < tcolumns; c += 8) {
1005 /* Get to the right column. In BSD tset, this
1006 * used to try a bunch of half-clever things
1007 * with cup and hpa, for an average saving of
1008 * somewhat less than two character times per
1009 * tab stop, less than .01 sec at 2400cps. We
1010 * lost all this cruft because it seemed to be
1011 * introducing some odd bugs.
1012 * -----------12345678----------- */
1013 (void) fputs(" ", stderr);
1014 tputs(set_tab, 0, outc);
1022 /**************************************************************************
1026 **************************************************************************/
1029 * Tell the user if a control key has been changed from the default value.
1033 report(const char *name, int which, unsigned def)
1035 unsigned older, newer;
1038 newer = mode.c_cc[which];
1039 older = oldmode.c_cc[which];
1041 if (older == newer && older == def)
1044 (void) fprintf(stderr, "%s %s ", name, older == newer ? "is" : "set to");
1046 if (DISABLED(newer))
1047 (void) fprintf(stderr, "undef.\n");
1049 * Check 'delete' before 'backspace', since the key_backspace value
1052 else if (newer == 0177)
1053 (void) fprintf(stderr, "delete.\n");
1054 else if ((p = key_backspace) != 0
1055 && newer == (unsigned char) p[0]
1057 (void) fprintf(stderr, "backspace.\n");
1058 else if (newer < 040) {
1060 (void) fprintf(stderr, "control-%c (^%c).\n", UChar(newer), UChar(newer));
1062 (void) fprintf(stderr, "%c.\n", UChar(newer));
1067 * Convert the obsolete argument forms into something that getopt can handle.
1068 * This means that -e, -i and -k get default arguments supplied for them.
1071 obsolete(char **argv)
1073 for (; *argv; ++argv) {
1074 char *parm = argv[0];
1076 if (parm[0] == '-' && parm[1] == '\0') {
1077 argv[0] = strdup("-q");
1081 if ((parm[0] != '-')
1082 || (argv[1] && argv[1][0] != '-')
1083 || (parm[1] != 'e' && parm[1] != 'i' && parm[1] != 'k')
1084 || (parm[2] != '\0'))
1086 switch (argv[0][1]) {
1088 argv[0] = strdup("-e^H");
1091 argv[0] = strdup("-i^C");
1094 argv[0] = strdup("-k^U");
1103 static const char *tbl[] =
1107 ," -c set control characters"
1108 ," -e ch erase character"
1109 ," -I no initialization strings"
1110 ," -i ch interrupt character"
1111 ," -k ch kill character"
1112 ," -m mapping map identifier to type"
1113 ," -Q do not output control key settings"
1114 ," -r display term on stderr"
1115 ," -s output TERM set command"
1116 ," -V print curses-version"
1117 ," -w set window-size"
1120 (void) fprintf(stderr, "Usage: %s [options] [terminal]\n", _nc_progname);
1121 for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); ++n)
1122 fprintf(stderr, "%s\n", tbl[n]);
1130 return (optarg[0] == '^' && optarg[1] != '\0')
1131 ? ((optarg[1] == '?') ? '\177' : CTRL(optarg[1]))
1136 main(int argc, char **argv)
1138 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1141 int ch, noinit, noset, quiet, Sflag, sflag, showterm;
1146 noinit = noset = quiet = Sflag = sflag = showterm = 0;
1147 while ((ch = getopt(argc, argv, "a:cd:e:Ii:k:m:np:qQSrsVw")) != -1) {
1149 case 'c': /* set control-chars */
1152 case 'a': /* OBSOLETE: map identifier to type */
1153 add_mapping("arpanet", optarg);
1155 case 'd': /* OBSOLETE: map identifier to type */
1156 add_mapping("dialup", optarg);
1158 case 'e': /* erase character */
1159 terasechar = arg_to_char();
1161 case 'I': /* no initialization strings */
1164 case 'i': /* interrupt character */
1165 intrchar = arg_to_char();
1167 case 'k': /* kill character */
1168 tkillchar = arg_to_char();
1170 case 'm': /* map identifier to type */
1171 add_mapping(0, optarg);
1173 case 'n': /* OBSOLETE: set new tty driver */
1175 case 'p': /* OBSOLETE: map identifier to type */
1176 add_mapping("plugboard", optarg);
1178 case 'Q': /* don't output control key settings */
1181 case 'q': /* display term only */
1184 case 'r': /* display term on stderr */
1187 case 'S': /* OBSOLETE: output TERM & TERMCAP */
1190 case 's': /* output TERM set command */
1193 case 'V': /* print curses-version */
1194 puts(curses_version());
1195 ExitProgram(EXIT_SUCCESS);
1196 case 'w': /* set window-size */
1205 _nc_progname = _nc_rootname(*argv);
1212 if (!opt_c && !opt_w)
1213 opt_c = opt_w = TRUE;
1215 if (GET_TTY(STDERR_FILENO, &mode) < 0)
1216 failed("standard error");
1218 original = oldmode = mode;
1220 ospeed = cfgetospeed(&mode);
1222 ospeed = mode.sg_ospeed;
1225 if (!strcmp(_nc_progname, PROG_RESET)) {
1230 ttype = get_termcap_entry(*argv);
1236 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1238 /* Set window size */
1239 (void) ioctl(STDERR_FILENO, TIOCGWINSZ, &win);
1240 if (win.ws_row == 0 && win.ws_col == 0 &&
1241 tlines > 0 && tcolumns > 0) {
1242 win.ws_row = tlines;
1243 win.ws_col = tcolumns;
1244 (void) ioctl(STDERR_FILENO, TIOCSWINSZ, &win);
1249 set_control_chars();
1255 /* Set the modes if they've changed. */
1256 if (memcmp(&mode, &oldmode, sizeof(mode))) {
1257 SET_TTY(STDERR_FILENO, &mode);
1262 /* Get the terminal name from the entry. */
1263 ttype = _nc_first_name(cur_term->type.term_names);
1266 (void) printf("%s\n", ttype);
1269 (void) fprintf(stderr, "Terminal type is %s.\n", ttype);
1271 * If erase, kill and interrupt characters could have been
1272 * modified and not -Q, display the changes.
1276 report("Erase", VERASE, CERASE);
1277 report("Kill", VKILL, CKILL);
1278 report("Interrupt", VINTR, CINTR);
1284 err("The -S option is not supported under terminfo.");
1291 * Figure out what shell we're using. A hack, we look for an
1292 * environmental variable SHELL ending in "csh".
1294 if ((var = getenv("SHELL")) != 0
1295 && ((len = strlen(leaf = _nc_basename(var))) >= 3)
1296 && !strcmp(leaf + len - 3, "csh"))
1297 p = "set noglob;\nsetenv TERM %s;\nunset noglob;\n";
1300 (void) printf(p, ttype);
1303 ExitProgram(EXIT_SUCCESS);