date and time created 80/10/30 00:33:36 by mckusick
[unix-history] / usr / src / usr.bin / pascal / libpc / IOSYNC.c
/* Copyright (c) 1979 Regents of the University of California */
static char sccsid[] = "@(#)IOSYNC.c 1.1 %G%";
#include "h00vars.h"
#include "h01errs.h"
/*
* insure that a usable image is in the buffer window
*/
IOSYNC(curfile)
register struct iorec *curfile;
{
register short unit = curfile->funit;
char *limit, *ptr;
if (unit & FWRITE) {
ERROR(EREADIT, curfile->pfname);
return;
}
if ((unit & SYNC) == 0) {
return;
}
if (unit & EOFF) {
ERROR(EPASTEOF, curfile->pfname);
return;
}
unit &= ~SYNC;
fread(curfile->fileptr, curfile->fsize, 1, curfile->fbuf);
if (ferror(curfile->fbuf)) {
ERROR(EPASTEOF, curfile->pfname);
return;
}
if (feof(curfile->fbuf)) {
curfile->funit = unit | EOFF;
limit = &curfile->fileptr[curfile->fsize];
for (ptr = curfile->fileptr; ptr < limit; )
*ptr++ = 0;
return;
}
if (unit & FTEXT) {
if (*curfile->fileptr == '\n') {
unit |= EOLN;
*curfile->fileptr = ' ';
} else {
unit &= ~EOLN;
}
}
curfile->funit = unit;
}