bday
changeset 18:c1cd1d444353
removed the type event: bday is only for birthdays and anniversaries
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Mon, 24 Feb 2014 21:32:18 +0100 |
parents | d18a3b2b76bd |
children | eb4620a01023 |
files | bday.1 bday.c |
diffstat | 2 files changed, 16 insertions(+), 128 deletions(-) [+] |
line diff
1.1 --- a/bday.1 Mon Feb 24 21:22:21 2014 +0100 1.2 +++ b/bday.1 Mon Feb 24 21:32:18 2014 +0100 1.3 @@ -1,6 +1,6 @@ 1.4 .TH bday 1 1.5 .SH NAME 1.6 -bday \- inform about upcoming birthdays and other events 1.7 +bday \- inform about upcoming birthdays and anniversaries 1.8 1.9 1.10 1.11 @@ -13,9 +13,8 @@ 1.12 .SH DESCRIPTION 1.13 The 1.14 .B bday 1.15 -command reads standard input which gives a list of birthdays and events (see section 1.16 -.B FILE FORMAT 1.17 -for details). It produces a list of events which are coming up within the next few weeks. 1.18 +command reads standard input which gives a list of birthdays and anniversaries. 1.19 +It produces a list of events which are coming up within the next few weeks. 1.20 1.21 1.22 1.23 @@ -27,8 +26,7 @@ 1.24 .I warn 1.25 days in advance, for entries that have no 1.26 .B #w 1.27 -flag (see 1.28 -.BR FILE\ FORMAT ). 1.29 +flag. 1.30 If this switch is not specified, it defaults to 14 days. 1.31 1.32 1.33 @@ -57,29 +55,12 @@ 1.34 given a line such as 1.35 .BR "1993-09-12 #ann Pen exploded" . 1.36 .TP 1.37 -.B #ev 1.38 -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 1.39 -be displayed every year. The remaining time is simply appended to the text; for instance, the input 1.40 -.B 1996-04-07 #ev Easter 1.41 -would give rise to the text 1.42 -.BR "In 1 week: Easter" . 1.43 -.TP 1.44 .BI #w n 1.45 Warn 1.46 .I n 1.47 days in advance of the date, rather than the default of 14 days or the number given with the 1.48 .B -w 1.49 flag. 1.50 -.TP 1.51 -.BI #for days 1.52 -The event lasts for 1.53 -.B days 1.54 -days. 1.55 -.TP 1.56 -.BI #to date 1.57 -The event lasts until 1.58 -.IR date , 1.59 -which should be in the same format as for the date of the event. 1.60 1.61 1.62
2.1 --- a/bday.c Mon Feb 24 21:22:21 2014 +0100 2.2 +++ b/bday.c Mon Feb 24 21:32:18 2014 +0100 2.3 @@ -30,16 +30,11 @@ 2.4 2.5 where: 2.6 date is YYYY-MM-DD 2.7 - flags is ONE or ZERO of 2.8 + flags is optionally 2.9 #ann for an anniversary 2.10 - #ev for an event 2.11 - and zero or more of 2.12 + and optionally 2.13 #w<n> to set the warn-in-advance time to n days 2.14 (don't include the brackets! :) 2.15 - #to<date> 2.16 - #for<days> 2.17 - to specify the length of time taken by an 2.18 - event, for example a holiday 2.19 separated by spaces. 2.20 2.21 Lines preceeded by # are treated as comments. 2.22 @@ -72,13 +67,10 @@ 2.23 /* -------- modifier flags */ 2.24 #define F_MTYPE 0x07 2.25 #define F_TANNIVERSARY 2 2.26 -#define F_TEVENT 3 2.27 2.28 /* flags processed immediately on encountering */ 2.29 #define F_MIMMEDIATE 0x24 2.30 #define F_WTIME_P 0x08 2.31 -#define F_FORDAYS 0x16 2.32 -#define F_TODATE 0x24 2.33 2.34 struct _ftable { 2.35 char* txt; 2.36 @@ -95,7 +87,6 @@ 2.37 struct event { 2.38 char* text; 2.39 struct date date; 2.40 - struct date enddate; 2.41 int warn; 2.42 }; 2.43 2.44 @@ -118,10 +109,7 @@ 2.45 2.46 const struct _ftable FTABLE[] = { 2.47 {"#ann",F_TANNIVERSARY}, 2.48 - {"#ev", F_TEVENT}, 2.49 {"#w", F_WTIME_P}, 2.50 - {"#to", F_TODATE}, 2.51 - {"#for", F_FORDAYS}, 2.52 {NULL, 0} 2.53 }; 2.54 2.55 @@ -322,7 +310,7 @@ 2.56 void 2.57 liststrings(struct event *evl) 2.58 { 2.59 - int i,j; 2.60 + int i; 2.61 char *buf, *tmp; 2.62 int size; 2.63 2.64 @@ -333,43 +321,12 @@ 2.65 2.66 if (evl[i].warn == -1 && delta(&(evl[i].date))==0) { 2.67 size = append(buf, size, evl[i].text); 2.68 - } else if (evl[i].enddate.day == 0) { 2.69 - 2.70 - if (delta(&(evl[i].date)) <= evl[i].warn) { 2.71 - tmp = tdelta(&(evl[i].date)); 2.72 - size = append(buf, size, tmp); 2.73 - size = append(buf, size, ": "); 2.74 - size = append(buf, size, evl[i].text); 2.75 - free(tmp); 2.76 - } 2.77 - } else { 2.78 - if (delta(&(evl[i].date)) <= evl[i].warn) { 2.79 - size = append(buf, size, evl[i].text); 2.80 - size = append(buf, size, " for "); 2.81 - /* +1 because, if the difference between 2.82 - two dates is one day, then the length of 2.83 - an event on those days is two days */ 2.84 - j = ddiff(&(evl[i].date),&(evl[i].enddate)) + 1; 2.85 - tmp = ttime(0, 0, j/7, j%7); 2.86 - size = append(buf, size, tmp); 2.87 - free(tmp); 2.88 - size = append(buf, size, " "); 2.89 - tmp = tdelta(&(evl[i].date)); 2.90 - size = append(buf, size, tmp); 2.91 - } else if (delta(&(evl[i].enddate)) <= evl[i].warn) { 2.92 - size = append(buf, size, evl[i].text); 2.93 - size = append(buf, size, " "); 2.94 - j = delta(&(evl[i].enddate)); 2.95 - if (j) { 2.96 - size = append(buf, size, "for "); 2.97 - tmp = ttime(0, 0, j/7, j%7); 2.98 - size = append(buf, size, tmp); 2.99 - free(tmp); 2.100 - size = append(buf, size, " longer"); 2.101 - } else { 2.102 - size = append(buf, size, "finishes today"); 2.103 - } 2.104 - } 2.105 + } else if (delta(&(evl[i].date)) <= evl[i].warn) { 2.106 + tmp = tdelta(&(evl[i].date)); 2.107 + size = append(buf, size, tmp); 2.108 + size = append(buf, size, ": "); 2.109 + size = append(buf, size, evl[i].text); 2.110 + free(tmp); 2.111 } 2.112 if (*buf) { 2.113 size = append(buf, size, "."); 2.114 @@ -387,9 +344,7 @@ 2.115 2.116 2.117 /* 2.118 -sort the events by the time before the next time they come up, 2.119 -putting those where the start has passed but we are still in the 2.120 -time-period first 2.121 +sort the events by the time before the next time they come up 2.122 */ 2.123 int 2.124 evcmp(const void *p1, const void *p2) 2.125 @@ -398,24 +353,11 @@ 2.126 struct event *e2=(struct event *) p2; 2.127 unsigned d1, d2; 2.128 2.129 - /* 2.130 - if the delta for the enddate is less than that for the start 2.131 - date, then we have passed the start date but not yet the end 2.132 - date, and so we should display the enddate; otherwise, we 2.133 - should display the start date 2.134 - */ 2.135 - 2.136 d1=delta(&(e1->date)); 2.137 - if (e1->enddate.day && delta(&(e1->enddate)) < d1) 2.138 - d1=delta(&(e1->enddate)); 2.139 - 2.140 d2=delta(&(e2->date)); 2.141 - if (e2->enddate.day && delta(&(e2->enddate)) < d2) 2.142 - d2=delta(&(e2->enddate)); 2.143 2.144 if (d1 < d2) return -1; 2.145 if (d1 > d2) return 1; 2.146 - 2.147 return strcmp(e1->text, e2->text); 2.148 } 2.149 2.150 @@ -545,7 +487,7 @@ 2.151 struct event * 2.152 readlist() 2.153 { 2.154 - int i, j, k, l, d; 2.155 + int i, j, k; 2.156 struct event *evl; 2.157 char buf[1024], buf2[1024]; 2.158 char *ptr, *cp; 2.159 @@ -554,7 +496,7 @@ 2.160 /* initialise */ 2.161 gettoday(); 2.162 2.163 - for (i = 0, evl = NULL; fgets(buf, sizeof(buf), stdin) != NULL; i++) { 2.164 + for (i=0, evl=NULL; fgets(buf, sizeof(buf), stdin) != NULL; i++) { 2.165 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1)); 2.166 2.167 /* ignore comments and empty lines */ 2.168 @@ -589,10 +531,6 @@ 2.169 /* parse flags */ 2.170 2.171 evl[i].warn = def_warn; 2.172 - evl[i].enddate.day = 0; 2.173 - evl[i].enddate.month = 0; 2.174 - evl[i].enddate.year = 0; 2.175 - 2.176 flags = 0; 2.177 j = 0; 2.178 cp = skptok(ptr); 2.179 @@ -604,27 +542,6 @@ 2.180 case F_WTIME_P: /* #w<n> -- sets warning time */ 2.181 sscanf(cp, "#w%u", &(evl[i].warn)); 2.182 break; 2.183 - case F_FORDAYS: /* #for<days> -- sets the duration of the event */ 2.184 - sscanf(cp, "#for%u", &d); 2.185 - evl[i].enddate=evl[i].date; 2.186 - for (l = 1; l < d; l++) { 2.187 - evl[i].enddate.day++; 2.188 - if (evl[i].enddate.day > mlen(evl[i].enddate.month, evl[i].enddate.year)) { 2.189 - evl[i].enddate.month++; 2.190 - evl[i].enddate.day = 1; 2.191 - } 2.192 - if (evl[i].enddate.month > 12) { 2.193 - evl[i].enddate.year++; 2.194 - evl[i].enddate.month = 1; 2.195 - } 2.196 - } 2.197 - break; 2.198 - case F_TODATE: /* #to<date> -- sets the end date of the event */ 2.199 - l = sscanf(cp, "#to%u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day)); 2.200 - if (l == 2) { 2.201 - evl[i].enddate.year = 0; 2.202 - } 2.203 - break; 2.204 case 0: 2.205 break; 2.206 default: 2.207 @@ -654,16 +571,6 @@ 2.208 strcpy(buf2, cp); 2.209 } 2.210 break; 2.211 - case F_TEVENT: 2.212 - /* if a year was specified, and this 2.213 - warning isn't for it, ignore! */ 2.214 - if ((evl[i].date.year && ydelta(evl[i].date, today)) 2.215 - && (!evl[i].enddate.year || ydelta(evl[i].enddate, today))) { 2.216 - i--; 2.217 - continue; 2.218 - } 2.219 - strcpy(buf2, cp); 2.220 - break; 2.221 } 2.222 evl[i].text = strdup(buf2); 2.223 }