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_util.c 8.14 (Berkeley) 7/19/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
29 #include "../common/common.h"
32 static int tk_op_push __P((SCR *, TK_PRIVATE *, e_event_t));
36 * Events provided directly from Tcl/Tk.
38 * PUBLIC: int tk_op __P((ClientData, Tcl_Interp *, int, char *[]));
41 tk_op(clientData, interp, argc, argv)
42 ClientData clientData;
50 sp = __global_list->dq.cqh_first; /* XXX */
51 tkp = (TK_PRIVATE *)clientData;
55 if (!strcmp(argv[1], "quit"))
56 return (tk_op_push(sp, tkp, E_QUIT));
59 if (!strcmp(argv[1], "write"))
60 return (tk_op_push(sp, tkp, E_WRITE));
61 if (!strcmp(argv[1], "writequit")) {
62 if (tk_op_push(sp, tkp, E_WRITE) != TCL_OK)
64 if (tk_op_push(sp, tkp, E_QUIT) != TCL_OK)
70 (void)Tcl_VarEval(tkp->interp,
71 "tk_err {", argv[1], ": unknown event", "}", NULL);
80 tk_op_push(sp, tkp, et)
87 CALLOC(sp, evp, EVENT *, 1, sizeof(EVENT));
92 TAILQ_INSERT_TAIL(&tkp->evq, evp, q);
98 * Initialize the values of the current options.
100 * PUBLIC: int tk_opt_init __P((ClientData, Tcl_Interp *, int, char *[]));
103 tk_opt_init(clientData, interp, argc, argv)
104 ClientData clientData;
115 sp = __global_list->dq.cqh_first; /* XXX */
117 tkp = (TK_PRIVATE *)clientData;
118 for (op = optlist, off = 0; op->name != NULL; ++op, ++off) {
119 if (F_ISSET(op, OPT_NDISP))
124 (void)Tcl_VarEval(tkp->interp, "set tko_",
125 op->name, O_ISSET(sp, off) ? " 1" : " 0", NULL);
129 sizeof(buf), " %lu", O_VAL(sp, off));
130 (void)Tcl_VarEval(tkp->interp,
131 "set tko_", op->name, buf, NULL);
134 (void)Tcl_VarEval(tkp->interp,
135 "set tko_", op->name, " {",
136 O_STR(sp, off) == NULL ? "" : O_STR(sp, off),
146 * Set an options button.
148 * PUBLIC: int tk_opt_set __P((ClientData, Tcl_Interp *, int, char *[]));
151 tk_opt_set(clientData, interp, argc, argv)
152 ClientData clientData;
161 void (*msg) __P((SCR *, mtype_t, char *, size_t));
165 sp = gp->dq.cqh_first; /* XXX */
169 a.bp = argv[1] + (sizeof("tko_") - 1);
170 a.len = strlen(a.bp);
174 a.len = snprintf(buf, sizeof(buf),
175 "%s%s", atoi(argv[2]) ? "no" : "", argv[1]);
185 /* Use Tcl/Tk for error messages. */
187 gp->scr_msg = tk_msg;
189 rval = opts_set(sp, ap, NULL);
192 return (rval ? TCL_ERROR : TCL_OK);
197 * Display the version in Tcl/Tk.
199 * PUBLIC: int tk_version __P((ClientData, Tcl_Interp *, int, char *[]));
202 tk_version(clientData, interp, argc, argv)
203 ClientData clientData;
212 void (*msg) __P((SCR *, mtype_t, char *, size_t));
215 sp = gp->dq.cqh_first; /* XXX */
218 gp->scr_msg = tk_msg;
220 ex_cinit(&cmd, C_VERSION, 0, OOBLNO, OOBLNO, 0, NULL);
221 rval = cmd.cmd->fn(sp, &cmd);
225 return (rval ? TCL_ERROR : TCL_OK);
230 * Display an error message in Tcl/Tk.
232 * PUBLIC: void tk_msg __P((SCR *, mtype_t, char *, size_t));
235 tk_msg(sp, mtype, line, rlen)
248 (void)snprintf(buf, sizeof(buf), "%.*s", (int)rlen, line);
249 (void)Tcl_VarEval(tkp->interp, "tk_err {", buf, "}", NULL);