# Calendar

" print "

Click on any highlighted date in the calendar below to move to" print "the events scheduled for that date, or click" print " here" print "to move directly to the chronological list of events.

" # # Emit a leading calendar with links to the events: the first event on each # date has an associated anchor with the date as its name. # # Determine the dates of the first day of the month of the first event and # last day of the month of the last event. # startMonth = substr(head, 1, 2) startYear = substr(head, 5, 2) wday = dow(startMonth "01" startYear) for(date = head; nxt[date]; date = nxt[date]); endMonth = substr(date, 1, 2) endYear = substr(date, 5, 2) # # Loop on all the days in all the months within the range of all the events # that are listed. Collect the output in cal[,] # mdx = 1 for(year = startYear; year <= endYear; year = incr(year)) { if(year == startYear) firstMonth = startMonth else firstMonth = "01" if(year == endYear) lastMonth = endMonth else lastMonth = "12" for(month = firstMonth; month <= lastMonth; month = incr(month)) { indent = substr(blanks, 1, 11 - ((length(monthStr[month])+5)/2)) cal[mdx,1] = indent monthStr[month] " 19" year cal[mdx,1] = cal[mdx,1] substr(blanks, 1, 21 - length(cal[mdx,1])) cal[mdx,2] = " S M Tu W Th F S " lastDay = ldom(month, year) ldx = 3 for(day = "01"; day <= lastDay; day = incr(day)) { if(day == "01") cal[mdx,ldx] = substr(blanks, 1, (wday-1) * 3) thisDate = month day year if((thisDate, 1) in title) cal[mdx,ldx] = cal[mdx,ldx] sprintf("%2d ", thisDate, day) else cal[mdx,ldx] = cal[mdx,ldx] sprintf("%2d ", day) if(wday == 7) { ldx++ wday = 1 } else wday++ } # end loop on days if(wday != 1) cal[mdx,ldx] = cal[mdx,ldx] substr(blanks,1,(8-wday)*3) mdx++ } # end loop on months } # end loop on years # # Now emit the calendar. Right now, it's done in two columns. # print "
```"
for(i = 1; i < mdx; i += 2) {
for(j = 1; (i,j) in cal || (i+1,j) in cal; j++) {
if((i,j) in cal)
filler = substr(blanks, 1, 5)
else
filler = substr(blanks, 1, 26)
print cal[i,j] filler cal[i+1,j]
}
print
}
print "```
" print # # Now, emit the events. # print "

# Events

" # # Loop on dates with associated events. # for(date = head; date; date = nxt[date]) { # # Loop on events. # for(i = 1; (date,i) in title; i++) { print "

## " title[date,i] "

" print # # Loop on paragraphs. # for(j = 1; (date,i,j) in body; j++) { print "

" body[date,i,j] "

" print } # end loop on paragraphs } # end loop on events } # end loop on dates print "" print "" } # # cmpDate() # # Compare dates, returning 0 if they are equal, 1 if 'one' is later than # 'two', and -1 if 'one' is earlier than 'two'. Special case: if the day # field of date 'one' is zero, return -2. # function cmpDate(one, two) { # # Compare the years. # if((diff = substr(one, 5) - substr(two, 5)) > 0) rval = 1 else if(diff < 0) rval = -1 # # Compare the months. # else if((diff = substr(one, 1, 2) - substr(two, 1, 2)) > 0) rval = 1 else if(diff < 0) rval = -1 # # Compare the days. # else if((diff = (dayOne = substr(one, 3, 2)) - substr(two, 3, 2)) > 0) rval = 1 else if(dayOne == "00") rval = -2 else if(diff < 0) rval = -1 else rval = 0 # if(debug) # print "Compared " one " with " two ", returned " rval > "/dev/stderr" return rval } # end cmpDates() # # ldom() # # Return the last day of the month. Valid for years 1901-2199. # function ldom(month, year) { if(month == "01") return "31" else if(month == "02") { if(year % 4 == 0) return 29 else return 28 } else if(month == "03") return "31" else if(month == "04") return "30" else if(month == "05") return "31" else if(month == "06") return "30" else if(month == "07") return "31" else if(month == "08") return "31" else if(month == "09") return "30" else if(month == "10") return "31" else if(month == "11") return "30" else return "31" } # end ldom() # # incr() # # Auto-increment for a two-digit decimal string. # function incr(i) { return sprintf("%02d", i+1) } # end incr() # # dow() # # Returns the day of the week-- as a digit between 1 and 7-- for any date # on or after 010194-- using the fact that that date was a Saturday (coded # as a 7) and the lame algorithm of determining how many days have since # passed. # function dow(date) { since = 0 year = substr(date, 5, 2) for(i = "94"; i < year; i = incr(i)) if(i % 4 == 0) since += 366 else since += 365 month = substr(date, 1, 2) for(i = "01"; i < month; i = incr(i)) since += ldom(i, year) day = substr(date, 3, 2) since += day-1 return (rVal = (since % 7)) ? rVal : 7 } # end dow()