1 ;# $RCSfile: termcap.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:16 $
5 ;# ioctl(TTY,$TIOCGETP,$foo);
6 ;# ($ispeed,$ospeed) = unpack('cc',$foo);
7 ;# require 'termcap.pl';
8 ;# &Tgetent('vt100'); # sets $TC{'cm'}, etc.
9 ;# &Tputs(&Tgoto($TC{'cm'},$col,$row), 0, 'FILEHANDLE');
10 ;# &Tputs($TC{'dl'},$affcnt,'FILEHANDLE');
14 local($TERMCAP,$_,$entry,$loop,$field);
16 warn "Tgetent: no ospeed set" unless $ospeed;
17 foreach $key (keys %TC) {
20 $TERM = $ENV{'TERM'} unless $TERM;
21 $TERM =~ s/(\W)/\\$1/g;
22 $TERMCAP = $ENV{'TERMCAP'};
23 $TERMCAP = '/etc/termcap' unless $TERMCAP;
24 if ($TERMCAP !~ m:^/:) {
25 if ($TERMCAP !~ /(^|\|)$TERM[:\|]/) {
26 $TERMCAP = '/etc/termcap';
29 if ($TERMCAP =~ m:^/:) {
33 open(TERMCAP,'<$TERMCAP') || die \"Can't open $TERMCAP\";
37 if (/(^|\\|)${TERM}[:\\|]/) {
39 while (chop eq '\\\\') {
51 } while s/:tc=([^:]+):/:/ && ($TERM = $1);
55 foreach $field (split(/:[\s:\\]*/,$TERMCAP)) {
56 if ($field =~ /^\w\w$/) {
59 elsif ($field =~ /^(\w\w)#(.*)/) {
60 $TC{$1} = $2 if $TC{$1} eq '';
62 elsif ($field =~ /^(\w\w)=(.*)/) {
66 s/\\(200)/pack('c',0)/eg; # NUL character
67 s/\\(0\d\d)/pack('c',oct($1))/eg; # octal
68 s/\\(0x[0-9A-Fa-f][0-9A-Fa-f])/pack('c',hex($1))/eg; # hex
69 s/\\(\d\d\d)/pack('c',$1 & 0177)/eg;
77 s/\^(.)/pack('c',ord($1) & 31)/eg;
80 $TC{$entry} = $_ if $TC{$entry} eq '';
83 $TC{'pc'} = "\0" if $TC{'pc'} eq '';
84 $TC{'bc'} = "\b" if $TC{'bc'} eq '';
87 @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);
90 local($string,$affcnt,$FH) = @_;
92 if ($string =~ /(^[\d.]+)(\*?)(.*)$/) {
96 $decr = $Tputs[$ospeed];
99 $string .= $TC{'pc'} x ($ms / $decr);
102 print $FH $string if $FH;
107 local($string) = shift(@_);
110 local($code,$tmp) = @_;
114 while ($string =~ /^([^%]*)%(.)(.*)/) {
119 $result .= sprintf("%d",shift(@tmp));
121 elsif ($code eq '.') {
123 if ($tmp == 0 || $tmp == 4 || $tmp == 10) {
125 ++$tmp, $after .= $TC{'up'} if $TC{'up'};
128 ++$tmp, $after .= $TC{'bc'};
131 $result .= sprintf("%c",$tmp);
134 elsif ($code eq '+') {
135 $result .= sprintf("%c",shift(@tmp)+ord($string));
136 $string = substr($string,1,99);
139 elsif ($code eq 'r') {
144 elsif ($code eq '>') {
145 ($code,$tmp,$string) = unpack("CCa99",$string);
146 if ($tmp[$[] > $code) {
150 elsif ($code eq '2') {
151 $result .= sprintf("%02d",shift(@tmp));
154 elsif ($code eq '3') {
155 $result .= sprintf("%03d",shift(@tmp));
158 elsif ($code eq 'i') {
160 @tmp = ($code+1,$tmp+1);
166 $result . $string . $after;