Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/cal add -3 option (display three month range)
details: https://anonhg.NetBSD.org/src/rev/1e99d8879e5f
branches: trunk
changeset: 533154:1e99d8879e5f
user: perry <perry%NetBSD.org@localhost>
date: Sat Jun 22 21:14:18 2002 +0000
description:
add -3 option (display three month range)
diffstat:
usr.bin/cal/cal.1 | 9 +++++-
usr.bin/cal/cal.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 66 insertions(+), 8 deletions(-)
diffs (163 lines):
diff -r 273555422798 -r 1e99d8879e5f usr.bin/cal/cal.1
--- a/usr.bin/cal/cal.1 Sat Jun 22 20:39:18 2002 +0000
+++ b/usr.bin/cal/cal.1 Sat Jun 22 21:14:18 2002 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: cal.1,v 1.9 2001/12/01 16:43:09 wiz Exp $
+.\" $NetBSD: cal.1,v 1.10 2002/06/22 21:14:18 perry Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -44,7 +44,7 @@
.Nd displays a calendar
.Sh SYNOPSIS
.Nm
-.Op Fl jy
+.Op Fl jy3
.Op Oo Ar month Oc Ar \ year
.Sh DESCRIPTION
.Nm
@@ -57,6 +57,11 @@
Display julian dates (days one-based, numbered from January 1).
.It Fl y
Display a calendar for the current year.
+.It Fl 3
+Display a three month calendar, starting with the current month or the
+specified year and month. If a year is specified but no month is
+specified January is assumed. This option is not compatible with
+.Fl j .
.El
.Pp
A single parameter specifies the year (1 - 9999) to be displayed;
diff -r 273555422798 -r 1e99d8879e5f usr.bin/cal/cal.c
--- a/usr.bin/cal/cal.c Sat Jun 22 20:39:18 2002 +0000
+++ b/usr.bin/cal/cal.c Sat Jun 22 21:14:18 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cal.c,v 1.12 2002/06/21 19:58:48 perry Exp $ */
+/* $NetBSD: cal.c,v 1.13 2002/06/22 21:14:18 perry Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -46,7 +46,7 @@
#if 0
static char sccsid[] = "@(#)cal.c 8.4 (Berkeley) 4/2/94";
#else
-__RCSID("$NetBSD: cal.c,v 1.12 2002/06/21 19:58:48 perry Exp $");
+__RCSID("$NetBSD: cal.c,v 1.13 2002/06/22 21:14:18 perry Exp $");
#endif
#endif /* not lint */
@@ -131,6 +131,7 @@
int day_in_week(int, int, int);
int day_in_year(int, int, int);
void j_yearly(int);
+void month3(int, int);
void monthly(int, int);
int main(int, char **);
void trim_trailing_spaces(char *);
@@ -142,10 +143,11 @@
{
struct tm *local_time;
time_t now;
- int ch, month, year, yflag;
+ int ch, month, year, yflag, threeflag;
yflag = year = 0;
- while ((ch = getopt(argc, argv, "jy")) != -1) {
+ threeflag = 0;
+ while ((ch = getopt(argc, argv, "jy3")) != -1) {
switch (ch) {
case 'j':
julian = 1;
@@ -153,12 +155,20 @@
case 'y':
yflag = 1;
break;
+ case '3':
+ threeflag = 1;
+ break;
case '?':
default:
usage();
/* NOTREACHED */
}
}
+
+ if (threeflag && julian) {
+ usage();
+ }
+
argc -= optind;
argv += optind;
@@ -183,12 +193,15 @@
usage();
}
- if (month)
+ if (threeflag)
+ month3(month ? month : 1 , year);
+ else if (month)
monthly(month, year);
else if (julian)
j_yearly(year);
else
yearly(year);
+
exit(0);
}
@@ -290,6 +303,46 @@
(void)printf("\n");
}
+void
+month3(int month, int year)
+{
+ int col, *dp, i, row, which_cal;
+ int days[12][MAXDAYS];
+ char *p, lineout[80];
+
+ for (i = 0; i < 12; i++)
+ day_array(i + 1, year, days[i]);
+
+ month--;
+
+ snprintf(lineout, sizeof(lineout), "%s %d",
+ month_names[month], year);
+ center(lineout, WEEK_LEN, HEAD_SEP);
+ snprintf(lineout, sizeof(lineout), "%s %d",
+ month_names[month+1], year);
+ center(lineout, WEEK_LEN, HEAD_SEP);
+ snprintf(lineout, sizeof(lineout), "%s %d",
+ month_names[month+2], year);
+ center(lineout, WEEK_LEN, 0);
+
+ (void)memset(lineout, ' ', sizeof(lineout) - 1);
+ lineout[sizeof(lineout) - 1] = '\0';
+
+ (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);
+ dp = &days[month + which_cal][row * 7];
+ for (col = 0; col < 7; col++, p += DAY_LEN)
+ ascii_day(p, *dp++);
+ }
+ *p = '\0';
+ trim_trailing_spaces(lineout);
+ (void)printf("%s\n", lineout);
+ }
+}
+
/*
* day_array --
* Fill in an array of 42 integers with a calendar. Assume for a moment
@@ -418,6 +471,6 @@
usage(void)
{
- (void)fprintf(stderr, "usage: cal [-jy] [[month] year]\n");
+ (void)fprintf(stderr, "usage: cal [-jy3] [[month] year]\n");
exit(1);
}
Home |
Main Index |
Thread Index |
Old Index