From 8b871ac36aa5a32fb14107950190e5d58763cf98 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 12 Jan 2021 17:34:49 +0100 Subject: [PATCH 1/3] ncurses: Add support for terminfo database Along with the termcap database, ncurses will now lookup for the terminfo database, note that the terminfo database is being looked up first and then it fallsback on the termcap one. While here drop our custom reader for the termcap datanase, over the time it needed maintenance to be able to catchup with changes on ncurses side. Install the ncurses tools which are needed to deal with the terminfo database. Note that to add a new terminfo information to the database from ports the ports will just need to add their extra information into: /usr/local/share/misc/site-terminfo// this is the default target of the tic(1) command --- lib/ncurses/config.mk | 14 +- lib/ncurses/ncurses/Makefile | 9 +- lib/ncurses/ncurses/ncurses_cfg.h | 63 +++-- lib/ncurses/ncurses/termcap.c | 266 ------------------- share/mk/src.tools.mk | 1 + usr.bin/Makefile | 4 +- usr.bin/ncurses/Makefile | 40 +++ usr.bin/ncurses/transform.h | 10 + usr.bin/tput/Makefile | 9 - usr.bin/tput/Makefile.depend | 18 -- usr.bin/tput/clear.sh | 37 --- usr.bin/tput/tput.1 | 179 ------------- usr.bin/tput/tput.c | 214 --------------- usr.bin/tset/Makefile | 11 - usr.bin/tset/Makefile.depend | 18 -- usr.bin/tset/extern.h | 51 ---- usr.bin/tset/map.c | 254 ------------------ usr.bin/tset/misc.c | 68 ----- usr.bin/tset/set.c | 324 ----------------------- usr.bin/tset/term.c | 158 ----------- usr.bin/tset/tset.1 | 421 ------------------------------ usr.bin/tset/tset.c | 299 --------------------- usr.bin/tset/wrterm.c | 116 -------- 23 files changed, 98 insertions(+), 2486 deletions(-) delete mode 100644 lib/ncurses/ncurses/termcap.c create mode 100644 usr.bin/ncurses/Makefile create mode 100644 usr.bin/ncurses/transform.h delete mode 100644 usr.bin/tput/Makefile delete mode 100644 usr.bin/tput/Makefile.depend delete mode 100644 usr.bin/tput/clear.sh delete mode 100644 usr.bin/tput/tput.1 delete mode 100644 usr.bin/tput/tput.c delete mode 100644 usr.bin/tset/Makefile delete mode 100644 usr.bin/tset/Makefile.depend delete mode 100644 usr.bin/tset/extern.h delete mode 100644 usr.bin/tset/map.c delete mode 100644 usr.bin/tset/misc.c delete mode 100644 usr.bin/tset/set.c delete mode 100644 usr.bin/tset/term.c delete mode 100644 usr.bin/tset/tset.1 delete mode 100644 usr.bin/tset/tset.c delete mode 100644 usr.bin/tset/wrterm.c diff --git a/lib/ncurses/config.mk b/lib/ncurses/config.mk index f199c5829b6..7a64a7b948e 100644 --- a/lib/ncurses/config.mk +++ b/lib/ncurses/config.mk @@ -3,8 +3,11 @@ # This Makefile is shared by libncurses, libform, libmenu, libpanel. NCURSES_DIR= ${SRCTOP}/contrib/ncurses +NCURSES_MAJOR= 6 +NCURSES_MINOR= 2 +NCURSES_PATCH= 20200215 -CFLAGS+= -D_XOPEN_SOURCE_EXTENDED -DENABLE_WIDEC +CFLAGS+= -D_XOPEN_SOURCE_EXTENDED NCURSES_CFG_H= ${.CURDIR}/ncurses_cfg.h CFLAGS+= -I. @@ -41,5 +44,12 @@ MANFILTER= sed -e 's%@TERMINFO@%${TERMINFODIR}/terminfo%g' \ -e 's%@NCURSES_MAJOR@%${NCURSES_MAJOR}%g' \ -e 's%@NCURSES_MINOR@%${NCURSES_MINOR}%g' \ -e 's%@NCURSES_PATCH@%${NCURSES_PATCH}%g' \ + -e 's%@TSET@%tset%g' \ + -e 's%@RESET@%reset%g' \ + -e 's%@CLEAR@%clear%g' \ + -e 's%@TABS@%tabs%g' \ -e 's%@TIC@%tic%g' \ - -e 's%@INFOCMP@%infocmp%g' + -e 's%@TOE@%toe%g' \ + -e 's%@INFOCMP@%infocmp%g' \ + -e 's%@CAPTOINFO@%captoinfo%g' \ + -e 's%@INFOTOCAP@%infotocap%g' diff --git a/lib/ncurses/ncurses/Makefile b/lib/ncurses/ncurses/Makefile index 6f03d93a9ac..aff569a7984 100644 --- a/lib/ncurses/ncurses/Makefile +++ b/lib/ncurses/ncurses/Makefile @@ -216,6 +216,7 @@ SRCS+= \ obsolete.c \ parse_entry.c \ read_entry.c \ + read_termcap.c \ strings.c \ trim_sgr0.c \ write_entry.c @@ -270,14 +271,10 @@ DBGSRCS= \ trace_xnames.c \ varargs.c -# From our old libtermcap. -# Used instead of the hideous read_termcap.c abomination. -SRCS+= termcap.c - CLEANFILES= ${GENSRCS} ${GENHDRS} keys.list make_hash term.h.new \ make_keys MKterm.h.awk comp_captab.c curses.head -CFLAGS+= -DFREEBSD_NATIVE -DTERMIOS +CFLAGS+= -DTERMIOS # Installed HEADERS= curses.h term.h termcap.h unctrl.h @@ -416,7 +413,7 @@ make_hash: make_hash.c hashsize.h ncurses_def.h ${HEADERS} ${BUILD_TOOLS_META} MKterm.h.awk: MKterm.h.awk.in sed <${NCURSES_DIR}/include/MKterm.h.awk.in >$@ \ -e "/@BROKEN_LINKER@/s%%${BROKEN_LINKER}%" \ - -e "s%@NCURSES_USE_DATABASE@%0%g" \ + -e "s%@NCURSES_USE_DATABASE@%1%g" \ -e "s%@NCURSES_USE_TERMCAP@%1%g" \ -e "/@NCURSES_MAJOR@/s%%${NCURSES_MAJOR}%" \ -e "/@NCURSES_MINOR@/s%%${NCURSES_MINOR}%" \ diff --git a/lib/ncurses/ncurses/ncurses_cfg.h b/lib/ncurses/ncurses/ncurses_cfg.h index 0a92c2f23ba..49cef464b80 100644 --- a/lib/ncurses/ncurses/ncurses_cfg.h +++ b/lib/ncurses/ncurses/ncurses_cfg.h @@ -59,6 +59,8 @@ #define HAVE_LONG_FILE_NAMES 1 #define MIXEDCASE_FILENAMES 1 #define USE_SYSMOUSE 1 +#define TERMINFO_DIRS "/usr/share/terminfo:/usr/local/share/site-terminfo" +#define TERMINFO "/usr/share/terminfo" #define HAVE_BIG_CORE 1 #define TERMPATH "/etc/termcap:/usr/share/misc/termcap" #define USE_GETCAP 1 @@ -70,6 +72,23 @@ #define USE_LINKS 1 #define BSD_TPUTS 1 #define HAVE_LANGINFO_CODESET 1 +#define USE_WIDEC_SUPPORT 1 +#define NCURSES_WIDECHAR 1 +#define HAVE_WCHAR_H 1 +#define HAVE_WCTYPE_H 1 +#define HAVE_PUTWC 1 +#define HAVE_BTOWC 1 +#define HAVE_WCTOB 1 +#define HAVE_MBTOWC 1 +#define HAVE_WCTOMB 1 +#define HAVE_MBLEN 1 +#define HAVE_MBRLEN 1 +#define HAVE_MBRTOWC 1 +#define HAVE_WCSRTOMBS 1 +#define HAVE_MBSRTOWCS 1 +#define HAVE_WCSTOMBS 1 +#define HAVE_MBSTOWCS 1 +#define NEED_WCHAR_H 1 #define HAVE_FSEEKO 1 #define STDC_HEADERS 1 #define HAVE_SYS_TYPES_H 1 @@ -96,6 +115,10 @@ #define HAVE_WRESIZE 1 #define NCURSES_SP_FUNCS 1 #define HAVE_TPUTS_SP 1 +#define NCURSES_EXT_COLORS 1 +#define HAVE_ALLOC_PAIR 1 +#define HAVE_INIT_EXTENDED_COLOR 1 +#define HAVE_RESET_COLOR_PAIRS 1 #define NCURSES_EXT_PUTWIN 1 #define NCURSES_NO_PADDING 1 #define USE_SIGWINCH 1 @@ -133,6 +156,11 @@ #define HAVE_UNISTD_H 1 #define HAVE_GETOPT_H 1 #define HAVE_GETOPT_HEADER 1 +#define DECL_ENVIRON 1 +#define HAVE_ENVIRON 1 +#define HAVE_PUTENV 1 +#define HAVE_SETENV 1 +#define HAVE_STRDUP 1 #define HAVE_SYS_TIME_SELECT 1 #define SIG_ATOMIC_T volatile sig_atomic_t #define HAVE_ERRNO 1 @@ -153,6 +181,7 @@ #define HAVE_SETVBUF 1 #define HAVE_SIGACTION 1 #define HAVE_SIGVEC 1 +#define HAVE_SNPRINTF 1 #define HAVE_STRDUP 1 #define HAVE_STRSTR 1 #define HAVE_SYSCONF 1 @@ -181,11 +210,12 @@ #define USE_FOPEN_BIN_R 1 #define USE_OPENPTY_HEADER #define USE_XTERM_PTY 1 -#define USE_HASHED_DB 1 #define HAVE_TYPEINFO 1 #define HAVE_IOSTREAM 1 #define IOSTREAM_NAMESPACE 1 +#define SIZEOF_BOOL 1 #define CPP_HAS_STATIC_CAST 1 +#define SIZEOF_WCHAR_T 4 #define HAVE_SLK_COLOR 1 #define HAVE_PANEL_H 1 #define HAVE_LIBPANEL 1 @@ -198,37 +228,6 @@ #define NCURSES_OSPEED_COMPAT 1 #define HAVE_CURSES_DATA_BOOLNAMES 1 -/* - * Begin FreeBSD-specific changes - */ -/* Support ENABLE_WIDEC */ -#ifdef ENABLE_WIDEC -#define USE_WIDEC_SUPPORT 1 -#define NCURSES_WIDECHAR 1 -#define NCURSES_EXT_FUNCS 1 -#define NCURSES_EXT_COLORS 1 -#define HAVE_ALLOC_PAIR 1 -#define HAVE_INIT_EXTENDED_COLOR 1 -#define HAVE_RESET_COLOR_PAIRS 1 -#define HAVE_PUTWC 1 -#define HAVE_BTOWC 1 -#define HAVE_WCTOB 1 -#define HAVE_MBTOWC 1 -#define HAVE_WCTOMB 1 -#define HAVE_MBLEN 1 -#define HAVE_MBRLEN 1 -#define HAVE_MBRTOWC 1 -#define HAVE_WCSRTOMBS 1 -#define HAVE_MBSRTOWCS 1 -#define HAVE_WCSTOMBS 1 -#define HAVE_MBSTOWCS 1 -#define NEED_WCHAR_H 1 -#define SIZEOF_WCHAR_T 4 -#endif -/* - * End FreeBSD-specific changes - */ - #include /* The C compiler may not treat these properly but C++ has to */ diff --git a/lib/ncurses/ncurses/termcap.c b/lib/ncurses/ncurses/termcap.c deleted file mode 100644 index 535301a1b47..00000000000 --- a/lib/ncurses/ncurses/termcap.c +++ /dev/null @@ -1,266 +0,0 @@ -/* A portion of this file is from ncurses: */ -/*************************************************************************** -* COPYRIGHT NOTICE * -**************************************************************************** -* ncurses is copyright (C) 1992-1995 * -* Zeyd M. Ben-Halim * -* zmbenhal@netcom.com * -* Eric S. Raymond * -* esr@snark.thyrsus.com * -* * -* Permission is hereby granted to reproduce and distribute ncurses * -* by any means and for any fee, whether alone or as part of a * -* larger distribution, in source or in binary form, PROVIDED * -* this notice is included with any such distribution, and is not * -* removed from any of its header files. Mention of ncurses in any * -* applications linked with it is highly appreciated. * -* * -* ncurses comes AS IS with no warranty, implied or expressed. * -* * -***************************************************************************/ - -#include - -#include -#include -#include -#include - -/* The rest is from BSD */ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1980, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -__FBSDID("$FreeBSD$"); - -#if 0 -#ifndef lint -static const char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93"; -#endif /* not lint */ -#endif - -#include -#include -#include -#include -#include -#include -#include "pathnames.h" - -#define PBUFSIZ MAXPATHLEN /* max length of filename path */ -#define PVECSIZ 32 /* max number of names in path */ -#define TBUFSIZ 1024 /* max length of _nc_tgetent buffer */ - -char _nc_termcap[TBUFSIZ + 1]; /* Last getcap, provided to tgetent() emul */ - -/* - * termcap - routines for dealing with the terminal capability data base - * - * BUG: Should use a "last" pointer in tbuf, so that searching - * for capabilities alphabetically would not be a n**2/2 - * process when large numbers of capabilities are given. - * Note: If we add a last pointer now we will screw up the - * tc capability. We really should compile termcap. - * - * Essentially all the work here is scanning and decoding escapes - * in string capabilities. We don't use stdio because the editor - * doesn't, and because living w/o it is not hard. - */ - -/* - * Get an entry for terminal name in buffer _nc_termcap from the termcap - * file. - */ -int -_nc_read_termcap_entry(const char *const name, TERMTYPE2 *const tp) -{ - ENTRY *ep; - char *p; - char *cp; - char *dummy; - char **fname; - char *home; - int i; - char pathbuf[PBUFSIZ]; /* holds raw path of filenames */ - char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ - char **pvec; /* holds usable tail of path vector */ - char *termpath; - - _nc_termcap[0] = '\0'; /* in case */ - dummy = NULL; - fname = pathvec; - pvec = pathvec; - p = pathbuf; - cp = getenv("TERMCAP"); - /* - * TERMCAP can have one of two things in it. It can be the - * name of a file to use instead of /etc/termcap. In this - * case it better start with a "/". Or it can be an entry to - * use so we don't have to read the file. In this case it - * has to already have the newlines crunched out. If TERMCAP - * does not hold a file name then a path of names is searched - * instead. The path is found in the TERMPATH variable, or - * becomes "$HOME/.termcap /etc/termcap" if no TERMPATH exists. - */ - if (!cp || *cp != '/') { /* no TERMCAP or it holds an entry */ - if ( (termpath = getenv("TERMPATH")) ) - strncpy(pathbuf, termpath, PBUFSIZ); - else { - if ( (home = getenv("HOME")) ) {/* set up default */ - strncpy(pathbuf, home, PBUFSIZ - 1); /* $HOME first */ - pathbuf[PBUFSIZ - 2] = '\0'; /* -2 because we add a slash */ - p += strlen(pathbuf); /* path, looking in */ - *p++ = '/'; - } /* if no $HOME look in current directory */ - strncpy(p, _PATH_DEF, PBUFSIZ - (p - pathbuf)); - } - } - else /* user-defined name in TERMCAP */ - strncpy(pathbuf, cp, PBUFSIZ); /* still can be tokenized */ - - /* For safety */ - if (issetugid()) - strcpy(pathbuf, _PATH_DEF_SEC); - - pathbuf[PBUFSIZ - 1] = '\0'; - - *fname++ = pathbuf; /* tokenize path into vector of names */ - while (*++p) - if (*p == ' ' || *p == ':') { - *p = '\0'; - while (*++p) - if (*p != ' ' && *p != ':') - break; - if (*p == '\0') - break; - *fname++ = p; - if (fname >= pathvec + PVECSIZ) { - fname--; - break; - } - } - *fname = (char *) 0; /* mark end of vector */ - if (cp && *cp && *cp != '/') - if (cgetset(cp) < 0) - return(-2); - - i = cgetent(&dummy, pathvec, (char *)name); - - if (i == 0) { - char *pd, *ps, *tok, *s, *tcs; - size_t len; - - pd = _nc_termcap; - ps = dummy; - if ((tok = strchr(ps, ':')) == NULL) { - len = strlen(ps); - if (len >= TBUFSIZ) - i = -1; - else - strcpy(pd, ps); - goto done; - } - len = tok - ps + 1; - if (pd + len + 1 - _nc_termcap >= TBUFSIZ) { - i = -1; - goto done; - } - memcpy(pd, ps, len); - ps += len; - pd += len; - *pd = '\0'; - tcs = pd - 1; - for (;;) { - while ((tok = strsep(&ps, ":")) != NULL && - *(tok - 2) != '\\' && - (*tok == '\0' || *tok == '\\' || !isgraph(UChar(*tok)))) - ; - if (tok == NULL) - break; - for (s = tcs; s != NULL && s[1] != '\0'; - s = strchr(s, ':')) { - s++; - if (s[0] == tok[0] && s[1] == tok[1]) - goto skip_it; - } - len = strlen(tok); - if (pd + len + 1 - _nc_termcap >= TBUFSIZ) { - i = -1; - break; - } - memcpy(pd, tok, len); - pd += len; - *pd++ = ':'; - *pd = '\0'; - skip_it: ; - } - } -done: - if (dummy) - free(dummy); - - -/* - * From here on is ncurses-specific glue code - */ - - if (i < 0) - return(TGETENT_ERR); - - _nc_set_source("TERMCAP"); - _nc_read_entry_source((FILE *)NULL, _nc_termcap, FALSE, TRUE, NULLHOOK); - - if (_nc_head == (ENTRY *)NULL) - return(TGETENT_ERR); - - /* resolve all use references */ - _nc_resolve_uses2(TRUE, FALSE); - - for_entry_list(ep) - if (_nc_name_match(ep->tterm.term_names, name, "|:")) - { - /* - * Make a local copy of the terminal capabilities, delinked - * from the list. - */ - memcpy(tp, &ep->tterm, sizeof(TERMTYPE)); - _nc_delink_entry(_nc_head, &(ep->tterm)); - free(ep); - _nc_free_entries(_nc_head); - _nc_head = _nc_tail = NULL; /* do not reuse! */ - - return TGETENT_YES; /* OK */ - } - - _nc_free_entries(_nc_head); - _nc_head = _nc_tail = NULL; /* do not reuse! */ - return(TGETENT_NO); /* not found */ -} diff --git a/share/mk/src.tools.mk b/share/mk/src.tools.mk index 722734bbfc1..5e3b7048409 100644 --- a/share/mk/src.tools.mk +++ b/share/mk/src.tools.mk @@ -20,6 +20,7 @@ MTREE_CMD?= mtree PWD_MKDB_CMD?= pwd_mkdb SERVICES_MKDB_CMD?= services_mkdb CAP_MKDB_CMD?= cap_mkdb +TIC_CMD?= tic ____: .endif # !target(____) diff --git a/usr.bin/Makefile b/usr.bin/Makefile index fcc406d2efc..3e71dbb30e6 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -97,6 +97,7 @@ SUBDIR= alias \ mkuzip \ mt \ ncal \ + ncurses \ netstat \ newgrp \ nfsstat \ @@ -146,7 +147,6 @@ SUBDIR= alias \ strings \ su \ systat \ - tabs \ tail \ tar \ tcopy \ @@ -156,11 +156,9 @@ SUBDIR= alias \ tip \ top \ touch \ - tput \ tr \ true \ truncate \ - tset \ tsort \ tty \ uname \ diff --git a/usr.bin/ncurses/Makefile b/usr.bin/ncurses/Makefile new file mode 100644 index 00000000000..cd8344aa1a9 --- /dev/null +++ b/usr.bin/ncurses/Makefile @@ -0,0 +1,40 @@ +PACKAGE= runtime + +.include +.include "${SRCTOP}/lib/ncurses/config.mk" + +.PATH: ${NCURSES_DIR}/progs ${NCURSES_DIR}/man + +PROGS= tic tput infocmp toe tabs clear tset +SRCS.tic= tic.c transform.c dump_entry.c tparm_type.c +SRCS.tput= tput.c tparm_type.c transform.c dump_entry.c clear_cmd.c reset_cmd.c \ + tty_settings.c +SRCS.infocmp= infocmp.c dump_entry.c +SRCS.tabs= tabs.c tty_settings.c +SRCS.clear= clear.c clear_cmd.c tty_settings.c +SRCS.tset= tset.c tty_settings.c transform.c reset_cmd.c +CFLAGS+= -I${NCURSES_DIR}/progs \ + -I${NCURSES_DIR}/include \ + -I${SRCTOP}/lib/ncurses/ncurses \ + -I${OBJTOP}/lib/ncurses/ncurses \ + -I${.CURDIR} +LIBADD= ncursesw +CLEANFILES= termsort.c + +termsort.c: MKtermsort.sh + sh ${NCURSES_DIR}/progs/MKtermsort.sh ${AWK} ${NCURSES_DIR}/include/Caps > ${.TARGET} +dump_entry.c: termsort.c + +LINKS.tic= ${BINDIR}/tic ${BINDIR}/captoinfo \ + ${BINDIR}/tic ${BINDIR}/infotocap +LINKS.tset= ${BINDIR}/tset ${BINDIR}/reset + +MLINKS.tic= tic.1 captoinfo.1 \ + tic.1 infotocap.1 +MLINKS.tset= tset.1 reset.1 + +.include + +.SUFFIXES: .1 .1m +.1m.1: + cat ${.IMPSRC} > ${.TARGET} diff --git a/usr.bin/ncurses/transform.h b/usr.bin/ncurses/transform.h new file mode 100644 index 00000000000..ec255c05c4d --- /dev/null +++ b/usr.bin/ncurses/transform.h @@ -0,0 +1,10 @@ +#ifndef __TRANSFORM_H +#define __TRANSFORM_H 1 +#include +extern bool same_program(const char *, const char *); +#define PROG_CAPTOINFO "captoinfo" +#define PROG_INFOTOCAP "infotocap" +#define PROG_CLEAR "clear" +#define PROG_RESET "reset" +#define PROG_INIT "init" +#endif /* __TRANSFORM_H */ diff --git a/usr.bin/tput/Makefile b/usr.bin/tput/Makefile deleted file mode 100644 index d3171dab7ef..00000000000 --- a/usr.bin/tput/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/6/93 -# $FreeBSD$ - -PROG= tput -LIBADD= ncursesw -SCRIPTS=clear.sh -MLINKS= tput.1 clear.1 - -.include diff --git a/usr.bin/tput/Makefile.depend b/usr.bin/tput/Makefile.depend deleted file mode 100644 index 9b2a343de2d..00000000000 --- a/usr.bin/tput/Makefile.depend +++ /dev/null @@ -1,18 +0,0 @@ -# $FreeBSD$ -# Autogenerated - do NOT edit! - -DIRDEPS = \ - gnu/lib/csu \ - include \ - include/xlocale \ - lib/${CSU_DIR} \ - lib/libc \ - lib/libcompiler_rt \ - lib/ncurses/ncursesw \ - - -.include - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif diff --git a/usr.bin/tput/clear.sh b/usr.bin/tput/clear.sh deleted file mode 100644 index 2c6e093e10c..00000000000 --- a/usr.bin/tput/clear.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -# -# SPDX-License-Identifier: BSD-3-Clause -# -# Copyright (c) 1989, 1993 -# The Regents of the University of California. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. Neither the name of the University nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. -# -# $FreeBSD$ -# -# @(#)clear.sh 8.1 (Berkeley) 6/6/93 -# - -exec tput clear diff --git a/usr.bin/tput/tput.1 b/usr.bin/tput/tput.1 deleted file mode 100644 index 996575bb622..00000000000 --- a/usr.bin/tput/tput.1 +++ /dev/null @@ -1,179 +0,0 @@ -.\" Copyright (c) 1989, 1990, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)tput.1 8.2 (Berkeley) 3/19/94 -.\" $FreeBSD$ -.\" -.Dd June 15, 2002 -.Dt TPUT 1 -.Os -.Sh NAME -.Nm tput , -.Nm clear -.Nd terminal capability interface -.Sh SYNOPSIS -.Nm -.Op Fl T Ar term -.Op Ar attribute ... -.Nm clear -.Sh DESCRIPTION -The -.Nm -utility makes terminal-dependent information available to users or shell -applications. -.Pp -The -.Nm clear -utility executes the -.Dl tput clear -command, ignoring any arguments. -.Pp -The only option to -.Nm -is: -.Bl -tag -width 2n -.It Fl T -The terminal name as specified in the -.Xr termcap 5 -database, for example, -.Dq vt100 -or -.Dq xterm . -If not specified, -.Nm -retrieves the -.Dq Ev TERM -variable from the environment unless that too is not specified, -in which case an error message will be sent to standard error and -the error status will be 2. -.El -.Pp -The -.Nm -utility outputs a string for each -.Ar attribute -that is of type string; a number for each of type integer. -Otherwise, -.Nm -exits 0 if the terminal has the capability and 1 if it does not, -without further action. -.Pp -If an -.Ar attribute -is of type string, and takes arguments (e.g.\& cursor movement, -the termcap -.Dq cm -capability) the arguments are taken from the command line immediately -following the attribute. -.Pp -The following special attributes are available. -The first three use the capabilities of the specified terminal, -and only work if compatible with the utility's terminal. -.Bl -tag -width Ar -.It Cm clear -Clear the screen (the -.Xr termcap 5 -.Dq cl -capability). -.It Cm init -Initialize the terminal (the -.Xr termcap 5 -.Dq is -capability). -.It Cm reset -Reset the terminal (the -.Xr termcap 5 -.Dq rs -capability). -.It Cm longname -Print the descriptive name of the user's terminal type. -.El -.Sh ENVIRONMENT -.Bl -tag -width ".Ev TERM" -.It Ev TERM -The terminal name, if set and -.Fl T -is not used. -.El -.Sh EXIT STATUS -The exit status of -.Nm -is as follows: -.Bl -tag -width indent -.It 0 -If the last -.Ar attribute -is of type string or integer, its value was successfully written -to standard output. -If the -.Ar attribute -is of type boolean, the terminal does have the -.Ar attribute . -Otherwise, no -.Ar attribute -was specified. -.It 1 -If the last -.Ar attribute -is of type boolean, -this terminal does not have the -.Ar attribute . -.It 2 -Usage error. -For example, see -.Fl T -description. -.It 3 -No information is available about the specified terminal type. -.El -.Sh SEE ALSO -.Xr termcap 5 , -.Xr terminfo 5 -.Sh STANDARDS -The -.Nm -utility conforms to -.St -p1003.1-2001 . -.Sh HISTORY -The -.Nm -utility appeared in -.Bx 4.4 . -.Sh BUGS -The -.Nm -utility cannot really distinguish between different types of attributes. -.Pp -Some termcap entries depend upon having a -.Sq % -in them that is just a -.Sq % -and nothing more. -Right now we just warn about them if they do not -have a valid type declaration. -These warnings are sent to -stderr. diff --git a/usr.bin/tput/tput.c b/usr.bin/tput/tput.c deleted file mode 100644 index 8f678f61b1a..00000000000 --- a/usr.bin/tput/tput.c +++ /dev/null @@ -1,214 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1980, 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -__FBSDID("$FreeBSD$"); - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1980, 1988, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif - -#ifndef lint -static const char sccsid[] = "@(#)tput.c 8.2 (Berkeley) 3/19/94"; -#endif - -#include - -#include -#include -#include -#include -#include -#include - -#undef putchar -#define outc putchar - -static void prlongname(char *); -static void usage(void); -static char **process(const char *, char *, char **); - -int -main(int argc, char **argv) -{ - int ch, exitval, n; - char *cptr, *term, buf[1024], tbuf[1024]; - const char *p; - - term = NULL; - while ((ch = getopt(argc, argv, "T:")) != -1) - switch(ch) { - case 'T': - term = optarg; - break; - case '?': - default: - usage(); - } - argc -= optind; - argv += optind; - - if (argc < 1) - usage(); - - if (!term && !(term = getenv("TERM"))) -errx(2, "no terminal type specified and no TERM environmental variable."); - if (tgetent(tbuf, term) != 1) - err(3, "tgetent failure"); - for (exitval = 0; (p = *argv) != NULL; ++argv) { - switch (*p) { - case 'c': - if (!strcmp(p, "clear")) - p = "cl"; - break; - case 'i': - if (!strcmp(p, "init")) - p = "is"; - break; - case 'l': - if (!strcmp(p, "longname")) { - prlongname(tbuf); - continue; - } - break; - case 'r': - if (!strcmp(p, "reset")) - p = "rs"; - break; - } - cptr = buf; - if (tgetstr(p, &cptr)) - argv = process(p, buf, argv); - else if ((n = tgetnum(p)) != -1) - (void)printf("%d\n", n); - else - exitval = !tgetflag(p); - } - exit(exitval); -} - -static void -prlongname(char *buf) -{ - int savech; - char *p, *savep; - - for (p = buf; *p && *p != ':'; ++p); - savech = *(savep = p); - for (*p = '\0'; p >= buf && *p != '|'; --p); - (void)printf("%s\n", p + 1); - *savep = savech; -} - -static char ** -process(const char *cap, char *str, char **argv) -{ - static const char errfew[] = - "not enough arguments (%d) for capability `%s'"; - static const char errmany[] = - "too many arguments (%d) for capability `%s'"; - static const char erresc[] = - "unknown %% escape `%c' for capability `%s'"; - char *cp; - int arg_need, arg_rows, arg_cols; - - /* Count how many values we need for this capability. */ - for (cp = str, arg_need = 0; *cp != '\0'; cp++) - if (*cp == '%') - switch (*++cp) { - case 'd': - case '2': - case '3': - case '.': - case '+': - arg_need++; - break; - case '%': - case '>': - case 'i': - case 'r': - case 'n': - case 'B': - case 'D': - break; - case 'p': - if (cp[1]) { - cp++; - break; - } - default: - /* - * hpux has lot's of them, but we complain - */ - warnx(erresc, *cp, cap); - } - - /* And print them. */ - switch (arg_need) { - case 0: - (void)tputs(str, 1, outc); - break; - case 1: - arg_cols = 0; - - if (*++argv == NULL || *argv[0] == '\0') - errx(2, errfew, 1, cap); - arg_rows = atoi(*argv); - - (void)tputs(tgoto(str, arg_cols, arg_rows), 1, outc); - break; - case 2: - if (*++argv == NULL || *argv[0] == '\0') - errx(2, errfew, 2, cap); - arg_cols = atoi(*argv); - - if (*++argv == NULL || *argv[0] == '\0') - errx(2, errfew, 2, cap); - arg_rows = atoi(*argv); - - (void) tputs(tgoto(str, arg_cols, arg_rows), arg_rows, outc); - break; - - default: - errx(2, errmany, arg_need, cap); - } - return (argv); -} - -static void -usage(void) -{ - (void)fprintf(stderr, "usage: tput [-T term] attribute ...\n"); - exit(2); -} diff --git a/usr.bin/tset/Makefile b/usr.bin/tset/Makefile deleted file mode 100644 index acf83349542..00000000000 --- a/usr.bin/tset/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -# @(#)Makefile 8.1 (Berkeley) 6/9/93 -# $FreeBSD$ - -PROG= tset -SRCS= map.c misc.c set.c term.c tset.c wrterm.c - -LIBADD= ncursesw -LINKS= ${BINDIR}/tset ${BINDIR}/reset -MLINKS= tset.1 reset.1 - -.include diff --git a/usr.bin/tset/Makefile.depend b/usr.bin/tset/Makefile.depend deleted file mode 100644 index 9b2a343de2d..00000000000 --- a/usr.bin/tset/Makefile.depend +++ /dev/null @@ -1,18 +0,0 @@ -# $FreeBSD$ -# Autogenerated - do NOT edit! - -DIRDEPS = \ - gnu/lib/csu \ - include \ - include/xlocale \ - lib/${CSU_DIR} \ - lib/libc \ - lib/libcompiler_rt \ - lib/ncurses/ncursesw \ - - -.include - -.if ${DEP_RELDIR} == ${_DEP_RELDIR} -# local dependencies - needed for -jN in clean tree -.endif diff --git a/usr.bin/tset/extern.h b/usr.bin/tset/extern.h deleted file mode 100644 index 79fee1be050..00000000000 --- a/usr.bin/tset/extern.h +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)extern.h 8.1 (Berkeley) 6/9/93 - * $FreeBSD$ - */ - -#include - -extern struct termios mode, oldmode; -extern int Columns, isreset, Lines; -extern int erasech, intrchar, killch; -extern speed_t Ospeed; - -void add_mapping(const char *, char *); -void cat(char *); -const char *get_termcap_entry(char *, char **); -const char *mapped(const char *); -int outc(int); -void reset_mode(void); -void set_control_chars(void); -void set_conversions(int); -void set_init(void); -void wrtermcap(char *); diff --git a/usr.bin/tset/map.c b/usr.bin/tset/map.c deleted file mode 100644 index 4fa6d859f05..00000000000 --- a/usr.bin/tset/map.c +++ /dev/null @@ -1,254 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -__FBSDID("$FreeBSD$"); - -#ifndef lint -static const char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/9/93"; -#endif - -#include - -#include -#include -#include -#include - -#include "extern.h" - -static speed_t tset_baudrate(char *); - -/* Baud rate conditionals for mapping. */ -#define GT 0x01 -#define EQ 0x02 -#define LT 0x04 -#define NOT 0x08 -#define GE (GT | EQ) -#define LE (LT | EQ) - -typedef struct map { - struct map *next; /* Linked list of maps. */ - char *porttype; /* Port type, or "" for any. */ - char *type; /* Terminal type to select. */ - int conditional; /* Baud rate conditionals bitmask. */ - speed_t speed; /* Baud rate to compare against. */ -} MAP; - -static MAP *cur, *maplist; - -/* - * Syntax for -m: - * [port-type][test baudrate]:terminal-type - * The baud rate tests are: >, <, @, =, ! - */ -void -add_mapping(const char *port, char *arg) -{ - MAP *mapp; - char *copy, *p, *termp; - - copy = strdup(arg); - mapp = malloc(sizeof(MAP)); - if (copy == NULL || mapp == NULL) - errx(1, "malloc"); - mapp->next = NULL; - if (maplist == NULL) - cur = maplist = mapp; - else { - cur->next = mapp; - cur = mapp; - } - - mapp->porttype = arg; - mapp->conditional = 0; - - arg = strpbrk(arg, "><@=!:"); - - if (arg == NULL) { /* [?]term */ - mapp->type = mapp->porttype; - mapp->porttype = NULL; - goto done; - } - - if (arg == mapp->porttype) /* [><@=! baud]:term */ - termp = mapp->porttype = NULL; - else - termp = arg; - - for (;; ++arg) /* Optional conditionals. */ - switch(*arg) { - case '<': - if (mapp->conditional & GT) - goto badmopt; - mapp->conditional |= LT; - break; - case '>': - if (mapp->conditional & LT) - goto badmopt; - mapp->conditional |= GT; - break; - case '@': - case '=': /* Not documented. */ - mapp->conditional |= EQ; - break; - case '!': - mapp->conditional |= NOT; - break; - default: - goto next; - } - -next: if (*arg == ':') { - if (mapp->conditional) - goto badmopt; - ++arg; - } else { /* Optional baudrate. */ - arg = strchr(p = arg, ':'); - if (arg == NULL) - goto badmopt; - *arg++ = '\0'; - mapp->speed = tset_baudrate(p); - } - - if (*arg == '\0') /* Non-optional type. */ - goto badmopt; - - mapp->type = arg; - - /* Terminate porttype, if specified. */ - if (termp != NULL) - *termp = '\0'; - - /* If a NOT conditional, reverse the test. */ - if (mapp->conditional & NOT) - mapp->conditional = ~mapp->conditional & (EQ | GT | LT); - - /* If user specified a port with an option flag, set it. */ -done: if (port) { - if (mapp->porttype) -badmopt: errx(1, "illegal -m option format: %s", copy); - mapp->porttype = strdup(port); - } - free(copy); - -#ifdef MAPDEBUG - (void)printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY"); - (void)printf("type: %s\n", mapp->type); - (void)printf("conditional: "); - p = ""; - if (mapp->conditional & GT) { - (void)printf("GT"); - p = "/"; - } - if (mapp->conditional & EQ) { - (void)printf("%sEQ", p); - p = "/"; - } - if (mapp->conditional & LT) - (void)printf("%sLT", p); - (void)printf("\nspeed: %d\n", mapp->speed); -#endif -} - -/* - * Return the type of terminal to use for a port of type 'type', as specified - * by the first applicable mapping in 'map'. If no mappings apply, return - * 'type'. - */ -const char * -mapped(const char *type) -{ - MAP *mapp; - int match; - - match = 0; - for (mapp = maplist; mapp; mapp = mapp->next) - if (mapp->porttype == NULL || !strcmp(mapp->porttype, type)) { - switch (mapp->conditional) { - case 0: /* No test specified. */ - match = 1; - break; - case EQ: - match = (Ospeed == mapp->speed); - break; - case GE: - match = (Ospeed >= mapp->speed); - break; - case GT: - match = (Ospeed > mapp->speed); - break; - case LE: - match = (Ospeed <= mapp->speed); - break; - case LT: - match = (Ospeed < mapp->speed); - break; - } - if (match) - return (mapp->type); - } - /* No match found; return given type. */ - return (type); -} - -typedef struct speeds { - const char *string; - speed_t speed; -} SPEEDS; - -static SPEEDS speeds[] = { - { "0", B0 }, - { "134.5", B134 }, - { "exta", B19200 }, - { "extb", B38400 }, - { NULL, 0 } -}; - -static speed_t -tset_baudrate(char *rate) -{ - SPEEDS *sp; - speed_t speed; - - /* The baudrate number can be preceded by a 'B', which is ignored. */ - if (*rate == 'B') - ++rate; - - for (sp = speeds; sp->string; ++sp) - if (!strcasecmp(rate, sp->string)) - return (sp->speed); - speed = atol(rate); - if (speed == 0) - errx(1, "unknown baud rate %s", rate); - return speed; -} diff --git a/usr.bin/tset/misc.c b/usr.bin/tset/misc.c deleted file mode 100644 index 737fde9dc13..00000000000 --- a/usr.bin/tset/misc.c +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -__FBSDID("$FreeBSD$"); - -#ifndef lint -static const char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/9/93"; -#endif - -#include -#include -#include -#include - -#include "extern.h" - -void -cat(char *file) -{ - register int fd, nr, nw; - char buf[1024]; - - if ((fd = open(file, O_RDONLY, 0)) < 0) - err(1, "%s", file); - - while ((nr = read(fd, buf, sizeof(buf))) > 0) - if ((nw = write(STDERR_FILENO, buf, nr)) == -1) - err(1, "write to stderr"); - if (nr != 0) - err(1, "%s", file); - (void)close(fd); -} - -int -outc(int c) -{ - return putc(c, stderr); -} diff --git a/usr.bin/tset/set.c b/usr.bin/tset/set.c deleted file mode 100644 index df204cebeeb..00000000000 --- a/usr.bin/tset/set.c +++ /dev/null @@ -1,324 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -__FBSDID("$FreeBSD$"); - -#ifndef lint -static const char sccsid[] = "@(#)set.c 8.2 (Berkeley) 2/28/94"; -#endif - -#include -#include -#include -#include - -#include "extern.h" - -#define CHK(val, dft) (val <= 0 ? dft : val) - -int set_tabs(void); - -/* - * Reset the terminal mode bits to a sensible state. Very useful after - * a child program dies in raw mode. - */ -void -reset_mode(void) -{ - tcgetattr(STDERR_FILENO, &mode); - -#if defined(VDISCARD) && defined(CDISCARD) - mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD); -#endif - mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF); - mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE); -#if defined(VFLUSH) && defined(CFLUSH) - mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH); -#endif - mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR); - mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL); -#if defined(VLNEXT) && defined(CLNEXT) - mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT); -#endif - mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT); -#if defined(VREPRINT) && defined(CRPRNT) - mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT); -#endif - mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART); - mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP); - mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP); -#if defined(VWERASE) && defined(CWERASE) - mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE); -#endif - - mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR -#ifdef IUCLC - | IUCLC -#endif -#ifdef IXANY - | IXANY -#endif - | IXOFF); - - mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON -#ifdef IMAXBEL - | IMAXBEL -#endif - ); - - mode.c_oflag &= ~(0 -#ifdef OLCUC - | OLCUC -#endif -#ifdef OCRNL - | OCRNL -#endif -#ifdef ONOCR - | ONOCR -#endif -#ifdef ONLRET - | ONLRET -#endif -#ifdef OFILL - | OFILL -#endif -#ifdef OFDEL - | OFDEL -#endif -#ifdef NLDLY - | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY -#endif - ); - - mode.c_oflag |= (OPOST -#ifdef ONLCR - | ONLCR -#endif - ); - - mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL); - mode.c_cflag |= (CS8 | CREAD); - mode.c_lflag &= ~(ECHONL | NOFLSH | TOSTOP -#ifdef ECHOPTR - | ECHOPRT -#endif -#ifdef XCASE - | XCASE -#endif - ); - - mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK -#ifdef ECHOCTL - | ECHOCTL -#endif -#ifdef ECHOKE - | ECHOKE -#endif - ); - - tcsetattr(STDERR_FILENO, TCSADRAIN, &mode); -} - -/* - * Determine the erase, interrupt, and kill characters from the termcap - * entry and command line and update their values in 'mode'. - */ -void -set_control_chars(void) -{ - char *bp, *p, bs_char, buf[1024]; - - bp = buf; - p = tgetstr("kb", &bp); - if (p == NULL || p[1] != '\0') - p = tgetstr("bc", &bp); - if (p != NULL && p[1] == '\0') - bs_char = p[0]; - else if (tgetflag("bs")) - bs_char = CTRL('h'); - else - bs_char = 0; - - if (erasech == 0 && bs_char != 0 && !tgetflag("os")) - erasech = -1; - if (erasech < 0) - erasech = (bs_char != 0) ? bs_char : CTRL('h'); - - if (mode.c_cc[VERASE] == 0 || erasech != 0) - mode.c_cc[VERASE] = erasech ? erasech : CERASE; - - if (mode.c_cc[VINTR] == 0 || intrchar != 0) - mode.c_cc[VINTR] = intrchar ? intrchar : CINTR; - - if (mode.c_cc[VKILL] == 0 || killch != 0) - mode.c_cc[VKILL] = killch ? killch : CKILL; -} - -/* - * Set up various conversions in 'mode', including parity, tabs, returns, - * echo, and case, according to the termcap entry. If the program we're - * running was named with a leading upper-case character, map external - * uppercase to internal lowercase. - */ -void -set_conversions(int usingupper) -{ - if (tgetflag("UC") || usingupper) { -#ifdef IUCLC - mode.c_iflag |= IUCLC; - mode.c_oflag |= OLCUC; -#endif - } else if (tgetflag("LC")) { -#ifdef IUCLC - mode.c_iflag &= ~IUCLC; - mode.c_oflag &= ~OLCUC; -#endif - } - mode.c_iflag &= ~(PARMRK | INPCK); - mode.c_lflag |= ICANON; - if (tgetflag("EP")) { - mode.c_cflag |= PARENB; - mode.c_cflag &= ~PARODD; - } - if (tgetflag("OP")) { - mode.c_cflag |= PARENB; - mode.c_cflag |= PARODD; - } - -#ifdef ONLCR - mode.c_oflag |= ONLCR; -#endif - mode.c_iflag |= ICRNL; - mode.c_lflag |= ECHO; - mode.c_oflag |= OXTABS; - if (tgetflag("NL")) { /* Newline, not linefeed. */ -#ifdef ONLCR - mode.c_oflag &= ~ONLCR; -#endif - mode.c_iflag &= ~ICRNL; - } - if (tgetflag("HD")) /* Half duplex. */ - mode.c_lflag &= ~ECHO; - if (tgetflag("pt")) /* Print tabs. */ - mode.c_oflag &= ~OXTABS; - mode.c_lflag |= (ECHOE | ECHOK); -} - -/* Output startup string. */ -void -set_init(void) -{ - char *bp, buf[1024]; - int settle; - - bp = buf; - if (tgetstr("pc", &bp) != 0) /* Get/set pad character. */ - PC = buf[0]; - -#ifdef TAB3 - if (oldmode.c_oflag & (TAB3 | ONLCR | OCRNL | ONLRET)) { - oldmode.c_oflag &= (TAB3 | ONLCR | OCRNL | ONLRET); - tcsetattr(STDERR_FILENO, TCSADRAIN, &oldmode); - } -#endif - settle = set_tabs(); - - if (isreset) { - bp = buf; - if (tgetstr("rs", &bp) != 0 || tgetstr("is", &bp) != 0) { - tputs(buf, 0, outc); - settle = 1; - } - bp = buf; - if (tgetstr("rf", &bp) != 0 || tgetstr("if", &bp) != 0) { - cat(buf); - settle = 1; - } - } - - if (settle) { - (void)putc('\r', stderr); - (void)fflush(stderr); - (void)sleep(1); /* Settle the terminal. */ - } -} - -/* - * Set the hardware tabs on the terminal, using the ct (clear all tabs), - * st (set one tab) and ch (horizontal cursor addressing) capabilities. - * This is done before if and is, so they can patch in case we blow this. - * Return nonzero if we set any tab stops, zero if not. - */ -int -set_tabs(void) -{ - int c; - char *capsp, *clear_tabs; - char *set_column, *set_pos, *Set_tab; - char caps[1024]; - const char *tg_out; - - capsp = caps; - Set_tab = tgetstr("st", &capsp); - - if (Set_tab && (clear_tabs = tgetstr("ct", &capsp))) { - (void)putc('\r', stderr); /* Force to left margin. */ - tputs(clear_tabs, 0, outc); - } - - set_column = tgetstr("ch", &capsp); - set_pos = set_column ? NULL : tgetstr("cm", &capsp); - - if (Set_tab) { - for (c = 8; c < Columns; c += 8) { - /* - * Get to the right column. "OOPS" is returned by - * tgoto() if it can't do the job. (*snarl*) - */ - tg_out = "OOPS"; - if (set_column) - tg_out = tgoto(set_column, 0, c); - if (*tg_out == 'O' && set_pos) - tg_out = tgoto(set_pos, c, Lines - 1); - if (*tg_out != 'O') - tputs(tg_out, 1, outc); - else - (void)fprintf(stderr, "%s", " "); - /* Set the tab. */ - tputs(Set_tab, 0, outc); - } - putc('\r', stderr); - return (1); - } - return (0); -} diff --git a/usr.bin/tset/term.c b/usr.bin/tset/term.c deleted file mode 100644 index 1c0196b1473..00000000000 --- a/usr.bin/tset/term.c +++ /dev/null @@ -1,158 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -__FBSDID("$FreeBSD$"); - -#ifndef lint -static const char sccsid[] = "@(#)term.c 8.1 (Berkeley) 6/9/93"; -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "extern.h" - -static char tbuf[1024]; /* Termcap entry. */ - -const char *askuser(const char *); -char *ttys(char *); - -/* - * Figure out what kind of terminal we're dealing with, and then read in - * its termcap entry. - */ -const char * -get_termcap_entry(char *userarg, char **tcapbufp) -{ - struct ttyent *t; - int rval; - char *p, *ttypath; - const char *ttype; - - if (userarg) { - ttype = userarg; - goto found; - } - - /* Try the environment. */ - if ((ttype = getenv("TERM"))) - goto map; - - /* Try ttyname(3); check for dialup or other mapping. */ - if ((ttypath = ttyname(STDERR_FILENO))) { - if ((p = strrchr(ttypath, '/'))) - ++p; - else - p = ttypath; - if ((t = getttynam(p))) { - ttype = t->ty_type; - goto map; - } - } - - /* If still undefined, use "unknown". */ - ttype = "unknown"; - -map: ttype = mapped(ttype); - - /* - * If not a path, remove TERMCAP from the environment so we get a - * real entry from /etc/termcap. This prevents us from being fooled - * by out of date stuff in the environment. - */ -found: if ((p = getenv("TERMCAP")) != NULL && *p != '/') - unsetenv("TERMCAP"); - - /* - * ttype now contains a pointer to the type of the terminal. - * If the first character is '?', ask the user. - */ - if (ttype[0] == '?') { - if (ttype[1] != '\0') - ttype = askuser(ttype + 1); - else - ttype = askuser(NULL); - } - - /* Find the termcap entry. If it doesn't exist, ask the user. */ - while ((rval = tgetent(tbuf, ttype)) == 0) { - warnx("terminal type %s is unknown", ttype); - ttype = askuser(NULL); - } - if (rval == -1) - errx(1, "termcap: %s", strerror(errno ? errno : ENOENT)); - *tcapbufp = tbuf; - return (ttype); -} - -/* Prompt the user for a terminal type. */ -const char * -askuser(const char *dflt) -{ - static char answer[256]; - char *p; - - /* We can get recalled; if so, don't continue uselessly. */ - if (feof(stdin) || ferror(stdin)) { - (void)fprintf(stderr, "\n"); - exit(1); - } - for (;;) { - if (dflt) - (void)fprintf(stderr, "Terminal type? [%s] ", dflt); - else - (void)fprintf(stderr, "Terminal type? "); - (void)fflush(stderr); - - if (fgets(answer, sizeof(answer), stdin) == NULL) { - if (dflt == NULL) { - (void)fprintf(stderr, "\n"); - exit(1); - } - return (dflt); - } - - if ((p = strchr(answer, '\n'))) - *p = '\0'; - if (answer[0]) - return (answer); - if (dflt != NULL) - return (dflt); - } -} diff --git a/usr.bin/tset/tset.1 b/usr.bin/tset/tset.1 deleted file mode 100644 index 57e904a37a0..00000000000 --- a/usr.bin/tset/tset.1 +++ /dev/null @@ -1,421 +0,0 @@ -.\" Copyright (c) 1985, 1990, 1993 -.\" The Regents of the University of California. All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)tset.1 8.1 (Berkeley) 6/9/93 -.\" $FreeBSD$ -.\" -.Dd June 6, 2015 -.Dt TSET 1 -.Os -.Sh NAME -.Nm tset , -.Nm reset -.Nd terminal initialization -.Sh SYNOPSIS -.Nm -.Op Fl IQrSs -.Op Fl -.Op Fl e Ar ch -.Op Fl i Ar ch -.Op Fl k Ar ch -.Op Fl m Ar mapping -.Op Ar terminal -.Nm reset -.Op Fl IQrSs -.Op Fl -.Op Fl e Ar ch -.Op Fl i Ar ch -.Op Fl k Ar ch -.Op Fl m Ar mapping -.Op Ar terminal -.Sh DESCRIPTION -The -.Nm -utility initializes terminals. -It first determines the type of terminal that you are using. -This determination is done as follows, using the first terminal type found. -.Pp -.Bl -bullet -compact -offset indent -.It -The -.Ar terminal -argument specified on the command line. -.It -The value of the -.Ev TERM -environment variable. -.It -The terminal type associated with the standard error output device in the -.Pa /etc/ttys -file. -.It -The default terminal type, ``unknown''. -.El -.Pp -If the terminal type was not specified on the command-line, the -.Fl m -option mappings are then applied (see below for more information). -Then, if the terminal type begins with a question mark (``?''), the user is -prompted for confirmation of the terminal type. -An empty response confirms the type, or, another type can be entered to -specify a new type. -Once the terminal type has been determined, the termcap entry for the terminal -is retrieved. -If no termcap entry is found for the type, the user is prompted for another -terminal type. -.Pp -Once the termcap entry is retrieved, the window size, backspace, interrupt -and line kill characters (among many other things) are set and the terminal -and tab initialization strings are sent to the standard error output. -Finally, if the erase, interrupt and line kill characters have changed, -or are not set to their default values, their values are displayed to the -standard error output. -.Pp -When invoked as -.Nm reset , -.Nm -sets cooked and echo modes, turns off cbreak and raw modes, turns on -newline translation and resets any unset special characters to their -default values before doing the terminal initialization described above. -This is useful after a program dies leaving a terminal in an abnormal state. -Note, you may have to type -.Dq Li reset -(the line-feed character is normally control-J) to get the terminal -to work, as carriage-return may no longer work in the abnormal state. -Also, the terminal will often not echo the command. -.Pp -The options are as follows: -.Bl -tag -width flag -.It Fl -The terminal type is displayed to the standard output, and the terminal is -not initialized in any way. -.It Fl e -Set the erase character to -.Ar ch . -.It Fl I -Do not send the terminal or tab initialization strings to the terminal. -.It Fl i -Set the interrupt character to -.Ar ch . -.It Fl k -Set the line kill character to -.Ar ch . -.It Fl m -Specify a mapping from a port type to a terminal. -See below for more information. -.It Fl Q -Do not display any values for the erase, interrupt and line kill characters. -.It Fl r -Print the terminal type to the standard error output. -.It Fl S -Print the terminal type and the termcap entry to the standard output. -See the section below on setting the environment for details. -.It Fl s -Print the sequence of shell commands to initialize the environment variables -.Ev TERM -and -.Ev TERMCAP -to the standard output. -See the section below on setting the environment for details. -.El -.Pp -The arguments for the -.Fl e , -.Fl i -and -.Fl k -options may either be entered as actual characters or by using the -.Dq hat -notation, i.e., control-h may be specified as -.Dq Li ^H -or -.Dq Li ^h . -.Sh SETTING THE ENVIRONMENT -It is often desirable to enter the terminal type and information about -the terminal's capabilities into the shell's environment. -This is done using the -.Fl S -and -.Fl s -options. -.Pp -When the -.Fl S -option is specified, the terminal type and the termcap entry are written -to the standard output, separated by a space and without a terminating -newline. -This can be assigned to an array by -.Nm csh -and -.Nm ksh -users and then used like any other shell array. -.Pp -When the -.Fl s -option is specified, the commands to enter the information into the -shell's environment are written to the standard output. -If the -.Ev SHELL -environment variable ends in ``csh'', the commands are for the -.Nm csh , -otherwise, they are for -.Xr sh 1 . -Note, the -.Nm csh -commands set and unset the shell variable -.Dq noglob , -leaving it unset. -The following line in the -.Pa .login -or -.Pa .profile -files will initialize the environment correctly: -.Bd -literal -offset indent -eval \`tset -s options ... \` -.Ed -.Pp -To demonstrate a simple use of the -.Fl S -option, the following lines in the -.Pa .login -file have an equivalent effect: -.Bd -literal -offset indent -set noglob -set term=(`tset -S options ...`) -setenv TERM $term[1] -setenv TERMCAP "$term[2]" -unset term -unset noglob -.Ed -.Sh TERMINAL TYPE MAPPING -When the terminal is not hardwired into the system (or the current system -information is incorrect) the terminal type derived from the -.Pa /etc/ttys -file or the -.Ev TERM -environment variable is often something generic like -.Dq network , -.Dq dialup , -or -.Dq unknown . -When -.Nm -is used in a startup script -.Pf ( Pa .profile -for -.Xr sh 1 -users or -.Pa .login -for -.Xr csh 1 -users) it is often desirable to provide information about the type of -terminal used on such ports. -The purpose of the -.Fl m -option is to -.Dq map -from some set of conditions to a terminal type, that is, to -tell -.Nm -``If I'm on this port at a particular speed, guess that I'm on that -kind of terminal''. -.Pp -The argument to the -.Fl m -option consists of an optional port type, an optional operator, an optional -baud rate specification, an optional colon (``:'') character and a terminal -type. -The port type is a string (delimited by either the operator or the colon -character). -The operator may be any combination of: -.Dq Li \&> , -.Dq Li \&< , -.Dq Li \&@ , -and -.Dq Li \&! ; -.Dq Li \&> -means greater than, -.Dq Li \&< -means less than, -.Dq Li \&@ -means equal to -and -.Dq Li !\& -inverts the sense of the test. -The baud rate is specified as a number and is compared with the speed -of the standard error output (which should be the control terminal). -The terminal type is a string. -.Pp -If the terminal type is not specified on the command line, the -.Fl m -mappings are applied to the terminal type. -If the port type and baud rate match the mapping, the terminal type specified -in the mapping replaces the current type. -If more than one mapping is specified, the first applicable mapping is used. -.Pp -For example, consider the following mapping: -.Dq Li dialup>9600:vt100 . -The port type is -.Dq Li dialup , -the operator is -.Dq Li > , -the baud rate specification is -.Dq Li 9600 , -and the terminal type is -.Dq Li vt100 . -The result of this mapping is to specify that if the terminal type is -.Dq Li dialup , -and the baud rate is greater than 9600 baud, a terminal type of -.Dq Li vt100 -will be used. -.Pp -If no port type is specified, the terminal type will match any port type, -for example, -.Dq Li -m dialup:vt100 -m :?xterm -will cause any dialup port, regardless of baud rate, to match the terminal -type -.Dq Li vt100 , -and any non-dialup port type to match the terminal type -.Dq Li ?xterm . -Note, because of the leading question mark, the user will be -queried on a default port as to whether they are actually using an -.Ar xterm -terminal. -.Pp -No whitespace characters are permitted in the -.Fl m -option argument. -Also, to avoid problems with metacharacters, it is suggested that the entire -.Fl m -option argument be placed within single quote characters, and that -.Nm csh -users insert a backslash character (``\e'') before any exclamation -marks (``!''). -.Sh ENVIRONMENT -The -.Nm -command utilizes the -.Ev SHELL -and -.Ev TERM -environment variables. -.Sh FILES -.Bl -tag -width /usr/share/misc/termcap -compact -.It Pa /etc/ttys -system port name to terminal type mapping database -.It Pa /usr/share/misc/termcap -terminal capability database -.El -.Sh COMPATIBILITY -The -.Fl A , -.Fl E , -.Fl h , -.Fl u -and -.Fl v -options have been deleted from the -.Nm -utility. -None of them were documented in -.Bx 4.3 -and all are of limited utility at -best. -The -.Fl a , -.Fl d -and -.Fl p -options are similarly not documented or useful, but were retained as they -appear to be in widespread use. -It is strongly recommended that any usage of these three options be -changed to use the -.Fl m -option instead. -The -.Fl n -option remains, but has no effect. -It is still permissible to specify the -.Fl e , -.Fl i -and -.Fl k -options without arguments, although it is strongly recommended that such -usage be fixed to explicitly specify the character. -.Pp -Executing -.Nm -as -.Nm reset -no longer implies the -.Fl Q -option. -Also, the interaction between the -.Fl -option and the -.Ar terminal -argument in some historic implementations of -.Nm -has been removed. -.Pp -Finally, the -.Nm -implementation has been completely redone (as part of the addition to the -system of a -.St -p1003.1-88 -compliant terminal interface) and will no longer compile on systems with -older terminal interfaces. -.Sh SEE ALSO -.Xr csh 1 , -.Xr sh 1 , -.Xr stty 1 , -.Xr tty 4 , -.Xr termcap 5 , -.Xr ttys 5 , -.Xr environ 7 -.Sh HISTORY -The -.Nm -and -.Nm reset -utilities first appeared in -.Bx 1 . -.Sh AUTHORS -.An -nosplit -The original version of -.Nm tset -was written by -.An Eric P. Allman -in October 1977, and -.Nm reset -was originally written by -.An Kurt Shoens . -The current version also contains code by -.An Zeyd M. Ben-Halim , -.An Eric S. Raymond , -and -.An Thomas E. Dickey . diff --git a/usr.bin/tset/tset.c b/usr.bin/tset/tset.c deleted file mode 100644 index be6fbf3abd2..00000000000 --- a/usr.bin/tset/tset.c +++ /dev/null @@ -1,299 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1980, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -__FBSDID("$FreeBSD$"); - -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1980, 1991, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif - -#ifndef lint -static const char sccsid[] = "@(#)tset.c 8.1 (Berkeley) 6/9/93"; -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "extern.h" - -void obsolete(char *[]); -void report(const char *, int, u_int); -void usage(void); - -struct termios mode, oldmode; - -int erasech; /* new erase character */ -int intrchar; /* new interrupt character */ -int isreset; /* invoked as reset */ -int killch; /* new kill character */ -int Lines, Columns; /* window size */ -speed_t Ospeed; - -int -main(int argc, char *argv[]) -{ -#ifdef TIOCGWINSZ - struct winsize win; -#endif - int ch, noinit, noset, quiet, Sflag, sflag, showterm, usingupper; - char *p, *tcapbuf; - const char *ttype; - - if (tcgetattr(STDERR_FILENO, &mode) < 0) - err(1, "standard error"); - - oldmode = mode; - Ospeed = cfgetospeed(&mode); - - if ((p = strrchr(*argv, '/'))) - ++p; - else - p = *argv; - usingupper = isupper(*p); - if (!strcasecmp(p, "reset")) { - isreset = 1; - reset_mode(); - } - - obsolete(argv); - noinit = noset = quiet = Sflag = sflag = showterm = 0; - while ((ch = getopt(argc, argv, "-a:d:e:Ii:k:m:np:QSrs")) != -1) { - switch (ch) { - case '-': /* display term only */ - noset = 1; - break; - case 'a': /* OBSOLETE: map identifier to type */ - add_mapping("arpanet", optarg); - break; - case 'd': /* OBSOLETE: map identifier to type */ - add_mapping("dialup", optarg); - break; - case 'e': /* erase character */ - erasech = optarg[0] == '^' && optarg[1] != '\0' ? - optarg[1] == '?' ? '\177' : CTRL(optarg[1]) : - optarg[0]; - break; - case 'I': /* no initialization strings */ - noinit = 1; - break; - case 'i': /* interrupt character */ - intrchar = optarg[0] == '^' && optarg[1] != '\0' ? - optarg[1] == '?' ? '\177' : CTRL(optarg[1]) : - optarg[0]; - break; - case 'k': /* kill character */ - killch = optarg[0] == '^' && optarg[1] != '\0' ? - optarg[1] == '?' ? '\177' : CTRL(optarg[1]) : - optarg[0]; - break; - case 'm': /* map identifier to type */ - add_mapping(NULL, optarg); - break; - case 'n': /* OBSOLETE: set new tty driver */ - break; - case 'p': /* OBSOLETE: map identifier to type */ - add_mapping("plugboard", optarg); - break; - case 'Q': /* don't output control key settings */ - quiet = 1; - break; - case 'S': /* output TERM/TERMCAP strings */ - Sflag = 1; - break; - case 'r': /* display term on stderr */ - showterm = 1; - break; - case 's': /* output TERM/TERMCAP strings */ - sflag = 1; - break; - case '?': - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (argc > 1) - usage(); - - ttype = get_termcap_entry(*argv, &tcapbuf); - - if (!noset) { - Columns = tgetnum("co"); - Lines = tgetnum("li"); - -#ifdef TIOCGWINSZ - /* Set window size */ - (void)ioctl(STDERR_FILENO, TIOCGWINSZ, &win); - if (win.ws_row == 0 && win.ws_col == 0 && - Lines > 0 && Columns > 0) { - win.ws_row = Lines; - win.ws_col = Columns; - (void)ioctl(STDERR_FILENO, TIOCSWINSZ, &win); - } -#endif - set_control_chars(); - set_conversions(usingupper); - - if (!noinit) - set_init(); - - /* Set the modes if they've changed. */ - if (memcmp(&mode, &oldmode, sizeof(mode))) - tcsetattr(STDERR_FILENO, TCSADRAIN, &mode); - } - - if (noset) - (void)printf("%s\n", ttype); - else { - if (showterm) - (void)fprintf(stderr, "Terminal type is %s.\n", ttype); - /* - * If erase, kill and interrupt characters could have been - * modified and not -Q, display the changes. - */ - if (!quiet) { - report("Erase", VERASE, CERASE); - report("Kill", VKILL, CKILL); - report("Interrupt", VINTR, CINTR); - } - } - - if (Sflag) { - (void)printf("%s ", ttype); - if (strlen(tcapbuf) > 0) - wrtermcap(tcapbuf); - } - - if (sflag) { - /* - * Figure out what shell we're using. A hack, we look for an - * environmental variable SHELL ending in "csh". - */ - if ((p = getenv("SHELL")) && - !strcmp(p + strlen(p) - 3, "csh")) { - printf("set noglob;\nsetenv TERM %s;\n", ttype); - if (strlen(tcapbuf) > 0) { - printf("setenv TERMCAP '"); - wrtermcap(tcapbuf); - printf("';\n"); - } - printf("unset noglob;\n"); - } else { - printf("TERM=%s;\n", ttype); - if (strlen(tcapbuf) > 0) { - printf("TERMCAP='"); - wrtermcap(tcapbuf); - printf("';\nexport TERMCAP;\n"); - } - printf("export TERM;\n"); - } - } - - exit(0); -} - -/* - * Tell the user if a control key has been changed from the default value. - */ -void -report(const char *name, int which, u_int def) -{ - u_int old, new; - - new = mode.c_cc[which]; - old = oldmode.c_cc[which]; - - if (old == new && old == def) - return; - - (void)fprintf(stderr, "%s %s ", name, old == new ? "is" : "set to"); - - if (new == 010) - (void)fprintf(stderr, "backspace.\n"); - else if (new == 0177) - (void)fprintf(stderr, "delete.\n"); - else if (new < 040) { - new ^= 0100; - (void)fprintf(stderr, "control-%c (^%c).\n", new, new); - } else - (void)fprintf(stderr, "%c.\n", new); -} - -/* - * Convert the obsolete argument form into something that getopt can handle. - * This means that -e, -i and -k get default arguments supplied for them. - */ -void -obsolete(char *argv[]) -{ - for (; *argv; ++argv) { - if (argv[0][0] != '-' || (argv[1] && argv[1][0] != '-') || - (argv[0][1] != 'e' && argv[0][1] != 'i' && argv[0][1] != 'k') || - argv[0][2] != '\0') - continue; - switch(argv[0][1]) { - case 'e': - argv[0] = strdup("-e^H"); - break; - case 'i': - argv[0] = strdup("-i^C"); - break; - case 'k': - argv[0] = strdup("-k^U"); - break; - } - } -} - -void -usage(void) -{ - (void)fprintf(stderr, "%s\n%s\n", -"usage: tset [-IQrSs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]", -" reset [-IQrSs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]"); - exit(1); -} - diff --git a/usr.bin/tset/wrterm.c b/usr.bin/tset/wrterm.c deleted file mode 100644 index cd98558f20a..00000000000 --- a/usr.bin/tset/wrterm.c +++ /dev/null @@ -1,116 +0,0 @@ -/*- - * SPDX-License-Identifier: BSD-3-Clause - * - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include - -__FBSDID("$FreeBSD$"); - -#ifndef lint -static const char sccsid[] = "@(#)wrterm.c 8.1 (Berkeley) 6/9/93"; -#endif - -#include - -#include -#include -#include -#include - -#include "extern.h" - -/* - * Output termcap entry to stdout, quoting characters that would give the - * shell problems and omitting empty fields. - */ -void -wrtermcap(char *bp) -{ - register int ch; - register char *p; - char *t, *sep; - - /* Find the end of the terminal names. */ - if ((t = strchr(bp, ':')) == NULL) - errx(1, "termcap names not colon terminated"); - *t++ = '\0'; - - /* Output terminal names that don't have whitespace. */ - sep = strdup(""); - while ((p = strsep(&bp, "|")) != NULL) - if (*p != '\0' && strpbrk(p, " \t") == NULL) { - (void)printf("%s%s", sep, p); - sep = strdup("|"); - } - (void)putchar(':'); - - /* - * Output fields, transforming any dangerous characters. Skip - * empty fields or fields containing only whitespace. - */ - while ((p = strsep(&t, ":")) != NULL) { - while ((ch = *p) != '\0' && isspace(ch)) - ++p; - if (ch == '\0') - continue; - while ((ch = *p++) != '\0') - switch(ch) { - case '\033': - (void)printf("\\E"); - case ' ': /* No spaces. */ - (void)printf("\\040"); - break; - case '!': /* No csh history chars. */ - (void)printf("\\041"); - break; - case ',': /* No csh history chars. */ - (void)printf("\\054"); - break; - case '"': /* No quotes. */ - (void)printf("\\042"); - break; - case '\'': /* No quotes. */ - (void)printf("\\047"); - break; - case '`': /* No quotes. */ - (void)printf("\\140"); - break; - case '\\': /* Anything following is OK. */ - case '^': - (void)putchar(ch); - if ((ch = *p++) == '\0') - break; - /* FALLTHROUGH */ - default: - (void)putchar(ch); - } - (void)putchar(':'); - } -} -- 2.30.1