X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=tclmain.c;h=33a34078a1f5a9a957bdc8d2fae36399f1609f1d;hb=aa30eee6a1b9d8b08982965c7235ba3b806e94b9;hp=70d0db1662a7124ecea6267e1751d4ef76700c15;hpb=b018d91ad37afe044cfb7a32874ea54bf4c4b7f2;p=ir-tcl-moved-to-github.git diff --git a/tclmain.c b/tclmain.c index 70d0db1..33a3407 100644 --- a/tclmain.c +++ b/tclmain.c @@ -1,8 +1,19 @@ /* * IR toolkit for tcl/tk * (c) Index Data 1995 + * See the file LICENSE for details. + * Sebastian Hammer, Adam Dickmeiss + * + * $Log: tclmain.c,v $ + * Revision 1.6 1995-05-29 08:44:28 adam + * Work on delete of objects. + * + * Revision 1.5 1995/03/20 08:53:30 adam + * Event loop in tclmain.c rewritten. New method searchStatus. + * + * Revision 1.4 1995/03/17 07:50:31 adam + * Headers have changed a little. * - * $Id: tclmain.c,v 1.2 1995-03-08 07:28:37 adam Exp $ */ #include @@ -16,9 +27,19 @@ static char *fileName = NULL; -static fd_set fdset_tcl; +/* select(2) callbacks */ +struct callback { + void (*r_handle)(void *p); + void (*w_handle)(void *p); + void (*x_handle)(void *p); + void *obj; +}; +#define MAX_CALLBACK 200 + +static struct callback callback_table[MAX_CALLBACK]; +static int max_fd = 3; /* don't worry: it will grow... */ -void tcl_mainloop (Tcl_Interp *interp); +void tcl_mainloop (Tcl_Interp *interp, int interactive); int Tcl_AppInit (Tcl_Interp *interp) { @@ -33,76 +54,113 @@ int main (int argc, char **argv) { Tcl_Interp *interp; int code; + int i; interp = Tcl_CreateInterp(); + Tcl_SetVar (interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); + if (argc == 2) + fileName = argv[1]; - if (argc != 2) + if (Tcl_AppInit(interp) != TCL_OK) { + fprintf(stderr, "Tcl_AppInit failed: %s\n", interp->result); + } + for (i=0; iresult != 0) + printf ("%s\n", interp->result); + if (code != TCL_OK) + exit (1); + tcl_mainloop (interp, 0); } - if (Tcl_AppInit(interp) != TCL_OK) { - fprintf(stderr, "Tcl_AppInit failed: %s\n", interp->result); + else + { + Tcl_SetVar (interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY); + tcl_mainloop (interp, 1); } - code = Tcl_EvalFile (interp, fileName); - if (*interp->result != 0) - printf ("%s\n", interp->result); - if (code != TCL_OK) - exit (1); - tcl_mainloop (interp); exit (0); } -struct callback { - void (*handle)(void *p); - void *obj; -}; - -#define MAX_CALLBACK 20 - -struct callback callback_table[MAX_CALLBACK]; - -void tcl_mainloop (Tcl_Interp *interp) +void tcl_mainloop (Tcl_Interp *interp, int interactive) { int i; int res; - int count; - char input_buf[256]; Tcl_DString command; + static fd_set fdset_tcl_r; + static fd_set fdset_tcl_w; + static fd_set fdset_tcl_x; + int min_fd; - for (i=0; iresult); + if (code) + printf ("[ERR:%s]\n", interp->result); + else + printf ("[RES:%s]\n", interp->result); printf ("[TCL]"); fflush (stdout); } } @@ -120,10 +181,28 @@ void tcl_mainloop (Tcl_Interp *interp) void ir_select_add (int fd, void *obj) { callback_table[fd].obj = obj; - callback_table[fd].handle = ir_select_proc; + callback_table[fd].r_handle = ir_select_read; + callback_table[fd].w_handle = NULL; + callback_table[fd].x_handle = NULL; + if (fd > max_fd) + max_fd = fd; +} + +void ir_select_add_write (int fd, void *obj) +{ + callback_table[fd].w_handle = ir_select_write; + if (fd > max_fd) + max_fd = fd; +} + +void ir_select_remove_write (int fd, void *obj) +{ + callback_table[fd].w_handle = NULL; } void ir_select_remove (int fd, void *obj) { - callback_table[fd].handle = NULL; + callback_table[fd].r_handle = NULL; + callback_table[fd].w_handle = NULL; + callback_table[fd].x_handle = NULL; }