bday
changeset 4:5326c222cd4e
removed MESSAGE; code beautifing
workaround for MESSAGE: use an event with warn 0 (message=yyyy-mm-dd w 0)
author | meillo@marmaro.de |
---|---|
date | Mon, 17 Dec 2007 12:14:41 +0100 |
parents | dc2f94280b01 |
children | 5af6bf2cb271 |
files | bday.1 bdengine.c birthday.h |
diffstat | 3 files changed, 43 insertions(+), 52 deletions(-) [+] |
line diff
1.1 --- a/bday.1 Mon Dec 17 11:28:40 2007 +0100 1.2 +++ b/bday.1 Mon Dec 17 12:14:41 2007 +0100 1.3 @@ -77,15 +77,15 @@ 1.4 .B -W 1.5 flag. 1.6 .TP 1.7 +.BI for days 1.8 +The event lasts for 1.9 +.B days 1.10 +days. 1.11 +.TP 1.12 .BI to date 1.13 The event lasts until 1.14 .IR date , 1.15 which should be in the same format as for the date of the event. 1.16 -.TP 1.17 -.BI for days 1.18 -The event lasts for 1.19 -.B days 1.20 -days. 1.21 1.22 .SH DATE SPECIFICATION 1.23
2.1 --- a/bdengine.c Mon Dec 17 11:28:40 2007 +0100 2.2 +++ b/bdengine.c Mon Dec 17 12:14:41 2007 +0100 2.3 @@ -33,14 +33,13 @@ 2.4 date is dd/mm, dd/mm/yy (assumes 20th century!) or dd/mm/yyyy 2.5 flags is ONE or ZERO of 2.6 o bd for a birthday (default) 2.7 - o bir for a birthday (exactly equivalent to `bd') 2.8 o ann for an anniversary 2.9 o ev for an event 2.10 and zero or more of 2.11 - o w<n> to set the warn-in-advance time to n days (don't include the 2.12 + o w <n> to set the warn-in-advance time to n days (don't include the 2.13 brackets! :) 2.14 - o to<date> 2.15 - o for<days> 2.16 + o to <date> 2.17 + o for <days> 2.18 to specify the length of time taken by an event, for example a 2.19 holiday. 2.20 2.21 @@ -125,7 +124,6 @@ 2.22 {"bd", F_TBIRTHDAY}, 2.23 {"ann",F_TANNIVERSARY}, 2.24 {"ev", F_TEVENT}, 2.25 - {"mes", F_TMESSAGE}, 2.26 {"w", F_WTIME_P}, 2.27 {"to", F_TODATE}, 2.28 {"for", F_FORDAYS}, 2.29 @@ -498,17 +496,17 @@ 2.30 2.31 if (fname[0] == '-' && fname[1] == 0) { 2.32 /* read from stdin */ 2.33 - file=stdin; 2.34 + file = stdin; 2.35 } else { 2.36 /* now read it */ 2.37 - if((file=fopen(fname, "rt"))==NULL) { 2.38 + if ((file = fopen(fname, "rt")) == NULL) { 2.39 fprintf(stderr, "Unable to open file \"%s\"\n", fname); 2.40 exit(1); 2.41 } 2.42 } 2.43 2.44 2.45 - for (i = 0, evl=NULL; fgets(buf, sizeof(buf), file) != NULL; i++) { 2.46 + for (i = 0, evl = NULL; fgets(buf, sizeof(buf), file) != NULL; i++) { 2.47 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1)); 2.48 2.49 /* ignore comments and empty lines */ 2.50 @@ -521,6 +519,7 @@ 2.51 ptr = strrchr(buf, '='); /* allow '=' in text */ 2.52 2.53 /* not a valid line, so ignore it! Cool, huh? */ 2.54 + /* Attention: only recognizes lines without '=' */ 2.55 if (ptr == NULL) { 2.56 fprintf(stderr, "WARNING: Invalid line in input file:\n%s", buf); 2.57 i--; 2.58 @@ -530,52 +529,55 @@ 2.59 *(ptr++) = 0; 2.60 2.61 j = sscanf(ptr, "%u-%u-%u", &(evl[i].date.year), &(evl[i].date.month), &(evl[i].date.day)); 2.62 - /* if our year is only two digits, add 1900 to it ... */ 2.63 - if(evl[i].date.year < 100) evl[i].date.year+=1900; 2.64 /* ... unless it wasn't read, in which case set it to zero */ 2.65 - if(j==2) evl[i].date.year=0; 2.66 + if (j==2) { 2.67 + evl[i].date.year = 0; 2.68 + } 2.69 + 2.70 2.71 /* parse flags */ 2.72 2.73 - evl[i].warn=iDWarn; 2.74 - evl[i].enddate.day=evl[i].enddate.month=evl[i].enddate.year=0; 2.75 + evl[i].warn = iDWarn; 2.76 + evl[i].enddate.day = 0; 2.77 + evl[i].enddate.month = 0; 2.78 + evl[i].enddate.year = 0; 2.79 2.80 - flags=j=0; 2.81 - while(j = skptok(j, ptr),ptr[j]!=0) { 2.82 - for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++); 2.83 + flags = 0; 2.84 + j = 0; 2.85 + 2.86 + while(j = skptok(j, ptr), ptr[j] != 0) { 2.87 + for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++) { 2.88 + } 2.89 + 2.90 switch (FTABLE[k].flag) { 2.91 - case F_WTIME_P: /* w<n> -- sets warning time */ 2.92 + case F_WTIME_P: /* w <n> -- sets warning time */ 2.93 sscanf(ptr + j, "w %u", &(evl[i].warn)); 2.94 break; 2.95 - case F_FORDAYS: /* for<days> -- sets the duration of the event */ 2.96 - sscanf(ptr + j, "for %d", &d); 2.97 + case F_FORDAYS: /* for <days> -- sets the duration of the event */ 2.98 + sscanf(ptr + j, "for %u", &d); 2.99 evl[i].enddate=evl[i].date; 2.100 - for (l=1; l < d; l++) { 2.101 + for (l = 1; l < d; l++) { 2.102 evl[i].enddate.day++; 2.103 - if (evl[i].enddate.day > mlen(evl[i].enddate.month, 2.104 - evl[i].enddate.year)) { 2.105 + if (evl[i].enddate.day > mlen(evl[i].enddate.month, evl[i].enddate.year)) { 2.106 evl[i].enddate.month++; 2.107 - evl[i].enddate.day=1; 2.108 + evl[i].enddate.day = 1; 2.109 } 2.110 if (evl[i].enddate.month > 12) { 2.111 evl[i].enddate.year++; 2.112 - evl[i].enddate.month=1; 2.113 + evl[i].enddate.month = 1; 2.114 } 2.115 } 2.116 break; 2.117 - case F_TODATE: 2.118 + case F_TODATE: /* to <date> -- sets the end date of the event */ 2.119 l = sscanf(ptr + j, "to %u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day)); 2.120 - if (evl[i].enddate.year < 100) { 2.121 - evl[i].enddate.year+=1900; 2.122 - } 2.123 if (l == 2) { 2.124 - evl[i].enddate.year=0; 2.125 + evl[i].enddate.year = 0; 2.126 } 2.127 break; 2.128 case 0: 2.129 break; 2.130 default: 2.131 - flags|=FTABLE[k].flag; 2.132 + flags |= FTABLE[k].flag; 2.133 break; 2.134 } 2.135 } 2.136 @@ -587,8 +589,8 @@ 2.137 case F_TBIRTHDAY: 2.138 default: /* assume it's a birthday */ 2.139 if (evl[i].date.year != 0) { 2.140 - int tmp_age=ydelta(evl[i].date, today); 2.141 - if (tmp_age!=1) { 2.142 + int tmp_age = ydelta(evl[i].date, today); 2.143 + if (tmp_age != 1) { 2.144 sprintf(buf2, "%s is %d years old", buf, tmp_age); 2.145 } else { 2.146 sprintf(buf2, "%s is %d year old", buf, tmp_age); 2.147 @@ -606,29 +608,20 @@ 2.148 break; 2.149 case F_TEVENT: 2.150 /* if a year was specified, and this warning isn't for it, ignore! */ 2.151 - if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) && 2.152 - (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) { 2.153 + if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) && (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) { 2.154 i--; 2.155 continue; 2.156 } 2.157 strcpy(buf2, buf); 2.158 break; 2.159 - case F_TMESSAGE: 2.160 - /* Like an event, except that it only comes up on the given date, and no text at all is appended */ 2.161 - if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) && 2.162 - (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) { 2.163 - i--; 2.164 - continue; 2.165 - } 2.166 - strcpy(buf2, buf); 2.167 - evl[i].warn=-1; /* special code! */ 2.168 - break; 2.169 } 2.170 evl[i].text = strdup(buf2); 2.171 } 2.172 2.173 evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1)); 2.174 - evl[i].date.day=evl[i].date.month=evl[i].date.year=0; 2.175 + evl[i].date.day = 0; 2.176 + evl[i].date.month = 0; 2.177 + evl[i].date.year = 0; 2.178 evl[i].text = (char *) NULL; 2.179 2.180 fclose(file);
3.1 --- a/birthday.h Mon Dec 17 11:28:40 2007 +0100 3.2 +++ b/birthday.h Mon Dec 17 12:14:41 2007 +0100 3.3 @@ -46,7 +46,6 @@ 3.4 #define mlen(m,y) (MLENDAT[(m)-1] != -1 ? MLENDAT[(m)-1] : (isleapyear((y)) ? 29 : 28)) 3.5 #define before(a,b) ((a).month < (b).month || ((a).month == (b).month && (a).day < (b).day)) 3.6 #define ydelta(a,b) ((int) (b).year - (a).year + before((a),(b))) 3.7 -#define warnperiod(ev) ( (ev).warn ) 3.8 3.9 /* -------- modifier flags */ 3.10 3.11 @@ -54,7 +53,6 @@ 3.12 #define F_TBIRTHDAY 1 3.13 #define F_TANNIVERSARY 2 3.14 #define F_TEVENT 3 3.15 -#define F_TMESSAGE 4 3.16 3.17 /* flags processed immediately on encountering */ 3.18 #define F_MIMMEDIATE 0x24