Merge from vendor branch NTPD:
[dragonfly.git] / contrib / nvi / ip / ip_screen.c
1 /*-
2  * Copyright (c) 1996
3  *      Keith Bostic.  All rights reserved.
4  *
5  * See the LICENSE file for redistribution information.
6  */
7
8 #include "config.h"
9
10 #ifndef lint
11 static const char sccsid[] = "@(#)ip_screen.c   8.2 (Berkeley) 10/13/96";
12 #endif /* not lint */
13
14 #include <sys/types.h>
15 #include <sys/queue.h>
16
17 #include <bitstring.h>
18 #include <stdio.h>
19
20 #include "../common/common.h"
21 #include "ip.h"
22
23 /*
24  * ip_screen --
25  *      Initialize/shutdown the IP screen.
26  *
27  * PUBLIC: int ip_screen __P((SCR *, u_int32_t));
28  */
29 int
30 ip_screen(sp, flags)
31         SCR *sp;
32         u_int32_t flags;
33 {
34         GS *gp;
35         IP_PRIVATE *ipp;
36
37         gp = sp->gp;
38         ipp = IPP(sp);
39
40         /* See if the current information is incorrect. */
41         if (F_ISSET(gp, G_SRESTART)) {
42                 if (ip_quit(gp))
43                         return (1);
44                 F_CLR(gp, G_SRESTART);
45         }
46         
47         /* See if we're already in the right mode. */
48         if (LF_ISSET(SC_VI) && F_ISSET(ipp, IP_SCR_VI_INIT))
49                 return (0);
50
51         /* Ex isn't possible. */
52         if (LF_ISSET(SC_EX))
53                 return (1);
54
55         /* Initialize terminal based information. */
56         if (ip_term_init(sp)) 
57                 return (1);
58
59         /* Put up the first file name. */
60         if (ip_rename(sp))
61                 return (1);
62
63         F_SET(ipp, IP_SCR_VI_INIT);
64         return (0);
65 }
66
67 /*
68  * ip_quit --
69  *      Shutdown the screens.
70  *
71  * PUBLIC: int ip_quit __P((GS *));
72  */
73 int
74 ip_quit(gp)
75         GS *gp;
76 {
77         IP_PRIVATE *ipp;
78         int rval;
79
80         /* Clean up the terminal mappings. */
81         rval = ip_term_end(gp);
82
83         ipp = GIPP(gp);
84         F_CLR(ipp, IP_SCR_VI_INIT);
85
86         return (rval);
87 }