Subversion Repositories planix.SVN

Compare Revisions

Ignore whitespace Rev 35 → Rev 36

/ports/trunk/unix/libterm/Makefile
0,0 → 1,13
# @(#)Makefile 5.10 (Berkeley) 6/1/90
 
LIB= termcap
CFLAGS+=-DCM_N -DCM_GT -DCM_B -DCM_D
SRCS= termcap.c tgoto.c tputs.c
 
MAN3= termcap.0
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
LINKS= ${LIBDIR}/libtermcap.a ${LIBDIR}/libtermlib.a \
${LIBDIR}/libtermcap_p.a ${LIBDIR}/libtermlib_p.a
 
.include <bsd.lib.mk>
/ports/trunk/unix/libterm/pathnames.h
0,0 → 1,36
/*
* Copyright (c) 1989 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.
*
* @(#)pathnames.h 5.2 (Berkeley) 6/1/90
*/
 
#define _PATH_DEF ".termcap /usr/share/misc/termcap"
/ports/trunk/unix/libterm/sgtty.h
0,0 → 1,116
/*
* Structure for stty and gtty system calls.
*/
 
struct sgttyb {
char sg_ispeed; /* input speed */
char sg_ospeed; /* output speed */
char sg_erase; /* erase character */
char sg_kill; /* kill character */
int sg_flags; /* mode flags */
};
 
/*
* List of special characters
*/
struct tchars {
char t_intrc; /* interrupt */
char t_quitc; /* quit */
char t_startc; /* start output */
char t_stopc; /* stop output */
char t_eofc; /* end-of-file */
char t_brkc; /* input delimiter (like nl) */
};
 
/*
* Modes
*/
#define TANDEM 01
#define CBREAK 02
#define LCASE 04
#define ECHO 010
#define CRMOD 020
#define RAW 040
#define ODDP 0100
#define EVENP 0200
#define ANYP 0300
#define NLDELAY 001400
#define TBDELAY 006000
#define XTABS 06000
#define CRDELAY 030000
#define VTDELAY 040000
#define BSDELAY 0100000
#define ALLDELAY 0177400
 
/*
* Delay algorithms
*/
#define CR0 0
#define CR1 010000
#define CR2 020000
#define CR3 030000
#define NL0 0
#define NL1 000400
#define NL2 001000
#define NL3 001400
#define TAB0 0
#define TAB1 002000
#define TAB2 004000
#define FF0 0
#define FF1 040000
#define BS0 0
#define BS1 0100000
 
/*
* Speeds
*/
#define B0 0
#define B50 1
#define B75 2
#define B110 3
#define B134 4
#define B150 5
#define B200 6
#define B300 7
#define B600 8
#define B1200 9
#define B1800 10
#define B2400 11
#define B4800 12
#define B9600 13
#define EXTA 14
#define EXTB 15
 
