suitcase

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

yearcal.c (1172B)


      1 #include <stdio.h>
      2 #include <tai/caldate.h>
      3 
      4 char *montab[] = {
      5   "January"
      6 , "February"
      7 , "March"
      8 , "April"
      9 , "May"
     10 , "June"
     11 , "July"
     12 , "August"
     13 , "September"
     14 , "October"
     15 , "November"
     16 , "December"
     17 } ;
     18 
     19 int main(int argc, char **argv)
     20 {
     21   int year;
     22   long daystart;
     23   long dayend;
     24   long day;
     25   int weekday;
     26   struct caldate cd;
     27 
     28   while (*++argv) {
     29     year = atoi(*argv);
     30 
     31     cd.year = year;
     32     cd.month = 1;
     33     cd.day = 1;
     34     daystart = caldate_mjd(&cd);
     35     cd.year = year + 1;
     36     dayend = caldate_mjd(&cd);
     37 
     38     while ((daystart + 3) % 7) --daystart;
     39     while ((dayend + 3) % 7) ++dayend;
     40 
     41     for (day = daystart;day < dayend;++day) {
     42       caldate_frommjd(&cd,day,&weekday,(int *) 0);
     43       if (cd.year != year)
     44 	printf("   ");
     45       else {
     46 	if (cd.month & 1)
     47 	  if (cd.day < 10)
     48 	    printf(" %d%c%d ",cd.day % 10,8,cd.day % 10);
     49 	  else
     50 	    printf("%d%c%d%d%c%d ",cd.day / 10,8,cd.day / 10,cd.day % 10,8,cd.day % 10);
     51 	else
     52 	  printf("%2d ",cd.day);
     53         if (weekday == 6) {
     54 	  if ((cd.day >= 15) && (cd.day < 22))
     55 	    printf(" %s %d\n",montab[cd.month - 1],year);
     56 	  else
     57 	    printf("\n");
     58         }
     59       }
     60     }
     61     printf("\n");
     62   }
     63 
     64   exit(0);
     65 }