xref: /freebsd/contrib/nvi/vi/v_zexit.c (revision 38f0b757fd84d17d0fc24739a7cda160c4516d81)
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 #ifndef lint
13 static const char sccsid[] = "$Id: v_zexit.c,v 10.7 2001/06/25 15:19:37 skimo Exp $";
14 #endif /* not lint */
15 
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/time.h>
19 
20 #include <bitstring.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <string.h>
24 
25 #include "../common/common.h"
26 #include "vi.h"
27 
28 /*
29  * v_zexit -- ZZ
30  *	Save the file and exit.
31  *
32  * PUBLIC: int v_zexit __P((SCR *, VICMD *));
33  */
34 int
35 v_zexit(SCR *sp, VICMD *vp)
36 {
37 	/* Write back any modifications. */
38 	if (F_ISSET(sp->ep, F_MODIFIED) &&
39 	    file_write(sp, NULL, NULL, NULL, FS_ALL))
40 		return (1);
41 
42 	/* Check to make sure it's not a temporary file. */
43 	if (file_m3(sp, 0))
44 		return (1);
45 
46 	/* Check for more files to edit. */
47 	if (ex_ncheck(sp, 0))
48 		return (1);
49 
50 	F_SET(sp, SC_EXIT);
51 	return (0);
52 }
53