top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
-# location of Catalog.pm
-catalogdir = $(top_srcdir)/src/backend/catalog
-
# 'make reformat-dat-files' is a convenience target for rewriting the
# catalog data files in our standard format. This includes collapsing
# out any entries that are redundant with a BKI_DEFAULT annotation.
reformat-dat-files:
- $(PERL) -I $(catalogdir) $(srcdir)/reformat_dat_file.pl -o $(srcdir) $(srcdir)/pg_*.dat
+ $(PERL) $(srcdir)/reformat_dat_file.pl --output $(srcdir) $(srcdir)/pg_*.dat
# 'make expand-dat-files' is a convenience target for expanding out all
# default values in the catalog data files. This should be run before
# altering or removing any BKI_DEFAULT annotation.
expand-dat-files:
- $(PERL) -I $(catalogdir) $(srcdir)/reformat_dat_file.pl -o $(srcdir) $(srcdir)/pg_*.dat --full-tuples
+ $(PERL) $(srcdir)/reformat_dat_file.pl --output $(srcdir) $(srcdir)/pg_*.dat --full-tuples
.PHONY: reformat-dat-files expand-dat-files
use strict;
use warnings;
+use FindBin;
+use Getopt::Long;
+
# 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 @METADATA =
('oid', 'oid_symbol', 'array_type_oid', 'descr', 'autogenerated');
-my @input_files;
+# Process command line switches.
my $output_path = '';
my $full_tuples = 0;
-# Process command line switches.
-while (@ARGV)
-{
- my $arg = shift @ARGV;
- if ($arg !~ /^-/)
- {
- push @input_files, $arg;
- }
- elsif ($arg =~ /^-o/)
- {
- $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
- }
- elsif ($arg eq '--full-tuples')
- {
- $full_tuples = 1;
- }
- else
- {
- usage();
- }
-}
+GetOptions(
+ 'output=s' => \$output_path,
+ 'full-tuples' => \$full_tuples) || usage();
# Sanity check arguments.
-die "No input files.\n"
- if !@input_files;
+die "No input files.\n" unless @ARGV;
# Make sure output_path ends in a slash.
if ($output_path ne '' && substr($output_path, -1) ne '/')
my %catalogs;
my %catalog_data;
my @catnames;
-foreach my $datfile (@input_files)
+foreach my $datfile (@ARGV)
{
$datfile =~ /(.+)\.dat$/
or die "Input files need to be data (.dat) files.\n";
if !(grep { $_ eq $attname } @METADATA);
}
- # Overwrite .dat files in place, since they are under version control.
+ # Write output files to specified directory.
my $datfile = "$output_path$catname.dat";
open my $dat, '>', $datfile
or die "can't open $datfile: $!";
Usage: reformat_dat_file.pl [options] datafile...
Options:
- -o PATH write output files to PATH instead of current directory
+ --output PATH output directory (default '.')
--full-tuples write out full tuples, including default values
-Expects a list of .dat files as arguments.
+Non-option arguments are the names of input .dat files.
+Updated files are written to the output directory,
+possibly overwriting the input files.
EOM
}