Re: [hackers] [SIC] alias patch

From: Kris Maglione <jg_AT_suckless.org>
Date: Thu, 9 Aug 2007 22:34:03 -0400

Something like this; it's longer than yours, but with more
functionality. I'm not really sure of its usefulness.

--- sic.c Thu Aug 9 18:11:09 2007
+++ - Thu Aug 9 22:32:36 2007
@@ -22,6 +22,7 @@
  static char *password;
  static char nick[32];
  
+static char *alias[256];
  static char bufin[4096];
  static char bufout[4096];
  static char channel[256];
@@ -67,7 +68,7 @@
  }
  
  static void
-parsein(char *msg) {
+parsein(int n, char *msg) {
          char *p;
          char c;
  
@@ -85,6 +86,12 @@
                  if(msg[1])
                          msg += 2;
                  switch(c) {
+ case 'a':
+ c = tok(&msg)[0];
+ if(alias[c])
+ free(alias[c]);
+ alias[c] = strdup(msg);
+ break;
                  case 'j':
                          sout("JOIN %s", msg);
                          if(channel[0] == '\0')
@@ -106,6 +113,16 @@
                          strlcpy(channel, msg, sizeof channel);
                          break;
                  default:
+ if(n > 30) {
+ print("sic: alias loop\n");
+ return;
+ }
+ if(alias[c]) {
+ p = malloc(strlen(msg)+strlen(alias[c])+2);
+ sprint(p, "%s %s", alias[c], msg);
+ parsein(n+1, p);
+ free(p);
+ }
                          sout("%c %s", c, msg);
                          break;
                  }
@@ -214,7 +231,7 @@
                  if(FD_ISSET(0, &rd)) {
                          if(fgets(bufin, sizeof bufin, stdin) == nil)
                                  eprint("sic: broken pipe\n");
- parsein(bufin);
+ parsein(0, bufin);
                  }
          }
          return 0;

-- 
Kris Maglione
The race is not always to the swift nor the battle to the
strong, but that's the way to bet.
Received on Fri Aug 10 2007 - 04:34:33 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:57:47 UTC