- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
sub Tgetent {
local($TERM) = @_;
local($TERMCAP,$_,$entry,$loop,$field);
# 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 ($TERMCAP !~ /(^|\|)$TERM[:\|]/) {
$TERMCAP = '/etc/termcap';
}
}
if ($TERMCAP =~ m:^/:) {
$entry = '';
do {
$loop = "
open(TERMCAP,'<$TERMCAP') || die \"Can't open $TERMCAP\";
while (<TERMCAP>) {
next if /^#/;
next if /^\t/;
if (/(^|\\|)${TERM}[:\\|]/) {
chop;
while (chop eq '\\\\') {
\$_ .= <TERMCAP>;
chop;
}
\$_ .= ':';
last;
}
}
close TERMCAP;
\$entry .= \$_;
";
eval $loop;
} while s/:tc=([^:]+):/:/ && ($TERM = $1);
$TERMCAP = $entry;
}
foreach $field (split(/:[\s:\\]*/,$TERMCAP)) {
if ($field =~ /^\w\w$/) {
$TC{$field} = 1;
}
elsif ($field =~ /^(\w\w)#(.*)/) {
$TC{$1} = $2 if $TC{$1} eq '';
}
elsif ($field =~ /^(\w\w)=(.*)/) {
$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/\\t/\t/g;
s/\\b/\b/g;
s/\\f/\f/g;
s/\\\^/\377/g;
s/\^\?/\177/g;
s/\^(.)/pack('c',ord($1) & 31)/eg;
s/\\(.)/$1/g;
s/\377/^/g;
$TC{$entry} = $_ if $TC{$entry} eq '';
}
}
$TC{'pc'} = "\0" if $TC{'pc'} eq '';
$TC{'bc'} = "\b" if $TC{'bc'} eq '';
}