]> jfr.im git - irc/xchat.git/commitdiff
Added word and word_eol procedures
authormooooooo <redacted>
Sun, 21 Mar 2010 00:49:41 +0000 (00:49 +0000)
committermooooooo <redacted>
Sun, 21 Mar 2010 00:49:41 +0000 (00:49 +0000)
git-svn-id: svn://svn.code.sf.net/p/xchat/svn@1403 893a96be-7f27-4fdf-9d1e-6aeec9d3cce1

plugins/tcl/tclplugin.c
plugins/tcl/tclplugin.h

index ba49d109869db61f2872d07acfb1579c8e3d8d1c..17dc7556fec59a6fe21d40e6615e2e5ea18bca97 100755 (executable)
@@ -2,8 +2,8 @@
                            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
  ***************************************************************************/
 
 /***************************************************************************
@@ -15,7 +15,7 @@
  *                                                                         *
  ***************************************************************************/
 
-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>
@@ -132,6 +132,11 @@ static char inlinetcl[] = {
 "      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 ()
@@ -442,6 +447,8 @@ static int Server_raw_line(char *word[], char *word_eol[], void *userdata)
     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];
@@ -569,6 +576,8 @@ static int Print_Hook(char *word[], void *userdata)
     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) {
 
@@ -1860,6 +1869,40 @@ static int tcl_xchat_nickcmp(ClientData cd, Tcl_Interp * irp, int argc, const ch
     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;
@@ -1874,6 +1917,8 @@ static int Command_Alias(char *word[], char *word_eol[], void *userdata)
     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);
 
@@ -1914,6 +1959,8 @@ static int Null_Command_Alias(char *word[], char *word_eol[], void *userdata)
     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++;
 
@@ -1946,11 +1993,19 @@ static int Null_Command_Alias(char *word[], char *word_eol[], void *userdata)
 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;
 }
 
@@ -1965,6 +2020,10 @@ static int Command_Source(char *word[], char *word_eol[], void *userdata)
     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) {
@@ -1991,10 +2050,14 @@ static int Command_Source(char *word[], char *word_eol[], void *userdata)
 
         Tcl_DStringFree(&ds);
 
+        complete_level--;
+
         return XCHAT_EAT_XCHAT;
 
-    } else
+    } else {
+        complete_level--;
         return XCHAT_EAT_NONE;
+    }
 
 }
 
@@ -2002,7 +2065,9 @@ static int Command_Reloadall(char *word[], char *word_eol[], void *userdata)
 {
     Tcl_Plugin_DeInit();
     Tcl_Plugin_Init();
+
     xchat_print(ph, "\0039Tcl plugin\003\tRehashed\n");
+
     return XCHAT_EAT_ALL;
 }
 
@@ -2056,6 +2121,8 @@ static void Tcl_Plugin_Init()
     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);
index 489374a74739edda91fe4a8d46b630551ab74f38..075c28f827e94e262972bb8786d2621af8869147 100755 (executable)
@@ -2,8 +2,8 @@
                            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
  ***************************************************************************/
 
 /***************************************************************************
@@ -44,9 +44,11 @@ typedef struct {
 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);
@@ -80,6 +82,8 @@ static int tcl_me(ClientData cd, Tcl_Interp * irp, int argc, const char *argv[])
 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);