mkxml.elems 786 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/rc
  2. echo \
  3. '#include "stdinc.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "httpd.h"
  7. #include "xml.h"
  8. '
  9. sed -n '/<struct/,/<\/struct>/{
  10. s/^[^<]+</</
  11. t cleart
  12. :cleart
  13. s/<struct name="(.*)" type="(.*)">.*/void xml\1(Hio *hout, \2s, char *tag, int indent){\n xmlIndent(hout, indent);\n hprint(hout, "<%s>\\n", tag);/
  14. t start
  15. s/<field name="(.*)" val="(.*)" type="(.*)"\/>.*/ xml\3(hout, \2, "\1", indent + 1);/
  16. t field
  17. s/<array name="(.*)" val="(.*)" elems="(.*)" type="(.*)"\/>.*/ for(i = 0; i < \3; i++)\n xml\4(hout, \2, "\1", indent + 1);/
  18. t array
  19. s/<\/struct>/ xmlIndent(hout, indent);\n hprint(hout, "<\/%s>\\n", tag);\n}\n/
  20. t produce
  21. }
  22. b
  23. :start
  24. h
  25. b
  26. :field
  27. H
  28. b
  29. :array
  30. H
  31. x
  32. s/{\n/& int i;\n\n/
  33. s/^ int i;\n\n int i;\n/ int i;\n/
  34. x
  35. b
  36. :produce
  37. H
  38. g
  39. p
  40. ' $1