Mercurial > pidgin
comparison libpurple/plugins/tcl/tcl_cmd.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 19 Mar 2007 07:01:17 +0000 |
parents | 5fe8042783c1 |
children | 44b4e8bd759b |
comparison
equal
deleted
inserted
replaced
15821:84b0f9b23ede | 15822:32c366eeeb99 |
---|---|
1 /** | 1 /** |
2 * @file tcl_cmd.c Gaim Tcl cmd API | 2 * @file tcl_cmd.c Purple Tcl cmd API |
3 * | 3 * |
4 * gaim | 4 * purple |
5 * | 5 * |
6 * Copyright (C) 2006 Etan Reisner <deryni@gmail.com> | 6 * Copyright (C) 2006 Etan Reisner <deryni@gmail.com> |
7 * | 7 * |
8 * This program is free software; you can redistribute it and/or modify | 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 | 9 * it under the terms of the GNU General Public License as published by |
19 * along with this program; if not, write to the Free Software | 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 | 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 */ | 21 */ |
22 #include <tcl.h> | 22 #include <tcl.h> |
23 | 23 |
24 #include "tcl_gaim.h" | 24 #include "tcl_purple.h" |
25 | 25 |
26 #include "internal.h" | 26 #include "internal.h" |
27 #include "cmds.h" | 27 #include "cmds.h" |
28 #include "debug.h" | 28 #include "debug.h" |
29 | 29 |
30 static GList *tcl_cmd_callbacks; | 30 static GList *tcl_cmd_callbacks; |
31 | 31 |
32 static GaimCmdRet tcl_cmd_callback(GaimConversation *conv, const gchar *cmd, | 32 static PurpleCmdRet tcl_cmd_callback(PurpleConversation *conv, const gchar *cmd, |
33 gchar **args, gchar **errors, | 33 gchar **args, gchar **errors, |
34 struct tcl_cmd_handler *handler); | 34 struct tcl_cmd_handler *handler); |
35 static Tcl_Obj *new_cmd_cb_namespace(void); | 35 static Tcl_Obj *new_cmd_cb_namespace(void); |
36 | 36 |
37 void tcl_cmd_init() | 37 void tcl_cmd_init() |
54 struct tcl_cmd_handler *handler; | 54 struct tcl_cmd_handler *handler; |
55 | 55 |
56 for (cur = tcl_cmd_callbacks; cur != NULL; cur = g_list_next(cur)) { | 56 for (cur = tcl_cmd_callbacks; cur != NULL; cur = g_list_next(cur)) { |
57 handler = cur->data; | 57 handler = cur->data; |
58 if (handler->interp == interp) { | 58 if (handler->interp == interp) { |
59 gaim_cmd_unregister(handler->id); | 59 purple_cmd_unregister(handler->id); |
60 tcl_cmd_handler_free(handler); | 60 tcl_cmd_handler_free(handler); |
61 cur->data = NULL; | 61 cur->data = NULL; |
62 } | 62 } |
63 } | 63 } |
64 tcl_cmd_callbacks = g_list_remove_all(tcl_cmd_callbacks, NULL); | 64 tcl_cmd_callbacks = g_list_remove_all(tcl_cmd_callbacks, NULL); |
65 } | 65 } |
66 | 66 |
67 GaimCmdId tcl_cmd_register(struct tcl_cmd_handler *handler) | 67 PurpleCmdId tcl_cmd_register(struct tcl_cmd_handler *handler) |
68 { | 68 { |
69 int id; | 69 int id; |
70 GString *proc; | 70 GString *proc; |
71 | 71 |
72 if ((id = gaim_cmd_register(Tcl_GetString(handler->cmd), | 72 if ((id = purple_cmd_register(Tcl_GetString(handler->cmd), |
73 handler->args, handler->priority, | 73 handler->args, handler->priority, |
74 handler->flags, handler->prpl_id, | 74 handler->flags, handler->prpl_id, |
75 GAIM_CMD_FUNC(tcl_cmd_callback), | 75 PURPLE_CMD_FUNC(tcl_cmd_callback), |
76 handler->helpstr, (void *)handler)) == 0) | 76 handler->helpstr, (void *)handler)) == 0) |
77 return 0; | 77 return 0; |
78 | 78 |
79 handler->namespace = new_cmd_cb_namespace (); | 79 handler->namespace = new_cmd_cb_namespace (); |
80 Tcl_IncrRefCount(handler->namespace); | 80 Tcl_IncrRefCount(handler->namespace); |
92 tcl_cmd_callbacks = g_list_append(tcl_cmd_callbacks, (gpointer)handler); | 92 tcl_cmd_callbacks = g_list_append(tcl_cmd_callbacks, (gpointer)handler); |
93 | 93 |
94 return id; | 94 return id; |
95 } | 95 } |
96 | 96 |
97 void tcl_cmd_unregister(GaimCmdId id, Tcl_Interp *interp) | 97 void tcl_cmd_unregister(PurpleCmdId id, Tcl_Interp *interp) |
98 { | 98 { |
99 GList *cur; | 99 GList *cur; |
100 GString *cmd; | 100 GString *cmd; |
101 gboolean found = FALSE; | 101 gboolean found = FALSE; |
102 struct tcl_cmd_handler *handler; | 102 struct tcl_cmd_handler *handler; |
103 | 103 |
104 for (cur = tcl_cmd_callbacks; cur != NULL; cur = g_list_next(cur)) { | 104 for (cur = tcl_cmd_callbacks; cur != NULL; cur = g_list_next(cur)) { |
105 handler = cur->data; | 105 handler = cur->data; |
106 if (handler->interp == interp && handler->id == id) { | 106 if (handler->interp == interp && handler->id == id) { |
107 gaim_cmd_unregister(id); | 107 purple_cmd_unregister(id); |
108 cmd = g_string_sized_new(64); | 108 cmd = g_string_sized_new(64); |
109 g_string_printf(cmd, "namespace delete %s", | 109 g_string_printf(cmd, "namespace delete %s", |
110 Tcl_GetString(handler->namespace)); | 110 Tcl_GetString(handler->namespace)); |
111 Tcl_EvalEx(interp, cmd->str, -1, TCL_EVAL_GLOBAL); | 111 Tcl_EvalEx(interp, cmd->str, -1, TCL_EVAL_GLOBAL); |
112 tcl_cmd_handler_free(handler); | 112 tcl_cmd_handler_free(handler); |
119 | 119 |
120 if (found) | 120 if (found) |
121 tcl_cmd_callbacks = g_list_remove_all(tcl_cmd_callbacks, NULL); | 121 tcl_cmd_callbacks = g_list_remove_all(tcl_cmd_callbacks, NULL); |
122 } | 122 } |
123 | 123 |
124 static GaimCmdRet tcl_cmd_callback(GaimConversation *conv, const gchar *cmd, | 124 static PurpleCmdRet tcl_cmd_callback(PurpleConversation *conv, const gchar *cmd, |
125 gchar **args, gchar **errors, | 125 gchar **args, gchar **errors, |
126 struct tcl_cmd_handler *handler) | 126 struct tcl_cmd_handler *handler) |
127 { | 127 { |
128 int retval, error, i; | 128 int retval, error, i; |
129 Tcl_Obj *command, *arg, *tclargs, *result; | 129 Tcl_Obj *command, *arg, *tclargs, *result; |
135 arg = Tcl_DuplicateObj(handler->namespace); | 135 arg = Tcl_DuplicateObj(handler->namespace); |
136 Tcl_AppendStringsToObj(arg, "::cb", NULL); | 136 Tcl_AppendStringsToObj(arg, "::cb", NULL); |
137 Tcl_ListObjAppendElement(handler->interp, command, arg); | 137 Tcl_ListObjAppendElement(handler->interp, command, arg); |
138 | 138 |
139 /* The conversation */ | 139 /* The conversation */ |
140 arg = gaim_tcl_ref_new(GaimTclRefConversation, conv); | 140 arg = purple_tcl_ref_new(PurpleTclRefConversation, conv); |
141 Tcl_ListObjAppendElement(handler->interp, command, arg); | 141 Tcl_ListObjAppendElement(handler->interp, command, arg); |
142 | 142 |
143 /* The command */ | 143 /* The command */ |
144 arg = Tcl_NewStringObj(cmd, -1); | 144 arg = Tcl_NewStringObj(cmd, -1); |
145 Tcl_ListObjAppendElement(handler->interp, command, arg); | 145 Tcl_ListObjAppendElement(handler->interp, command, arg); |
157 TCL_EVAL_GLOBAL)) != TCL_OK) { | 157 TCL_EVAL_GLOBAL)) != TCL_OK) { |
158 gchar *errorstr; | 158 gchar *errorstr; |
159 | 159 |
160 errorstr = g_strdup_printf("error evaluating callback: %s\n", | 160 errorstr = g_strdup_printf("error evaluating callback: %s\n", |
161 Tcl_GetString(Tcl_GetObjResult(handler->interp))); | 161 Tcl_GetString(Tcl_GetObjResult(handler->interp))); |
162 gaim_debug(GAIM_DEBUG_ERROR, "tcl", errorstr); | 162 purple_debug(PURPLE_DEBUG_ERROR, "tcl", errorstr); |
163 *errors = errorstr; | 163 *errors = errorstr; |
164 retval = GAIM_CMD_RET_FAILED; | 164 retval = PURPLE_CMD_RET_FAILED; |
165 } else { | 165 } else { |
166 result = Tcl_GetObjResult(handler->interp); | 166 result = Tcl_GetObjResult(handler->interp); |
167 if ((error = Tcl_GetIntFromObj(handler->interp, result, | 167 if ((error = Tcl_GetIntFromObj(handler->interp, result, |
168 &retval)) != TCL_OK) { | 168 &retval)) != TCL_OK) { |
169 gchar *errorstr; | 169 gchar *errorstr; |
170 | 170 |
171 errorstr = g_strdup_printf("Error retreiving procedure result: %s\n", | 171 errorstr = g_strdup_printf("Error retreiving procedure result: %s\n", |
172 Tcl_GetString(Tcl_GetObjResult(handler->interp))); | 172 Tcl_GetString(Tcl_GetObjResult(handler->interp))); |
173 gaim_debug(GAIM_DEBUG_ERROR, "tcl", errorstr); | 173 purple_debug(PURPLE_DEBUG_ERROR, "tcl", errorstr); |
174 *errors = errorstr; | 174 *errors = errorstr; |
175 retval = GAIM_CMD_RET_FAILED; | 175 retval = PURPLE_CMD_RET_FAILED; |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 return retval; | 179 return retval; |
180 } | 180 } |
182 static Tcl_Obj *new_cmd_cb_namespace() | 182 static Tcl_Obj *new_cmd_cb_namespace() |
183 { | 183 { |
184 char name[32]; | 184 char name[32]; |
185 static int cbnum; | 185 static int cbnum; |
186 | 186 |
187 g_snprintf(name, sizeof(name), "::gaim::_cmd_callback::cb_%d", | 187 g_snprintf(name, sizeof(name), "::purple::_cmd_callback::cb_%d", |
188 cbnum++); | 188 cbnum++); |
189 return Tcl_NewStringObj(name, -1); | 189 return Tcl_NewStringObj(name, -1); |
190 } | 190 } |