Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit27aaf6e

Browse files
committed
Minor improvements for reformat_dat_file.pl.
Use Getopt::Long in preference to hand-rolled option parsing code.Also, remove "-I .../backend/catalog" switch from the Makefileinvocations. That's been unnecessary for some time, and leaving itthere gives the false impression it's needed in manual invocations.John Naylor (extracted from a larger but more controversial patch)Discussion:https://postgr.es/m/CACPNZCsHdcQN2jQ1=ptbi1Co2Nj3aHgRCUMk62=ThgWNabPY+Q@mail.gmail.com
1 parente1e0e8d commit27aaf6e

File tree

2 files changed

+16
-34
lines changed

2 files changed

+16
-34
lines changed

‎src/include/catalog/Makefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,16 @@ subdir = src/include/catalog
1313
top_builddir = ../../..
1414
include$(top_builddir)/src/Makefile.global
1515

16-
# location of Catalog.pm
17-
catalogdir =$(top_srcdir)/src/backend/catalog
18-
1916
# 'make reformat-dat-files' is a convenience target for rewriting the
2017
# catalog data files in our standard format. This includes collapsing
2118
# out any entries that are redundant with a BKI_DEFAULT annotation.
2219
reformat-dat-files:
23-
$(PERL)-I$(catalogdir)$(srcdir)/reformat_dat_file.pl -o$(srcdir)$(srcdir)/pg_*.dat
20+
$(PERL)$(srcdir)/reformat_dat_file.pl --output$(srcdir)$(srcdir)/pg_*.dat
2421

2522
# 'make expand-dat-files' is a convenience target for expanding out all
2623
# default values in the catalog data files. This should be run before
2724
# altering or removing any BKI_DEFAULT annotation.
2825
expand-dat-files:
29-
$(PERL)-I$(catalogdir)$(srcdir)/reformat_dat_file.pl -o$(srcdir)$(srcdir)/pg_*.dat --full-tuples
26+
$(PERL)$(srcdir)/reformat_dat_file.pl --output$(srcdir)$(srcdir)/pg_*.dat --full-tuples
3027

3128
.PHONY: reformat-dat-files expand-dat-files

‎src/include/catalog/reformat_dat_file.pl

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
use strict;
2121
use warnings;
2222

23+
use FindBin;
24+
use Getopt::Long;
25+
2326
# If you copy this script to somewhere other than src/include/catalog,
2427
# you'll need to modify this "use lib" or provide a suitable -I switch.
25-
use FindBin;
2628
use lib"$FindBin::RealBin/../../backend/catalog/";
2729
use Catalog;
2830

@@ -34,35 +36,16 @@
3436
my@METADATA =
3537
('oid','oid_symbol','array_type_oid','descr','autogenerated');
3638

37-
my@input_files;
39+
# Process command line switches.
3840
my$output_path ='';
3941
my$full_tuples = 0;
4042

41-
# Process command line switches.
42-
while (@ARGV)
43-
{
44-
my$arg =shift@ARGV;
45-
if ($arg !~/^-/)
46-
{
47-
push@input_files,$arg;
48-
}
49-
elsif ($arg =~/^-o/)
50-
{
51-
$output_path =length($arg) > 2 ?substr($arg, 2) :shift@ARGV;
52-
}
53-
elsif ($argeq'--full-tuples')
54-
{
55-
$full_tuples = 1;
56-
}
57-
else
58-
{
59-
usage();
60-
}
61-
}
43+
GetOptions(
44+
'output=s'=> \$output_path,
45+
'full-tuples'=> \$full_tuples) || usage();
6246

6347
# Sanity check arguments.
64-
die"No input files.\n"
65-
if !@input_files;
48+
die"No input files.\n"unless@ARGV;
6649

6750
# Make sure output_path ends in a slash.
6851
if ($output_pathne'' &&substr($output_path, -1)ne'/')
@@ -76,7 +59,7 @@
7659
my%catalogs;
7760
my%catalog_data;
7861
my@catnames;
79-
foreachmy$datfile (@input_files)
62+
foreachmy$datfile (@ARGV)
8063
{
8164
$datfile =~/(.+)\.dat$/
8265
ordie"Input files need to be data (.dat) files.\n";
@@ -130,7 +113,7 @@
130113
if !(grep {$_eq$attname }@METADATA);
131114
}
132115

133-
#Overwrite .dat filesin place, since they are under version control.
116+
#Write output filesto specified directory.
134117
my$datfile ="$output_path$catname.dat";
135118
openmy$dat,'>',$datfile
136119
ordie"can't open$datfile:$!";
@@ -318,10 +301,12 @@ sub usage
318301
Usage: reformat_dat_file.pl [options] datafile...
319302
320303
Options:
321-
-o PATH writeoutputfiles to PATH instead of current directory
304+
--output PATH outputdirectory (default '.')
322305
--full-tuples write out full tuples, including default values
323306
324-
Expects a list of .dat files as arguments.
307+
Non-option arguments are the names of input .dat files.
308+
Updated files are written to the output directory,
309+
possibly overwriting the input files.
325310
326311
EOM
327312
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp