home *** CD-ROM | disk | FTP | other *** search
- /*
- * The routines in this file
- * read and write ASCII files from the
- * disk. All of the knowledge about files
- * are here. A better message writing
- * scheme should be used.
- */
- #define EOFCHAR 0x1A
- #include <stdio.h>
- #include "ed.h"
-
- FILE *ffp; /* File pointer, all functions. */
-
- /*
- * Open a file for reading.
- */
- ffropen(fn)
- char *fn;
- {
- if ((ffp=fopen(fn, "r")) == NULL)
- return (FIOFNF);
- return (FIOSUC);
- }
-
- /*
- * Open a file for writing.
- * Return TRUE if all is well, and
- * FALSE on error (cannot create).
- */
- ffwopen(fn)
- char *fn;
- {
- if ((ffp=fopen(fn, "w")) == NULL) {
- mlwrite("Cannot open file for writing");
- return (FIOERR);
- }
- return (FIOSUC);
- }
-
- /* write an eof mark at end of file */
- weof()
- {
- if (fputc(EOFCHAR,ffp))
- return(FIOSUC);
- else
- return(FIOERR);
- }
-
- /*
- * Close a file.
- * Should look at the status in all systems.
- */
- ffclose()
- {
- fclose(ffp);
- return (FIOSUC);
- }
-
- /*
- * Write a line to the already
- * opened file. The "buf" points to the
- * buffer, and the "nbuf" is its length, less
- * the free newline. Return the status.
- * Check only at the newline.
- */
- ffputline(buf, nbuf)
- register char buf[];
- {
- register int i;
- static char crlf[] = "\r\n" ;
-
- if (nbuf==0 || fwrite(buf, 1, nbuf, ffp))
- {
- if (fwrite(crlf, 1, 2, ffp))
- {
- return FIOSUC ;
- }
- }
- mlwrite("Write I/O error");
- return (FIOERR);
- }
-
- /*
- * Read a line from a file,
- * and store the bytes in the supplied
- * buffer. The "nbuf" is the length of the
- * buffer. Complain about long lines and lines
- * at the end of the file that don't have a
- * newline present. Check for I/O errors
- * too. Return status.
- */
- ffgetline(buf, nbuf)
- register char buf[];
- {
- register int c;
- register int i;
-
- if (fgets(buf, nbuf, ffp))
- {
- buf[strlen(buf) - 1] = 0 ;
- return (FIOSUC) ;
- }
- return FIOEOF ;
- }
-