xref: /minix/external/bsd/nvi/dist/vi/v_screen.c (revision 84d9c625)
1 /*	$NetBSD: v_screen.c,v 1.4 2013/11/28 03:15:20 christos Exp $	*/
2 /*-
3  * Copyright (c) 1993, 1994
4  *	The Regents of the University of California.  All rights reserved.
5  * Copyright (c) 1992, 1993, 1994, 1995, 1996
6  *	Keith Bostic.  All rights reserved.
7  *
8  * See the LICENSE file for redistribution information.
9  */
10 
11 #include "config.h"
12 
13 #ifndef lint
14 static const char sccsid[] = "Id: v_screen.c,v 10.12 2001/06/25 15:19:34 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:34 ";
15 #endif /* not lint */
16 
17 #include <sys/types.h>
18 #include <sys/queue.h>
19 #include <sys/time.h>
20 
21 #include <bitstring.h>
22 #include <limits.h>
23 #include <stdio.h>
24 
25 #include "../common/common.h"
26 #include "vi.h"
27 
28 /*
29  * v_screen -- ^W
30  *	Switch screens.
31  *
32  * PUBLIC: int v_screen __P((SCR *, VICMD *));
33  */
34 int
35 v_screen(SCR *sp, VICMD *vp)
36 {
37 	/*
38 	 * You can't leave a colon command-line edit window -- it's not that
39 	 * it won't work, but it gets real weird, real fast when you execute
40 	 * a colon command out of a window that was forked from a window that's
41 	 * now backgrounded...  You get the idea.
42 	 */
43 	if (F_ISSET(sp, SC_COMEDIT)) {
44 		msgq(sp, M_ERR,
45 		    "308|Enter <CR> to execute a command, :q to exit");
46 		return (1);
47 	}
48 
49 	/*
50 	 * Try for the next lower screen, or, go back to the first
51 	 * screen on the stack.
52 	 */
53 	if (TAILQ_NEXT(sp, q) != NULL)
54 		sp->nextdisp = TAILQ_NEXT(sp, q);
55 	else if (TAILQ_FIRST(&sp->wp->scrq) == sp) {
56 		msgq(sp, M_ERR, "187|No other screen to switch to");
57 		return (1);
58 	} else
59 		sp->nextdisp = TAILQ_FIRST(&sp->wp->scrq);
60 
61 	F_SET(sp->nextdisp, SC_STATUS);
62 	F_SET(sp, SC_SSWITCH | SC_STATUS);
63 	return (0);
64 }
65