summaryrefslogtreecommitdiff
path: root/testing.c
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2014-02-05 04:27:07 -0600
committerepoch <epoch@hacking.allowed.org>2014-02-05 04:27:07 -0600
commit8ea60384731c92fe1daa64160f6cacc33177066d (patch)
treed68c6d74cab9b5d76562d386da5addba15eca40f /testing.c
parent517add9afbc9ffbc0cf3425074ecb093fa59fdca (diff)
downloadsegfault-8ea60384731c92fe1daa64160f6cacc33177066d.tar.gz
segfault-8ea60384731c92fe1daa64160f6cacc33177066d.zip
first useful commit. hopefully it compiles...
Diffstat (limited to 'testing.c')
-rw-r--r--testing.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/testing.c b/testing.c
new file mode 100644
index 0000000..63c2620
--- /dev/null
+++ b/testing.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+
+char *format_magic(char *from,char *nick,char *fmt,char *arg);
+
+int main(int argc,char *argv[]) {
+ char *o=format_magic("#default","epoch",argv[1],argv[2]);
+ printf("%s\n",o);
+ return 0;
+}
+
+char *format_magic(char *from,char *nick,char *fmt,char *arg) {
+ int i;
+ int j;
+ int c=1;
+ for(i=0;fmt[i];i++) {
+ if(fmt[i] == '%') {
+ i++;
+ switch(fmt[i]) {
+ case 0:
+ printf("error! last character is a '%'!!!\n");
+ exit(1);
+ case 'u':
+ case 'f':
+ case 's':
+ c++;
+ }
+ }
+ }
+ char **args=malloc((sizeof(char *)) * (c + 1));
+ c=0;
+ for(i=0;fmt[i];i++) {
+ if(fmt[i] == '%') {
+ i++;
+ switch(fmt[i]) {
+ case 0:
+ printf("error! last character is a '%'!!!\n");
+ exit(1);
+ case 'u':
+ args[c]=nick;
+ fmt[i]='s';
+ c++;
+ break;
+ case 'f':
+ args[c]=from;
+ fmt[i]='s';
+ c++;
+ break;
+ case 's':
+ args[c]=arg;
+ c++;
+ break;
+ }
+ }
+ }
+// args[c]=0;
+// for(i=0;i<c;i++) {
+// printf("args[%d]=%s\n",i,args[i]);
+// }
+// printf("format string: %s\nc: %d\n",fmt,c);
+ int sz=vprintf(fmt,args)+1;
+// printf("\nsize: %d\n",sz);
+ char *output=malloc(sz);
+ vsnprintf(output,sz,fmt,args);
+ return output;
+}