#!/bin/perl # rem2html # # $Id: rem2html,v 1.6 1998-02-12 03:32:17 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.] # # Rem2html puts "normal" CAL or MSG-type reminders in a

pair, # and escapes any special HTML characters. # # If you want to put actual HTML code in the calendar (hyper-links, for # example), use the "SPECIAL HTML" type. For example: # # REM Wed SPECIAL HTML

Meeting at \ # Linux HQ

# # This file is Copyright (C) 1997-8 by Don Schwarz # and David F. Skoll use Getopt::Long; @months = (January,February,March,April,May,June,July,August,September,October,November,December); $rem2html_version = "1.0"; &parse_options(); if (-t STDIN) { print STDERR "(Rem2HTML: Input should not come from a terminal.)\n"; $Options{'help'} = 1; } if ($Options{'help'}) { &show_usage(); } elsif ($Options{'version'}) { print "Rem2HTML Version $rem2html_version.\n"; } else { $successes = 0; while(1) { last if (!parse_input()); $successes++; &output_header(); &output_data(); &output_footer(); } print STDERR "Rem2HTML: Couldn't find any calendar data.\n" if (!$successes); } 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 escape_html { my($in) = @_; $in =~ s/\&/\&/g; $in =~ s/\/\>/g; return $in; } 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", "append|a=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) { @DayNames = split(" "); } elsif ($where == 3) { @prevsc = split(" "); } elsif ($where == 4) { @nextsc = split(" "); } else { return 1 if /rem2(html|ps) end/; next unless m/^(\d*).(\d*).(\d*)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*(.*)$/; $type = $4; $msg = $8; $day = $3; next unless ($type eq "HTML" || ($type eq "*")); if ($type eq "HTML") { $days[$day] .= "$msg "; } else { $msg = &escape_html($msg); $days[$day] .= "

$msg

"; } } $where++; } if ($where) { return 1; } return 0; } 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($DayNames[0]); for($i=1; $i<7; $i++) { &print_day_header($DayNames[$i]); } $mfirst && &print_day_header($DayNames[0]); print " \n"; } sub output_footer { print "
$caption
\n"; if ($Options{'append'}) { open(EPILOGUE, "< $Options{'append'}"); print while ( ); close(EPILOGUE); } 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(substr($DayNames[0], 0, 1), 1); for ($i=1; $i<7; $i++) { &print_day_header(substr($DayNames[$i], 0, 1), 1); } $mfirst && &print_day_header(substr($DayNames[0], 0, 1), 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