1 /****************************************************************************
2 * Copyright (c) 1998-2002,2003 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.56 2003/12/06 17:21:01 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");
145 ExitProgram(EXIT_FAILURE
);
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
= (MAP
*) 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 unless the
631 * commonly-altered ones are defined.
633 #if !(defined(CERASE) && defined(CINTR) && defined(CKILL) && defined(CQUIT))
646 /* control-character defaults */
648 #define CEOF CTRL('D')
651 #define CERASE CTRL('H')
654 #define CINTR 127 /* ^? */
657 #define CKILL CTRL('U')
660 #define CLNEXT CTRL('v')
663 #define CRPRNT CTRL('r')
666 #define CQUIT CTRL('\\')
669 #define CSTART CTRL('Q')
672 #define CSTOP CTRL('S')
675 #define CSUSP CTRL('Z')
678 #define CHK(val, dft) ((int)val <= 0 ? dft : val)
680 static bool set_tabs(void);
683 * Reset the terminal mode bits to a sensible state. Very useful after
684 * a child program dies in raw mode.
690 tcgetattr(STDERR_FILENO
, &mode
);
692 stty(STDERR_FILENO
, &mode
);
696 #if defined(VDISCARD) && defined(CDISCARD)
697 mode
.c_cc
[VDISCARD
] = CHK(mode
.c_cc
[VDISCARD
], CDISCARD
);
699 mode
.c_cc
[VEOF
] = CHK(mode
.c_cc
[VEOF
], CEOF
);
700 mode
.c_cc
[VERASE
] = CHK(mode
.c_cc
[VERASE
], CERASE
);
701 #if defined(VFLUSH) && defined(CFLUSH)
702 mode
.c_cc
[VFLUSH
] = CHK(mode
.c_cc
[VFLUSH
], CFLUSH
);
704 mode
.c_cc
[VINTR
] = CHK(mode
.c_cc
[VINTR
], CINTR
);
705 mode
.c_cc
[VKILL
] = CHK(mode
.c_cc
[VKILL
], CKILL
);
706 #if defined(VLNEXT) && defined(CLNEXT)
707 mode
.c_cc
[VLNEXT
] = CHK(mode
.c_cc
[VLNEXT
], CLNEXT
);
709 mode
.c_cc
[VQUIT
] = CHK(mode
.c_cc
[VQUIT
], CQUIT
);
710 #if defined(VREPRINT) && defined(CRPRNT)
711 mode
.c_cc
[VREPRINT
] = CHK(mode
.c_cc
[VREPRINT
], CRPRNT
);
713 #if defined(VSTART) && defined(CSTART)
714 mode
.c_cc
[VSTART
] = CHK(mode
.c_cc
[VSTART
], CSTART
);
716 #if defined(VSTOP) && defined(CSTOP)
717 mode
.c_cc
[VSTOP
] = CHK(mode
.c_cc
[VSTOP
], CSTOP
);
719 #if defined(VSUSP) && defined(CSUSP)
720 mode
.c_cc
[VSUSP
] = CHK(mode
.c_cc
[VSUSP
], CSUSP
);
722 #if defined(VWERASE) && defined(CWERASE)
723 mode
.c_cc
[VWERASE
] = CHK(mode
.c_cc
[VWERASE
], CWERASE
);
726 mode
.c_iflag
&= ~(IGNBRK
| PARMRK
| INPCK
| ISTRIP
| INLCR
| IGNCR
735 mode
.c_iflag
|= (BRKINT
| IGNPAR
| ICRNL
| IXON
761 | NLDLY
| CRDLY
| TABDLY
| BSDLY
| VTDLY
| FFDLY
765 mode
.c_oflag
|= (OPOST
771 mode
.c_cflag
&= ~(CSIZE
| CSTOPB
| PARENB
| PARODD
| CLOCAL
);
772 mode
.c_cflag
|= (CS8
| CREAD
);
773 mode
.c_lflag
&= ~(ECHONL
| NOFLSH
785 mode
.c_lflag
|= (ISIG
| ICANON
| ECHO
| ECHOE
| ECHOK
795 SET_TTY(STDERR_FILENO
, &mode
);
799 * Returns a "good" value for the erase character. This is loosely based on
809 && key_backspace
!= 0
810 && strlen(key_backspace
) == 1)
811 result
= key_backspace
[0];
820 * Update the values of the erase, interrupt, and kill characters in 'mode'.
822 * SVr4 tset (e.g., Solaris 2.5) only modifies the intr, quit or erase
823 * characters if they're unset, or if we specify them as options. This differs
824 * from BSD 4.4 tset, which always sets erase.
827 set_control_chars(void)
830 if (mode
.c_cc
[VERASE
] == 0 || terasechar
>= 0)
831 mode
.c_cc
[VERASE
] = terasechar
>= 0 ? terasechar
: default_erase();
833 if (mode
.c_cc
[VINTR
] == 0 || intrchar
>= 0)
834 mode
.c_cc
[VINTR
] = intrchar
>= 0 ? intrchar
: CINTR
;
836 if (mode
.c_cc
[VKILL
] == 0 || tkillchar
>= 0)
837 mode
.c_cc
[VKILL
] = tkillchar
>= 0 ? tkillchar
: CKILL
;
842 * Set up various conversions in 'mode', including parity, tabs, returns,
843 * echo, and case, according to the termcap entry. If the program we're
844 * running was named with a leading upper-case character, map external
845 * uppercase to internal lowercase.
848 set_conversions(void)
852 * Conversion logic for some *really* ancient terminal glitches,
853 * not supported in terminfo. Left here for succeeding generations
856 if (tgetflag("UC")) {
858 mode
.c_iflag
|= IUCLC
;
859 mode
.c_oflag
|= OLCUC
;
861 } else if (tgetflag("LC")) {
863 mode
.c_iflag
&= ~IUCLC
;
864 mode
.c_oflag
&= ~OLCUC
;
867 mode
.c_iflag
&= ~(PARMRK
| INPCK
);
868 mode
.c_lflag
|= ICANON
;
869 if (tgetflag("EP")) {
870 mode
.c_cflag
|= PARENB
;
871 mode
.c_cflag
&= ~PARODD
;
873 if (tgetflag("OP")) {
874 mode
.c_cflag
|= PARENB
;
875 mode
.c_cflag
|= PARODD
;
877 #endif /* __OBSOLETE__ */
881 mode
.c_oflag
|= ONLCR
;
883 mode
.c_iflag
|= ICRNL
;
884 mode
.c_lflag
|= ECHO
;
886 mode
.c_oflag
|= OXTABS
;
889 /* test used to be tgetflag("NL") */
890 if (newline
!= (char *) 0 && newline
[0] == '\n' && !newline
[1]) {
891 /* Newline, not linefeed. */
893 mode
.c_oflag
&= ~ONLCR
;
895 mode
.c_iflag
&= ~ICRNL
;
898 if (tgetflag("HD")) /* Half duplex. */
899 mode
.c_lflag
&= ~ECHO
;
900 #endif /* __OBSOLETE__ */
902 /* test used to be tgetflag("pt") */
903 if (has_hardware_tabs
) /* Print tabs. */
904 mode
.c_oflag
&= ~OXTABS
;
906 mode
.c_lflag
|= (ECHOE
| ECHOK
);
910 /* Output startup string. */
918 if (pad_char
!= (char *) 0) /* Get/set pad character. */
920 #endif /* OBSOLETE */
923 if (oldmode
.c_oflag
& (TAB3
| ONLCR
| OCRNL
| ONLRET
)) {
924 oldmode
.c_oflag
&= (TAB3
| ONLCR
| OCRNL
| ONLRET
);
925 SET_TTY(STDERR_FILENO
, &oldmode
);
931 if ((p
= reset_1string
) != 0) {
935 if ((p
= reset_2string
) != 0) {
939 /* What about rf, rs3, as per terminfo man page? */
940 /* also might be nice to send rmacs, rmul, rmm */
941 if ((p
= reset_file
) != 0
942 || (p
= init_file
) != 0) {
949 (void) putc('\r', stderr
);
950 (void) fflush(stderr
);
951 (void) napms(1000); /* Settle the terminal. */
956 * Set the hardware tabs on the terminal, using the ct (clear all tabs),
957 * st (set one tab) and ch (horizontal cursor addressing) capabilities.
958 * This is done before if and is, so they can patch in case we blow this.
959 * Return TRUE if we set any tab stops, FALSE if not.
964 if (set_tab
&& clear_all_tabs
) {
967 (void) putc('\r', stderr
); /* Force to left margin. */
968 tputs(clear_all_tabs
, 0, outc
);
970 for (c
= 8; c
< tcolumns
; c
+= 8) {
971 /* Get to the right column. In BSD tset, this
972 * used to try a bunch of half-clever things
973 * with cup and hpa, for an average saving of
974 * somewhat less than two character times per
975 * tab stop, less that .01 sec at 2400cps. We
976 * lost all this cruft because it seemed to be
977 * introducing some odd bugs.
978 * ----------12345678----------- */
979 (void) fputs(" ", stderr
);
980 tputs(set_tab
, 0, outc
);
988 /**************************************************************************
992 **************************************************************************/
995 * Tell the user if a control key has been changed from the default value.
999 report(const char *name
, int which
, unsigned def
)
1001 unsigned older
, newer
;
1004 newer
= mode
.c_cc
[which
];
1005 older
= oldmode
.c_cc
[which
];
1007 if (older
== newer
&& older
== def
)
1010 (void) fprintf(stderr
, "%s %s ", name
, older
== newer
? "is" : "set to");
1013 * Check 'delete' before 'backspace', since the key_backspace value
1017 (void) fprintf(stderr
, "delete.\n");
1018 else if ((p
= key_backspace
) != 0
1019 && newer
== (unsigned char) p
[0]
1021 (void) fprintf(stderr
, "backspace.\n");
1022 else if (newer
< 040) {
1024 (void) fprintf(stderr
, "control-%c (^%c).\n", newer
, newer
);
1026 (void) fprintf(stderr
, "%c.\n", newer
);
1031 * Convert the obsolete argument forms into something that getopt can handle.
1032 * This means that -e, -i and -k get default arguments supplied for them.
1035 obsolete(char **argv
)
1037 for (; *argv
; ++argv
) {
1038 char *parm
= argv
[0];
1040 if (parm
[0] == '-' && parm
[1] == '\0') {
1041 argv
[0] = strdup("-q");
1045 if ((parm
[0] != '-')
1046 || (argv
[1] && argv
[1][0] != '-')
1047 || (parm
[1] != 'e' && parm
[1] != 'i' && parm
[1] != 'k')
1048 || (parm
[2] != '\0'))
1050 switch (argv
[0][1]) {
1052 argv
[0] = strdup("-e^H");
1055 argv
[0] = strdup("-i^C");
1058 argv
[0] = strdup("-k^U");
1065 usage(const char *pname
)
1067 (void) fprintf(stderr
,
1068 "usage: %s [-IQVrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]", pname
);
1076 return (optarg
[0] == '^' && optarg
[1] != '\0')
1077 ? ((optarg
[1] == '?') ? '\177' : CTRL(optarg
[1]))
1082 main(int argc
, char **argv
)
1084 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1087 int ch
, noinit
, noset
, quiet
, Sflag
, sflag
, showterm
;
1091 if (GET_TTY(STDERR_FILENO
, &mode
) < 0)
1092 failed("standard error");
1094 original
= oldmode
= mode
;
1096 ospeed
= cfgetospeed(&mode
);
1098 ospeed
= mode
.sg_ospeed
;
1101 p
= _nc_rootname(*argv
);
1102 if (!strcmp(p
, PROG_RESET
)) {
1108 noinit
= noset
= quiet
= Sflag
= sflag
= showterm
= 0;
1109 while ((ch
= getopt(argc
, argv
, "a:d:e:Ii:k:m:np:qQSrsV")) != EOF
) {
1111 case 'q': /* display term only */
1114 case 'a': /* OBSOLETE: map identifier to type */
1115 add_mapping("arpanet", optarg
);
1117 case 'd': /* OBSOLETE: map identifier to type */
1118 add_mapping("dialup", optarg
);
1120 case 'e': /* erase character */
1121 terasechar
= arg_to_char();
1123 case 'I': /* no initialization strings */
1126 case 'i': /* interrupt character */
1127 intrchar
= arg_to_char();
1129 case 'k': /* kill character */
1130 tkillchar
= arg_to_char();
1132 case 'm': /* map identifier to type */
1133 add_mapping(0, optarg
);
1135 case 'n': /* OBSOLETE: set new tty driver */
1137 case 'p': /* OBSOLETE: map identifier to type */
1138 add_mapping("plugboard", optarg
);
1140 case 'Q': /* don't output control key settings */
1143 case 'S': /* OBSOLETE: output TERM & TERMCAP */
1146 case 'r': /* display term on stderr */
1149 case 's': /* output TERM set command */
1153 puts(curses_version());
1154 return EXIT_SUCCESS
;
1166 ttype
= get_termcap_entry(*argv
);
1172 #if defined(TIOCGWINSZ) && defined(TIOCSWINSZ)
1173 /* Set window size */
1174 (void) ioctl(STDERR_FILENO
, TIOCGWINSZ
, &win
);
1175 if (win
.ws_row
== 0 && win
.ws_col
== 0 &&
1176 tlines
> 0 && tcolumns
> 0) {
1177 win
.ws_row
= tlines
;
1178 win
.ws_col
= tcolumns
;
1179 (void) ioctl(STDERR_FILENO
, TIOCSWINSZ
, &win
);
1182 set_control_chars();
1188 /* Set the modes if they've changed. */
1189 if (memcmp(&mode
, &oldmode
, sizeof(mode
))) {
1190 SET_TTY(STDERR_FILENO
, &mode
);
1194 /* Get the terminal name from the entry. */
1195 ttype
= _nc_first_name(cur_term
->type
.term_names
);
1198 (void) printf("%s\n", ttype
);
1201 (void) fprintf(stderr
, "Terminal type is %s.\n", ttype
);
1203 * If erase, kill and interrupt characters could have been
1204 * modified and not -Q, display the changes.
1208 report("Erase", VERASE
, CERASE
);
1209 report("Kill", VKILL
, CKILL
);
1210 report("Interrupt", VINTR
, CINTR
);
1216 err("The -S option is not supported under terminfo.");
1221 * Figure out what shell we're using. A hack, we look for an
1222 * environmental variable SHELL ending in "csh".
1224 if ((p
= getenv("SHELL")) != 0
1225 && (len
= strlen(p
)) >= 3
1226 && !strcmp(p
+ len
- 3, "csh"))
1227 p
= "set noglob;\nsetenv TERM %s;\nunset noglob;\n";
1230 (void) printf(p
, ttype
);
1233 return EXIT_SUCCESS
;