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