Fri, 16 Jun 2006 03:49:14 +0000
[gaim-migrate @ 16269]
Fix some spacing bugs and a stupid copy-and-paste error
| 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 | ||
| 13812 | 53 | GaimStringref *GaimTclRefAccount; |
| 13817 | 54 | GaimStringref *GaimTclRefConnection; |
| 13812 | 55 | GaimStringref *GaimTclRefConversation; |
| 13819 | 56 | GaimStringref *GaimTclRefPointer; |
| 13823 | 57 | GaimStringref *GaimTclRefPresence; |
| 13812 | 58 | GaimStringref *GaimTclRefStatus; |
| 59 | GaimStringref *GaimTclRefStatusAttr; | |
| 60 | GaimStringref *GaimTclRefStatusType; | |
| 61 | ||
| 6694 | 62 | static GHashTable *tcl_plugins = NULL; |
| 63 | ||
| 64 | GaimPlugin *_tcl_plugin; | |
| 65 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
66 | static gboolean tcl_loaded = FALSE; |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
67 | |
| 6694 | 68 | GaimPlugin *tcl_interp_get_plugin(Tcl_Interp *interp) |
| 69 | { | |
| 70 | struct tcl_plugin_data *data; | |
| 71 | ||
| 72 | if (tcl_plugins == NULL) | |
| 73 | return NULL; | |
| 74 | ||
| 75 | data = g_hash_table_lookup(tcl_plugins, (gpointer)interp); | |
| 76 | return data != NULL ? data->plugin : NULL; | |
| 77 | } | |
| 78 | ||
| 79 | static int tcl_init_interp(Tcl_Interp *interp) | |
| 80 | { | |
| 81 | char *rcfile; | |
| 9943 | 82 | char init[] = |
| 6694 | 83 | "namespace eval ::gaim {\n" |
| 84 | " namespace export account buddy connection conversation\n" | |
| 85 | " namespace export core debug notify prefs send_im\n" | |
| 86 | " namespace export signal unload\n" | |
| 87 | " namespace eval _callback { }\n" | |
| 88 | "\n" | |
| 89 | " proc conv_send { account who text } {\n" | |
| 90 | " set gc [gaim::account connection $account]\n" | |
| 91 | " set convo [gaim::conversation new $account $who]\n" | |
| 92 | " set myalias [gaim::account alias $account]\n" | |
| 93 | "\n" | |
| 94 | " if {![string length $myalias]} {\n" | |
| 95 | " set myalias [gaim::account username $account]\n" | |
| 96 | " }\n" | |
| 97 | "\n" | |
| 98 | " gaim::send_im $gc $who $text\n" | |
| 99 | " gaim::conversation write $convo send $myalias $text\n" | |
| 100 | " }\n" | |
| 101 | "}\n" | |
| 102 | "\n" | |
| 103 | "proc bgerror { message } {\n" | |
| 104 | " global errorInfo\n" | |
| 105 | " gaim::notify -error \"Tcl Error\" \"Tcl Error: $message\" \"$errorInfo\"\n" | |
| 106 | "}\n"; | |
| 107 | ||
| 108 | if (Tcl_EvalEx(interp, init, -1, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 109 | return 1; | |
| 110 | } | |
| 111 | ||
| 112 | Tcl_SetVar(interp, "argc", "0", TCL_GLOBAL_ONLY); | |
| 113 | Tcl_SetVar(interp, "argv0", "gaim", TCL_GLOBAL_ONLY); | |
| 114 | Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY); | |
| 115 | rcfile = g_strdup_printf("%s" G_DIR_SEPARATOR_S "tclrc", gaim_user_dir()); | |
| 116 | Tcl_SetVar(interp, "tcl_rcFileName", rcfile, TCL_GLOBAL_ONLY); | |
| 117 | g_free(rcfile); | |
| 118 | ||
| 119 | Tcl_SetVar(interp, "::gaim::version", VERSION, TCL_GLOBAL_ONLY); | |
| 120 | Tcl_SetVar(interp, "::gaim::user_dir", gaim_user_dir(), TCL_GLOBAL_ONLY); | |
| 121 | #ifdef HAVE_TK | |
| 122 | Tcl_SetVar(interp, "::gaim::tk_available", "1", TCL_GLOBAL_ONLY); | |
| 123 | #else | |
| 124 | Tcl_SetVar(interp, "::gaim::tk_available", "0", TCL_GLOBAL_ONLY); | |
| 125 | #endif /* HAVE_TK */ | |
| 126 | ||
| 127 | Tcl_CreateObjCommand(interp, "::gaim::account", tcl_cmd_account, (ClientData)NULL, NULL); | |
| 128 | Tcl_CreateObjCommand(interp, "::gaim::buddy", tcl_cmd_buddy, (ClientData)NULL, NULL); | |
| 129 | Tcl_CreateObjCommand(interp, "::gaim::connection", tcl_cmd_connection, (ClientData)NULL, NULL); | |
| 130 | Tcl_CreateObjCommand(interp, "::gaim::conversation", tcl_cmd_conversation, (ClientData)NULL, NULL); | |
| 131 | Tcl_CreateObjCommand(interp, "::gaim::core", tcl_cmd_core, (ClientData)NULL, NULL); | |
| 132 | Tcl_CreateObjCommand(interp, "::gaim::debug", tcl_cmd_debug, (ClientData)NULL, NULL); | |
| 133 | Tcl_CreateObjCommand(interp, "::gaim::notify", tcl_cmd_notify, (ClientData)NULL, NULL); | |
| 134 | Tcl_CreateObjCommand(interp, "::gaim::prefs", tcl_cmd_prefs, (ClientData)NULL, NULL); | |
| 13823 | 135 | Tcl_CreateObjCommand(interp, "::gaim::presence", tcl_cmd_presence, (ClientData)NULL, NULL); |
| 6694 | 136 | Tcl_CreateObjCommand(interp, "::gaim::send_im", tcl_cmd_send_im, (ClientData)NULL, NULL); |
| 137 | Tcl_CreateObjCommand(interp, "::gaim::signal", tcl_cmd_signal, (ClientData)NULL, NULL); | |
| 13827 | 138 | Tcl_CreateObjCommand(interp, "::gaim::status", tcl_cmd_status, (ClientData)NULL, NULL); |
| 139 | Tcl_CreateObjCommand(interp, "::gaim::status_attr", tcl_cmd_status_attr, (ClientData)NULL, NULL); | |
| 13812 | 140 | Tcl_CreateObjCommand(interp, "::gaim::status_type", tcl_cmd_status_type, (ClientData)NULL, NULL); |
| 6694 | 141 | Tcl_CreateObjCommand(interp, "::gaim::unload", tcl_cmd_unload, (ClientData)NULL, NULL); |
| 142 | ||
| 143 | return 0; | |
| 144 | } | |
| 145 | ||
| 146 | static Tcl_Interp *tcl_create_interp() | |
| 147 | { | |
| 148 | Tcl_Interp *interp; | |
| 149 | ||
| 150 | interp = Tcl_CreateInterp(); | |
| 151 | if (Tcl_Init(interp) == TCL_ERROR) { | |
| 152 | Tcl_DeleteInterp(interp); | |
| 153 | return NULL; | |
| 154 | } | |
| 155 | ||
| 156 | if (tcl_init_interp(interp)) { | |
| 157 | Tcl_DeleteInterp(interp); | |
| 158 | return NULL; | |
| 159 | } | |
| 160 | Tcl_StaticPackage(interp, "gaim", tcl_init_interp, NULL); | |
| 161 | ||
| 162 | return interp; | |
| 163 | } | |
| 164 | ||
| 165 | static gboolean tcl_probe_plugin(GaimPlugin *plugin) | |
| 166 | { | |
| 167 | GaimPluginInfo *info; | |
| 168 | Tcl_Interp *interp; | |
| 169 | Tcl_Parse parse; | |
| 170 | Tcl_Obj *result, **listitems; | |
| 171 | struct stat st; | |
| 172 | FILE *fp; | |
| 173 | char *buf, *cur; | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
174 | const char *next; |
| 6694 | 175 | int len, found = 0, err = 0, nelems; |
| 176 | gboolean status = FALSE; | |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
10454
diff
changeset
|
177 | if ((fp = g_fopen(plugin->path, "r")) == NULL) |
| 6694 | 178 | return FALSE; |
| 179 | if (fstat(fileno(fp), &st)) { | |
| 180 | fclose(fp); | |
| 181 | return FALSE; | |
| 182 | } | |
| 183 | len = st.st_size; | |
| 184 | ||
| 185 | buf = g_malloc(len + 1); | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
186 | |
|
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
187 | cur = buf; |
| 8989 | 188 | while (fgets(cur, (int) buf - (buf - cur), fp)) { |
| 189 | cur += strlen(cur); | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
190 | if (feof(fp)) |
| 8989 | 191 | break; |
| 192 | } | |
| 193 | ||
| 194 | if (ferror(fp)) { | |
| 195 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "error reading %s (%s)\n", plugin->path, strerror(errno)); | |
| 6694 | 196 | g_free(buf); |
| 197 | fclose(fp); | |
| 198 | return FALSE; | |
| 199 | } | |
| 8989 | 200 | |
| 6694 | 201 | fclose(fp); |
| 202 | ||
| 203 | if ((interp = tcl_create_interp()) == NULL) { | |
| 204 | return FALSE; | |
| 205 | } | |
| 206 | ||
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
207 | next = buf; |
| 6694 | 208 | do { |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
209 | if (Tcl_ParseCommand(interp, next, len, 0, &parse) == TCL_ERROR) { |
| 6694 | 210 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "parse error in %s: %s\n", plugin->path, |
| 211 | Tcl_GetString(Tcl_GetObjResult(interp))); | |
| 212 | err = 1; | |
| 213 | break; | |
| 214 | } | |
| 215 | if (parse.tokenPtr[0].type == TCL_TOKEN_SIMPLE_WORD | |
| 216 | && !strncmp(parse.tokenPtr[0].start, "proc", parse.tokenPtr[0].size)) { | |
| 217 | if (!strncmp(parse.tokenPtr[2].start, "plugin_init", parse.tokenPtr[2].size)) { | |
| 218 | if (Tcl_EvalEx(interp, parse.commandStart, parse.commandSize, TCL_EVAL_GLOBAL) != TCL_OK) { | |
| 219 | Tcl_FreeParse(&parse); | |
| 220 | break; | |
| 221 | } | |
| 222 | found = 1; | |
| 223 | /* We'll continue parsing the file, just in case */ | |
| 224 | } | |
| 225 | } | |
|
10344
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
226 | len -= (parse.commandStart + parse.commandSize) - next; |
|
09d0502090b3
[gaim-migrate @ 11554]
Mark Doliner <markdoliner@pidgin.im>
parents:
10281
diff
changeset
|
227 | next = parse.commandStart + parse.commandSize; |
| 6694 | 228 | Tcl_FreeParse(&parse); |
| 229 | } while (len); | |
| 230 | ||
| 231 | if (found && !err) { | |
| 232 | if (Tcl_EvalEx(interp, "plugin_init", -1, TCL_EVAL_GLOBAL) == TCL_OK) { | |
| 233 | result = Tcl_GetObjResult(interp); | |
| 234 | if (Tcl_ListObjGetElements(interp, result, &nelems, &listitems) == TCL_OK) { | |
| 12987 | 235 | if ((nelems == 6) || (nelems == 7)) { |
| 6694 | 236 | info = g_new0(GaimPluginInfo, 1); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
237 | |
| 9943 | 238 | info->magic = GAIM_PLUGIN_MAGIC; |
| 239 | info->major_version = GAIM_MAJOR_VERSION; | |
| 240 | info->minor_version = GAIM_MINOR_VERSION; | |
| 6694 | 241 | info->type = GAIM_PLUGIN_STANDARD; |
| 242 | info->dependencies = g_list_append(info->dependencies, "core-tcl"); | |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
243 | |
| 6694 | 244 | info->name = g_strdup(Tcl_GetString(listitems[0])); |
| 245 | info->version = g_strdup(Tcl_GetString(listitems[1])); | |
| 8117 | 246 | info->summary = g_strdup(Tcl_GetString(listitems[2])); |
|
9775
e3a3555b0621
[gaim-migrate @ 10643]
Daniel Atallah <datallah@pidgin.im>
parents:
8993
diff
changeset
|
247 | info->description = g_strdup(Tcl_GetString(listitems[3])); |
|
10454
48b2b0d6a957
[gaim-migrate @ 11722]
Balwinder S Dheeman <bsd@rubyforge.org>
parents:
10344
diff
changeset
|
248 | info->author = g_strdup(Tcl_GetString(listitems[4])); |
| 8117 | 249 | info->homepage = g_strdup(Tcl_GetString(listitems[5])); |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
250 | |
| 12987 | 251 | if (nelems == 6) |
| 252 | info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[0])); | |
| 253 | else if (nelems == 7) | |
| 254 | info->id = g_strdup_printf("tcl-%s", Tcl_GetString(listitems[6])); | |
| 255 | ||
| 6694 | 256 | plugin->info = info; |
|
8761
2d596fd60ba8
[gaim-migrate @ 9516]
Mark Doliner <markdoliner@pidgin.im>
parents:
8759
diff
changeset
|
257 | |
| 6694 | 258 | if (gaim_plugin_register(plugin)) |
| 259 | status = TRUE; | |
| 260 | } | |
| 261 | } | |
| 262 | } | |
| 263 | } | |
| 264 | ||
| 265 | Tcl_DeleteInterp(interp); | |
| 266 | g_free(buf); | |
| 267 | return status; | |
| 268 | } | |
| 269 | ||
| 270 | static gboolean tcl_load_plugin(GaimPlugin *plugin) | |
| 271 | { | |
| 272 | struct tcl_plugin_data *data; | |
| 273 | Tcl_Interp *interp; | |
| 274 | Tcl_Obj *result; | |
| 275 | ||
| 276 | plugin->extra = NULL; | |
| 277 | ||
| 278 | if ((interp = tcl_create_interp()) == NULL) { | |
| 279 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Could not initialize Tcl interpreter\n"); | |
| 280 | return FALSE; | |
| 281 | } | |
| 282 | ||
| 283 | Tcl_SourceRCFile(interp); | |
| 284 | ||
| 285 | if (Tcl_EvalFile(interp, plugin->path) != TCL_OK) { | |
| 286 | result = Tcl_GetObjResult(interp); | |
| 287 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Error evaluating %s: %s\n", plugin->path, Tcl_GetString(result)); | |
| 288 | Tcl_DeleteInterp(interp); | |
| 289 | return FALSE; | |
| 290 | } | |
| 291 | ||
| 292 | Tcl_Preserve((ClientData)interp); | |
| 293 | ||
| 294 | data = g_new0(struct tcl_plugin_data, 1); | |
| 295 | data->plugin = plugin; | |
| 296 | data->interp = interp; | |
| 297 | plugin->extra = data; | |
| 298 | ||
| 299 | g_hash_table_insert(tcl_plugins, (gpointer)interp, (gpointer)data); | |
| 300 | ||
| 301 | return TRUE; | |
| 302 | } | |
| 303 | ||
| 304 | static gboolean tcl_unload_plugin(GaimPlugin *plugin) | |
| 305 | { | |
| 306 | struct tcl_plugin_data *data; | |
| 307 | ||
| 308 | if (plugin == NULL) | |
| 309 | return TRUE; | |
| 310 | ||
| 311 | data = plugin->extra; | |
| 312 | ||
| 313 | if (data != NULL) { | |
|
13439
1ef0c638a216
[gaim-migrate @ 15813]
Richard Laager <rlaager@pidgin.im>
parents:
13199
diff
changeset
|
314 | g_hash_table_remove(tcl_plugins, (gpointer)(data->interp)); |
| 6694 | 315 | gaim_signals_disconnect_by_handle(data->interp); |
| 316 | tcl_signal_cleanup(data->interp); | |
| 317 | Tcl_Release((ClientData)data->interp); | |
| 318 | Tcl_DeleteInterp(data->interp); | |
| 319 | g_free(data); | |
| 320 | } | |
| 321 | ||
| 322 | return TRUE; | |
| 323 | } | |
| 324 | ||
| 325 | static void tcl_destroy_plugin(GaimPlugin *plugin) | |
| 326 | { | |
| 327 | if (plugin->info != NULL) { | |
| 13199 | 328 | g_free(plugin->info->id); |
| 6694 | 329 | g_free(plugin->info->name); |
| 330 | g_free(plugin->info->version); | |
| 331 | g_free(plugin->info->description); | |
| 332 | g_free(plugin->info->author); | |
| 333 | g_free(plugin->info->homepage); | |
| 334 | } | |
| 335 | ||
| 336 | return; | |
| 337 | } | |
| 338 | ||
| 339 | static gboolean tcl_load(GaimPlugin *plugin) | |
| 340 | { | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
341 | if(!tcl_loaded) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
342 | return FALSE; |
| 6694 | 343 | tcl_glib_init(); |
| 344 | tcl_signal_init(); | |
| 13812 | 345 | gaim_tcl_ref_init(); |
| 346 | ||
| 347 | GaimTclRefAccount = gaim_stringref_new("Account"); | |
| 13817 | 348 | GaimTclRefConnection = gaim_stringref_new("Connection"); |
| 13812 | 349 | GaimTclRefConversation = gaim_stringref_new("Conversation"); |
| 13819 | 350 | GaimTclRefPointer = gaim_stringref_new("Pointer"); |
| 13823 | 351 | GaimTclRefPresence = gaim_stringref_new("Presence"); |
| 13812 | 352 | GaimTclRefStatus = gaim_stringref_new("Status"); |
| 353 | GaimTclRefStatusAttr = gaim_stringref_new("StatusAttr"); | |
| 354 | GaimTclRefStatusType = gaim_stringref_new("StatusType"); | |
| 355 | ||
| 6694 | 356 | tcl_plugins = g_hash_table_new(g_direct_hash, g_direct_equal); |
| 357 | ||
| 7828 | 358 | #ifdef HAVE_TK |
| 359 | Tcl_StaticPackage(NULL, "Tk", Tk_Init, Tk_SafeInit); | |
| 360 | #endif /* HAVE_TK */ | |
| 361 | ||
| 6694 | 362 | return TRUE; |
| 363 | } | |
| 364 | ||
| 365 | static gboolean tcl_unload(GaimPlugin *plugin) | |
| 366 | { | |
| 367 | g_hash_table_destroy(tcl_plugins); | |
| 368 | tcl_plugins = NULL; | |
| 369 | ||
| 13812 | 370 | gaim_stringref_unref(GaimTclRefAccount); |
| 13817 | 371 | gaim_stringref_unref(GaimTclRefConnection); |
| 13812 | 372 | gaim_stringref_unref(GaimTclRefConversation); |
| 13819 | 373 | gaim_stringref_unref(GaimTclRefPointer); |
| 13823 | 374 | gaim_stringref_unref(GaimTclRefPresence); |
| 13812 | 375 | gaim_stringref_unref(GaimTclRefStatus); |
| 376 | gaim_stringref_unref(GaimTclRefStatusAttr); | |
| 377 | gaim_stringref_unref(GaimTclRefStatusType); | |
| 378 | ||
| 6694 | 379 | return TRUE; |
| 380 | } | |
| 381 | ||
| 382 | static GaimPluginLoaderInfo tcl_loader_info = | |
| 383 | { | |
| 384 | NULL, | |
| 385 | tcl_probe_plugin, | |
| 386 | tcl_load_plugin, | |
| 387 | tcl_unload_plugin, | |
| 388 | tcl_destroy_plugin, | |
| 389 | }; | |
| 390 | ||
| 391 | static GaimPluginInfo tcl_info = | |
| 392 | { | |
| 9943 | 393 | GAIM_PLUGIN_MAGIC, |
| 394 | GAIM_MAJOR_VERSION, | |
| 395 | GAIM_MINOR_VERSION, | |
| 6694 | 396 | GAIM_PLUGIN_LOADER, |
| 397 | NULL, | |
| 398 | 0, | |
| 399 | NULL, | |
| 400 | GAIM_PRIORITY_DEFAULT, | |
| 401 | "core-tcl", | |
| 402 | N_("Tcl Plugin Loader"), | |
| 403 | VERSION, | |
| 404 | N_("Provides support for loading Tcl plugins"), | |
| 405 | N_("Provides support for loading Tcl plugins"), | |
| 406 | "Ethan Blanton <eblanton@cs.purdue.edu>", | |
| 407 | GAIM_WEBSITE, | |
| 408 | tcl_load, | |
| 409 | tcl_unload, | |
| 410 | NULL, | |
| 411 | NULL, | |
| 8993 | 412 | &tcl_loader_info, |
| 413 | NULL, | |
| 414 | NULL | |
| 6694 | 415 | }; |
| 416 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
417 | #ifdef _WIN32 |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
418 | typedef Tcl_Interp* (CALLBACK* LPFNTCLCREATEINTERP)(void); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
419 | typedef void (CALLBACK* LPFNTKINIT)(Tcl_Interp*); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
420 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
421 | LPFNTCLCREATEINTERP wtcl_CreateInterp = NULL; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
422 | LPFNTKINIT wtk_Init = NULL; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
423 | #undef Tcl_CreateInterp |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
424 | #define Tcl_CreateInterp wtcl_CreateInterp |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
425 | #undef Tk_Init |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
426 | #define Tk_Init wtk_Init |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
427 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
428 | static gboolean tcl_win32_init() { |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
429 | gaim_debug(GAIM_DEBUG_INFO, "tcl", |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
430 | "Initializing the Tcl runtime. If Gaim doesn't load, it is " |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
431 | "most likely because you have cygwin in your PATH and you " |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
432 | "should remove it. See http://gaim.sf.net/win32 for more " |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
433 | "information\n"); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
434 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
435 | if(!(wtcl_CreateInterp = (LPFNTCLCREATEINTERP) wgaim_find_and_loadproc("tcl84.dll", "Tcl_CreateInterp"))) { |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
436 | gaim_debug(GAIM_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tcl_CreateInterp\n"); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
437 | return FALSE; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
438 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
439 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
440 | if(!(wtk_Init = (LPFNTKINIT) wgaim_find_and_loadproc("tk84.dll", "Tk_Init"))) { |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
441 | HMODULE mod; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
442 | gaim_debug(GAIM_DEBUG_INFO, "tcl", "tcl_win32_init error loading Tk_Init\n"); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
443 | if((mod = GetModuleHandle("tcl84.dll"))) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
444 | FreeLibrary(mod); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
445 | return FALSE; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
446 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
447 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
448 | if (GetModuleHandle("cygwin1.dll")) { |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
449 | HMODULE mod; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
450 | gaim_debug(GAIM_DEBUG_INFO, "tcl", "Cygwin has been loaded by tcl84.dll and/or tk84.dll. Disabling Tcl support to avoid problems.\n"); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
451 | if((mod = GetModuleHandle("tcl84.dll"))) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
452 | FreeLibrary(mod); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
453 | if((mod = GetModuleHandle("tk84.dll"))) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
454 | FreeLibrary(mod); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
455 | return FALSE; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
456 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
457 | |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
458 | return TRUE; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
459 | } |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
460 | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
461 | #endif /* _WIN32 */ |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
462 | |
| 6694 | 463 | static void tcl_init_plugin(GaimPlugin *plugin) |
| 464 | { | |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
465 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
466 | Tcl_Interp *interp = NULL; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
467 | #endif |
| 6694 | 468 | _tcl_plugin = plugin; |
| 469 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
470 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
471 | #ifdef _WIN32 |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
472 | if(!tcl_win32_init()) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
473 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
474 | #endif |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
475 | if(!(interp = Tcl_CreateInterp())) |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
476 | return; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
477 | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
478 | if(!Tcl_InitStubs(interp, TCL_VERSION, 0)) { |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
479 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Tcl_InitStubs: %s\n", interp->result); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
480 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
481 | } |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
482 | #endif |
|
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
483 | |
| 6694 | 484 | Tcl_FindExecutable("gaim"); |
| 485 | ||
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
486 | #if defined(USE_TK_STUBS) && defined(HAVE_TK) |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
487 | Tk_Init(interp); |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
488 | |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
489 | if(!Tk_InitStubs(interp, TK_VERSION, 0)) { |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
490 | gaim_debug(GAIM_DEBUG_ERROR, "tcl", "Error Tk_InitStubs: %s\n", interp->result); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
491 | Tcl_DeleteInterp(interp); |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
492 | return; |
|
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
493 | } |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
494 | #endif |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
495 | tcl_loaded = TRUE; |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
496 | #ifdef USE_TCL_STUBS |
|
13456
4949b0656a2b
[gaim-migrate @ 15830]
Daniel Atallah <datallah@pidgin.im>
parents:
13439
diff
changeset
|
497 | Tcl_DeleteInterp(interp); |
|
7831
54076c9af6ad
[gaim-migrate @ 8483]
Herman Bloggs <herman@bluedigits.com>
parents:
7828
diff
changeset
|
498 | #endif |
| 6694 | 499 | tcl_loader_info.exts = g_list_append(tcl_loader_info.exts, "tcl"); |
| 500 | } | |
| 501 | ||
|
6735
a8c70aeddbe7
[gaim-migrate @ 7267]
Mark Doliner <markdoliner@pidgin.im>
parents:
6694
diff
changeset
|
502 | GAIM_INIT_PLUGIN(tcl, tcl_init_plugin, tcl_info) |