xref: /freebsd/contrib/nvi/ex/ex_stop.c (revision c271fa9295c13b3cc926562c9b204fa597dba7e6)
1b8ba871bSPeter Wemm /*-
2b8ba871bSPeter Wemm  * Copyright (c) 1993, 1994
3b8ba871bSPeter Wemm  *	The Regents of the University of California.  All rights reserved.
4b8ba871bSPeter Wemm  * Copyright (c) 1992, 1993, 1994, 1995, 1996
5b8ba871bSPeter Wemm  *	Keith Bostic.  All rights reserved.
6b8ba871bSPeter Wemm  *
7b8ba871bSPeter Wemm  * See the LICENSE file for redistribution information.
8b8ba871bSPeter Wemm  */
9b8ba871bSPeter Wemm 
10b8ba871bSPeter Wemm #include "config.h"
11b8ba871bSPeter Wemm 
12b8ba871bSPeter Wemm #ifndef lint
13f0957ccaSPeter Wemm static const char sccsid[] = "$Id: ex_stop.c,v 10.11 2001/06/25 15:19:20 skimo Exp $";
14b8ba871bSPeter Wemm #endif /* not lint */
15b8ba871bSPeter Wemm 
16b8ba871bSPeter Wemm #include <sys/types.h>
17b8ba871bSPeter Wemm #include <sys/queue.h>
18f0957ccaSPeter Wemm #include <sys/time.h>
19b8ba871bSPeter Wemm 
20b8ba871bSPeter Wemm #include <bitstring.h>
21b8ba871bSPeter Wemm #include <errno.h>
22b8ba871bSPeter Wemm #include <limits.h>
23b8ba871bSPeter Wemm #include <stdio.h>
24b8ba871bSPeter Wemm #include <string.h>
25b8ba871bSPeter Wemm #include <unistd.h>
26b8ba871bSPeter Wemm 
27b8ba871bSPeter Wemm #include "../common/common.h"
28b8ba871bSPeter Wemm 
29b8ba871bSPeter Wemm /*
30b8ba871bSPeter Wemm  * ex_stop -- :stop[!]
31b8ba871bSPeter Wemm  *	      :suspend[!]
32b8ba871bSPeter Wemm  *	Suspend execution.
33b8ba871bSPeter Wemm  *
34*c271fa92SBaptiste Daroussin  * PUBLIC: int ex_stop(SCR *, EXCMD *);
35b8ba871bSPeter Wemm  */
36b8ba871bSPeter Wemm int
37f0957ccaSPeter Wemm ex_stop(SCR *sp, EXCMD *cmdp)
38b8ba871bSPeter Wemm {
39b8ba871bSPeter Wemm 	int allowed;
40b8ba871bSPeter Wemm 
41b8ba871bSPeter Wemm 	/* For some strange reason, the force flag turns off autowrite. */
42b8ba871bSPeter Wemm 	if (!FL_ISSET(cmdp->iflags, E_C_FORCE) && file_aw(sp, FS_ALL))
43b8ba871bSPeter Wemm 		return (1);
44b8ba871bSPeter Wemm 
45b8ba871bSPeter Wemm 	if (sp->gp->scr_suspend(sp, &allowed))
46b8ba871bSPeter Wemm 		return (1);
47b8ba871bSPeter Wemm 	if (!allowed)
48b8ba871bSPeter Wemm 		ex_emsg(sp, NULL, EXM_NOSUSPEND);
49b8ba871bSPeter Wemm 	return (0);
50b8ba871bSPeter Wemm }
51