/*
* tty ioctl commands
*/
#define TIOCGETD (('t'<<8)|0)
#define TIOCSETD (('t'<<8)|1)
#define TIOCHPCL (('t'<<8)|2)
#define TIOCMODG (('t'<<8)|3)
#define TIOCMODS (('t'<<8)|4)
#define TIOCGETP (('t'<<8)|8)
#define TIOCSETP (('t'<<8)|9)
#define TIOCSETN (('t'<<8)|10)
#define TIOCEXCL (('t'<<8)|13)
#define TIOCNXCL (('t'<<8)|14)
#define TIOHMODE (('t'<<8)|15)
#define TIOCTSTP (('t'<<8)|16)
#define TIOCSETC (('t'<<8)|17)
#define TIOCGETC (('t'<<8)|18)
#define DIOCLSTN (('d'<<8)|1)
#define DIOCNTRL (('d'<<8)|2)
#define DIOCMPX (('d'<<8)|3)
#define DIOCNMPX (('d'<<8)|4)
#define DIOCSCALL (('d'<<8)|5)
#define DIOCRCALL (('d'<<8)|6)
#define DIOCPGRP (('d'<<8)|7)
#define DIOCGETP (('d'<<8)|8)
#define DIOCSETP (('d'<<8)|9)
#define DIOCLOSE (('d'<<8)|10)
#define DIOCTIME (('d'<<8)|11)
#define DIOCRESET (('d'<<8)|12)
#define FIOCLEX (('f'<<8)|1)
#define FIONCLEX (('f'<<8)|2)
#define MXLSTN (('x'<<8)|1)
#define MXNBLK (('x'<<8)|2)
/ports/trunk/unix/libterm/tags
0,0 → 1,12
CTRL tgoto.c /^#define CTRL(c) ((c) & 037)$/
tdecode termcap.c /^tdecode(str, area)$/
tfindent termcap.c /^tfindent(bp, name)$/
tgetent termcap.c /^tgetent(bp, name)$/
tgetflag termcap.c /^tgetflag(id)$/
tgetnum termcap.c /^tgetnum(id)$/
tgetstr termcap.c /^tgetstr(id, area)$/
tgoto tgoto.c /^tgoto(CM, destcol, destline)$/
tnamatch termcap.c /^tnamatch(np)$/
tnchktc termcap.c /^tnchktc()$/
tputs tputs.c /^tputs(cp, affcnt, outc)$/
tskip termcap.c /^tskip(bp)$/
/ports/trunk/unix/libterm/termcap.3
0,0 → 1,254
.\" Copyright (c) 1980, 1991 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.
.\"
.\" @(#)termcap.3 6.6 (Berkeley) 4/19/91
.\"
.Dd April 19, 1991
.Dt TERMCAP 3
.Os BSD 4
.Sh NAME
.Nm tgetent ,
.Nm tgetnum ,
.Nm tgetflag ,
.Nm tgetstr ,
.Nm tgoto ,
.Nm tputs
.Nd terminal independent operation routines
.Sh SYNOPSIS
.Vt char PC;
.Vt char *BC;
.Vt char *UP;
.Vt short ospeed;
.Fn tgetent "char *bp" "char *name"
.Fn tgetnum "char *id"
.Fn tgetflag "char *id"
.Ft char *
.Fn tgetstr "char *id" "char *area"
.Ft char *
.Fn tgoto "char *cm" destcol destline
.Fn tputs "register char *cp" "int affcnt" "int (*outc)()"
.Sh DESCRIPTION
These functions extract and use capabilities from a terminal capability data
base, usually
.Pa /usr/share/misc/termcap ,
the format of which is described in
.Xr termcap 5 .
These are low level routines;
see
.Xr curses 3
for a higher level package.
.Pp
The
.Fn tgetent
function
extracts the entry for terminal
.Fa name
into the buffer at
.Fa bp .
The
.Fa bp
argument
should be a character buffer of size
1024 and must be retained through all subsequent calls to
.Fn tgetnum ,
.Fn tgetflag ,
and
.Fn tgetstr .
The
.Fn tgetent
function
returns \-1 if none of the
.Nm termcap
data base files could be opened,
0 if the terminal name given does not have an entry,
and 1 if all goes well.
It will look in the environment for a
.Ev TERMCAP
variable.
If found, and the value does not begin with a slash,
and the terminal type
.Fa name
is the same as the environment string
.Ev TERM ,
the
.Ev TERMCAP
string is used instead of reading a
.Nm termcap
file.
If it does begin with a slash, the string is used as a path name
of the
.Nm termcap
file to search.
If
.Ev TERMCAP
does not begin with a slash and
.Fa name
is different from
.Ev TERM ,
.Fn tgetent
searches the files
.Pa $HOME/.termcap
and
.Pa /usr/share/misc/termcap ,
in that order, unless the environment variable
.Ev TERMPATH
exists,
in which case it specifies a list of file pathnames
(separated by spaces or colons) to be searched instead.
Whenever multiple files are searched and a
.Sy tc
field occurs in the requested entry, the entry it names must be found
in the same file or one of the succeeding files.
This can speed up entry into programs that call
.Fn tgetent ,
as well as help debug new terminal descriptions
or make one for your terminal if you can't write the file
.Pa /usr/share/misc/termcap .
.Pp
The
.Fn tgetnum
function
gets the numeric value of capability
.Fa id ,
returning \-1 if is not given for the terminal.
The
.Fn tgetflag
function
returns 1 if the specified capability is present in
the terminal's entry, 0 if it is not.
The
.Fn tgetstr
function
returns the string value of the capability
.Fa id ,
places it in the buffer at
.Fa area ,
and advances the
.Fa area
pointer.
It decodes the abbreviations for this field described in
.Xr termcap 5 ,
except for cursor addressing and padding information.
The
.Fn tgetstr
function
returns
.Dv NULL
if the capability was not found.
.Pp
The
.Fn tgoto
function
returns a cursor addressing string decoded from
.Fa cm
to go to column
.Fa destcol
in line
.Fa destline .
It uses the external variables
.Va UP
(from the
.Sy up
capability)
and
.Va BC
(if
.Sy bc
is given rather than
.Sy bs )
if necessary to avoid placing
.Sy \en ,
.Sy ^D
or
.Sy ^@
in
the returned string.
(Programs which call
.Fn tgoto
should be sure to turn off the
.Dv XTABS
bit(s),
since
.Fn tgoto
may now output a tab.
Note that programs using termcap should in general turn off
.Dv XTABS
anyway since some terminals use control-I for other functions,
such as nondestructive space.)
If a
.Sy %
sequence is given which is not understood, then
.Fn tgoto
returns
.Pq Dv OOPS .
.Pp
The
.Fn tputs
function
decodes the leading padding information of the string
.Fa cp ;
.Fa affcnt
gives the number of lines affected by the operation, or 1 if this is
not applicable,
.Fa outc
is a routine which is called with each character in turn.
The external variable
.Va ospeed
should contain the output speed of the terminal as encoded by
.Xr stty 3 .
The external variable
.Va PC
should contain a pad character to be used (from the
.SY pc
capability)
if a null
.Pq Sy ^@
is inappropriate.
.Sh FILES
.Bl -tag -width /usr/share/misc/termcap -compact
.It Pa /usr/lib/libtermcap.a
.Fl l Ar ltermcap
library (also known as
.Fl l Ar ltermlib )
.It Pa /usr/share/misc/termcap
standard terminal capability data base
.It Pa $HOME/.termcap
user's terminal capability data base
.El
.Sh SEE ALSO
.Xr ex 1 ,
.Xr curses 3 ,
.Xr termcap 5
.Sh HISTORY
The
.Nm
functions appeared in
.Bx 4.0 .
/ports/trunk/unix/libterm/termcap.c
0,0 → 1,434
/*
* Copyright (c) 1980 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.
*/
 
