Workspace update.
[ir-tcl-moved-to-github.git] / tkmain.c
1 /*
2  * IR toolkit for tcl/tk
3  * (c) Index Data 1995-1996
4  * See the file LICENSE for details.
5  * Sebastian Hammer, Adam Dickmeiss
6  *
7  * $Log: tkmain.c,v $
8  * Revision 1.1  1996-08-20 09:27:49  adam
9  * More work on explain.
10  * Renamed tkinit.c to tkmain.c. The tcl shell uses the Tcl 7.5 interface
11  * for socket i/o instead of the handcrafted one (for Tcl 7.3 and Tcl7.4).
12  *
13  */
14
15 #include <tk.h>
16 #include <log.h>
17 #include "ir-tcl.h"
18
19 /* socket layer code for tk3.x and tk4.0 */
20 #if TK_MAJOR_VERSION < 4 || (TK_MAJOR_VERSION == 4 && TK_MINOR_VERSION == 0)
21
22 struct sel_proc {
23     void (*f)(ClientData clientData, int r, int w, int e);
24     ClientData clientData;
25     int fd;
26     struct sel_proc *next;
27 };
28
29 static struct sel_proc *sel_proc_list = NULL;
30
31 static void ir_tcl_tk_select_proc (ClientData clientData, int mask)
32 {
33     struct sel_proc *sp = (struct sel_proc *) clientData;
34
35     if (!sp->f)
36         return ;
37     (*sp->f)(sp->clientData, mask & TK_READABLE, mask & TK_WRITABLE,
38              mask & TK_EXCEPTION);
39 }
40
41 void ir_tcl_select_set (void (*f)(ClientData clientData, int r, int w, int e),
42                         int fd, ClientData clientData, int r, int w, int e)
43 {
44     int mask = 0;
45     struct sel_proc *sp = sel_proc_list;
46
47     if (r)
48         mask |= TK_READABLE;
49     if (w)
50         mask |= TK_WRITABLE;
51     if (e)
52         mask |= TK_EXCEPTION;
53     while (sp)
54     {
55         if (sp->fd == fd)
56              break;
57         sp = sp->next;
58     }
59     if (!sp)
60     {
61         sp = ir_tcl_malloc (sizeof(*sp));
62         sp->next = sel_proc_list;
63         sel_proc_list = sp;
64         sp->fd = fd;
65     }
66     sp->f = f;
67     sp->clientData = clientData;
68     if (f)
69         Tk_CreateFileHandler (fd, mask, ir_tcl_tk_select_proc, sp);
70     else
71         Tk_DeleteFileHandler (fd);
72 }
73 #endif
74
75 #if TK_MAJOR_VERSION >= 4
76
77 extern int matherr ();
78 int *tclDummyMathPtr = (int*) matherr;
79
80 int main (int argc, char **argv)
81 {
82     Tk_Main (argc, argv, Tcl_AppInit);
83     return 0;
84 }
85
86 #else
87
88 extern int main ();
89 int *tclDummyMainPtr = (int*) main;
90
91 #endif
92
93 int Tcl_AppInit (Tcl_Interp *interp)
94 {
95 #if TK_MAJOR_VERSION < 4 
96     Tk_Window mainw;
97
98     if (!(mainw = Tk_MainWindow(interp)))
99         return TCL_ERROR;
100 #endif
101     if (Tcl_Init(interp) == TCL_ERROR)
102         return TCL_ERROR;
103     if (Tk_Init(interp) == TCL_ERROR)
104         return TCL_ERROR;
105     if (Irtcl_Init(interp) == TCL_ERROR)
106         return TCL_ERROR;
107     return TCL_OK;
108 }