#!/usr/bin/awk -f
# awk program to convert my calendar.tbl file into an HTML table
#
# Brent Chivers 2004/Sep/23-
#
# include short commented-out lines in the HTML file. BDC 2004/09/28
#
# Turn HREF anchors into links on the next line. BDC 2004/10/21
#
# Use HTML
between entries. BDC 2005/04/23
# Add a after the date each day.
#
# favicon tags weren't done right. BDC 2006/04/18
# (I got poor directions from the web.)
#
# Do not add a "BASE HREF" tag; rely on index.html. BDC 2008/Apr/21
BEGIN { goturl = 0
days[1] = "SUNDAY" # days of the week
days[2] = "MONDAY"
days[3] = "TUESDAY"
days[4] = "WEDNESDAY"
days[5] = "THURSDAY"
days[6] = "FRIDAY"
days[7] = "SATURDAY" # HTML page headers
printf ("\n")
printf ("Brent's Calendar\n")
# printf ("\n")
printf ("\n")
printf ("\n")
printf ("\n")
printf ("\n")
printf ("\n")
printf ("\n")
printf ("\n")
printf ("\n")
printf ("\n")
printf ("\n")
printf ("
\n")
printf ("\n")
printf ("
Brent's Calendar
\n")
printf ("
\n") }
/^\.ex/ { done = 1 ; next } # nroff exit -- ignore the rest of the input
/\\\{/ { ignore = 1 ; next } # begin private calendar entry -- discard input
/\\\}/ { ignore = 0 ; next } # end private calendar entry -- examine following input
{ if (done) { next }} # don't process any more input
{ if (ignore) { next }} # don't process this input
/^\.__$/ { printf ("\n") ; next } # broken line across column
/^\._$/ { printf ("\n") ; next } # horizontal line across column
/^\.ds td / { updated = substr ($0, 8) ; next } # source file last-modified date
/^\.ce 120/ { live = 1 ; newday = 1 ; next } # we've gotten into the real stuff
/^\.\\\"leave/ { next } # omit hidden "leave" reminders
/^\.\\\"\._$/ { printf ("\n") ; next } # keep commented-out horizontal line across column
/^\.\\\"\.__$/ { printf ("\n") ; next } # keep commented-out broken line across column
/^\.\\\"http:/ { url = substr ($1, 4) # grab commented-out URL
goturl = 1
next } # URL to use on next line
/^\.\\\"/ { test = $0 # copy the input line
gsub ("", "", test) # remove italics tags,
gsub ("", "", test) # then find out the line length
if ((length (test)) < 22) {
if (goturl) {
printf ("%s \n", url, substr ($0, 4)) # make short nroff comment a link
goturl = 0 } # link has been used
else { printf ("%s \n", substr ($0, 4)) }} # short nroff comment -- include it
else { next }} # long nroff comment -- ignore this line
/^\./ { next } # ignore other roff commands/macros
/^T\{$/ { printf ("
\nSUNDAY \n") # start table row/column
day = 1 ; next }
/^T\}\|T\{$/ { printf ("
\n") # end column/start next
day++ ; printf ("%s \n", days[day]) ; next }
/^T\}$/ { printf ("
\n") ; next } # end column/table row
{ if (live) { if (goturl) {
printf ("%s \n", url, $0) # print lines as links and break
goturl = 0 } # link has been used
else { printf ("%s \n", $0) }}} # print other lines and break
{ newday++ ; if (live && (newday == 2)) {
printf ("\n") ; next }} # add horizontal line after the date
END { printf ("