summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2005-11-16 16:45:11 +0000
committerderaadt <deraadt@openbsd.org>2005-11-16 16:45:11 +0000
commit638175c6231bbd3215c704b10c21bcbca827fb1b (patch)
tree7ef4cd0e7fa87ff160e640772c18ed7545b6c53d
parentno need for -h, any illegal option is fine (diff)
downloadwireguard-openbsd-638175c6231bbd3215c704b10c21bcbca827fb1b.tar.xz
wireguard-openbsd-638175c6231bbd3215c704b10c21bcbca827fb1b.zip
knf & cleanup; mickey ok
-rw-r--r--usr.bin/calendar/calendar.c14
-rw-r--r--usr.bin/calendar/day.c117
-rw-r--r--usr.bin/calendar/io.c155
-rw-r--r--usr.bin/calendar/ostern.c61
-rw-r--r--usr.bin/calendar/paskha.c7
5 files changed, 171 insertions, 183 deletions
diff --git a/usr.bin/calendar/calendar.c b/usr.bin/calendar/calendar.c
index e2ed6ff02d8..71a7ed21332 100644
--- a/usr.bin/calendar/calendar.c
+++ b/usr.bin/calendar/calendar.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: calendar.c,v 1.24 2005/08/09 12:32:58 mickey Exp $ */
+/* $OpenBSD: calendar.c,v 1.25 2005/11/16 16:45:11 deraadt Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -39,7 +39,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94";
#else
-static const char rcsid[] = "$OpenBSD: calendar.c,v 1.24 2005/08/09 12:32:58 mickey Exp $";
+static const char rcsid[] = "$OpenBSD: calendar.c,v 1.25 2005/11/16 16:45:11 deraadt Exp $";
#endif
#endif /* not lint */
@@ -232,7 +232,8 @@ main(int argc, char *argv[])
warnx("uid %u did not finish in time", pw->pw_uid);
}
if (time(NULL) - t >= SECSPERDAY)
- errx(2, "'calendar -a' took more than a day; stopped at uid %u",
+ errx(2, "'calendar -a' took more than a day; "
+ "stopped at uid %u",
pw->pw_uid);
}
for (;;) {
@@ -242,10 +243,9 @@ main(int argc, char *argv[])
runningkids--;
}
if (runningkids)
- warnx(
-"%d child processes still running when 'calendar -a' finished", runningkids);
- }
- else if ((caldir = getenv("CALENDAR_DIR")) != NULL) {
+ warnx("%d child processes still running when "
+ "'calendar -a' finished", runningkids);
+ } else if ((caldir = getenv("CALENDAR_DIR")) != NULL) {
if(!chdir(caldir))
cal();
} else
diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c
index d23b8dc0168..dc97bfb8bc1 100644
--- a/usr.bin/calendar/day.c
+++ b/usr.bin/calendar/day.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: day.c,v 1.19 2005/08/09 12:32:58 mickey Exp $ */
+/* $OpenBSD: day.c,v 1.20 2005/11/16 16:45:11 deraadt Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -39,7 +39,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94";
#else
-static const char rcsid[] = "$OpenBSD: day.c,v 1.19 2005/08/09 12:32:58 mickey Exp $";
+static const char rcsid[] = "$OpenBSD: day.c,v 1.20 2005/11/16 16:45:11 deraadt Exp $";
#endif
#endif /* not lint */
@@ -91,7 +91,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;
@@ -160,8 +161,7 @@ void setnnames(void)
}
void
-settime(now)
- time_t *now;
+settime(time_t *now)
{
tp = localtime(now);
tp->tm_sec = 0;
@@ -190,57 +190,57 @@ settime(now)
/* 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;
-
- (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;
-
- /* Day */
- tm.tm_mday = atoi(date + len - 2);
-
- /* Month */
- if (len >= 4) {
- *(date + len - 2) = '\0';
- tm.tm_mon = atoi(date + len - 4) - 1;
- }
-
- /* Year */
- if (len >= 6) {
+ time_t t;
+ int len;
+ struct tm tm;
+
+ (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;
+
+ /* Day */
+ tm.tm_mday = atoi(date + len - 2);
+
+ /* Month */
+ if (len >= 4) {
+ *(date + len - 2) = '\0';
+ tm.tm_mon = atoi(date + len - 4) - 1;
+ }
+
+ /* 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 %d %d %s\n", (int)mktime(&tm), (int)t, len,
+ asctime(&tm));
#endif
- return(mktime(&tm));
+ return(mktime(&tm));
}
void
@@ -274,9 +274,7 @@ adjust_calendar(int *day, int *month)
* 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;
@@ -592,8 +590,7 @@ isnow(endp, bodun)
int
-getmonth(s)
- char *s;
+getmonth(char *s)
{
char **p;
struct fixs *n;
@@ -612,8 +609,7 @@ getmonth(s)
int
-getday(s)
- char *s;
+getday(char *s)
{
char **p;
struct fixs *n;
@@ -636,8 +632,7 @@ getday(s)
* ... etc ...
*/
int
-getdayvar(s)
- char *s;
+getdayvar(char *s)
{
int offset;
@@ -677,8 +672,7 @@ getdayvar(s)
int
-foy(year)
- int year;
+foy(int year)
{
/* 0-6; what weekday Jan 1 is */
year--;
@@ -688,8 +682,7 @@ foy(year)
void
-variable_weekday(day, month, year)
- int *day, month, year;
+variable_weekday(int *day, int month, int year)
{
int v1, v2;
int *cumdays;
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c
index 2ec4952c692..70d9cd10d36 100644
--- a/usr.bin/calendar/io.c
+++ b/usr.bin/calendar/io.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: io.c,v 1.30 2005/11/14 15:56:35 deraadt Exp $ */
+/* $OpenBSD: io.c,v 1.31 2005/11/16 16:45:11 deraadt Exp $ */
/*
* Copyright (c) 1989, 1993, 1994
@@ -39,7 +39,7 @@ static const char copyright[] =
#if 0
static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94";
#else
-static const char rcsid[] = "$OpenBSD: io.c,v 1.30 2005/11/14 15:56:35 deraadt Exp $";
+static const char rcsid[] = "$OpenBSD: io.c,v 1.31 2005/11/16 16:45:11 deraadt Exp $";
#endif
#endif /* not lint */
@@ -67,28 +67,25 @@ static const char rcsid[] = "$OpenBSD: io.c,v 1.30 2005/11/14 15:56:35 deraadt E
struct iovec header[] = {
- {"From: ", 6},
- {NULL, 0},
- {" (Reminder Service)\nTo: ", 24},
- {NULL, 0},
- {"\nSubject: ", 10},
- {NULL, 0},
- {"'s Calendar\nPrecedence: bulk\n\n", 30},
+ { "From: ", 6 },
+ { NULL, 0 },
+ { " (Reminder Service)\nTo: ", 24 },
+ { NULL, 0 },
+ { "\nSubject: ", 10 },
+ { NULL, 0 },
+ { "'s Calendar\nPrecedence: bulk\n\n", 30 },
};
void
cal(void)
{
- int printing;
- char *p;
- FILE *fp;
- int ch, l, i, bodun = 0, bodun_maybe = 0;
- int var;
- char buf[2048 + 1], *prefix = NULL;
+ int ch, l, i, bodun = 0, bodun_maybe = 0, var, printing;
struct event *events, *cur_evt, *ev1, *tmp;
+ char buf[2048 + 1], *prefix = NULL, *p;
struct match *m;
size_t nlen;
+ FILE *fp;
events = NULL;
cur_evt = NULL;
@@ -147,19 +144,21 @@ cal(void)
/* User defined names for special events */
if ((p = strchr(buf, '='))) {
for (i = 0; i < NUMEV; i++) {
- if (strncasecmp(buf, spev[i].name, spev[i].nlen) == 0 &&
- (p - buf == spev[i].nlen) && buf[spev[i].nlen + 1]) {
- p++;
- if (spev[i].uname != NULL)
- free(spev[i].uname);
- if ((spev[i].uname = strdup(p)) == NULL)
- err(1, NULL);
- spev[i].ulen = strlen(p);
- i = NUMEV + 1;
- }
+ if (strncasecmp(buf, spev[i].name,
+ spev[i].nlen) == 0 &&
+ (p - buf == spev[i].nlen) &&
+ buf[spev[i].nlen + 1]) {
+ p++;
+ if (spev[i].uname != NULL)
+ free(spev[i].uname);
+ if ((spev[i].uname = strdup(p)) == NULL)
+ err(1, NULL);
+ spev[i].ulen = strlen(p);
+ i = NUMEV + 1;
+ }
}
- if (i > NUMEV)
- continue;
+ if (i > NUMEV)
+ continue;
}
if (buf[0] != '\t') {
printing = (m = isnow(buf, bodun)) ? 1 : 0;
@@ -178,32 +177,33 @@ cal(void)
ev1 = NULL;
while (m) {
- cur_evt = (struct event *) malloc(sizeof(struct event));
- if (cur_evt == NULL)
- err(1, NULL);
-
- cur_evt->when = m->when;
- snprintf(cur_evt->print_date,
- sizeof(cur_evt->print_date), "%s%c",
- m->print_date, (var + m->var) ? '*' : ' ');
- if (ev1) {
- cur_evt->desc = ev1->desc;
- cur_evt->ldesc = NULL;
- } else {
- if (m->bodun && prefix) {
- if (asprintf(&cur_evt->ldesc,
- "\t%s %s", prefix, p + 1) == -1)
- err(1, NULL);
- } else if ((cur_evt->ldesc =
- strdup(p)) == NULL)
+ cur_evt = malloc(sizeof(struct event));
+ if (cur_evt == NULL)
err(1, NULL);
- cur_evt->desc = &(cur_evt->ldesc);
- ev1 = cur_evt;
- }
- insert(&events, cur_evt);
- foo = m;
- m = m->next;
- free(foo);
+
+ cur_evt->when = m->when;
+ snprintf(cur_evt->print_date,
+ sizeof(cur_evt->print_date), "%s%c",
+ m->print_date, (var + m->var) ? '*' : ' ');
+ if (ev1) {
+ cur_evt->desc = ev1->desc;
+ cur_evt->ldesc = NULL;
+ } else {
+ if (m->bodun && prefix) {
+ if (asprintf(&cur_evt->ldesc,
+ "\t%s %s", prefix,
+ p + 1) == -1)
+ err(1, NULL);
+ } else if ((cur_evt->ldesc =
+ strdup(p)) == NULL)
+ err(1, NULL);
+ cur_evt->desc = &(cur_evt->ldesc);
+ ev1 = cur_evt;
+ }
+ insert(&events, cur_evt);
+ foo = m;
+ m = m->next;
+ free(foo);
}
}
} else if (printing) {
@@ -231,9 +231,7 @@ cal(void)
}
int
-getfield(p, endp, flags)
- char *p, **endp;
- int *flags;
+getfield(char *p, char **endp, int *flags)
{
int val, var, i;
char *start, savech;
@@ -257,8 +255,8 @@ getfield(p, endp, flags)
/* Sunday-1 */
if (*p == '+' || *p == '-')
- for(; isdigit(*++p);)
- ;
+ for(; isdigit(*++p); )
+ ;
savech = *p;
*p = '\0';
@@ -269,16 +267,16 @@ getfield(p, endp, flags)
/* Day */
else if ((val = getday(start)) != 0) {
- *flags |= F_ISDAY;
+ *flags |= F_ISDAY;
- /* variable weekday */
- if ((var = getdayvar(start)) != 0) {
- if (var <= 5 && var >= -4)
- val += var * 10;
+ /* variable weekday */
+ if ((var = getdayvar(start)) != 0) {
+ if (var <= 5 && var >= -4)
+ val += var * 10;
#ifdef DEBUG
- printf("var: %d\n", var);
+ printf("var: %d\n", var);
#endif
- }
+ }
}
/* Try specials (Easter, Paskha, ...) */
@@ -299,20 +297,20 @@ getfield(p, endp, flags)
switch(*start) {
case '-':
case '+':
- var = atoi(start);
- if (var > 365 || var < -365)
- return (0); /* Someone is just being silly */
- val += (NUMEV + 1) * var;
- /* We add one to the matching event and multiply by
- * (NUMEV + 1) so as not to return 0 if there's a match.
- * val will overflow if there is an obscenely large
- * number of special events. */
- break;
+ var = atoi(start);
+ if (var > 365 || var < -365)
+ return (0); /* Someone is just being silly */
+ val += (NUMEV + 1) * var;
+ /* We add one to the matching event and multiply by
+ * (NUMEV + 1) so as not to return 0 if there's a match.
+ * val will overflow if there is an obscenely large
+ * number of special events. */
+ break;
}
- *flags |= F_SPECIAL;
+ *flags |= F_SPECIAL;
}
if (!(*flags & F_SPECIAL)) {
- /* undefined rest */
+ /* undefined rest */
*p = savech;
return (0);
}
@@ -391,8 +389,7 @@ opencal(void)
}
void
-closecal(fp)
- FILE *fp;
+closecal(FILE *fp)
{
struct stat sbuf;
int nread, pdes[2], status;
@@ -439,9 +436,7 @@ done: (void)fclose(fp);
void
-insert(head, cur_evt)
- struct event **head;
- struct event *cur_evt;
+insert(struct event **head, struct event *cur_evt)
{
struct event *tmp, *tmp2;
diff --git a/usr.bin/calendar/ostern.c b/usr.bin/calendar/ostern.c
index 936850d25cd..aed15d996fd 100644
--- a/usr.bin/calendar/ostern.c
+++ b/usr.bin/calendar/ostern.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ostern.c,v 1.5 2004/12/10 15:31:01 mickey Exp $ */
+/* $OpenBSD: ostern.c,v 1.6 2005/11/16 16:45:11 deraadt Exp $ */
/*
* Copyright (c) 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
@@ -25,11 +25,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: ostern.c,v 1.5 2004/12/10 15:31:01 mickey Exp $
+ * $Id: ostern.c,v 1.6 2005/11/16 16:45:11 deraadt Exp $
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: ostern.c,v 1.5 2004/12/10 15:31:01 mickey Exp $";
+static const char rcsid[] = "$OpenBSD: ostern.c,v 1.6 2005/11/16 16:45:11 deraadt Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -40,41 +40,42 @@ static const char rcsid[] = "$OpenBSD: ostern.c,v 1.5 2004/12/10 15:31:01 mickey
/* return year day for Easter */
-int easter (year)
- int year; /* 0 ... abcd, NOT since 1900 */
+int
+easter(int year) /* 0 ... abcd, NOT since 1900 */
{
+ int e_a, e_b, e_c, e_d, e_e,e_f, e_g, e_h, e_i, e_k;
+ int e_l, e_m, e_n, e_p, e_q;
- int e_a, e_b, e_c, e_d, e_e,e_f, e_g, e_h, e_i, e_k,
- e_l, e_m, e_n, e_p, e_q;
+ /* silly, but it works */
+ e_a = year % 19;
+ e_b = year / 100;
+ e_c = year % 100;
- /* silly, but it works */
- e_a = year % 19;
- e_b = year / 100;
- e_c = year % 100;
+ e_d = e_b / 4;
+ e_e = e_b % 4;
+ e_f = (e_b + 8) / 25;
+ e_g = (e_b + 1 - e_f) / 3;
+ e_h = ((19 * e_a) + 15 + e_b - (e_d + e_g)) % 30;
+ e_i = e_c / 4;
+ e_k = e_c % 4;
+ e_l = (32 + 2 * e_e + 2 * e_i - (e_h + e_k)) % 7;
+ e_m = (e_a + 11 * e_h + 22 * e_l) / 451;
+ e_n = (e_h + e_l + 114 - (7 * e_m)) / 31;
+ e_p = (e_h + e_l + 114 - (7 * e_m)) % 31;
+ e_p = e_p + 1;
- e_d = e_b / 4;
- e_e = e_b % 4;
- e_f = (e_b + 8) / 25;
- e_g = (e_b + 1 - e_f) / 3;
- e_h = ((19 * e_a) + 15 + e_b - (e_d + e_g)) % 30;
- e_i = e_c / 4;
- e_k = e_c % 4;
- e_l = (32 + 2 * e_e + 2 * e_i - (e_h + e_k)) % 7;
- e_m = (e_a + 11 * e_h + 22 * e_l) / 451;
- e_n = (e_h + e_l + 114 - (7 * e_m)) / 31;
- e_p = (e_h + e_l + 114 - (7 * e_m)) % 31;
- e_p = e_p + 1;
+ e_q = 31 + 28 + e_p;
+ if (isleap(year))
+ e_q++;
- e_q = 31 + 28 + e_p;
- if (isleap(year))
- e_q++;
-
- if (e_n == 4)
+ if (e_n == 4)
e_q += 31;
#if DEBUG
- printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", e_a , e_b , e_c , e_d , e_e , e_f , e_g , e_h , e_i , e_k , e_l , e_m , e_n , e_p , e_q);
+ printf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
+ e_a, e_b, e_c, e_d, e_e, e_f, e_g, e_h,
+ e_i, e_k, e_l, e_m, e_n, e_p, e_q);
#endif
- return (e_q);
+ return (e_q);
}
diff --git a/usr.bin/calendar/paskha.c b/usr.bin/calendar/paskha.c
index 9109fe921a6..0200d53aebf 100644
--- a/usr.bin/calendar/paskha.c
+++ b/usr.bin/calendar/paskha.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: paskha.c,v 1.4 2004/12/10 15:31:01 mickey Exp $ */
+/* $OpenBSD: paskha.c,v 1.5 2005/11/16 16:45:11 deraadt Exp $ */
/*
* Copyright (C) 1993-1996 by Andrey A. Chernov, Moscow, Russia.
@@ -27,7 +27,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: paskha.c,v 1.4 2004/12/10 15:31:01 mickey Exp $";
+static const char rcsid[] = "$OpenBSD: paskha.c,v 1.5 2005/11/16 16:45:11 deraadt Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -39,8 +39,7 @@ static const char rcsid[] = "$OpenBSD: paskha.c,v 1.4 2004/12/10 15:31:01 mickey
/* (new style result); subtract 13 for old style */
int
-paskha (R)
- int R; /*year*/
+paskha(int R) /*year*/
{
int a, b, c, d, e;
static int x = 15;