Tweak reformat_dat_file.pl to make it more easily hand-invokable.

Use the same code we already applied in duplicate_oids and unused_oids
to let this script find Catalog.pm without help.  This removes the need
to supply a -I switch in most cases.

Also, mark the script executable, again to follow the precedent of
duplicate_oids and unused_oids.  Now you can just do
"./reformat_dat_file.pl pg_proc.dat"
if you want to reformat only one or a few .dat files rather than all.

It'd be possible to remove the -I switches in the Makefile's convenience
targets, but I chose to leave them: they don't hurt anything, and it's
possible that in weird VPATH situations they might be of value.
This commit is contained in:
Tom Lane 2018-04-28 16:09:03 -04:00
parent 45c6d75f8c
commit 84549ebd4c
2 changed files with 15 additions and 13 deletions

View File

@ -594,7 +594,7 @@
Run the new script: Run the new script:
<programlisting> <programlisting>
$ cd src/include/catalog $ cd src/include/catalog
$ perl -I ../../backend/catalog rewrite_dat_with_prokind.pl pg_proc.dat $ perl rewrite_dat_with_prokind.pl pg_proc.dat
</programlisting> </programlisting>
At this point <filename>pg_proc.dat</filename> has all three At this point <filename>pg_proc.dat</filename> has all three
columns, <structfield>prokind</structfield>, columns, <structfield>prokind</structfield>,

26
src/include/catalog/reformat_dat_file.pl Normal file → Executable file
View File

@ -1,13 +1,14 @@
#!/usr/bin/perl -w #!/usr/bin/perl
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# #
# reformat_dat_file.pl # reformat_dat_file.pl
# Perl script that reads in a catalog data file and writes out # Perl script that reads in catalog data file(s) and writes out
# a functionally equivalent file in a standard format. # functionally equivalent file(s) in a standard format.
# #
# Metadata entries (if any) come first, with normal attributes # In each entry of a reformatted file, metadata fields (if any) come
# starting on the following line, in the same order they would be in # first, with normal attributes starting on the following line, in
# the corresponding table. Comments and blank lines are preserved. # the same order as the columns of the corresponding catalog.
# Comments and blank lines are preserved.
# #
# Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
@ -16,11 +17,15 @@
# #
#---------------------------------------------------------------------- #----------------------------------------------------------------------
use Catalog;
use strict; use strict;
use warnings; use warnings;
# If you copy this script to somewhere other than src/include/catalog,
# you'll need to modify this "use lib" or provide a suitable -I switch.
use FindBin;
use lib "$FindBin::RealBin/../../backend/catalog/";
use Catalog;
my @input_files; my @input_files;
my $output_path = ''; my $output_path = '';
my $full_tuples = 0; my $full_tuples = 0;
@ -293,13 +298,10 @@ sub usage
Usage: reformat_dat_file.pl [options] datafile... Usage: reformat_dat_file.pl [options] datafile...
Options: Options:
-o output path -o PATH write output files to PATH instead of current directory
--full-tuples write out full tuples, including default values --full-tuples write out full tuples, including default values
Expects a list of .dat files as arguments. Expects a list of .dat files as arguments.
Make sure location of Catalog.pm is passed to the perl interpreter:
perl -I /path/to/Catalog.pm/ ...
EOM EOM
} }