diff options
Diffstat (limited to 'usr.bin/tput')
-rw-r--r-- | usr.bin/tput/Makefile | 7 | ||||
-rw-r--r-- | usr.bin/tput/tput.1 | 39 | ||||
-rw-r--r-- | usr.bin/tput/tput.c | 100 |
3 files changed, 59 insertions, 87 deletions
diff --git a/usr.bin/tput/Makefile b/usr.bin/tput/Makefile index 77018ee2160..836899278a7 100644 --- a/usr.bin/tput/Makefile +++ b/usr.bin/tput/Makefile @@ -1,8 +1,9 @@ -# $OpenBSD: Makefile,v 1.9 1999/03/06 20:19:21 millert Exp $ +# $OpenBSD: Makefile,v 1.10 1999/03/06 20:27:42 millert Exp $ PROG= tput -DPADD= ${LIBCURSES} -LDADD= -lcurses +CFLAGS+= -D_USE_OLD_CURSES_ +DPADD= ${LIBOLDCURSES} +LDADD= -locurses MLINKS= tput.1 clear.1 LINKS= ${BINDIR}/tput ${BINDIR}/clear diff --git a/usr.bin/tput/tput.1 b/usr.bin/tput/tput.1 index bef16e1dfd0..8a6623a5c90 100644 --- a/usr.bin/tput/tput.1 +++ b/usr.bin/tput/tput.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tput.1,v 1.4 1999/03/06 20:19:21 millert Exp $ +.\" $OpenBSD: tput.1,v 1.5 1999/03/06 20:27:42 millert Exp $ .\" $NetBSD: tput.1,v 1.4 1994/12/07 08:49:10 jtc Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 @@ -34,7 +34,7 @@ .\" .\" @(#)tput.1 8.2 (Berkeley) 3/19/94 .\" -.Dd July 25, 1998 +.Dd March 19, 1994 .Dt TPUT 1 .Os BSD 4.4 .Sh NAME @@ -46,9 +46,6 @@ .Ar attribute .Op Ar attribute-args .Ar ... -.Nm tput -.Op Fl T Ar term -.Fl S .Sh DESCRIPTION .Nm tput makes terminal-dependent information available to users or shell @@ -57,17 +54,13 @@ The options are as follows: .Bl -tag -width Ds .It Fl T The terminal name as specified in the -.Xr terminfo +.Xr termcap database, for example, ``vt100'' or ``xterm''. If not specified, .Nm tput retrieves the .Dq Ev TERM variable from the environment. -.It Fl S -The -.Ar attributes -are read from stdin instead of from the command line. .El .Pp .Nm tput @@ -82,8 +75,8 @@ without further action. If the .Ar attribute is of type string, and takes arguments (e.g. cursor movement, -the terminfo -.Dq cup +the termcap +.Dq cm sequence) the arguments are taken from the command line immediately following the attribute. .Pp @@ -91,18 +84,18 @@ The following special attributes are available: .Bl -tag -width Ar .It clear Clear the screen (the -.Xr terminfo -``clear'' sequence). +.Xr termcap +``cl'' sequence). .It init Initialize the terminal (the -.Xr terminfo -``is2'' sequence). +.Xr termcap +``is'' sequence). .It longname Print the descriptive name of the user's terminal type. .It reset Reset the terminal (the -.Xr termifo -``rs2'' sequence). +.Xr termcap +``rs'' sequence). .Sh DIAGNOSTICS The exit value of .Nm tput @@ -117,15 +110,15 @@ exits 0 if the terminal has this attribute, and 1 if it does not. .Nm tput exits 2 if any error occurred. .Sh EXAMPLES -.Bl -tag -width "tput cup 6 11 dch 6" -compact -.It Li "tput clear cup 5 10" +.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 cup 6 11 dch 6" +.It Li "tput cm 6 11 DC 6" goto line 6 column 11 and delete 6 characters .Sh SEE ALSO -.Xr terminfo 3 , -.Xr terminfo 5 +.Xr termcap 3 , +.Xr termcap 5 .Sh BUGS .Nm tput can't really distinguish between different types of attributes. diff --git a/usr.bin/tput/tput.c b/usr.bin/tput/tput.c index e354f260882..0b961ac0001 100644 --- a/usr.bin/tput/tput.c +++ b/usr.bin/tput/tput.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tput.c,v 1.6 1999/03/06 20:19:22 millert Exp $ */ +/* $OpenBSD: tput.c,v 1.7 1999/03/06 20:27:42 millert Exp $ */ /* $NetBSD: tput.c,v 1.8 1995/08/31 22:11:37 jtc Exp $ */ /*- @@ -44,14 +44,13 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)tput.c 8.3 (Berkeley) 4/28/95"; #endif -static char rcsid[] = "$OpenBSD: tput.c,v 1.6 1999/03/06 20:19:22 millert Exp $"; +static char rcsid[] = "$OpenBSD: tput.c,v 1.7 1999/03/06 20:27:42 millert Exp $"; #endif /* not lint */ #include <termios.h> #include <err.h> #include <curses.h> -#include <term.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -59,101 +58,75 @@ static char rcsid[] = "$OpenBSD: tput.c,v 1.6 1999/03/06 20:19:22 millert Exp $" static void prlongname __P((char *)); static void setospeed __P((void)); +static void outc __P((int)); static void usage __P((void)); static char **process __P((char *, char *, char **)); -extern char *__progname; - int main(argc, argv) int argc; char **argv; { - int ch, exitval, n, Sflag = 0; - size_t len; - char *p, *term, *str; + extern char *optarg; + extern int optind; + int ch, exitval, n; + char *argv0, *cptr, *p, *term, buf[1024], tbuf[1024]; term = NULL; - while ((ch = getopt(argc, argv, "ST:")) != -1) + while ((ch = getopt(argc, argv, "T:")) != -1) switch(ch) { case 'T': term = optarg; break; - case 'S': - Sflag = 1; - break; case '?': default: usage(); } + if ((argv0 = (char *)strrchr(argv[0], '/')) != NULL) + argv0++; + else + argv0 = argv[0]; argc -= optind; argv += optind; - if (Sflag && argc > 0) - usage(); if (!term && !(term = getenv("TERM"))) errx(2, "no terminal type specified and no TERM environmental variable."); - if (setupterm(term, STDOUT_FILENO, NULL) == ERR) - err(2, "setupterm failure"); + if (tgetent(tbuf, term) != 1) + err(2, "tgetent failure"); setospeed(); - if (strcmp(__progname, "clear") == 0) { - if (Sflag) - usage(); + if (strcmp(argv0, "clear") == 0) { *argv = "clear"; *(argv+1) = NULL; } - if (Sflag) { - char **av; - - /* Build new argv based on stdin */ - argc = n = 0; - av = NULL; - while ((str = fgetln(stdin, &len)) != NULL) { - if (str[len-1] != '\n') - errx(1, "premature EOF"); - str[len-1] = '\0'; - /* grow av as needed */ - if (argc + 1 >= n) { - n += 64; - av = (char **)realloc(av, sizeof(char *) * n); - if (av == NULL) - errx(1, "out of memory"); - av = &av[argc]; - } - while ((p = strsep(&str, " \t")) != NULL) - if ((av[argc++] = strdup(p)) == NULL) - errx(1, "out of memory"); - } - if (argc > 0) { - av[argc] = NULL; - argv = av; - } - } 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 = "is2"; /* XXX - is1 as well? */ + p = "is"; break; case 'l': if (!strcmp(p, "longname")) { - prlongname(CUR term_names); + prlongname(tbuf); continue; } break; case 'r': if (!strcmp(p, "reset")) - p = "rs2"; /* XXX - rs1 as well? */ + p = "rs"; break; } - /* XXX - check termcap names too */ - if ((str = tigetstr(p)) != NULL && str != (char *)-1) - argv = process(p, str, argv); - else if ((n = tigetnum(p)) != -1 && n != -2) + cptr = buf; + if (tgetstr(p, &cptr)) + argv = process(p, buf, argv); + else if ((n = tgetnum(p)) != -1) (void)printf("%d\n", n); else - exitval = (tigetflag(p) == -1); + exitval = !tgetflag(p); if (argv == NULL) break; @@ -211,7 +184,7 @@ process(cap, str, argv) break; default: /* - * HP-UX has lots of them, but we complain + * hpux has lot's of them, but we complain */ errx(2, erresc, *cp, cap); } @@ -219,7 +192,7 @@ process(cap, str, argv) /* And print them. */ switch (arg_need) { case 0: - (void)putp(str); + (void)tputs(str, 1, outc); break; case 1: arg_cols = 0; @@ -228,7 +201,7 @@ process(cap, str, argv) errx(2, errfew, 1, cap); arg_rows = atoi(*argv); - (void)putp(tparm(str, arg_cols, arg_rows)); + (void)tputs(tgoto(str, arg_cols, arg_rows), 1, outc); break; case 2: if (*++argv == NULL || *argv[0] == '\0') @@ -239,7 +212,7 @@ process(cap, str, argv) errx(2, errfew, 2, cap); arg_cols = atoi(*argv); - (void) tputs(tparm(str, arg_cols, arg_rows), arg_rows, putchar); + (void) tputs(tgoto(str, arg_cols, arg_rows), arg_rows, outc); break; default: @@ -262,10 +235,15 @@ setospeed() } static void +outc(c) + int c; +{ + (void)putchar(c); +} + +static void usage() { - (void)fprintf(stderr, - "usage: %s [-T term] attribute [attribute-args] ...\n" - " %s [-T term] -S\n", __progname, __progname); + (void)fprintf(stderr, "usage: tput [-T term] attribute ...\n"); exit(1); } |