#ifndef lint
static char sccsid[] = "@(#)termcap.c 5.6 (Berkeley) 7/3/92";
#endif /* not lint */
 
#define BUFSIZ 1024
#define MAXHOP 32 /* max number of tc= indirections */
#define PBUFSIZ 512 /* max length of filename path */
#define PVECSIZ 32 /* max number of names in path */
 
#include <ctype.h>
#include <stdlib.h>
#include "pathnames.h"
 
/*
* 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.
*/
 
static char *tbuf;
static int hopcount; /* detect infinite loops in termcap, init 0 */
static char pathbuf[PBUFSIZ]; /* holds raw path of filenames */
static char *pathvec[PVECSIZ]; /* to point to names in pathbuf */
static char **pvec; /* holds usable tail of path vector */
 
static char *tdecode __P((char *, char **));
static char *tskip __P ((char *));
 
/*
* Get an entry for terminal name in buffer bp from the termcap file.
*/
tgetent(bp, name)
char *bp, *name;
{
register char *p;
register char *cp;
register int c;
char *term, *home, *termpath;
char **fname = pathvec;
 
pvec = pathvec;
tbuf = bp;
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 */
p += strlen(home); /* path, looking in */
strcpy(pathbuf, home); /* $HOME first */
*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 */
 
*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 != '/') {
tbuf = cp;
c = tnamatch(name);
tbuf = bp;
if (c) {
strcpy(bp,cp);
return (tnchktc());
}
}
return (tfindent(bp, name)); /* find terminal entry in path */
}
 
