separate.awk 934 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/awk -f
  2. #
  3. # Usage: awk -f separate.awk foo.SUSv4.in
  4. # Input: http://www.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html#tag_13_77_03_06
  5. # Output: foo-$CODE.SUSv4.syms, foo.SUSv4.syms
  6. #
  7. # Copyright (C) 2010 Bernhard Reutner-Fischer
  8. # Public domain
  9. function get_code(line)
  10. {
  11. sub("\\]\\[.*", "", line)
  12. sub("\\[", "", line)
  13. sub(" ", "", line)
  14. return line
  15. }
  16. BEGIN{
  17. code="";# feature set; XSI, OB XSI, CX, etc
  18. }
  19. /\[Option Start\]/{
  20. code = get_code($0)
  21. next
  22. }
  23. /\[Option End\]/{ code = ""; next; }
  24. /.*/ {
  25. if (!hdrname) {
  26. split(FILENAME, fparts, ".")
  27. hdrname = fparts[1]
  28. stdname = fparts[2]
  29. if (fparts[3] != "in") {
  30. print "inputfilename may not be ok, exiting."
  31. exit(1)
  32. }
  33. }
  34. if (code) {
  35. fname = hdrname "-" code "." stdname ".syms"
  36. } else {
  37. fname = hdrname "." stdname ".syms"
  38. }
  39. sub("^*", "", $0)
  40. if (file[code]) {
  41. print $0 >> fname
  42. } else {
  43. print $0 > fname
  44. file[code] = 1
  45. }
  46. }