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