2 * IR toolkit for tcl/tk
4 * See the file LICENSE for details.
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.6 1999-02-11 11:30:13 adam
11 * Revision 1.5 1997/09/09 10:19:55 adam
12 * New MSV5.0 port with fewer warnings.
14 * Revision 1.4 1997/08/28 20:20:48 adam
15 * Added support for Tk8.0/Tcl8.0. Since Tcl_File handlers are gone
16 * we've moved to Tcl_Channel handlers instead.
18 * Revision 1.3 1997/04/13 18:57:28 adam
19 * Better error reporting and aligned with Tcl/Tk style.
20 * Rework of notifier code with Tcl_File handles.
22 * Revision 1.2 1996/09/13 10:51:48 adam
23 * Bug fix: ir_tcl_select_set called Tcl_GetFile at disconnect.
25 * Revision 1.1 1996/08/20 09:33:23 adam
26 * Tcl7.5 Generic file handling.
34 #if TCL_MAJOR_VERSION == 8
36 void (*f)(ClientData clientData, int r, int w, int e);
37 ClientData clientData;
39 Tcl_Channel tcl_Channel;
40 struct sel_proc *next;
43 static struct sel_proc *sel_proc_list = NULL;
45 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
47 struct sel_proc *sp = (struct sel_proc *) clientData;
51 (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE,
52 mask & TCL_EXCEPTION);
55 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
56 int fd, ClientData clientData, int r, int w, int e)
59 struct sel_proc **sp = &sel_proc_list;
66 mask |= TCL_EXCEPTION;
73 logf (LOG_DEBUG, "r=%d w=%d e=%d sp=%p", r, w, e, *sp);
75 Tcl_DeleteChannelHandler ((*sp)->tcl_Channel, ir_tcl_tk_select_proc,
81 Tcl_Close (NULL, (*sp)->tcl_Channel);
88 *sp = ir_tcl_malloc (sizeof(**sp));
91 (*sp)->tcl_Channel = Tcl_MakeTcpClientChannel ((ClientData) fd);
94 (*sp)->clientData = clientData;
95 Tcl_CreateChannelHandler ((*sp)->tcl_Channel, mask,
96 ir_tcl_tk_select_proc,
101 #if (TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION > 4)
104 void (*f)(ClientData clientData, int r, int w, int e);
105 ClientData clientData;
108 struct sel_proc *next;
111 static struct sel_proc *sel_proc_list = NULL;
113 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
115 struct sel_proc *sp = (struct sel_proc *) clientData;
119 (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE,
120 mask & TCL_EXCEPTION);
123 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
124 int fd, ClientData clientData, int r, int w, int e)
127 struct sel_proc **sp = &sel_proc_list;
130 mask |= TCL_READABLE;
132 mask |= TCL_WRITABLE;
134 mask |= TCL_EXCEPTION;
141 logf (LOG_DEBUG, "r=%d w=%d e=%d sp=%p", r, w, e, *sp);
146 Tcl_DeleteFileHandler ((*sp)->tcl_File);
147 Tcl_FreeFile ((*sp)->tcl_File);
154 *sp = ir_tcl_malloc (sizeof(**sp));
158 (*sp)->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_WIN_SOCKET);
160 (*sp)->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_UNIX_FD);
164 (*sp)->clientData = clientData;
165 Tcl_CreateFileHandler ((*sp)->tcl_File, mask, ir_tcl_tk_select_proc, *sp);