[BACK]Return to cal.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / cal

Diff for /src/usr.bin/cal/cal.c between version 1.21 and 1.22

version 1.21, 2006/10/29 22:51:09 version 1.22, 2008/04/10 15:07:04
Line 69 
Line 69 
         {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},          {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
 };  };
   
 const int sep1752[MAXDAYS] = {  const int sep1752s[MAXDAYS] = {
         SPACE,  SPACE,  1,      2,      14,     15,     16,          SPACE,  SPACE,  1,      2,      14,     15,     16,
         17,     18,     19,     20,     21,     22,     23,          17,     18,     19,     20,     21,     22,     23,
         24,     25,     26,     27,     28,     29,     30,          24,     25,     26,     27,     28,     29,     30,
         SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,          SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
         SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,          SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
         SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,          SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
 }, j_sep1752[MAXDAYS] = {  }, sep1752m[MAXDAYS] = {
           SPACE,  1,      2,      14,     15,     16,     17,
           18,     19,     20,     21,     22,     23,     24,
           25,     26,     27,     28,     29,     30,     SPACE,
           SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
           SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
           SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
   }, sep1752js[MAXDAYS] = {
         SPACE,  SPACE,  245,    246,    258,    259,    260,          SPACE,  SPACE,  245,    246,    258,    259,    260,
         261,    262,    263,    264,    265,    266,    267,          261,    262,    263,    264,    265,    266,    267,
         268,    269,    270,    271,    272,    273,    274,          268,    269,    270,    271,    272,    273,    274,
         SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,          SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
         SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,          SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
         SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,          SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
   }, sep1752jm[MAXDAYS] = {
           SPACE,  245,    246,    258,    259,    260,    261,
           262,    263,    264,    265,    266,    267,    268,
           269,    270,    271,    272,    273,    274,    SPACE,
           SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
           SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
           SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
 }, empty[MAXDAYS] = {  }, empty[MAXDAYS] = {
         SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,          SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
         SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,          SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,  SPACE,
Line 97 
Line 111 
         "July", "August", "September", "October", "November", "December",          "July", "August", "September", "October", "November", "December",
 };  };
   
 const char *day_headings = "Su Mo Tu We Th Fr Sa";  #define DAY_HEADINGS_S  "Su Mo Tu We Th Fr Sa"
 const char *j_day_headings = " Su  Mo  Tu  We  Th  Fr  Sa";  #define DAY_HEADINGS_M  "Mo Tu We Th Fr Sa Su"
   #define DAY_HEADINGS_JS " Su  Mo  Tu  We  Th  Fr  Sa"
   #define DAY_HEADINGS_JM " Mo  Tu  We  Th  Fr  Sa  Su"
   
   const int       *sep1752 = NULL;
   const char      *day_headings = NULL;
   
 /* leap year -- account for gregorian reformation in 1752 */  /* leap year -- account for gregorian reformation in 1752 */
 #define leap_year(yr) \  #define leap_year(yr) \
         ((yr) <= 1752 ? !((yr) % 4) : \          ((yr) <= 1752 ? !((yr) % 4) : \
Line 118 
Line 137 
         ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))          ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr))
   
 int julian;  int julian;
   int mflag = 0;
   
 void    ascii_day(char *, int);  void    ascii_day(char *, int);
 void    center(const char *, int, int);  void    center(const char *, int, int);
