/* Original source is from the VED editor provided with the */ /* Aztec C compiler from Manx Systems */ /* It has been heavily modified for CP/M and VT100 terminals */ /* JWD 10/15/2024 */ #include "vi.h" int read_fil(name) char *name; { register int fd; register char *bufptr, *endbuf; char msg[70]; maknam(msg, name); mesg(msg); bufptr = Cur_ptr; endbuf = Mem_buf + Max_mem; if ((fd = fopen(name, "r")) == 0) { mesg("can't open file."); return(-1); } while (bufptr <= endbuf) { if (fread (bufptr, 1, 1, fd) == 0) { mesg("error reading file!"); break; } if (*bufptr == 0x1a) /* End of file */ { if (*(bufptr-1) != 0x0d) /* Make sure line is CR terminated */ { *bufptr = 0x0d; ++bufptr; } else *bufptr = 0; /* Make sure buffer is zero terminated */ break; } if (*bufptr == 0x0a) /* Skip line feed */ *bufptr = 0; else ++bufptr; } if (bufptr > endbuf) { mesg("file too big"); } if (bufptr != Cur_ptr) End_buf = bufptr; fclose(fd); return(0); } writ_fil(name) char *name; { register int fd; register char *tmp; char msg[70]; maknam(msg, name); mesg(msg); tmp = Mem_buf; if ((fd = fopen(name, "w")) == 0) { mesg("can't open file."); return(-1); } while (tmp != End_buf) { if (fwrite (tmp, 1, 1, fd) == 0) { mesg("error writing file!"); return (-1); } if (*tmp == 0x0d) { if (fwrite ("\n", 1, 1, fd) == 0) { mesg("error writing file!"); return (-1); } } ++tmp; } fclose(fd); return(0); } maknam(buf, nam) char *buf, *nam; { *buf++ = '"'; strcpy(buf, nam); strcat(buf, "\" "); }