11 "January", "February", "March", "April",
12 "May", "June", "July", "August",
13 "September", "October", "November", "December",
25 void main(int argc, char *argv[]);
26 int number(char *str);
27 void pstr(char *str, int n);
28 void cal(int m, int y, char *p, int w);
34 main(int argc, char *argv[])
39 fprint(2, "usage: cal [month] [year]\n");
42 Binit(&bout, 1, OWRITE);
45 * no arg, print current month
55 * if looks like a month, print month
62 if(y >= 1 && y <= 12) {
71 * two arg, month and year
80 * print out just month
87 Bprint(&bout, " %s %ud\n", smon[m-1], y);
88 Bprint(&bout, "%s\n", dayw);
89 cal(m, y, string, 24);
90 for(i=0; i<6*24; i+=24)
95 * print out complete year
101 Bprint(&bout, "\n\n\n");
102 Bprint(&bout, " %ud\n", y);
104 for(i=0; i<12; i+=3) {
105 for(j=0; j<6*72; j++)
107 Bprint(&bout, " %.3s", smon[i]);
108 Bprint(&bout, " %.3s", smon[i+1]);
109 Bprint(&bout, " %.3s\n", smon[i+2]);
110 Bprint(&bout, "%s %s %s\n", dayw, dayw, dayw);
111 cal(i+1, y, string, 72);
112 cal(i+2, y, string+23, 72);
113 cal(i+3, y, string+46, 72);
114 for(j=0; j<6*72; j+=72)
117 Bprint(&bout, "\n\n\n");
121 Bprint(&bout, "cal: bad argument\n");
158 * convert to a number.
159 * if its a dictionary word,
160 * return negative number
168 for(n=0; s=dict[n].word; n++)
169 if(strcmp(s, str) == 0)
182 pstr(char *str, int n)
197 Bprint(&bout, "%s\n", str);
201 cal(int m, int y, char *p, int w)
211 switch((jan1(y+1)+7-d)%7) {
237 for(i=1; i<=mon[m]; i++) {
238 if(i==3 && mon[m]==19) {
256 * return day of the week
257 * of jan 1 of given year
265 * normal gregorian calendar
266 * one extra day per four years
275 * less three days per 400
284 * great calendar changeover instant
295 * get current month and year
302 tm = localtime(time(0));
311 tm = localtime(time(0));
312 return tm->year+1900;