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

Commitfe33a19

Browse files
committed
Use Getopt::Long for catalog scripts
Replace hand-rolled option parsing with the Getopt module. This isshorter and easier to read. In passing, make some cosmetic adjustmentsfor consistency.Author: John NaylorReviewed-by: David FetterDiscussion:https://postgr.es/m/CACPNZCvRjepXh5b2N50njN+rO_2Nzcf=jhMkKX7=79XWUKJyKA@mail.gmail.com
1 parent232a8e2 commitfe33a19

File tree

4 files changed

+29
-68
lines changed

4 files changed

+29
-68
lines changed

‎src/backend/catalog/Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ POSTGRES_BKI_DATA = $(addprefix $(top_srcdir)/src/include/catalog/,\
6868
pg_ts_template.dat pg_type.dat \
6969
)
7070

71-
# location of Catalog.pm
72-
catalogdir =$(top_srcdir)/src/backend/catalog
73-
7471
all: distprep generated-header-symlinks
7572

7673
distprep: bki-stamp
@@ -88,9 +85,8 @@ generated-header-symlinks: $(top_builddir)/src/include/catalog/header-stamp
8885
# instead is cheating a bit, but it will achieve the goal of updating the
8986
# version number when it changes.
9087
bki-stamp: genbki.pl Catalog.pm$(POSTGRES_BKI_SRCS)$(POSTGRES_BKI_DATA)$(top_srcdir)/configure.in
91-
$(PERL) -I$(catalogdir)$<\
92-
-I$(top_srcdir)/src/include/ --set-version=$(MAJORVERSION)\
93-
$(POSTGRES_BKI_SRCS)
88+
$(PERL)$< --include-path=$(top_srcdir)/src/include/\
89+
--set-version=$(MAJORVERSION)$(POSTGRES_BKI_SRCS)
9490
touch$@
9591

9692
# The generated headers must all be symlinked into builddir/src/include/,

‎src/backend/catalog/genbki.pl

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,29 @@
1616

1717
use strict;
1818
use warnings;
19+
use Getopt::Long;
1920

2021
use File::Basename;
2122
use File::Spec;
2223
BEGIN {use lib File::Spec->rel2abs(dirname(__FILE__)); }
2324

2425
use Catalog;
2526

26-
my@input_files;
2727
my$output_path ='';
2828
my$major_version;
2929
my$include_path;
3030

31-
# Process command line switches.
32-
while (@ARGV)
33-
{
34-
my$arg =shift@ARGV;
35-
if ($arg !~/^-/)
36-
{
37-
push@input_files,$arg;
38-
}
39-
elsif ($arg =~/^-I/)
40-
{
41-
$include_path =length($arg) > 2 ?substr($arg, 2) :shift@ARGV;
42-
}
43-
elsif ($arg =~/^-o/)
44-
{
45-
$output_path =length($arg) > 2 ?substr($arg, 2) :shift@ARGV;
46-
}
47-
elsif ($arg =~/^--set-version=(.*)$/)
48-
{
49-
$major_version =$1;
50-
die"Invalid version string.\n"
51-
if !($major_version =~/^\d+$/);
52-
}
53-
else
54-
{
55-
usage();
56-
}
57-
}
31+
GetOptions(
32+
'output:s'=> \$output_path,
33+
'set-version:s'=> \$major_version,
34+
'include-path:s'=> \$include_path) || usage();
5835

5936
# Sanity check arguments.
60-
die"No input files.\n"if !@input_files;
61-
die"--set-version must be specified.\n"if !defined$major_version;
62-
die"-I, the header include path, must be specified.\n"if !$include_path;
37+
die"No input files.\n"unless@ARGV;
38+
die"--set-version must be specified.\n"unless$major_version;
39+
die"Invalid version string:$major_version\n"
40+
unless$major_version =~/^\d+$/;
41+
die"--include-path must be specified.\n"unless$include_path;
6342

6443
# Make sure paths end with a slash.
6544
if ($output_pathne'' &&substr($output_path, -1)ne'/')
@@ -79,7 +58,7 @@
7958
my@index_decls;
8059
my%oidcounts;
8160

