From 7c0587c85ff56c1fa1d95bc5228a7aff2da43d6c Mon Sep 17 00:00:00 2001 From: Larry Wall Date: Mon, 8 Jun 1992 04:53:03 +0000 Subject: perl 4.0 patch 32: patch #20, continued See patch #20. --- lib/termcap.pl | 6 +++--- lib/timelocal.pl | 18 +++++++++++------- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/termcap.pl b/lib/termcap.pl index 46ac858247..aa221dfc39 100644 --- a/lib/termcap.pl +++ b/lib/termcap.pl @@ -1,4 +1,4 @@ -;# $Header: termcap.pl,v 4.0 91/03/20 01:26:33 lwall Locked $ +;# $RCSfile: termcap.pl,v $$Revision: 4.0.1.1 $$Date: 92/06/08 13:49:17 $ ;# ;# Usage: ;# require 'ioctl.pl'; @@ -21,7 +21,7 @@ sub Tgetent { $TERMCAP = $ENV{'TERMCAP'}; $TERMCAP = '/etc/termcap' unless $TERMCAP; if ($TERMCAP !~ m:^/:) { - if (index($TERMCAP,"|$TERM|") < $[) { + if ($TERMCAP !~ /(^|\|)$TERM[:\|]/) { $TERMCAP = '/etc/termcap'; } } @@ -33,7 +33,7 @@ sub Tgetent { while () { next if /^#/; next if /^\t/; - if (/\\|$TERM[:\\|]/) { + if (/(^|\\|)$TERM[:\\|]/) { chop; while (chop eq '\\\\') { \$_ .= ; diff --git a/lib/timelocal.pl b/lib/timelocal.pl index a228041637..5be3840035 100644 --- a/lib/timelocal.pl +++ b/lib/timelocal.pl @@ -1,7 +1,7 @@ ;# timelocal.pl ;# ;# Usage: -;# $time = timelocal($sec,$min,$hours,$mday,$mon,$year,$junk,$junk,$isdst); +;# $time = timelocal($sec,$min,$hours,$mday,$mon,$year); ;# $time = timegm($sec,$min,$hours,$mday,$mon,$year); ;# These routines are quite efficient and yet are always guaranteed to agree @@ -24,6 +24,7 @@ CONFIG: { package timelocal; + local($[) = 0; @epoch = localtime(0); $tzmin = $epoch[2] * 60 + $epoch[1]; # minutes east of GMT if ($tzmin > 0) { @@ -40,6 +41,7 @@ CONFIG: { sub timegm { package timelocal; + local($[) = 0; $ym = pack(C2, @_[5,4]); $cheat = $cheat{$ym} || &cheat; $cheat + $_[0] * $SEC + $_[1] * $MIN + $_[2] * $HR + ($_[3]-1) * $DAYS; @@ -48,10 +50,11 @@ sub timegm { sub timelocal { package timelocal; - $ym = pack(C2, @_[5,4]); - $cheat = $cheat{$ym} || &cheat; - $cheat + $_[0] * $SEC + $_[1] * $MIN + $_[2] * $HR + ($_[3]-1) * $DAYS - + $tzmin * $MIN - 60 * 60 * ($_[8] != 0); + local($[) = 0; + $time = &main'timegm + $tzmin*$MIN; + @test = localtime($time); + $time -= $HR if $test[2] != $_[2]; + $time; } package timelocal; @@ -59,14 +62,15 @@ package timelocal; sub cheat { $year = $_[5]; $month = $_[4]; + die "Month out of range 0..11 in ctime.pl\n" if $month > 11; $guess = $^T; @g = gmtime($guess); while ($diff = $year - $g[5]) { - $guess += $diff * (364 * $DAYS); + $guess += $diff * (363 * $DAYS); @g = gmtime($guess); } while ($diff = $month - $g[4]) { - $guess += $diff * (28 * $DAYS); + $guess += $diff * (27 * $DAYS); @g = gmtime($guess); } $g[3]--; -- cgit v1.2.1