svn commit: r204982 - user/edwin/ncal

Edwin Groothuis edwin at FreeBSD.org
Wed Mar 10 21:42:05 UTC 2010


Author: edwin
Date: Wed Mar 10 21:42:05 2010
New Revision: 204982
URL: http://svn.freebsd.org/changeset/base/204982

Log:
  Move -d to -H.
  Use -d to select the current date.

Modified:
  user/edwin/ncal/ncal.1
  user/edwin/ncal/ncal.c

Modified: user/edwin/ncal/ncal.1
==============================================================================
--- user/edwin/ncal/ncal.1	Wed Mar 10 21:37:19 2010	(r204981)
+++ user/edwin/ncal/ncal.1	Wed Mar 10 21:42:05 2010	(r204982)
@@ -117,12 +117,6 @@ Britain and her colonies switched to the
 Print the number of the week below each week column.
 .It Fl y
 Display a calendar for the specified year.
-.It Fl b
-Switch to backwards compatibility mode (for debugging).
-.It Fl d Ar yyyy-mm-dd
-Use
-.Ar yyyy-mm-dd
-as the current date (for debugging of highlighting).
 .It Fl 3
 Display the previous, current and next month surrounding today.
 .It Fl A Ar number
@@ -133,6 +127,16 @@ of months after the current month.
 Display the
 .Ar number
 of months before the current month.
+.It Fl b
+Switch to backwards compatibility mode (for debugging).
+.It Fl d Ar yyyy-mm
+Use
+.Ar yyyy-mm
+as the current date (for debugging of date selection).
+.It Fl H Ar yyyy-mm-dd
+Use
+.Ar yyyy-mm-dd
+as the current date (for debugging of highlighting).
 .El
 .Pp
 A single parameter specifies the year (1\(en9999) to be displayed;

Modified: user/edwin/ncal/ncal.c
==============================================================================
--- user/edwin/ncal/ncal.c	Wed Mar 10 21:37:19 2010	(r204981)
+++ user/edwin/ncal/ncal.c	Wed Mar 10 21:42:05 2010	(r204982)
@@ -163,7 +163,7 @@ int	flag_nohighlight;	/* user doesn't wa
 int     flag_weeks;		/* user wants number of week */
 int     nswitch;		/* user defined switch date */
 int	nswitchb;		/* switch date for backward compatibility */
-int	today;
+int	highlightdate;
 
 char	*center(char *s, char *t, int w);
 wchar_t *wcenter(wchar_t *s, wchar_t *t, int w);
@@ -196,8 +196,7 @@ main(int argc, char *argv[])
 	int     flag_backward = 0;	/* user called cal--backward compat. */
 	int     flag_wholeyear = 0;	/* user wants the whole year */
 	int	flag_julian_cal = 0;	/* user wants Julian Calendar */
-	int     flag_julian_day = 0;	/* user wants the Julian day
-					 * numbers */
+	int     flag_julian_day = 0;	/* user wants the Julian day numbers */
 	int	flag_orthodox = 0;	/* user wants Orthodox easter */
 	int	flag_easter = 0;	/* user wants easter date */
 	int	flag_3months = 0;	/* user wants 3 month display (-3) */
@@ -207,8 +206,9 @@ main(int argc, char *argv[])
 	int	flag_givenmonth = 0;	/* user has specified month [n] */
 	int	flag_givenyear = 0;	/* user has specified year [n] */
 	char	*cp;			/* character pointer */
+	char	*flag_today = NULL;	/* debug: use date as being today */
 	char	*flag_month = NULL;	/* requested month as string */
-	char	*flag_highlightdate = NULL;
+	char	*flag_highlightdate = NULL; /* debug: date to highlight */
 	int	before, after;
 	const char    *locale;		/* locale to get country code */
 
@@ -256,7 +256,7 @@ main(int argc, char *argv[])
 
 	before = after = -1;
 
-	while ((ch = getopt(argc, argv, "A:B:3Jbd:ehjm:ops:wy")) != -1)
+	while ((ch = getopt(argc, argv, "A:B:3Jbd:eH:hjm:ops:wy")) != -1)
 		switch (ch) {
 		case '3':
 			flag_3months = 1;
@@ -287,6 +287,9 @@ main(int argc, char *argv[])
 			flag_backward = 1;
 			break;
 		case 'd':
+			flag_today = optarg;
+			break;
+		case 'H':
 			flag_highlightdate = optarg;
 			break;
 		case 'h':
@@ -362,7 +365,10 @@ main(int argc, char *argv[])
 		flag_givenyear = 1;
 		break;
 	case 0:
-		{
+		if (flag_today != NULL) {
+			y = strtol(flag_today, NULL, 10);
+			m = strtol(flag_today + 5, NULL, 10);
+		} else {
 			time_t t;
 			struct tm *tm;
 
@@ -443,6 +449,10 @@ main(int argc, char *argv[])
 		before = 1;
 		after = 1;
 	}
+	if (after == -1)
+		after = 0;
+	if (before == -1)
+		before = 0;
 
 	/* Highlight a specified day or today */
 	if (flag_highlightdate != NULL) {
@@ -459,7 +469,7 @@ main(int argc, char *argv[])
 		dt.m = tm1->tm_mon + 1;
 		dt.d = tm1->tm_mday;
 	}
-	today = sndaysb(&dt);
+	highlightdate = sndaysb(&dt);
 
 	if (flag_easter)
 		printeaster(y, flag_julian_cal, flag_orthodox);
@@ -480,7 +490,7 @@ usage(void)
 	    "       cal [-hj] [-m month] [year]\n"
 	    "       ncal [-hJjpwy] [-s country_code] [[month] year]\n"
 	    "       ncal [-hJeo] [year]\n"
-	    "for debug the highlighting: [-b] [-d yyyy-mm-dd]\n",
+	    "for debug the highlighting: [-b] [-H yyyy-mm-dd] [-d yyyy-mm]\n",
 	    stderr);
 	exit(EX_USAGE);
 }
@@ -791,7 +801,7 @@ mkmonthr(int y, int m, int jd_flag, stru
 					dt.d = j - jan1 + 1;
 				else
 					sdater(j, &dt);
-				if (j == today && !flag_nohighlight)
+				if (j == highlightdate && !flag_nohighlight)
 					highlight(mlines->lines[i] + k,
 					    ds + dt.d * dw, dw, &l);
 				else
@@ -895,7 +905,7 @@ mkmonthb(int y, int m, int jd_flag, stru
 					dt.d = j - jan1 + 1;
 				else
 					sdateb(j, &dt);
-				if (j == today && !flag_nohighlight)
+				if (j == highlightdate && !flag_nohighlight)
 					highlight(mlines->lines[i] + k,
 					    ds + dt.d * dw, dw, &l);
 				else


More information about the svn-src-user mailing list