xref: /csrg-svn/usr.bin/pascal/libpc/READ8.c (revision 6498)
11680Smckusick /* Copyright (c) 1979 Regents of the University of California */
21680Smckusick 
3*6498Smckusick static char sccsid[] = "@(#)READ8.c 1.5 04/09/82";
41680Smckusick 
51680Smckusick #include "h00vars.h"
6*6498Smckusick #include <errno.h>
7*6498Smckusick extern int errno;
81680Smckusick 
91680Smckusick double
101680Smckusick READ8(curfile)
111680Smckusick 
121680Smckusick 	register struct iorec	*curfile;
131680Smckusick {
141680Smckusick 	double			data;
152223Smckusic 	int			retval;
161680Smckusick 
171680Smckusick 	if (curfile->funit & FWRITE) {
183869Smckusic 		ERROR("%s: Attempt to read, but open for writing\n",
193869Smckusic 			curfile->pfname);
201680Smckusick 		return;
211680Smckusick 	}
221680Smckusick 	UNSYNC(curfile);
23*6498Smckusick 	errno = 0;
242223Smckusic 	retval = fscanf(curfile->fbuf, "%lf", &data);
252223Smckusic 	if (retval == EOF) {
263869Smckusic 		ERROR("%s: Tried to read past end of file\n", curfile->pfname);
272223Smckusic 		return;
282223Smckusic 	}
292223Smckusic 	if (retval == 0) {
303869Smckusic 		ERROR("%s: Bad data found on real read\n", curfile->pfname);
311680Smckusick 		return;
321680Smckusick 	}
33*6498Smckusick 	if (errno == ERANGE) {
34*6498Smckusick 		if (data == 0.0)
35*6498Smckusick 			ERROR("%s: Underflow on real read\n", curfile->pfname);
36*6498Smckusick 		else
37*6498Smckusick 			ERROR("%s: Overflow on real read\n", curfile->pfname);
38*6498Smckusick 		return;
39*6498Smckusick 	}
40*6498Smckusick 	if (errno != 0) {
41*6498Smckusick 		PERROR(curfile->pfname);
42*6498Smckusick 		return;
43*6498Smckusick 	}
442309Smckusic 	curfile->funit &= ~EOLN;
451680Smckusick 	curfile->funit |= SYNC;
461680Smckusick 	return data;
471680Smckusick }
48