Assorted minor cleanups for bootstrap-data Perl scripts.
FindDefinedSymbol was intended to take an array of possible include paths, but it never actually worked correctly for any but the first array element. Since there's no use-case for more than one path anyway, let's just simplify this code and its callers by redefining it as taking only one include path. Minor other code-beautification without functional effects, except that in one place we format the output as pgindent would do. John Naylor Discussion: https://postgr.es/m/CAJVSVGXM_n32hTTkircW4_K1LQFsJNb6xjs0pAP4QC0ZpyJfPQ@mail.gmail.com
This commit is contained in:
parent
06f66cff9e
commit
e7a808f947
@ -198,7 +198,7 @@ sub ParseHeader
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
die
|
die
|
||||||
"unknown column option $attopt on column $attname";
|
"unknown or misformatted column option $attopt on column $attname";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($column{forcenull} and $column{forcenotnull})
|
if ($column{forcenull} and $column{forcenotnull})
|
||||||
@ -370,34 +370,30 @@ sub RenameTempFile
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Find a symbol defined in a particular header file and extract the value.
|
# Find a symbol defined in a particular header file and extract the value.
|
||||||
#
|
# include_path should be the path to src/include/.
|
||||||
# The include path has to be passed as a reference to an array.
|
|
||||||
sub FindDefinedSymbol
|
sub FindDefinedSymbol
|
||||||
{
|
{
|
||||||
my ($catalog_header, $include_path, $symbol) = @_;
|
my ($catalog_header, $include_path, $symbol) = @_;
|
||||||
|
my $value;
|
||||||
|
|
||||||
for my $path (@$include_path)
|
# Make sure include path ends in a slash.
|
||||||
|
if (substr($include_path, -1) ne '/')
|
||||||
{
|
{
|
||||||
|
$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";
|
my $file = $include_path . $catalog_header;
|
||||||
|
open(my $find_defined_symbol, '<', $file) || die "$file: $!";
|
||||||
|
while (<$find_defined_symbol>)
|
||||||
|
{
|
||||||
|
if (/^#define\s+\Q$symbol\E\s+(\S+)/)
|
||||||
|
{
|
||||||
|
$value = $1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close $find_defined_symbol;
|
||||||
|
return $value if defined $value;
|
||||||
|
die "$file: no definition found for $symbol\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
# Similar to FindDefinedSymbol, but looks in the bootstrap metadata.
|
# Similar to FindDefinedSymbol, but looks in the bootstrap metadata.
|
||||||
|
@ -357,8 +357,7 @@ EOM
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Emit Anum_* constants
|
# Emit Anum_* constants
|
||||||
print $def
|
printf $def "#define Anum_%s_%s %s\n", $catname, $attname, $attnum;
|
||||||
sprintf("#define Anum_%s_%s %s\n", $catname, $attname, $attnum);
|
|
||||||
}
|
}
|
||||||
print $bki "\n )\n";
|
print $bki "\n )\n";
|
||||||
|
|
||||||
@ -493,7 +492,7 @@ EOM
|
|||||||
}
|
}
|
||||||
|
|
||||||
print $bki "close $catname\n";
|
print $bki "close $catname\n";
|
||||||
print $def sprintf("\n#endif\t\t\t\t\t\t\t/* %s_D_H */\n", uc $catname);
|
printf $def "\n#endif\t\t\t\t\t\t\t/* %s_D_H */\n", uc $catname;
|
||||||
|
|
||||||
# Close and rename definition header
|
# Close and rename definition header
|
||||||
close $def;
|
close $def;
|
||||||
|
@ -22,7 +22,7 @@ use warnings;
|
|||||||
# Collect arguments
|
# Collect arguments
|
||||||
my @input_files;
|
my @input_files;
|
||||||
my $output_path = '';
|
my $output_path = '';
|
||||||
my @include_path;
|
my $include_path;
|
||||||
|
|
||||||
while (@ARGV)
|
while (@ARGV)
|
||||||
{
|
{
|
||||||
@ -37,7 +37,7 @@ while (@ARGV)
|
|||||||
}
|
}
|
||||||
elsif ($arg =~ /^-I/)
|
elsif ($arg =~ /^-I/)
|
||||||
{
|
{
|
||||||
push @include_path, length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
|
$include_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -52,8 +52,8 @@ if ($output_path ne '' && substr($output_path, -1) ne '/')
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Sanity check arguments.
|
# Sanity check arguments.
|
||||||
die "No input files.\n" if !@input_files;
|
die "No input files.\n" if !@input_files;
|
||||||
die "No include path; you must specify -I at least once.\n" if !@include_path;
|
die "No include path; you must specify -I.\n" if !$include_path;
|
||||||
|
|
||||||
# Read all the input files into internal data structures.
|
# Read all the input files into internal data structures.
|
||||||
# Note: We pass data file names as arguments and then look for matching
|
# Note: We pass data file names as arguments and then look for matching
|
||||||
@ -80,7 +80,7 @@ foreach my $datfile (@input_files)
|
|||||||
|
|
||||||
# Fetch some values for later.
|
# Fetch some values for later.
|
||||||
my $FirstBootstrapObjectId =
|
my $FirstBootstrapObjectId =
|
||||||
Catalog::FindDefinedSymbol('access/transam.h', \@include_path,
|
Catalog::FindDefinedSymbol('access/transam.h', $include_path,
|
||||||
'FirstBootstrapObjectId');
|
'FirstBootstrapObjectId');
|
||||||
my $INTERNALlanguageId =
|
my $INTERNALlanguageId =
|
||||||
Catalog::FindDefinedSymbolFromData($catalog_data{pg_language},
|
Catalog::FindDefinedSymbolFromData($catalog_data{pg_language},
|
||||||
@ -119,8 +119,8 @@ open my $pfh, '>', $protosfile . $tmpext
|
|||||||
open my $tfh, '>', $tabfile . $tmpext
|
open my $tfh, '>', $tabfile . $tmpext
|
||||||
or die "Could not open $tabfile$tmpext: $!";
|
or die "Could not open $tabfile$tmpext: $!";
|
||||||
|
|
||||||
print $ofh
|
print $ofh <<OFH;
|
||||||
qq|/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* fmgroids.h
|
* fmgroids.h
|
||||||
* Macros that define the OIDs of built-in functions.
|
* Macros that define the OIDs of built-in functions.
|
||||||
@ -154,10 +154,10 @@ print $ofh
|
|||||||
* its equivalent macro will be defined with the lowest OID among those
|
* its equivalent macro will be defined with the lowest OID among those
|
||||||
* entries.
|
* entries.
|
||||||
*/
|
*/
|
||||||
|;
|
OFH
|
||||||
|
|
||||||
print $pfh
|
print $pfh <<PFH;
|
||||||
qq|/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* fmgrprotos.h
|
* fmgrprotos.h
|
||||||
* Prototypes for built-in functions.
|
* Prototypes for built-in functions.
|
||||||
@ -180,10 +180,10 @@ print $pfh
|
|||||||
|
|
||||||
#include "fmgr.h"
|
#include "fmgr.h"
|
||||||
|
|
||||||
|;
|
PFH
|
||||||
|
|
||||||
print $tfh
|
print $tfh <<TFH;
|
||||||
qq|/*-------------------------------------------------------------------------
|
/*-------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* fmgrtab.c
|
* fmgrtab.c
|
||||||
* The function manager's table of internal functions.
|
* The function manager's table of internal functions.
|
||||||
@ -208,7 +208,7 @@ print $tfh
|
|||||||
#include "utils/fmgrtab.h"
|
#include "utils/fmgrtab.h"
|
||||||
#include "utils/fmgrprotos.h"
|
#include "utils/fmgrprotos.h"
|
||||||
|
|
||||||
|;
|
TFH
|
||||||
|
|
||||||
# Emit #define's and extern's -- only one per prosrc value
|
# Emit #define's and extern's -- only one per prosrc value
|
||||||
my %seenit;
|
my %seenit;
|
||||||
@ -282,8 +282,8 @@ print $tfh "};\n";
|
|||||||
|
|
||||||
|
|
||||||
# And add the file footers.
|
# And add the file footers.
|
||||||
print $ofh "\n#endif /* FMGROIDS_H */\n";
|
print $ofh "\n#endif\t\t\t\t\t\t\t/* FMGROIDS_H */\n";
|
||||||
print $pfh "\n#endif /* FMGRPROTOS_H */\n";
|
print $pfh "\n#endif\t\t\t\t\t\t\t/* FMGRPROTOS_H */\n";
|
||||||
|
|
||||||
close($ofh);
|
close($ofh);
|
||||||
close($pfh);
|
close($pfh);
|
||||||
|
@ -125,7 +125,6 @@ foreach my $catname (@catnames)
|
|||||||
open my $dat, '>', $datfile
|
open my $dat, '>', $datfile
|
||||||
or die "can't open $datfile: $!";
|
or die "can't open $datfile: $!";
|
||||||
|
|
||||||
# Write the data.
|
|
||||||
foreach my $data (@{ $catalog_data{$catname} })
|
foreach my $data (@{ $catalog_data{$catname} })
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ my $oids = Catalog::FindAllOidsFromHeaders(@input_files);
|
|||||||
|
|
||||||
# Also push FirstBootstrapObjectId to serve as a terminator for the last gap.
|
# Also push FirstBootstrapObjectId to serve as a terminator for the last gap.
|
||||||
my $FirstBootstrapObjectId =
|
my $FirstBootstrapObjectId =
|
||||||
Catalog::FindDefinedSymbol('access/transam.h', [".."],
|
Catalog::FindDefinedSymbol('access/transam.h', '..',
|
||||||
'FirstBootstrapObjectId');
|
'FirstBootstrapObjectId');
|
||||||
push @{$oids}, $FirstBootstrapObjectId;
|
push @{$oids}, $FirstBootstrapObjectId;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user