update makefile
[musl-tools.git] / type.sh
blobed17978c9c5934781b6177918600cd19f1707c85
1 #!/bin/sh
3 export LC_ALL=C
5 # drop names from a declaration (hack to make prototypes comparable)
6 awk '
7 BEGIN {
8 # builtin type specifiers/qualifiers..
9 s = "void char short int long float double signed unsigned _Bool _Complex bool complex"
10 s = s " static extern auto register inline const volatile restrict __restrict"
11 # typedef names in posix without _t
12 s = s " FILE DIR VISIT ENTRY ACTION DBM datum fd_set jmp_buf sigjmp_buf va_list __isoc_va_list nl_item nl_catd"
13 s = s " scalar real-floating" # used in macros
14 split(s, a)
15 for (i in a)
16 tok[a[i]] = "builtin"
18 # next token is an id
19 split("struct union enum", a)
20 for (i in a)
21 tok[a[i]] = "struct"
24 function put(tok) {
25 if (tok ~ /^[a-zA-Z_]/) {
26 s = s sep tok
27 sep = " "
28 } else {
29 s = s tok
30 sep = ""
35 # eat comments
36 gsub(/\/\*[^\/]*\*\//, "")
37 gsub(/\/\/.*/, "")
39 gsub(/[^a-zA-Z0-9_.-]/," & ")
40 gsub(/\.\.\./, " & ")
42 sep = ""
43 s = ""
44 for (i = 1; i <= NF; i++) {
45 if ($i == ";")
46 break
47 if ($i ~ /[a-zA-Z_][a-zA-Z0-9_]*/ && !tok[$i] && $i !~ /_t$/)
48 continue
49 put($i)
50 if (tok[$i] == "struct") {
51 i++
52 put($i)
56 # fixes
57 gsub(/\[[0-9]+\]/, "[]", s)
58 gsub(/unsigned int/, "unsigned", s)
59 gsub(/long int/, "long", s)
60 gsub(/__restrict/, "restrict", s)
61 gsub(/__isoc_va_list/, "va_list", s)
63 print s