/*
* tfindent - reads through the list of files in pathvec as if they were one
* continuous file searching for terminal entries along the way. It will
* participate in indirect recursion if the call to tnchktc() finds a tc=
* field, which is only searched for in the current file and files ocurring
* after it in pathvec. The usable part of this vector is kept in the global
* variable pvec. Terminal entries may not be broken across files. Parse is
* very rudimentary; we just notice escaped newlines.
*/
tfindent(bp, name)
char *bp, *name;
{
register char *cp;
register int c;
register int i, cnt;
char ibuf[BUFSIZ];
int opencnt = 0;
int tf;
 
tbuf = bp;
nextfile:
i = cnt = 0;
while (*pvec && (tf = open(*pvec, 0)) < 0)
pvec++;
if (!*pvec)
return (opencnt ? 0 : -1);
opencnt++;
for (;;) {
cp = bp;
for (;;) {
if (i == cnt) {
cnt = read(tf, ibuf, BUFSIZ);
if (cnt <= 0) {
close(tf);
pvec++;
goto nextfile;
}
i = 0;
}
c = ibuf[i++];
if (c == '\n') {
if (cp > bp && cp[-1] == '\\'){
cp--;
continue;
}
break;
}
if (cp >= bp+BUFSIZ) {
write(2,"Termcap entry too long\n", 23);
break;
} else
*cp++ = c;
}
*cp = 0;
 
/*
* The real work for the match.
*/
if (tnamatch(name)) {
close(tf);
return(tnchktc());
}
}
}
 
/*
* tnchktc: check the last entry, see if it's tc=xxx. If so,
* recursively find xxx and append that entry (minus the names)
* to take the place of the tc=xxx entry. This allows termcap
* entries to say "like an HP2621 but doesn't turn on the labels".
* Note that this works because of the left to right scan.
*/
tnchktc()
{
register char *p, *q;
char tcname[16]; /* name of similar terminal */
char tcbuf[BUFSIZ];
char *holdtbuf = tbuf;
int l;
 
p = tbuf + strlen(tbuf) - 2; /* before the last colon */
while (*--p != ':')
if (p<tbuf) {
write(2, "Bad termcap entry\n", 18);
return (0);
}
p++;
/* p now points to beginning of last field */
if (p[0] != 't' || p[1] != 'c')
return(1);
strcpy(tcname,p+3);
q = tcname;
while (*q && *q != ':')
q++;
*q = 0;
if (++hopcount > MAXHOP) {
write(2, "Infinite tc= loop\n", 18);
return (0);
}
if (tfindent(tcbuf, tcname) != 1) {
hopcount = 0; /* unwind recursion */
return(0);
}
for (q=tcbuf; *q != ':'; q++)
;
l = p - holdtbuf + strlen(q);
if (l > BUFSIZ) {
write(2, "Termcap entry too long\n", 23);
q[BUFSIZ - (p-tbuf)] = 0;
}
strcpy(p, q+1);
tbuf = holdtbuf;
hopcount = 0; /* unwind recursion */
return(1);
}
 
/*
* Tnamatch deals with name matching. The first field of the termcap
* entry is a sequence of names separated by |'s, so we compare
* against each such name. The normal : terminator after the last
* name (before the first field) stops us.
*/
tnamatch(np)
char *np;
{
register char *Np, *Bp;
 
Bp = tbuf;
if (*Bp == '#')
return(0);
for (;;) {
for (Np = np; *Np && *Bp == *Np; Bp++, Np++)
continue;
if (*Np == 0 && (*Bp == '|' || *Bp == ':' || *Bp == 0))
return (1);
while (*Bp && *Bp != ':' && *Bp != '|')
Bp++;
if (*Bp == 0 || *Bp == ':')
return (0);
Bp++;
}
}
 
/*
* Skip to the next field. Notice that this is very dumb, not
* knowing about \: escapes or any such. If necessary, :'s can be put
* into the termcap file in octal.
*/
static char *
tskip(bp)
register char *bp;
{
 
while (*bp && *bp != ':')
bp++;
if (*bp == ':')
bp++;
return (bp);
}
 