Line 140 
Line 160 
         const char *errstr;          const char *errstr;
   
         yflag = year = 0;          yflag = year = 0;
         while ((ch = getopt(argc, argv, "jy")) != -1)          while ((ch = getopt(argc, argv, "jmy")) != -1)
                 switch(ch) {                  switch(ch) {
                 case 'j':                  case 'j':
                         julian = 1;                          julian = 1;
                         break;                          break;
                   case 'm':
                           mflag = 1;
                           break;
                 case 'y':                  case 'y':
                         yflag = 1;                          yflag = 1;
                         break;                          break;
Line 155 
Line 178 
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
   
           day_headings = DAY_HEADINGS_S;
           sep1752 = sep1752s;
           if (mflag && julian) {
                   sep1752 = sep1752jm;
                   day_headings = DAY_HEADINGS_JM;
           } else if (mflag) {
                   sep1752 = sep1752m;
                   day_headings = DAY_HEADINGS_M;
           } else if (julian) {
                   sep1752 = sep1752js;
                   day_headings = DAY_HEADINGS_JS;
           }
   
         month = 0;          month = 0;
         switch(argc) {          switch(argc) {
         case 2:          case 2:
Line 215 
Line 251 
         len = strlen(lineout);          len = strlen(lineout);
         (void)printf("%*s%s\n%s\n",          (void)printf("%*s%s\n%s\n",
             ((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "",              ((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "",
             lineout, julian ? j_day_headings : day_headings);              lineout, day_headings);
         for (row = 0; row < 6; row++) {          for (row = 0; row < 6; row++) {
                 for (col = 0, p = lineout; col < 7; col++,                  for (col = 0, p = lineout; col < 7; col++,
                     p += julian ? J_DAY_LEN : DAY_LEN)                      p += julian ? J_DAY_LEN : DAY_LEN)
Line 243 
Line 279 
         for (month = 0; month < 12; month += 2) {          for (month = 0; month < 12; month += 2) {
                 center(month_names[month], J_WEEK_LEN, J_HEAD_SEP);                  center(month_names[month], J_WEEK_LEN, J_HEAD_SEP);
                 center(month_names[month + 1], J_WEEK_LEN, 0);                  center(month_names[month + 1], J_WEEK_LEN, 0);
                 (void)printf("\n%s%*s%s\n", j_day_headings, J_HEAD_SEP, "",                  (void)printf("\n%s%*s%s\n", day_headings,
                     j_day_headings);                      J_HEAD_SEP, "", day_headings);
   
                 for (row = 0; row < 6; row++) {                  for (row = 0; row < 6; row++) {
                         for (which_cal = 0; which_cal < 2; which_cal++) {                          for (which_cal = 0; which_cal < 2; which_cal++) {
                                 p = lineout + which_cal * (J_WEEK_LEN + 2);                                  p = lineout + which_cal * (J_WEEK_LEN + 2);
Line 278 
Line 315 
                 center(month_names[month], WEEK_LEN, HEAD_SEP);                  center(month_names[month], WEEK_LEN, HEAD_SEP);
                 center(month_names[month + 1], WEEK_LEN, HEAD_SEP);                  center(month_names[month + 1], WEEK_LEN, HEAD_SEP);
                 center(month_names[month + 2], WEEK_LEN, 0);                  center(month_names[month + 2], WEEK_LEN, 0);
                 (void)printf("\n%s%*s%s%*s%s\n", day_headings, HEAD_SEP,                  (void)printf("\n%s%*s%s%*s%s\n", day_headings,
                     "", day_headings, HEAD_SEP, "", day_headings);                      HEAD_SEP, "", day_headings, HEAD_SEP, "", day_headings);
   
                 for (row = 0; row < 6; row++) {                  for (row = 0; row < 6; row++) {
                         for (which_cal = 0; which_cal < 3; which_cal++) {                          for (which_cal = 0; which_cal < 3; which_cal++) {
                                 p = lineout + which_cal * (WEEK_LEN + 2);                                  p = lineout + which_cal * (WEEK_LEN + 2);
Line 308 
Line 346 
         int day, dw, dm;          int day, dw, dm;
   
         if (month == 9 && year == 1752) {          if (month == 9 && year == 1752) {
                 memmove(days,                  memmove(days, sep1752, MAXDAYS * sizeof(int));
                     julian ? j_sep1752 : sep1752, MAXDAYS * sizeof(int));  
                 return;                  return;
         }          }
         memmove(days, empty, MAXDAYS * sizeof(int));          memmove(days, empty, MAXDAYS * sizeof(int));
         dm = days_in_month[leap_year(year)][month];          dm = days_in_month[leap_year(year)][month];
         dw = day_in_week(1, month, year);          dw = day_in_week(mflag?0:1, month, year);
         day = julian ? day_in_year(1, month, year) : 1;          day = julian ? day_in_year(1, month, year) : 1;
         while (dm--)          while (dm--)
                 days[dw++] = day++;                  days[dw++] = day++;
Line 423 
Line 460 
 usage(void)  usage(void)
 {  {
   
         (void)fprintf(stderr, "usage: cal [-jy] [month] [year]\n");          (void)fprintf(stderr, "usage: cal [-jmy] [month] [year]\n");
         exit(1);          exit(1);
 }  }
   

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22