$self = {} unless defined $self;
bless $self, $class;
- my ( $term, $cap, $search, $field, $max, $tmp_term, $TERMCAP );
+ my ( $term, $cap, $search, $field, $tmp_term, $TERMCAP );
my ( $state, $first, $entry );
local $_;
# $tmp_term is always the next term (possibly :tc=...:) we are looking for
$tmp_term = $self->{TERM};
+ my $seen = {};
my $foo = ( exists $ENV{TERMCAP} ? $ENV{TERMCAP} : '' );
if ( ( $foo !~ m:^/:s ) && ( $foo =~ m/(^|\|)\Q$tmp_term\E[:|]/s ) )
{
$entry = $foo;
+ $seen->{$tmp_term} = 1;
}
my @termcap_path = termcap_path();
&& ( $tmp =~ /(^|\|)\Q$tmp_term\E[:|]/s ) )
{
$entry = $tmp;
+ $seen->{$tmp_term} = 1;
}
};
warn "Can't run infocmp to get a termcap entry: $@" if $@;
$first = 0; # first entry (keeps term name)
- $max = 64; # max :tc=...:'s
-
if ($entry)
{
# do the same file again
# prevent endless recursion
- $max-- || croak "failed termcap loop at $tmp_term";
$state = 1; # ok, maybe do a new file next time
}
chomp;
s/^[^:]*:// if $first++;
$state = 0;
+ $seen->{$tmp_term} = 1;
while (s/\\$//) {
defined(my $x = <$fh>) or last;
$_ .= $x; chomp;
close $fh;
# If :tc=...: found then search this file again
- $entry =~ s/:tc=([^:]+):/:/ && ( $tmp_term = $1, $state = 2 );
+ while ($entry =~ s/:tc=([^:]+):/:/) {
+ $tmp_term = $1;
+ next if $seen->{$tmp_term};
+ $state = 2;
+ last;
+ }
}
croak "Can't find $term" if $entry eq '';