13507Seric #include	"../hdr/defines.h"
23507Seric 
33507Seric # define ONEYEAR 31536000L
43507Seric 
53507Seric SCCSID(@(#)dodelt	2.1);
63507Seric 
73507Seric long	Timenow;
83507Seric 
96188Seric char	Pgmr[SZLNAM];	/* for rmdel & chghist (rmchg) */
103507Seric int	First_esc;
113507Seric 
dodelt(pkt,statp,sidp,type)123507Seric dodelt(pkt,statp,sidp,type)
133507Seric register struct packet *pkt;
143507Seric struct stats *statp;
153507Seric struct sid *sidp;
163507Seric char type;
173507Seric {
183507Seric 	extern	char	*satoi();
193507Seric 	struct deltab dt;
203507Seric 	register struct idel *rdp;
213507Seric 	int n, founddel;
223507Seric 	long timediff;
233507Seric 	register char *p;
243507Seric 
253507Seric 	pkt->p_idel = 0;
263507Seric 	founddel = 0;
273507Seric 
283507Seric 	time(&Timenow);
293507Seric 	stats_ab(pkt,statp);
303507Seric 	while (getadel(pkt,&dt) == BDELTAB) {
313507Seric 		if (pkt->p_idel == 0) {
323507Seric 			if (Timenow < dt.d_datetime)
333507Seric 				fprintf(stderr,"Clock may be set wrong! (co11)");
343507Seric 			timediff = Timenow - dt.d_datetime;
353507Seric 			pkt->p_idel = alloc(n = ((dt.d_serial + 1) * sizeof(*pkt->p_idel)));
3619940Ssam 			bzero(pkt->p_idel,n);
373507Seric 			pkt->p_apply = alloc(n = ((dt.d_serial + 1) * sizeof(*pkt->p_apply)));
3819940Ssam 			bzero(pkt->p_apply,n);
393507Seric 			pkt->p_idel->i_pred = dt.d_serial;
403507Seric 		}
413507Seric 		if (dt.d_type == 'D') {
423507Seric 			if (sidp && eqsid(&dt.d_sid,sidp)) {
433507Seric 				copy(dt.d_pgmr,Pgmr);	/* for rmchg */
4419940Ssam 				bzero(sidp,sizeof(*sidp));
453507Seric 				founddel = 1;
463507Seric 				First_esc = 1;
473507Seric 				for (p = pkt->p_line; *p && *p != 'D'; p++)
483507Seric 					;
493507Seric 				if (*p)
503507Seric 					*p = type;
513507Seric 			}
523507Seric 			else
533507Seric 				First_esc = founddel = 0;
543507Seric 			pkt->p_maxr = max(pkt->p_maxr,dt.d_sid.s_rel);
553507Seric 			rdp = &pkt->p_idel[dt.d_serial];
563507Seric 			rdp->i_sid.s_rel = dt.d_sid.s_rel;
573507Seric 			rdp->i_sid.s_lev = dt.d_sid.s_lev;
583507Seric 			rdp->i_sid.s_br = dt.d_sid.s_br;
593507Seric 			rdp->i_sid.s_seq = dt.d_sid.s_seq;
603507Seric 			rdp->i_pred = dt.d_pred;
613507Seric 			rdp->i_datetime = dt.d_datetime;
623507Seric 		}
633507Seric 		while ((n = getline(pkt)) != NULL)
643507Seric 			if (pkt->p_line[0] != CTLCHAR)
653507Seric 				break;
663507Seric 			else {
673507Seric 				switch (pkt->p_line[1]) {
683507Seric 				case EDELTAB:
693507Seric 					break;
703507Seric 				case COMMENTS:
713507Seric 				case MRNUM:
723507Seric 					if (founddel)
733507Seric 						escdodelt(pkt);
743507Seric 					continue;
753507Seric 				default:
763507Seric 					fmterr(pkt);
773507Seric 				case INCLUDE:
783507Seric 				case EXCLUDE:
793507Seric 				case IGNORE:
803507Seric 					if (dt.d_type == 'D')
813507Seric 						doixg(pkt->p_line,&rdp->i_ixg);
823507Seric 					continue;
833507Seric 				}
843507Seric 				break;
853507Seric 			}
863507Seric 		if (n == NULL || pkt->p_line[0] != CTLCHAR || getline(pkt) == NULL)
873507Seric 			fmterr(pkt);
883507Seric 		if (pkt->p_line[0] != CTLCHAR || pkt->p_line[1] != STATS)
893507Seric 			break;
903507Seric 	}
913507Seric 	return(pkt->p_idel);
923507Seric }
933507Seric 
943507Seric 
getadel(pkt,dt)953507Seric getadel(pkt,dt)
963507Seric register struct packet *pkt;
973507Seric register struct deltab *dt;
983507Seric {
993507Seric 	if (getline(pkt) == NULL)
1003507Seric 		fmterr(pkt);
1013507Seric 	return(del_ab(pkt->p_line,dt,pkt));
1023507Seric }
1033507Seric 
1043507Seric 
doixg(p,ixgp)1053507Seric doixg(p,ixgp)
1063507Seric char *p;
1073507Seric struct ixg *ixgp;
1083507Seric {
1093507Seric 	int *v, *ip;
1103507Seric 	int type, cnt;
1113507Seric 	struct ixg *cur, *prev;
112*36473Ssam 	char buf[BUFSIZ];
1133507Seric 
114*36473Ssam 	v = ip = (int *)buf;
1153507Seric 	++p;
1163507Seric 	type = *p++;
1173507Seric 	NONBLANK(p);
1183507Seric 	while (numeric(*p)) {
1193507Seric 		p = satoi(p,ip++);
1203507Seric 		NONBLANK(p);
1213507Seric 	}
1223507Seric 	cnt = ip - v;
1233507Seric 	for (cur = ixgp; cur = (prev = cur)->i_next; )
1243507Seric 		;
1253507Seric 	prev->i_next = cur = alloc(sizeof(*cur) + (cnt - 1) * sizeof(cur->i_ser[0]));
1263507Seric 	cur->i_next = 0;
1273507Seric 	cur->i_type = type;
1283507Seric 	cur->i_cnt = cnt;
12919940Ssam 	bcopy(v,cur->i_ser,cnt * sizeof(cur->i_ser[0]));
1303507Seric }
131