diff options
author | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2008-04-10 15:07:05 +0000 |
---|---|---|
committer | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2008-04-10 15:07:05 +0000 |
commit | 4829ef2cd36463eb34bb2ada75bd852f8df8b1e1 (patch) | |
tree | 4434d7402774cf195fb0fb3e118bd93904299f36 /usr.bin | |
parent | cdc3faf39f24fa825b21ededc134a49ab7c641ea (diff) |
Introduce the -m flag which shows weeks as starting on mondays.
input from tom@ through markus@
ok henning@, mbalmer@ and jmc@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cal/cal.1 | 10 | ||||
-rw-r--r-- | usr.bin/cal/cal.c | 69 |
2 files changed, 59 insertions, 20 deletions
diff --git a/usr.bin/cal/cal.1 b/usr.bin/cal/cal.1 index 474b332daa8..63b74d346ff 100644 --- a/usr.bin/cal/cal.1 +++ b/usr.bin/cal/cal.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: cal.1,v 1.17 2007/05/31 19:20:08 jmc Exp $ +.\" $OpenBSD: cal.1,v 1.18 2008/04/10 15:07:04 pyr Exp $ .\" $NetBSD: cal.1,v 1.6 1995/09/02 05:34:20 jtc Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 @@ -33,7 +33,7 @@ .\" .\" @(#)cal.1 8.2 (Berkeley) 4/28/95 .\" -.Dd $Mdocdate: May 31 2007 $ +.Dd $Mdocdate: April 10 2008 $ .Dt CAL 1 .Os .Sh NAME @@ -41,7 +41,7 @@ .Nd displays a calendar .Sh SYNOPSIS .Nm cal -.Op Fl jy +.Op Fl jmy .Op Ar month .Op Ar year .Sh DESCRIPTION @@ -53,6 +53,8 @@ The options are as follows: .Bl -tag -width Ds .It Fl j Display Julian dates (days one-based, numbered from January 1). +.It Fl m +Display weeks starting on Monday instead of Sunday. .It Fl y Display a calendar for the current year. .El @@ -96,7 +98,7 @@ utility is compliant with the specification. .Pp The flags -.Op Fl jy +.Op Fl jmy are extensions to that specification. .Sh HISTORY A diff --git a/usr.bin/cal/cal.c b/usr.bin/cal/cal.c index 8478f185d50..b45b02ef785 100644 --- a/usr.bin/cal/cal.c +++ b/usr.bin/cal/cal.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cal.c,v 1.21 2006/10/29 22:51:09 tom Exp $ */ +/* $OpenBSD: cal.c,v 1.22 2008/04/10 15:07:04 pyr Exp $ */ /* $NetBSD: cal.c,v 1.6 1995/03/26 03:10:24 glass Exp $ */ /* @@ -40,7 +40,7 @@ static const char copyright[] = #if 0 static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94"; #else -static const char rcsid[] = "$OpenBSD: cal.c,v 1.21 2006/10/29 22:51:09 tom Exp $"; +static const char rcsid[] = "$OpenBSD: cal.c,v 1.22 2008/04/10 15:07:04 pyr Exp $"; #endif #endif /* not lint */ @@ -69,20 +69,34 @@ static const int days_in_month[2][13] = { {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, 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, -}, 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, 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, @@ -97,8 +111,13 @@ const char *month_names[12] = { "July", "August", "September", "October", "November", "December", }; -const char *day_headings = "Su Mo Tu We Th Fr Sa"; -const char *j_day_headings = " Su Mo Tu We Th Fr Sa"; +#define DAY_HEADINGS_S "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 */ #define leap_year(yr) \ @@ -118,6 +137,7 @@ const char *j_day_headings = " Su Mo Tu We Th Fr Sa"; ((yr) / 4 - centuries_since_1700(yr) + quad_centuries_since_1700(yr)) int julian; +int mflag = 0; void ascii_day(char *, int); void center(const char *, int, int); @@ -140,11 +160,14 @@ main(int argc, char *argv[]) const char *errstr; yflag = year = 0; - while ((ch = getopt(argc, argv, "jy")) != -1) + while ((ch = getopt(argc, argv, "jmy")) != -1) switch(ch) { case 'j': julian = 1; break; + case 'm': + mflag = 1; + break; case 'y': yflag = 1; break; @@ -155,6 +178,19 @@ main(int argc, char *argv[]) argc -= 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; switch(argc) { case 2: @@ -215,7 +251,7 @@ monthly(int month, int year) len = strlen(lineout); (void)printf("%*s%s\n%s\n", ((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 (col = 0, p = lineout; col < 7; col++, p += julian ? J_DAY_LEN : DAY_LEN) @@ -243,8 +279,9 @@ j_yearly(int year) for (month = 0; month < 12; month += 2) { center(month_names[month], J_WEEK_LEN, J_HEAD_SEP); center(month_names[month + 1], J_WEEK_LEN, 0); - (void)printf("\n%s%*s%s\n", j_day_headings, J_HEAD_SEP, "", - j_day_headings); + (void)printf("\n%s%*s%s\n", day_headings, + J_HEAD_SEP, "", day_headings); + for (row = 0; row < 6; row++) { for (which_cal = 0; which_cal < 2; which_cal++) { p = lineout + which_cal * (J_WEEK_LEN + 2); @@ -278,8 +315,9 @@ yearly(int year) center(month_names[month], WEEK_LEN, HEAD_SEP); center(month_names[month + 1], WEEK_LEN, HEAD_SEP); center(month_names[month + 2], WEEK_LEN, 0); - (void)printf("\n%s%*s%s%*s%s\n", day_headings, HEAD_SEP, - "", day_headings, HEAD_SEP, "", day_headings); + (void)printf("\n%s%*s%s%*s%s\n", day_headings, + HEAD_SEP, "", day_headings, HEAD_SEP, "", day_headings); + for (row = 0; row < 6; row++) { for (which_cal = 0; which_cal < 3; which_cal++) { p = lineout + which_cal * (WEEK_LEN + 2); @@ -308,13 +346,12 @@ day_array(int month, int year, int *days) int day, dw, dm; if (month == 9 && year == 1752) { - memmove(days, - julian ? j_sep1752 : sep1752, MAXDAYS * sizeof(int)); + memmove(days, sep1752, MAXDAYS * sizeof(int)); return; } memmove(days, empty, MAXDAYS * sizeof(int)); 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; while (dm--) days[dw++] = day++; @@ -423,7 +460,7 @@ void usage(void) { - (void)fprintf(stderr, "usage: cal [-jy] [month] [year]\n"); + (void)fprintf(stderr, "usage: cal [-jmy] [month] [year]\n"); exit(1); } |