blob: 20051d3398af5e73d8079b16daed91bf7a75853b [file] [log] [blame]
Glenn Randers-Pehrsoncd745492010-04-28 07:52:16 -05001#!/bin/awk -f
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -05002# Check a list of symbols against the master definition
3# (official) list. Arguments:
4#
5# awk -f checksym.awk official-def list-to-check
6#
7# Output is a file in the current directory called 'symbols.new',
8# stdout holds error messages. Error code indicates success or
9# failure.
10#
11# NOTE: this is a pure, old fashioned, awk script. It will
12# work with any awk
13
14BEGIN{
15 err=0
16 master="" # master file
17 official[1] = "" # defined symbols from master file
18 symbol[1] = "" # defined symbols from png.h
19 removed[1] = "" # removed symbols from png.h
20 lasto = 0 # last ordinal value from png.h
21 mastero = 0 # highest ordinal in master file
22 symbolo = 0 # highest ordinal in png.h
23}
24
25# Read existing definitions from the master file (the first
26# file on the command line.) This must be a def file and it
27# has definition lines (others are ignored) of the form:
28#
29# symbol @ordinal
30#
31master == "" {
32 master = FILENAME;
33}
34FILENAME==master && NF==2 && $2~/^@/ && $1!~/^;/ {
35 o=0+substr($2,2)
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -050036 if (o > 0) {
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -050037 if (official[o] == "") {
38 official[o] = $1
39 if (o > mastero) mastero = o
40 next
41 } else
42 print master ": duplicated symbol:", official[o] ":", $0
43 } else
44 print master ": bad export line format:", $0
45 err = 1
46}
47FILENAME==master {
48 next
49}
50
51# Read new definitions, these are free form but the lines must
52# just be symbol definitions. Lines will be commented out for
53# 'removed' symbols, introduced in png.h using PNG_REMOVED rather
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -050054# than PNG_EXPORT. Use symbols.dfn or pngwin.dfn to generate the
55# input file.
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -050056#
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -050057# symbol @ordinal # two fields, exported symbol
58# ; symbol @ordinal # three fields, removed symbol
59# ; @ordinal # two fields, the last ordinal
60NF==2 && $1 == ";" && $2 ~ /^@[1-9][0-9]*$/ { # last ordinal
61 o=0+substr($2,2)
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -050062 if (lasto == 0 || lasto == o)
63 lasto=o
64 else {
65 print "png.h: duplicated last ordinal:", lasto, o
66 err = 1
67 }
68 next
69}
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -050070NF==3 && $1 == ";" && $3 ~ /^@[1-9][0-9]*$/ { # removed symbol
71 o=0+substr($3,2)
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -050072 if (removed[o] == "" || removed[o] == $2) {
73 removed[o] = $2
74 if (o > symbolo) symbolo = o
75 } else {
76 print "png.h: duplicated removed symbol",
77 o ": '" removed[o] "' != '" $2 "'"
78 err = 1
79 }
80 next
81}
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -050082NF==2 && $2 ~ /^@[1-9][0-9]*$/ { # exported symbol
83 o=0+substr($2,2)
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -050084 if (symbol[o] == "" || symbol[o] == $1) {
85 symbol[o] = $1
86 if (o > symbolo) symbolo = o
87 } else {
88 print "png.h: duplicated symbol",
89 o ": '" symbol[o] "' != '" $1 "'"
90 err = 1
91 }
92}
93{
94 next # skip all other lines
95}
96
97# At the end check for symbols marked as both duplicated and removed
98END{
99 if (symbolo > lasto) {
100 print "highest symbol ordinal in png.h,",
101 symbolo ", exceeds last ordinal from png.h", lasto
102 err = 1
103 }
104 if (mastero > lasto) {
105 print "highest symbol ordinal in", master ",",
106 mastero ", exceeds last ordinal from png.h", lasto
107 err = 1
108 }
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -0500109 unexported=0
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500110 for (o=1; o<=lasto; ++o) {
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500111 if (symbol[o] == "" && removed[o] == "") {
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -0500112 if (unexported == 0) unexported = o
113 if (official[o] == "") {
114 # missing in export list too, so ok
115 if (o < lasto) continue
116 }
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500117 }
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -0500118 if (unexported != 0) {
119 # Symbols in the .def but not in the new file are errors
120 if (o-1 > unexported)
121 print "png.h: warning: unexported symbol definitions:",
122 unexported "-" o-1
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500123 else
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -0500124 print "png.h: warning: unexported symbol definition:",
125 unexported
126 unexported = 0
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500127 }
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500128 if (symbol[o] != "" && removed[o] != "") {
129 print "png.h: symbol", o,
130 "both exported as '" symbol[o] "' and removed as '" removed[o] "'"
131 err = 1
132 } else if (symbol[o] != official[o]) {
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -0500133 # either the symbol is missing somewhere or it changed
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500134 err = 1
135 if (symbol[o] == "")
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -0500136 print "png.h: symbol", o,
137 "is exported as '" official[o] "' in", master
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500138 else if (official[o] == "")
Glenn Randers-Pehrson862cb202010-04-16 22:12:51 -0500139 print "png.h: exported symbol", o,
140 "'" symbol[o] "' not present in", master
Glenn Randers-Pehrson8069aeb2010-03-16 08:07:22 -0500141 else
142 print "png.h: exported symbol", o,
143 "'" symbol[o] "' exists as '" official[o] "' in", master
144 }
145
146 # Finally generate symbols.new
147 if (symbol[o] != "")
148 print " " symbol[o], "@" o > "symbols.new"
149 }
150
151 if (err != 0) {
152 print "*** A new list is in symbols.new ***"
153 exit 1
154 }
155}