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.
This commit is contained in:
Andrey A. Chernov 1995-08-05 21:22:07 +00:00
parent f8791190ac
commit 021e5b9d1f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=9938
7 changed files with 53 additions and 48 deletions

View file

@ -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} \

View file

@ -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 @@ tgetent(bp, name)
* 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;

View file

@ -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_ */

View file

@ -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;

View file

@ -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;

View file

@ -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";

View file

@ -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;