summaryrefslogtreecommitdiff
path: root/segfault.c
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2014-02-09 06:27:44 -0600
committerepoch <epoch@hacking.allowed.org>2014-02-09 06:27:44 -0600
commit2bf21d6516ed44567e9cf842b25fc30a3affc03f (patch)
tree327d5a9bf3ec02a43a4ceb73117bbf4870cc968e /segfault.c
parent8ea60384731c92fe1daa64160f6cacc33177066d (diff)
downloadsegfault-2bf21d6516ed44567e9cf842b25fc30a3affc03f.tar.gz
segfault-2bf21d6516ed44567e9cf842b25fc30a3affc03f.zip
upgraded format_magic() to hopefully be more compatible and less voodoo-y.
Diffstat (limited to 'segfault.c')
-rw-r--r--segfault.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/segfault.c b/segfault.c
index f3721b4..b98973c 100644
--- a/segfault.c
+++ b/segfault.c
@@ -112,6 +112,67 @@ 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<c;i++) {
+ strcat(output,notargs[i]);
+ strcat(output,args[i]);
+ }
+ strcat(output,notargs[i]);
+ free(fmt);
+ return output;
+}
+/*
+char *format_magic(int fd,char *from,char *nick,char *orig_fmt,char *arg) {
int i;
int c=1;
char *fmt=strdup(orig_fmt);
@@ -167,7 +228,7 @@ char *format_magic(int fd,char *from,char *nick,char *orig_fmt,char *arg) {
free(fmt);
return output;
}
-
+*/
//get rid of this?
char *good_format_string(int fd,char *from,char *line) {
int i;