MFC: An off-by-one malloc size was corrupting the installer's memory,
[dragonfly.git] / contrib / nvi / tk / tk_screen.c
blobe1090930ba23519756c0a4d3454872889b66ce55
1 /*-
2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "@(#)tk_screen.c 8.9 (Berkeley) 5/24/96";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <errno.h>
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <termios.h>
26 #include <unistd.h>
28 #include "../common/common.h"
29 #include "tki.h"
32 * tk_screen --
33 * Initialize/shutdown the Tcl/Tk screen.
35 * PUBLIC: int tk_screen __P((SCR *, u_int32_t));
37 int
38 tk_screen(sp, flags)
39 SCR *sp;
40 u_int32_t flags;
42 TK_PRIVATE *tkp;
44 tkp = TKP(sp);
46 /* See if we're already in the right mode. */
47 if (LF_ISSET(SC_VI) && F_ISSET(sp, SC_SCR_VI))
48 return (0);
50 /* Ex isn't possible. */
51 if (LF_ISSET(SC_EX))
52 return (1);
54 /* Initialize terminal based information. */
55 if (tk_term_init(sp))
56 return (1);
58 /* Put up the first file name. */
59 if (tk_rename(sp))
60 return (1);
62 F_SET(tkp, TK_SCR_VI_INIT);
63 return (0);
67 * tk_quit --
68 * Shutdown the screens.
70 * PUBLIC: int tk_quit __P((GS *));
72 int
73 tk_quit(gp)
74 GS *gp;
76 TK_PRIVATE *tkp;
77 int rval;
79 /* Clean up the terminal mappings. */
80 rval = tk_term_end(gp);
82 tkp = GTKP(gp);
83 F_CLR(tkp, TK_SCR_VI_INIT);
85 return (rval);