=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/calendar/day.c,v retrieving revision 1.17 retrieving revision 1.28 diff -u -r1.17 -r1.28 --- src/usr.bin/calendar/day.c 2004/12/10 15:31:01 1.17 +++ src/usr.bin/calendar/day.c 2015/03/15 00:41:28 1.28 @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.17 2004/12/10 15:31:01 mickey Exp $ */ +/* $OpenBSD: day.c,v 1.28 2015/03/15 00:41:28 millert Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -29,20 +29,6 @@ * SUCH DAMAGE. */ -#ifndef lint -static const char copyright[] = -"@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -#if 0 -static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; -#else -static const char rcsid[] = "$OpenBSD: day.c,v 1.17 2004/12/10 15:31:01 mickey Exp $"; -#endif -#endif /* not lint */ - #include #include @@ -53,11 +39,12 @@ #include #include #include -#include #include "pathnames.h" #include "calendar.h" +extern struct iovec header[]; + #define WEEKLY 1 #define MONTHLY 2 #define YEARLY 3 @@ -90,8 +77,8 @@ static struct fixs fnmonths[13]; /* full national months names */ static struct fixs nmonths[13]; /* short national month names */ - -void setnnames(void) +void +setnnames(void) { char buf[80]; int i, l; @@ -100,7 +87,7 @@ for (i = 0; i < 7; i++) { tm.tm_wday = i; l = strftime(buf, sizeof(buf), "%a", &tm); - for (; l > 0 && isspace((int)buf[l - 1]); l--) + for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) ; buf[l] = '\0'; if (ndays[i].name != NULL) @@ -110,7 +97,7 @@ ndays[i].len = strlen(buf); l = strftime(buf, sizeof(buf), "%A", &tm); - for (; l > 0 && isspace((int)buf[l - 1]); l--) + for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) ; buf[l] = '\0'; if (fndays[i].name != NULL) @@ -123,7 +110,7 @@ for (i = 0; i < 12; i++) { tm.tm_mon = i; l = strftime(buf, sizeof(buf), "%b", &tm); - for (; l > 0 && isspace((int)buf[l - 1]); l--) + for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) ; buf[l] = '\0'; if (nmonths[i].name != NULL) @@ -133,7 +120,7 @@ nmonths[i].len = strlen(buf); l = strftime(buf, sizeof(buf), "%B", &tm); - for (; l > 0 && isspace((int)buf[l - 1]); l--) + for (; l > 0 && isspace((unsigned char)buf[l - 1]); l--) ; buf[l] = '\0'; if (fnmonths[i].name != NULL) @@ -143,12 +130,15 @@ fnmonths[i].len = strlen(buf); } /* Hardwired special events */ - spev[0].name = strdup(EASTER); - spev[0].nlen = EASTERNAMELEN; - spev[0].getev = easter; - spev[1].name = strdup(PASKHA); - spev[1].nlen = PASKHALEN; - spev[1].getev = paskha; + spev[0].name = strdup(PESACH); + spev[0].nlen = PESACHLEN; + spev[0].getev = pesach; + spev[1].name = strdup(EASTER); + spev[1].nlen = EASTERNAMELEN; + spev[1].getev = easter; + spev[2].name = strdup(PASKHA); + spev[2].nlen = PASKHALEN; + spev[2].getev = paskha; for (i = 0; i < NUMEV; i++) { if (spev[i].name == NULL) err(1, NULL); @@ -157,8 +147,7 @@ } void -settime(now) - time_t *now; +settime(time_t *now) { tp = localtime(now); tp->tm_sec = 0; @@ -173,7 +162,7 @@ cumdays = daytab[0]; /* Friday displays Monday's events */ offset = tp->tm_wday == 5 ? 3 : 1; - if (f_dayAfter) + if (f_SetdayAfter) offset = 0; /* Except not when range is set explicitly */ header[5].iov_base = dayname; @@ -187,60 +176,61 @@ /* convert [Year][Month]Day into unix time (since 1970) * Year: two or four digits, Month: two digits, Day: two digits */ -time_t Mktime (date) - char *date; +time_t +Mktime(char *date) { - time_t t; - int len; - struct tm tm; + time_t t; + int len; + struct tm tm; - (void)time(&t); - tp = localtime(&t); + (void)time(&t); + tp = localtime(&t); - len = strlen(date); - if (len < 2) - return((time_t)-1); - tm.tm_sec = 0; - tm.tm_min = 0; - /* Avoid getting caught by a timezone shift; set time to noon */ - tm.tm_isdst = 0; - tm.tm_hour = 12; - tm.tm_wday = 0; - tm.tm_mday = tp->tm_mday; - tm.tm_mon = tp->tm_mon; - tm.tm_year = tp->tm_year; + len = strlen(date); + if (len < 2) + return((time_t)-1); + bzero(&tm, sizeof tm); + tm.tm_sec = 0; + tm.tm_min = 0; + /* Avoid getting caught by a timezone shift; set time to noon */ + tm.tm_isdst = 0; + tm.tm_hour = 12; + tm.tm_wday = 0; + tm.tm_mday = tp->tm_mday; + tm.tm_mon = tp->tm_mon; + tm.tm_year = tp->tm_year; - /* Day */ - tm.tm_mday = atoi(date + len - 2); + /* Day */ + tm.tm_mday = atoi(date + len - 2); - /* Month */ - if (len >= 4) { - *(date + len - 2) = '\0'; - tm.tm_mon = atoi(date + len - 4) - 1; - } + /* Month */ + if (len >= 4) { + *(date + len - 2) = '\0'; + tm.tm_mon = atoi(date + len - 4) - 1; + } - /* Year */ - if (len >= 6) { + /* Year */ + if (len >= 6) { *(date + len - 4) = '\0'; tm.tm_year = atoi(date); - /* tm_year up TM_YEAR_BASE ... */ - if (tm.tm_year < 69) /* Y2K */ - tm.tm_year += 2000 - TM_YEAR_BASE; - else if (tm.tm_year < 100) - tm.tm_year += 1900 - TM_YEAR_BASE; - else if (tm.tm_year > TM_YEAR_BASE) - tm.tm_year -= TM_YEAR_BASE; - } + /* tm_year up TM_YEAR_BASE ... */ + if (tm.tm_year < 69) /* Y2K */ + tm.tm_year += 2000 - TM_YEAR_BASE; + else if (tm.tm_year < 100) + tm.tm_year += 1900 - TM_YEAR_BASE; + else if (tm.tm_year > TM_YEAR_BASE) + tm.tm_year -= TM_YEAR_BASE; + } #if DEBUG - printf("Mktime: %d %d %d %s\n", (int)mktime(&tm), (int)t, len, - asctime(&tm)); + printf("Mktime: %d %lld %d %s\n", (int)mktime(&tm), (long long)t, len, + asctime(&tm)); #endif - return(mktime(&tm)); + return(mktime(&tm)); } -void +static void adjust_calendar(int *day, int *month) { switch (calendar) { @@ -271,9 +261,7 @@ * with \t, is shown along with the matched line. */ struct match * -isnow(endp, bodun) - char *endp; - int bodun; +isnow(char *endp, int bodun) { int day = 0, flags = 0, month = 0, v1, v2, i; int monthp, dayp, varp = 0; @@ -300,7 +288,7 @@ /* adjust bodun rate */ if (bodun && !bodun_always) - bodun = !(arc4random() % 3); + bodun = !arc4random_uniform(3); /* Easter or Easter depending days */ if (flags & F_SPECIAL) @@ -589,8 +577,7 @@ int -getmonth(s) - char *s; +getmonth(char *s) { char **p; struct fixs *n; @@ -609,8 +596,7 @@ int -getday(s) - char *s; +getday(char *s) { char **p; struct fixs *n; @@ -633,8 +619,7 @@ * ... etc ... */ int -getdayvar(s) - char *s; +getdayvar(char *s) { int offset; @@ -674,8 +659,7 @@ int -foy(year) - int year; +foy(int year) { /* 0-6; what weekday Jan 1 is */ year--; @@ -685,8 +669,7 @@ void -variable_weekday(day, month, year) - int *day, month, year; +variable_weekday(int *day, int month, int year) { int v1, v2; int *cumdays;