xref: /csrg-svn/usr.bin/pascal/libpc/RESET.c (revision 1695)
1*1695Smckusick /* Copyright (c) 1979 Regents of the University of California */
2*1695Smckusick 
3*1695Smckusick static char sccsid[] = "@(#)RESET.c 1.1 10/30/80";
4*1695Smckusick 
5*1695Smckusick #include "h00vars.h"
6*1695Smckusick #include "h01errs.h"
7*1695Smckusick 
8*1695Smckusick RESET(filep, name, maxnamlen, datasize)
9*1695Smckusick 
10*1695Smckusick 	register struct iorec	*filep;
11*1695Smckusick 	char			*name;
12*1695Smckusick 	int			maxnamlen;
13*1695Smckusick 	int			datasize;
14*1695Smckusick {
15*1695Smckusick 	if (name == NULL && filep == INPUT && filep->fname[0] == '\0') {
16*1695Smckusick 		if (rewind(filep->fbuf)) {
17*1695Smckusick 			ERROR(ESEEK, filep->pfname);
18*1695Smckusick 			return;
19*1695Smckusick 		}
20*1695Smckusick 		filep->funit &= ~(EOFF | EOLN);
21*1695Smckusick 		filep->funit |= SYNC;
22*1695Smckusick 		return;
23*1695Smckusick 	}
24*1695Smckusick 	filep = GETNAME(filep, name, maxnamlen, datasize);
25*1695Smckusick 	filep->fbuf = fopen(filep->fname, "r");
26*1695Smckusick 	if (filep->fbuf == NULL) {
27*1695Smckusick 		if (filep->funit & TEMP) {
28*1695Smckusick 			filep->funit |= (EOFF | SYNC | FREAD);
29*1695Smckusick 			return;
30*1695Smckusick 		}
31*1695Smckusick 		ERROR(EOPEN, filep->pfname);
32*1695Smckusick 		return;
33*1695Smckusick 	}
34*1695Smckusick 	filep->funit |= (SYNC | FREAD);
35*1695Smckusick 	if (filep->fblk > PREDEF) {
36*1695Smckusick 		setbuf(filep->fbuf, &filep->buf[0]);
37*1695Smckusick 	}
38*1695Smckusick }
39