xref: /freebsd/contrib/nvi/vi/v_zexit.c (revision a0b9e2e854027e6ff61fb075a1309dbc71c42b54)
1 /*-
2  * Copyright (c) 1992, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1992, 1993, 1994, 1995, 1996
5  *	Keith Bostic.  All rights reserved.
6  *
7  * See the LICENSE file for redistribution information.
8  */
9 
10 #include "config.h"
11 
12 #include <sys/types.h>
13 #include <sys/queue.h>
14 #include <sys/time.h>
15 
16 #include <bitstring.h>
17 #include <limits.h>
18 #include <stdio.h>
19 #include <string.h>
20 
21 #include "../common/common.h"
22 #include "vi.h"
23 
24 /*
25  * v_zexit -- ZZ
26  *	Save the file and exit.
27  *
28  * PUBLIC: int v_zexit(SCR *, VICMD *);
29  */
30 int
31 v_zexit(SCR *sp, VICMD *vp)
32 {
33 	/* Write back any modifications. */
34 	if (F_ISSET(sp->ep, F_MODIFIED) &&
35 	    file_write(sp, NULL, NULL, NULL, FS_ALL))
36 		return (1);
37 
38 	/* Check to make sure it's not a temporary file. */
39 	if (file_m3(sp, 0))
40 		return (1);
41 
42 	/* Check for more files to edit. */
43 	if (ex_ncheck(sp, 0))
44 		return (1);
45 
46 	F_SET(sp, SC_EXIT);
47 	return (0);
48 }
49