RC3: lib/constant.t #35
[p5sagit/p5-mst-13.2.git] / lib / Term / Cap.pm
index 69a2f5e..03d2573 100644 (file)
@@ -1,10 +1,12 @@
 package Term::Cap;
 
 use Carp;
+use strict;
 
-use vars qw($VERSION);
+use vars qw($VERSION $VMS_TERMCAP);
+use vars qw($termpat $state $first $entry);
 
-$VERSION = '1.03';
+$VERSION = '1.07';
 
 # Version undef: Thu Dec 14 20:02:42 CST 1995 by sanders@bsdi.com
 # Version 1.00:  Thu Nov 30 23:34:29 EST 2000 by schwern@pobox.com
@@ -19,6 +21,14 @@ $VERSION = '1.03';
 #       VMS Support from Charles Lane <lane@DUPHY4.Physics.Drexel.Edu>
 # Version 1.04:  Thu Nov 29 16:22:03 GMT 2001
 #       Fixed warnings in test
+# Version 1.05:  Mon Dec  3 15:33:49 GMT 2001
+#       Don't try to fall back on infocmp if it's not there. From chromatic.
+# Version 1.06:  Thu Dec  6 18:43:22 GMT 2001
+#       Preload the default VMS termcap from Charles Lane
+#       Don't carp at setting OSPEED unless warnings are on.
+# Version 1.07:  Wed Jan  2 21:35:09 GMT 2002
+#       Sanity check on infocmp output from Norton Allen
+#       Repaired INSTALLDIRS thanks to Michael Schwern
 
 # TODO:
 # support Berkeley DB termcaps
@@ -63,7 +73,17 @@ output the string to $FH if specified.
 
 =cut
 
+# Preload the default VMS termcap.
+# If a different termcap is required then the text of one can be supplied
+# in $Term::Cap::VMS_TERMCAP before Tgetent is called.
+
+if ( $^O eq 'VMS') {
+       chomp (my @entry = <DATA>);
+       $VMS_TERMCAP = join '', @entry;
+}
+
 # Returns a list of termcap files to check.
+
 sub termcap_path { ## private
     my @termcap_path;
     # $TERMCAP, if it's a filespec
@@ -84,6 +104,7 @@ sub termcap_path { ## private
            '/usr/share/misc/termcap',
        );
     }
+
     # return the list of those termcaps that exist
     return grep(-f, @termcap_path);
 }
@@ -155,7 +176,9 @@ sub Tgetent { ## public -- static method
 
     # Compute PADDING factor from OSPEED (to be used by Tpad)
     if (! $self->{OSPEED}) {
-       carp "OSPEED was not set, defaulting to 9600";
+        if ( $^W ) {
+          carp "OSPEED was not set, defaulting to 9600";
+        }
        $self->{OSPEED} = 9600;
     }
     if ($self->{OSPEED} < 16) {
@@ -189,17 +212,21 @@ sub Tgetent { ## public -- static method
        # last resort--fake up a termcap from terminfo 
        local $ENV{TERM} = $term;
 
-         if ( $^O eq 'VMS' ) {
-            chomp(my @entry = <DATA>);
-            $entry = join '', @entry;
-         }
-         else {
-            eval
-            {
-                $entry = `infocmp -C 2>/dev/null`;
-            }
-        }
-
+        if ( $^O eq 'VMS' ) {
+          $entry = $VMS_TERMCAP;
+        }
+        else {
+           if ( grep { -x "$_/infocmp" } split /:/, $ENV{PATH} ) {
+              eval
+              {
+                my $tmp = `infocmp -C 2>/dev/null`;
+
+                if (( $tmp !~ m%^/%s ) && ( $tmp =~ /(^|\|)${termpat}[:|]/s)) {
+                   $entry = $tmp;
+                }
+              };
+           }
+        }
     }
 
     croak "Can't find a valid termcap file" unless @termcap_path || $entry;