#!/usr/bin/perl -w
#
# web.calendar
#
# Generate a calendar.
#
# Generate a calendar which fills a page. Get the information
# from a calendar file.
#
# Generate a page for each month which has an activity.
#
# Usage:
# web.calendar [flags]
# Flags:
# --data datafile
# This is the name of the calendar data file. It contains
# which are of the form:
# # Comment line
# Year=1999 Introduces a new year
# Month=10 Introduces a new month
# 1=event Some event on the specified day.
# TBA=event Some event at an unknown date within the month.
# The event calendar must be in order. If not specified, the
# event calendar's filename is assumed to be "calendar.data".
# The events may contain HTML, but keep it simple.
# --start 1998/10
# This specifies the starting month. This must be in the
# format shown. If unspecified, it starts as early as possible.
# --end 1999/05
# This specifies the ending month. If unspecified, the calendar
# goes as long as possible.
# --bg color
# This specifies the background color. This can be anything
# that HTML allows. This defaults to no specific color.
# --title "some title"
# This specifies the title of the calendar.
# --banner "some message"
# This is the header text of the calendar.
# --html directory
# This specifies the name of the directory to store
# the generated files. By default, they will go into
# the current directory.
#
#
use strict;
use Time::Local;
use Getopt::Long;
use vars qw(%Activities $EndMonth $EndYear %Months @MonTab @MonTabShort
%Params $StartMonth $StartYear $Version);
%Params =
(
"data" => "calendar.data",
"start" => "0000/01",
"end" => "9999/12",
"bg" => "",
"title" => "Calendar",
"banner" => "Calendar",
"html" => ".",
);
@MonTab = ( "", "January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December");
@MonTabShort = ( "", "jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec");
$StartYear = 1000;
$StartMonth = 1;
$EndYear = 9999;
$EndMonth = 12;
$Version = 'web.calendar v0.11 regan@ao.com';
###
### Main program
###
my(@cal, $dom, $dow, $line, $mon, $mon2, $month, $next, $prev,
$text, $year, $year2);
# chdir($ENV{'HOME'});
GetOptions(\%Params,
"data=s", "bg=s", "title=s", "banner=s", "html=s");
$Params{'bg'} = qq|bgcolor="$Params{'bg'}"| if ($Params{'bg'} ne "");
# Split the years and month
($StartYear, $StartMonth) = split(/[\D]/, $Params{'start'});
($EndYear, $EndMonth) = split(/[\D]/, $Params{'end'});
ReadCalendar($Params{'data'});
for $month (sort(keys %Months))
{
print "Handle $month\n";
($year, $mon) = split(/\./, $month);
$year2 = $year;
$mon2 = $mon - 1;
if ($mon2 == 0)
{
$mon2 = 12;
$year2--;
}
$prev = "
";
$prev = "Previous"
if (defined($Months{"$year2.$mon2"}));
$year2 = $year;
$mon2 = $mon + 1;
if ($mon2 == 13)
{
$mon2 = 1;
$year2++;
}
$next = "
";
$next = "Next"
if (defined($Months{"$year2.$mon2"}));
if (!open(WEB, ">$Params{'html'}/$year.$mon.html"))
{
print "Cannot open $Params{'html'}/$year.$mon.html: $!\n";
exit 1;
}
# Put in month header information
print WEB << " EOF";
| $prev | $Params{'banner'} |
$MonTab[$mon] |
$year |
$next | ||
|---|---|---|---|---|---|---|
| Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday |
";
$dom = $cal{$line, $dow} || 0;
if ($dom > 0)
{
print WEB "\n";
print WEB "$dom"; $text = $Activities{$year, $mon, $dom} || ""; $text =~ s/\n/\n/gm; print WEB $text; } print WEB " | \n";
}
}
print WEB "||||||