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.
5 # This legacy library is deprecated and will be removed in a future
8 # In particular, this should not be used as an example of modern Perl
9 # programming techniques.
11 # Suggested alternative: Term::Cap
14 warn( "The 'termcap.pl' legacy library is deprecated and will be"
15 . " removed in the next major release of perl. Please use the"
16 . " Term::Cap module instead." );
20 ;# require 'ioctl.pl';
21 ;# ioctl(TTY,$TIOCGETP,$foo);
22 ;# ($ispeed,$ospeed) = unpack('cc',$foo);
23 ;# require 'termcap.pl';
24 ;# &Tgetent('vt100'); # sets $TC{'cm'}, etc.
25 ;# &Tputs(&Tgoto($TC{'cm'},$col,$row), 0, 'FILEHANDLE');
26 ;# &Tputs($TC{'dl'},$affcnt,'FILEHANDLE');
30 local($TERMCAP,$_,$entry,$loop,$field);
32 # warn "Tgetent: no ospeed set" unless $ospeed;
33 foreach $key (keys %TC) {
36 $TERM = $ENV{'TERM'} unless $TERM;
37 $TERM =~ s/(\W)/\\$1/g;
38 $TERMCAP = $ENV{'TERMCAP'};
39 $TERMCAP = '/etc/termcap' unless $TERMCAP;
40 if ($TERMCAP !~ m:^/:) {
41 if ($TERMCAP !~ /(^|\|)$TERM[:\|]/) {
42 $TERMCAP = '/etc/termcap';
45 if ($TERMCAP =~ m:^/:) {
49 open(TERMCAP,'<$TERMCAP') || die \"Can't open $TERMCAP\";
53 if (/(^|\\|)${TERM}[:\\|]/) {
55 while (chop eq '\\\\') {
67 } while s/:tc=([^:]+):/:/ && ($TERM = $1);
71 foreach $field (split(/:[\s:\\]*/,$TERMCAP)) {
72 if ($field =~ /^\w\w$/) {
75 elsif ($field =~ /^(\w\w)#(.*)/) {
76 $TC{$1} = $2 if $TC{$1} eq '';
78 elsif ($field =~ /^(\w\w)=(.*)/) {
82 s/\\(200)/pack('c',0)/eg; # NUL character
83 s/\\(0\d\d)/pack('c',oct($1))/eg; # octal
84 s/\\(0x[0-9A-Fa-f][0-9A-Fa-f])/pack('c',hex($1))/eg; # hex
85 s/\\(\d\d\d)/pack('c',$1 & 0177)/eg;
93 s/\^(.)/pack('c',ord($1) & 31)/eg;
96 $TC{$entry} = $_ if $TC{$entry} eq '';
99 $TC{'pc'} = "\0" if $TC{'pc'} eq '';
100 $TC{'bc'} = "\b" if $TC{'bc'} eq '';
103 @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);
106 local($string,$affcnt,$FH) = @_;
108 if ($string =~ /(^[\d.]+)(\*?)(.*)$/) {
110 $ms *= $affcnt if $2;
112 $decr = $Tputs[$ospeed];
115 $string .= $TC{'pc'} x ($ms / $decr);
118 print $FH $string if $FH;
123 local($string) = shift(@_);
126 local($code,$tmp) = @_;
130 while ($string =~ /^([^%]*)%(.)(.*)/) {
135 $result .= sprintf("%d",shift(@tmp));
137 elsif ($code eq '.') {
139 if ($tmp == 0 || $tmp == 4 || $tmp == 10) {
141 ++$tmp, $after .= $TC{'up'} if $TC{'up'};
144 ++$tmp, $after .= $TC{'bc'};
147 $result .= sprintf("%c",$tmp);
150 elsif ($code eq '+') {
151 $result .= sprintf("%c",shift(@tmp)+ord($string));
152 $string = substr($string,1,99);
155 elsif ($code eq 'r') {
160 elsif ($code eq '>') {
161 ($code,$tmp,$string) = unpack("CCa99",$string);
162 if ($tmp[$[] > $code) {
166 elsif ($code eq '2') {
167 $result .= sprintf("%02d",shift(@tmp));
170 elsif ($code eq '3') {
171 $result .= sprintf("%03d",shift(@tmp));
174 elsif ($code eq 'i') {
176 @tmp = ($code+1,$tmp+1);
182 $result . $string . $after;