# HG changeset patch # User meillo@marmaro.de # Date 1197874935 -3600 # Node ID 9ec037775c3808fa1e3cfca79de2ba41b2f54982 # Parent 8534f0e3a0db9524ff5ca16a0f7be9faa31d918f removed code for &include in input files diff -r 8534f0e3a0db -r 9ec037775c38 bdengine.c --- a/bdengine.c Sun Dec 16 22:52:15 2007 +0100 +++ b/bdengine.c Mon Dec 17 08:02:15 2007 +0100 @@ -112,7 +112,7 @@ int evcmp(const void *e1, const void *e2); char *deffname(void); -struct event *dir_include(char *dir, char *parm); +/*struct event *dir_include(char *dir, char *parm);*/ /* ========== Global variables */ @@ -136,20 +136,6 @@ }; -/* list of directives. These are entered in the file prefixed by '&'. The function should be declared as - struct event *dir_func(char *directive, char *parameters); - and should return a pointer to a NULL-terminated list of extra records, or NULL if there are none. - This structure will allow us to dynamically add directives, if we wish to do so in the future. - */ - -struct { - const char *text; - int len; - struct event *(*func)(char*,char*); -} directlist[] = { - { "include", 0, dir_include }, - { NULL, 0, NULL } -}; /* ========== */ @@ -356,7 +342,7 @@ char* deffname(void) { char buf[256]; - strcpy(buf,getpwuid(getuid())->pw_dir); + strcpy(buf, getpwuid(getuid())->pw_dir); strcat(buf, "/" DEFAULT_FILE); return strdup(buf); @@ -505,7 +491,7 @@ char buf[1024], buf2[1024]; char *ptr; unsigned flags; - struct event *nevl; + /* initialise */ if (fname==NULL) { fname=deffname(); @@ -528,56 +514,21 @@ for (i = 0, evl=NULL; fgets(buf, sizeof(buf), file) != NULL; i++) { evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1)); - if (*buf == '#' || *buf == '\n') - { - i--; - continue; - } - if (*buf == '&') { - buf[strlen(buf)-1] = 0; - if ((ptr=strchr(buf+1,' ')) == NULL && (ptr=strchr((buf+1),'\t')) == NULL) { - ptr=(buf+1)+strlen((buf+1)); - } - - *ptr++=0; - nevl=NULL; - k=0; - for (j=0; directlist[j].text != NULL; j++) { - if (directlist[j].len == 0) directlist[j].len = strlen(directlist[j].text); - /* - fprintf(stderr, "Checking against directive #%d, %s, which has length %d, against \"%s\" with length %d\n", - j, directlist[j].text, directlist[j].len, buf+1, ptr-(buf+1)-1); - */ - if (directlist[j].len == ptr-(buf+1)-1 && !strncmp(directlist[j].text,(buf+1),directlist[j].len)) { - nevl = directlist[j].func((buf+1),ptr); - k=1; - break; - } - } - - if (nevl != NULL) { - for (j=0; nevl[j].text != NULL; j++); - i+=j-1; - evl = (struct event *) xrealloc(evl, sizeof(struct event) * (i + 1)); - /* in fact, this loop reverses the order of the elements, but we're going to sort them later anyway. */ - for (j=0; nevl[j].text != NULL; j++) - evl[i-j]=nevl[j]; - } - if (!k) { - fprintf(stderr, "Warning: unrecognised directive \"%s\" ignored.\n", (buf+1)); - i--; - } + /* ignore comments and empty lines */ + if (*buf == '#' || *buf == '\n') { + i--; continue; } /* parse string in buf */ ptr = strrchr(buf, '='); /* allow '=' in text */ - if(ptr==NULL) /* not a valid line, so ignore it! Cool, huh? */ - { - fprintf(stderr, "WARNING: Invalid line in input file:\n%s", buf); - i--; - continue; - } + + /* not a valid line, so ignore it! Cool, huh? */ + if (ptr == NULL) { + fprintf(stderr, "WARNING: Invalid line in input file:\n%s", buf); + i--; + continue; + } *(ptr++) = 0; @@ -593,10 +544,9 @@ evl[i].enddate.day=evl[i].enddate.month=evl[i].enddate.year=0; flags=j=0; - while(j = skptok(j, ptr),ptr[j]!=0) - { - for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++); - switch (FTABLE[k].flag) { + while(j = skptok(j, ptr),ptr[j]!=0) { + for (k = 0; FTABLE[k].txt != NULL && strncmp(FTABLE[k].txt, ptr + j, strlen(FTABLE[k].txt)); k++); + switch (FTABLE[k].flag) { case F_WTIME_P: /* w -- sets warning time */ sscanf(ptr + j, "w %u", &(evl[i].warn)); break; @@ -618,59 +568,64 @@ break; case F_TODATE: l = sscanf(ptr + j, "to %u-%u-%u", &(evl[i].enddate.year), &(evl[i].enddate.month), &(evl[i].enddate.day)); - if (evl[i].enddate.year < 100) evl[i].enddate.year+=1900; - if (l == 2) evl[i].enddate.year=0; + if (evl[i].enddate.year < 100) { + evl[i].enddate.year+=1900; + } + if (l == 2) { + evl[i].enddate.year=0; + } break; case 0: break; default: flags|=FTABLE[k].flag; break; - } } + } + /* construct event text */ switch(flags & F_MTYPE) { - case F_TBIRTHDAY: - default: /* assume it's a birthday */ - if (evl[i].date.year != 0) { - int tmp_age=ydelta(evl[i].date, today); - if (tmp_age!=1) { - sprintf(buf2, "%s is %d years old", buf, tmp_age); + case F_TBIRTHDAY: + default: /* assume it's a birthday */ + if (evl[i].date.year != 0) { + int tmp_age=ydelta(evl[i].date, today); + if (tmp_age!=1) { + sprintf(buf2, "%s is %d years old", buf, tmp_age); + } else { + sprintf(buf2, "%s is %d year old", buf, tmp_age); + } } else { - sprintf(buf2, "%s is %d year old", buf, tmp_age); + sprintf(buf2, "%s has a birthday", buf); } - } else { - sprintf(buf2, "%s has a birthday", buf); - } - break; - case F_TANNIVERSARY: - if (evl[i].date.year != 0) { - sprintf(buf2, "%s %d years ago", buf, ydelta(evl[i].date, today)); - } else { + break; + case F_TANNIVERSARY: + if (evl[i].date.year != 0) { + sprintf(buf2, "%s %d years ago", buf, ydelta(evl[i].date, today)); + } else { + strcpy(buf2, buf); + } + break; + case F_TEVENT: + /* if a year was specified, and this warning isn't for it, ignore! */ + if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) && + (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) { + i--; + continue; + } strcpy(buf2, buf); - } - break; - case F_TEVENT: - /* if a year was specified, and this warning isn't for it, ignore! */ - if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) && - (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) { - i--; - continue; - } - strcpy(buf2, buf); - break; - case F_TMESSAGE: - /* Like an event, except that it only comes up on the given date, and no text at all is appended */ - if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) && - (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) { - i--; - continue; - } - strcpy(buf2, buf); - evl[i].warn=-1; /* special code! */ - break; + break; + case F_TMESSAGE: + /* Like an event, except that it only comes up on the given date, and no text at all is appended */ + if ((evl[i].date.year != 0 && ydelta(evl[i].date, today) != 0) && + (evl[i].enddate.year == 0 || ydelta(evl[i].enddate, today) != 0)) { + i--; + continue; + } + strcpy(buf2, buf); + evl[i].warn=-1; /* special code! */ + break; } evl[i].text = strdup(buf2); } @@ -702,16 +657,3 @@ } - - - - -/* ---------------------------------------------------------------------- */ -/* Functions to parse input file directives */ -struct event *dir_include(char *dir, char *parm) { - struct event *evl; - - evl=readlist(strdup(parm)); - - return evl; -}