/*
* Return the (numeric) option id.
* Numeric options look like
* li#80
* i.e. the option string is separated from the numeric value by
* a # character. If the option is not found we return -1.
* Note that we handle octal numbers beginning with 0.
*/
tgetnum(id)
char *id;
{
register int i, base;
register char *bp = tbuf;
 
for (;;) {
bp = tskip(bp);
if (*bp == 0)
return (-1);
if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
continue;
if (*bp == '@')
return(-1);
if (*bp != '#')
continue;
bp++;
base = 10;
if (*bp == '0')
base = 8;
i = 0;
while (isdigit(*bp))
i *= base, i += *bp++ - '0';
return (i);
}
}
 
/*
* Handle a flag option.
* Flag options are given "naked", i.e. followed by a : or the end
* of the buffer. Return 1 if we find the option, or 0 if it is
* not given.
*/
tgetflag(id)
char *id;
{
register char *bp = tbuf;
 
for (;;) {
bp = tskip(bp);
if (!*bp)
return (0);
if (*bp++ == id[0] && *bp != 0 && *bp++ == id[1]) {
if (!*bp || *bp == ':')
return (1);
else if (*bp == '@')
return(0);
}
}
}
 
/*
* Get a string valued option.
* These are given as
* cl=^Z
* Much decoding is done on the strings, and the strings are
* placed in area, which is a ref parameter which is updated.
* No checking on area overflow.
*/
char *
tgetstr(id, area)
char *id, **area;
{
register char *bp = tbuf;
 
for (;;) {
bp = tskip(bp);
if (!*bp)
return (0);
if (*bp++ != id[0] || *bp == 0 || *bp++ != id[1])
continue;
if (*bp == '@')
return(0);
if (*bp != '=')
continue;
bp++;
return (tdecode(bp, area));
}
}
 
/*
* Tdecode does the grung work to decode the
* string capability escapes.
*/
static char *
tdecode(str, area)
register char *str;
char **area;
{
register char *cp;
register int c;
register char *dp;
int i;
 
cp = *area;
while ((c = *str++) && c != ':') {
switch (c) {
 
case '^':
c = *str++ & 037;
break;
 
case '\\':
dp = "E\033^^\\\\::n\nr\rt\tb\bf\f";
c = *str++;
nextc:
if (*dp++ == c) {
c = *dp++;
break;
}
dp++;
if (*dp)
goto nextc;
if (isdigit(c)) {
c -= '0', i = 2;
do
c <<= 3, c |= *str++ - '0';
while (--i && isdigit(*str));
}
break;
}
*cp++ = c;
}
*cp++ = 0;
str = *area;
*area = cp;
return (str);
}
/ports/trunk/unix/libterm/test/tc1.c
0,0 → 1,63
/*-
* Copyright (c) 1983 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.
*/
 
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
 
#ifndef lint
static char sccsid[] = "@(#)tc1.c 5.3 (Berkeley) 4/12/91";
#endif /* not lint */
 
/*
* tc1 [term]
* dummy program to test termlib.
* gets entry, counts it, and prints it.
*/
#include <stdio.h>
char buf[1024];
char *getenv();
 
main(argc, argv) char **argv; {
char *p;
int rc;
 
if (argc < 2)
p = getenv("TERM");
else
p = argv[1];
rc = tgetent(buf,p);
printf("tgetent returns %d, len=%d, text=\n'%s'\n",rc,strlen(buf),buf);
}
/ports/trunk/unix/libterm/test/tc2.c
0,0 → 1,90
/*-
* Copyright (c) 1983 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.
*/
 
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
 
#ifndef lint
static char sccsid[] = "@(#)tc2.c 5.3 (Berkeley) 4/12/91";
#endif /* not lint */
 
/*
* tc2 [term]
* Dummy program to test out termlib.
* Commands are "tcc\n" where t is type (s for string, f for flag,
* or n for number) and cc is the name of the capability.
*/
#include <stdio.h>
char buf[1024];
char *getenv(), *tgetstr();
 
