summaryrefslogtreecommitdiff
path: root/sys/src/libhttpd/httpfmt.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/libhttpd/httpfmt.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/libhttpd/httpfmt.c')
-rwxr-xr-xsys/src/libhttpd/httpfmt.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sys/src/libhttpd/httpfmt.c b/sys/src/libhttpd/httpfmt.c
new file mode 100755
index 000000000..feedbd5e7
--- /dev/null
+++ b/sys/src/libhttpd/httpfmt.c
@@ -0,0 +1,30 @@
+#include <u.h>
+#include <libc.h>
+#include <bin.h>
+#include <httpd.h>
+
+int
+httpfmt(Fmt *f)
+{
+ char buf[HMaxWord*2];
+ Rune r;
+ char *t, *s;
+ Htmlesc *l;
+
+ s = va_arg(f->args, char*);
+ for(t = buf; t < buf + sizeof(buf) - 8; ){
+ s += chartorune(&r, s);
+ if(r == 0)
+ break;
+ for(l = htmlesc; l->name != nil; l++)
+ if(l->value == r)
+ break;
+ if(l->name != nil){
+ strcpy(t, l->name);
+ t += strlen(t);
+ }else
+ *t++ = r;
+ }
+ *t = 0;
+ return fmtstrcpy(f, buf);
+}