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