main(argc, argv) char **argv; {
char *p, *q;
int rc;
char b[3], c;
char area[200];
 
if (argc < 2)
p = getenv("TERM");
else
p = argv[1];
rc = tgetent(buf,p);
for (;;) {
c = getchar();
if (c < 0)
exit(0);
b[0] = getchar();
if (b[0] < ' ')
exit(0);
b[1] = getchar();
b[2] = 0;
getchar();
switch(c) {
case 'f':
printf("%s: %d\n",b,tgetflag(b));
break;
case 'n':
printf("%s: %d\n",b,tgetnum(b));
break;
case 's':
q = area;
printf("%s: %s\n",b,tgetstr(b,&q));
break;
default:
exit(0);
}
}
}
/ports/trunk/unix/libterm/test/tc3.c
0,0 → 1,112
/*-
* Copyright (c) 1983 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.
*/
 
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1983 The Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
 
#ifndef lint
static char sccsid[] = "@(#)tc3.c 5.4 (Berkeley) 4/12/91";
#endif /* not lint */
 
/*
* tc3 [term]
* Dummy program to test out termlib. Input two numbers (row and col)
* and it prints out the tgoto string generated.
*/
#include <stdio.h>
char buf[1024];
char *getenv(), *tgetstr();
char *rdchar();
char *tgoto();
char *CM;
char cmbuff[30];
char *x;
char *UP;
char *tgout;
 
main(argc, argv) char **argv; {
char *p;
int rc;
int row, col;
 
if (argc < 2)
p = getenv("TERM");
else
p = argv[1];
rc = tgetent(buf,p);
x = cmbuff;
UP = tgetstr("up", &x);
printf("UP = %x = ", UP); pr(UP); printf("\n");
if (UP && *UP==0)
UP = 0;
CM = tgetstr("cm", &x);
printf("CM = "); pr(CM); printf("\n");
for (;;) {
if (scanf("%d %d", &row, &col) < 2)
exit(0);
tgout = tgoto(CM, col, row);
pr(tgout);
printf("\n");
}
}
 
pr(p)
register char *p;
{
for (; *p; p++)
printf("%s", rdchar(*p));
}
 
/*
* rdchar() returns a readable representation of an ASCII character
* using ^ for control, ' for meta.
*/
#include <ctype.h>
char *rdchar(c)
char c;
{
static char ret[4];
register char *p = ret;
 
if ((c&0377) > 0177)
*p++ = '\'';
c &= 0177;
if (!isprint(c))
*p++ = '^';
*p++ = (isprint(c) ? c : c^0100);
*p = 0;
return (ret);
}
/ports/trunk/unix/libterm/tgoto.c
0,0 → 1,207
/*
* Copyright (c) 1980 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.
*/
 
#ifndef lint
static char sccsid[] = "@(#)tgoto.c 5.4 (Berkeley) 6/1/90";
#endif /* not lint */
 
#define CTRL(c) ((c) & 037)
 
#define MAXRETURNSIZE 64
 
char *UP;
char *BC;
 
