rework initial error handling -- since we check for any screens on
[nvi.git] / ex / ex_quit.c
blob4efbbaad26bb9db27f98d90ced821fa0a8729dcc
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_quit.c,v 8.7 1993/12/10 12:20:58 bostic Exp $ (Berkeley) $Date: 1993/12/10 12:20:58 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "excmd.h"
18 * ex_quit -- :quit[!]
19 * Quit.
21 int
22 ex_quit(sp, ep, cmdp)
23 SCR *sp;
24 EXF *ep;
25 EXCMDARG *cmdp;
27 int force;
29 force = F_ISSET(cmdp, E_FORCE);
31 /* Check for modifications. */
32 if (F_ISSET(ep, F_MODIFIED) && ep->refcnt <= 1 && !force) {
33 msgq(sp, M_ERR,
34 "Modified since last write; write or use ! to override.");
35 return (1);
39 * !!!
40 * Historic practice: quit! or two quit's done in succession
41 * (where ZZ counts as a quit) didn't check for other files.
43 * Also check for related screens; if they exist, quit, the
44 * user will get the message on the last screen.
46 if (!force && sp->ccnt != sp->q_ccnt + 1 &&
47 ep->refcnt <= 1 && file_unedited(sp) != NULL) {
48 sp->q_ccnt = sp->ccnt;
49 msgq(sp, M_ERR,
50 "More files; use \":n\" to go to the next file, \":q!\" to quit.");
51 return (1);
54 F_SET(sp, force ? S_EXIT_FORCE : S_EXIT);
55 return (0);