if (m->prefix[0]) { int l1 = strlen(m->prefix);
if (m->bodun && prefix) { int l1 = strlen(prefix);
cal(){	register int printing;	register char *p;	FILE *fp;	int ch, l, i, bodun = 0, bodun_maybe = 0;	int var;	char buf[2048 + 1];	struct event *events, *cur_evt, *ev1, *tmp;	struct match *m;	events = NULL;	cur_evt = NULL;	if ((fp = opencal()) == NULL)		return;	for (printing = 0; fgets(buf, sizeof(buf), stdin) != NULL;) {		if ((p = strchr(buf, '\n')) != NULL)			*p = '\0';		else			while ((ch = getchar()) != '\n' && ch != EOF);		for (l = strlen(buf); l > 0 && isspace(buf[l - 1]); l--)			;		buf[l] = '\0';		if (buf[0] == '\0')			continue;		if (strncmp(buf, "LANG=", 5) == 0) {			(void) setlocale(LC_ALL, buf + 5);			setnnames();			if (!strcmp(buf + 5, "ru_RU.KOI8-R") ||			    !strcmp(buf + 5, "uk_UA.KOI8-U") ||			    !strcmp(buf + 5, "by_BY.KOI8-B")) {				bodun_maybe++;				bodun = bodun_always;			} else				bodun_maybe = 0;			continue;		}		if (bodun_maybe && strncmp(buf, "BODUN=", 6) == 0)			bodun++;		/* User defined names for special events */		if ((p = strchr(buf, '='))) {			for (i = 0; i < NUMEV; i++) {			if (strncasecmp(buf, spev[i].name, spev[i].nlen) == 0 &&			    (p - buf == spev[i].nlen) && buf[spev[i].nlen + 1]) {				p++;				if (spev[i].uname != NULL)					free(spev[i].uname);				if ((spev[i].uname = strdup(p)) == NULL)					err(1, NULL);				spev[i].ulen = strlen(p);				i = NUMEV + 1;			}			}		if (i > NUMEV)			continue;		}		if (buf[0] != '\t') {			printing = (m = isnow(buf, bodun)) ? 1 : 0;			if ((p = strchr(buf, '\t')) == NULL) {				printing = 0;				continue;			}			/* Need the following to catch hardwired "variable"			 * dates */			if (p > buf && p[-1] == '*')				var = 1;			else				var = 0;			if (printing) {				struct match *foo;								ev1 = NULL;				while (m) {				cur_evt = (struct event *) malloc(sizeof(struct event));				if (cur_evt == NULL)					err(1, NULL);				cur_evt->when = m->when;				snprintf(cur_evt->print_date,				    sizeof(cur_evt->print_date), "%s%c",				    m->print_date, (var + m->var) ? '*' : ' ');				if (ev1) {					cur_evt->desc = ev1->desc;					cur_evt->ldesc = NULL;				} else {					if (m->prefix[0]) {						int l1 = strlen(m->prefix);						int l2 = strlen(p);						if ((cur_evt->ldesc =						    malloc(l1 + l2)) == NULL)							err(1, "realloc");						sprintf(cur_evt->ldesc, "\t%s%s",						    m->prefix, p + 1);					} else if ((cur_evt->ldesc =					    strdup(p)) == NULL)						err(1, NULL);					cur_evt->desc = &(cur_evt->ldesc);					ev1 = cur_evt;				}				insert(&events, cur_evt);				foo = m;				m = m->next;				free(foo);				}			}		}		else if (printing) {			if ((ev1->ldesc = realloc(ev1->ldesc,			    (2 + strlen(ev1->ldesc) + strlen(buf)))) == NULL)				err(1, NULL);			strcat(ev1->ldesc, "\n");			strcat(ev1->ldesc, buf);		}	}	tmp = events;	while (tmp) {		(void)fprintf(fp, "%s%s\n", tmp->print_date, *(tmp->desc));		tmp = tmp->next;	}	tmp = events;	while (tmp) {		events = tmp;		if (tmp->ldesc)			free(tmp->ldesc);		tmp = tmp->next;		free(events);	}	closecal(fp);}