2 * IR toolkit for tcl/tk
4 * See the file LICENSE for details.
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.5 1997-09-09 10:19:55 adam
9 * New MSV5.0 port with fewer warnings.
11 * Revision 1.4 1997/08/28 20:20:48 adam
12 * Added support for Tk8.0/Tcl8.0. Since Tcl_File handlers are gone
13 * we've moved to Tcl_Channel handlers instead.
15 * Revision 1.3 1997/04/13 18:57:28 adam
16 * Better error reporting and aligned with Tcl/Tk style.
17 * Rework of notifier code with Tcl_File handles.
19 * Revision 1.2 1996/09/13 10:51:48 adam
20 * Bug fix: ir_tcl_select_set called Tcl_GetFile at disconnect.
22 * Revision 1.1 1996/08/20 09:33:23 adam
23 * Tcl7.5 Generic file handling.
31 #if TCL_MAJOR_VERSION == 8
33 void (*f)(ClientData clientData, int r, int w, int e);
34 ClientData clientData;
36 Tcl_Channel tcl_Channel;
37 struct sel_proc *next;
40 static struct sel_proc *sel_proc_list = NULL;
42 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
44 struct sel_proc *sp = (struct sel_proc *) clientData;
48 (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE,
49 mask & TCL_EXCEPTION);
52 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
53 int fd, ClientData clientData, int r, int w, int e)
56 struct sel_proc **sp = &sel_proc_list;
63 mask |= TCL_EXCEPTION;
70 logf (LOG_DEBUG, "r=%d w=%d e=%d sp=%p", r, w, e, *sp);
72 Tcl_DeleteChannelHandler ((*sp)->tcl_Channel, ir_tcl_tk_select_proc,
78 Tcl_Close (NULL, (*sp)->tcl_Channel);
85 *sp = ir_tcl_malloc (sizeof(**sp));
88 (*sp)->tcl_Channel = Tcl_MakeTcpClientChannel ((ClientData) fd);
91 (*sp)->clientData = clientData;
92 Tcl_CreateChannelHandler ((*sp)->tcl_Channel, mask,
93 ir_tcl_tk_select_proc,
98 #if (TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION > 4)
101 void (*f)(ClientData clientData, int r, int w, int e);
102 ClientData clientData;
105 struct sel_proc *next;
108 static struct sel_proc *sel_proc_list = NULL;
110 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
112 struct sel_proc *sp = (struct sel_proc *) clientData;
116 (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE,
117 mask & TCL_EXCEPTION);
120 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
121 int fd, ClientData clientData, int r, int w, int e)
124 struct sel_proc **sp = &sel_proc_list;
127 mask |= TCL_READABLE;
129 mask |= TCL_WRITABLE;
131 mask |= TCL_EXCEPTION;
138 logf (LOG_DEBUG, "r=%d w=%d e=%d sp=%p", r, w, e, *sp);
143 Tcl_DeleteFileHandler ((*sp)->tcl_File);
144 Tcl_FreeFile ((*sp)->tcl_File);
151 *sp = ir_tcl_malloc (sizeof(**sp));
155 (*sp)->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_WIN_SOCKET);
157 (*sp)->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_UNIX_FD);
161 (*sp)->clientData = clientData;
162 Tcl_CreateFileHandler ((*sp)->tcl_File, mask, ir_tcl_tk_select_proc, *sp);