Merge from vendor branch GDB:
[dragonfly.git] / contrib / nvi / tk / tk_term.c
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.
6  *
7  * See the LICENSE file for redistribution information.
8  */
9
10 #include "config.h"
11
12 #ifndef lint
13 static const char sccsid[] = "@(#)tk_term.c     8.12 (Berkeley) 10/13/96";
14 #endif /* not lint */
15
16 #include <sys/types.h>
17 #include <sys/queue.h>
18
19 #include <bitstring.h>
20 #include <errno.h>
21 #include <limits.h>
22 #include <signal.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include <termios.h>
27 #include <unistd.h>
28
29 #include "../common/common.h"
30 #include "tki.h"
31
32 /*
33  * tk_term_init --
34  *      Initialize the terminal special keys.
35  *
36  * PUBLIC: int tk_term_init __P((SCR *));
37  */
38 int
39 tk_term_init(sp)
40         SCR *sp;
41 {
42         SEQ *qp;
43
44         /*
45          * Rework any function key mappings that were set before the
46          * screen was initialized.
47          */
48         for (qp = sp->gp->seqq.lh_first; qp != NULL; qp = qp->q.le_next)
49                 if (F_ISSET(qp, SEQ_FUNCMAP))
50                         (void)tk_fmap(sp, qp->stype,
51                             qp->input, qp->ilen, qp->output, qp->olen);
52         return (0);
53 }
54
55 /*
56  * tk_term_end --
57  *      End the special keys defined by the termcap/terminfo entry.
58  *
59  * PUBLIC: int tk_term_end __P((GS *));
60  */
61 int
62 tk_term_end(gp)
63         GS *gp;
64 {
65         SEQ *qp, *nqp;
66
67         /* Delete screen specific mappings. */
68         for (qp = gp->seqq.lh_first; qp != NULL; qp = nqp) {
69                 nqp = qp->q.le_next;
70                 if (F_ISSET(qp, SEQ_SCREEN))
71                         (void)seq_mdel(qp);
72         }
73         return (0);
74 }
75
76 /*
77  * tk_fmap --
78  *      Map a function key.
79  *
80  * PUBLIC: int tk_fmap __P((SCR *, seq_t, CHAR_T *, size_t, CHAR_T *, size_t));
81  */
82 int
83 tk_fmap(sp, stype, from, flen, to, tlen)
84         SCR *sp;
85         seq_t stype;
86         CHAR_T *from, *to;
87         size_t flen, tlen;
88 {
89         VI_INIT_IGNORE(sp);
90
91         /* Bind a Tk/Tcl function key to a string sequence. */
92         return (0);
93 }
94
95 /*
96  * tk_optchange --
97  *      Curses screen specific "option changed" routine.
98  *
99  * PUBLIC: int tk_optchange __P((SCR *, int, char *, u_long *));
100  */
101 int
102 tk_optchange(sp, opt, str, valp)
103         SCR *sp;
104         int opt;
105         char *str;
106         u_long *valp;
107 {
108         switch (opt) {
109         case O_COLUMNS:
110         case O_LINES:
111                 /*
112                  * Changing the columns or lines require that we restart
113                  * the screen.
114                  */
115                 F_SET(sp->gp, G_SRESTART);
116                 F_CLR(sp, SC_SCR_EX | SC_SCR_VI);
117                 break;
118         case O_TERM:
119                 msgq(sp, M_ERR, "The screen type may not be changed");
120                 return (1);
121         }
122         return (0);
123 }
124
125 /*
126  * tk_ssize --
127  *      Return the window size.
128  *
129  * PUBLIC: int tk_ssize __P((SCR *, int, size_t *, size_t *, int *));
130  */
131 int
132 tk_ssize(sp, sigwinch, rowp, colp, changedp)
133         SCR *sp;
134         int sigwinch;
135         size_t *rowp, *colp;
136         int *changedp;
137 {
138         TK_PRIVATE *tkp;
139
140         tkp = GTKP(__global_list);
141         (void)Tcl_Eval(tkp->interp, "tk_ssize");
142
143         /*
144          * SunOS systems deliver SIGWINCH when windows are uncovered
145          * as well as when they change size.  In addition, we call
146          * here when continuing after being suspended since the window
147          * may have changed size.  Since we don't want to background
148          * all of the screens just because the window was uncovered,
149          * ignore the signal if there's no change.
150          *
151          * !!!
152          * sp may be NULL.
153          */
154         if (sigwinch && sp != NULL &&
155             tkp->tk_ssize_row == O_VAL(sp, O_LINES) &&
156             tkp->tk_ssize_col == O_VAL(sp, O_COLUMNS)) {
157                 if (changedp != NULL)
158                         *changedp = 0;
159                 return (0);
160         }
161
162         if (rowp != NULL)
163                 *rowp = tkp->tk_ssize_row;
164         if (colp != NULL)
165                 *colp = tkp->tk_ssize_col;
166         if (changedp != NULL)
167                 *changedp = 1;
168         return (0);
169 }