82-
foreachmy$header (@input_files)
61+
foreachmy$header (@ARGV)
8362
{
8463
$header =~/(.+)\.h$/
8564
ordie"Input files need to be header files.\n";
@@ -917,12 +896,12 @@ sub form_pg_type_symbol
917896
subusage
918897
{
919898
die<<EOM;
920-
Usage: genbki.pl [options] header...
899+
Usage:perl -I [directory of Catalog.pm]genbki.pl [--output/-o <path>] [--include-path/-i <path>] header...
921900
922901
Options:
923-
-I include path
924-
-o output path
902+
--output Output directory (default '.')
925903
--set-version PostgreSQL version number for initdb cross-check
904+
--include-path Include path in source tree
926905
927906
genbki.pl generates BKI files and symbol definition
928907
headers from specially formatted header files and .dat

‎src/backend/utils/Gen_fmgrtab.pl

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,14 @@
1818

1919
use strict;
2020
use warnings;
21+
use Getopt::Long;
2122

22-
# Collect arguments
23-
my@input_files;
2423
my$output_path ='';
2524
my$include_path;
2625

27-
while (@ARGV)
28-
{
29-
my$arg =shift@ARGV;
30-
if ($arg !~/^-/)
31-
{
32-
push@input_files,$arg;
33-
}
34-
elsif ($arg =~/^-o/)
35-
{
36-
$output_path =length($arg) > 2 ?substr($arg, 2) :shift@ARGV;
37-
}
38-
elsif ($arg =~/^-I/)
39-
{
40-
$include_path =length($arg) > 2 ?substr($arg, 2) :shift@ARGV;
41-
}
42-
else
43-
{
44-
usage();
45-
}
46-
}
26+
GetOptions(
27+
'output:s'=> \$output_path,
28+
'include-path:s'=> \$include_path) || usage();
4729

4830
# Make sure output_path ends in a slash.
4931
if ($output_pathne'' &&substr($output_path, -1)ne'/')
@@ -52,8 +34,8 @@
5234
}
5335

5436
# Sanity check arguments.
55-
die"No input files.\n"if !@input_files;
56-
die"Noincludepath; youmustspecify -I.\n"if !$include_path;
37+
die"No input files.\n"unless@ARGV;
38+
die"--include-pathmustbe specified.\n"unless$include_path;
5739

5840
# Read all the input files into internal data structures.
5941
# Note: We pass data file names as arguments and then look for matching
@@ -63,7 +45,7 @@
6345
# more than one data file.
6446
my%catalogs;
6547
my%catalog_data;
66-
foreachmy$datfile (@input_files)
48+
foreachmy$datfile (@ARGV)
6749
{
6850
$datfile =~/(.+)\.dat$/
6951
ordie"Input files need to be data (.dat) files.\n";
@@ -292,7 +274,11 @@
292274
subusage
293275
{
294276
die<<EOM;
295-
Usage: perl -I [directory of Catalog.pm] Gen_fmgrtab.pl -I [include path] [path to pg_proc.dat]
277+
Usage: perl -I [directory of Catalog.pm] Gen_fmgrtab.pl [--include-path/-i <path>] [path to pg_proc.dat]
278+
279+
Options:
280+
--output Output directory (default '.')
281+
--include-path Include path in source tree
296282
297283
Gen_fmgrtab.pl generates fmgroids.h, fmgrprotos.h, and fmgrtab.c from
298284
pg_proc.dat

‎src/backend/utils/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $(SUBDIRS:%=%-recursive): fmgr-stamp errcodes.h
3535
# the timestamps of the individual output files, because the Perl script
3636
# won't update them if they didn't change (to avoid unnecessary recompiles).
3737
fmgr-stamp: Gen_fmgrtab.pl$(catalogdir)/Catalog.pm$(top_srcdir)/src/include/catalog/pg_proc.dat$(top_srcdir)/src/include/access/transam.h
38-
$(PERL) -I$(catalogdir)$< -I$(top_srcdir)/src/include/$(top_srcdir)/src/include/catalog/pg_proc.dat
38+
$(PERL) -I$(catalogdir)$< --include-path=$(top_srcdir)/src/include/$(top_srcdir)/src/include/catalog/pg_proc.dat
3939
touch$@
4040

4141
errcodes.h:$(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp