import tput from NetBSD

Posix tool to allow direct use of the terminfo database.
The clear script is adjusted accordingly.
The (MINIX-specific) clr equivalent is now gone.
This commit is contained in:
Antoine Leca 2013-01-18 17:20:49 +00:00 committed by Lionel Sambuc
parent fc1c7a3483
commit 1999c518b6
12 changed files with 430 additions and 33 deletions

View file

@ -4,7 +4,7 @@
SUBDIR= add_route arp ash at backup banner basename btrace cal \
cawf cd cdprobe cpp \
chmod chown ci cleantmp clear cmp co \
chmod chown ci cleantmp cmp co \
comm compress cp crc cron crontab cut \
dd decomp16 DESCRIBE devmand devsize df dhcpd \
dhrystone diff dirname diskctl dumpcore \

View file

@ -1,6 +0,0 @@
SCRIPTS= clear.sh
MAN=
LINKS+= ${BINDIR}/clear ${BINDIR}/clr
.include <bsd.prog.mk>

View file

@ -1,6 +0,0 @@
#!/bin/sh
#
# clear 1.0 - clear the screen Author: Kees J. Bot
# 30 Mar 1996
export PATH=/bin:/usr/bin
exec tget -str cl

View file

@ -184,7 +184,6 @@
./usr/bin/cksum minix-sys
./usr/bin/cleantmp minix-sys
./usr/bin/clear minix-sys
./usr/bin/clr minix-sys
./usr/bin/cmp minix-sys
./usr/bin/colcrt minix-sys
./usr/bin/co minix-sys
@ -381,6 +380,7 @@
./usr/bin/time minix-sys
./usr/bin/top minix-sys
./usr/bin/touch minix-sys
./usr/bin/tput minix-sys
./usr/bin/tr minix-sys
./usr/bin/truncate minix-sys
./usr/bin/tsort minix-sys
@ -1339,6 +1339,7 @@
./usr/man/man1/tic.1 minix-sys
./usr/man/man1/time.1 minix-sys
./usr/man/man1/touch.1 minix-sys
./usr/man/man1/tput.1 minix-sys
./usr/man/man1/tr.1 minix-sys
./usr/man/man1/trap.1 minix-sys
./usr/man/man1/true.1 minix-sys

View file

@ -1,6 +1,6 @@
MAN= ash.1 at.1 banner.1 basename.1 \
bsfilt.1 cal.1 cawf.1 chgrp.1 \
chmod.1 clear.1 cmp.1 comm.1 compress.1 \
chmod.1 cmp.1 comm.1 compress.1 \
cp.1 crc.1 crontab.1 dd.1 \
df.1 dhrystone.1 dosdir.1 dosread.1 doswrite.1 \
dumpcore.1 echo.1 eject.1 \

View file

@ -1,17 +0,0 @@
.TH CLEAR 1
.SH NAME
clear, clr \- clear the screen
.SH SYNOPSIS
.B clear
.br
.B clr
.SH DESCRIPTION
.B Clear
or its synonym
.B clr
clears the screen. It is exactly equivalent to
.BR "tget -str cl" .
.SH "SEE ALSO"
.BR tget (1).
.SH AUTHOR
Kees J. Bot (kjb@cs.vu.nl)

View file

@ -142,6 +142,7 @@
2011/01/15 22:54:10,usr.bin/stat
2012/02/10 16:16:12,usr.bin/su
2012/06/01 12:08:40,usr.bin/tic
2012/10/17 12:00:00,usr.bin/tput
2012/10/17 12:00:00,usr.bin/tsort
2010/10/06 07:59:18,usr.bin/uniq
2012/10/17 12:00:00,usr.bin/xinstall

View file

@ -25,7 +25,7 @@ SUBDIR= \
\
sed seq \
sort stat su \
tic \
tic tput \
tsort \
uniq \
\

10
usr.bin/tput/Makefile Executable file
View file

@ -0,0 +1,10 @@
# $NetBSD: Makefile,v 1.10 2010/02/03 15:34:46 roy Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= tput
DPADD= ${LIBTERMINFO}
LDADD= -lterminfo
MLINKS= tput.1 clear.1
SCRIPTS=clear.sh
.include <bsd.prog.mk>

38
usr.bin/tput/clear.sh Executable file
View file

@ -0,0 +1,38 @@
#!/bin/sh -
# $NetBSD: clear.sh,v 1.2 1994/12/07 08:49:09 jtc Exp $
#
# 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. All advertising materials mentioning features or use of this software
# must display the following acknowledgement:
# This product includes software developed by the University of
# California, Berkeley and its contributors.
# 4. 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.
#
# @(#)clear.sh 8.1 (Berkeley) 6/6/93
#
exec tput clear

139
usr.bin/tput/tput.1 Normal file
View file

@ -0,0 +1,139 @@
.\" $NetBSD: tput.1,v 1.16 2012/04/21 12:27:30 roy Exp $
.\"
.\" 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
.\"
.Dd April 5, 2012
.Dt TPUT 1
.Os
.Sh NAME
.Nm tput ,
.Nm clear
.Nd terminal capability interface
.Sh SYNOPSIS
.Nm
.Op Fl T Ar term
.Ar attribute
.Op Ar attribute-args
.Ar ...
.Sh DESCRIPTION
.Nm
makes terminal-dependent information available to users or shell
applications.
The options are as follows:
.Bl -tag -width Ds
.It Fl T
The terminal name as specified in the
.Xr terminfo 5
database, for example,
.Dq vt100
or
.Dq xterm .
If not specified,
.Nm
retrieves the
.Dq Ev TERM
variable from the environment.
.El
.Pp
.Nm
outputs a string if the
.Ar attribute
is of type string; a number if it is of type integer.
Otherwise,
.Nm
exits 0 if the terminal has the capability and 1 if it does not,
without further action.
.Pp
If the
.Ar attribute
is of type string, and takes arguments (e.g. cursor movement,
the terminfo
.Dq cup
sequence) the arguments are taken from the command line immediately
following the attribute.
.Pp
The following special attributes are available:
.Bl -tag -width Ar
.It clear
Clear the screen (the
.Xr terminfo 5
.Dq cl
sequence).
.It init
Initialize the terminal (the
.Xr terminfo 5
.Dq is2
sequence).
.It longname
Print the descriptive name of the user's terminal type.
.It reset
Reset the terminal (the
.Xr terminfo 5
.Dq rs1 , rs2 , rs3
and
.Dq rf
sequence).
.El
.Sh EXIT STATUS
The exit status of
.Nm
is based on the last attribute specified.
If the attribute is of type string or of type integer,
.Nm
exits 0 if the attribute is defined for this terminal type and 1
if it is not.
If the attribute is of type boolean,
.Nm
exits 0 if the terminal has this attribute, and 1 if it does not.
.Nm
exits 2 if any error occurred.
.Sh EXAMPLES
.Bl -tag -width "tput cm 6 11 DC 6" -compact
.It Li "tput cl cm 5 10"
clear the screen and goto line 5 column 10
.Pp
.It Li "tput cm 6 11 DC 6"
goto line 6 column 11 and delete 6 characters
.El
.Sh SEE ALSO
.Xr termcap 3 ,
.Xr terminfo 3 ,
.Xr terminfo 5
.Sh HISTORY
The
.Nm
command appears in
.Bx 4.4 .
.Sh BUGS
.Nm
can't really distinguish between different types of attributes.
.Pp
Not all terminfo entries contain the reset sequence, so using the init
sequence may be more useful.

237
usr.bin/tput/tput.c Executable file
View file

