[alt.sources] program to print concurrent month output

tchrist@convexe.uucp (Tom Christiansen) (10/26/89)

Here is a simple litle script, which i call "now", that
does a cal on this month, last month, and next month, 
and prints them out all together, like this

         September 1989             October 1989               November 1989  
     S  M Tu  W Th  F  S        S  M Tu  W Th  F  S        S  M Tu  W Th  F  S
35                  1  2   40   1  2  3  4  5  6  7   44            1  2  3  4
36   3  4  5  6  7  8  9   41   8  9 10 11 12 13 14   45   5  6  7  8  9 10 11
37  10 11 12 13 14 15 16   42  15 16 17 18 19 20 21   46  12 13 14 15 16 17 18
38  17 18 19 20 21 22 23   43  22 23 24 25 _2_6 27 28   47  19 20 21 22 23 24 25
39  24 25 26 27 28 29 30   44  29 30 31               48  26 27 28 29 30      
                                                                              

The current day is printed in reverse video.  I've been lazy and hard-coded
the vt100 standout escape sequence.  You can always parse out $ENV{'TERMCAP'}
if you really want to.  And see, the ||'d together substitute is pretty gross, 
but I couldn't make it work for the boudary conditions otherwise.  This has
been running for over a year, so I've tested it during December and January.

#!/usr/local/bin/perl

  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);


   $mon++; 		# 0 based
   $year += 1900;

  $nmon = $mon + 1;
  $nyear = $year;
  if ( $nmon == 13 ) {
    $nmon = 1;
    $nyear++;
  } 


  $pmon = $mon - 1;
  $pyear = $year;

  if ( $pmon == 0 ) {
    $pmon = 12;
    $pyear--;
  } 

  $SO = "\033[7m";
  $SE = "\033[m";

  open ( prev, "cal $pmon $pyear |" );
  open ( cur, "cal $mon $year |" );
  open ( foll, "cal $nmon $nyear |" );

  until (eof(prev) && eof(cur) && eof(foll)) {
    $prev = <prev>; chop($prev);
    $cur = <cur>; chop($cur);
    $cur =~ s/([^0-9][^0-9]*)$mday([^0-9][^0-9]*)/$1$SO$mday$SE$2/ ||
	$cur =~ s/([^0-9][^0-9]*)$mday$/$1$SO$mday$SE/ ||
	$cur =~ s/^$mday([^0-9][^0-9]*)/$SO$mday$SE$1/;
    $foll = <foll>; chop($foll);

    printf ("%-20s   %-20s   %-20s\n", $prev, $cur, $foll );
  } 

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist@convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"