3 # Check a list of symbols against the master definition
4 # (official) list. Arguments:
6 # awk -f checksym.awk official-def list-to-check
8 # Output is a file in the current directory called 'symbols.new',
9 # the value of the awk variable "of" (which can be changed on the
10 # command line if required.) stdout holds error messages. Error
11 # code indicates success or failure.
13 # NOTE: this is a pure, old fashioned, awk script. It will
18 master="" # master file
19 official[1] = "" # defined symbols from master file
20 symbol[1] = "" # defined symbols from png.h
21 removed[1] = "" # removed symbols from png.h
22 lasto = 0 # last ordinal value from png.h
23 mastero = 0 # highest ordinal in master file
24 symbolo = 0 # highest ordinal in png.h
25 missing = "error"# log an error on missing symbols
26 of="symbols.new" # default to a fixed name
29 # Read existing definitions from the master file (the first
30 # file on the command line.) This must be a def file and it
31 # has definition lines (others are ignored) of the form:
38 FILENAME==master && NF==2 && $2~/^@/ && $1!~/^;/ {
41 if (official[o] == "") {
43 if (o > mastero) mastero = o
46 print master ": duplicated symbol:", official[o] ":", $0
48 print master ": bad export line format:", $0
51 FILENAME==master && $1==";missing" && NF==2{
52 # This allows the master file to control how missing symbols
53 # are handled; symbols that aren't in either the master or
54 # the new file. Valid values are 'ignore', 'warning' and
62 # Read new definitions, these are free form but the lines must
63 # just be symbol definitions. Lines will be commented out for
64 # 'removed' symbols, introduced in png.h using PNG_REMOVED rather
65 # than PNG_EXPORT. Use symbols.dfn or pngwin.dfn to generate the
68 # symbol @ordinal # two fields, exported symbol
69 # ; symbol @ordinal # three fields, removed symbol
70 # ; @ordinal # two fields, the last ordinal
71 NF==2 && $1 == ";" && $2 ~ /^@[1-9][0-9]*$/ { # last ordinal
73 if (lasto == 0 || lasto == o)
76 print "png.h: duplicated last ordinal:", lasto, o
81 NF==3 && $1 == ";" && $3 ~ /^@[1-9][0-9]*$/ { # removed symbol
83 if (removed[o] == "" || removed[o] == $2) {
85 if (o > symbolo) symbolo = o
87 print "png.h: duplicated removed symbol", o ": '" removed[o] "' != '" $2 "'"
92 NF==2 && $2 ~ /^@[1-9][0-9]*$/ { # exported symbol
94 if (symbol[o] == "" || symbol[o] == $1) {
96 if (o > symbolo) symbolo = o
98 print "png.h: duplicated symbol", o ": '" symbol[o] "' != '" $1 "'"
103 next # skip all other lines
106 # At the end check for symbols marked as both duplicated and removed
108 if (symbolo > lasto) {
109 print "highest symbol ordinal in png.h,", symbolo ", exceeds last ordinal from png.h", lasto
112 if (mastero > lasto) {
113 print "highest symbol ordinal in", master ",", mastero ", exceeds last ordinal from png.h", lasto
117 # Add a standard header to symbols.new:
118 print ";Version INSERT-VERSION-HERE" >of
119 print ";--------------------------------------------------------------" >of
120 print "; LIBPNG symbol list as a Win32 DEF file" >of
121 print "; Contains all the symbols that can be exported from libpng" >of
122 print ";--------------------------------------------------------------" >of
127 for (o=1; o<=lasto; ++o) {
128 if (symbol[o] == "" && removed[o] == "") {
129 if (unexported == 0) unexported = o
130 if (official[o] == "") {
131 # missing in export list too, so ok
132 if (o < lasto) continue
135 if (unexported != 0) {
136 # Symbols in the .def but not in the new file are errors, but
137 # the 'unexported' symbols aren't in either. By default this
138 # is an error too (see the setting of 'missing' at the start),
139 # but this can be reset on the command line or by stuff in the
140 # file - see the comments above.
141 if (missing != "ignore") {
142 if (o-1 > unexported)
143 print "png.h:", missing ": missing symbols:", unexported "-" o-1
145 print "png.h:", missing ": missing symbol:", unexported
146 if (missing != "warning")
151 if (symbol[o] != "" && removed[o] != "") {
152 print "png.h: symbol", o, "both exported as '" symbol[o] "' and removed as '" removed[o] "'"
154 } else if (symbol[o] != official[o]) {
155 # either the symbol is missing somewhere or it changed
158 print "png.h: symbol", o, "is exported as '" official[o] "' in", master
159 else if (official[o] == "")
160 print "png.h: exported symbol", o, "'" symbol[o] "' not present in", master
162 print "png.h: exported symbol", o, "'" symbol[o] "' exists as '" official[o] "' in", master
165 # Finally generate symbols.new
167 print " " symbol[o], "@" o > of
171 print "*** A new list is in", of, "***"