/* * TCL scripting extension. * * climm TCL extension Copyright (C) © 2007 Roman Hoog Antink * * This extension is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 dated June, 1991. * * This extension is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * In addition, as a special exception permission is granted to link the * code of this release of climm with the OpenSSL project's "OpenSSL" * library, and distribute the linked executables. You must obey the GNU * General Public License in all respects for all of the code used other * than "OpenSSL". If you modify this file, you may extend this exception * to your version of the file, but you are not obligated to do so. If you * do not wish to do so, delete this exception statement from your version * of this file. * * You should have received a copy of the GNU General Public License * along with this package; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * $Id$ */ #include "climm.h" #include #include "util_tcl.h" #ifdef ENABLE_TCL #include "contact.h" #include "preferences.h" #include "connection.h" #include "cmd_user.h" #include "util_str.h" #include "color.h" #if HAVE_TCL8_5_TCL_H #include #elif HAVE_TCL8_4_TCL_H #include #elif HAVE_TCL8_3_TCL_H #include #else #include #endif static Tcl_Interp *tinterp; static tcl_hook_p tcl_events = NULL; static tcl_hook_p tcl_msgs = NULL; static char tcl_inited = 0; static str_s buf = { NULL, 0, 0 }; char *RemEscapes (const char *s) { /* Ansi sequences: ESC [ m ESC ! ESC */ const char *c = s, *d; char *p, *q; q = strdup (s); for (p = q; *c; ) { if (*c == *ESC) { if (c[1] == '[') { d = strchr (c, 'm'); if (!d) c += 2; else c = d + 1; } else if (c[1] == '!' && c[2]) c += 3; else c += 2; } else *(p++) = *(c++); } *p = 0; return q; } TCL_CALLBACK (TCL_collect_out) { char *unes; unes = RemEscapes (s); s_cat (&buf, unes); free (unes); } TCL_COMMAND (TCL_command_help) { if (argc <= 2) { rl_printf (i18n (2346, "The following Tcl commands are supported:\n")); CMD_USER_HELP ("climm receive