update tables (wchar.h, signal.h changes)
[musl-tools.git] / type.sh
blobc59f9d5492301d7787f6fd0074c778818c3a1056
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"
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 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"
23 # todo: drop restrict for now
24 tok["restrict"] = ""
27 function put(tok) {
28 if (tok ~ /^[a-zA-Z_]/) {
29 s = s sep tok
30 sep = " "
31 } else {
32 s = s tok
33 sep = ""
38 # eat comments
39 gsub(/\/\*[^/]*\*\//, "")
40 gsub(/\/\/.*/, "")
42 gsub(/[^a-zA-Z0-9_.-]/," & ")
43 gsub(/\.\.\./, " & ")
45 sep = ""
46 s = ""
47 for (i = 1; i <= NF; i++) {
48 if ($i == ";")
49 break
50 if ($i ~ /[a-zA-Z_][a-zA-Z0-9_]*/ && !tok[$i] && $i !~ /_t$/)
51 continue
52 put($i)
53 if (tok[$i] == "struct") {
54 i++
55 put($i)
59 # fixes
60 gsub(/\[[0-9]+\]/, "[]", s)
61 gsub(/unsigned int/, "unsigned", s)
62 gsub(/long int/, "long", s)
64 print s