The attached patch should make the -M and -S flags work correctly even when ncal is called via the "cal" symlink.
Thanks, Stefan Kangas
Index: bsdmainutils/usr.bin/ncal/ncal.c =================================================================== --- bsdmainutils.orig/usr.bin/ncal/ncal.c 2010-10-17 01:30:45.000000000 +0200 +++ bsdmainutils/usr.bin/ncal/ncal.c 2010-10-17 02:10:27.000000000 +0200 @@ -274,10 +274,8 @@ nswitchb = ndaysj(&ukswitch); /* Determine on what day the week starts. */ - if (flag_backward) - weekstart = 1; /* technically not correct, but removing the need to add 1 later on */ #ifdef __GLIBC__ - else { + if (!flag_backward) { first_week_i = (intptr_t) nl_langinfo(_NL_TIME_WEEK_1STDAY); first_week_d.d = first_week_i % 100; first_week_i /= 100; @@ -346,13 +344,9 @@ flag_hole_year = 1; break; case 'S': - if (flag_backward) - usage(); weekstart = 0; break; case 'M': - if (flag_backward) - usage(); weekstart = 1; break; default: @@ -391,6 +385,10 @@ usage(); } + /* Technically not correct, but removes the need to add 1 later on */ + if (flag_backward) + weekstart += 1; + if (flag_month != NULL) { if (parsemonth(flag_month, &m, &y)) { errx(EX_USAGE, @@ -887,7 +885,7 @@ date dt; /* handy date */ int dw; /* width of numbers */ int first; /* first day of month */ - int firsts; /* sunday of first week of month */ + int firsts; /* first day of first week of month */ int i, j, k, l; /* just indices */ int jan1 = 0; /* the first day of this year */ int last; /* the first day of next month */ @@ -939,10 +937,13 @@ } /* - * Set firsts to the day number of sunday of the first week of + * Set firsts to the day number of the day starting the first week of * this month. (This might be in the last month) */ - firsts = first - (weekday(first)+1) % 7; + if (weekstart == 1) + firsts = first - (weekday(first)+1) % 7; + else + firsts = first - weekday(first); /* * Fill the lines with day of month or day of year (Julian day)