mkxml 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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", tag);\n hprint(hout, ">\\n");/
  14. t start
  15. s/<field name="(.*)" val="(.*)" type="(.*)"\/>.*/ xml\3(hout, \2, "\1");\n hprint(hout, ">\\n");/
  16. t field
  17. s/<array name="(.*)" val="(.*)" elems="(.*)" type="(.*)"\/>.*/ xmlIndent(hout, indent + 1);\n hprint(hout, "<\1s>\\n");\n for(i = 0; i < \3; i++)\n xml\4(hout, \2, "\1", indent + 2);\n xmlIndent(hout, indent + 1);\n hprint(hout, "<\/\1s>\\n");/
  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. x
  28. s/ hprint\(hout, ">\\n"\);//g
  29. x
  30. H
  31. b
  32. :array
  33. H
  34. x
  35. s/{\n/& int i;\n\n/
  36. s/^ int i;\n\n int i;\n/ int i;\n/
  37. x
  38. b
  39. :produce
  40. H
  41. g
  42. s/\n\n/\n/g
  43. s/ hprint.hout, ">\\n".;\n xmlIndent.hout, indent.;\n hprint.*/ hprint(hout, "\/>\\n");/
  44. p
  45. ' $1