tclplugin.c - Tcl plugin for xchat 1.9.x / 2.x.x
-------------------------------------------------s
begin : Sat Nov 19 17:31:20 MST 2002
- copyright : Copyright 2002-2007 Daniel P. Stasinski
- email : mooooooo@avenues.org
+ copyright : Copyright 2002-2010 Daniel P. Stasinski
+ email : daniel@avenues.org
***************************************************************************/
/***************************************************************************
* *
***************************************************************************/
-static char RCSID[] = "$Id: tclplugin.c,v 1.63 2007-11-18 00:04:33 zed Exp $";
+static char RCSID[] = "$Id: tclplugin.c,v 1.64 2010/03/10 04:24:16 mooooooo Exp $";
#include <stdio.h>
#include <stdlib.h>
" set text [split $::errorInfo \\n]\n"
" puts [string trim [join [lrange $text 0 [expr {[llength $text] - 4}]] \\n]]\n"
"}\n"
+
+"proc ::bgerror { message } {\n"
+" set text [split $::errorInfo \\n]\n"
+" puts [string trim [join [lrange $text 0 [expr {[llength $text] - 4}]] \\n]]\n"
+"}\n"
};
static void NiceErrorInfo ()
complete_level++;
complete[complete_level].defresult = XCHAT_EAT_NONE; /* XCHAT_EAT_PLUGIN; */
complete[complete_level].result = XCHAT_EAT_NONE;
+ complete[complete_level].word = word;
+ complete[complete_level].word_eol = word_eol;
if (word[1][0] == ':') {
src = word[1];
complete_level++;
complete[complete_level].defresult = XCHAT_EAT_NONE; /* XCHAT_EAT_PLUGIN; */
complete[complete_level].result = XCHAT_EAT_NONE;
+ complete[complete_level].word = word;
+ complete[complete_level].word_eol = word;
if ((entry = Tcl_FindHashEntry(&cmdTablePtr, xc[(int) userdata].event)) != NULL) {
return TCL_OK;
}
+static int tcl_word(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[])
+{
+ int index;
+
+ BADARGS(2, 2, " index");
+
+ if (Tcl_GetInt(irp, argv[1], &index) != TCL_OK)
+ return TCL_ERROR;
+
+ if (!index || (index > 31))
+ Tcl_AppendResult(interp, "", NULL);
+ else
+ Tcl_AppendResult(interp, complete[complete_level].word[index], NULL);
+
+ return TCL_OK;
+}
+
+static int tcl_word_eol(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[])
+{
+ int index;
+
+ BADARGS(2, 2, " index");
+
+ if (Tcl_GetInt(irp, argv[1], &index) != TCL_OK)
+ return TCL_ERROR;
+
+ if (!index || (index > 31))
+ Tcl_AppendResult(interp, "", NULL);
+ else
+ Tcl_AppendResult(interp, complete[complete_level].word_eol[index], NULL);
+
+ return TCL_OK;
+}
+
static int Command_Alias(char *word[], char *word_eol[], void *userdata)
{
alias *aliasPtr;
complete_level++;
complete[complete_level].defresult = XCHAT_EAT_ALL;
complete[complete_level].result = XCHAT_EAT_NONE;
+ complete[complete_level].word = word;
+ complete[complete_level].word_eol = word_eol;
string = StrDup(word[1], &dummy);
complete_level++;
complete[complete_level].defresult = XCHAT_EAT_ALL;
complete[complete_level].result = XCHAT_EAT_NONE;
+ complete[complete_level].word = word;
+ complete[complete_level].word_eol = word_eol;
recurse++;
static int Command_TCL(char *word[], char *word_eol[], void *userdata)
{
const char *errorInfo;
+
+ complete_level++;
+ complete[complete_level].word = word;
+ complete[complete_level].word_eol = word_eol;
+
if (Tcl_Eval(interp, word_eol[2]) == TCL_ERROR) {
errorInfo = Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY);
xchat_printf(ph, "\0039Tcl plugin\003\tERROR: %s ", errorInfo);
} else
xchat_printf(ph, "\0039Tcl plugin\003\tRESULT: %s ", Tcl_GetStringResult(interp));
+
+ complete_level--;
+
return XCHAT_EAT_ALL;
}
if (!strlen(word_eol[2]))
return XCHAT_EAT_NONE;
+ complete_level++;
+ complete[complete_level].word = word;
+ complete[complete_level].word_eol = word_eol;
+
len = strlen(word[2]);
if (len > 4 && strcasecmp(".tcl", word[2] + len - 4) == 0) {
Tcl_DStringFree(&ds);
+ complete_level--;
+
return XCHAT_EAT_XCHAT;
- } else
+ } else {
+ complete_level--;
return XCHAT_EAT_NONE;
+ }
}
{
Tcl_Plugin_DeInit();
Tcl_Plugin_Init();
+
xchat_print(ph, "\0039Tcl plugin\003\tRehashed\n");
+
return XCHAT_EAT_ALL;
}
Tcl_CreateCommand(interp, "timers", tcl_timers, NULL, NULL);
Tcl_CreateCommand(interp, "topic", tcl_topic, NULL, NULL);
Tcl_CreateCommand(interp, "users", tcl_users, NULL, NULL);
+ Tcl_CreateCommand(interp, "word", tcl_word, NULL, NULL);
+ Tcl_CreateCommand(interp, "word_eol", tcl_word_eol, NULL, NULL);
Tcl_InitHashTable(&cmdTablePtr, TCL_STRING_KEYS);
Tcl_InitHashTable(&aliasTablePtr, TCL_STRING_KEYS);
tclplugin.h - TCL plugin header file
-------------------------------------------------
begin : Sat Nov 9 17:31:20 MST 2002
- copyright : Copyright 2002-2005 Daniel P. Stasinski
- email : mooooooo@avenues.org
+ copyright : Copyright 2002-2010 Daniel P. Stasinski
+ email : daniel@avenues.org
***************************************************************************/
/***************************************************************************
typedef struct {
int result;
int defresult;
+ char **word;
+ char **word_eol;
} t_complete;
-#define MAX_TIMERS 256
+#define MAX_TIMERS 512
#define MAX_COMPLETES 128
static char *StrDup(const char *string, int *length);
static int tcl_xchat_nickcmp(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[]);
static int tcl_strip(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[]);
static int tcl_topic(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[]);
+static int tcl_word(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[]);
+static int tcl_word_eol(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[]);
static int tcl_notifylist(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[]);
static int Command_Alias(char *word[], char *word_eol[], void *userdata);
static int Null_Command_Alias(char *word[], char *word_eol[], void *userdata);