bday

diff bday.c @ 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
line diff
     1.1 --- a/bday.c	Mon Feb 24 21:22:21 2014 +0100
     1.2 +++ b/bday.c	Mon Feb 24 21:32:18 2014 +0100
     1.3 @@ -30,16 +30,11 @@
     1.4  
     1.5  where:
     1.6  	date is YYYY-MM-DD
     1.7 -	flags is ONE or ZERO of
     1.8 +	flags is optionally
     1.9  		#ann for an anniversary
    1.10 -		#ev  for an event
    1.11 -	and zero or more of
    1.12 +	and optionally
    1.13  		#w<n> to set the warn-in-advance time to n days
    1.14  			(don't include the brackets! :)
    1.15 -		#to<date>
    1.16 -		#for<days>
    1.17 -			to specify the length of time taken by an
    1.18 -			event, for example a holiday
    1.19  	separated by spaces.
    1.20  
    1.21  Lines preceeded by # are treated as comments.
    1.22 @@ -72,13 +67,10 @@
    1.23  /* -------- modifier flags */
    1.24  #define F_MTYPE 0x07
    1.25  #define F_TANNIVERSARY 2
    1.26 -#define F_TEVENT 3
    1.27  
    1.28  /* flags processed immediately on encountering */
    1.29  #define F_MIMMEDIATE 0x24
    1.30  #define F_WTIME_P 0x08
    1.31 -#define F_FORDAYS 0x16
    1.32 -#define F_TODATE 0x24
    1.33  
    1.34  struct _ftable {
    1.35  	char* txt;
    1.36 @@ -95,7 +87,6 @@
    1.37  struct event {
    1.38  	char* text;
    1.39  	struct date date;
    1.40 -	struct date enddate;
    1.41  	int warn;
    1.42  };
    1.43  
    1.44 @@ -118,10 +109,7 @@
    1.45  
    1.46  const struct _ftable FTABLE[] = {
    1.47  	{"#ann",F_TANNIVERSARY},
    1.48 -	{"#ev", F_TEVENT},
    1.49  	{"#w",  F_WTIME_P},
    1.50 -	{"#to", F_TODATE},
    1.51 -	{"#for", F_FORDAYS},
    1.52  	{NULL, 0}
    1.53  };
    1.54  
    1.55 @@ -322,7 +310,7 @@
    1.56  void
    1.57  liststrings(struct event *evl)
    1.58  {
    1.59 -	int i,j;
    1.60 +	int i;
    1.61  	char *buf, *tmp;
    1.62  	int size;
    1.63  
    1.64 @@ -333,43 +321,12 @@
    1.65  
    1.66  		if (evl[i].warn == -1 && delta(&(evl[i].date))==0) {
    1.67  			 size = append(buf, size, evl[i].text);
    1.68 -		} else if (evl[i].enddate.day == 0) {
    1.69 -			
    1.70 -			if (delta(&(evl[i].date)) <= evl[i].warn) {
    1.71 -				tmp = tdelta(&(evl[i].date));
    1.72 -				size = append(buf, size, tmp);
    1.73 -				size = append(buf, size, ":  ");
    1.74 -				size = append(buf, size, evl[i].text);
    1.75 -				free(tmp);
    1.76 -			}
    1.77 -		} else {
    1.78 -			if (delta(&(evl[i].date)) <= evl[i].warn) {
    1.79 -				size = append(buf, size, evl[i].text);
    1.80 -				size = append(buf, size, " for ");
    1.81 -				/* +1 because, if the difference between
    1.82 -				two dates is one day, then the length of
    1.83 -				an event on those days is two days */
    1.84 -				j = ddiff(&(evl[i].date),&(evl[i].enddate)) + 1;
    1.85 -				tmp = ttime(0, 0, j/7, j%7);
    1.86 -				size = append(buf, size, tmp);
    1.87 -				free(tmp);
    1.88 -				size = append(buf, size, " ");
    1.89 -				tmp = tdelta(&(evl[i].date));
    1.90 -				size = append(buf, size, tmp);
    1.91 -			} else if (delta(&(evl[i].enddate)) <= evl[i].warn) {
    1.92 -				size = append(buf, size, evl[i].text);
    1.93 -				size = append(buf, size, " ");
    1.94 -				j = delta(&(evl[i].enddate));
    1.95 -				if (j) {
    1.96 -					size = append(buf, size, "for ");
    1.97 -					tmp = ttime(0, 0, j/7, j%7);
    1.98 -					size = append(buf, size, tmp);
    1.99 -					free(tmp);
   1.100 -					size = append(buf, size, " longer");
   1.101 -				} else {
   1.102 -					size = append(buf, size, "finishes today");
   1.103 -				}
   1.104 -			}
   1.105 +		} else if (delta(&(evl[i].date)) <= evl[i].warn) {
   1.106 +			tmp = tdelta(&(evl[i].date));
   1.107 +			size = append(buf, size, tmp);
   1.108 +			size = append(buf, size, ":  ");
   1.109 +			size = append(buf, size, evl[i].text);
   1.110 +			free(tmp);
   1.111  		}
   1.112  		if (*buf) {
   1.113  			size = append(buf, size, ".");
   1.114 @@ -387,9 +344,7 @@
   1.115  
   1.116  
   1.117  /*
   1.118 -sort the events by the time before the next time they come up,
   1.119 -putting those where the start has passed but we are still in the
   1.120 -time-period first
   1.121 +sort the events by the time before the next time they come up
   1.122  */
   1.123  int
   1.124  evcmp(const void *p1, const void *p2)
   1.125 @@ -398,24 +353,11 @@
   1.126  	struct event *e2=(struct event *) p2;
   1.127  	unsigned d1, d2;
   1.128  
   1.129 -	/*
   1.130 -	if the delta for the enddate is less than that for the start
   1.131 -	date, then we have passed the start date but not yet the end
   1.132 -	date, and so we should display the enddate; otherwise, we
   1.133 -	should display the start date
   1.134 -	*/
   1.135 -
   1.136  	d1=delta(&(e1->date));
   1.137 -	if (e1->enddate.day && delta(&(e1->enddate)) < d1)
   1.138 -		d1=delta(&(e1->enddate));
   1.139 -
   1.140  	d2=delta(&(e2->date));
   1.141 -	if (e2->enddate.day && delta(&(e2->enddate)) < d2)
   1.142 -		d2=delta(&(e2->enddate));
   1.143  
   1.144  	if (d1 < d2) return -1;
   1.145  	if (d1 > d2) return 1;
   1.146 -
   1.147  	return strcmp(e1->text, e2->text);
   1.148  }
   1.149  
   1.150 @@ -545,7 +487,7 @@
   1.151  struct event *
   1.152  readlist()
   1.153  {
   1.154 -	int i, j, k, l, d;
   1.155 +	int i, j, k;
   1.156  	struct event *evl;
   1.157  	char buf[1024], buf2[1024];
   1.158  	char *ptr, *cp;
   1.159 @@ -554,7 +496,7 @@
   1.160  	/* initialise */
   1.161  	gettoday();
   1.162  
   1.163 -	for (i = 0, evl = NULL; fgets(buf, sizeof(buf), stdin) != NULL; i++) {
   1.164 +	for (i=0, evl=NULL; fgets(buf, sizeof(buf), stdin) != NULL; i++) {
   1.165  		evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1));
   1.166  
   1.167  		/* ignore comments and empty lines */
   1.168 @@ -589,10 +531,6 @@
   1.169  		/* parse flags */
   1.170  
   1.171  		evl[i].warn = def_warn;
   1.172 -		evl[i].enddate.day = 0;
   1.173 -		evl[i].enddate.month = 0;
   1.174 -		evl[i].enddate.year = 0;
   1.175 -
   1.176  		flags = 0;
   1.177  		j = 0;
   1.178  		cp = skptok(ptr);
   1.179 @@ -604,27 +542,6 @@
   1.180  			case F_WTIME_P: /* #w<n> -- sets warning time */
   1.181  				sscanf(cp, "#w%u", &(evl[i].warn));
   1.182  				break;
   1.183 -			case F_FORDAYS: /* #for<days> -- sets the duration of the event */
   1.184 -				sscanf(cp, "#for%u", &d);
   1.185 -				evl[i].enddate=evl[i].date;
   1.186 -				for (l = 1; l < d; l++) {
   1.187 -					evl[i].enddate.day++;
   1.188 -					if (evl[i].enddate.day > mlen(evl[i].enddate.month, evl[i].enddate.year)) {
   1.189 -						evl[i].enddate.month++;
   1.190 -						evl[i].enddate.day = 1;
   1.191 -					}
   1.192 -					if (evl[i].enddate.month > 12) {
   1.193 -						evl[i].enddate.year++;
   1.194 -						evl[i].enddate.month = 1;
   1.195 -					}
   1.196 -				}
   1.197 -				break;
   1.198 -			case F_TODATE: /* #to<date> -- sets the end date of the event */
   1.199 -				l = sscanf(cp, "#to%u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day));
   1.200 -				if (l == 2) {
   1.201 -					evl[i].enddate.year = 0;
   1.202 -				}
   1.203 -				break;
   1.204  			case 0:
   1.205  				break;
   1.206  			default:
   1.207 @@ -654,16 +571,6 @@
   1.208  					strcpy(buf2, cp);
   1.209  				}
   1.210  				break;
   1.211 -			case F_TEVENT:
   1.212 -				/* if a year was specified, and this
   1.213 -				   warning isn't for it, ignore! */
   1.214 -				if ((evl[i].date.year && ydelta(evl[i].date, today))
   1.215 -				    && (!evl[i].enddate.year || ydelta(evl[i].enddate, today))) {
   1.216 -					i--;
   1.217 -					continue;
   1.218 -				}
   1.219 -				strcpy(buf2, cp);
   1.220 -				break;
   1.221  		}
   1.222  		evl[i].text = strdup(buf2);
   1.223  	}