# HG changeset patch # User markus schnalke # Date 1393273938 -3600 # Node ID c1cd1d444353c2faed22dd61ee090a6edcaa88ac # Parent d18a3b2b76bd7f3b929b5f502858a6e7d48bf1c4 removed the type event: bday is only for birthdays and anniversaries diff -r d18a3b2b76bd -r c1cd1d444353 bday.1 --- a/bday.1 Mon Feb 24 21:22:21 2014 +0100 +++ b/bday.1 Mon Feb 24 21:32:18 2014 +0100 @@ -1,6 +1,6 @@ .TH bday 1 .SH NAME -bday \- inform about upcoming birthdays and other events +bday \- inform about upcoming birthdays and anniversaries @@ -13,9 +13,8 @@ .SH DESCRIPTION The .B bday -command reads standard input which gives a list of birthdays and events (see section -.B FILE FORMAT -for details). It produces a list of events which are coming up within the next few weeks. +command reads standard input which gives a list of birthdays and anniversaries. +It produces a list of events which are coming up within the next few weeks. @@ -27,8 +26,7 @@ .I warn days in advance, for entries that have no .B #w -flag (see -.BR FILE\ FORMAT ). +flag. If this switch is not specified, it defaults to 14 days. @@ -57,29 +55,12 @@ given a line such as .BR "1993-09-12 #ann Pen exploded" . .TP -.B #ev -This line is an event of some sort. If a year is given, the text will be displayed in that year only; otherwise, it will -be displayed every year. The remaining time is simply appended to the text; for instance, the input -.B 1996-04-07 #ev Easter -would give rise to the text -.BR "In 1 week: Easter" . -.TP .BI #w n Warn .I n days in advance of the date, rather than the default of 14 days or the number given with the .B -w flag. -.TP -.BI #for days -The event lasts for -.B days -days. -.TP -.BI #to date -The event lasts until -.IR date , -which should be in the same format as for the date of the event. diff -r d18a3b2b76bd -r c1cd1d444353 bday.c --- a/bday.c Mon Feb 24 21:22:21 2014 +0100 +++ b/bday.c Mon Feb 24 21:32:18 2014 +0100 @@ -30,16 +30,11 @@ where: date is YYYY-MM-DD - flags is ONE or ZERO of + flags is optionally #ann for an anniversary - #ev for an event - and zero or more of + and optionally #w to set the warn-in-advance time to n days (don't include the brackets! :) - #to - #for - to specify the length of time taken by an - event, for example a holiday separated by spaces. Lines preceeded by # are treated as comments. @@ -72,13 +67,10 @@ /* -------- modifier flags */ #define F_MTYPE 0x07 #define F_TANNIVERSARY 2 -#define F_TEVENT 3 /* flags processed immediately on encountering */ #define F_MIMMEDIATE 0x24 #define F_WTIME_P 0x08 -#define F_FORDAYS 0x16 -#define F_TODATE 0x24 struct _ftable { char* txt; @@ -95,7 +87,6 @@ struct event { char* text; struct date date; - struct date enddate; int warn; }; @@ -118,10 +109,7 @@ const struct _ftable FTABLE[] = { {"#ann",F_TANNIVERSARY}, - {"#ev", F_TEVENT}, {"#w", F_WTIME_P}, - {"#to", F_TODATE}, - {"#for", F_FORDAYS}, {NULL, 0} }; @@ -322,7 +310,7 @@ void liststrings(struct event *evl) { - int i,j; + int i; char *buf, *tmp; int size; @@ -333,43 +321,12 @@ if (evl[i].warn == -1 && delta(&(evl[i].date))==0) { size = append(buf, size, evl[i].text); - } else if (evl[i].enddate.day == 0) { - - if (delta(&(evl[i].date)) <= evl[i].warn) { - tmp = tdelta(&(evl[i].date)); - size = append(buf, size, tmp); - size = append(buf, size, ": "); - size = append(buf, size, evl[i].text); - free(tmp); - } - } else { - if (delta(&(evl[i].date)) <= evl[i].warn) { - size = append(buf, size, evl[i].text); - size = append(buf, size, " for "); - /* +1 because, if the difference between - two dates is one day, then the length of - an event on those days is two days */ - j = ddiff(&(evl[i].date),&(evl[i].enddate)) + 1; - tmp = ttime(0, 0, j/7, j%7); - size = append(buf, size, tmp); - free(tmp); - size = append(buf, size, " "); - tmp = tdelta(&(evl[i].date)); - size = append(buf, size, tmp); - } else if (delta(&(evl[i].enddate)) <= evl[i].warn) { - size = append(buf, size, evl[i].text); - size = append(buf, size, " "); - j = delta(&(evl[i].enddate)); - if (j) { - size = append(buf, size, "for "); - tmp = ttime(0, 0, j/7, j%7); - size = append(buf, size, tmp); - free(tmp); - size = append(buf, size, " longer"); - } else { - size = append(buf, size, "finishes today"); - } - } + } else if (delta(&(evl[i].date)) <= evl[i].warn) { + tmp = tdelta(&(evl[i].date)); + size = append(buf, size, tmp); + size = append(buf, size, ": "); + size = append(buf, size, evl[i].text); + free(tmp); } if (*buf) { size = append(buf, size, "."); @@ -387,9 +344,7 @@ /* -sort the events by the time before the next time they come up, -putting those where the start has passed but we are still in the -time-period first +sort the events by the time before the next time they come up */ int evcmp(const void *p1, const void *p2) @@ -398,24 +353,11 @@ struct event *e2=(struct event *) p2; unsigned d1, d2; - /* - if the delta for the enddate is less than that for the start - date, then we have passed the start date but not yet the end - date, and so we should display the enddate; otherwise, we - should display the start date - */ - d1=delta(&(e1->date)); - if (e1->enddate.day && delta(&(e1->enddate)) < d1) - d1=delta(&(e1->enddate)); - d2=delta(&(e2->date)); - if (e2->enddate.day && delta(&(e2->enddate)) < d2) - d2=delta(&(e2->enddate)); if (d1 < d2) return -1; if (d1 > d2) return 1; - return strcmp(e1->text, e2->text); } @@ -545,7 +487,7 @@ struct event * readlist() { - int i, j, k, l, d; + int i, j, k; struct event *evl; char buf[1024], buf2[1024]; char *ptr, *cp; @@ -554,7 +496,7 @@ /* initialise */ gettoday(); - for (i = 0, evl = NULL; fgets(buf, sizeof(buf), stdin) != NULL; i++) { + for (i=0, evl=NULL; fgets(buf, sizeof(buf), stdin) != NULL; i++) { evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1)); /* ignore comments and empty lines */ @@ -589,10 +531,6 @@ /* parse flags */ evl[i].warn = def_warn; - evl[i].enddate.day = 0; - evl[i].enddate.month = 0; - evl[i].enddate.year = 0; - flags = 0; j = 0; cp = skptok(ptr); @@ -604,27 +542,6 @@ case F_WTIME_P: /* #w -- sets warning time */ sscanf(cp, "#w%u", &(evl[i].warn)); break; - case F_FORDAYS: /* #for -- sets the duration of the event */ - sscanf(cp, "#for%u", &d); - evl[i].enddate=evl[i].date; - for (l = 1; l < d; l++) { - evl[i].enddate.day++; - if (evl[i].enddate.day > mlen(evl[i].enddate.month, evl[i].enddate.year)) { - evl[i].enddate.month++; - evl[i].enddate.day = 1; - } - if (evl[i].enddate.month > 12) { - evl[i].enddate.year++; - evl[i].enddate.month = 1; - } - } - break; - case F_TODATE: /* #to -- sets the end date of the event */ - l = sscanf(cp, "#to%u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day)); - if (l == 2) { - evl[i].enddate.year = 0; - } - break; case 0: break; default: @@ -654,16 +571,6 @@ strcpy(buf2, cp); } break; - case F_TEVENT: - /* if a year was specified, and this - warning isn't for it, ignore! */ - if ((evl[i].date.year && ydelta(evl[i].date, today)) - && (!evl[i].enddate.year || ydelta(evl[i].enddate, today))) { - i--; - continue; - } - strcpy(buf2, cp); - break; } evl[i].text = strdup(buf2); }