2 * IR toolkit for tcl/tk
3 * (c) Index Data 1996-1999
4 * See the file LICENSE for details.
5 * Sebastian Hammer, Adam Dickmeiss
8 * Revision 1.7 1999-11-30 14:05:58 adam
9 * Updated for new location of YAZ headers.
11 * Revision 1.6 1999/02/11 11:30:13 adam
14 * Revision 1.5 1997/09/09 10:19:55 adam
15 * New MSV5.0 port with fewer warnings.
17 * Revision 1.4 1997/08/28 20:20:48 adam
18 * Added support for Tk8.0/Tcl8.0. Since Tcl_File handlers are gone
19 * we've moved to Tcl_Channel handlers instead.
21 * Revision 1.3 1997/04/13 18:57:28 adam
22 * Better error reporting and aligned with Tcl/Tk style.
23 * Rework of notifier code with Tcl_File handles.
25 * Revision 1.2 1996/09/13 10:51:48 adam
26 * Bug fix: ir_tcl_select_set called Tcl_GetFile at disconnect.
28 * Revision 1.1 1996/08/20 09:33:23 adam
29 * Tcl7.5 Generic file handling.
37 #if TCL_MAJOR_VERSION == 8
39 void (*f)(ClientData clientData, int r, int w, int e);
40 ClientData clientData;
42 Tcl_Channel tcl_Channel;
43 struct sel_proc *next;
46 static struct sel_proc *sel_proc_list = NULL;
48 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
50 struct sel_proc *sp = (struct sel_proc *) clientData;
54 (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE,
55 mask & TCL_EXCEPTION);
58 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
59 int fd, ClientData clientData, int r, int w, int e)
62 struct sel_proc **sp = &sel_proc_list;
69 mask |= TCL_EXCEPTION;
76 logf (LOG_DEBUG, "r=%d w=%d e=%d sp=%p", r, w, e, *sp);
78 Tcl_DeleteChannelHandler ((*sp)->tcl_Channel, ir_tcl_tk_select_proc,
84 Tcl_Close (NULL, (*sp)->tcl_Channel);
91 *sp = ir_tcl_malloc (sizeof(**sp));
94 (*sp)->tcl_Channel = Tcl_MakeTcpClientChannel ((ClientData) fd);
97 (*sp)->clientData = clientData;
98 Tcl_CreateChannelHandler ((*sp)->tcl_Channel, mask,
99 ir_tcl_tk_select_proc,
104 #if (TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION > 4)
107 void (*f)(ClientData clientData, int r, int w, int e);
108 ClientData clientData;
111 struct sel_proc *next;
114 static struct sel_proc *sel_proc_list = NULL;
116 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
118 struct sel_proc *sp = (struct sel_proc *) clientData;
122 (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE,
123 mask & TCL_EXCEPTION);
126 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
127 int fd, ClientData clientData, int r, int w, int e)
130 struct sel_proc **sp = &sel_proc_list;
133 mask |= TCL_READABLE;
135 mask |= TCL_WRITABLE;
137 mask |= TCL_EXCEPTION;
144 logf (LOG_DEBUG, "r=%d w=%d e=%d sp=%p", r, w, e, *sp);
149 Tcl_DeleteFileHandler ((*sp)->tcl_File);
150 Tcl_FreeFile ((*sp)->tcl_File);
157 *sp = ir_tcl_malloc (sizeof(**sp));
161 (*sp)->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_WIN_SOCKET);
163 (*sp)->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_UNIX_FD);
167 (*sp)->clientData = clientData;
168 Tcl_CreateFileHandler ((*sp)->tcl_File, mask, ir_tcl_tk_select_proc, *sp);