/* exp_tk.c - Tk event interface for Expect Written by: Don Libes, NIST, 2/6/90 Design and implementation of this program was paid for by U.S. tax dollars. Therefore it is public domain. However, the author and NIST would appreciate credit if this program or parts of it are used. */ /* Notes: I'm only a little worried because Tk does not check for errno == EBADF after calling select. I imagine that if the user passes in a bad file descriptor, we'll never get called back, and thus, we'll hang forever - it would be better to at least issue a diagnostic to the user. Another possible problem: Tk does not do file callbacks round-robin. Another possible problem: Calling Create/DeleteFileHandler before/after every Tcl_Eval... in expect/interact could be very expensive. */ #include "exp_conf.h" #include #include #ifdef HAVE_PTYTRAP # include #endif #include "tk.h" #include "exp_global.h" #include "exp_command.h" /* for struct f defs */ #include "exp_event.h" /* Tk_DoOneEvent will call our filehandler which will set the following vars */ /* enabling us to know where and what kind of I/O we can do */ /*#define EXP_SPAWN_ID_BAD -1*/ /*#define EXP_SPAWN_ID_TIMEOUT -2*/ /* really indicates a timeout */ static int ready_fd = EXP_SPAWN_ID_BAD; static int ready_mask; static int default_mask = TK_READABLE | TK_EXCEPTION; #if 0 #ifdef HAVE_PTYTRAP static int default_mask = TK_READABLE | TK_EXCEPTION; #else static int default_mask = TK_READABLE; #endif #endif void exp_filehandler(clientData,mask) ClientData clientData; int mask; { if (ready_fd == (int)clientData) { Tk_DeleteFileHandler(ready_fd); fs[ready_fd].armed = FALSE; } else { ready_fd = (int)clientData; ready_mask = mask; } } /*ARGSUSED*/ void exp_timehandler(clientData) ClientData clientData; { /* clientData == &timer_fired */ *(int *)clientData = TRUE; /* old implementation */ /* ready_fd = EXP_SPAWN_ID_TIMEOUT; */ } #if 0 void exp_disarm_event_handler(count,fds) int count; int *fds; { int i; for (i=0;i= n) rr = 0; m = masters[rr]; f = fs + m; if (f->key != key) { f->key = key; f->force_read = FALSE; *master_out = m; return(EXP_DATA_OLD); } else if ((!f->force_read) && (f->size != 0)) { *master_out = m; return(EXP_DATA_OLD); } } if (!timer_created) { if (timeout >= 0) { timetoken = Tk_CreateTimerHandler(1000*timeout, exp_timehandler, (ClientData)&timer_fired); timer_created = TRUE; } } for (;;) { extern int fd_max; int j; /* make sure that all fds that should be armed are */ for (j=0;j