xref: /freebsd/contrib/nvi/ex/ex_stop.c (revision f4b37ed0f8b307b1f3f0f630ca725d68f1dff30d)
1 /*-
2  * Copyright (c) 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: ex_stop.c,v 10.11 2001/06/25 15:19:20 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 <errno.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <unistd.h>
26 
27 #include "../common/common.h"
28 
29 /*
30  * ex_stop -- :stop[!]
31  *	      :suspend[!]
32  *	Suspend execution.
33  *
34  * PUBLIC: int ex_stop(SCR *, EXCMD *);
35  */
36 int
37 ex_stop(SCR *sp, EXCMD *cmdp)
38 {
39 	int allowed;
40 
41 	/* For some strange reason, the force flag turns off autowrite. */
42 	if (!FL_ISSET(cmdp->iflags, E_C_FORCE) && file_aw(sp, FS_ALL))
43 		return (1);
44 
45 	if (sp->gp->scr_suspend(sp, &allowed))
46 		return (1);
47 	if (!allowed)
48 		ex_emsg(sp, NULL, EXM_NOSUSPEND);
49 	return (0);
50 }
51