terminfo

Tony L. Hansen hansen at pegasus.UUCP
Fri Sep 16 13:51:58 AEST 1988


<> = me
< = Peter da Silva

< Fine. I've got some more questions, if you don't mind...

No problem.

<> The free-form input format and longer names, however, make it considerably
<> harder (and slower) to interpret the input file.

< Nonsense. I wrote a termcap emulation for CP/M in 1981 that supported long
< names. I didn't actually time it, but since the code I wrote did a strcmp
< type search (abort as soon as a match fails) it might even be faster than
< a two-byte match (which is what you seem to be implying termcap does).

A two byte match done with && is considerably faster than calling strcmp().
Both abort as soon as a match fails and the first is done without the
overhead of a function call.

Parsing the data file is not the only problem with termcap, however. The
algorithm for searching for a given capability, after having parsed the
entire entry into memory, is an n^2 algorithm. The search for each
capability starts over again at the very beginning of the entry. Given that
curses pulls in a large majority of the boolean, numeric and string
capabilities, this searching for all of the capabilities overshadows the
parsing of the data file.

< Also, there isn't much you can do to speed things up that will beat having
< a TERMCAP environment entry.

You haven't been doing your homework. Benchmarks run by Mark Horton showed
that the linear algorithms used by the terminfo library and doing a single
read from the file system were considerably faster even than the use of a
TERMCAP environment variable.

This was all reported in the 1982 Usenix proceedings.

<> 5) I want to define my own capabilites
<> The user defined terminfo capabilities user0 to user9 were added in
<> SysVr3.1. You're free to do with these as you will.

<I want to call my new capability 'Fred'.

This I can't help you with.

< 5a) I want my users to be able to change their terminfo entries quickly
< and easily. Right now they have to create their own terminfo directory
< tree, compile it, and remember to change back when they want to use the
< standard ones. With TERMCAP they could just edit their environment. No
< need to fill /usr/tmp up with little terminfo files.

Here is chgtinfo.sh:
	TERMINFO=/tmp/tinfo.$$; export TERMINFO
	T1=`expr "$TERM" : '\(.\)'`
	mkdir $TERMINFO $TERMINFO/$T1
	cp /usr/lib/terminfo/$T1/$TERM $TERMINFO/$T1
	echo "${TERM}X," "$@" "use=$TERM," > $TERMINFO/ti
	tic $TERMINFO/ti > /dev/null 2>&1
	ln $TERMINFO/$T1/${TERM}X $TERMINFO/$T1/$TERM
	echo $TERMINFO

One modifies their terminfo entry like this (this adds auto_left_margin and
auto_right_margin to the current terminfo entry):

	TERMINFO=`chgtinfo am, bw,`

To unset this, one does this:

	rm -r $TERMINFO
	unset TERMINFO

This is both quick and easy. Especially under System V release 3 where tic
is 3 to 10 times faster than the System V release 2 version of tic.

With both termcap and terminfo, you have to remember to change back when you
want to use the standard ones. I don't see an advantage on other side.

And how do you usually edit your environment variable TERMCAP? Unless you
have the ksh, you usually have to type it all in, do it via a separate
program, or writing the variable to a temp file and using an editor such as
vi on that temp file, then read the temp file back into your environment.

< 10) Use the terminfo routines in other environments. I can define a
< gamecap file and use the termcap routines to access it. The entries in
< there don't have to have anything to do with terminals.

I agree that the routines could be made usable in other environments. I
believe that your use of the termcap routines for gamecap would require
either having the source avaiable or doing various tricks with the
environment.

Actually, better yet would be a standard set of database routines available
on all systems.

< 11) Use standard UNIX tools on a terminfo file. What's the quickest way to
< get a listing of all the terminals supported under terminfo? I don't know
< any easy ones.

The quickest way that I know of is:

	ls -C /usr/lib/terminfo/?

Egrep also works fine on the files under /usr/lib/terminfo.

					Tony Hansen
				att!pegasus!hansen, attmail!tony



More information about the Comp.unix.wizards mailing list