=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/day.c,v retrieving revision 1.30 retrieving revision 1.34 diff -u -r1.30 -r1.34 --- src/usr.bin/calendar/day.c 2015/10/23 11:43:16 1.30 +++ src/usr.bin/calendar/day.c 2016/09/14 15:09:46 1.34 @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.30 2015/10/23 11:43:16 zhuk Exp $ */ +/* $OpenBSD: day.c,v 1.34 2016/09/14 15:09:46 millert Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -78,6 +78,14 @@ 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]; @@ -90,8 +98,7 @@ for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) ; buf[l] = '\0'; - if (ndays[i].name != NULL) - free(ndays[i].name); + free(ndays[i].name); if ((ndays[i].name = strdup(buf)) == NULL) err(1, NULL); ndays[i].len = strlen(buf); @@ -100,8 +107,7 @@ for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) ; buf[l] = '\0'; - if (fndays[i].name != NULL) - free(fndays[i].name); + free(fndays[i].name); if ((fndays[i].name = strdup(buf)) == NULL) err(1, NULL); fndays[i].len = strlen(buf); @@ -113,8 +119,7 @@ for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) ; buf[l] = '\0'; - if (nmonths[i].name != NULL) - free(nmonths[i].name); + free(nmonths[i].name); if ((nmonths[i].name = strdup(buf)) == NULL) err(1, NULL); nmonths[i].len = strlen(buf); @@ -123,8 +128,7 @@ for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) ; buf[l] = '\0'; - if (fnmonths[i].name != NULL) - free(fnmonths[i].name); + free(fnmonths[i].name); if ((fnmonths[i].name = strdup(buf)) == NULL) err(1, NULL); fnmonths[i].len = strlen(buf); @@ -455,12 +459,7 @@ } (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); @@ -544,16 +543,15 @@ tdiff = difftime(ttmp, f_time)/ SECSPERDAY; if (tdiff <= offset + f_dayAfter || (bodun && tdiff == -1)) { - if (tdiff >= 0 || - (bodun && tdiff == -1)) { + if (((tmtmp.tm_mon == month) || + (flags & F_SPECIAL) || + (interval == WEEKLY)) && + (tdiff >= 0 || + (bodun && tdiff == -1))) { 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;