-;# $Header: termcap.pl,v 3.0 89/10/18 15:19:58 lwall Locked $
+;# $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
+#
;#
;# Usage:
-;# do 'ioctl.pl';
+;# require 'ioctl.pl';
;# ioctl(TTY,$TIOCGETP,$foo);
;# ($ispeed,$ospeed) = unpack('cc',$foo);
-;# do 'termcap.pl';
-;# do Tgetent('vt100'); # sets $TC{'cm'}, etc.
-;# do Tgoto($TC{'cm'},$row,$col);
-;# do Tputs($TC{'dl'},$affcnt,'FILEHANDLE');
+;# require 'termcap.pl';
+;# &Tgetent('vt100'); # sets $TC{'cm'}, etc.
+;# &Tputs(&Tgoto($TC{'cm'},$col,$row), 0, 'FILEHANDLE');
+;# &Tputs($TC{'dl'},$affcnt,'FILEHANDLE');
;#
sub Tgetent {
local($TERM) = @_;
local($TERMCAP,$_,$entry,$loop,$field);
- warn "Tgetent: no ospeed set" unless $ospeed;
- foreach $key (keys(TC)) {
+ # warn "Tgetent: no ospeed set" unless $ospeed;
+ foreach $key (keys %TC) {
delete $TC{$key};
}
$TERM = $ENV{'TERM'} unless $TERM;
+ $TERM =~ s/(\W)/\\$1/g;
$TERMCAP = $ENV{'TERMCAP'};
$TERMCAP = '/etc/termcap' unless $TERMCAP;
if ($TERMCAP !~ m:^/:) {
- if (index($TERMCAP,"|$TERM|") < $[) {
+ if ($TERMCAP !~ /(^|\|)$TERM[:\|]/) {
$TERMCAP = '/etc/termcap';
}
}
while (<TERMCAP>) {
next if /^#/;
next if /^\t/;
- if (/\\|$TERM[:\\|]/) {
+ if (/(^|\\|)${TERM}[:\\|]/) {
chop;
while (chop eq '\\\\') {
\$_ .= <TERMCAP>;
\$entry .= \$_;
";
eval $loop;
- } while s/:tc=([^:]+):/:/, $TERM = $1;
+ } while s/:tc=([^:]+):/:/ && ($TERM = $1);
$TERMCAP = $entry;
}
$entry = $1;
$_ = $2;
s/\\E/\033/g;
+ 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/\\n/\n/g;
s/\\r/\r/g;
s/\\f/\f/g;
s/\\\^/\377/g;
s/\^\?/\177/g;
- s/\^(.)/pack('c',$1 & 031)/eg;
+ s/\^(.)/pack('c',ord($1) & 31)/eg;
s/\\(.)/$1/g;
s/\377/^/g;
$TC{$entry} = $_ if $TC{$entry} eq '';
local($result) = '';
local($after) = '';
local($code,$tmp) = @_;
- @_ = ($tmp,$code);
+ local(@tmp);
+ @tmp = ($tmp,$code);
local($online) = 0;
while ($string =~ /^([^%]*)%(.)(.*)/) {
$result .= $1;
$code = $2;
$string = $3;
if ($code eq 'd') {
- $result .= sprintf("%d",shift(@_));
+ $result .= sprintf("%d",shift(@tmp));
}
elsif ($code eq '.') {
- $tmp = shift(@_);
+ $tmp = shift(@tmp);
if ($tmp == 0 || $tmp == 4 || $tmp == 10) {
if ($online) {
++$tmp, $after .= $TC{'up'} if $TC{'up'};
$online = !$online;
}
elsif ($code eq '+') {
- $result .= sprintf("%c",shift(@_)+ord($string));
+ $result .= sprintf("%c",shift(@tmp)+ord($string));
$string = substr($string,1,99);
$online = !$online;
}
elsif ($code eq 'r') {
- ($code,$tmp) = @_;
- @_ = ($tmp,$code);
+ ($code,$tmp) = @tmp;
+ @tmp = ($tmp,$code);
$online = !$online;
}
elsif ($code eq '>') {
($code,$tmp,$string) = unpack("CCa99",$string);
- if ($_[$[] > $code) {
- $_[$[] += $tmp;
+ if ($tmp[$[] > $code) {
+ $tmp[$[] += $tmp;
}
}
elsif ($code eq '2') {
- $result .= sprintf("%02d",shift(@_));
+ $result .= sprintf("%02d",shift(@tmp));
$online = !$online;
}
elsif ($code eq '3') {
- $result .= sprintf("%03d",shift(@_));
+ $result .= sprintf("%03d",shift(@tmp));
$online = !$online;
}
elsif ($code eq 'i') {
- ($code,$tmp) = @_;
- @_ = ($code+1,$tmp+1);
+ ($code,$tmp) = @tmp;
+ @tmp = ($code+1,$tmp+1);
}
else {
return "OOPS";