1 /* cal - return monthly calendar
3 * usage: cal [mm] [yyyy]
5 * bugs: 1901 - 32767 only
7 * based on Kent Porter's code from "Software Spare Parts," 1986
8 * (software routines from the book are for use in any project,
9 * according to the author, but he deserves credit)
11 * returns current month's calendar with no arguments
12 * prints calendar for specified month and year
14 * -i causes interactive mode to prompt for month and year
16 * hacked for uClinux on uCsimm, bball@staffnet.com 2000-3-13
17 * (yes, i know some of this is ugly, but i don't program for a living)
28 int d, nd, mt[] = { 0, 21, 59, 90, 120, 151,
29 181, 212, 243, 273, 304, 334 };
31 if ( yr < 1901 || mo < 1 || mo > 12)
35 nd += (( d/4) - (d/100) + (d/400)) + mt[mo-1];
36 if (( yr % 4) == 0 && mo > 2)
38 return (( nd + 2) % 7);
42 fputs("usage: cal [option] [mm yyyy]\n", stdout);
43 fputs("-[h][?] - show help\n",stdout);
44 fputs("-i - interactive\n",stdout);
45 fputs("print monthly calendar as in: cal 3 2000\n", stdout);
48 int print_cal(mo, year)
51 int i, day, c, s, cal_lm();
52 static char *n[] = { "January", "February", "March", "April",
53 "May", "June", "July", "August", "September",
54 "October", "November", "December" };
55 static dmp [] = { 31, 28, 31, 30, 31, 30,
56 31, 31, 30, 31, 30, 31 };
58 if (( day = cal_lm (mo, year)) > 6) {
63 printf ("\n %s %d", n[mo], year);
64 fputs ("\n Su Mo Tu We Th Fr Sa",stdout);
68 for (s =0; s < day; s++)
74 printf ("%3d", day++);
79 } while (day <= dmp [mo] );
80 if ( mo == 1 && (year % 4) == 0)
81 if (( year % 100 ) != 0 || (year % 400 ) == 0)
83 fputs ("\n\n\n",stdout);
87 main(int argc, char *argv[])
94 char mbuff[4],ybuff[5];
100 ptr = localtime(&now);
103 /* we only need month and year */
104 sscanf(t,"%s%s%s%s%s",NULL,mbuff,NULL,NULL,ybuff);
105 if (strcmp(mbuff,"Jan") == 0)
107 if (strcmp(mbuff,"Feb") == 0)
109 if (strcmp(mbuff,"Mar") == 0)
111 if (strcmp(mbuff,"Apr") == 0)
113 if (strcmp(mbuff,"May") == 0)
115 if (strcmp(mbuff,"Jun") == 0)
117 if (strcmp(mbuff,"Jul") == 0)
119 if (strcmp(mbuff,"Aug") == 0)
121 if (strcmp(mbuff,"Sep") == 0)
123 if (strcmp(mbuff,"Oct") == 0)
125 if (strcmp(mbuff,"Nov") == 0)
127 if (strcmp(mbuff,"Dec") == 0)
129 if ((mo <= 0) || (mo > 12)) {
133 if ((year < 1901) || (year > 32767)) {
142 if (argv[param][0] == '-') {
143 switch(argv[param][1]) {
145 fputs("Enter month [1-12]:\n", stdout);
148 if ((mo <= 0) || (mo > 12)) {
151 fputs("Enter year [2000]:\n", stdout);
154 if ((year < 1901) || (year > 32767)) {
162 default: usage(); exit(0);
167 if ((mo <= 0) || (mo > 12)) {
171 year = atoi(argv[2]);
172 if ((year < 1901) || (year > 32767)) {