update tables and decl problems
[musl-tools.git] / type.sh
blob3aa5a9cec719f3140764048496782c10d9d61085
1 #!/bin/sh
3 export LC_ALL=C
5 # drop names from a declaration (hack to make prototypes comparable)
6 awk '
7 BEGIN {
8 # type is not typedefed so next unknown id is probably a variable name
9 split("void char short int long float double signed unsigned _Bool _Complex", a)
10 for (i in a)
11 tok[a[i]] = "type"
13 # next token is an id, type is not typedefed
14 split("struct union enum", a)
15 for (i in a)
16 tok[a[i]] = "struct"
18 # decoratoin that can be skipped
19 split("static extern auto register inline const volatile restrict", a)
20 for (i in a)
21 tok[a[i]] = "decor"
23 # punctuators
24 split("( ) [ ] , ... *", a)
25 for (i in a)
26 tok[a[i]] = "punct"
29 function put(tok) {
30 if (tok ~ /^[a-zA-Z_]/) {
31 s = s sep tok
32 sep = " "
33 } else {
34 s = s tok
35 sep = ""
40 # eat comments
41 gsub(/\/\*[^/]*\*\//, "")
42 gsub(/\/\/.*/, "")
44 gsub(/[^a-zA-Z0-9_.]/," & ")
45 gsub(/\.\.\./, " & ")
47 state = "type"
48 sep = ""
49 s = ""
50 for (i = 1; i <= NF; i++) {
51 if ($i == ";")
52 break
53 if (state == "type") {
54 put($i)
55 if (!tok[$i] || tok[$i] == "type")
56 state = "id"
57 if (tok[$i] == "struct") {
58 i++
59 put($i)
60 state = "id"
62 } else if (state == "id") {
63 if (!tok[$i]) {
64 state = "idfound"
65 continue
67 put($i)
68 if ($i == ")")
69 state = "idfound"
70 if ($i == ",")
71 state = "type"
72 } else if (state == "idfound") {
73 put($i)
74 if ($i == "(" || $i == ",")
75 state = "type"
78 print s