/* * file_m1 -- * First modification check routine. The :next, :prev, :rewind, :tag, * :tagpush, :tagpop, ^^ modifications check. * * PUBLIC: int file_m1 __P((SCR *, int, int)); */ int file_m1(SCR *sp, int force, int flags) { EXF *ep; ep = sp->ep; /* If no file loaded, return no modifications. */ if (ep == NULL) return (0); /* * If the file has been modified, we'll want to write it back or * fail. If autowrite is set, we'll write it back automatically, * unless force is also set. Otherwise, we fail unless forced or * there's another open screen on this file. */ if (F_ISSET(ep, F_MODIFIED)) { if (O_ISSET(sp, O_AUTOWRITE)) { if (!force && file_aw(sp, flags)) return (1); } else if (ep->refcnt <= 1 && !force) { msgq(sp, M_ERR, LF_ISSET(FS_POSSIBLE) ? "262|File modified since last complete write; write or use ! to override" : "263|File modified since last complete write; write or use :edit! to override"); return (1); } } return (file_m3(sp, force)); }
/* * ex_wn -- :wn[!] [>>] [file] * Write to a file and switch to the next one. * * PUBLIC: int ex_wn __P((SCR *, EXCMD *)); */ int ex_wn(SCR *sp, EXCMD *cmdp) { if (exwr(sp, cmdp, WN)) return (1); if (file_m3(sp, 0)) return (1); /* The file name isn't a new file to edit. */ cmdp->argc = 0; return (ex_next(sp, cmdp)); }
/* * ex_wq -- :wq[!] [>>] [file] * Write to a file and quit. * * PUBLIC: int ex_wq __P((SCR *, EXCMD *)); */ int ex_wq(SCR *sp, EXCMD *cmdp) { int force; if (exwr(sp, cmdp, WQ)) return (1); if (file_m3(sp, 0)) return (1); force = FL_ISSET(cmdp->iflags, E_C_FORCE); if (ex_ncheck(sp, force)) return (1); F_SET(sp, force ? SC_EXIT_FORCE : SC_EXIT); return (0); }
/* * v_zexit -- ZZ * Save the file and exit. * * PUBLIC: int v_zexit __P((SCR *, VICMD *)); */ int v_zexit(SCR *sp, VICMD *vp) { /* Write back any modifications. */ if (F_ISSET(sp->ep, F_MODIFIED) && file_write(sp, NULL, NULL, NULL, FS_ALL)) return (1); /* Check to make sure it's not a temporary file. */ if (file_m3(sp, 0)) return (1); /* Check for more files to edit. */ if (ex_ncheck(sp, 0)) return (1); F_SET(sp, SC_EXIT); return (0); }
/* * ex_xit -- :x[it]! [file] * Write out any modifications and quit. * * PUBLIC: int ex_xit __P((SCR *, EXCMD *)); */ int ex_xit(SCR *sp, EXCMD *cmdp) { int force; NEEDFILE(sp, cmdp); if (F_ISSET(sp->ep, F_MODIFIED) && exwr(sp, cmdp, XIT)) return (1); if (file_m3(sp, 0)) return (1); force = FL_ISSET(cmdp->iflags, E_C_FORCE); if (ex_ncheck(sp, force)) return (1); F_SET(sp, force ? SC_EXIT_FORCE : SC_EXIT); return (0); }
/* * file_m2 -- * Second modification check routine. The :edit, :quit, :recover * modifications check. * * PUBLIC: int file_m2 __P((SCR *, int)); */ int file_m2(SCR *sp, int force) { EXF *ep; ep = sp->ep; /* If no file loaded, return no modifications. */ if (ep == NULL) return (0); /* * If the file has been modified, we'll want to fail, unless forced * or there's another open screen on this file. */ if (F_ISSET(ep, F_MODIFIED) && ep->refcnt <= 1 && !force) { msgq(sp, M_ERR, "264|File modified since last complete write; write or use ! to override"); return (1); } return (file_m3(sp, force)); }