1 /* Copyright (c) 1979 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)IOSYNC.c 1.2 01/24/81"; 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 { 15 register short unit = curfile->funit; 16 char *limit, *ptr; 17 18 if (unit & FWRITE) { 19 ERROR(EREADIT, curfile->pfname); 20 return; 21 } 22 if ((unit & SYNC) == 0) { 23 return; 24 } 25 if (unit & EOFF) { 26 ERROR(EPASTEOF, curfile->pfname); 27 return; 28 } 29 unit &= ~SYNC; 30 fread(curfile->fileptr, curfile->fsize, 1, curfile->fbuf); 31 if (ferror(curfile->fbuf)) { 32 ERROR(EPASTEOF, curfile->pfname); 33 return; 34 } 35 if (feof(curfile->fbuf)) { 36 curfile->funit = unit | EOFF; 37 if (unit & FTEXT) { 38 *curfile->fileptr = ' '; 39 return; 40 } 41 limit = &curfile->fileptr[curfile->fsize]; 42 for (ptr = curfile->fileptr; ptr < limit; ) 43 *ptr++ = 0; 44 return; 45 } 46 if (unit & FTEXT) { 47 if (*curfile->fileptr == '\n') { 48 unit |= EOLN; 49 *curfile->fileptr = ' '; 50 } else { 51 unit &= ~EOLN; 52 } 53 } 54 curfile->funit = unit; 55 } 56