|
Revision 5, 1.5 KB
(checked in by moo, 7 years ago)
|
|
use the name of awk instead of gawk
|
| Line | |
|---|
| 1 | #!/usr/bin/awk -f |
|---|
| 2 | # vim:ts=4:sw=4 |
|---|
| 3 | BEGIN { |
|---|
| 4 | brace = 0; |
|---|
| 5 | delete buffer; |
|---|
| 6 | buffer_len = 0; |
|---|
| 7 | } |
|---|
| 8 | /^}.*;/ { |
|---|
| 9 | if (instruct) { |
|---|
| 10 | sub(";", ""); |
|---|
| 11 | if (instruct == 1 && $2) { |
|---|
| 12 | instruct = $2; |
|---|
| 13 | } |
|---|
| 14 | if (instruct in typedefs) { |
|---|
| 15 | instruct = typedefs[instruct]; |
|---|
| 16 | } |
|---|
| 17 | elm = ""; |
|---|
| 18 | elms = ""; |
|---|
| 19 | for (i = 0; i in buffer; i ++) { |
|---|
| 20 | if (i) elm = elm " + "; |
|---|
| 21 | # elm = elm "sizeof(((`" instruct "'*)NULL)->`" buffer[i] "')"; |
|---|
| 22 | # elms = elms " `" buffer[i] "'"; |
|---|
| 23 | elm = elm "sizeof(((" instruct "*)NULL)->" buffer[i] ")"; |
|---|
| 24 | |
|---|
| 25 | if (elms == "") { |
|---|
| 26 | elms = buffer[i]; |
|---|
| 27 | } |
|---|
| 28 | else { |
|---|
| 29 | elms = elms "," buffer[i]; |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | printf "define(`ELEMENTSOF_%s', `%s')\n", instruct, elms; |
|---|
| 33 | printf "define(`COUNTOF_%s', `%s')\n", instruct, i; |
|---|
| 34 | printf "define(`SIZEOF_%s', `( %s )')\n", instruct, elm; |
|---|
| 35 | print "\n"; |
|---|
| 36 | delete buffer; |
|---|
| 37 | buffer_len = 0; |
|---|
| 38 | instruct = 0; |
|---|
| 39 | } |
|---|
| 40 | next; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | /.{/ { |
|---|
| 44 | brace = brace + 1; |
|---|
| 45 | } |
|---|
| 46 | /.}/ { |
|---|
| 47 | brace = brace - 1; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | { |
|---|
| 51 | if (brace == 1 && instruct) { |
|---|
| 52 | sub(/.*[{}]/, ""); |
|---|
| 53 | gsub(/\[[^\]]+\]/, ""); |
|---|
| 54 | gsub(/:[0-9]+/, ""); |
|---|
| 55 | str = $0; |
|---|
| 56 | if (match(str, /\([ ]*\*([^)]+)\)/, a)) { |
|---|
| 57 | buffer[buffer_len] = a[1]; |
|---|
| 58 | buffer_len ++; |
|---|
| 59 | } |
|---|
| 60 | else { |
|---|
| 61 | while (gsub(/(\([^)]*\))/, "", str)) { |
|---|
| 62 | } |
|---|
| 63 | while (match(str, /([^*() ]+)[ ]*[,;](.*)/, a)) { |
|---|
| 64 | buffer[buffer_len] = a[1]; |
|---|
| 65 | buffer_len ++; |
|---|
| 66 | str = a[2]; |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | next; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | /^typedef struct [^{]*;/ { |
|---|
| 74 | sub(";", ""); |
|---|
| 75 | typedefs[$3] = $4; |
|---|
| 76 | next; |
|---|
| 77 | } |
|---|
| 78 | /^typedef struct .*{/ { |
|---|
| 79 | brace = 1; |
|---|
| 80 | instruct = 1; |
|---|
| 81 | next; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /^struct .*{/ { |
|---|
| 85 | instruct = $2; |
|---|
| 86 | brace = 1; |
|---|
| 87 | next; |
|---|
| 88 | } |
|---|