update tables
[musl-tables] / type.sh
1 #!/bin/sh
2
3 export LC_ALL=C
4
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"
17
18         # next token is an id
19         split("struct union enum", a)
20         for (i in a)
21                 tok[a[i]] = "struct"
22
23         # todo: drop restrict for now
24         tok["restrict"] = ""
25 }
26
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 = ""
34         }
35 }
36
37 {
38         # eat comments
39         gsub(/\/\*[^/]*\*\//, "")
40         gsub(/\/\/.*/, "")
41
42         gsub(/[^a-zA-Z0-9_.-]/," & ")
43         gsub(/\.\.\./, " & ")
44
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)
56                 }
57         }
58
59         # fixes
60         gsub(/\[[0-9]+\]/, "[]", s)
61         gsub(/unsigned int/, "unsigned", s)
62         gsub(/long int/, "long", s)
63
64         print s
65 }
66 '