changeset 7831:409f7f167c98

[gaim-migrate @ 8483] Using tcl and tk stubs for Windows tcl loader committer: Tailor Script <tailor@pidgin.im>
author Herman Bloggs <hermanator12002@yahoo.com>
date Thu, 11 Dec 2003 19:06:28 +0000
parents d26a33b16335
children 14b7a43dd18d
files plugins/tcl/.cvsignore plugins/tcl/Makefile.mingw plugins/tcl/tcl.c plugins/tcl/tcl_glib.c plugins/tcl/tcl_win32.c
diffstat 5 files changed, 240 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/tcl/.cvsignore	Thu Dec 11 12:07:02 2003 +0000
+++ b/plugins/tcl/.cvsignore	Thu Dec 11 19:06:28 2003 +0000
@@ -5,3 +5,4 @@
 .deps
 .libs
 *.lo
+*.dll
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/tcl/Makefile.mingw	Thu Dec 11 19:06:28 2003 +0000
@@ -0,0 +1,132 @@
+#
+# Makefile.mingw
+#
+# Description: Makefile for tcl plugin loader plugin.
+#
+
+#
+# PATHS
+#
+
+GTK_TOP :=		../../../win32-dev/gtk_2_0
+GAIM_TOP :=		../..
+TCL_LIB_DIR :=		../../../win32-dev/tcl-8.4.5
+TCL_INC_DIR :=		$(TCL_LIB_DIR)/include
+GAIM_INSTALL_DIR :=	$(GAIM_TOP)/win32-install-dir
+DLL_INSTALL_DIR :=	$(GAIM_INSTALL_DIR)/plugins
+
+##
+## VARIABLE DEFINITIONS
+##
+
+TARGET = tcl
+
+CC = gcc.exe
+
+# Compiler Options
+
+CFLAGS =
+
+DEFINES = -DHAVE_TK -DUSE_TCL_STUBS -DUSE_TK_STUBS
+
+##
+## INCLUDE  MAKEFILES
+##
+
+include $(GAIM_TOP)/src/win32/global.mak
+
+##
+## INCLUDE PATHS
+##
+
+INCLUDE_PATHS +=	-I. \
+			-I$(GAIM_TOP) \
+			-I$(GAIM_TOP)/src \
+			-I$(GAIM_TOP)/src/win32 \
+			-I$(GTK_TOP)/include \
+			-I$(GTK_TOP)/include/gtk-2.0 \
+			-I$(GTK_TOP)/include/glib-2.0 \
+			-I$(GTK_TOP)/include/pango-1.0 \
+			-I$(GTK_TOP)/include/atk-1.0 \
+			-I$(GTK_TOP)/lib/glib-2.0/include \
+			-I$(GTK_TOP)/lib/gtk-2.0/include \
+			-I$(TCL_INC_DIR)
+
+
+LIB_PATHS =		-L$(GTK_TOP)/lib \
+			-L$(GAIM_TOP)/src \
+			-L$(TCL_LIB_DIR)
+
+
+##
+##  SOURCES, OBJECTS
+##
+
+C_SRC =			tcl.c \
+			tcl_cmds.c \
+			tcl_glib.c \
+			tcl_signals.c \
+			tcl_win32.c
+
+
+OBJECTS = $(C_SRC:%.c=%.o)
+
+
+##
+## LIBRARIES
+##
+
+LIBS =			-lgtk-win32-2.0 \
+			-lglib-2.0 \
+			-lgdk-win32-2.0 \
+			-lgmodule-2.0 \
+			-lgobject-2.0 \
+			-lws2_32 \
+			-lintl \
+			-lgaim \
+			-ltclstub84 \
+			-ltkstub84
+
+
+##
+## RULES
+##
+
+# How to make a C file
+
+%.o: %.c
+	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDE_PATHS) -o $@ -c $<
+
+##
+## TARGET DEFINITIONS
+##
+
+.PHONY: all clean
+
+all: $(TARGET).dll
+
+install: $(TARGET).dll
+	cp $(TARGET).dll $(DLL_INSTALL_DIR)
+
+##
+## BUILD Dependencies
+##
+
+$(GAIM_TOP)/src/gaim.lib:
+	$(MAKE) -C $(GAIM_TOP)/src -f Makefile.mingw gaim.lib
+
+##
+## BUILD DLL
+##
+
+$(TARGET).dll: $(OBJECTS) $(GAIM_TOP)/src/gaim.lib
+	$(CC) -shared $(OBJECTS) $(LIB_PATHS) $(LIBS) $(DLL_LD_FLAGS) -o $(TARGET).dll
+
+
+##
+## CLEAN RULES
+##
+
+clean:
+	rm -rf *.o
+	rm -rf $(TARGET).dll
--- a/plugins/tcl/tcl.c	Thu Dec 11 12:07:02 2003 +0000
+++ b/plugins/tcl/tcl.c	Thu Dec 11 19:06:28 2003 +0000
@@ -53,6 +53,8 @@
 
 GaimPlugin *_tcl_plugin;
 
