#!/opt/local/bin/perl
# makepage.pl
# Copyright 2000-3 Michael Castleman.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Note that the GNU General Public License, found here in the file
# COPYING, applies only to the script makepage.pl, not to any input or
# output files of that script.
# I hereby note that the output of this script should NOT be considered
# a derived work for the purposes of copyleft/right, even though it may
# contain strings from this code.
#
use strict;
sub contact( \%;$ );
sub dumpfile( $ );
sub events( $ );
sub groups( $ );
$_ = <>; chomp;
unless (/^head (.*)$/i) {
die('the first directive must be "head"');
}
print '
';
dumpfile $1;
print "\n\n";
$_ = <>; chomp;
unless (/^h1 (.*)$/i) {
die('the second directive must be "h1"');
}
print "$1
\n";
print "\n";
my $line = 2;
while (<>) {
$line++;
chomp;
unless(/^([a-z]+) +\"([^\"]*?)\" +(.*)$/i) { # yay regexp!
print $_;
die("bad format on line $line");
}
print "\n| $2 | \n\n";
if ($1 eq "file") {
dumpfile $3;
} elsif ($1 eq "events") {
events $3;
} elsif ($1 eq "groups") {
groups $3;
} else {
die("unknown directive $1 on line $line");
}
print " |
\n";
}
print '
';
sub dumpfile( $ ) {
local $/;
undef $/;
open DUMPFH, $_[0] or die("couldn't open $_[0]: $!");
print ;
}
sub events( $ ) {
local ($/, $_);
$/ = "\n\n";
open EVENTFH, $_[0] or die("couldn't open $_[0]: $!");
while(my $in = ) {
unless ($in =~ /^\\/) {
chomp $in;
my @lines = split('\n', $in);
my $link = shift @lines;
my $evt = shift @lines;
my $first;
if ($link eq "0") {
$first = $evt;
} elsif ($link =~ m|^[0-9/]*$|) {
$first = "$evt";
} else {
$first = "$evt";
}
print("$first");
foreach(@lines) {
s[][$2]i;
print("
\n$_");
}
print("
\n");
} else {
print substr($in, 1) . "\n";
}
}
}
sub groups( $ ) {
local ($/, $_);
$/ = "\n\n";
open GROUPFH, $_[0] or die("couldn't open $_[0]: $!");
my $intro = ;
print $intro;
my (@groups, $i, $j); $i = -1;
while (my $bunch = ) {
$i++;
my $contact = -1;
chomp $bunch;
foreach(split('\n', $bunch)) {
my ($key, $val) = split (' ', $_, 2);
if ($key eq "contact") {
$contact++;
}
if ($key eq "phone") {
$val =~ s/x/\(212\) 85/;
$val =~ s/ / /;
}
($val .= "\@columbia.edu") if (($key eq "email") && !($val =~ /@/));
if ($contact == -1) {
$groups[$i]{$key} = $val;
} else {
$groups[$i]{"c"}[$contact]{$key} = $val;
}
}
}
@groups = sort { uc($::a->{group}) cmp uc($::b->{group}) } @groups;
print "\n";
for $i ( 0 .. $#groups ) {
print "\n";
if ( $#{$groups[$i]{"c"}} > 0 ) {
print "| ";
} else {
print " | \n";
}
print "";
print "" if ($groups[$i]{"url"});
print $groups[$i]{"group"};
print "" if ($groups[$i]{"url"});
print " ($groups[$i]{acronym})" if ($groups[$i]{"acronym"});
print "";
print " $groups[$i]{meet}" if ($groups[$i]{"meet"});
print " | \n";
if ( $#{$groups[$i]{"c"}} > 0 ) {
contact %{$groups[$i]{"c"}[0]}, "first";
} else {
contact %{$groups[$i]{"c"}[0]};
}
print "
\n";
if ( $#{$groups[$i]{"c"}} > 0 ) {
for $j ( 1 .. $#{$groups[$i]{"c"}} ) {
print "\n";
contact %{$groups[$i]{"c"}[$j]}, "next";
print "
\n";
}
}
}
print "
\n";
}
sub contact( \%;$ ) {
my ($href, $class) = @_;
if ($class) {
print "";
} else {
print " | ";
}
if ($href->{email}) {
# allegedly, this protects email addresses from spam-bots. I dunno.
my $spam = $href->{email};
$spam =~ s/@/@/g;
$spam =~ s/\././g;
print "";
print $href->{"contact"};
print "";
} else {
print $href->{"contact"};
}
print " | \n";
if ($class) {
print "";
} else {
print " | ";
}
if ($href->{phone}) {
print $href->{phone}
} else {
print " ";
}
print " | \n";
}