7 "Su M Tu W Th F Sa Su M Tu W Th F Sa",
11 "January", "February", "March", "April",
12 "May", "June", "July", "August",
13 "September", "October", "November", "December",
26 void main(int argc, char *argv[]);
27 int number(char *str);
28 void pstr(char *str, int n);
29 void cal(int m, int y, char *p, int w);
37 fprint(2, "usage: cal [-s 1..7] [month] [year]\n");
42 main(int argc, char *argv[])
49 wstart = atoi(EARGF(usage()));
50 if(wstart < 0 || wstart > 7)
60 Binit(&bout, 1, OWRITE);
62 dayw = dayws + 3*wstart;
66 * no arg, print current month
76 * if looks like a month, print month
83 if(y >= 1 && y <= 12) {
92 * two arg, month and year
101 * print out just month
106 if(y < 1 || y > 9999)
108 Bprint(&bout, " %s %ud\n", smon[m-1], y);
109 Bprint(&bout, "%s\n", dayw);
110 cal(m, y, string, 24);
111 for(i=0; i<6*24; i+=24)
116 * print out complete year
121 Bprint(&bout, "\n\n\n");
122 Bprint(&bout, " %ud\n", y);
124 for(i=0; i<12; i+=3) {
125 for(j=0; j<6*72; j++)
127 Bprint(&bout, " %.3s", smon[i]);
128 Bprint(&bout, " %.3s", smon[i+1]);
129 Bprint(&bout, " %.3s\n", smon[i+2]);
130 Bprint(&bout, "%s %s %s\n", dayw, dayw, dayw);
131 cal(i+1, y, string, 72);
132 cal(i+2, y, string+23, 72);
133 cal(i+3, y, string+46, 72);
134 for(j=0; j<6*72; j+=72)
137 Bprint(&bout, "\n\n\n");
141 Bprint(&bout, "cal: bad argument\n");
178 * convert to a number.
179 * if its a dictionary word,
180 * return negative number
188 for(n=0; s=dict[n].word; n++)
189 if(strcmp(s, str) == 0)
202 pstr(char *str, int n)
217 Bprint(&bout, "%s\n", str);
221 cal(int m, int y, char *p, int w)
231 switch((jan1(y+1)+7-d)%7) {
258 for(i=1; i<=mon[m]; i++) {
259 if(i==3 && mon[m]==19) {
277 * return day of the week
278 * of jan 1 of given year
286 * normal gregorian calendar
287 * one extra day per four years
296 * less three days per 400
305 * great calendar changeover instant
316 * get current month and year
323 tm = localtime(time(0));
332 tm = localtime(time(0));
333 return tm->year+1900;