2 * IR toolkit for tcl/tk
6 * Revision 1.4 1995-03-17 07:50:31 adam
7 * Headers have changed a little.
12 #include <sys/types.h>
20 static char *fileName = NULL;
22 static fd_set fdset_tcl;
24 void tcl_mainloop (Tcl_Interp *interp);
26 int Tcl_AppInit (Tcl_Interp *interp)
28 if (Tcl_Init(interp) == TCL_ERROR)
30 if (ir_tcl_init(interp) == TCL_ERROR)
35 int main (int argc, char **argv)
40 interp = Tcl_CreateInterp();
41 Tcl_SetVar (interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
45 if (Tcl_AppInit(interp) != TCL_OK) {
46 fprintf(stderr, "Tcl_AppInit failed: %s\n", interp->result);
50 code = Tcl_EvalFile (interp, fileName);
51 if (*interp->result != 0)
52 printf ("%s\n", interp->result);
56 Tcl_SetVar (interp, "tcl_interactive", "1", TCL_GLOBAL_ONLY);
57 tcl_mainloop (interp);
62 void (*handle)(void *p);
66 #define MAX_CALLBACK 20
68 struct callback callback_table[MAX_CALLBACK];
70 void tcl_mainloop (Tcl_Interp *interp)
78 for (i=0; i<MAX_CALLBACK; i++)
79 callback_table[i].handle = NULL;
80 Tcl_DStringInit (&command);
81 printf ("[TCL]"); fflush (stdout);
85 FD_SET (0, &fdset_tcl);
86 for (i=3; i<MAX_CALLBACK; i++)
87 if (callback_table[i].handle)
88 FD_SET (i, &fdset_tcl);
89 if ((res = select(MAX_CALLBACK+1, &fdset_tcl, 0, 0, 0)) < 0)
96 for (i=3; i<MAX_CALLBACK; i++)
97 if (FD_ISSET (i, &fdset_tcl))
99 assert (callback_table[i].handle);
100 (*callback_table[i].handle) (callback_table[i].obj);
102 if (FD_ISSET(0, &fdset_tcl))
104 count = read (0, input_buf, 256);
107 Tcl_DStringAppend (&command, input_buf, count);
108 if (Tcl_CommandComplete (Tcl_DStringValue (&command)))
110 int code = Tcl_Eval (interp, Tcl_DStringValue (&command));
111 Tcl_DStringFree (&command);
113 printf ("[ERR:%s]\n", interp->result);
115 printf ("[RES:%s]\n", interp->result);
116 printf ("[TCL]"); fflush (stdout);
122 void ir_select_add (int fd, void *obj)
124 callback_table[fd].obj = obj;
125 callback_table[fd].handle = ir_select_proc;
128 void ir_select_remove (int fd, void *obj)
130 callback_table[fd].handle = NULL;