date and time created 82/01/18 19:21:15 by linton
[unix-history] / usr / src / usr.bin / pascal / libpc / IOSYNC.c
CommitLineData
f2d6dc3b
KM
1/* Copyright (c) 1979 Regents of the University of California */
2
86997b19 3static char sccsid[] = "@(#)IOSYNC.c 1.5 %G%";
f2d6dc3b
KM
4
5#include "h00vars.h"
f2d6dc3b
KM
6
7/*
8 * insure that a usable image is in the buffer window
9 */
10IOSYNC(curfile)
11
12 register struct iorec *curfile;
13{
f2d6dc3b
KM
14 char *limit, *ptr;
15
8066db34 16 if (curfile->funit & FWRITE) {
86997b19
KM
17 ERROR("%s: Attempt to read, but open for writing\n",
18 curfile->pfname);
f2d6dc3b
KM
19 return;
20 }
8066db34 21 if ((curfile->funit & SYNC) == 0) {
f2d6dc3b
KM
22 return;
23 }
8066db34 24 if (curfile->funit & EOFF) {
86997b19 25 ERROR("%s: Tried to read past end of file\n", curfile->pfname);
f2d6dc3b
KM
26 return;
27 }
8066db34
KM
28 curfile->funit &= ~SYNC;
29 if (curfile->funit & SPEOLN) {
30 curfile->funit &= ~(SPEOLN|EOLN);
31 curfile->funit |= EOFF;
32 return;
33 }
492cc5d3 34 fread(curfile->fileptr, (int)curfile->fsize, 1, curfile->fbuf);
f2d6dc3b 35 if (ferror(curfile->fbuf)) {
86997b19 36 ERROR("%s: Tried to read past end of file\n", curfile->pfname);
f2d6dc3b
KM
37 return;
38 }
39 if (feof(curfile->fbuf)) {
8066db34 40 if (curfile->funit & FTEXT) {
29b34693 41 *curfile->fileptr = ' ';
8066db34
KM
42 if (curfile->funit & EOLN) {
43 curfile->funit &= ~EOLN;
44 curfile->funit |= EOFF;
45 return;
46 }
47 curfile->funit |= (SPEOLN|EOLN);
29b34693
KM
48 return;
49 }
8066db34 50 curfile->funit |= EOFF;
f2d6dc3b
KM
51 limit = &curfile->fileptr[curfile->fsize];
52 for (ptr = curfile->fileptr; ptr < limit; )
53 *ptr++ = 0;
54 return;
55 }
8066db34 56 if (curfile->funit & FTEXT) {
f2d6dc3b 57 if (*curfile->fileptr == '\n') {
8066db34 58 curfile->funit |= EOLN;
f2d6dc3b 59 *curfile->fileptr = ' ';
8066db34 60 return;
f2d6dc3b 61 }
8066db34 62 curfile->funit &= ~EOLN;
f2d6dc3b 63 }
f2d6dc3b 64}