1*0a6a1f1dSLionel Sambuc /* $NetBSD: ip_screen.c,v 1.3 2014/01/26 21:43:45 christos Exp $ */
284d9c625SLionel Sambuc /*-
384d9c625SLionel Sambuc * Copyright (c) 1996
484d9c625SLionel Sambuc * Keith Bostic. All rights reserved.
584d9c625SLionel Sambuc *
684d9c625SLionel Sambuc * See the LICENSE file for redistribution information.
784d9c625SLionel Sambuc */
884d9c625SLionel Sambuc
984d9c625SLionel Sambuc #include "config.h"
1084d9c625SLionel Sambuc
11*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
12*0a6a1f1dSLionel Sambuc #if 0
1384d9c625SLionel Sambuc #ifndef lint
1484d9c625SLionel Sambuc 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 ";
1584d9c625SLionel Sambuc #endif /* not lint */
16*0a6a1f1dSLionel Sambuc #else
17*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: ip_screen.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
18*0a6a1f1dSLionel Sambuc #endif
1984d9c625SLionel Sambuc
2084d9c625SLionel Sambuc #include <sys/types.h>
2184d9c625SLionel Sambuc #include <sys/queue.h>
2284d9c625SLionel Sambuc
2384d9c625SLionel Sambuc #include <bitstring.h>
2484d9c625SLionel Sambuc #include <stdio.h>
2584d9c625SLionel Sambuc
2684d9c625SLionel Sambuc #include "../common/common.h"
2784d9c625SLionel Sambuc #include "../ipc/ip.h"
2884d9c625SLionel Sambuc
2984d9c625SLionel Sambuc /*
3084d9c625SLionel Sambuc * ip_screen --
3184d9c625SLionel Sambuc * Initialize/shutdown the IP screen.
3284d9c625SLionel Sambuc *
3384d9c625SLionel Sambuc * PUBLIC: int ip_screen __P((SCR *, u_int32_t));
3484d9c625SLionel Sambuc */
3584d9c625SLionel Sambuc int
ip_screen(SCR * sp,u_int32_t flags)3684d9c625SLionel Sambuc ip_screen(SCR *sp, u_int32_t flags)
3784d9c625SLionel Sambuc {
3884d9c625SLionel Sambuc GS *gp;
3984d9c625SLionel Sambuc IP_PRIVATE *ipp;
4084d9c625SLionel Sambuc
4184d9c625SLionel Sambuc gp = sp->gp;
4284d9c625SLionel Sambuc ipp = IPP(sp);
4384d9c625SLionel Sambuc
4484d9c625SLionel Sambuc /* See if the current information is incorrect. */
4584d9c625SLionel Sambuc if (F_ISSET(gp, G_SRESTART)) {
4684d9c625SLionel Sambuc if (ip_quit(sp->wp))
4784d9c625SLionel Sambuc return (1);
4884d9c625SLionel Sambuc F_CLR(gp, G_SRESTART);
4984d9c625SLionel Sambuc }
5084d9c625SLionel Sambuc
5184d9c625SLionel Sambuc /* See if we're already in the right mode. */
5284d9c625SLionel Sambuc if ((LF_ISSET(SC_EX) && F_ISSET(sp, SC_SCR_EX)) ||
5384d9c625SLionel Sambuc (LF_ISSET(SC_VI) && F_ISSET(sp, SC_SCR_VI)))
5484d9c625SLionel Sambuc return (0);
5584d9c625SLionel Sambuc
5684d9c625SLionel Sambuc /* Ex isn't possible if there is no terminal. */
5784d9c625SLionel Sambuc if (LF_ISSET(SC_EX) && ipp->t_fd == -1)
5884d9c625SLionel Sambuc return (1);
5984d9c625SLionel Sambuc
6084d9c625SLionel Sambuc if (F_ISSET(sp, SC_SCR_EX))
6184d9c625SLionel Sambuc F_CLR(sp, SC_SCR_EX);
6284d9c625SLionel Sambuc
6384d9c625SLionel Sambuc if (F_ISSET(sp, SC_SCR_VI))
6484d9c625SLionel Sambuc F_CLR(sp, SC_SCR_VI);
6584d9c625SLionel Sambuc
6684d9c625SLionel Sambuc if (LF_ISSET(SC_EX)) {
6784d9c625SLionel Sambuc F_SET(ipp, IP_IN_EX);
6884d9c625SLionel Sambuc } else {
6984d9c625SLionel Sambuc /* Initialize terminal based information. */
7084d9c625SLionel Sambuc if (ip_term_init(sp))
7184d9c625SLionel Sambuc return (1);
7284d9c625SLionel Sambuc
7384d9c625SLionel Sambuc F_CLR(ipp, IP_IN_EX);
7484d9c625SLionel Sambuc F_SET(ipp, IP_SCR_VI_INIT);
7584d9c625SLionel Sambuc }
7684d9c625SLionel Sambuc return (0);
7784d9c625SLionel Sambuc }
7884d9c625SLionel Sambuc
7984d9c625SLionel Sambuc /*
8084d9c625SLionel Sambuc * ip_quit --
8184d9c625SLionel Sambuc * Shutdown the screens.
8284d9c625SLionel Sambuc *
8384d9c625SLionel Sambuc * PUBLIC: int ip_quit __P((WIN *));
8484d9c625SLionel Sambuc */
8584d9c625SLionel Sambuc int
ip_quit(WIN * wp)8684d9c625SLionel Sambuc ip_quit(WIN *wp)
8784d9c625SLionel Sambuc {
8884d9c625SLionel Sambuc IP_PRIVATE *ipp;
8984d9c625SLionel Sambuc int rval;
9084d9c625SLionel Sambuc
9184d9c625SLionel Sambuc /* Clean up the terminal mappings. */
9284d9c625SLionel Sambuc rval = ip_term_end(wp->gp);
9384d9c625SLionel Sambuc
9484d9c625SLionel Sambuc ipp = WIPP(wp);
9584d9c625SLionel Sambuc F_CLR(ipp, IP_SCR_VI_INIT);
9684d9c625SLionel Sambuc
9784d9c625SLionel Sambuc return (rval);
9884d9c625SLionel Sambuc }
99