include c:\cxpl\codes; \intrinsic 'code' declarations func WeekDay(Year, Month, Day); \Return day of week (0=Sun 1=Mon..6=Sat) int Year, Month, Day; \Works for years from 1583 onward [if Month<=2 then [Month:= Month+12; Year:= Year-1]; return rem((Day-1 + (Month+1)*26/10 + Year + Year/4 + Year/100*6 + Year/400)/7); ]; proc Space(N); \Display N space characters int N; while N do [ChOut(0, ^ ); N:= N-1]; proc Calendar(Year); \Display calendar for specified year int Year; int Month, Col, C, Line, MoName, Days, DayMax, Day(3); [MoName:= [ " January ", " February", " March ", " April ", " May ", " June ", " July ", " August ", "September", " October", " November", " December"]; Space(35); Text(0, "[Snoopy]"); CrLf(0); Space(37); IntOut(0, Year); CrLf(0); CrLf(0); for Month:= 1 to 12 do [for Col:= 0 to 3-1 do [Space(5); Text(0, MoName(Month+Col-1)); Space(7); if Col<2 then Space(8); ]; CrLf(0); for Col:= 0 to 3-1 do [Text(0, "Su Mo Tu We Th Fr Sa"); if Col<2 then Space(9); ]; CrLf(0); for Col:= 0 to 3-1 do \day of first Sunday of month (can be negative) Day(Col):= 1 - WeekDay(Year, Month+Col, 1); for Line:= 0 to 6-1 do [for Col:= 0 to 3-1 do [Days:= [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; DayMax:= Days(Month+Col); if Month+Col=2 & (rem(Year/4)=0 & rem(Year/100)#0 ! rem(Year/400)=0) then DayMax:= DayMax+1; \if February and leap year then add a day for C:= 0 to 7-1 do [if Day(Col)>=1 & Day(Col)<=DayMax then [IntOut(0, Day(Col)); if Day(Col)<10 then Space(1); \left justify ] else Space(2); \suppress out of range days Space(1); Day(Col):= Day(Col)+1; ]; if Col<2 then Space(8); ]; CrLf(0); ]; CrLf(0); Month:= Month+2; \2+1 months per Col(umn) ]; ]; Calendar(1969)