#!/bin/perl # rem2html # # $Id: rem2html,v 1.3 1997-09-16 03:16:42 dfs Exp $ # # A script to convert from the output of "remind -p" to Hyper-Text Markup # Language (HTML), the text format used in WWW documents. By default, it # outputs a stand-alone file which can be fed directly into a web browser. # The output uses nested blocks, so it will only work in a browser # which supports tables (Netscape, MSIE, etc, NOT Lynx). # # This script works well on my computer (Linux 2.0.27) under Perl 5.003 and # 5.004. It should work fine on other unices but I have no idea whether # it will run under VMS, OS/2, Windows, etc. # # [Note from David: The REMIND license prohibits you from using REMIND # under Windows.] # # This file is Copyright (C) 1997 by Don Schwarz . use Getopt::Long; @months = (January,February,March,April,May,June,July,August,September,October,November,December); $rem2html_version = "1.0"; &parse_options(); if ($Options{'help'}) { &show_usage(); } elsif ($Options{'version'}) { print "Rem2HTML Version $rem2html_version.\n"; } else { &parse_input(); &output_header(); &output_data(); &output_footer(); } exit(0); sub show_usage { print STDERR < --forwurl url Same as --backurl, but with the next month's small calendar --tableonly Output the results as a
block only, no , etc. --border,-b size Set the border thickness of the table --cellspace,-t size Set the line thickness of the table --bgcolor,-g color Set the background color for the day entries EndOfUsage } sub parse_options { %Options = (); GetOptions (\%Options, "help|h", "version", "border|b=i", "cellspace|t=i", "backurl|bu:s", "forwurl|fu:s", "tableonly|to", "prologue|p=s", "bgcolor|g=s", "fs=s", "fh=s", "ft=s", "fe=s", "fd=s", "sh=i", "st=i", "se=i", "sd=i", ); $Options{'border'} = "BORDER=" . ($Options{'border'} || 1); $Options{'cellspace'} &&= "CELLSPACING=$Options{'cellspace'}"; $Options{'bgcolor'} &&= "BGCOLOR=$Options{'bgcolor'}"; } sub parse_input { local $where = 0; local $msg; local $type; local $day; @days = (); while (<>) { chomp($_); if (/rem2(html|ps) begin/) { } elsif (!$where) { next; } elsif ($where == 1) { local ($month, $year); ($month, $year, $month_length, $firstday, $mfirst) = split(" "); $caption = "$month, $year"; for $i ( 1 .. $month_length) { push(@days, ""); } } elsif ($where == 2) { @prevsc = split(" "); } elsif ($where == 3) { @nextsc = split(" "); } else { last if /rem2(html|ps) end/; next unless m/^(....).(\d*).(\d*)\s+(\S+)\s+(\S+)\s+(\S+)\s*(.*)$/; $type = $1; $msg = $7; $day = $3; next unless ($type eq "HTML" || ($type =~ /\d\d\d\d/)); if ($type eq "HTML") { $days[$day] .= "$msg "; } else { $days[$day] .= "

$msg

"; } } $where++; } die "Rem2HTML: Could not find any calendar data.\n", unless $where; } sub output_header { local ($title, $dayheader); if (!$Options{'tableonly'}) { print < Reminders for $caption EndOfHTML } print <) and Remind (written by David F. Skoll). --> EndOfHTML if ($Options{'prologue'}) { open(PROLOGUE, "< $Options{'prologue'}"); print while ( ); close(PROLOGUE); } $caption = &format_font($caption, $Options{'ft'}, $Options{'st'} || "+1"); print < EndOfHTML $mfirst || &print_day_header("Sunday"); foreach $dayheader (Monday,Tuesday,Wednesday,Thursday,Friday,Saturday) { &print_day_header($dayheader); } $mfirst && &print_day_header("Sunday"); print " \n"; } sub output_footer { print "
$caption
\n"; unless ($Options{'tableonly'}) { print < EndOfHTML } } sub output_data { local ($endday, $prevday, $nextday, $week, $weekday); local ($element, $day, $msg, $fday); $firstday -= $mfirst; if ($firstday < 0) { $firstday += 7; } $endday = $firstday + $month_length; $endweek = $endday + (6 - ($endday % 7)); $endday %= 7; if ( $firstday > 1 ) { $prevday = 0; $nextday = 1; } elsif ($endday ? ($endday < 5) : !$firstday) { $prevday = $endweek - 1; $nextday = $endweek; } else { $prevday = 0; $nextday = $endweek; } for $week ( 0..5 ) { print " \n"; for $weekday ( 0..6 ) { $element = ($week * 7) + ($weekday * 1); $day = $element - $firstday + 1; $msg = $days[$day]; $msg = $msg ? &format_font($msg, $Options{'fe'}, $Options{'se'}) : "



"; $fday = &format_font($day, $Options{'fd'}, $Options{'sd'} || -1); if ($day > 0 && $day <= $month_length) { print <

$fday

$msg EndOfHTML } elsif ($element == $prevday) { &small_calendar(@prevsc, 1, $Options{'backurl'}); } elsif ($element == $nextday) { &small_calendar(@nextsc, 2, $Options{'forwurl'}); } else { print "
"; } } print " \n"; last if $day >= $month_length && $element >= $nextday; } } sub small_calendar { local ($scname, $scn, $which, $url) = @_; local ($scstart, $l, $week, $weekday, $tday); $scname = "$scname", if $url; $scname = &format_font($scname, $Options{'fs'}, -2); if ($which == 1) { $scstart = $firstday - ($scn % 7); if ($scstart < 0) { $scstart += 7; } } else { $scstart = $firstday + ($month_length % 7); if ($scstart > 6) { $scstart -= 7; } } print < EndOfHTML $mfirst || &print_day_header("S", 1); foreach $l (M,T,W,T,F,S) { &print_day_header($l, 1); } $mfirst && &print_day_header("S", 1); print "\n"; for $week ( 0..5 ) { print " \n"; for $weekday ( 0..6 ) { $tday = ($week * 7) + ($weekday * 1) - $scstart + 1; $tday = "", if $tday <= 0 || $tday > $scn; print " \n"; } print " \n"; last if $tday >= $scn; } print < EndOfHTML } sub format_font { local ($text, $font, $size) = @_; if (!$text) { return ""; } elsif ($font && $size) { return "$text"; } elsif ($font) { return "$text"; } elsif ($size) { return "$text"; } else { return $text; } } sub print_day_header { local ($dheader, $small) = @_; if ($small) { $dheader = &format_font($dheader, $Options{'fs'}, -2); } else { $dheader = &format_font($dheader, $Options{'fh'}, $Options{'sh'}); } print " \n"; }
$scname
$tday
$dheader