diff -r a6692d249139 sic.1 --- a/sic.1 Fri Apr 13 11:50:51 2007 +0200 +++ b/sic.1 Thu Aug 09 18:41:45 2007 -0700 @@ -44,4 +44,7 @@ Write a message to #channel/user .B :s #channel/user Set default channel/user .TP +.B :a alias #channel/user +Set alias for #channel/user. Can then use alias instead of #channel/user for :j, :l, and :m +.TP Everything which is not a command is simply send the server. diff -r a6692d249139 sic.c --- a/sic.c Fri Apr 13 11:50:51 2007 +0200 +++ b/sic.c Thu Aug 09 18:41:45 2007 -0700 @@ -15,6 +15,7 @@ #define PINGTIMEOUT 300 #define MAXMSG 4096 +#define MAXALIAS 256 static char *host = "irc.oftc.net"; static unsigned short port = 6667; @@ -23,6 +24,8 @@ static char nick[32]; static char bufin[MAXMSG], bufout[MAXMSG]; static char channel[256]; +static char alias[MAXALIAS][256]; +static int num_alias = 0; static int srv; static time_t trespond; @@ -60,10 +63,23 @@ pout(char *channel, char *msg) { fprintf(stdout, "%-12.12s: %s %s\n", channel, timestr, msg); } +static char* +alias_lookup(char *channel) { + int i; + char *p; + for(i = 0; i < 256; i++) { + p = strchr(alias[i], ' '); + if(!strncmp(channel, alias[i], p - alias[i])) + break; + } + return (i < 256)? p+1 : channel; +} + static void privmsg(char *channel, char *msg) { if(channel[0] == 0) return; + channel = alias_lookup(channel); snprintf(bufout, sizeof bufout, "<%s> %s", nick, msg); pout(channel, bufout); snprintf(bufout, sizeof bufout, "PRIVMSG %s :%s\r\n", channel, msg); @@ -80,10 +96,12 @@ parsein(char *msg) { privmsg(channel, msg); return; } - if(!strncmp(msg + 1, "j ", 2) && (msg[3] == '#')) - snprintf(bufout, sizeof bufout, "JOIN %s\r\n", msg + 3); + if(!strncmp(msg + 1, "j ", 2)) + msg = alias_lookup(msg+3), snprintf(bufout, sizeof bufout, "JOIN %s\r\n", msg); else if(!strncmp(msg + 1, "l ", 2)) - snprintf(bufout, sizeof bufout, "PART %s :sic - 250 LOC are too much!\r\n", msg + 3); + msg = alias_lookup(msg+3), snprintf(bufout, sizeof bufout, "PART %s :sic - 250 LOC are too much!\r\n", msg); + else if(!strncmp(msg + 1, "a ", 2)) + strncpy(alias[num_alias], msg + 3, sizeof alias[num_alias]), num_alias++, snprintf(bufout, sizeof bufout, ""); else if(!strncmp(msg + 1, "m ", 2)) { if((p = strchr(msg + 3, ' '))) *(p++) = 0;