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
16 ;# require 'ioctl.pl';
17 ;# ioctl(TTY,$TIOCGETP,$foo);
18 ;# ($ispeed,$ospeed) = unpack('cc',$foo);
19 ;# require 'termcap.pl';
20 ;# &Tgetent('vt100'); # sets $TC{'cm'}, etc.
21 ;# &Tputs(&Tgoto($TC{'cm'},$col,$row), 0, 'FILEHANDLE');
22 ;# &Tputs($TC{'dl'},$affcnt,'FILEHANDLE');
26 local($TERMCAP,$_,$entry,$loop,$field);
28 # warn "Tgetent: no ospeed set" unless $ospeed;
29 foreach $key (keys %TC) {
32 $TERM = $ENV{'TERM'} unless $TERM;
33 $TERM =~ s/(\W)/\\$1/g;
34 $TERMCAP = $ENV{'TERMCAP'};
35 $TERMCAP = '/etc/termcap' unless $TERMCAP;
36 if ($TERMCAP !~ m:^/:) {
37 if ($TERMCAP !~ /(^|\|)$TERM[:\|]/) {
38 $TERMCAP = '/etc/termcap';
41 if ($TERMCAP =~ m:^/:) {
45 open(TERMCAP,'<$TERMCAP') || die \"Can't open $TERMCAP\";
49 if (/(^|\\|)${TERM}[:\\|]/) {
51 while (chop eq '\\\\') {
63 } while s/:tc=([^:]+):/:/ && ($TERM = $1);
67 foreach $field (split(/:[\s:\\]*/,$TERMCAP)) {
68 if ($field =~ /^\w\w$/) {
71 elsif ($field =~ /^(\w\w)#(.*)/) {
72 $TC{$1} = $2 if $TC{$1} eq '';
74 elsif ($field =~ /^(\w\w)=(.*)/) {
78 s/\\(200)/pack('c',0)/eg; # NUL character
79 s/\\(0\d\d)/pack('c',oct($1))/eg; # octal
80 s/\\(0x[0-9A-Fa-f][0-9A-Fa-f])/pack('c',hex($1))/eg; # hex
81 s/\\(\d\d\d)/pack('c',$1 & 0177)/eg;
89 s/\^(.)/pack('c',ord($1) & 31)/eg;
92 $TC{$entry} = $_ if $TC{$entry} eq '';
95 $TC{'pc'} = "\0" if $TC{'pc'} eq '';
96 $TC{'bc'} = "\b" if $TC{'bc'} eq '';
99 @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);
102 local($string,$affcnt,$FH) = @_;
104 if ($string =~ /(^[\d.]+)(\*?)(.*)$/) {
106 $ms *= $affcnt if $2;
108 $decr = $Tputs[$ospeed];
111 $string .= $TC{'pc'} x ($ms / $decr);
114 print $FH $string if $FH;
119 local($string) = shift(@_);
122 local($code,$tmp) = @_;
126 while ($string =~ /^([^%]*)%(.)(.*)/) {
131 $result .= sprintf("%d",shift(@tmp));
133 elsif ($code eq '.') {
135 if ($tmp == 0 || $tmp == 4 || $tmp == 10) {
137 ++$tmp, $after .= $TC{'up'} if $TC{'up'};
140 ++$tmp, $after .= $TC{'bc'};
143 $result .= sprintf("%c",$tmp);
146 elsif ($code eq '+') {
147 $result .= sprintf("%c",shift(@tmp)+ord($string));
148 $string = substr($string,1,99);
151 elsif ($code eq 'r') {
156 elsif ($code eq '>') {
157 ($code,$tmp,$string) = unpack("CCa99",$string);
158 if ($tmp[$[] > $code) {
162 elsif ($code eq '2') {
163 $result .= sprintf("%02d",shift(@tmp));
166 elsif ($code eq '3') {
167 $result .= sprintf("%03d",shift(@tmp));
170 elsif ($code eq 'i') {
172 @tmp = ($code+1,$tmp+1);
178 $result . $string . $after;