@ -0,0 +1,237 @@
/* $NetBSD: tput.c,v 1.22 2011/10/04 12:23:14 roy Exp $ */
/*-
* 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 <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1980, 1988, 1993\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)tput.c 8.3 (Berkeley) 4/28/95";
#endif
__RCSID("$NetBSD: tput.c,v 1.22 2011/10/04 12:23:14 roy Exp $");
#endif /* not lint */
#include <termios.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <term.h>
#include <termcap.h>
#include <unistd.h>
static int outc(int);
static void usage(void) __dead;
static char **process(const char *, const char *, char **);
int
main(int argc, char **argv)
{
int ch, exitval, n;
char *term;
const char *p, *s;
size_t pl;
term = NULL;
while ((ch = getopt(argc, argv, "T:")) != -1)
switch(ch) {
case 'T':
term = optarg;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
if (!term && !(term = getenv("TERM")))
errx(2, "No terminal type specified and no TERM "
"variable set in the environment.");
setupterm(term, 0, NULL);
for (exitval = 0; (p = *argv) != NULL; ++argv) {
switch (*p) {
case 'c':
if (!strcmp(p, "clear"))
p = "clear";
break;
case 'i':
if (!strcmp(p, "init")) {
s = tigetstr("is1");
if (s != NULL)
tputs(s, 0, outc);
p = "is2";
}
break;
case 'l':
if (!strcmp(p, "longname")) {
(void)printf("%s\n", longname());
continue;
}
break;
case 'r':
if (!strcmp(p, "reset")) {
s = tigetstr("rs1");
if (s != NULL)
tputs(s, 0, outc);
p = "rs2";
}
break;
}
pl = strlen(p);
if (((s = tigetstr(p)) != NULL && s != (char *)-1) ||
(pl <= 2 && (s = tgetstr(p, NULL)) != NULL))
argv = process(p, s, argv);
else if ((((n = tigetnum(p)) != -1 && n != -2 ) ||
(pl <= 2 && (n = tgetnum(p)) != -1)))
(void)printf("%d\n", n);
else {
exitval = tigetflag(p);
if (exitval == -1) {
if (pl <= 2)
exitval = !tgetflag(p);
else
exitval = 1;
} else
exitval = !exitval;
}
if (argv == NULL)
break;
}
return argv ? exitval : 2;
}
static char **
process(const char *cap, const char *str, char **argv)
{
static const char errfew[] =
"Not enough arguments (%d) for capability `%s'";
static const char erresc[] =
"Unknown %% escape `%c' for capability `%s'";
char c, l;
const char *p;
int arg_need, p1, p2, p3, p4, p5, p6, p7, p8, p9;
/* Count how many values we need for this capability. */
arg_need = 0;
p = str;
while ((c = *p++) != '\0') {
if (c != '%')
continue;
c = *p++;
if (c == '\0')
break;
if (c != 'p')
continue;
c = *p++;
if (c < '1' || c > '9')
errx(2, erresc, c, cap);
l = c - '0';
if (l > arg_need)
arg_need = l;
}
#define NEXT_ARG \
{ \
if (*++argv == NULL || *argv[0] == '\0') \
errx(2, errfew, 1, cap); \
}
if (arg_need > 0) {
NEXT_ARG;
p1 = atoi(*argv);
} else
p1 = 0;
if (arg_need > 1) {
NEXT_ARG;
p2 = atoi(*argv);
} else
p2 = 0;
if (arg_need > 2) {
NEXT_ARG;
p3 = atoi(*argv);
} else
p3 = 0;
if (arg_need > 3) {
NEXT_ARG;
p4 = atoi(*argv);
} else
p4 = 0;
if (arg_need > 4) {
NEXT_ARG;
p5 = atoi(*argv);
} else
p5 = 0;
if (arg_need > 5) {
NEXT_ARG;
p6 = atoi(*argv);
} else
p6 = 0;
if (arg_need > 6) {
NEXT_ARG;
p7 = atoi(*argv);
} else
p7 = 0;
if (arg_need > 7) {
NEXT_ARG;
p8 = atoi(*argv);
} else
p8 = 0;
if (arg_need > 8) {
NEXT_ARG;
p9 = atoi(*argv);
} else
p9 = 0;
/* And print them. */
(void)tputs(tparm(str, p1, p2, p3, p4, p5, p6, p7, p8, p9), 0, outc);
return argv;
}
static int
outc(int c)
{
return putchar(c);
}
static void
usage(void)
{
(void)fprintf(stderr,
"Usage: %s [-T term] attribute [attribute-args] ...\n",
getprogname());
exit(2);
}