bday

changeset 2:9ec037775c38

removed code for &include in input files
author meillo@marmaro.de
date Mon, 17 Dec 2007 08:02:15 +0100
parents 8534f0e3a0db
children dc2f94280b01
files bdengine.c
diffstat 1 files changed, 60 insertions(+), 118 deletions(-) [+]
line diff
     1.1 --- a/bdengine.c	Sun Dec 16 22:52:15 2007 +0100
     1.2 +++ b/bdengine.c	Mon Dec 17 08:02:15 2007 +0100
     1.3 @@ -112,7 +112,7 @@
     1.4  int evcmp(const void *e1, const void *e2);
     1.5  char *deffname(void);
     1.6  
     1.7 -struct event *dir_include(char *dir, char *parm);
     1.8 +/*struct event *dir_include(char *dir, char *parm);*/
     1.9  
    1.10  /* ========== Global variables */
    1.11  
    1.12 @@ -136,20 +136,6 @@
    1.13  };
    1.14  
    1.15  
    1.16 -/* list of directives. These are entered in the file prefixed by '&'. The function should be declared as
    1.17 -	 	struct event *dir_func(char *directive, char *parameters);
    1.18 -	 and should return a pointer to a NULL-terminated list of extra records, or NULL if there are none.
    1.19 -	 This structure will allow us to dynamically add directives, if we wish to do so in the future.
    1.20 -	 */
    1.21 -
    1.22 -struct {
    1.23 -	const char *text;
    1.24 -	int len;
    1.25 -	struct event *(*func)(char*,char*);
    1.26 -} directlist[] = {
    1.27 -	{ "include", 0, dir_include },
    1.28 -	{ NULL, 0, NULL }
    1.29 -};
    1.30  
    1.31  /* ========== */
    1.32  
    1.33 @@ -356,7 +342,7 @@
    1.34  char* deffname(void) {
    1.35  char buf[256];
    1.36  
    1.37 -	strcpy(buf,getpwuid(getuid())->pw_dir);
    1.38 +	strcpy(buf, getpwuid(getuid())->pw_dir);
    1.39  	strcat(buf, "/" DEFAULT_FILE);
    1.40  
    1.41  	return strdup(buf);
    1.42 @@ -505,7 +491,7 @@
    1.43  	char buf[1024], buf2[1024];
    1.44  	char *ptr;
    1.45  	unsigned flags;
    1.46 -	struct event *nevl;
    1.47 +
    1.48  	/* initialise */
    1.49  	if (fname==NULL) {
    1.50  		fname=deffname();
    1.51 @@ -528,56 +514,21 @@
    1.52  	for (i = 0, evl=NULL; fgets(buf, sizeof(buf), file) != NULL; i++) {
    1.53  		evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1));
    1.54  
    1.55 -		if (*buf == '#' || *buf == '\n')
    1.56 -			{
    1.57 -	i--;
    1.58 -	continue;
    1.59 -			}
    1.60 -		if (*buf == '&') {
    1.61 -			buf[strlen(buf)-1] = 0;
    1.62 -			if ((ptr=strchr(buf+1,' ')) == NULL && (ptr=strchr((buf+1),'\t')) == NULL) {
    1.63 -				ptr=(buf+1)+strlen((buf+1));
    1.64 -			}
    1.65 -
    1.66 -			*ptr++=0;
    1.67 -			nevl=NULL;
    1.68 -			k=0;
    1.69 -			for (j=0; directlist[j].text != NULL; j++) {
    1.70 -				if (directlist[j].len == 0) directlist[j].len = strlen(directlist[j].text);
    1.71 -				/*
    1.72 -					fprintf(stderr, "Checking against directive #%d, %s, which has length %d, against \"%s\" with length %d\n",
    1.73 -					j, directlist[j].text, directlist[j].len, buf+1, ptr-(buf+1)-1);
    1.74 -					*/
    1.75 -				if (directlist[j].len == ptr-(buf+1)-1 && !strncmp(directlist[j].text,(buf+1),directlist[j].len)) {
    1.76 -					nevl = directlist[j].func((buf+1),ptr);
    1.77 -					k=1;
    1.78 -					break;
    1.79 -				}
    1.80 -			}
    1.81 -
    1.82 -			if (nevl != NULL) {
    1.83 -				for (j=0; nevl[j].text != NULL; j++);
    1.84 -				i+=j-1;
    1.85 -				evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1));
    1.86 -				/* in fact, this loop reverses the order of the elements, but we're going to sort them later anyway. */
    1.87 -				for (j=0; nevl[j].text != NULL; j++)
    1.88 -					evl[i-j]=nevl[j];
    1.89 -			}
    1.90 -			if (!k) {
    1.91 -				fprintf(stderr, "Warning: unrecognised directive \"%s\" ignored.\n", (buf+1));
    1.92 -				i--;
    1.93 -			}
    1.94 +		/* ignore comments and empty lines */
    1.95 +		if (*buf == '#' || *buf == '\n') {
    1.96 +			i--;
    1.97  			continue;
    1.98  		}
    1.99  
   1.100  		/* parse string in buf */
   1.101  		ptr = strrchr(buf, '='); /* allow '=' in text */
   1.102 -		if(ptr==NULL) /* not a valid line, so ignore it! Cool, huh? */
   1.103 -			{
   1.104 -				fprintf(stderr, "WARNING: Invalid line in input file:\n%s", buf);
   1.105 -				i--;
   1.106 -				continue;
   1.107 -			}
   1.108 +
   1.109 +		/* not a valid line, so ignore it! Cool, huh? */
   1.110 +		if (ptr == NULL) {
   1.111 +			fprintf(stderr, "WARNING: Invalid line in input file:\n%s", buf);
   1.112 +			i--;
   1.113 +			continue;
   1.114 +		}
   1.115  
   1.116  		*(ptr++) = 0;
   1.117  
   1.118 @@ -593,10 +544,9 @@
   1.119  		evl[i].enddate.day=evl[i].enddate.month=evl[i].enddate.year=0;
   1.120  
   1.121  		flags=j=0;
   1.122 -		while(j = skptok(j, ptr),ptr[j]!=0)
   1.123 -			{
   1.124 -				for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++);
   1.125 -				switch (FTABLE[k].flag) {
   1.126 +		while(j = skptok(j, ptr),ptr[j]!=0) {
   1.127 +			for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++);
   1.128 +			switch (FTABLE[k].flag) {
   1.129  				case F_WTIME_P: /* w<n> -- sets warning time */
   1.130  					sscanf(ptr + j, "w %u", &(evl[i].warn));
   1.131  					break;
   1.132 @@ -618,59 +568,64 @@
   1.133  					break;
   1.134  				case F_TODATE:
   1.135  					l = sscanf(ptr + j, "to %u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day));
   1.136 -					if (evl[i].enddate.year < 100) evl[i].enddate.year+=1900;
   1.137 -					if (l == 2) evl[i].enddate.year=0;
   1.138 +					if (evl[i].enddate.year < 100) {
   1.139 +						evl[i].enddate.year+=1900;
   1.140 +					}
   1.141 +					if (l == 2) {
   1.142 +						evl[i].enddate.year=0;
   1.143 +					}
   1.144  					break;
   1.145  				case 0:
   1.146  					break;
   1.147  				default:
   1.148  					flags|=FTABLE[k].flag;
   1.149  					break;
   1.150 -				}
   1.151  			}
   1.152 +		}
   1.153 +
   1.154  
   1.155  		/* construct event text */
   1.156  
   1.157  		switch(flags & F_MTYPE) {
   1.158 -		case F_TBIRTHDAY:
   1.159 -		default: /* assume it's a birthday */
   1.160 -			if (evl[i].date.year != 0) {
   1.161 -				int tmp_age=ydelta(evl[i].date, today);
   1.162 -				if (tmp_age!=1) {
   1.163 -					sprintf(buf2, "%s is %d years old", buf, tmp_age);
   1.164 +			case F_TBIRTHDAY:
   1.165 +			default: /* assume it's a birthday */
   1.166 +				if (evl[i].date.year != 0) {
   1.167 +					int tmp_age=ydelta(evl[i].date, today);
   1.168 +					if (tmp_age!=1) {
   1.169 +						sprintf(buf2, "%s is %d years old", buf, tmp_age);
   1.170 +					} else {
   1.171 +						sprintf(buf2, "%s is %d year old", buf, tmp_age);
   1.172 +					}
   1.173  				} else {
   1.174 -					sprintf(buf2, "%s is %d year old", buf, tmp_age);
   1.175 +					sprintf(buf2, "%s has a birthday", buf);
   1.176  				}
   1.177 -			} else {
   1.178 -				sprintf(buf2, "%s has a birthday", buf);
   1.179 -			}
   1.180 -			break;
   1.181 -		case F_TANNIVERSARY:
   1.182 -			if (evl[i].date.year != 0) {
   1.183 -				sprintf(buf2, "%s %d years ago", buf, ydelta(evl[i].date, today));
   1.184 -			} else {
   1.185 +				break;
   1.186 +			case F_TANNIVERSARY:
   1.187 +				if (evl[i].date.year != 0) {
   1.188 +					sprintf(buf2, "%s %d years ago", buf, ydelta(evl[i].date, today));
   1.189 +				} else {
   1.190 +					strcpy(buf2, buf);
   1.191 +				}
   1.192 +				break;
   1.193 +			case F_TEVENT:
   1.194 +				/* if a year was specified, and this warning isn't for it, ignore! */
   1.195 +				if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) &&
   1.196 +						(evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) {
   1.197 +					i--;
   1.198 +					continue;
   1.199 +				}
   1.200  				strcpy(buf2, buf);
   1.201 -			}
   1.202 -			break;
   1.203 -		case F_TEVENT:
   1.204 -			/* if a year was specified, and this warning isn't for it, ignore! */
   1.205 -			if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) &&
   1.206 -					(evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) {
   1.207 -				i--;
   1.208 -				continue;
   1.209 -			}
   1.210 -			strcpy(buf2, buf);
   1.211 -			break;
   1.212 -		case F_TMESSAGE:
   1.213 -			/* Like an event, except that it only comes up on the given date, and no text at all is appended */
   1.214 -			if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) &&
   1.215 -					(evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) {
   1.216 -				i--;
   1.217 -				continue;
   1.218 -			}
   1.219 -			strcpy(buf2, buf);
   1.220 -			evl[i].warn=-1; /* special code! */
   1.221 -			break;
   1.222 +				break;
   1.223 +			case F_TMESSAGE:
   1.224 +				/* Like an event, except that it only comes up on the given date, and no text at all is appended */
   1.225 +				if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) &&
   1.226 +						(evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) {
   1.227 +					i--;
   1.228 +					continue;
   1.229 +				}
   1.230 +				strcpy(buf2, buf);
   1.231 +				evl[i].warn=-1; /* special code! */
   1.232 +				break;
   1.233  		}
   1.234  		evl[i].text = strdup(buf2);
   1.235  	}
   1.236 @@ -702,16 +657,3 @@
   1.237  }
   1.238  
   1.239  
   1.240 -
   1.241 -
   1.242 -
   1.243 -
   1.244 -/* ---------------------------------------------------------------------- */
   1.245 -/* Functions to parse input file directives */
   1.246 -struct event *dir_include(char *dir, char *parm) {
   1.247 -	struct event *evl;
   1.248 -
   1.249 -	evl=readlist(strdup(parm));
   1.250 -
   1.251 -	return evl;
   1.252 -}