@ -20,9 +20,11 @@
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 ;
@ -34,35 +36,16 @@ 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 '/' )
@ -76,7 +59,7 @@ 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" ;
@ -130,7 +113,7 @@ foreach my $catname (@catnames)
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: $!" ;
@ -318,10 +301,12 @@ sub usage
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
}