2006-03-16 15:12:26 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2006 Daniel M. Eischen. All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
# SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# Make a list of all the library versions listed in the master file.
|
|
|
|
#
|
|
|
|
# versions[] - array indexed by version name, contains number
|
|
|
|
# of symbols (+ 1) found for each version.
|
|
|
|
# successors[] - array index by version name, contains successor
|
|
|
|
# version name.
|
|
|
|
# symbols[][] - array index by [version name, symbol index], contains
|
|
|
|
# names of symbols defined for each version.
|
2007-10-18 10:32:28 +00:00
|
|
|
# names[] - array index is symbol name and value is its first version seen,
|
2007-10-17 20:09:56 +00:00
|
|
|
# used to check for duplicate symbols and warn about them.
|
2006-03-16 15:12:26 +00:00
|
|
|
#
|
|
|
|
BEGIN {
|
|
|
|
brackets = 0;
|
2007-10-18 10:32:28 +00:00
|
|
|
errors = warns = 0;
|
2006-03-16 15:12:26 +00:00
|
|
|
version_count = 0;
|
|
|
|
current_version = "";
|
|
|
|
stderr = "/dev/stderr";
|
|
|
|
while (getline < vfile) {
|
|
|
|
# Strip comments.
|
|
|
|
sub("#.*$", "", $0);
|
|
|
|
|
2007-10-17 20:09:56 +00:00
|
|
|
# Strip leading and trailing whitespace.
|
|
|
|
sub("^[ \t]+", "", $0);
|
|
|
|
sub("[ \t]+$", "", $0);
|
2006-03-16 15:12:26 +00:00
|
|
|
|
2007-10-17 20:09:56 +00:00
|
|
|
if (/^[a-zA-Z0-9._]+[ \t]*{$/) {
|
|
|
|
# Strip brace.
|
|
|
|
sub("{", "", $1);
|
2006-03-16 15:12:26 +00:00
|
|
|
brackets++;
|
|
|
|
symver = $1;
|
|
|
|
versions[symver] = 1;
|
|
|
|
successors[symver] = "";
|
2007-04-23 03:24:33 +00:00
|
|
|
generated[symver] = 0;
|
2006-03-16 15:12:26 +00:00
|
|
|
version_count++;
|
|
|
|
}
|
2007-10-17 20:09:56 +00:00
|
|
|
else if (/^}[ \t]*[a-zA-Z0-9._]+[ \t]*;$/) {
|
|
|
|
v = $1 != "}" ? $1 : $2;
|
|
|
|
# Strip brace.
|
|
|
|
sub("}", "", v);
|
2006-03-16 15:12:26 +00:00
|
|
|
# Strip semicolon.
|
2007-10-17 20:09:56 +00:00
|
|
|
sub(";", "", v);
|
|
|
|
if (symver == "") {
|
|
|
|
printf("File %s: Unmatched bracket.\n",
|
|
|
|
vfile) > stderr;
|
|
|
|
errors++;
|
|
|
|
}
|
|
|
|
else if (versions[v] != 1) {
|
|
|
|
printf("File %s: `%s' has unknown " \
|
|
|
|
"successor `%s'.\n",
|
|
|
|
vfile, symver, v) > stderr;
|
|
|
|
errors++;
|
|
|
|
}
|
2006-03-16 15:12:26 +00:00
|
|
|
else
|
2007-10-17 20:09:56 +00:00
|
|
|
successors[symver] = v;
|
2006-03-16 15:12:26 +00:00
|
|
|
brackets--;
|
|
|
|
}
|
2007-10-17 20:09:56 +00:00
|
|
|
else if (/^}[ \t]*;$/) {
|
|
|
|
if (symver == "") {
|
2006-03-16 15:12:26 +00:00
|
|
|
printf("File %s: Unmatched bracket.\n",
|
|
|
|
vfile) > stderr;
|
2007-10-17 20:09:56 +00:00
|
|
|
errors++;
|
|
|
|
}
|
2006-03-16 15:12:26 +00:00
|
|
|
# No successor
|
|
|
|
brackets--;
|
|
|
|
}
|
2007-10-17 20:09:56 +00:00
|
|
|
else if (/^}$/) {
|
|
|
|
printf("File %s: Missing final semicolon.\n",
|
2006-03-16 15:12:26 +00:00
|
|
|
vfile) > stderr;
|
2007-10-17 20:09:56 +00:00
|
|
|
errors++;
|
2006-03-16 15:12:26 +00:00
|
|
|
}
|
|
|
|
else if (/^$/)
|
|
|
|
; # Ignore blank lines.
|
2007-10-17 20:09:56 +00:00
|
|
|
else {
|
|
|
|
printf("File %s: Unknown directive: `%s'.\n",
|
2006-03-16 15:12:26 +00:00
|
|
|
vfile, $0) > stderr;
|
2007-10-17 20:09:56 +00:00
|
|
|
errors++;
|
|
|
|
}
|
2006-03-16 15:12:26 +00:00
|
|
|
}
|
|
|
|
brackets = 0;
|
|
|
|
}
|
|
|
|
|
2007-10-17 20:09:56 +00:00
|
|
|
{
|
|
|
|
# Set meaningful filename for diagnostics.
|
|
|
|
filename = FILENAME != "" ? FILENAME : "<stdin>";
|
|
|
|
|
2006-03-16 15:12:26 +00:00
|
|
|
# Delete comments, preceding and trailing whitespace, then
|
|
|
|
# consume blank lines.
|
|
|
|
sub("#.*$", "", $0);
|
|
|
|
sub("^[ \t]+", "", $0);
|
|
|
|
sub("[ \t]+$", "", $0);
|
|
|
|
if ($0 == "")
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2007-10-17 20:09:56 +00:00
|
|
|
/^[a-zA-Z0-9._]+[ \t]*{$/ {
|
2006-03-16 15:12:26 +00:00
|
|
|
# Strip bracket from version name.
|
|
|
|
sub("{", "", $1);
|
2007-10-17 20:09:56 +00:00
|
|
|
if (current_version != "") {
|
2006-03-16 15:12:26 +00:00
|
|
|
printf("File %s, line %d: Illegal nesting detected.\n",
|
2007-10-17 20:09:56 +00:00
|
|
|
filename, FNR) > stderr;
|
|
|
|
errors++;
|
|
|
|
}
|
2006-03-16 15:12:26 +00:00
|
|
|
else if (versions[$1] == 0) {
|
|
|
|
printf("File %s, line %d: Undefined " \
|
2007-10-17 20:09:56 +00:00
|
|
|
"library version `%s'.\n", filename, FNR, $1) > stderr;
|
|
|
|
errors++;
|
2006-03-16 15:12:26 +00:00
|
|
|
# Remove this entry from the versions.
|
|
|
|
delete versions[$1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
current_version = $1;
|
|
|
|
brackets++;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2007-10-17 20:09:56 +00:00
|
|
|
/^[a-zA-Z0-9._]+[ \t]*;$/ {
|
|
|
|
# Strip semicolon.
|
|
|
|
sub(";", "", $1);
|
2006-03-16 15:12:26 +00:00
|
|
|
if (current_version != "") {
|
|
|
|
count = versions[current_version];
|
|
|
|
versions[current_version]++;
|
|
|
|
symbols[current_version, count] = $1;
|
2007-10-18 10:32:28 +00:00
|
|
|
if ($1 in names && names[$1] != current_version) {
|
|
|
|
#
|
|
|
|
# A graver case when a dup symbol appears under
|
|
|
|
# different versions in the map. That can result
|
|
|
|
# in subtle problems with the library later.
|
|
|
|
#
|
|
|
|
printf("File %s, line %d: Duplicated symbol `%s' " \
|
|
|
|
"in version `%s', first seen in `%s'. " \
|
2007-10-17 20:09:56 +00:00
|
|
|
"Did you forget to move it to ObsoleteVersions?\n",
|
2007-10-18 10:32:28 +00:00
|
|
|
filename, FNR, $1,
|
|
|
|
current_version, names[$1]) > stderr;
|
2007-10-17 20:09:56 +00:00
|
|
|
errors++;
|
|
|
|
}
|
2007-10-18 10:32:28 +00:00
|
|
|
else if (names[$1] == current_version) {
|
|
|
|
#
|
|
|
|
# A harmless case: a dup symbol with the same version.
|
|
|
|
#
|
|
|
|
printf("File %s, line %d: warning: " \
|
|
|
|
"Duplicated symbol `%s' in version `%s'.\n",
|
|
|
|
filename, FNR, $1, current_version) > stderr;
|
|
|
|
warns++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
names[$1] = current_version;
|
2007-10-17 20:09:56 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("File %s, line %d: Symbol `%s' outside version scope.\n",
|
|
|
|
filename, FNR, $1) > stderr;
|
|
|
|
errors++;
|
2006-03-16 15:12:26 +00:00
|
|
|
}
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2007-10-17 20:09:56 +00:00
|
|
|
/^}[ \t]*;$/ {
|
2006-03-16 15:12:26 +00:00
|
|
|
brackets--;
|
|
|
|
if (brackets < 0) {
|
|
|
|
printf("File %s, line %d: Unmatched bracket.\n",
|
2007-10-17 20:09:56 +00:00
|
|
|
filename, FNR, $1) > stderr;
|
|
|
|
errors++;
|
2006-03-16 15:12:26 +00:00
|
|
|
brackets = 0; # Reset
|
|
|
|
}
|
|
|
|
current_version = "";
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-17 20:09:56 +00:00
|
|
|
{
|
|
|
|
printf("File %s, line %d: Unknown directive: `%s'.\n",
|
|
|
|
filename, FNR, $0) > stderr;
|
|
|
|
errors++;
|
2006-03-16 15:12:26 +00:00
|
|
|
}
|
|
|
|
|
2007-04-23 03:24:33 +00:00
|
|
|
function print_version(v)
|
|
|
|
{
|
|
|
|
# This function is recursive, so return if this version
|
|
|
|
# has already been printed. Otherwise, if there is an
|
|
|
|
# ancestral version, recursively print its symbols before
|
|
|
|
# printing the symbols for this version.
|
|
|
|
#
|
|
|
|
if (generated[v] == 1)
|
|
|
|
return;
|
|
|
|
if (successors[v] != "")
|
|
|
|
print_version(successors[v]);
|
|
|
|
|
|
|
|
printf("%s {\n", v);
|
|
|
|
|
|
|
|
# The version count is always one more that actual,
|
|
|
|
# so the loop ranges from 1 to n-1.
|
|
|
|
#
|
|
|
|
for (i = 1; i < versions[v]; i++) {
|
|
|
|
if (i == 1)
|
|
|
|
printf("global:\n");
|
2007-10-17 20:09:56 +00:00
|
|
|
printf("\t%s;\n", symbols[v, i]);
|
2007-04-23 03:24:33 +00:00
|
|
|
}
|
2007-07-21 20:52:32 +00:00
|
|
|
|
|
|
|
version_count--;
|
|
|
|
if (version_count == 0) {
|
2007-04-23 03:24:33 +00:00
|
|
|
printf("local:\n");
|
|
|
|
printf("\t*;\n");
|
|
|
|
}
|
2007-07-21 20:52:32 +00:00
|
|
|
if (successors[v] == "")
|
|
|
|
printf("};\n");
|
2007-04-23 03:24:33 +00:00
|
|
|
else
|
|
|
|
printf("} %s;\n", successors[v]);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
generated[v] = 1;
|
|
|
|
}
|
2007-10-17 20:09:56 +00:00
|
|
|
|
2006-03-16 15:12:26 +00:00
|
|
|
END {
|
2007-10-17 20:09:56 +00:00
|
|
|
if (errors) {
|
2007-10-18 10:32:28 +00:00
|
|
|
printf("%d error(s) total.\n", errors) > stderr;
|
2007-10-17 20:09:56 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
# OK, no errors.
|
2006-03-16 15:12:26 +00:00
|
|
|
for (v in versions) {
|
2007-04-23 03:24:33 +00:00
|
|
|
print_version(v);
|
2006-03-16 15:12:26 +00:00
|
|
|
}
|
|
|
|
}
|