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