svn commit: r204492 - user/edwin/ncal
Edwin Groothuis
edwin at FreeBSD.org
Sun Feb 28 22:33:54 UTC 2010
Author: edwin
Date: Sun Feb 28 22:33:53 2010
New Revision: 204492
URL: http://svn.freebsd.org/changeset/base/204492
Log:
Fix this enhancement:
bin/144329: [request] cal(1) not highlightening today in year mode
Modified:
user/edwin/ncal/ncal.1
user/edwin/ncal/ncal.c
Modified: user/edwin/ncal/ncal.1
==============================================================================
--- user/edwin/ncal/ncal.1 Sun Feb 28 22:25:39 2010 (r204491)
+++ user/edwin/ncal/ncal.1 Sun Feb 28 22:33:53 2010 (r204492)
@@ -109,6 +109,12 @@ 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).
.El
.Pp
A single parameter specifies the year (1\(en9999) to be displayed;
@@ -116,12 +122,13 @@ note the year must be fully specified:
.Dq Li cal 89
will
.Em not
-display a calendar for 1989.
-Two parameters denote the month and year; the month is either a number between
-1 and 12, or a full or abbreviated name as specified by the current locale.
-Month and year default to those of the current system clock and time zone (so
+display a calendar for 1989. Two parameters denote the month and
+year; the month is either a number between 1 and 12, or a full or
+abbreviated name as specified by the current locale. Month and
+year default to those of the current system clock and time zone (so
.Dq Li cal -m 8
-will display a calendar for the month of August in the current year).
+will display a calendar for the month of August in the current
+year).
.Pp
A year starts on January 1.
.Sh SEE ALSO
@@ -142,5 +149,5 @@ The
command and manual were written by
.An Wolfgang Helbig Aq helbig at FreeBSD.org .
.Sh BUGS
-The assignment of Julian\(enGregorian switching dates to
-country codes is historically naive for many countries.
+The assignment of Julian\(enGregorian switching dates to country
+codes is historically naive for many countries.
Modified: user/edwin/ncal/ncal.c
==============================================================================
--- user/edwin/ncal/ncal.c Sun Feb 28 22:25:39 2010 (r204491)
+++ user/edwin/ncal/ncal.c Sun Feb 28 22:33:53 2010 (r204492)
@@ -60,6 +60,7 @@ struct monthlines {
wchar_t name[MAX_WIDTH + 1];
char lines[7][MAX_WIDTH + 1];
char weeks[MAX_WIDTH + 1];
+ int linelen[7];
};
struct weekdays {
@@ -202,6 +203,7 @@ main(int argc, char *argv[])
int flag_easter = 0; /* use wants easter date */
char *cp; /* character pointer */
char *flag_month = NULL; /* requested month as string */
+ char *flag_date = NULL;
const char *locale; /* locale to get country code */
char tbuf[1024], cbuf[512], *b;
time_t t;
@@ -263,7 +265,7 @@ main(int argc, char *argv[])
if (flag_backward)
nswitchb = ndaysj(&ukswitch);
- while ((ch = getopt(argc, argv, "Jehjm:ops:wy")) != -1)
+ while ((ch = getopt(argc, argv, "Jbd:ehjm:ops:wy")) != -1)
switch (ch) {
case 'J':
if (flag_backward)
@@ -271,6 +273,12 @@ main(int argc, char *argv[])
nswitch = ndaysj(&never);
flag_julian_cal = 1;
break;
+ case 'b':
+ flag_backward = 1;
+ break;
+ case 'd':
+ flag_date = optarg;
+ break;
case 'h':
term_so = term_se = NULL;
break;
@@ -359,11 +367,19 @@ main(int argc, char *argv[])
}
}
+ if (flag_date != NULL) {
+ date dt; /* handy date */
+
+ dt.y = strtol(flag_date, NULL, 10);
+ dt.m = strtol(flag_date + 5, NULL, 10);
+ dt.d = strtol(flag_date + 8, NULL, 10);
+
+ today = sndaysb(&dt);
+ }
+
if (flag_easter)
printeaster(y, flag_julian_cal, flag_orthodox);
else if (argc == 1 || flag_hole_year) {
- /* disable the highlight for now */
- today = 0;
if (flag_backward)
printyearb(y, flag_julian_day);
else
@@ -385,7 +401,9 @@ usage(void)
"usage: cal [-hjy] [[month] year]\n"
" cal [-hj] [-m month] [year]\n"
" ncal [-hJjpwy] [-s country_code] [[month] year]\n"
- " ncal [-hJeo] [year]\n", stderr);
+ " ncal [-hJeo] [year]\n"
+ "for debug the highlighting: [-b] [-d yyyy-mm-dd]\n",
+ stderr);
exit(EX_USAGE);
}
@@ -512,6 +530,9 @@ printyear(int y, int jd_flag)
sprintf(s, "%d", y);
printf("%s\n", center(t, s, mpl * mw));
+#define MW(mw, ms, ml) \
+ strlen(ms) > (ml) ? (mw) + 9 : (mw)
+
for (j = 0; j != 12; j += mpl) {
wprintf(L" %-*ls%-*ls",
mw, year[j].name,
@@ -523,16 +544,19 @@ printyear(int y, int jd_flag)
mw, year[j + 2].name,
year[j + 3].name);
for (i = 0; i != 7; i++) {
- wprintf(L"%.2ls%-*s%-*s",
+ wprintf(L"%.2ls%-*s%-*s%-*s",
wds.names[i],
- mw, year[j].lines[i],
- mw, year[j + 1].lines[i]);
- if (mpl == 3)
- printf("%s\n", year[j + 2].lines[i]);
- else
- printf("%-*s%s\n",
- mw, year[j + 2].lines[i],
- year[j + 3].lines[i]);
+ MW(mw, year[j].lines[i], year[j].linelen[i]),
+ year[j].lines[i],
+ MW(mw, year[j + 1].lines[i],
+ year[j + 1].linelen[i]),
+ year[j + 1].lines[i],
+ MW(mw, year[j + 2].lines[i],
+ year[j + 2].linelen[i]),
+ year[j + 2].lines[i]);
+ if (mpl == 4)
+ printf("%s", year[j + 3].lines[i]);
+ printf("\n");
}
if (flag_weeks) {
if (mpl == 3)
@@ -706,7 +730,7 @@ mkmonth(int y, int m, int jd_flag, struc
memcpy(mlines->lines[i] + k + l, " ", dw);
}
mlines->lines[i][k + l] = '\0';
-
+ mlines->linelen[i] = k;
}
/* fill the weeknumbers */
More information about the svn-src-user
mailing list