1: char    dayw[]
   2: {
   3:     " S  M Tu  W Th  F  S"
   4: };
   5: char    *smon[]
   6: {
   7:     "Jan", "Feb", "Mar", "Apr",
   8:     "May", "Jun", "Jul", "Aug",
   9:     "Sep", "Oct", "Nov", "Dec",
  10: };
  11: char    string[432];
  12: main(argc, argv)
  13: char *argv[];
  14: {
  15:     register y, i, j;
  16:     int m;
  17: 
  18:     if(argc < 2) {
  19:         printf("usage: cal [month] year\n");
  20:         exit();
  21:     }
  22:     if(argc == 2)
  23:         goto xlong;
  24: 
  25: /*
  26:  *	print out just month
  27:  */
  28: 
  29:     m = number(argv[1]);
  30:     if(m<1 || m>12)
  31:         goto badarg;
  32:     y = number(argv[2]);
  33:     if(y<1 || y>9999)
  34:         goto badarg;
  35:     printf("      %s %l\n", smon[m-1], y);
  36:     printf("%s\n", dayw);
  37:     cal(m, y, string, 24);
  38:     for(i=0; i<6*24; i=+24)
  39:         pstr(string+i, 24);
  40:     exit();
  41: 
  42: /*
  43:  *	print out complete year
  44:  */
  45: 
  46: xlong:
  47:     y = number(argv[1]);
  48:     if(y<1 || y>9999)
  49:         goto badarg;
  50:     printf("\n\n\n");
  51:     printf("				%l\n", y);
  52:     printf("\n");
  53:     for(i=0; i<12; i=+3) {
  54:         for(j=0; j<6*72; j++)
  55:             string[j] = '\0';
  56:         printf("	 %s", smon[i]);
  57:         printf("			%s", smon[i+1]);
  58:         printf("		       %s\n", smon[i+2]);
  59:         printf("%s   %s   %s\n", dayw, dayw, dayw);
  60:         cal(i+1, y, string, 72);
  61:         cal(i+2, y, string+23, 72);
  62:         cal(i+3, y, string+46, 72);
  63:         for(j=0; j<6*72; j=+72)
  64:             pstr(string+j, 72);
  65:     }
  66:     printf("\n\n\n");
  67:     exit();
  68: 
  69: badarg:
  70:     printf("Bad argument\n");
  71: }
  72: 
  73: number(str)
  74: char *str;
  75: {
  76:     register n, c;
  77:     register char *s;
  78: 
  79:     n = 0;
  80:     s = str;
  81:     while(c = *s++) {
  82:         if(c<'0' || c>'9')
  83:             return(0);
  84:         n = n*10 + c-'0';
  85:     }
  86:     return(n);
  87: }
  88: 
  89: pstr(str, n)
  90: char *str;
  91: {
  92:     register i;
  93:     register char *s;
  94: 
  95:     s = str;
  96:     i = n;
  97:     while(i--)
  98:         if(*s++ == '\0')
  99:             s[-1] = ' ';
 100:     i = n+1;
 101:     while(i--)
 102:         if(*--s != ' ')
 103:             break;
 104:     s[1] = '\0';
 105:     printf("%s\n", str);
 106: }
 107: 
 108: char    mon[]
 109: {
 110:     0,
 111:     31, 29, 31, 30,
 112:     31, 30, 31, 31,
 113:     30, 31, 30, 31,
 114: };
 115: 
 116: cal(m, y, p, w)
 117: char *p;
 118: {
 119:     register d, i;
 120:     register char *s;
 121: 
 122:     s = p;
 123:     d = jan1(y);
 124:     mon[2] = 29;
 125:     mon[9] = 30;
 126: 
 127:     switch((jan1(y+1)+7-d)%7) {
 128: 
 129:     /*
 130: 	 *	non-leap year
 131: 	 */
 132:     case 1:
 133:         mon[2] = 28;
 134:         break;
 135: 
 136:     /*
 137: 	 *	1752
 138: 	 */
 139:     default:
 140:         mon[9] = 19;
 141:         break;
 142: 
 143:     /*
 144: 	 *	leap year
 145: 	 */
 146:     case 2:
 147:         ;
 148:     }
 149:     for(i=1; i<m; i++)
 150:         d =+ mon[i];
 151:     d =% 7;
 152:     s =+ 3*d;
 153:     for(i=1; i<=mon[m]; i++) {
 154:         if(i==3 & mon[m]==19) {
 155:             i =+ 11;
 156:             mon[m] =+ 11;
 157:         }
 158:         if(i > 9)
 159:             *s = i/10+'0';
 160:         s++;
 161:         *s++ = i%10+'0';
 162:         s++;
 163:         if(++d == 7) {
 164:             d = 0;
 165:             s = p+w;
 166:             p = s;
 167:         }
 168:     }
 169: }
 170: 
 171: /*
 172:  *	return day of the week
 173:  *	of jan 1 of given year
 174:  */
 175: 
 176: jan1(yr)
 177: {
 178:     register y, d;
 179: 
 180: /*
 181:  *	normal gregorian calendar
 182:  *	one extra day per four years
 183:  */
 184: 
 185:     y = yr;
 186:     d = 4+y+(y+3)/4;
 187: 
 188: /*
 189:  *	julian calendar
 190:  *	regular gregorian
 191:  *	less three days per 400
 192:  */
 193: 
 194:     if(y > 1800) {
 195:         d =- (y-1701)/100;
 196:         d =+ (y-1601)/400;
 197:     }
 198: 
 199: /*
 200:  *	great calendar changeover instant
 201:  */
 202: 
 203:     if(y > 1752)
 204:         d =+ 3;
 205: 
 206:     return(d%7);
 207: }

Defined functions

cal defined in line 116; used 4 times
jan1 defined in line 176; used 2 times
main defined in line 12; never used
number defined in line 73; used 3 times
pstr defined in line 89; used 2 times

Defined variables

dayw defined in line 1; used 4 times
mon defined in line 108; used 8 times
smon defined in line 5; used 4 times
string defined in line 11; used 7 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1061
Valid CSS Valid XHTML 1.0 Strict