DEFINITIONS
This source file includes following functions.
- DL_OPEN
- ruby_tcltk_stubs
1 #if defined USE_TCL_STUBS && defined USE_TK_STUBS
2 #include <tcl.h>
3 #include <tk.h>
4 #include "ruby.h"
5
6 #if defined _WIN32 || defined __CYGWIN__
7 # include <windows.h>
8 typedef HINSTANCE DL_HANDLE;
9 # define DL_OPEN LoadLibrary
10 # define DL_SYM GetProcAddress
11 # define TCL_INDEX 4
12 # define TK_INDEX 3
13 # define TCL_NAME "tcl89%s"
14 # define TK_NAME "tk89%s"
15 # undef DLEXT
16 # define DLEXT ".dll"
17 #elif defined HAVE_DLOPEN
18 # include <dlfcn.h>
19 typedef void *DL_HANDLE;
20 # define DL_OPEN(file) dlopen(file, RTLD_LAZY|RTLD_GLOBAL)
21 # define DL_SYM dlsym
22 # define TCL_INDEX 8
23 # define TK_INDEX 7
24 # define TCL_NAME "libtcl8.9%s"
25 # define TK_NAME "libtk8.9%s"
26 #endif
27
28 int
29 ruby_tcltk_stubs()
30 {
31 DL_HANDLE tcl_dll;
32 DL_HANDLE tk_dll;
33 Tcl_Interp *(*p_Tcl_CreateInterp)();
34 int (*p_Tk_Init) _((Tcl_Interp *));
35 Tcl_Interp *tcl_ip;
36 int n;
37 char *ruby_tcl_dll;
38 char *ruby_tk_dll;
39 char tcl_name[20];
40 char tk_name[20];
41
42 ruby_tcl_dll = getenv("RUBY_TCL_DLL");
43 #if defined NT
44 if (ruby_tcl_dll) ruby_tcl_dll = ruby_strdup(ruby_tcl_dll);
45 #endif
46 ruby_tk_dll = getenv("RUBY_TK_DLL");
47 if (ruby_tcl_dll && ruby_tk_dll) {
48 tcl_dll = (DL_HANDLE)DL_OPEN(ruby_tcl_dll);
49 tk_dll = (DL_HANDLE)DL_OPEN(ruby_tk_dll);
50 #if defined NT
51 ruby_xfree(ruby_tcl_dll);
52 #endif
53 } else {
54 snprintf(tcl_name, sizeof tcl_name, TCL_NAME, DLEXT);
55 snprintf(tk_name, sizeof tk_name, TK_NAME, DLEXT);
56
57 for (n = '9'; n > '0'; n--) {
58 tcl_name[TCL_INDEX] = n;
59 tk_name[TK_INDEX] = n;
60 tcl_dll = (DL_HANDLE)DL_OPEN(tcl_name);
61 tk_dll = (DL_HANDLE)DL_OPEN(tk_name);
62 if (tcl_dll && tk_dll)
63 break;
64 }
65 }
66
67 if (!tcl_dll || !tk_dll)
68 return -1;
69
70 p_Tcl_CreateInterp = (Tcl_Interp *(*)())DL_SYM(tcl_dll, "Tcl_CreateInterp");
71 if (!p_Tcl_CreateInterp)
72 return -2;
73
74 tcl_ip = (*p_Tcl_CreateInterp)();
75 if (!tcl_ip)
76 return -3;
77
78 p_Tk_Init = (int (*) _((Tcl_Interp *)))DL_SYM(tk_dll, "Tk_Init");
79 if (!p_Tk_Init)
80 return -4;
81 (*p_Tk_Init)(tcl_ip);
82
83 if (!Tcl_InitStubs(tcl_ip, "8.1", 0))
84 return -5;
85 if (!Tk_InitStubs(tcl_ip, "8.1", 0))
86 return -6;
87
88 Tcl_DeleteInterp(tcl_ip);
89
90 return 0;
91 }
92 #endif