mirror of
https://github.com/postgres/postgres.git
synced 2025-04-27 22:56:53 +03:00
Move genbki.pl's find_defined_symbol to Catalog.pm.
Will be used in Gen_fmgrtab.pl in a followup commit.
This commit is contained in:
parent
4736d74479
commit
18f791ab2b
@ -19,7 +19,7 @@ use warnings;
|
|||||||
require Exporter;
|
require Exporter;
|
||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT = ();
|
our @EXPORT = ();
|
||||||
our @EXPORT_OK = qw(Catalogs SplitDataLine RenameTempFile);
|
our @EXPORT_OK = qw(Catalogs SplitDataLine RenameTempFile FindDefinedSymbol);
|
||||||
|
|
||||||
# Call this function with an array of names of header files to parse.
|
# Call this function with an array of names of header files to parse.
|
||||||
# Returns a nested data structure describing the data in the headers.
|
# Returns a nested data structure describing the data in the headers.
|
||||||
@ -252,6 +252,39 @@ sub RenameTempFile
|
|||||||
rename($temp_name, $final_name) || die "rename: $temp_name: $!";
|
rename($temp_name, $final_name) || die "rename: $temp_name: $!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Find a symbol defined in a particular header file and extract the value.
|
||||||
|
#
|
||||||
|
# The include path has to be passed as a reference to an array.
|
||||||
|
sub FindDefinedSymbol
|
||||||
|
{
|
||||||
|
my ($catalog_header, $include_path, $symbol) = @_;
|
||||||
|
|
||||||
|
for my $path (@$include_path)
|
||||||
|
{
|
||||||
|
|
||||||
|
# Make sure include path ends in a slash.
|
||||||
|
if (substr($path, -1) ne '/')
|
||||||
|
{
|
||||||
|
$path .= '/';
|
||||||
|
}
|
||||||
|
my $file = $path . $catalog_header;
|
||||||
|
next if !-f $file;
|
||||||
|
open(my $find_defined_symbol, '<', $file) || die "$file: $!";
|
||||||
|
while (<$find_defined_symbol>)
|
||||||
|
{
|
||||||
|
if (/^#define\s+\Q$symbol\E\s+(\S+)/)
|
||||||
|
{
|
||||||
|
return $1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $find_defined_symbol;
|
||||||
|
die "$file: no definition found for $symbol\n";
|
||||||
|
}
|
||||||
|
die "$catalog_header: not found in any include directory\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# verify the number of fields in the passed-in DATA line
|
# verify the number of fields in the passed-in DATA line
|
||||||
sub check_natts
|
sub check_natts
|
||||||
{
|
{
|
||||||
|
@ -87,9 +87,11 @@ open my $shdescr, '>', $shdescrfile . $tmpext
|
|||||||
# NB: make sure that the files used here are known to be part of the .bki
|
# NB: make sure that the files used here are known to be part of the .bki
|
||||||
# file's dependencies by src/backend/catalog/Makefile.
|
# file's dependencies by src/backend/catalog/Makefile.
|
||||||
my $BOOTSTRAP_SUPERUSERID =
|
my $BOOTSTRAP_SUPERUSERID =
|
||||||
find_defined_symbol('pg_authid.h', 'BOOTSTRAP_SUPERUSERID');
|
Catalog::FindDefinedSymbol('pg_authid.h', \@include_path,
|
||||||
|
'BOOTSTRAP_SUPERUSERID');
|
||||||
my $PG_CATALOG_NAMESPACE =
|
my $PG_CATALOG_NAMESPACE =
|
||||||
find_defined_symbol('pg_namespace.h', 'PG_CATALOG_NAMESPACE');
|
Catalog::FindDefinedSymbol('pg_namespace.h', \@include_path,
|
||||||
|
'PG_CATALOG_NAMESPACE');
|
||||||
|
|
||||||
# Read all the input header files into internal data structures
|
# Read all the input header files into internal data structures
|
||||||
my $catalogs = Catalog::Catalogs(@input_files);
|
my $catalogs = Catalog::Catalogs(@input_files);
|
||||||
@ -500,34 +502,6 @@ sub emit_schemapg_row
|
|||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Find a symbol defined in a particular header file and extract the value.
|
|
||||||
sub find_defined_symbol
|
|
||||||
{
|
|
||||||
my ($catalog_header, $symbol) = @_;
|
|
||||||
for my $path (@include_path)
|
|
||||||
{
|
|
||||||
|
|
||||||
# Make sure include path ends in a slash.
|
|
||||||
if (substr($path, -1) ne '/')
|
|
||||||
{
|
|
||||||
$path .= '/';
|
|
||||||
}
|
|
||||||
my $file = $path . $catalog_header;
|
|
||||||
next if !-f $file;
|
|
||||||
open(my $find_defined_symbol, '<', $file) || die "$file: $!";
|
|
||||||
while (<$find_defined_symbol>)
|
|
||||||
{
|
|
||||||
if (/^#define\s+\Q$symbol\E\s+(\S+)/)
|
|
||||||
{
|
|
||||||
return $1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close $find_defined_symbol;
|
|
||||||
die "$file: no definition found for $symbol\n";
|
|
||||||
}
|
|
||||||
die "$catalog_header: not found in any include directory\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
sub usage
|
sub usage
|
||||||
{
|
{
|
||||||
die <<EOM;
|
die <<EOM;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user