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.
13 static const char sccsid
[] = "@(#)tk_read.c 8.12 (Berkeley) 9/24/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
29 #include "../common/common.h"
30 #include "../ex/script.h"
33 static input_t tk_read
__P((SCR
*, int));
34 static int tk_resize
__P((SCR
*, size_t, size_t));
39 * Return a single event.
41 * PUBLIC: int tk_event __P((SCR *, EVENT *, u_int32_t, int));
44 tk_event(sp
, evp
, flags
, timeout
)
52 size_t lines
, columns
;
56 * Queue signal based events. We never clear SIGHUP or SIGTERM events,
57 * so that we just keep returning them until the editor dies.
60 sig
: if (LF_ISSET(EC_INTERRUPT
) || F_ISSET(tkp
, TK_SIGINT
)) {
61 if (F_ISSET(tkp
, TK_SIGINT
)) {
62 F_CLR(tkp
, TK_SIGINT
);
63 evp
->e_event
= E_INTERRUPT
;
65 evp
->e_event
= E_TIMEOUT
;
68 if (F_ISSET(tkp
, TK_SIGHUP
| TK_SIGTERM
| TK_SIGWINCH
)) {
69 if (F_ISSET(tkp
, TK_SIGHUP
)) {
70 evp
->e_event
= E_SIGHUP
;
73 if (F_ISSET(tkp
, TK_SIGTERM
)) {
74 evp
->e_event
= E_SIGTERM
;
77 if (F_ISSET(tkp
, TK_SIGWINCH
)) {
78 F_CLR(tkp
, TK_SIGWINCH
);
79 (void)tk_ssize(sp
, 1, &lines
, &columns
, &changed
);
81 (void)tk_resize(sp
, lines
, columns
);
82 evp
->e_event
= E_WRESIZE
;
85 /* No change, so ignore the signal. */
89 /* Queue special ops. */
90 ops
: if ((tevp
= tkp
->evq
.tqh_first
) != NULL
) {
92 TAILQ_REMOVE(&tkp
->evq
, tevp
, q
);
97 /* Read input characters. */
98 switch (tk_read(sp
, timeout
)) {
100 evp
->e_csp
= tkp
->ibuf
;
101 evp
->e_len
= tkp
->ibuf_cnt
;
102 evp
->e_event
= E_STRING
;
106 evp
->e_event
= E_EOF
;
109 evp
->e_event
= E_ERR
;
115 /* May have returned because queued a special op. */
116 if (tkp
->evq
.tqh_first
!= NULL
)
119 /* Otherwise, we timed out. */
120 evp
->e_event
= E_TIMEOUT
;
130 * Read characters from the input.
141 * Check scripting window file descriptors. It's ugly that we wait
142 * on scripting file descriptors here, but it's the only way to keep
143 * from locking out scripting windows.
145 if (F_ISSET(sp
->gp
, G_SCRWIN
) && sscr_input(sp
))
148 /* Read characters. */
150 (void)snprintf(buf
, sizeof(buf
), "%d", timeout
);
151 (void)Tcl_VarEval(tkp
->interp
, "tk_key_wait ", buf
, NULL
);
153 return (tkp
->ibuf_cnt
== 0 ? INP_TIMEOUT
: INP_OK
);
158 * Receive an input key.
160 * PUBLIC: int tk_key __P((ClientData, Tcl_Interp *, int, char *[]));
163 tk_key(clientData
, interp
, argc
, argv
)
164 ClientData clientData
;
172 tkp
= (TK_PRIVATE
*)clientData
;
174 tkp
->ibuf
+ tkp
->ibuf_cnt
, t
= argv
[1]; (*p
++ = *t
++) != '\0';
181 * Reset the options for a resize event.
184 tk_resize(sp
, lines
, columns
)
186 size_t lines
, columns
;
198 (void)snprintf(b1
, sizeof(b1
), "lines=%lu", (u_long
)lines
);
200 if (opts_set(sp
, argv
, NULL
))
202 (void)snprintf(b1
, sizeof(b1
), "columns=%lu", (u_long
)columns
);
204 if (opts_set(sp
, argv
, NULL
))