Commit | Line | Data |
---|---|---|
f2d6dc3b KM |
1 | /* Copyright (c) 1979 Regents of the University of California */ |
2 | ||
492cc5d3 | 3 | static char sccsid[] = "@(#)IOSYNC.c 1.4 %G%"; |
f2d6dc3b KM |
4 | |
5 | #include "h00vars.h" | |
6 | #include "h01errs.h" | |
7 | ||
8 | /* | |
9 | * insure that a usable image is in the buffer window | |
10 | */ | |
11 | IOSYNC(curfile) | |
12 | ||
13 | register struct iorec *curfile; | |
14 | { | |
f2d6dc3b KM |
15 | char *limit, *ptr; |
16 | ||
8066db34 | 17 | if (curfile->funit & FWRITE) { |
f2d6dc3b KM |
18 | ERROR(EREADIT, curfile->pfname); |
19 | return; | |
20 | } | |
8066db34 | 21 | if ((curfile->funit & SYNC) == 0) { |
f2d6dc3b KM |
22 | return; |
23 | } | |
8066db34 | 24 | if (curfile->funit & EOFF) { |
f2d6dc3b KM |
25 | ERROR(EPASTEOF, curfile->pfname); |
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 KM |
35 | if (ferror(curfile->fbuf)) { |
36 | ERROR(EPASTEOF, curfile->pfname); | |
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 | } |