From 1f5d222e3f2243f335e7c45f4c1a2529297ddb6c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 20 Aug 1996 09:33:23 +0000 Subject: [PATCH] Tcl7.5 Generic file handling. --- Makefile.in | 4 +- select.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 select.c diff --git a/Makefile.in b/Makefile.in index 76960de..05b4698 100644 --- a/Makefile.in +++ b/Makefile.in @@ -2,7 +2,7 @@ # (c) Index Data 1995-1996 # See the file LICENSE for details. # Sebastian Hammer, Adam Dickmeiss -# $Id: Makefile.in,v 1.40 1996-08-20 09:27:48 adam Exp $ +# $Id: Makefile.in,v 1.41 1996-08-20 09:33:23 adam Exp $ SHELL=/bin/sh # IrTcl Version @@ -53,7 +53,7 @@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ RANLIB = @RANLIB@ -O=ir-tcl.o marc.o queue.o mem.o grs.o explain.o events.o +O=ir-tcl.o marc.o queue.o mem.o grs.o explain.o select.o all: ir-tcl ir-tk diff --git a/select.c b/select.c new file mode 100644 index 0000000..93f2012 --- /dev/null +++ b/select.c @@ -0,0 +1,138 @@ +/* + * IR toolkit for tcl/tk + * (c) Index Data 1996 + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: select.c,v $ + * Revision 1.1 1996-08-20 09:33:23 adam + * Tcl7.5 Generic file handling. + * + */ + +#include +#include +#include "ir-tcl.h" + +#if TCL_MAJOR_VERSION > 7 || (TCL_MAJOR_VERSION == 7 && TCL_MINOR_VERSION > 4) + +#define IRTCL_USE_TIMER 0 + +struct sel_proc { + void (*f)(ClientData clientData, int r, int w, int e); + ClientData clientData; + int fd; +#if IRTCL_USE_TIMER + int mask; + Tcl_TimerToken timer_token; +#else + Tcl_File tcl_File; +#endif + struct sel_proc *next; +}; + +static struct sel_proc *sel_proc_list = NULL; + +#if IRTCL_USE_TIMER +static void ir_tcl_timer_proc (ClientData clientData) +{ + struct sel_proc *sp = (struct sel_proc *) clientData; + + if (!sp->f) + return ; + sp->timer_token = + Tcl_CreateTimerHandler (250, ir_tcl_timer_proc, clientData); + (*sp->f)(sp->clientData, sp->mask & TCL_READABLE, sp->mask & TCL_WRITABLE, + sp->mask & TCL_EXCEPTION); + +} + +void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e), + int fd, ClientData clientData, int r, int w, int e) +{ + int mask = 0; + struct sel_proc **sp = &sel_proc_list; + + if (r) + mask |= TCL_READABLE; + if (w) + mask |= TCL_WRITABLE; + if (e) + mask |= TCL_EXCEPTION; + while (*sp) + { + if ((*sp)->fd == fd) + break; + sp = &(*sp)->next; + } + if (!*sp) + { + *sp = ir_tcl_malloc (sizeof(**sp)); + (*sp)->next = NULL; + (*sp)->fd = fd; + (*sp)->timer_token = + Tcl_CreateTimerHandler (250, ir_tcl_timer_proc, *sp); + } + (*sp)->mask = TCL_READABLE|TCL_WRITABLE; + (*sp)->f = f; + (*sp)->clientData = clientData; + if (!f) + { + struct sel_proc *sp_tmp = *sp; + Tcl_DeleteTimerHandler ((*sp)->timer_token); + *sp = (*sp)->next; + xfree (sp_tmp); + } +} + +#else +static void ir_tcl_tk_select_proc (ClientData clientData, int mask) +{ + struct sel_proc *sp = (struct sel_proc *) clientData; + + if (!sp->f) + return ; + (*sp->f)(sp->clientData, mask & TCL_READABLE, mask & TCL_WRITABLE, + mask & TCL_EXCEPTION); +} + +void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e), + int fd, ClientData clientData, int r, int w, int e) +{ + int mask = 0; + struct sel_proc *sp = sel_proc_list; + + if (r) + mask |= TCL_READABLE; + if (w) + mask |= TCL_WRITABLE; + if (e) + mask |= TCL_EXCEPTION; + while (sp) + { + if (sp->fd == fd) + break; + sp = sp->next; + } + if (!sp) + { + sp = ir_tcl_malloc (sizeof(*sp)); + sp->next = sel_proc_list; + sel_proc_list = sp; + sp->fd = fd; +#if WINDOWS + sp->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_WIN_SOCKET); +#else + sp->tcl_File = Tcl_GetFile ((ClientData) fd, TCL_UNIX_FD); +#endif + } + sp->f = f; + sp->clientData = clientData; + if (f) + Tcl_CreateFileHandler (sp->tcl_File, mask, ir_tcl_tk_select_proc, sp); + else + Tcl_DeleteFileHandler (sp->tcl_File); +} +#endif + +#endif -- 1.7.10.4