11660Smckusick /* Copyright (c) 1979 Regents of the University of California */ 21660Smckusick 3*2218Smckusic static char sccsid[] = "@(#)IOSYNC.c 1.2 01/24/81"; 41660Smckusick 51660Smckusick #include "h00vars.h" 61660Smckusick #include "h01errs.h" 71660Smckusick 81660Smckusick /* 91660Smckusick * insure that a usable image is in the buffer window 101660Smckusick */ 111660Smckusick IOSYNC(curfile) 121660Smckusick 131660Smckusick register struct iorec *curfile; 141660Smckusick { 151660Smckusick register short unit = curfile->funit; 161660Smckusick char *limit, *ptr; 171660Smckusick 181660Smckusick if (unit & FWRITE) { 191660Smckusick ERROR(EREADIT, curfile->pfname); 201660Smckusick return; 211660Smckusick } 221660Smckusick if ((unit & SYNC) == 0) { 231660Smckusick return; 241660Smckusick } 251660Smckusick if (unit & EOFF) { 261660Smckusick ERROR(EPASTEOF, curfile->pfname); 271660Smckusick return; 281660Smckusick } 291660Smckusick unit &= ~SYNC; 301660Smckusick fread(curfile->fileptr, curfile->fsize, 1, curfile->fbuf); 311660Smckusick if (ferror(curfile->fbuf)) { 321660Smckusick ERROR(EPASTEOF, curfile->pfname); 331660Smckusick return; 341660Smckusick } 351660Smckusick if (feof(curfile->fbuf)) { 361660Smckusick curfile->funit = unit | EOFF; 37*2218Smckusic if (unit & FTEXT) { 38*2218Smckusic *curfile->fileptr = ' '; 39*2218Smckusic return; 40*2218Smckusic } 411660Smckusick limit = &curfile->fileptr[curfile->fsize]; 421660Smckusick for (ptr = curfile->fileptr; ptr < limit; ) 431660Smckusick *ptr++ = 0; 441660Smckusick return; 451660Smckusick } 461660Smckusick if (unit & FTEXT) { 471660Smckusick if (*curfile->fileptr == '\n') { 481660Smckusick unit |= EOLN; 491660Smckusick *curfile->fileptr = ' '; 501660Smckusick } else { 511660Smckusick unit &= ~EOLN; 521660Smckusick } 531660Smckusick } 541660Smckusick curfile->funit = unit; 551660Smckusick } 56