119927Ssam # include	"../hdr/defines.h"
219927Ssam 
319927Ssam SCCSID(@(#)sinit	2.1);
419927Ssam /*
519927Ssam 	Does initialization for sccs files and packet.
619927Ssam */
719927Ssam 
sinit(pkt,file,openflag)819927Ssam sinit(pkt,file,openflag)
919927Ssam register struct packet *pkt;
1019927Ssam register char *file;
1119927Ssam {
1219927Ssam 	extern	char	*satoi();
1319927Ssam 	register char *p;
1419927Ssam 
15*19940Ssam 	bzero(pkt,sizeof(*pkt));
1619927Ssam 	if (size(file) > FILESIZE)
1719927Ssam 		fatal("too long (co7)");
1819927Ssam 	if (!sccsfile(file))
1919927Ssam 		fatal("not an SCCS file (co1)");
2019927Ssam 	copy(file,pkt->p_file);
2119927Ssam 	pkt->p_wrttn = 1;
2219927Ssam 	pkt->do_chksum = 1;	/* turn on checksum check for getline */
2319927Ssam 	if (openflag) {
2419927Ssam 		pkt->p_iop = xfopen(file,0);
2519927Ssam 		setbuf(pkt->p_iop,pkt->p_buf);
2619927Ssam 		fstat(fileno(pkt->p_iop),&Statbuf);
2719927Ssam 		if (Statbuf.st_nlink > 1)
2819927Ssam 			fatal("more than one link (co3)");
2919927Ssam 		if ((p = getline(pkt)) == NULL || *p++ != CTLCHAR || *p++ != HEAD) {
3019927Ssam 			fclose(pkt->p_iop);
3119927Ssam 			fmterr(pkt);
3219927Ssam 		}
3319927Ssam 		p = satoi(p,&pkt->p_ihash);
3419927Ssam 		if (*p != '\n')
3519927Ssam 			fmterr(pkt);
3619927Ssam 	}
3719927Ssam 	pkt->p_chash = 0;
3819927Ssam }
39