RC3: lib/constant.t #35
[p5sagit/p5-mst-13.2.git] / lib / Term / Cap.pm
index bf5512a..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.02';
+$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
@@ -15,6 +17,18 @@ $VERSION = '1.02';
 #       Altered layout of the POD
 #       Added Test::More to PREREQ_PM in Makefile.PL
 #       Fixed no argument Tgetent()
+# Version 1.03:  Wed Nov 28 10:09:38 GMT 2001
+#       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
@@ -59,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
@@ -80,6 +104,7 @@ sub termcap_path { ## private
            '/usr/share/misc/termcap',
        );
     }
+
     # return the list of those termcaps that exist
     return grep(-f, @termcap_path);
 }
@@ -151,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) {
@@ -184,29 +211,22 @@ sub Tgetent { ## public -- static method
     {
        # last resort--fake up a termcap from terminfo 
        local $ENV{TERM} = $term;
-       if ($^O eq 'VMS') {  # we use REAL dec terminals, not stinkin' emulators!
-    $entry = 'vt220|vt200|DEC VT220 in vt100 emulation mode:'
-           .'am:mi:xn:xo:'
-           .'co#80:li#24:'
-           .'RA=\E[?7l:SA=\E[?7h:'
-           .'ac=kkllmmjjnnwwqquuttvvxx:ae=\E(B:al=\E[L:as=\E(0:'
-           .'bl=^G:cd=\E[J:ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:'
-           .'cr=^M:cs=\E[%i%d;%dr:dc=\E[P:dl=\E[M:do=\E[B:'
-           .'ei=\E[4l:ho=\E[H:im=\E[4h:'
-           .'is=\E[1;24r\E[24;1H:'
-           .'nd=\E[C:'
-           .'kd=\E[B::kl=\E[D:kr=\E[C:ku=\E[A:le=^H:'
-           .'mb=\E[5m:md=\E[1m:me=\E[m:mr=\E[7m:'
-           .'kb=\0177:'
-           .'r2=\E>\E[24;1H\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h\E=:rc=\E8:'
-           .'sc=\E7:se=\E[27m:sf=\ED:so=\E[7m:sr=\EM:ta=^I:'
-           .'ue=\E[24m:up=\E[A:us=\E[4m:ve=\E[?25h:vi=\E[?25l:';
-       } 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;
@@ -285,19 +305,19 @@ sub Tgetent { ## public -- static method
     # Precompile $entry into the object
     $entry =~ s/^[^:]*://;
     foreach $field (split(/:[\s:\\]*/,$entry)) {
-       if ($field =~ /^(\w\w)$/) {
+       if (defined $field && $field =~ /^(\w\w)$/) {
            $self->{'_' . $field} = 1 unless defined $self->{'_' . $1};
            # print STDERR "DEBUG: flag $1\n";
        }
-       elsif ($field =~ /^(\w\w)\@/) {
+       elsif (defined $field && $field =~ /^(\w\w)\@/) {
            $self->{'_' . $1} = "";
            # print STDERR "DEBUG: unset $1\n";
        }
-       elsif ($field =~ /^(\w\w)#(.*)/) {
+       elsif (defined $field && $field =~ /^(\w\w)#(.*)/) {
            $self->{'_' . $1} = $2 unless defined $self->{'_' . $1};
            # print STDERR "DEBUG: numeric $1 = $2\n";
        }
-       elsif ($field =~ /^(\w\w)=(.*)/) {
+       elsif (defined $field && $field =~ /^(\w\w)=(.*)/) {
            # print STDERR "DEBUG: string $1 = $2\n";
            next if defined $self->{'_' . ($cap = $1)};
            $_ = $2;
@@ -358,7 +378,7 @@ sub Tpad { ## public
     my($string, $cnt, $FH) = @_;
     my($decr, $ms);
 
-    if ($string =~ /(^[\d.]+)(\*?)(.*)$/) {
+    if (defined $string && $string =~ /(^[\d.]+)(\*?)(.*)$/) {
        $ms = $1;
        $ms *= $cnt if $2;
        $string = $3;
@@ -562,9 +582,6 @@ sub Trequire { ## public
     croak "Terminal does not support: (@undefined)" if @undefined;
 }
 
-1;
-__END__
-
 =back
 
 =head1 EXAMPLES
@@ -610,3 +627,25 @@ for CPAN by Jonathan Stowe <jns@gellyfish.com>.
 termcap(5)
 
 =cut
+
+# Below is a default entry for systems where there are terminals but no
+# termcap
+1;
+__DATA__
+vt220|vt200|DEC VT220 in vt100 emulation mode:
+am:mi:xn:xo:
+co#80:li#24:
+RA=\E[?7l:SA=\E[?7h:
+ac=kkllmmjjnnwwqquuttvvxx:ae=\E(B:al=\E[L:as=\E(0:
+bl=^G:cd=\E[J:ce=\E[K:cl=\E[H\E[2J:cm=\E[%i%d;%dH:
+cr=^M:cs=\E[%i%d;%dr:dc=\E[P:dl=\E[M:do=\E[B:
+ei=\E[4l:ho=\E[H:im=\E[4h:
+is=\E[1;24r\E[24;1H:
+nd=\E[C:
+kd=\E[B::kl=\E[D:kr=\E[C:ku=\E[A:le=^H:
+mb=\E[5m:md=\E[1m:me=\E[m:mr=\E[7m:
+kb=\0177:
+r2=\E>\E[24;1H\E[?3l\E[?4l\E[?5l\E[?7h\E[?8h\E=:rc=\E8:
+sc=\E7:se=\E[27m:sf=\ED:so=\E[7m:sr=\EM:ta=^I:
+ue=\E[24m:up=\E[A:us=\E[4m:ve=\E[?25h:vi=\E[?25l:
+