httpfmt.c 472 B

123456789101112131415161718192021222324252627282930
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <bin.h>
  4. #include <httpd.h>
  5. int
  6. httpfmt(Fmt *f)
  7. {
  8. char buf[HMaxWord*2];
  9. Rune r;
  10. char *t, *s;
  11. Htmlesc *l;
  12. s = va_arg(f->args, char*);
  13. for(t = buf; t < buf + sizeof(buf) - 8; ){
  14. s += chartorune(&r, s);
  15. if(r == 0)
  16. break;
  17. for(l = htmlesc; l->name != nil; l++)
  18. if(l->value == r)
  19. break;
  20. if(l->name != nil){
  21. strcpy(t, l->name);
  22. t += strlen(t);
  23. }else
  24. *t++ = r;
  25. }
  26. *t = 0;
  27. return fmtstrcpy(f, buf);
  28. }