Peace,

This patch does away with the sixth week-row of each calendar month,
using the empty space in the first row in stead, as is conventional
in most printed calendars.

e.g.

$ cal jan
    January 2016
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31                  

becomes

    January 2016
Su Mo Tu We Th Fr Sa
31              1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Got the idea while working on a lunar calendar maker [1] which in
turn benefited from some of the ideas in cal.

Peace.

[1] aupc.orgfree.com/lc

--

Index: cal.c
===================================================================
RCS file: /cvs/src/usr.bin/cal/cal.c,v
retrieving revision 1.30
diff -u -p -r1.30 cal.c
--- cal.c       9 Oct 2015 01:37:06 -0000       1.30
+++ cal.c       21 Jun 2016 06:00:29 -0000
@@ -49,7 +49,7 @@
 #define        FIRST_MISSING_DAY       639799          /* 3 Sep 1752 */
 #define        NUMBER_MISSING_DAYS     11              /* 11 day correction */
 
-#define        MAXDAYS                 42              /* max slots in a month 
array */
+#define        MAXDAYS                 35              /* max slots in a month 
array */
 #define        SPACE                   -1              /* used in day array */
 
 static const int days_in_month[2][13] = {
@@ -63,35 +63,30 @@ const int sep1752s[MAXDAYS] = {
        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,
 }, 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,
        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,
 }, 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] = {
        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,
 };
 
 const char *month_names[12] = {
@@ -309,7 +304,7 @@ monthly(int month, int year)
        (void)printf("%*s%s\n%s\n",
            ((julian ? J_WEEK_LEN : WEEK_LEN) - len) / 2, "",
            lineout, day_headings);
-       for (row = 0; row < 6; row++) {
+       for (row = 0; row < 5; row++) {
                firstday = SPACE;
                for (col = 0, p = lineout; col < 7; col++,
                    p += julian ? J_DAY_LEN : DAY_LEN) {
@@ -346,7 +341,7 @@ j_yearly(int year)
                (void)printf("\n%s%*s%s\n", day_headings,
                    J_HEAD_SEP, "", day_headings);
 
-               for (row = 0; row < 6; row++) {
+               for (row = 0; row < 5; row++) {
                        for (which_cal = 0; which_cal < 2; which_cal++) {
                                p = lineout + which_cal * (J_WEEK_LEN + 2);
                                dp = &days[month + which_cal][row * 7];
@@ -386,7 +381,7 @@ yearly(int year)
                    HEAD_SEP + (wflag ? WEEKNUMBER_LEN : 0), "", day_headings,
                    HEAD_SEP + (wflag ? WEEKNUMBER_LEN : 0), "", day_headings);
 
-               for (row = 0; row < 6; row++) {
+               for (row = 0; row < 5; row++) {
                        for (which_cal = 0; which_cal < 3; which_cal++) {
                                p = lineout + which_cal * (week_len + 2);
                                
@@ -416,9 +411,9 @@ yearly(int year)
 
 /*
  * day_array --
- *     Fill in an array of 42 integers with a calendar.  Assume for a moment
- *     that you took the (maximum) 6 rows in a calendar and stretched them
- *     out end to end.  You would have 42 numbers or spaces.  This routine
+ *     Fill in an array of 35 integers with a calendar.  Assume for a moment
+ *     that you took the (maximum) 5 rows in a calendar and stretched them
+ *     out end to end.  You would have 35 numbers or spaces.  This routine
  *     builds that array for any month from Jan. 1 through Dec. 9999.
  */
 void
@@ -434,8 +429,10 @@ day_array(int month, int year, int *days
        dm = days_in_month[leap_year(year)][month];
        dw = day_in_week(mflag?0:1, month, year);
        day = julian ? day_in_year(1, month, year) : 1;
-       while (dm--)
+       while (dm--) {
                days[dw++] = day++;
+               dw %= MAXDAYS;
+       }
 }
 
 /*

Reply via email to