New patch again. I was working on it before I got your latest message
Kris, so it doesn't follow your code, although it probably should, as
that's most likely a cleaner way to do it. As it is now, I've added
recursive aliases to the mix. Some examples...
:a long #thisisalongchannelname
:a mlong :m long
:j long
:mlong message to #thisisalongchannelname
:l long
:a bot :m bot_name
:bot command to bot
:a com :bot frequently used command
:com parameters to command
:a foo :bar
:a bar :foo
:foo
results in
emg : 08/10/07 20:25 <sic> alias loop
This patch can be applied to the current tip and updates the man page
accordingly. Let me know if you have find any problems. I'll most
likely be trying to change over to the way Kris suggested.
-E
On 8/10/07, Kris Maglione <jg_AT_suckless.org> wrote:
> Something like this (still doesn't apply to channel name as
> yours does; still untested; could be shorter);
>
> #define nelem(x) (sizeof(x)/sizeof *(x))
> static char *alias[256][2];
> static int nalias;
>
> static char**
> getalias(char *a) {
> int i;
>
> for(i=0; i < nalias; i++)
> if(!strcmp(a, alias[i][0]))
> return alias[i];
> return nil;
> }
>
> static void
> parsein(long n, char *msg) {
> char *p, **q;
>
> if(msg[0] == '\0')
> return;
> msg = ctok(&msg, '\n');
> if(msg[0] != ':') {
> privmsg(channel, msg);
> return;
> }
> msg++;
> p = tok(&msg);
> if(!p[0] || p[1])
> goto casdef;
> else {
> if(msg[1])
> msg += 2;
> switch(p[1]) {
> case 'a':
> p = tok(&msg);
> if(!p)
> return;
> if((q = getalias(p)))
> free(q[1]);
> else
> q = alias[nalias++];
> assert(nalias <= nelem(alias));
> q[1] = strdup(msg);
> break;
> /* ... */
> default:
> casdef:
> if((q = getalias(p))) {
> assert(n < 50);
> p = smprint("%s %s", q[1], msg);
> parsein(n+1, p);
> free(p);
> }else
> sout("%s %s", p, msg);
> break;
> }
> }
> }
>
> /* ... */
>
> static char*
> smprint(const char *fmt, ...) {
> va_list ap;
> char *buf = "";
> int n;
>
> va_start(ap, fmt);
> n = snprintf(buf, 0, fmt, ap);
> va_end(ap);
>
> buf = malloc(++n);
> if(buf) {
> va_start(ap, fmt);
> snprintf(buf, n, fmt, ap);
> va_end(ap);
> }
> return buf;
> }
>
> --
> Kris Maglione
>
> If you are given an open-book exam, you will forget
> your book.
> If you are given a take-home exam, you will forget
> where you live.
>
>
Received on Sat Aug 11 2007 - 05:26:24 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:57:49 UTC