diff options
author | ache <ache@FreeBSD.org> | 1995-08-05 21:22:07 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1995-08-05 21:22:07 +0000 |
commit | 100e6f311c5d20fdb09afe48750d3d733c8b8e45 (patch) | |
tree | 84255860ff0aa7fd3bacde0ab4494a6ab882406e | |
parent | c426abc4240ef56049117a4cc11d9db6a62c0db1 (diff) | |
download | FreeBSD-src-100e6f311c5d20fdb09afe48750d3d733c8b8e45.zip FreeBSD-src-100e6f311c5d20fdb09afe48750d3d733c8b8e45.tar.gz |
Do a little trick which covers 99% cases: initialize ospeed
variable directly in tgetent by stderr or stdout output speed.
It helps hide in non-standard __set_ospeed function and remove it
from other sources (coming soon).
Do prototype cleanup too.
-rw-r--r-- | lib/libtermcap/Makefile | 4 | ||||
-rw-r--r-- | lib/libtermcap/termcap.c | 30 | ||||
-rw-r--r-- | lib/libtermcap/termcap.h | 4 | ||||
-rw-r--r-- | lib/libtermcap/tgoto.c | 8 | ||||
-rw-r--r-- | lib/libtermcap/tospeed.c | 47 | ||||
-rw-r--r-- | lib/libtermcap/tparm.c | 1 | ||||
-rw-r--r-- | lib/libtermcap/tputs.c | 7 |
7 files changed, 53 insertions, 48 deletions
diff --git a/lib/libtermcap/Makefile b/lib/libtermcap/Makefile index 0ed230c..cab35af 100644 --- a/lib/libtermcap/Makefile +++ b/lib/libtermcap/Makefile @@ -3,13 +3,13 @@ LIB= termcap SHLIB_MAJOR= 2 SHLIB_MINOR= 1 -CFLAGS+=-DCM_N -DCM_GT -DCM_B -DCM_D +CFLAGS+=-DCM_N -DCM_GT -DCM_B -DCM_D -I${.CURDIR} SRCS= termcap.c tgoto.c tputs.c tparm.c tospeed.c MAN3= termcap.3 MLINKS= termcap.3 tgetent.3 termcap.3 tgetflag.3 termcap.3 tgetnum.3 \ termcap.3 tgetstr.3 termcap.3 tgoto.3 termcap.3 tputs.3 \ - termcap.3 tparm.3 termcap.3 _set_ospeed.3 + termcap.3 tparm.3 LINKS= ${LIBDIR}/libtermcap.a ${LIBDIR}/libtermlib.a .if !defined(NOPIC) LINKS+= ${SHLIBDIR}/libtermcap.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \ diff --git a/lib/libtermcap/termcap.c b/lib/libtermcap/termcap.c index 38ae9da..7f8d39d 100644 --- a/lib/libtermcap/termcap.c +++ b/lib/libtermcap/termcap.c @@ -43,8 +43,13 @@ static char sccsid[] = "@(#)termcap.c 8.1 (Berkeley) 6/4/93"; #include <ctype.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> +#include <termios.h> +#include "termcap.h" #include "pathnames.h" +extern void __set_ospeed(speed_t speed); + /* * termcap - routines for dealing with the terminal capability data base * @@ -65,8 +70,7 @@ static char *tbuf; /* termcap buffer */ * Get an entry for terminal name in buffer bp from the termcap file. */ int -tgetent(bp, name) - char *bp, *name; +tgetent(char *bp, const char *name) { register char *p; register char *cp; @@ -78,6 +82,7 @@ tgetent(bp, name) char *pathvec[PVECSIZ]; /* to point to names in pathbuf */ char **pvec; /* holds usable tail of path vector */ char *termpath; + struct termios tty; dummy = NULL; fname = pathvec; @@ -130,7 +135,7 @@ tgetent(bp, name) if (cgetset(cp) < 0) return(-2); - i = cgetent(&dummy, pathvec, name); + i = cgetent(&dummy, pathvec, (char *)name); if (i == 0) { char *pd, *ps, *tok, *s, *tcs; @@ -180,6 +185,12 @@ tgetent(bp, name) } } done: + if ( i == 0 + && ( tcgetattr(STDERR_FILENO, &tty) != -1 + || tcgetattr(STDOUT_FILENO, &tty) != -1 + ) + ) + __set_ospeed(cfgetospeed(&tty)); if (dummy) free(dummy); /* no tc reference loop return code in libterm XXX */ @@ -197,12 +208,11 @@ done: * Note that we handle octal numbers beginning with 0. */ int -tgetnum(id) - char *id; +tgetnum(const char *id) { long num; - if (cgetnum(tbuf, id, &num) == 0) + if (cgetnum(tbuf, (char *)id, &num) == 0) return(num); else return(-1); @@ -215,10 +225,9 @@ tgetnum(id) * not given. */ int -tgetflag(id) - char *id; +tgetflag(const char *id) { - return(cgetcap(tbuf, id, ':') != NULL); + return(cgetcap(tbuf, (char *)id, ':') != NULL); } /* @@ -230,8 +239,7 @@ tgetflag(id) * No checking on area overflow. */ char * -tgetstr(id, area) - char *id, **area; +tgetstr(const char *id, char **area) { char ids[3]; char *s; diff --git a/lib/libtermcap/termcap.h b/lib/libtermcap/termcap.h index 059d573..6e2ef39 100644 --- a/lib/libtermcap/termcap.h +++ b/lib/libtermcap/termcap.h @@ -24,7 +24,7 @@ * SUCH DAMAGE. */ -/* $Id: termcap.h,v 1.4 1994/12/10 22:01:25 ache Exp $ */ +/* $Id: termcap.h,v 1.5 1995/08/04 06:39:54 ache Exp $ */ #ifndef _TERMCAP_H_ #define _TERMCAP_H_ @@ -46,8 +46,6 @@ extern int tputs __P((const char *, int, int (*)(int))); extern char *tgoto __P((const char *, int, int)); extern char *tparm __P((const char *, ...)); -extern void _set_ospeed __P((long speed)); - __END_DECLS #endif /* _TERMCAP_H_ */ diff --git a/lib/libtermcap/tgoto.c b/lib/libtermcap/tgoto.c index c4dd9d7..e28a85c 100644 --- a/lib/libtermcap/tgoto.c +++ b/lib/libtermcap/tgoto.c @@ -35,6 +35,8 @@ static char sccsid[] = "@(#)tgoto.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ +#include "termcap.h" + #define CTRL(c) ((c) & 037) #define MAXRETURNSIZE 64 @@ -67,13 +69,11 @@ char *BC; * all other characters are ``self-inserting''. */ char * -tgoto(CM, destcol, destline) - char *CM; - int destcol, destline; +tgoto(const char *CM, int destcol, int destline) { static char result[MAXRETURNSIZE]; static char added[10]; - char *cp = CM; + const char *cp = CM; register char *dp = result; register int c; int oncol = 0; diff --git a/lib/libtermcap/tospeed.c b/lib/libtermcap/tospeed.c index 89c37aa..dd2026a 100644 --- a/lib/libtermcap/tospeed.c +++ b/lib/libtermcap/tospeed.c @@ -24,42 +24,43 @@ * SUCH DAMAGE. */ -extern short ospeed; +#include <termios.h> +#include "termcap.h" static struct stable { - long speed; + speed_t speed; short code; } table[] = { - {115200,17}, - {57600, 16}, - {38400, 15}, - {19200, 14}, - {9600, 13}, - {4800, 12}, - {2400, 11}, - {1800, 10}, - {1200, 9}, - {600, 8}, - {300, 7}, - {200, 6}, - {150, 5}, - {134, 4}, - {110, 3}, - {75, 2}, - {50, 1}, - {0, 0}, + {B115200,17}, + {B57600, 16}, + {B38400, 15}, + {B19200, 14}, + {B9600, 13}, + {B4800, 12}, + {B2400, 11}, + {B1800, 10}, + {B1200, 9}, + {B600, 8}, + {B300, 7}, + {B200, 6}, + {B150, 5}, + {B134, 4}, + {B110, 3}, + {B75, 2}, + {B50, 1}, + {B0, 0}, {-1, -1} }; -void _set_ospeed(long speed) +void __set_ospeed(speed_t speed) { struct stable *stable; - if (speed == 0) { + if (speed == B0) { ospeed = 0; return; } - for (stable = table; stable->speed > 0; stable++) { + for (stable = table; stable->speed > B0; stable++) { /* nearest one, rounded down */ if (stable->speed <= speed) { ospeed = stable->code; diff --git a/lib/libtermcap/tparm.c b/lib/libtermcap/tparm.c index 36070d9..6a537ce 100644 --- a/lib/libtermcap/tparm.c +++ b/lib/libtermcap/tparm.c @@ -11,6 +11,7 @@ #include <stdarg.h> #include <stdio.h> #include <string.h> +#include "termcap.h" #ifdef USE_SCCS_IDS static const char SCCSid[] = "@(#) mytinfo tparm.c 3.2 92/02/01 public domain, By Ross Ridge"; diff --git a/lib/libtermcap/tputs.c b/lib/libtermcap/tputs.c index b017fd7..46b6dc2 100644 --- a/lib/libtermcap/tputs.c +++ b/lib/libtermcap/tputs.c @@ -35,8 +35,8 @@ static char sccsid[] = "@(#)tputs.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ -#include <sgtty.h> #include <ctype.h> +#include "termcap.h" /* * The following array gives the number of tens of milliseconds per @@ -57,10 +57,7 @@ char PC; * The number of affected lines is affcnt, and the routine * used to output one character is outc. */ -tputs(cp, affcnt, outc) - register char *cp; - int affcnt; - int (*outc)(); +tputs(const char *cp, int affcnt, int (*outc)(int)) { register int i = 0; register int mspc10; |