+static gboolean tcl_loaded = FALSE;
+
 GaimPlugin *tcl_interp_get_plugin(Tcl_Interp *interp)
 {
 	struct tcl_plugin_data *data;
@@ -304,6 +306,8 @@
 
 static gboolean tcl_load(GaimPlugin *plugin)
 {
+        if(!tcl_loaded)
+                return FALSE;
 	tcl_glib_init();
 	tcl_signal_init();
 	tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -354,12 +358,47 @@
 	&tcl_loader_info
 };
 
+#ifdef _WIN32
+extern Tcl_Interp* (CALLBACK* wtcl_CreateInterp)();
+extern void (CALLBACK* wtk_Init)(Tcl_Interp*);
+#undef Tcl_CreateInterp
+#define Tcl_CreateInterp wtcl_CreateInterp
+#undef Tk_Init
+#define Tk_Init wtk_Init
+#endif /* _WIN32 */
+
 static void tcl_init_plugin(GaimPlugin *plugin)
 {
+#ifdef USE_TCL_STUBS
+        Tcl_Interp *interp=NULL;
+#endif
 	_tcl_plugin = plugin;
 
+#ifdef USE_TCL_STUBS
+        if(!(interp=Tcl_CreateInterp()))
+                return;
+
+        if(!Tcl_InitStubs(interp, TCL_VERSION, 0)) {
+                gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Tcl_InitStubs: %s\n", interp->result);
+                return;
+        }
+#endif
+
 	Tcl_FindExecutable("gaim");
 
+#if defined(USE_TK_STUBS) && defined(HAVE_TK)
+        Tk_Init(interp);
+
+        if(!Tk_InitStubs(interp, TK_VERSION, 0)) {
+                gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Error Tk_InitStubs: %s\n", interp->result);
+                Tcl_DeleteInterp(interp);
+                return;
+        }
+#endif
+        tcl_loaded = TRUE;
+#ifdef USE_TCL_STUBS
+        Tcl_DeleteInterp(interp);
+#endif
 	tcl_loader_info.exts = g_list_append(tcl_loader_info.exts, "tcl");
 }
 
--- a/plugins/tcl/tcl_glib.c	Thu Dec 11 12:07:02 2003 +0000
+++ b/plugins/tcl/tcl_glib.c	Thu Dec 11 19:06:28 2003 +0000
@@ -70,6 +70,8 @@
 static gboolean tcl_file_callback(GIOChannel *source, GIOCondition condition, gpointer data);
 static int tcl_file_event_callback(Tcl_Event *event, int flags);
 
+#undef Tcl_InitNotifier
+
 ClientData Tcl_InitNotifier()
 {
 	return NULL;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/tcl/tcl_win32.c	Thu Dec 11 19:06:28 2003 +0000
@@ -0,0 +1,66 @@
+/**
+ * @file tcl_win32.c Gaim Tcl Windows Init
+ *
+ * gaim
+ *
+ * Copyright (C) 2003 Herman Bloggs <hermanator12002@yahoo.com>
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include "internal.h"
+#include "debug.h"
+#include <tcl.h>
+
+#ifdef HAVE_TK
+#include <tk.h>
+#endif
+
+typedef Tcl_Interp* (CALLBACK* LPFNTCLCREATEINTERP)();
+typedef void        (CALLBACK* LPFNTKINIT)(Tcl_Interp*);
+
+LPFNTCLCREATEINTERP wtcl_CreateInterp = NULL;
+LPFNTKINIT wtk_Init = NULL;
+
+BOOL tcl_win32_init() {
+        if(!(wtcl_CreateInterp=(LPFNTCLCREATEINTERP)wgaim_find_and_loadproc("tcl84.dll", "Tcl_CreateInterp"))) {
+                gaim_debug(GAIM_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tcl_CreateInterp\n");
+                return FALSE;
+        }
+
+        if(!(wtk_Init=(LPFNTKINIT)wgaim_find_and_loadproc("tk84.dll", "Tk_Init"))) {
+                gaim_debug(GAIM_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tk_Init\n");
+                return FALSE;
+        }
+        return TRUE;
+}
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
+        switch( fdwReason ) { 
+        case DLL_PROCESS_ATTACH:
+                return tcl_win32_init();
+
+        case DLL_THREAD_ATTACH:
+                break;
+
+        case DLL_THREAD_DETACH:
+                break;
+
+        case DLL_PROCESS_DETACH:
+                break;
+    }
+    return TRUE;
+}
+
+