cvt 938 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. awk '
  2. /^{/ {
  3. if (prev != "") {
  4. # comments can be trouble (e.g. ffree())
  5. if ( (c = match(prev, /\/\*.*\*\/$/)) != 0 ) {
  6. comment = substr(prev, c)
  7. sub(/\/\*.*\*\/$/, "", prev)
  8. } else comment = ""
  9. x = prev
  10. # isolate argument list
  11. sub(/^[^(]*\(/, "", x)
  12. sub(/\)[^)]*$/, "", x)
  13. # find the names in it
  14. n = split(x, args)
  15. arglist = ""
  16. for (i = 2; i <= n; i += 2)
  17. arglist = arglist args[i]
  18. gsub(/\(\*f\)\(Tchar\)/, "f", arglist) # special case for n4.c
  19. gsub(/\[[0-9]+\]/, "", arglist) # for n8.c
  20. gsub(/[*()\[\]]/, "", arglist) # discard noise characters *()[]
  21. gsub(/,/, ", ", arglist) # space nicely
  22. sub(/\(.*\)/, "(" arglist ")", prev) # reconstruct
  23. print prev comment
  24. # argument declarations
  25. gsub(/,/, ";", x)
  26. gsub(/\(\*f\)\(Tchar\)/, "(*f)()", x) # special case for n4.c
  27. if (x != "")
  28. print "\t" x ";"
  29. }
  30. prev = $0
  31. next
  32. }
  33. { print prev
  34. prev = $0
  35. }
  36. END { print prev }
  37. ' $*