From 2bf21d6516ed44567e9cf842b25fc30a3affc03f Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 9 Feb 2014 06:27:44 -0600 Subject: upgraded format_magic() to hopefully be more compatible and less voodoo-y. --- segfault.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'segfault.c') diff --git a/segfault.c b/segfault.c index f3721b4..b98973c 100644 --- a/segfault.c +++ b/segfault.c @@ -111,6 +111,67 @@ struct tail { void message_handler(int fd,char *from,char *nick,char *msg,int redones); void c_untail(int fd,char *from, char *file); +char *format_magic(int fd,char *from,char *nick,char *orig_fmt,char *arg) { + int i,j; + int sz=0,c=1; + char *output; + char *fmt=strdup(orig_fmt); + char **args,**notargs; + for(i=0;fmt[i];i++) { + if(fmt[i] == '%') { + i++; + switch(fmt[i]) { + case 'u': + case 'f': + case 's': + c++; + } + } + } + args=malloc((sizeof(char *)) * (c + 1)); + notargs=malloc((sizeof(char *)) * (c + 2)); + c=0; + for(j=0,i=0;fmt[i];i++) { + if(fmt[i] == '%') { + i++; + switch(fmt[i]) { + case 'u': + args[c]=nick; + break; + case 'f': + args[c]=from; + break; + case 's': + args[c]=arg; + break; + } + switch(fmt[i]) { + case 'u': + case 'f': + case 's': + fmt[i-1]=0; + notargs[c]=strdup(fmt+j); + sz+=strlen(args[c]); + sz+=strlen(notargs[c]); + c++; + i++; + j=i; + break; + } + } + } + notargs[c]=strdup(fmt+j); + sz+=strlen(notargs[c]); + output=malloc(sz+1); + for(i=0;i