18d0a93d29c5c1f7fc92e8c73c894cc0a2972f1c
[musl-tables] / findproblems.sh
1 #!/bin/sh
2
3 export LC_ALL=C
4
5 ./makeproto.sh
6 {
7         awk -F'\t' '{print $1}' data/musl.tags data/posix2008.ok # data/c99
8         awk -F'\t' '{print $2}' data/musl.syms
9 } |sort |uniq |awk -F'\t' '
10 BEGIN {
11         syms = "data/musl.syms"
12         tags = "data/musl.tags.proto"
13         posix = "data/posix2008.ok.proto"
14
15         while (getline < syms == 1)
16                 sym[$2] = $1
17
18         # todo: same tag may be defined in several headers
19         while (getline < tags == 1) {
20                 if ($5 ~ /^#undef/)
21                         continue
22                 if ($1 in tag)
23                         tag[$1] = tag[$1] "@" $2 "\t" $3 "\t" $5 "\t" $6
24                 else
25                         tag[$1] = $2 "\t" $3 "\t" $5 "\t" $6
26         }
27
28         while (getline < posix == 1)
29                 pos[$1] = $2 "\t" $5 "\t" $6
30 }
31 {
32         s = ""
33         if (sym[$1])
34                 s = s " obj"
35         if (tag[$1])
36                 s = s " inc"
37         if (pos[$1])
38                 s = s " posix"
39
40         n = split(tag[$1],a,"@")
41         if (n==0) {
42                 n=1
43                 a[1]=""
44         }
45         for (i = 1; i <= n; i++)
46                 print $1 "\t" substr(s,2) "\t" sym[$1] "\t" a[i] "\t" pos[$1]
47 }' >data/musl.all
48
49 awk -F'\t' '
50 $2 == "obj" || $2 == "obj posix" {
51         # not declared
52         if ($1 !~ /^_/)
53                 print "nodecl\t" $1 "\t" $3
54 }
55 $2 ~ /inc/ && $5 == "p" {
56         # check for different declarations of the same symbol
57         if ($1 in proto) {
58                 if (proto[$1] != $6)
59                         print "proto\t" $1 "\t" $4 "\t" head[$1] "\t" $6 "\t" proto[$1]
60         } else {
61                 proto[$1] = $6
62                 head[$1] = $4
63         }
64 }
65 $2 ~ /inc posix/ && $4 != $8 {
66         # different header
67         n = split($8, a, " ")
68         for (i = 1; i <= n; i++)
69                 if ($4 == a[i])
70                         break
71         if (i > n)
72                 print "header\t" $1 "\t" $4 "\t" $8
73 }
74 $2 ~ /inc posix/ && $7 != $10 && $5 == "p" {
75         # different prototype
76         print "proto\t" $1 "\t" $4 "\t" $7 "\t" $10 "\t" $6 "\t" $9
77 }
78 ' data/musl.all >data/musl.problems
79