xref: /minix/external/bsd/nvi/dist/ip/ip_screen.c (revision 84d9c625)
1 /*	$NetBSD: ip_screen.c,v 1.2 2013/11/22 15:52:05 christos Exp $	*/
2 /*-
3  * Copyright (c) 1996
4  *	Keith Bostic.  All rights reserved.
5  *
6  * See the LICENSE file for redistribution information.
7  */
8 
9 #include "config.h"
10 
11 #ifndef lint
12 static const char sccsid[] = "Id: ip_screen.c,v 8.8 2001/06/25 15:19:24 skimo Exp  (Berkeley) Date: 2001/06/25 15:19:24 ";
13 #endif /* not lint */
14 
15 #include <sys/types.h>
16 #include <sys/queue.h>
17 
18 #include <bitstring.h>
19 #include <stdio.h>
20 
21 #include "../common/common.h"
22 #include "../ipc/ip.h"
23 
24 /*
25  * ip_screen --
26  *	Initialize/shutdown the IP screen.
27  *
28  * PUBLIC: int ip_screen __P((SCR *, u_int32_t));
29  */
30 int
31 ip_screen(SCR *sp, u_int32_t flags)
32 {
33 	GS *gp;
34 	IP_PRIVATE *ipp;
35 
36 	gp = sp->gp;
37 	ipp = IPP(sp);
38 
39 	/* See if the current information is incorrect. */
40 	if (F_ISSET(gp, G_SRESTART)) {
41 		if (ip_quit(sp->wp))
42 			return (1);
43 		F_CLR(gp, G_SRESTART);
44 	}
45 
46 	/* See if we're already in the right mode. */
47 	if ((LF_ISSET(SC_EX) && F_ISSET(sp, SC_SCR_EX)) ||
48 	    (LF_ISSET(SC_VI) && F_ISSET(sp, SC_SCR_VI)))
49 		return (0);
50 
51 	/* Ex isn't possible if there is no terminal. */
52 	if (LF_ISSET(SC_EX) && ipp->t_fd == -1)
53 		return (1);
54 
55 	if (F_ISSET(sp, SC_SCR_EX))
56 		F_CLR(sp, SC_SCR_EX);
57 
58 	if (F_ISSET(sp, SC_SCR_VI))
59 		F_CLR(sp, SC_SCR_VI);
60 
61 	if (LF_ISSET(SC_EX)) {
62 		F_SET(ipp, IP_IN_EX);
63 	} else {
64 		/* Initialize terminal based information. */
65 		if (ip_term_init(sp))
66 			return (1);
67 
68 		F_CLR(ipp, IP_IN_EX);
69 		F_SET(ipp, IP_SCR_VI_INIT);
70 	}
71 	return (0);
72 }
73 
74 /*
75  * ip_quit --
76  *	Shutdown the screens.
77  *
78  * PUBLIC: int ip_quit __P((WIN *));
79  */
80 int
81 ip_quit(WIN *wp)
82 {
83 	IP_PRIVATE *ipp;
84 	int rval;
85 
86 	/* Clean up the terminal mappings. */
87 	rval = ip_term_end(wp->gp);
88 
89 	ipp = WIPP(wp);
90 	F_CLR(ipp, IP_SCR_VI_INIT);
91 
92 	return (rval);
93 }
94