Mercurial > pidgin
annotate plugins/tcl/tcl.c @ 13561:104fbbfc91fb
[gaim-migrate @ 15940]
beta3 for the RPM spec file too
committer: Tailor Script <tailor@pidgin.im>
| author | Stu Tomlinson <stu@nosnilmot.com> |
|---|---|
| date | Sat, 25 Mar 2006 15:17:15 +0000 |
| parents | 70197e8ac15c |
| children | a84523152a24 |
| 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 | |
| 53 static GHashTable *tcl_plugins = NULL; | |
| 54 | |
| 55 GaimPlugin *_tcl_plugin; | |
| 56 | |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
57 static gboolean tcl_loaded = FALSE; |
|
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
58 |
| 6694 | 59 GaimPlugin *tcl_interp_get_plugin(Tcl_Interp *interp) |
| 60 { | |
| 61 struct tcl_plugin_data *data; | |
| 62 | |
| 63 if (tcl_plugins == NULL) | |
| 64 return NULL; | |
| 65 | |
| 66 data = g_hash_table_lookup(tcl_plugins, (gpointer)interp); | |
| 67 return data != NULL ? data->plugin : NULL; | |
| 68 } | |
| 69 | |
| 70 static int tcl_init_interp(Tcl_Interp *interp) | |
| 71 { | |
| 72 char *rcfile; | |
| 9943 | 73 char init[] = |
| 6694 | 74 "namespace eval ::gaim {\n" |
| 75 " namespace export account buddy connection conversation\n" | |
| 76 " namespace export core debug notify prefs send_im\n" | |
| 77 " namespace export signal unload\n" | |
| 78 " namespace eval _callback { }\n" | |
| 79 "\n" | |
| 80 " proc conv_send { account who text } {\n" | |
| 81 " set gc [gaim::account connection $account]\n" | |
| 82 " set convo [gaim::conversation new $account $who]\n" | |
| 83 " set myalias [gaim::account alias $account]\n" | |
| 84 "\n" | |
| 85 " if {![string length $myalias]} {\n" | |
| 86 " set myalias [gaim::account username $account]\n" | |
| 87 " }\n" | |
| 88 "\n" | |
| 89 " gaim::send_im $gc $who $text\n" | |
| 90 " gaim::conversation write $convo send $myalias $text\n" | |
| 91 " }\n" | |
| 92 "}\n" | |
| 93 "\n" | |
| 94 "proc bgerror { message } {\n" | |
| 95 " global errorInfo\n" | |
| 96 " gaim::notify -error \"Tcl Error\" \"Tcl Error: $message\" \"$errorInfo\"\n" | |
| 97 "}\n"; | |
| 98 | |
| 99 if (Tcl_EvalEx(interp, init, -1, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 100 return 1; | |
| 101 } | |
| 102 | |
| 103 Tcl_SetVar(interp, "argc", "0", TCL_GLOBAL_ONLY); | |
| 104 Tcl_SetVar(interp, "argv0", "gaim", TCL_GLOBAL_ONLY); | |
| 105 Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 106 rcfile = g_strdup_printf("%s" G_DIR_SEPARATOR_S "tclrc", gaim_user_dir()); | |
| 107 Tcl_SetVar(interp, "tcl_rcFileName", rcfile, TCL_GLOBAL_ONLY); | |
| 108 g_free(rcfile); | |
| 109 | |
| 110 Tcl_SetVar(interp, "::gaim::version", VERSION, TCL_GLOBAL_ONLY); | |
| 111 Tcl_SetVar(interp, "::gaim::user_dir", gaim_user_dir(), TCL_GLOBAL_ONLY); | |
| 112 #ifdef HAVE_TK | |
| 113 Tcl_SetVar(interp, "::gaim::tk_available", "1", TCL_GLOBAL_ONLY); | |
| 114 #else | |
| 115 Tcl_SetVar(interp, "::gaim::tk_available", "0", TCL_GLOBAL_ONLY); | |
| 116 #endif /* HAVE_TK */ | |
| 117 | |
| 118 Tcl_CreateObjCommand(interp, "::gaim::account", tcl_cmd_account, (ClientData)NULL, NULL); | |
| 119 Tcl_CreateObjCommand(interp, "::gaim::buddy", tcl_cmd_buddy, (ClientData)NULL, NULL); | |
| 120 Tcl_CreateObjCommand(interp, "::gaim::connection", tcl_cmd_connection, (ClientData)NULL, NULL); | |
| 121 Tcl_CreateObjCommand(interp, "::gaim::conversation", tcl_cmd_conversation, (ClientData)NULL, NULL); | |
| 122 Tcl_CreateObjCommand(interp, "::gaim::core", tcl_cmd_core, (ClientData)NULL, NULL); | |
| 123 Tcl_CreateObjCommand(interp, "::gaim::debug", tcl_cmd_debug, (ClientData)NULL, NULL); | |
| 124 Tcl_CreateObjCommand(interp, "::gaim::notify", tcl_cmd_notify, (ClientData)NULL, NULL); | |
| 125 Tcl_CreateObjCommand(interp, "::gaim::prefs", tcl_cmd_prefs, (ClientData)NULL, NULL); | |
| 126 Tcl_CreateObjCommand(interp, "::gaim::send_im", tcl_cmd_send_im, (ClientData)NULL, NULL); | |
| 127 Tcl_CreateObjCommand(interp, "::gaim::signal", tcl_cmd_signal, (ClientData)NULL, NULL); | |
| 128 Tcl_CreateObjCommand(interp, "::gaim::unload", tcl_cmd_unload, (ClientData)NULL, NULL); | |
| 129 | |
| 130 return 0; | |
| 131 } | |
| 132 | |
| 133 static Tcl_Interp *tcl_create_interp() | |
| 134 { | |
| 135 Tcl_Interp *interp; | |
| 136 | |
| 137 interp = Tcl_CreateInterp(); | |
| 138 if (Tcl_Init(interp) == TCL_ERROR) { | |
| 139 Tcl_DeleteInterp(interp); | |
| 140 return NULL; | |
| 141 } | |
| 142 | |
| 143 if (tcl_init_interp(interp)) { | |
| 144 Tcl_DeleteInterp(interp); | |
| 145 return NULL; | |
| 146 } | |
| 147 Tcl_StaticPackage(interp, "gaim", tcl_init_interp, NULL); | |
| 148 | |
| 149 return interp; | |
| 150 } | |
| 151 | |
| 152 static gboolean tcl_probe_plugin(GaimPlugin *plugin) | |
| 153 { | |
| 154 GaimPluginInfo *info; | |
| 155 Tcl_Interp *interp; | |
| 156 Tcl_Parse parse; | |
| 157 Tcl_Obj *result, **listitems; | |
| 158 struct stat st; | |
| 159 FILE *fp; | |
| 160 char *buf, *cur; | |
| 10344 | 161 const char *next; |
| 6694 | 162 int len, found = 0, err = 0, nelems; |
| 163 gboolean status = FALSE; | |
|
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10454
diff
changeset
|
164 if ((fp = g_fopen(plugin->path, "r")) == NULL) |
| 6694 | 165 return FALSE; |
| 166 if (fstat(fileno(fp), &st)) { | |
| 167 fclose(fp); | |
| 168 return FALSE; | |
| 169 } | |
| 170 len = st.st_size; | |
| 171 | |
| 172 buf = g_malloc(len + 1); | |
| 10344 | 173 |
| 174 cur = buf; | |
| 8989 | 175 while (fgets(cur, (int) buf - (buf - cur), fp)) { |
| 176 cur += strlen(cur); | |
| 10344 | 177 if (feof(fp)) |
| 8989 | 178 break; |
| 179 } | |
| 180 | |
| 181 if (ferror(fp)) { | |
| 182 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "error reading %s (%s)\n", plugin->path, strerror(errno)); | |
| 6694 | 183 g_free(buf); |
| 184 fclose(fp); | |
| 185 return FALSE; | |
| 186 } | |
| 8989 | 187 |
| 6694 | 188 fclose(fp); |
| 189 | |
| 190 if ((interp = tcl_create_interp()) == NULL) { | |
| 191 return FALSE; | |
| 192 } | |
| 193 | |
| 10344 | 194 next = buf; |
| 6694 | 195 do { |
| 10344 | 196 if (Tcl_ParseCommand(interp, next, len, 0, &parse) == TCL_ERROR) { |
| 6694 | 197 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "parse error in %s: %s\n", plugin->path, |
| 198 Tcl_GetString(Tcl_GetObjResult(interp))); | |
| 199 err = 1; | |
| 200 break; | |
| 201 } | |
| 202 if (parse.tokenPtr[0].type == TCL_TOKEN_SIMPLE_WORD | |
| 203 && !strncmp(parse.tokenPtr[0].start, "proc", parse.tokenPtr[0].size)) { | |
| 204 if (!strncmp(parse.tokenPtr[2].start, "plugin_init", parse.tokenPtr[2].size)) { | |
| 205 if (Tcl_EvalEx(interp, parse.commandStart, parse.commandSize, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 206 Tcl_FreeParse(&parse); | |
| 207 break; | |
| 208 } | |
| 209 found = 1; | |
| 210 /* We'll continue parsing the file, just in case */ | |
| 211 } | |
| 212 } | |
| 10344 | 213 len -= (parse.commandStart + parse.commandSize) - next; |
| 214 next = parse.commandStart + parse.commandSize; | |
| 6694 | 215 Tcl_FreeParse(&parse); |
| 216 } while (len); | |
| 217 | |
| 218 if (found && !err) { | |
| 219 if (Tcl_EvalEx(interp, "plugin_init", -1, TCL_EVAL_GLOBAL) == TCL_OK) { | |
| 220 result = Tcl_GetObjResult(interp); | |
| 221 if (Tcl_ListObjGetElements(interp, result, &nelems, &listitems) == TCL_OK) { | |
|
12987
750968cab201
[gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11256
diff
changeset
|
222 if ((nelems == 6) || (nelems == 7)) { |
| 6694 | 223 info = g_new0(GaimPluginInfo, 1); |
| 8761 | 224 |
| 9943 | 225 info->magic = GAIM_PLUGIN_MAGIC; |
| 226 info->major_version = GAIM_MAJOR_VERSION; | |
| 227 info->minor_version = GAIM_MINOR_VERSION; | |
| 6694 | 228 info->type = GAIM_PLUGIN_STANDARD; |
| 229 info->dependencies = g_list_append(info->dependencies, "core-tcl"); | |
| 8761 | 230 |
| 6694 | 231 info->name = g_strdup(Tcl_GetString(listitems[0])); |
| 232 info->version = g_strdup(Tcl_GetString(listitems[1])); | |
| 8117 | 233 info->summary = g_strdup(Tcl_GetString(listitems[2])); |
| 9775 | 234 info->description = g_strdup(Tcl_GetString(listitems[3])); |
| 10454 | 235 info->author = g_strdup(Tcl_GetString(listitems[4])); |
| 8117 | 236 info->homepage = g_strdup(Tcl_GetString(listitems[5])); |
| 8761 | 237 |
|
12987
750968cab201
[gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11256
diff
changeset
|
238 if (nelems == 6) |
|
750968cab201
[gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11256
diff
changeset
|
239 info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[0])); |
|
750968cab201
[gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11256
diff
changeset
|
240 else if (nelems == 7) |
|
750968cab201
[gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11256
diff
changeset
|
241 info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[6])); |
|
750968cab201
[gaim-migrate @ 15340]
Etan Reisner <pidgin@unreliablesource.net>
parents:
11256
diff
changeset
|
242 |
| 6694 | 243 plugin->info = info; |
| 8761 | 244 |
| 6694 | 245 if (gaim_plugin_register(plugin)) |
| 246 status = TRUE; | |
| 247 } | |
| 248 } | |
| 249 } | |
| 250 } | |
| 251 | |
| 252 Tcl_DeleteInterp(interp); | |
| 253 g_free(buf); | |
| 254 return status; | |
| 255 } | |
| 256 | |
| 257 static gboolean tcl_load_plugin(GaimPlugin *plugin) | |
| 258 { | |
| 259 struct tcl_plugin_data *data; | |
| 260 Tcl_Interp *interp; | |
| 261 Tcl_Obj *result; | |
| 262 | |
| 263 plugin->extra = NULL; | |
| 264 | |
| 265 if ((interp = tcl_create_interp()) == NULL) { | |
| 266 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Could not initialize Tcl interpreter\n"); | |
| 267 return FALSE; | |
| 268 } | |
| 269 | |
| 270 Tcl_SourceRCFile(interp); | |
| 271 | |
| 272 if (Tcl_EvalFile(interp, plugin->path) != TCL_OK) { | |
| 273 result = Tcl_GetObjResult(interp); | |
| 274 gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Error evaluating %s: %s\n", plugin->path, Tcl_GetString(result)); | |
| 275 Tcl_DeleteInterp(interp); | |
| 276 return FALSE; | |
| 277 } | |
| 278 | |
| 279 Tcl_Preserve((ClientData)interp); | |
| 280 | |
| 281 data = g_new0(struct tcl_plugin_data, 1); | |
| 282 data->plugin = plugin; | |
| 283 data->interp = interp; | |
| 284 plugin->extra = data; | |
| 285 | |
| 286 g_hash_table_insert(tcl_plugins, (gpointer)interp, (gpointer)data); | |
| 287 | |
| 288 return TRUE; | |
| 289 } | |
| 290 | |
| 291 static gboolean tcl_unload_plugin(GaimPlugin *plugin) | |
| 292 { | |
| 293 struct tcl_plugin_data *data; | |
| 294 | |
| 295 if (plugin == NULL) | |
| 296 return TRUE; | |
| 297 | |
| 298 data = plugin->extra; | |
| 299 | |
| 300 if (data != NULL) { | |
|
13438
068282089843
[gaim-migrate @ 15813]
Richard Laager <rlaager@wiktel.com>
parents:
13198
diff
changeset
|
301 g_hash_table_remove(tcl_plugins, (gpointer)(data->interp)); |
| 6694 | 302 gaim_signals_disconnect_by_handle(data->interp); |
| 303 tcl_signal_cleanup(data->interp); | |
| 304 Tcl_Release((ClientData)data->interp); | |
| 305 Tcl_DeleteInterp(data->interp); | |
| 306 g_free(data); | |
| 307 } | |
| 308 | |
| 309 return TRUE; | |
| 310 } | |
| 311 | |
| 312 static void tcl_destroy_plugin(GaimPlugin *plugin) | |
| 313 { | |
| 314 if (plugin->info != NULL) { | |
|
13198
83b39a76e06e
[gaim-migrate @ 15561]
Etan Reisner <pidgin@unreliablesource.net>
parents:
12987
diff
changeset
|
315 g_free(plugin->info->id); |
| 6694 | 316 g_free(plugin->info->name); |
| 317 g_free(plugin->info->version); | |
| 318 g_free(plugin->info->description); | |
| 319 g_free(plugin->info->author); | |
| 320 g_free(plugin->info->homepage); | |
| 321 } | |
| 322 | |
| 323 return; | |
| 324 } | |
| 325 | |
| 326 static gboolean tcl_load(GaimPlugin *plugin) | |
| 327 { | |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
328 if(!tcl_loaded) |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
329 return FALSE; |
| 6694 | 330 tcl_glib_init(); |
| 331 tcl_signal_init(); | |
| 332 tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal); | |
| 333 | |
| 7828 | 334 #ifdef HAVE_TK |
| 335 Tcl_StaticPackage(NULL, "Tk", Tk_Init, Tk_SafeInit); | |
| 336 #endif /* HAVE_TK */ | |
| 337 | |
| 6694 | 338 return TRUE; |
| 339 } | |
| 340 | |
| 341 static gboolean tcl_unload(GaimPlugin *plugin) | |
| 342 { | |
| 343 g_hash_table_destroy(tcl_plugins); | |
| 344 tcl_plugins = NULL; | |
| 345 | |
| 346 return TRUE; | |
| 347 } | |
| 348 | |
| 349 static GaimPluginLoaderInfo tcl_loader_info = | |
| 350 { | |
| 351 NULL, | |
| 352 tcl_probe_plugin, | |
| 353 tcl_load_plugin, | |
| 354 tcl_unload_plugin, | |
| 355 tcl_destroy_plugin, | |
| 356 }; | |
| 357 | |
| 358 static GaimPluginInfo tcl_info = | |
| 359 { | |
| 9943 | 360 GAIM_PLUGIN_MAGIC, |
| 361 GAIM_MAJOR_VERSION, | |
| 362 GAIM_MINOR_VERSION, | |
| 6694 | 363 GAIM_PLUGIN_LOADER, |
| 364 NULL, | |
| 365 0, | |
| 366 NULL, | |
| 367 GAIM_PRIORITY_DEFAULT, | |
| 368 "core-tcl", | |
| 369 N_("Tcl Plugin Loader"), | |
| 370 VERSION, | |
| 371 N_("Provides support for loading Tcl plugins"), | |
| 372 N_("Provides support for loading Tcl plugins"), | |
| 373 "Ethan Blanton <eblanton@cs.purdue.edu>", | |
| 374 GAIM_WEBSITE, | |
| 375 tcl_load, | |
| 376 tcl_unload, | |
| 377 NULL, | |
| 378 NULL, | |
| 8993 | 379 &tcl_loader_info, |
| 380 NULL, | |
| 381 NULL | |
| 6694 | 382 }; |
| 383 | |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
384 #ifdef _WIN32 |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
385 typedef Tcl_Interp* (CALLBACK* LPFNTCLCREATEINTERP)(void); |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
386 typedef void (CALLBACK* LPFNTKINIT)(Tcl_Interp*); |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
387 |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
388 LPFNTCLCREATEINTERP wtcl_CreateInterp = NULL; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
389 LPFNTKINIT wtk_Init = NULL; |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
390 #undef Tcl_CreateInterp |
|
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
391 #define Tcl_CreateInterp wtcl_CreateInterp |
|
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
392 #undef Tk_Init |
|
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
393 #define Tk_Init wtk_Init |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
394 |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
395 static gboolean tcl_win32_init() { |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
396 gaim_debug(GAIM_DEBUG_INFO, "tcl", |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
397 "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
|
398 "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
|
399 "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
|
400 "information\n"); |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
401 |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
402 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
|
403 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
|
404 return FALSE; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
405 } |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
406 |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
407 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
|
408 HMODULE mod; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
409 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
|
410 if((mod = GetModuleHandle("tcl84.dll"))) |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
411 FreeLibrary(mod); |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
412 return FALSE; |
|
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 |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
415 if (GetModuleHandle("cygwin1.dll")) { |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
416 HMODULE mod; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
417 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
|
418 if((mod = GetModuleHandle("tcl84.dll"))) |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
419 FreeLibrary(mod); |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
420 if((mod = GetModuleHandle("tk84.dll"))) |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
421 FreeLibrary(mod); |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
422 return FALSE; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
423 } |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
424 |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
425 return TRUE; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
426 } |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
427 |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
428 #endif /* _WIN32 */ |
|
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
429 |
| 6694 | 430 static void tcl_init_plugin(GaimPlugin *plugin) |
| 431 { | |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
432 #ifdef USE_TCL_STUBS |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
433 Tcl_Interp *interp = NULL; |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
434 #endif |
| 6694 | 435 _tcl_plugin = plugin; |
| 436 | |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
437 #ifdef USE_TCL_STUBS |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
438 #ifdef _WIN32 |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
439 if(!tcl_win32_init()) |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
440 return; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
441 #endif |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
442 if(!(interp = Tcl_CreateInterp())) |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
443 return; |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
444 |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
445 if(!Tcl_InitStubs(interp, TCL_VERSION, 0)) { |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
446 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
|
447 return; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
448 } |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
449 #endif |
|
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
450 |
| 6694 | 451 Tcl_FindExecutable("gaim"); |
| 452 | |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
453 #if defined(USE_TK_STUBS) && defined(HAVE_TK) |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
454 Tk_Init(interp); |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
455 |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
456 if(!Tk_InitStubs(interp, TK_VERSION, 0)) { |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
457 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
|
458 Tcl_DeleteInterp(interp); |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
459 return; |
|
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
460 } |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
461 #endif |
|
13455
70197e8ac15c
[gaim-migrate @ 15830]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
13438
diff
changeset
|
462 tcl_loaded = TRUE; |
|
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 Tcl_DeleteInterp(interp); |
|
7831
409f7f167c98
[gaim-migrate @ 8483]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7828
diff
changeset
|
465 #endif |
| 6694 | 466 tcl_loader_info.exts = g_list_append(tcl_loader_info.exts, "tcl"); |
| 467 } | |
| 468 | |
| 6735 | 469 GAIM_INIT_PLUGIN(tcl, tcl_init_plugin, tcl_info) |
