/* * Name: MicroEMACS * CP/M-86 file I/O. * Version: 29 * Last edit: 05-Feb-86 * By: rex::conroy * decvax!decwrl!dec-rhea!dec-rex!conroy */ #include "def.h" static FILE *ffp; /* * 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) { eprintf("Cannot open file for writing"); return (FIOERR); } return (FIOSUC); } /* * Close a file. * Should look at the status. */ 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; for (i=0; i= nbuf-1) { eprintf("File has long line"); return (FIOERR); } buf[i++] = '\r'; } } if (c==EOF || c=='\n') /* End of line. */ break; if (i >= nbuf-1) { eprintf("File has long line"); return (FIOERR); } buf[i++] = c; } if (c == EOF) { /* End of file. */ if (ferror(ffp) != FALSE) { eprintf("File read error"); return (FIOERR); } if (i == 0) /* Don't get upset if */ return (FIOEOF); /* no newline at EOF. */ } buf[i] = 0; return (FIOSUC); } /* * Some CP/M-86 user should figure out * the right rules for backup file names, and make * this work. I don't use CP/M-86, so I cannot figure * out the right rules. Return TRUE so the callers * don't abort writes. */ fbackupfile(fname) char *fname; { return (TRUE); /* Hack. */ } /* * The string "fn" is a file name. * Perform any required case adjustments. All sustems * we deal with so far have case insensitive file systems. * We zap everything to lower case. The problem we are trying * to solve is getting 2 buffers holding the same file if * you visit one of them with the "caps lock" key down. * On UNIX file names are dual case, so we leave * everything alone. */ adjustcase(fn) register char *fn; { register int c; while ((c = *fn) != 0) { if (c>='A' && c<='Z') *fn = c + 'a' - 'A'; ++fn; } }