annotate plugins/tcl/tcl.c @ 14177:cdc1850eb4ab

[gaim-migrate @ 16827] A couple of leak fixes, some avoidance of unnecessary memory allocation/freeing and some cleanup. There are a lot fewer changes if you ignore space changes. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Fri, 18 Aug 2006 03:59:01 +0000
parents 3cd388613624
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
1 /**
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
2 * @file tcl.c Gaim Tcl plugin bindings
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
3 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
4 * gaim
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
5 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
6 * Copyright (C) 2003 Ethan Blanton <eblanton@cs.purdue.edu>
9943
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
7 *
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
12 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
17 *
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
21 */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
22
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
23 #include "config.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
24
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
25 #include <tcl.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
26
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
27 #ifdef HAVE_TK
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
28 #include <tk.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
29 #endif
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
30
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
31 #include <stdio.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
32 #include <sys/types.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
33 #include <sys/stat.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
34 #include <unistd.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
35 #include <string.h>
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
36
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
37 #include "tcl_glib.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
38 #include "tcl_gaim.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
39
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
40 #include "internal.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
41 #include "connection.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
42 #include "plugin.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
43 #include "signals.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
44 #include "debug.h"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
45 #include "util.h"
9943
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
46 #include "version.h"
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
47
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
48 struct tcl_plugin_data {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
49 GaimPlugin *plugin;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
50 Tcl_Interp *interp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
51 };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
52
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
53 GaimStringref *GaimTclRefAccount;
13815
724e4c08391a [gaim-migrate @ 16247]
Ethan Blanton <elb@pidgin.im>
parents: 13810
diff changeset
54 GaimStringref *GaimTclRefConnection;
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
55 GaimStringref *GaimTclRefConversation;
13817
ad8ddfa756ad [gaim-migrate @ 16249]
Ethan Blanton <elb@pidgin.im>
parents: 13815
diff changeset
56 GaimStringref *GaimTclRefPointer;
13946
4d577b63299a [gaim-migrate @ 16486]
Ethan Blanton <elb@pidgin.im>
parents: 13845
diff changeset
57 GaimStringref *GaimTclRefPlugin;
13821
e5e07c996c56 [gaim-migrate @ 16254]
Ethan Blanton <elb@pidgin.im>
parents: 13817
diff changeset
58 GaimStringref *GaimTclRefPresence;
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
59 GaimStringref *GaimTclRefStatus;
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
60 GaimStringref *GaimTclRefStatusAttr;
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
61 GaimStringref *GaimTclRefStatusType;
13946
4d577b63299a [gaim-migrate @ 16486]
Ethan Blanton <elb@pidgin.im>
parents: 13845
diff changeset
62 GaimStringref *GaimTclRefXfer;
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
63
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
64 static GHashTable *tcl_plugins = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
65
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
66 GaimPlugin *_tcl_plugin;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
67
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
68 static gboolean tcl_loaded = FALSE;
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
69
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
70 GaimPlugin *tcl_interp_get_plugin(Tcl_Interp *interp)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
71 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
72 struct tcl_plugin_data *data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
73
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
74 if (tcl_plugins == NULL)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
75 return NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
76
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
77 data = g_hash_table_lookup(tcl_plugins, (gpointer)interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
78 return data != NULL ? data->plugin : NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
79 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
80
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
81 static int tcl_init_interp(Tcl_Interp *interp)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
82 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
83 char *rcfile;
9943
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
84 char init[] =
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
85 "namespace eval ::gaim {\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
86 " namespace export account buddy connection conversation\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
87 " namespace export core debug notify prefs send_im\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
88 " namespace export signal unload\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
89 " namespace eval _callback { }\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
90 "\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
91 " proc conv_send { account who text } {\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
92 " set gc [gaim::account connection $account]\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
93 " set convo [gaim::conversation new $account $who]\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
94 " set myalias [gaim::account alias $account]\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
95 "\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
96 " if {![string length $myalias]} {\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
97 " set myalias [gaim::account username $account]\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
98 " }\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
99 "\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
100 " gaim::send_im $gc $who $text\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
101 " gaim::conversation write $convo send $myalias $text\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
102 " }\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
103 "}\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
104 "\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
105 "proc bgerror { message } {\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
106 " global errorInfo\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
107 " gaim::notify -error \"Tcl Error\" \"Tcl Error: $message\" \"$errorInfo\"\n"
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
108 "}\n";
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
109
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
110 if (Tcl_EvalEx(interp, init, -1, TCL_EVAL_GLOBAL) != TCL_OK) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
111 return 1;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
112 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
113
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
114 Tcl_SetVar(interp, "argc", "0", TCL_GLOBAL_ONLY);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
115 Tcl_SetVar(interp, "argv0", "gaim", TCL_GLOBAL_ONLY);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
116 Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
117 rcfile = g_strdup_printf("%s" G_DIR_SEPARATOR_S "tclrc", gaim_user_dir());
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
118 Tcl_SetVar(interp, "tcl_rcFileName", rcfile, TCL_GLOBAL_ONLY);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
119 g_free(rcfile);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
120
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
121 Tcl_SetVar(interp, "::gaim::version", VERSION, TCL_GLOBAL_ONLY);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
122 Tcl_SetVar(interp, "::gaim::user_dir", gaim_user_dir(), TCL_GLOBAL_ONLY);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
123 #ifdef HAVE_TK
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
124 Tcl_SetVar(interp, "::gaim::tk_available", "1", TCL_GLOBAL_ONLY);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
125 #else
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
126 Tcl_SetVar(interp, "::gaim::tk_available", "0", TCL_GLOBAL_ONLY);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
127 #endif /* HAVE_TK */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
128
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
129 Tcl_CreateObjCommand(interp, "::gaim::account", tcl_cmd_account, (ClientData)NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
130 Tcl_CreateObjCommand(interp, "::gaim::buddy", tcl_cmd_buddy, (ClientData)NULL, NULL);
13845
d0ff520f87da [gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13825
diff changeset
131 Tcl_CreateObjCommand(interp, "::gaim::cmd", tcl_cmd_cmd, (ClientData)NULL, NULL);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
132 Tcl_CreateObjCommand(interp, "::gaim::connection", tcl_cmd_connection, (ClientData)NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
133 Tcl_CreateObjCommand(interp, "::gaim::conversation", tcl_cmd_conversation, (ClientData)NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
134 Tcl_CreateObjCommand(interp, "::gaim::core", tcl_cmd_core, (ClientData)NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
135 Tcl_CreateObjCommand(interp, "::gaim::debug", tcl_cmd_debug, (ClientData)NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
136 Tcl_CreateObjCommand(interp, "::gaim::notify", tcl_cmd_notify, (ClientData)NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
137 Tcl_CreateObjCommand(interp, "::gaim::prefs", tcl_cmd_prefs, (ClientData)NULL, NULL);
13821
e5e07c996c56 [gaim-migrate @ 16254]
Ethan Blanton <elb@pidgin.im>
parents: 13817
diff changeset
138 Tcl_CreateObjCommand(interp, "::gaim::presence", tcl_cmd_presence, (ClientData)NULL, NULL);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
139 Tcl_CreateObjCommand(interp, "::gaim::send_im", tcl_cmd_send_im, (ClientData)NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
140 Tcl_CreateObjCommand(interp, "::gaim::signal", tcl_cmd_signal, (ClientData)NULL, NULL);
13825
140ffd4934a0 [gaim-migrate @ 16269]
Ethan Blanton <elb@pidgin.im>
parents: 13821
diff changeset
141 Tcl_CreateObjCommand(interp, "::gaim::status", tcl_cmd_status, (ClientData)NULL, NULL);
140ffd4934a0 [gaim-migrate @ 16269]
Ethan Blanton <elb@pidgin.im>
parents: 13821
diff changeset
142 Tcl_CreateObjCommand(interp, "::gaim::status_attr", tcl_cmd_status_attr, (ClientData)NULL, NULL);
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
143 Tcl_CreateObjCommand(interp, "::gaim::status_type", tcl_cmd_status_type, (ClientData)NULL, NULL);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
144 Tcl_CreateObjCommand(interp, "::gaim::unload", tcl_cmd_unload, (ClientData)NULL, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
145
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
146 return 0;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
147 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
148
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
149 static Tcl_Interp *tcl_create_interp()
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
150 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
151 Tcl_Interp *interp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
152
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
153 interp = Tcl_CreateInterp();
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
154 if (Tcl_Init(interp) == TCL_ERROR) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
155 Tcl_DeleteInterp(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
156 return NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
157 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
158
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
159 if (tcl_init_interp(interp)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
160 Tcl_DeleteInterp(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
161 return NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
162 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
163 Tcl_StaticPackage(interp, "gaim", tcl_init_interp, NULL);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
164
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
165 return interp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
166 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
167
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
168 static gboolean tcl_probe_plugin(GaimPlugin *plugin)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
169 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
170 GaimPluginInfo *info;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
171 Tcl_Interp *interp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
172 Tcl_Parse parse;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
173 Tcl_Obj *result, **listitems;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
174 struct stat st;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
175 FILE *fp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
176 char *buf, *cur;
10344
5976491e07a7 [gaim-migrate @ 11554]
Mark Doliner <mark@kingant.net>
parents: 10281
diff changeset
177 const char *next;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
178 int len, found = 0, err = 0, nelems;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
179 gboolean status = FALSE;
10589
0f7452b1f777 [gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 10454
diff changeset
180 if ((fp = g_fopen(plugin->path, "r")) == NULL)
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
181 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
182 if (fstat(fileno(fp), &st)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
183 fclose(fp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
184 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
185 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
186 len = st.st_size;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
187
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
188 buf = g_malloc(len + 1);
10344
5976491e07a7 [gaim-migrate @ 11554]
Mark Doliner <mark@kingant.net>
parents: 10281
diff changeset
189
5976491e07a7 [gaim-migrate @ 11554]
Mark Doliner <mark@kingant.net>
parents: 10281
diff changeset
190 cur = buf;
13946
4d577b63299a [gaim-migrate @ 16486]
Ethan Blanton <elb@pidgin.im>
parents: 13845
diff changeset
191 while (fgets(cur, GPOINTER_TO_INT(buf) - (buf - cur), fp)) {
8989
a88d4463d233 [gaim-migrate @ 9764]
Ethan Blanton <elb@pidgin.im>
parents: 8761
diff changeset
192 cur += strlen(cur);
10344
5976491e07a7 [gaim-migrate @ 11554]
Mark Doliner <mark@kingant.net>
parents: 10281
diff changeset
193 if (feof(fp))
8989
a88d4463d233 [gaim-migrate @ 9764]
Ethan Blanton <elb@pidgin.im>
parents: 8761
diff changeset
194 break;
a88d4463d233 [gaim-migrate @ 9764]
Ethan Blanton <elb@pidgin.im>
parents: 8761
diff changeset
195 }
a88d4463d233 [gaim-migrate @ 9764]
Ethan Blanton <elb@pidgin.im>
parents: 8761
diff changeset
196
a88d4463d233 [gaim-migrate @ 9764]
Ethan Blanton <elb@pidgin.im>
parents: 8761
diff changeset
197 if (ferror(fp)) {
a88d4463d233 [gaim-migrate @ 9764]
Ethan Blanton <elb@pidgin.im>
parents: 8761
diff changeset
198 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "error reading %s (%s)\n", plugin->path, strerror(errno));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
199 g_free(buf);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
200 fclose(fp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
201 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
202 }
8989
a88d4463d233 [gaim-migrate @ 9764]
Ethan Blanton <elb@pidgin.im>
parents: 8761
diff changeset
203
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
204 fclose(fp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
205
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
206 if ((interp = tcl_create_interp()) == NULL) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
207 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
208 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
209
10344
5976491e07a7 [gaim-migrate @ 11554]
Mark Doliner <mark@kingant.net>
parents: 10281
diff changeset
210 next = buf;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
211 do {
10344
5976491e07a7 [gaim-migrate @ 11554]
Mark Doliner <mark@kingant.net>
parents: 10281
diff changeset
212 if (Tcl_ParseCommand(interp, next, len, 0, &parse) == TCL_ERROR) {
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
213 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "parse error in %s: %s\n", plugin->path,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
214 Tcl_GetString(Tcl_GetObjResult(interp)));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
215 err = 1;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
216 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
217 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
218 if (parse.tokenPtr[0].type == TCL_TOKEN_SIMPLE_WORD
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
219 && !strncmp(parse.tokenPtr[0].start, "proc", parse.tokenPtr[0].size)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
220 if (!strncmp(parse.tokenPtr[2].start, "plugin_init", parse.tokenPtr[2].size)) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
221 if (Tcl_EvalEx(interp, parse.commandStart, parse.commandSize, TCL_EVAL_GLOBAL) != TCL_OK) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
222 Tcl_FreeParse(&parse);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
223 break;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
224 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
225 found = 1;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
226 /* We'll continue parsing the file, just in case */
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
227 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
228 }
10344
5976491e07a7 [gaim-migrate @ 11554]
Mark Doliner <mark@kingant.net>
parents: 10281
diff changeset
229 len -= (parse.commandStart + parse.commandSize) - next;
5976491e07a7 [gaim-migrate @ 11554]
Mark Doliner <mark@kingant.net>
parents: 10281
diff changeset
230 next = parse.commandStart + parse.commandSize;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
231 Tcl_FreeParse(&parse);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
232 } while (len);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
233
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
234 if (found && !err) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
235 if (Tcl_EvalEx(interp, "plugin_init", -1, TCL_EVAL_GLOBAL) == TCL_OK) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
236 result = Tcl_GetObjResult(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
237 if (Tcl_ListObjGetElements(interp, result, &nelems, &listitems) == TCL_OK) {
12987
750968cab201 [gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents: 11256
diff changeset
238 if ((nelems == 6) || (nelems == 7)) {
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
239 info = g_new0(GaimPluginInfo, 1);
8761
10caa1ec2dc4 [gaim-migrate @ 9516]
Mark Doliner <mark@kingant.net>
parents: 8759
diff changeset
240
9943
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
241 info->magic = GAIM_PLUGIN_MAGIC;
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
242 info->major_version = GAIM_MAJOR_VERSION;
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
243 info->minor_version = GAIM_MINOR_VERSION;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
244 info->type = GAIM_PLUGIN_STANDARD;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
245 info->dependencies = g_list_append(info->dependencies, "core-tcl");
8761
10caa1ec2dc4 [gaim-migrate @ 9516]
Mark Doliner <mark@kingant.net>
parents: 8759
diff changeset
246
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
247 info->name = g_strdup(Tcl_GetString(listitems[0]));
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
248 info->version = g_strdup(Tcl_GetString(listitems[1]));
8117
e280d73ed07f [gaim-migrate @ 8821]
Ethan Blanton <elb@pidgin.im>
parents: 7831
diff changeset
249 info->summary = g_strdup(Tcl_GetString(listitems[2]));
9775
4c1a1be8ce33 [gaim-migrate @ 10643]
Mark Doliner <mark@kingant.net>
parents: 8993
diff changeset
250 info->description = g_strdup(Tcl_GetString(listitems[3]));
10454
4f1a59fb4159 [gaim-migrate @ 11722]
Mark Doliner <mark@kingant.net>
parents: 10344
diff changeset
251 info->author = g_strdup(Tcl_GetString(listitems[4]));
8117
e280d73ed07f [gaim-migrate @ 8821]
Ethan Blanton <elb@pidgin.im>
parents: 7831
diff changeset
252 info->homepage = g_strdup(Tcl_GetString(listitems[5]));
8761
10caa1ec2dc4 [gaim-migrate @ 9516]
Mark Doliner <mark@kingant.net>
parents: 8759
diff changeset
253
12987
750968cab201 [gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents: 11256
diff changeset
254 if (nelems == 6)
750968cab201 [gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents: 11256
diff changeset
255 info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[0]));
750968cab201 [gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents: 11256
diff changeset
256 else if (nelems == 7)
750968cab201 [gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents: 11256
diff changeset
257 info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[6]));
750968cab201 [gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents: 11256
diff changeset
258
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
259 plugin->info = info;
8761
10caa1ec2dc4 [gaim-migrate @ 9516]
Mark Doliner <mark@kingant.net>
parents: 8759
diff changeset
260
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
261 if (gaim_plugin_register(plugin))
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
262 status = TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
263 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
264 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
265 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
266 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
267
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
268 Tcl_DeleteInterp(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
269 g_free(buf);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
270 return status;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
271 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
272
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
273 static gboolean tcl_load_plugin(GaimPlugin *plugin)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
274 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
275 struct tcl_plugin_data *data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
276 Tcl_Interp *interp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
277 Tcl_Obj *result;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
278
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
279 plugin->extra = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
280
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
281 if ((interp = tcl_create_interp()) == NULL) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
282 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Could not initialize Tcl interpreter\n");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
283 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
284 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
285
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
286 Tcl_SourceRCFile(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
287
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
288 if (Tcl_EvalFile(interp, plugin->path) != TCL_OK) {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
289 result = Tcl_GetObjResult(interp);
13845
d0ff520f87da [gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13825
diff changeset
290 gaim_debug(GAIM_DEBUG_ERROR, "tcl",
d0ff520f87da [gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13825
diff changeset
291 "Error evaluating %s: %s\n", plugin->path,
d0ff520f87da [gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13825
diff changeset
292 Tcl_GetString(result));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
293 Tcl_DeleteInterp(interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
294 return FALSE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
295 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
296
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
297 Tcl_Preserve((ClientData)interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
298
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
299 data = g_new0(struct tcl_plugin_data, 1);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
300 data->plugin = plugin;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
301 data->interp = interp;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
302 plugin->extra = data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
303
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
304 g_hash_table_insert(tcl_plugins, (gpointer)interp, (gpointer)data);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
305
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
306 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
307 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
308
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
309 static gboolean tcl_unload_plugin(GaimPlugin *plugin)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
310 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
311 struct tcl_plugin_data *data;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
312
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
313 if (plugin == NULL)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
314 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
315
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
316 data = plugin->extra;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
317
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
318 if (data != NULL) {
13438
068282089843 [gaim-migrate @ 15813]
Richard Laager <rlaager@wiktel.com>
parents: 13198
diff changeset
319 g_hash_table_remove(tcl_plugins, (gpointer)(data->interp));
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
320 gaim_signals_disconnect_by_handle(data->interp);
13845
d0ff520f87da [gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13825
diff changeset
321 tcl_cmd_cleanup(data->interp);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
322 tcl_signal_cleanup(data->interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
323 Tcl_Release((ClientData)data->interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
324 Tcl_DeleteInterp(data->interp);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
325 g_free(data);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
326 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
327
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
328 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
329 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
330
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
331 static void tcl_destroy_plugin(GaimPlugin *plugin)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
332 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
333 if (plugin->info != NULL) {
13198
83b39a76e06e [gaim-migrate @ 15561]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12987
diff changeset
334 g_free(plugin->info->id);
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
335 g_free(plugin->info->name);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
336 g_free(plugin->info->version);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
337 g_free(plugin->info->description);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
338 g_free(plugin->info->author);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
339 g_free(plugin->info->homepage);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
340 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
341
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
342 return;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
343 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
344
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
345 static gboolean tcl_load(GaimPlugin *plugin)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
346 {
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
347 if(!tcl_loaded)
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
348 return FALSE;
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
349 tcl_glib_init();
13845
d0ff520f87da [gaim-migrate @ 16301]
Etan Reisner <pidgin@unreliablesource.net>
parents: 13825
diff changeset
350 tcl_cmd_init();
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
351 tcl_signal_init();
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
352 gaim_tcl_ref_init();
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
353
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
354 GaimTclRefAccount = gaim_stringref_new("Account");
13815
724e4c08391a [gaim-migrate @ 16247]
Ethan Blanton <elb@pidgin.im>
parents: 13810
diff changeset
355 GaimTclRefConnection = gaim_stringref_new("Connection");
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
356 GaimTclRefConversation = gaim_stringref_new("Conversation");
13817
ad8ddfa756ad [gaim-migrate @ 16249]
Ethan Blanton <elb@pidgin.im>
parents: 13815
diff changeset
357 GaimTclRefPointer = gaim_stringref_new("Pointer");
13946
4d577b63299a [gaim-migrate @ 16486]
Ethan Blanton <elb@pidgin.im>
parents: 13845
diff changeset
358 GaimTclRefPlugin = gaim_stringref_new("Plugin");
13821
e5e07c996c56 [gaim-migrate @ 16254]
Ethan Blanton <elb@pidgin.im>
parents: 13817
diff changeset
359 GaimTclRefPresence = gaim_stringref_new("Presence");
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
360 GaimTclRefStatus = gaim_stringref_new("Status");
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
361 GaimTclRefStatusAttr = gaim_stringref_new("StatusAttr");
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
362 GaimTclRefStatusType = gaim_stringref_new("StatusType");
13946
4d577b63299a [gaim-migrate @ 16486]
Ethan Blanton <elb@pidgin.im>
parents: 13845
diff changeset
363 GaimTclRefXfer = gaim_stringref_new("Xfer");
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
364
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
365 tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
366
7828
0408e93c8a72 [gaim-migrate @ 8480]
Ethan Blanton <elb@pidgin.im>
parents: 6735
diff changeset
367 #ifdef HAVE_TK
0408e93c8a72 [gaim-migrate @ 8480]
Ethan Blanton <elb@pidgin.im>
parents: 6735
diff changeset
368 Tcl_StaticPackage(NULL, "Tk", Tk_Init, Tk_SafeInit);
0408e93c8a72 [gaim-migrate @ 8480]
Ethan Blanton <elb@pidgin.im>
parents: 6735
diff changeset
369 #endif /* HAVE_TK */
0408e93c8a72 [gaim-migrate @ 8480]
Ethan Blanton <elb@pidgin.im>
parents: 6735
diff changeset
370
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
371 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
372 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
373
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
374 static gboolean tcl_unload(GaimPlugin *plugin)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
375 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
376 g_hash_table_destroy(tcl_plugins);
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
377 tcl_plugins = NULL;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
378
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
379 gaim_stringref_unref(GaimTclRefAccount);
13815
724e4c08391a [gaim-migrate @ 16247]
Ethan Blanton <elb@pidgin.im>
parents: 13810
diff changeset
380 gaim_stringref_unref(GaimTclRefConnection);
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
381 gaim_stringref_unref(GaimTclRefConversation);
13817
ad8ddfa756ad [gaim-migrate @ 16249]
Ethan Blanton <elb@pidgin.im>
parents: 13815
diff changeset
382 gaim_stringref_unref(GaimTclRefPointer);
13954
3cd388613624 [gaim-migrate @ 16502]
Mark Doliner <mark@kingant.net>
parents: 13946
diff changeset
383 gaim_stringref_unref(GaimTclRefPlugin);
13821
e5e07c996c56 [gaim-migrate @ 16254]
Ethan Blanton <elb@pidgin.im>
parents: 13817
diff changeset
384 gaim_stringref_unref(GaimTclRefPresence);
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
385 gaim_stringref_unref(GaimTclRefStatus);
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
386 gaim_stringref_unref(GaimTclRefStatusAttr);
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
387 gaim_stringref_unref(GaimTclRefStatusType);
13954
3cd388613624 [gaim-migrate @ 16502]
Mark Doliner <mark@kingant.net>
parents: 13946
diff changeset
388 gaim_stringref_unref(GaimTclRefXfer);
13810
a84523152a24 [gaim-migrate @ 16240]
Ethan Blanton <elb@pidgin.im>
parents: 13455
diff changeset
389
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
390 return TRUE;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
391 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
392
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
393 static GaimPluginLoaderInfo tcl_loader_info =
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
394 {
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
395 NULL,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
396 tcl_probe_plugin,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
397 tcl_load_plugin,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
398 tcl_unload_plugin,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
399 tcl_destroy_plugin,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
400 };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
401
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
402 static GaimPluginInfo tcl_info =
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
403 {
9943
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
404 GAIM_PLUGIN_MAGIC,
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
405 GAIM_MAJOR_VERSION,
f8e395a054e2 [gaim-migrate @ 10835]
Nathan Walp <nwalp@pidgin.im>
parents: 9775
diff changeset
406 GAIM_MINOR_VERSION,
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
407 GAIM_PLUGIN_LOADER,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
408 NULL,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
409 0,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
410 NULL,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
411 GAIM_PRIORITY_DEFAULT,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
412 "core-tcl",
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
413 N_("Tcl Plugin Loader"),
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
414 VERSION,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
415 N_("Provides support for loading Tcl plugins"),
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
416 N_("Provides support for loading Tcl plugins"),
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
417 "Ethan Blanton <eblanton@cs.purdue.edu>",
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
418 GAIM_WEBSITE,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
419 tcl_load,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
420 tcl_unload,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
421 NULL,
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
422 NULL,
8993
294ae6548d4e [gaim-migrate @ 9768]
Luke Schierer <lschiere@pidgin.im>
parents: 8989
diff changeset
423 &tcl_loader_info,
294ae6548d4e [gaim-migrate @ 9768]
Luke Schierer <lschiere@pidgin.im>
parents: 8989
diff changeset
424 NULL,
294ae6548d4e [gaim-migrate @ 9768]
Luke Schierer <lschiere@pidgin.im>
parents: 8989
diff changeset
425 NULL
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
426 };
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
427
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
428 #ifdef _WIN32
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
429 typedef Tcl_Interp* (CALLBACK* LPFNTCLCREATEINTERP)(void);
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
430 typedef void (CALLBACK* LPFNTKINIT)(Tcl_Interp*);
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
431
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
432 LPFNTCLCREATEINTERP wtcl_CreateInterp = NULL;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
433 LPFNTKINIT wtk_Init = NULL;
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
434 #undef Tcl_CreateInterp
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
435 #define Tcl_CreateInterp wtcl_CreateInterp
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
436 #undef Tk_Init
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
437 #define Tk_Init wtk_Init
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
438
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
439 static gboolean tcl_win32_init() {
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
440 gaim_debug(GAIM_DEBUG_INFO, "tcl",
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
441 "Initializing the Tcl runtime. If Gaim doesn't load, it is "
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
442 "most likely because you have cygwin in your PATH and you "
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
443 "should remove it. See http://gaim.sf.net/win32 for more "
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
444 "information\n");
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
445
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
446 if(!(wtcl_CreateInterp = (LPFNTCLCREATEINTERP) wgaim_find_and_loadproc("tcl84.dll", "Tcl_CreateInterp"))) {
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
447 gaim_debug(GAIM_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tcl_CreateInterp\n");
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
448 return FALSE;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
449 }
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
450
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
451 if(!(wtk_Init = (LPFNTKINIT) wgaim_find_and_loadproc("tk84.dll", "Tk_Init"))) {
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
452 HMODULE mod;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
453 gaim_debug(GAIM_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tk_Init\n");
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
454 if((mod = GetModuleHandle("tcl84.dll")))
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
455 FreeLibrary(mod);
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
456 return FALSE;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
457 }
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
458
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
459 if (GetModuleHandle("cygwin1.dll")) {
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
460 HMODULE mod;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
461 gaim_debug(GAIM_DEBUG_INFO, "tcl", "Cygwin has been loaded by tcl84.dll and/or tk84.dll. Disabling Tcl support to avoid problems.\n");
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
462 if((mod = GetModuleHandle("tcl84.dll")))
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
463 FreeLibrary(mod);
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
464 if((mod = GetModuleHandle("tk84.dll")))
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
465 FreeLibrary(mod);
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
466 return FALSE;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
467 }
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
468
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
469 return TRUE;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
470 }
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
471
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
472 #endif /* _WIN32 */
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
473
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
474 static void tcl_init_plugin(GaimPlugin *plugin)
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
475 {
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
476 #ifdef USE_TCL_STUBS
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
477 Tcl_Interp *interp = NULL;
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
478 #endif
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
479 _tcl_plugin = plugin;
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
480
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
481 #ifdef USE_TCL_STUBS
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
482 #ifdef _WIN32
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
483 if(!tcl_win32_init())
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
484 return;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
485 #endif
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
486 if(!(interp = Tcl_CreateInterp()))
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
487 return;
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
488
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
489 if(!Tcl_InitStubs(interp, TCL_VERSION, 0)) {
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
490 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Tcl_InitStubs: %s\n", interp->result);
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
491 return;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
492 }
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
493 #endif
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
494
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
495 Tcl_FindExecutable("gaim");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
496
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
497 #if defined(USE_TK_STUBS) && defined(HAVE_TK)
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
498 Tk_Init(interp);
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
499
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
500 if(!Tk_InitStubs(interp, TK_VERSION, 0)) {
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
501 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Error Tk_InitStubs: %s\n", interp->result);
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
502 Tcl_DeleteInterp(interp);
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
503 return;
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
504 }
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
505 #endif
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
506 tcl_loaded = TRUE;
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
507 #ifdef USE_TCL_STUBS
13455
70197e8ac15c [gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13438
diff changeset
508 Tcl_DeleteInterp(interp);
7831
409f7f167c98 [gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 7828
diff changeset
509 #endif
6694
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
510 tcl_loader_info.exts = g_list_append(tcl_loader_info.exts, "tcl");
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
511 }
2d2f04c5c7d2 [gaim-migrate @ 7220]
Ethan Blanton <elb@pidgin.im>
parents:
diff changeset
512
6735
b0913ab92893 [gaim-migrate @ 7267]
Mark Doliner <mark@kingant.net>
parents: 6694
diff changeset
513 GAIM_INIT_PLUGIN(tcl, tcl_init_plugin, tcl_info)