httpfmt.c 884 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bin.h>
  12. #include <httpd.h>
  13. int
  14. httpfmt(Fmt *f)
  15. {
  16. char buf[HMaxWord*2];
  17. Rune r;
  18. char *t, *s;
  19. Htmlesc *l;
  20. s = va_arg(f->args, char*);
  21. for(t = buf; t < buf + sizeof(buf) - 8; ){
  22. s += chartorune(&r, s);
  23. if(r == 0)
  24. break;
  25. for(l = htmlesc; l->name != nil; l++)
  26. if(l->value == r)
  27. break;
  28. if(l->name != nil){
  29. strcpy(t, l->name);
  30. t += strlen(t);
  31. }else
  32. *t++ = r;
  33. }
  34. *t = 0;
  35. return fmtstrcpy(f, buf);
  36. }