2 * IR toolkit for tcl/tk
4 * See the file LICENSE for details.
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.4 1997-08-28 20:20:48 adam
9 * Added support for Tk8.0/Tcl8.0. Since Tcl_File handlers are gone
10 * we've moved to Tcl_Channel handlers instead.
12 * Revision 1.3 1997/04/13 18:57:28 adam
13 * Better error reporting and aligned with Tcl/Tk style.
14 * Rework of notifier code with Tcl_File handles.
16 * Revision 1.2 1996/09/13 10:51:48 adam
17 * Bug fix: ir_tcl_select_set called Tcl_GetFile at disconnect.
19 * Revision 1.1 1996/08/20 09:33:23 adam
20 * Tcl7.5 Generic file handling.
28 #if TCL_MAJOR_VERSION == 8
30 void (*f)(ClientData clientData, int r, int w, int e);
31 ClientData clientData;
33 Tcl_Channel tcl_Channel;
34 struct sel_proc *next;
37 static struct sel_proc *sel_proc_list = NULL;
39 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
41 struct sel_proc *sp = (struct sel_proc *) clientData;
45 (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE,
46 mask & TCL_EXCEPTION);
49 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
50 int fd, ClientData clientData, int r, int w, int e)
53 struct sel_proc **sp = &sel_proc_list;
60 mask |= TCL_EXCEPTION;
67 logf (LOG_DEBUG, "r=%d w=%d e=%d sp=%p", r, w, e, *sp);
69 Tcl_DeleteChannelHandler ((*sp)->tcl_Channel, ir_tcl_tk_select_proc,
75 Tcl_Close (NULL, (*sp)->tcl_Channel);
82 *sp = ir_tcl_malloc (sizeof(**sp));
85 (*sp)->tcl_Channel = Tcl_MakeTcpClientChannel ((ClientData) fd);
88 (*sp)->clientData = clientData;
89 Tcl_CreateChannelHandler ((*sp)->tcl_Channel, mask,
90 ir_tcl_tk_select_proc, *sp);
94 #if (TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION > 4)
97 void (*f)(ClientData clientData, int r, int w, int e);
98 ClientData clientData;
101 struct sel_proc *next;
104 static struct sel_proc *sel_proc_list = NULL;
106 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
108 struct sel_proc *sp = (struct sel_proc *) clientData;
112 (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE,
113 mask & TCL_EXCEPTION);
116 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
117 int fd, ClientData clientData, int r, int w, int e)
120 struct sel_proc **sp = &sel_proc_list;
123 mask |= TCL_READABLE;
125 mask |= TCL_WRITABLE;
127 mask |= TCL_EXCEPTION;
134 logf (LOG_DEBUG, "r=%d w=%d e=%d sp=%p", r, w, e, *sp);
139 Tcl_DeleteFileHandler ((*sp)->tcl_File);
140 Tcl_FreeFile ((*sp)->tcl_File);
147 *sp = ir_tcl_malloc (sizeof(**sp));
151 (*sp)->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_WIN_SOCKET);
153 (*sp)->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_UNIX_FD);
157 (*sp)->clientData = clientData;
158 Tcl_CreateFileHandler ((*sp)->tcl_File, mask, ir_tcl_tk_select_proc, *sp);