/*
* Routine to perform cursor addressing.
* CM is a string containing printf type escapes to allow
* cursor addressing. We start out ready to print the destination
* line, and switch each time we print row or column.
* The following escapes are defined for substituting row/column:
*
* %d as in printf
* %2 like %2d
* %3 like %3d
* %. gives %c hacking special case characters
* %+x like %c but adding x first
*
* The codes below affect the state but don't use up a value.
*
* %>xy if value > x add y
* %r reverses row/column
* %i increments row/column (for one origin indexing)
* %% gives %
* %B BCD (2 decimal digits encoded in one byte)
* %D Delta Data (backwards bcd)
*
* all other characters are ``self-inserting''.
*/
char *
tgoto(CM, destcol, destline)
char *CM;
int destcol, destline;
{
static char result[MAXRETURNSIZE];
static char added[10];
char *cp = CM;
register char *dp = result;
register int c;
int oncol = 0;
register int which = destline;
 
if (cp == 0) {
toohard:
/*
* ``We don't do that under BOZO's big top''
*/
return ("OOPS");
}
added[0] = 0;
while (c = *cp++) {
if (c != '%') {
*dp++ = c;
continue;
}
switch (c = *cp++) {
 
#ifdef CM_N
case 'n':
destcol ^= 0140;
destline ^= 0140;
goto setwhich;
#endif
 
case 'd':
if (which < 10)
goto one;
if (which < 100)
goto two;
/* fall into... */
 
case '3':
*dp++ = (which / 100) | '0';
which %= 100;
/* fall into... */
 
case '2':
two:
*dp++ = which / 10 | '0';
one:
*dp++ = which % 10 | '0';
swap:
oncol = 1 - oncol;
setwhich:
which = oncol ? destcol : destline;
continue;
 
#ifdef CM_GT
case '>':
if (which > *cp++)
which += *cp++;
else
cp++;
continue;
#endif
 
case '+':
which += *cp++;
/* fall into... */
 
case '.':
casedot:
/*
* This code is worth scratching your head at for a
* while. The idea is that various weird things can
* happen to nulls, EOT's, tabs, and newlines by the
* tty driver, arpanet, and so on, so we don't send
* them if we can help it.
*
* Tab is taken out to get Ann Arbors to work, otherwise
* when they go to column 9 we increment which is wrong
* because bcd isn't continuous. We should take out
* the rest too, or run the thing through more than
* once until it doesn't make any of these, but that
* would make termlib (and hence pdp-11 ex) bigger,
* and also somewhat slower. This requires all
* programs which use termlib to stty tabs so they
* don't get expanded. They should do this anyway
* because some terminals use ^I for other things,
* like nondestructive space.
*/
if (which == 0 || which == CTRL('d') || /* which == '\t' || */ which == '\n') {
if (oncol || UP) /* Assumption: backspace works */
/*
* Loop needed because newline happens
* to be the successor of tab.
*/
do {
strcat(added, oncol ? (BC ? BC : "\b") : UP);
which++;
} while (which == '\n');
}
*dp++ = which;
goto swap;
 
case 'r':
oncol = 1;
goto setwhich;
 
case 'i':
destcol++;
destline++;
which++;
continue;
 
case '%':
*dp++ = c;
continue;
 
#ifdef CM_B
case 'B':
which = (which/10 << 4) + which%10;
continue;
#endif
 
#ifdef CM_D
case 'D':
which = which - 2 * (which%16);
continue;
#endif
 
default:
goto toohard;
}
}
strcpy(dp, added);
return (result);
}
/ports/trunk/unix/libterm/tputs.c
0,0 → 1,123
/*
* Copyright (c) 1980 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.
*/
 
#ifndef lint
static char sccsid[] = "@(#)tputs.c 5.3 (Berkeley) 6/1/90";
#endif /* not lint */
 
#include "sgtty.h"
#include <ctype.h>
 
/*
* The following array gives the number of tens of milliseconds per
* character for each speed as returned by gtty. Thus since 300
* baud returns a 7, there are 33.3 milliseconds per char at 300 baud.
*/
static
short tmspc10[] = {
0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5
};
 
short ospeed;
char PC;
 
/*
* Put the character string cp out, with padding.
* 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)();
{
register int i = 0;
register int mspc10;
 
if (cp == 0)
return;
 
/*
* Convert the number representing the delay.
*/
if (isdigit(*cp)) {
do
i = i * 10 + *cp++ - '0';
while (isdigit(*cp));
}
i *= 10;
if (*cp == '.') {
cp++;
if (isdigit(*cp))
i += *cp - '0';
/*
* Only one digit to the right of the decimal point.
*/
while (isdigit(*cp))
cp++;
}
 
/*
* If the delay is followed by a `*', then
* multiply by the affected lines count.
*/
if (*cp == '*')
cp++, i *= affcnt;
 
/*
* The guts of the string.
*/
while (*cp)
(*outc)(*cp++);
 
/*
* If no delay needed, or output speed is
* not comprehensible, then don't try to delay.
*/
if (i == 0)
return;
if (ospeed <= 0 || ospeed >= (sizeof tmspc10 / sizeof tmspc10[0]))
return;
 
/*
* Round up by a half a character frame,
* and then do the delay.
* Too bad there are no user program accessible programmed delays.
* Transmitting pad characters slows many
* terminals down and also loads the system.
*/
mspc10 = tmspc10[ospeed];
i += mspc10 / 2;
for (i /= mspc10; i > 0; i--)
(*outc)(PC);
}