version 1.4, 1998/03/30 06:59:27 |
version 1.5, 1998/11/08 04:31:13 |
|
|
register char *p; |
register char *p; |
FILE *fp; |
FILE *fp; |
int ch, l; |
int ch, l; |
int month; |
|
int day; |
|
int var; |
int var; |
char buf[2048 + 1]; |
char buf[2048 + 1]; |
|
struct event *events, *cur_evt, *tmp; |
|
struct match *m; |
|
|
|
events = NULL; |
|
cur_evt = NULL; |
if ((fp = opencal()) == NULL) |
if ((fp = opencal()) == NULL) |
return; |
return; |
for (printing = 0; fgets(buf, sizeof(buf), stdin) != NULL;) { |
for (printing = 0; fgets(buf, sizeof(buf), stdin) != NULL;) { |
|
|
continue; |
continue; |
} |
} |
if (buf[0] != '\t') { |
if (buf[0] != '\t') { |
printing = isnow(buf, &month, &day, &var) ? 1 : 0; |
printing = (m = isnow(buf)) ? 1 : 0; |
if ((p = strchr(buf, '\t')) == NULL) |
if ((p = strchr(buf, '\t')) == NULL) |
continue; |
continue; |
|
/* Need the following to catch hardwired "variable" |
|
* dates */ |
if (p > buf && p[-1] == '*') |
if (p > buf && p[-1] == '*') |
var = 1; |
var = 1; |
|
else |
|
var = 0; |
if (printing) { |
if (printing) { |
struct tm tm; |
struct tm tm; |
char dbuf[30]; |
struct match *foo; |
|
char *dsc; |
|
|
|
dsc = NULL; |
|
while (m) { |
|
cur_evt = (struct event *) malloc(sizeof(struct event)); |
|
if (cur_evt == NULL) |
|
errx(1, "cannot allocate memory"); |
|
|
tm.tm_sec = 0; /* unused */ |
tm.tm_sec = 0; /* unused */ |
tm.tm_min = 0; /* unused */ |
tm.tm_min = 0; /* unused */ |
tm.tm_hour = 0; /* unused */ |
tm.tm_hour = 12; /* unused */ |
tm.tm_wday = 0; /* unused */ |
tm.tm_wday = 0; /* unused */ |
tm.tm_mon = month - 1; |
tm.tm_mon = m->month - 1; |
tm.tm_mday = day; |
tm.tm_mday = m->day; |
tm.tm_year = tp->tm_year; /* unused */ |
tm.tm_year = m->year; |
tm.tm_isdst = tp->tm_isdst; /* unused */ |
tm.tm_isdst = tp->tm_isdst; /* unused */ |
tm.tm_gmtoff = tp->tm_gmtoff; /* unused */ |
tm.tm_gmtoff = tp->tm_gmtoff; /* unused */ |
tm.tm_zone = tp->tm_zone; /* unused */ |
tm.tm_zone = tp->tm_zone; /* unused */ |
(void)strftime(dbuf, sizeof(dbuf), "%a %b %d", |
(void)strftime(cur_evt->print_date, |
&tm); |
sizeof(cur_evt->print_date) - 1, |
(void)fprintf(fp, "%s%c%s\n", |
/* "%a %b %d", &tm); Skip weekdays */ |
dbuf + 4/* skip weekdays */, |
"%b %d", &tm); |
var ? '*' : ' ', p); |
strcat(cur_evt->print_date, |
|
(var + m->var) ? "*" : " "); |
|
cur_evt->when = mktime(&tm); |
|
if (dsc) |
|
cur_evt->desc = dsc; |
|
else { |
|
if ((cur_evt->desc = strdup(p)) == NULL) |
|
errx(1, "cannot allocate memory"); |
|
dsc = cur_evt->desc; |
|
} |
|
insert(&events, cur_evt); |
|
foo = m; |
|
m = m->next; |
|
free(foo); |
|
} |
} |
} |
} |
} |
else if (printing) |
else if (printing) { |
fprintf(fp, "%s\n", buf); |
if ((cur_evt->desc = realloc(cur_evt->desc, |
|
(2 + strlen(cur_evt->desc) + strlen(buf)))) == NULL) |
|
errx(1, "cannot allocate memory"); |
|
strcat(cur_evt->desc, "\n"); |
|
strcat(cur_evt->desc, buf); |
|
} |
} |
} |
|
tmp = events; |
|
while (tmp) { |
|
(void)fprintf(fp, "%s%s\n", tmp->print_date, tmp->desc); |
|
/* Can't free descriptions since they may be shared */ |
|
(void)realloc(tmp->desc, 0); |
|
events = tmp; |
|
tmp = tmp->next; |
|
free(events); |
|
} |
closecal(fp); |
closecal(fp); |
} |
} |
|
|
|
|
done: (void)fclose(fp); |
done: (void)fclose(fp); |
(void)unlink(path); |
(void)unlink(path); |
while (wait(&status) >= 0); |
while (wait(&status) >= 0); |
|
} |
|
|
|
|
|
void |
|
insert(head, cur_evt) |
|
struct event **head; |
|
struct event *cur_evt; |
|
{ |
|
struct event *tmp, *tmp2; |
|
|
|
if (*head) { |
|
/* Insert this one in order */ |
|
tmp = *head; |
|
tmp2 = NULL; |
|
while (tmp->next && |
|
tmp->when <= cur_evt->when) { |
|
tmp2 = tmp; |
|
tmp = tmp->next; |
|
} |
|
if (tmp->when > cur_evt->when) { |
|
cur_evt->next = tmp; |
|
if (tmp2) |
|
tmp2->next = cur_evt; |
|
else |
|
*head = cur_evt; |
|
} else { |
|
cur_evt->next = tmp->next; |
|
tmp->next = cur_evt; |
|
} |
|
} else { |
|
*head = cur_evt; |
|
cur_evt->next = NULL; |
|
} |
} |
} |