Instead of an archaic limit, just keep track of tc's. This is actually slightly faster, because the termcap links is a tree, not a list.
Please test. Index: Cap.pm =================================================================== RCS file: /cvs/src/gnu/usr.bin/perl/cpan/Term-Cap/Cap.pm,v retrieving revision 1.3 diff -u -p -r1.3 Cap.pm --- Cap.pm 18 Oct 2023 01:49:26 -0000 1.3 +++ Cap.pm 18 Oct 2023 08:24:54 -0000 @@ -280,7 +280,7 @@ sub Tgetent $first = 0; # first entry (keeps term name) - $max = 64; # max :tc=...:'s + my $seen = {}; # keep track of :tc=...:s if ($entry) { @@ -291,6 +291,7 @@ sub Tgetent if ( $entry =~ s/:tc=([^:]+):/:/ ) { $tmp_term = $1; + $seen->{$tmp_term} = 1; # protect any pattern metacharacters in $tmp_term $termpat = $tmp_term; @@ -332,10 +333,7 @@ sub Tgetent } else { - # 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 } @@ -345,11 +343,20 @@ sub Tgetent close TERMCAP; # If :tc=...: found then search this file again - $entry =~ s/:tc=([^:]+):/:/ && ( $tmp_term = $1, $state = 2 ); + while ($entry =~ s/:tc=([^:]+):/:/) { + $tmp_term = $1; + if ($seen->{$tmp_term}) { + # XXX first version of this croaked, but we can actually + # get several intermediate entries with the same tc ! + next; + } + $seen->{$tmp_term} = 1; + $state = 2; - # protect any pattern metacharacters in $tmp_term - $termpat = $tmp_term; - $termpat =~ s/(\W)/\\$1/g; + # protect any pattern metacharacters in $tmp_term + $termpat = $tmp_term; + $termpat =~ s/(\W)/\\$1/g; + } } croak "Can't find $term" if $entry eq '';