| Rev | Line | |
|---|
| [1] | 1 | #!/usr/bin/gawk -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 | elms = elms " " buffer[i] ""; |
|---|
| 25 | } |
|---|
| 26 | printf "define(`ELEMENTSOF_%s', `%s')\n", instruct, elms; |
|---|
| 27 | printf "define(`COUNTOF_%s', `%s')\n", instruct, i; |
|---|
| 28 | printf "define(`SIZEOF_%s', `( %s )')\n", instruct, elm; |
|---|
| 29 | print "\n"; |
|---|
| 30 | delete buffer; |
|---|
| 31 | buffer_len = 0; |
|---|
| 32 | instruct = 0; |
|---|
| 33 | } |
|---|
| 34 | next; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | /.{/ { |
|---|
| 38 | brace = brace + 1; |
|---|
| 39 | } |
|---|
| 40 | /.}/ { |
|---|
| 41 | brace = brace - 1; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | { |
|---|
| 45 | if (brace == 1 && instruct) { |
|---|
| 46 | sub(/.*[{}]/, ""); |
|---|
| 47 | gsub(/\[[^\]]+\]/, ""); |
|---|
| 48 | gsub(/:[0-9]+/, ""); |
|---|
| 49 | str = $0; |
|---|
| 50 | if (match(str, /\([ ]*\*([^)]+)\)/, a)) { |
|---|
| 51 | buffer[buffer_len] = a[1]; |
|---|
| 52 | buffer_len ++; |
|---|
| 53 | } |
|---|
| 54 | else { |
|---|
| 55 | while (gsub(/(\([^)]*\))/, "", str)) { |
|---|
| 56 | } |
|---|
| 57 | while (match(str, /([^*() ]+)[ ]*[,;](.*)/, a)) { |
|---|
| 58 | buffer[buffer_len] = a[1]; |
|---|
| 59 | buffer_len ++; |
|---|
| 60 | str = a[2]; |
|---|
| 61 | } |
|---|
| 62 | } |
|---|
| 63 | next; |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | /^typedef struct [^{]*;/ { |
|---|
| 68 | sub(";", ""); |
|---|
| 69 | typedefs[$3] = $4; |
|---|
| 70 | next; |
|---|
| 71 | } |
|---|
| 72 | /^typedef struct .*{/ { |
|---|
| 73 | brace = 1; |
|---|
| 74 | instruct = 1; |
|---|
| 75 | next; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | /^struct .*{/ { |
|---|
| 79 | instruct = $2; |
|---|
| 80 | brace = 1; |
|---|
| 81 | next; |
|---|
| 82 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.