;# $RCSfile: termcap.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:16 $
# This library is no longer being maintained, and is included for backward
# compatibility with Perl 4 programs which may require it.
# In particular, this should not be used as an example of modern Perl
# programming techniques.
# Suggested alternative: Term::Cap
;# ioctl(TTY,$TIOCGETP,$foo);
;# ($ispeed,$ospeed) = unpack('cc',$foo);
;# &Tgetent('vt100'); # sets $TC{'cm'}, etc.
;# &Tputs(&Tgoto($TC{'cm'},$col,$row), 0, 'FILEHANDLE');
;# &Tputs($TC{'dl'},$affcnt,'FILEHANDLE');
local($TERMCAP,$_,$entry,$loop,$field);
# warn "Tgetent: no ospeed set" unless $ospeed;
foreach $key (keys %TC) {
$TERM = $ENV{'TERM'} unless $TERM;
$TERMCAP = $ENV{'TERMCAP'};
$TERMCAP = '/etc/termcap' unless $TERMCAP;
if ($TERMCAP !~ /(^|\|)$TERM[:\|]/) {
$TERMCAP = '/etc/termcap';
open(TERMCAP,'<$TERMCAP') || die \"Can't open $TERMCAP\";
if (/(^|\\|)${TERM}[:\\|]/) {
} while s/:tc=([^:]+):/:/ && ($TERM = $1);
foreach $field (split(/:[\s:\\]*/,$TERMCAP)) {
if ($field =~ /^\w\w$/) {
elsif ($field =~ /^(\w\w)#(.*)/) {
$TC{$1} = $2 if $TC{$1} eq '';
elsif ($field =~ /^(\w\w)=(.*)/) {
s/\\(200)/pack('c',0)/eg; # NUL character
s/\\(0\d\d)/pack('c',oct($1))/eg; # octal
s/\\(0x[0-9A-Fa-f][0-9A-Fa-f])/pack('c',hex($1))/eg; # hex
s/\\(\d\d\d)/pack('c',$1 & 0177)/eg;
s/\^(.)/pack('c',ord($1) & 31)/eg;
$TC{$entry} = $_ if $TC{$entry} eq '';
$TC{'pc'} = "\0" if $TC{'pc'} eq '';
$TC{'bc'} = "\b" if $TC{'bc'} eq '';
@Tputs = (0,200,133.3,90.9,74.3,66.7,50,33.3,16.7,8.3,5.5,4.1,2,1,.5,.2);
local($string,$affcnt,$FH) = @_;
if ($string =~ /(^[\d.]+)(\*?)(.*)$/) {
$string .= $TC{'pc'} x
($ms / $decr);
print $FH $string if $FH;
local($string) = shift(@_);
while ($string =~ /^([^%]*)%(.)(.*)/) {
$result .= sprintf("%d",shift(@tmp));
if ($tmp == 0 || $tmp == 4 || $tmp == 10) {
++$tmp, $after .= $TC{'up'} if $TC{'up'};
++$tmp, $after .= $TC{'bc'};
$result .= sprintf("%c",$tmp);
$result .= sprintf("%c",shift(@tmp)+ord($string));
$string = substr($string,1,99);
($code,$tmp,$string) = unpack("CCa99",$string);
$result .= sprintf("%02d",shift(@tmp));
$result .= sprintf("%03d",shift(@tmp));
$result . $string . $after;