diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-09-26 20:38:56 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2001-09-26 20:38:56 +0000 |
commit | b2f9818c35850bf64da266930b62d0b5fca22748 (patch) | |
tree | 97c350fc8fb93d3c80ca3bca9decb4c23542427d /usr.bin | |
parent | 0ccfb0dc34bb07d622fc6e61e51834706a5b948f (diff) |
special procesing for cyrillic calendars (.ru, .ua, .by for now).
does not affect any existing behaviour for everything else.
old idea expressed by form@; millert@ ok
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/calendar/calendar.1 | 7 | ||||
-rw-r--r-- | usr.bin/calendar/calendar.c | 13 | ||||
-rw-r--r-- | usr.bin/calendar/calendar.h | 6 | ||||
-rw-r--r-- | usr.bin/calendar/day.c | 29 | ||||
-rw-r--r-- | usr.bin/calendar/io.c | 28 |
5 files changed, 64 insertions, 19 deletions
diff --git a/usr.bin/calendar/calendar.1 b/usr.bin/calendar/calendar.1 index 7114042f674..e03a69a08d6 100644 --- a/usr.bin/calendar/calendar.1 +++ b/usr.bin/calendar/calendar.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: calendar.1,v 1.14 2000/04/15 11:45:54 aaron Exp $ +.\" $OpenBSD: calendar.1,v 1.15 2001/09/26 20:38:55 mickey Exp $ .\" .\" Copyright (c) 1989, 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -43,9 +43,10 @@ .Nm calendar .Op Fl a .Op Fl A Ar num +.Op Fl b .Op Fl B Ar num -.Op Fl t Ar [[[cc]yy][mm]]dd .Op Fl f Ar calendarfile +.Op Fl t Ar [[[cc]yy][mm]]dd .Sh DESCRIPTION The .Nm @@ -69,6 +70,8 @@ This requires superuser privileges. Print lines from today and next .Ar num days (forward, future). +.It Fl b +Enforce special date calculation mode for KOI8 calendars. .It Fl B Ar num Print lines from today and previous .Ar num diff --git a/usr.bin/calendar/calendar.c b/usr.bin/calendar/calendar.c index 553da968cb7..dc83991eb7d 100644 --- a/usr.bin/calendar/calendar.c +++ b/usr.bin/calendar/calendar.c @@ -1,4 +1,4 @@ -/* $OpenBSD: calendar.c,v 1.15 2001/09/03 15:53:00 pjanzen Exp $ */ +/* $OpenBSD: calendar.c,v 1.16 2001/09/26 20:38:55 mickey Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -43,7 +43,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: calendar.c,v 1.15 2001/09/03 15:53:00 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: calendar.c,v 1.16 2001/09/26 20:38:55 mickey Exp $"; #endif #endif /* not lint */ @@ -73,6 +73,7 @@ char *calendarNoMail = "nomail"; /* don't sent mail if this file exists */ struct passwd *pw; int doall = 0; time_t f_time = 0; +int bodun_always = 0; int f_dayAfter = 0; /* days after current date */ int f_dayBefore = 0; /* days before current date */ @@ -91,7 +92,7 @@ main(argc, argv) (void)setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "-af:t:A:B:")) != -1) + while ((ch = getopt(argc, argv, "-abf:t:A:B:")) != -1) switch (ch) { case '-': /* backward contemptible */ case 'a': @@ -100,6 +101,10 @@ main(argc, argv) doall = 1; break; + case 'b': + bodun_always++; + break; + case 'f': /* other calendar file */ calendarFile = optarg; break; @@ -258,7 +263,7 @@ void usage() { (void)fprintf(stderr, - "usage: calendar [-a] [-A num] [-B num] [-t [[[cc]yy][mm]]dd] " + "usage: calendar [-a] [-A num] [-b] [-B num] [-t [[[cc]yy][mm]]dd] " "[-f calendarfile]\n"); exit(1); } diff --git a/usr.bin/calendar/calendar.h b/usr.bin/calendar/calendar.h index 2fe6d35225b..0b5f5a83990 100644 --- a/usr.bin/calendar/calendar.h +++ b/usr.bin/calendar/calendar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: calendar.h,v 1.5 2001/09/03 15:53:00 pjanzen Exp $ */ +/* $OpenBSD: calendar.h,v 1.6 2001/09/26 20:38:55 mickey Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -36,6 +36,7 @@ extern struct passwd *pw; extern int doall; +extern int bodun_always; extern time_t f_time; extern struct iovec header[]; extern struct tm *tp; @@ -59,6 +60,7 @@ struct event { struct match { time_t when; char print_date[30]; + char prefix[30]; int var; struct match *next; }; @@ -80,7 +82,7 @@ int getmonth __P((char *)); int easter __P((int)); int paskha __P((int)); void insert __P((struct event **, struct event *)); -struct match *isnow __P((char *)); +struct match *isnow __P((char *, int)); FILE *opencal __P((void)); void settime __P((time_t *)); time_t Mktime __P((char *)); diff --git a/usr.bin/calendar/day.c b/usr.bin/calendar/day.c index 9588b8e2755..74a5379148e 100644 --- a/usr.bin/calendar/day.c +++ b/usr.bin/calendar/day.c @@ -1,4 +1,4 @@ -/* $OpenBSD: day.c,v 1.11 2001/06/05 21:27:16 pjanzen Exp $ */ +/* $OpenBSD: day.c,v 1.12 2001/09/26 20:38:55 mickey Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -43,7 +43,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: day.c,v 1.11 2001/06/05 21:27:16 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: day.c,v 1.12 2001/09/26 20:38:55 mickey Exp $"; #endif #endif /* not lint */ @@ -253,8 +253,9 @@ time_t Mktime (date) * with \t, is shown along with the matched line. */ struct match * -isnow(endp) +isnow(endp, bodun) char *endp; + int bodun; { int day = 0, flags = 0, month = 0, v1, v2, i; int monthp, dayp, varp = 0; @@ -279,6 +280,10 @@ isnow(endp) if (!(v1 = getfield(endp, &endp, &flags))) return (NULL); + /* adjust bodun rate */ + if (bodun && !bodun_always) + bodun = !(arc4random() % 3); + /* Easter or Easter depending days */ if (flags & F_SPECIAL) vwd = v1; @@ -423,7 +428,7 @@ isnow(endp) if ((v2 += isleap(tp->tm_year + TM_YEAR_BASE) ? 366 : 365) <= v1) tmtmp.tm_year++; - else + else if(!bodun || (day - tp->tm_yday) != -1) return(NULL); } if ((tmp = malloc(sizeof(struct match))) == NULL) @@ -435,6 +440,11 @@ isnow(endp) /* "%a %b %d", &tm); Skip weekdays */ "%b %d", &tmtmp) == 0) tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; + if (bodun && (day - tp->tm_yday) == -1) + strcpy(tmp->prefix, "Бодун на утро от: "); + else + tmp->prefix[0] = '\0'; + tmp->var = varp; tmp->next = NULL; return(tmp); @@ -517,8 +527,10 @@ isnow(endp) warnx("time out of range: %s", endp); else { tdiff = difftime(ttmp, f_time)/ SECSPERDAY; - if (tdiff <= offset + f_dayAfter) { - if (tdiff >= 0) { + if (tdiff <= offset + f_dayAfter || + (bodun && tdiff == -1)) { + if (tdiff >= 0 || + (bodun && tdiff == -1)) { if ((tmp = malloc(sizeof(struct match))) == NULL) err(1, NULL); tmp->when = ttmp; @@ -527,6 +539,11 @@ isnow(endp) /* "%a %b %d", &tm); Skip weekdays */ "%b %d", &tmtmp) == 0) tmp->print_date[sizeof(tmp->print_date) - 1] = '\0'; + if (bodun && tdiff == -1) + strcpy(tmp->prefix, + "Bodun na ytpo ot: "); + else + tmp->prefix[0] = '\0'; tmp->var = varp; tmp->next = NULL; if (tmp2) diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c index 163dfe469ae..47df11d22e2 100644 --- a/usr.bin/calendar/io.c +++ b/usr.bin/calendar/io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: io.c,v 1.14 2001/09/03 16:15:08 pjanzen Exp $ */ +/* $OpenBSD: io.c,v 1.15 2001/09/26 20:38:55 mickey Exp $ */ /* * Copyright (c) 1989, 1993, 1994 @@ -43,7 +43,7 @@ static const char copyright[] = #if 0 static const char sccsid[] = "@(#)calendar.c 8.3 (Berkeley) 3/25/94"; #else -static char rcsid[] = "$OpenBSD: io.c,v 1.14 2001/09/03 16:15:08 pjanzen Exp $"; +static char rcsid[] = "$OpenBSD: io.c,v 1.15 2001/09/26 20:38:55 mickey Exp $"; #endif #endif /* not lint */ @@ -87,7 +87,7 @@ cal() register int printing; register char *p; FILE *fp; - int ch, l, i; + int ch, l, i, bodun, bodun_maybe; int var; char buf[2048 + 1]; struct event *events, *cur_evt, *ev1, *tmp; @@ -110,8 +110,17 @@ cal() if (strncmp(buf, "LANG=", 5) == 0) { (void) setlocale(LC_ALL, buf + 5); setnnames(); + if (!strcmp(buf + 5, "ru_RU.KOI8-R") || + !strcmp(buf + 5, "uk_UA.KOI8-U") || + !strcmp(buf + 5, "by_BY.KOI8-B")) { + bodun_maybe++; + bodun = bodun_always; + } else + bodun_maybe = 0; continue; } + if (bodun_maybe && strncmp(buf, "BODUN=", 6) == 0) + bodun++; /* User defined names for special events */ if ((p = strchr(buf, '='))) { for (i = 0; i < NUMEV; i++) { @@ -130,7 +139,7 @@ cal() continue; } if (buf[0] != '\t') { - printing = (m = isnow(buf)) ? 1 : 0; + printing = (m = isnow(buf, bodun)) ? 1 : 0; if ((p = strchr(buf, '\t')) == NULL) { printing = 0; continue; @@ -158,7 +167,16 @@ cal() cur_evt->desc = ev1->desc; cur_evt->ldesc = NULL; } else { - if ((cur_evt->ldesc = strdup(p)) == NULL) + if (m->prefix[0]) { + int l1 = strlen(m->prefix); + int l2 = strlen(p); + if ((cur_evt->ldesc = + malloc(l1 + l2)) == NULL) + err(1, "realloc"); + sprintf(cur_evt->ldesc, "\t%s%s", + m->prefix, p + 1); + } else if ((cur_evt->ldesc = + strdup(p)) == NULL) err(1, NULL); cur_evt->desc = &(cur_evt->ldesc); ev1 = cur_evt; |