2 # SPDX-License-Identifier: BSD-2-Clause
4 # Copyright (C) 2006 Daniel M. Eischen. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # Make a list of all the library versions listed in the master file.
32 # versions[] - array indexed by version name, contains number
33 # of symbols (+ 1) found for each version.
34 # successors[] - array index by version name, contains successor
36 # symbols[][] - array index by [version name, symbol index], contains
37 # names of symbols defined for each version.
38 # names[] - array index is symbol name and value is its first version seen,
39 # used to check for duplicate symbols and warn about them.
46 stderr = "/dev/stderr";
47 while (getline < vfile) {
51 # Strip leading and trailing whitespace.
52 sub("^[ \t]+", "", $0);
53 sub("[ \t]+$", "", $0);
55 if (/^[a-zA-Z0-9._]+[ \t]*{$/) {
61 successors[symver] = "";
62 generated[symver] = 0;
65 else if (/^}[ \t]*[a-zA-Z0-9._]+[ \t]*;$/) {
66 v = $1 != "}" ? $1 : $2;
72 printf("File %s: Unmatched bracket.\n",
76 else if (versions[v] != 1) {
77 printf("File %s: `%s' has unknown " \
79 vfile, symver, v) > stderr;
83 successors[symver] = v;
86 else if (/^}[ \t]*;$/) {
88 printf("File %s: Unmatched bracket.\n",
96 printf("File %s: Missing final semicolon.\n",
101 ; # Ignore blank lines.
103 printf("File %s: Unknown directive: `%s'.\n",
112 # Set meaningful filename for diagnostics.
113 filename = FILENAME != "" ? FILENAME : "<stdin>";
115 # Delete comments, preceding and trailing whitespace, then
116 # consume blank lines.
118 sub("^[ \t]+", "", $0);
119 sub("[ \t]+$", "", $0);
124 /^[a-zA-Z0-9._]+[ \t]*{$/ {
125 # Strip bracket from version name.
127 if (current_version != "") {
128 printf("File %s, line %d: Illegal nesting detected.\n",
129 filename, FNR) > stderr;
132 else if (versions[$1] == 0) {
133 printf("File %s, line %d: Undefined " \
134 "library version `%s'.\n", filename, FNR, $1) > stderr;
136 # Remove this entry from the versions.
140 current_version = $1;
145 /^[a-zA-Z0-9._]+[ \t]*;$/ {
148 if (current_version != "") {
149 count = versions[current_version];
150 versions[current_version]++;
151 symbols[current_version, count] = $1;
152 if ($1 in names && names[$1] != current_version) {
154 # A graver case when a dup symbol appears under
155 # different versions in the map. That can result
156 # in subtle problems with the library later.
158 printf("File %s, line %d: Duplicated symbol `%s' " \
159 "in version `%s', first seen in `%s'. " \
160 "Did you forget to move it to ObsoleteVersions?\n",
162 current_version, names[$1]) > stderr;
165 else if (names[$1] == current_version) {
167 # A harmless case: a dup symbol with the same version.
169 printf("File %s, line %d: warning: " \
170 "Duplicated symbol `%s' in version `%s'.\n",
171 filename, FNR, $1, current_version) > stderr;
175 names[$1] = current_version;
178 printf("File %s, line %d: Symbol `%s' outside version scope.\n",
179 filename, FNR, $1) > stderr;
188 printf("File %s, line %d: Unmatched bracket.\n",
189 filename, FNR, $1) > stderr;
191 brackets = 0; # Reset
193 current_version = "";
199 printf("File %s, line %d: Unknown directive: `%s'.\n",
200 filename, FNR, $0) > stderr;
204 function print_version(v)
206 # This function is recursive, so return if this version
207 # has already been printed. Otherwise, if there is an
208 # ancestral version, recursively print its symbols before
209 # printing the symbols for this version.
211 if (generated[v] == 1)
213 if (successors[v] != "")
214 print_version(successors[v]);
218 # The version count is always one more that actual,
219 # so the loop ranges from 1 to n-1.
221 for (i = 1; i < versions[v]; i++) {
224 printf("\t%s;\n", symbols[v, i]);
228 if (version_count == 0) {
232 if (successors[v] == "")
235 printf("} %s;\n", successors[v]);
243 printf("%d error(s) total.\n", errors) > stderr;
247 for (v in versions) {