xref: /netbsd-src/external/bsd/nvi/dist/ip/ip_screen.c (revision 2f698edb5c1cb2dcd9e762b0abb50c41dde8b6b7)
1 /*	$NetBSD: ip_screen.c,v 1.3 2014/01/26 21:43:45 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 #include <sys/cdefs.h>
12 #if 0
13 #ifndef lint
14 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 ";
15 #endif /* not lint */
16 #else
17 __RCSID("$NetBSD: ip_screen.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
18 #endif
19 
20 #include <sys/types.h>
21 #include <sys/queue.h>
22 
23 #include <bitstring.h>
24 #include <stdio.h>
25 
26 #include "../common/common.h"
27 #include "../ipc/ip.h"
28 
29 /*
30  * ip_screen --
31  *	Initialize/shutdown the IP screen.
32  *
33  * PUBLIC: int ip_screen __P((SCR *, u_int32_t));
34  */
35 int
ip_screen(SCR * sp,u_int32_t flags)36 ip_screen(SCR *sp, u_int32_t flags)
37 {
38 	GS *gp;
39 	IP_PRIVATE *ipp;
40 
41 	gp = sp->gp;
42 	ipp = IPP(sp);
43 
44 	/* See if the current information is incorrect. */
45 	if (F_ISSET(gp, G_SRESTART)) {
46 		if (ip_quit(sp->wp))
47 			return (1);
48 		F_CLR(gp, G_SRESTART);
49 	}
50 
51 	/* See if we're already in the right mode. */
52 	if ((LF_ISSET(SC_EX) && F_ISSET(sp, SC_SCR_EX)) ||
53 	    (LF_ISSET(SC_VI) && F_ISSET(sp, SC_SCR_VI)))
54 		return (0);
55 
56 	/* Ex isn't possible if there is no terminal. */
57 	if (LF_ISSET(SC_EX) && ipp->t_fd == -1)
58 		return (1);
59 
60 	if (F_ISSET(sp, SC_SCR_EX))
61 		F_CLR(sp, SC_SCR_EX);
62 
63 	if (F_ISSET(sp, SC_SCR_VI))
64 		F_CLR(sp, SC_SCR_VI);
65 
66 	if (LF_ISSET(SC_EX)) {
67 		F_SET(ipp, IP_IN_EX);
68 	} else {
69 		/* Initialize terminal based information. */
70 		if (ip_term_init(sp))
71 			return (1);
72 
73 		F_CLR(ipp, IP_IN_EX);
74 		F_SET(ipp, IP_SCR_VI_INIT);
75 	}
76 	return (0);
77 }
78 
79 /*
80  * ip_quit --
81  *	Shutdown the screens.
82  *
83  * PUBLIC: int ip_quit __P((WIN *));
84  */
85 int
ip_quit(WIN * wp)86 ip_quit(WIN *wp)
87 {
88 	IP_PRIVATE *ipp;
89 	int rval;
90 
91 	/* Clean up the terminal mappings. */
92 	rval = ip_term_end(wp->gp);
93 
94 	ipp = WIPP(wp);
95 	F_CLR(ipp, IP_SCR_VI_INIT);
96 
97 	return (rval);
98 }
99