1 ;# $RCSfile: termcap.pl,v $$Revision: 4.1 $$Date: 92/08/07 18:24:16 $
3 # This library is no longer being maintained, and is included for backward
4 # compatibility with Perl 4 programs which may require it.
6 # In particular, this should not be used as an example of modern Perl
7 # programming techniques.
9 # Suggested alternative: Term::Cap
13 ;# require 'ioctl.pl';
14 ;# ioctl(TTY,$TIOCGETP,$foo);
15 ;# ($ispeed,$ospeed) = unpack('cc',$foo);
16 ;# require 'termcap.pl';
17 ;# &Tgetent('vt100'); # sets $TC{'cm'}, etc.
18 ;# &Tputs(&Tgoto($TC{'cm'},$col,$row), 0, 'FILEHANDLE');
19 ;# &Tputs($TC{'dl'},$affcnt,'FILEHANDLE');
23 local($TERMCAP,$_,$entry,$loop,$field);
25 # warn "Tgetent: no ospeed set" unless $ospeed;
26 foreach $key (keys %TC) {
29 $TERM = $ENV{'TERM'} unless $TERM;
30 $TERM =~ s/(\W)/\\$1/g;
31 $TERMCAP = $ENV{'TERMCAP'};
32 $TERMCAP = '/etc/termcap' unless $TERMCAP;
33 if ($TERMCAP !~ m:^/:) {
34 if ($TERMCAP !~ /(^|\|)$TERM[:\|]/) {
35 $TERMCAP = '/etc/termcap';
38 if ($TERMCAP =~ m:^/:) {
42 open(TERMCAP,'<$TERMCAP') || die \"Can't open $TERMCAP\";
46 if (/(^|\\|)${TERM}[:\\|]/) {
48 while (chop eq '\\\\') {
60 } while s/:tc=([^:]+):/:/ && ($TERM = $1);
64 foreach $field (split(/:[\s:\\]*/,$TERMCAP)) {
65 if ($field =~ /^\w\w$/) {
68 elsif ($field =~ /^(\w\w)#(.*)/) {
69 $TC{$1} = $2 if $TC{$1} eq '';
71 elsif ($field =~ /^(\w\w)=(.*)/) {
75 s/\\(200)/pack('c',0)/eg; # NUL character
76 s/\\(0\d\d)/pack('c',oct($1))/eg; # octal
77 s/\\(0x[0-9A-Fa-f][0-9A-Fa-f])/pack('c',hex($1))/eg; # hex
78 s/\\(\d\d\d)/pack('c',$1 & 0177)/eg;
86 s/\^(.)/pack('c',ord($1) & 31)/eg;
89 $TC{$entry} = $_ if $TC{$entry} eq '';
92 $TC{'pc'} = "\0" if $TC{'pc'} eq '';
93 $TC{'bc'} = "\b" if $TC{'bc'} eq '';
96 @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);
99 local($string,$affcnt,$FH) = @_;
101 if ($string =~ /(^[\d.]+)(\*?)(.*)$/) {
103 $ms *= $affcnt if $2;
105 $decr = $Tputs[$ospeed];
108 $string .= $TC{'pc'} x ($ms / $decr);
111 print $FH $string if $FH;
116 local($string) = shift(@_);
119 local($code,$tmp) = @_;
123 while ($string =~ /^([^%]*)%(.)(.*)/) {
128 $result .= sprintf("%d",shift(@tmp));
130 elsif ($code eq '.') {
132 if ($tmp == 0 || $tmp == 4 || $tmp == 10) {
134 ++$tmp, $after .= $TC{'up'} if $TC{'up'};
137 ++$tmp, $after .= $TC{'bc'};
140 $result .= sprintf("%c",$tmp);
143 elsif ($code eq '+') {
144 $result .= sprintf("%c",shift(@tmp)+ord($string));
145 $string = substr($string,1,99);
148 elsif ($code eq 'r') {
153 elsif ($code eq '>') {
154 ($code,$tmp,$string) = unpack("CCa99",$string);
155 if ($tmp[$[] > $code) {
159 elsif ($code eq '2') {
160 $result .= sprintf("%02d",shift(@tmp));
163 elsif ($code eq '3') {
164 $result .= sprintf("%03d",shift(@tmp));
167 elsif ($code eq 'i') {
169 @tmp = ($code+1,$tmp+1);
175 $result . $string . $after;