diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2015-12-07 18:46:36 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2015-12-07 18:46:36 +0000 |
commit | 88d4d81dc11ff64a730d9dcdae82cff7d36e64db (patch) | |
tree | 282bd95b7751a53a5e6b4c83d19aa1d5da252f3c /usr.bin | |
parent | 14361d31da15e695410110aee9f724f20f5b6086 (diff) |
tweak the code a bit and add a -w option to display day of week.
okay jmc@, millert@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/calendar/calendar.1 | 8 | ||||
-rw-r--r-- | usr.bin/calendar/calendar.c | 11 | ||||
-rw-r--r-- | usr.bin/calendar/calendar.h | 9 | ||||
-rw-r--r-- | usr.bin/calendar/day.c | 23 |
4 files changed, 30 insertions, 21 deletions
diff --git a/usr.bin/calendar/calendar.1 b/usr.bin/calendar/calendar.1 index f0a9596c797..b795f4c65bf 100644 --- a/usr.bin/calendar/calendar.1 +++ b/usr.bin/calendar/calendar.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: calendar.1,v 1.39 2015/10/23 11:01:30 zhuk Exp $ +.\" $OpenBSD: calendar.1,v 1.40 2015/12/07 18:46:35 espie Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)calendar.1 8.1 (Berkeley) 6/29/93 .\" -.Dd $Mdocdate: October 23 2015 $ +.Dd $Mdocdate: December 7 2015 $ .Dt CALENDAR 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd reminder service .Sh SYNOPSIS .Nm calendar -.Op Fl ab +.Op Fl abw .Op Fl A Ar num .Op Fl B Ar num .Op Fl f Ar calendarfile @@ -82,6 +82,8 @@ instead of using the current date. If yy is specified, but cc is not, a value for yy between 69 and 99 results in a cc value of 19. Otherwise, a cc value of 20 is used. +.It Fl w +Print day of the week name in front of each event. .El .Pp To handle calendars in your national code table you can specify diff --git a/usr.bin/calendar/calendar.c b/usr.bin/calendar/calendar.c index 3a6df15d909..cc20f596bbc 100644 --- a/usr.bin/calendar/calendar.c +++ b/usr.bin/calendar/calendar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: calendar.c,v 1.34 2015/11/21 12:50:58 semarie Exp $ */ +/* $OpenBSD: calendar.c,v 1.35 2015/12/07 18:46:35 espie Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -54,6 +54,7 @@ char *calendarNoMail = "nomail"; /* don't sent mail if this file exists */ struct passwd *pw; int doall = 0; +int daynames = 0; time_t f_time = 0; int bodun_always = 0; @@ -74,7 +75,7 @@ main(int argc, char *argv[]) (void)setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "abf:t:A:B:-")) != -1) + while ((ch = getopt(argc, argv, "abwf:t:A:B:-")) != -1) switch (ch) { case '-': /* backward contemptible */ case 'a': @@ -109,6 +110,10 @@ main(int argc, char *argv[]) errx(1, "-B %s: %s", optarg, errstr); break; + case 'w': + daynames = 1; + break; + default: usage(); } @@ -263,7 +268,7 @@ void usage(void) { (void)fprintf(stderr, - "usage: calendar [-ab] [-A num] [-B num] [-f calendarfile] " + "usage: calendar [-abw] [-A num] [-B num] [-f calendarfile] " "[-t [[[cc]yy]mm]dd]\n"); exit(1); } diff --git a/usr.bin/calendar/calendar.h b/usr.bin/calendar/calendar.h index f329a079a22..2fc2e649e65 100644 --- a/usr.bin/calendar/calendar.h +++ b/usr.bin/calendar/calendar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: calendar.h,v 1.14 2015/03/15 00:41:28 millert Exp $ */ +/* $OpenBSD: calendar.h,v 1.15 2015/12/07 18:46:35 espie Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -32,6 +32,7 @@ extern struct passwd *pw; extern int doall; +extern int daynames; extern int bodun_always; extern time_t f_time; extern struct tm *tp; @@ -44,9 +45,11 @@ struct fixs { int len; }; +#define PRINT_DATE_BASE_LEN 35 + struct event { time_t when; - char print_date[31]; + char print_date[PRINT_DATE_BASE_LEN+1]; char **desc; char *ldesc; struct event *next; @@ -54,7 +57,7 @@ struct event { struct match { time_t when; - char print_date[30]; + char print_date[PRINT_DATE_BASE_LEN]; int bodun; int var; struct match *next; diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c index 0d73aae3823..f33c0accf2a 100644 --- a/usr.bin/calendar/day.c +++ b/usr.bin/calendar/day.c @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.30 2015/10/23 11:43:16 zhuk Exp $ */ +/* $OpenBSD: day.c,v 1.31 2015/12/07 18:46:35 espie Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -78,6 +78,14 @@ static struct fixs fnmonths[13]; /* full national months names */ static struct fixs nmonths[13]; /* short national month names */ void +fill_print_date(struct match *m, struct tm *tm) +{ + if (strftime(m->print_date, sizeof(m->print_date), + daynames ? "%a %b %d" : "%b %d", tm) == 0) + m->print_date[sizeof(m->print_date) - 1] = '\0'; +} + +void setnnames(void) { char buf[80]; @@ -455,12 +463,7 @@ isnow(char *endp, int bodun) } (void)mktime(&tmtmp); - if (strftime(tmp->print_date, - sizeof(tmp->print_date), - /* "%a %b %d", &tm); Skip weekdays */ - "%b %d", &tmtmp) == 0) - tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; - + fill_print_date(tmp, &tmtmp); tmp->var = varp; tmp->next = NULL; return(tmp); @@ -549,11 +552,7 @@ isnow(char *endp, int bodun) if ((tmp = malloc(sizeof(struct match))) == NULL) err(1, NULL); tmp->when = ttmp; - if (strftime(tmp->print_date, - sizeof(tmp->print_date), - /* "%a %b %d", &tm); Skip weekdays */ - "%b %d", &tmtmp) == 0) - tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; + fill_print_date(tmp, &tmtmp); tmp->bodun = bodun && tdiff == -1; tmp->var = varp; tmp->next = NULL; |