diff options
| author | Peter Eisentraut | 2017-03-27 02:24:13 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2017-03-27 12:18:22 +0000 |
| commit | facde2a98f0b5f7689b4e30a9e7376e926e733b8 (patch) | |
| tree | ab8b2cc1b2bd47b7db5e2def26d8eca4ce6ca438 /src/backend | |
| parent | de4da168d57de812bb30d359394b7913635d21a9 (diff) | |
Clean up Perl code according to perlcritic
Fix all perlcritic warnings of severity level 5, except in
src/backend/utils/Gen_dummy_probes.pl, which is automatically generated.
Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/catalog/Catalog.pm | 8 | ||||
| -rw-r--r-- | src/backend/catalog/genbki.pl | 64 | ||||
| -rw-r--r-- | src/backend/parser/check_keywords.pl | 30 | ||||
| -rw-r--r-- | src/backend/storage/lmgr/generate-lwlocknames.pl | 30 | ||||
| -rw-r--r-- | src/backend/utils/Gen_fmgrtab.pl | 32 | ||||
| -rw-r--r-- | src/backend/utils/generate-errcodes.pl | 2 |
6 files changed, 83 insertions, 83 deletions
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm index bccbc5118db..6ffd5f904a1 100644 --- a/src/backend/catalog/Catalog.pm +++ b/src/backend/catalog/Catalog.pm @@ -44,13 +44,13 @@ sub Catalogs $catalog{columns} = []; $catalog{data} = []; - open(INPUT_FILE, '<', $input_file) || die "$input_file: $!"; + open(my $ifh, '<', $input_file) || die "$input_file: $!"; my ($filename) = ($input_file =~ m/(\w+)\.h$/); my $natts_pat = "Natts_$filename"; # Scan the input file. - while (<INPUT_FILE>) + while (<$ifh>) { # Strip C-style comments. @@ -59,7 +59,7 @@ sub Catalogs { # handle multi-line comments properly. - my $next_line = <INPUT_FILE>; + my $next_line = <$ifh>; die "$input_file: ends within C-style comment\n" if !defined $next_line; $_ .= $next_line; @@ -211,7 +211,7 @@ sub Catalogs } } $catalogs{$catname} = \%catalog; - close INPUT_FILE; + close $ifh; } return \%catalogs; } diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index 079516ca2f1..f9ecb025483 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -66,16 +66,16 @@ if ($output_path ne '' && substr($output_path, -1) ne '/') # Open temp files my $tmpext = ".tmp$$"; my $bkifile = $output_path . 'postgres.bki'; -open BKI, '>', $bkifile . $tmpext +open my $bki, '>', $bkifile . $tmpext or die "can't open $bkifile$tmpext: $!"; my $schemafile = $output_path . 'schemapg.h'; -open SCHEMAPG, '>', $schemafile . $tmpext +open my $schemapg, '>', $schemafile . $tmpext or die "can't open $schemafile$tmpext: $!"; my $descrfile = $output_path . 'postgres.description'; -open DESCR, '>', $descrfile . $tmpext +open my $descr, '>', $descrfile . $tmpext or die "can't open $descrfile$tmpext: $!"; my $shdescrfile = $output_path . 'postgres.shdescription'; -open SHDESCR, '>', $shdescrfile . $tmpext +open my $shdescr, '>', $shdescrfile . $tmpext or die "can't open $shdescrfile$tmpext: $!"; # Fetch some special data that we will substitute into the output file. @@ -97,7 +97,7 @@ my $catalogs = Catalog::Catalogs(@input_files); # Generate postgres.bki, postgres.description, and postgres.shdescription # version marker for .bki file -print BKI "# PostgreSQL $major_version\n"; +print $bki "# PostgreSQL $major_version\n"; # vars to hold data needed for schemapg.h my %schemapg_entries; @@ -110,7 +110,7 @@ foreach my $catname (@{ $catalogs->{names} }) # .bki CREATE command for this catalog my $catalog = $catalogs->{$catname}; - print BKI "create $catname $catalog->{relation_oid}" + print $bki "create $catname $catalog->{relation_oid}" . $catalog->{shared_relation} . $catalog->{bootstrap} . $catalog->{without_oids} @@ -120,7 +120,7 @@ foreach my $catname (@{ $catalogs->{names} }) my @attnames; my $first = 1; - print BKI " (\n"; + print $bki " (\n"; foreach my $column (@{ $catalog->{columns} }) { my $attname = $column->{name}; @@ -130,27 +130,27 @@ foreach my $catname (@{ $catalogs->{names} }) if (!$first) { - print BKI " ,\n"; + print $bki " ,\n"; } $first = 0; - print BKI " $attname = $atttype"; + print $bki " $attname = $atttype"; if (defined $column->{forcenotnull}) { - print BKI " FORCE NOT NULL"; + print $bki " FORCE NOT NULL"; } elsif (defined $column->{forcenull}) { - print BKI " FORCE NULL"; + print $bki " FORCE NULL"; } } - print BKI "\n )\n"; + print $bki "\n )\n"; # open it, unless bootstrap case (create bootstrap does this automatically) if ($catalog->{bootstrap} eq '') { - print BKI "open $catname\n"; + print $bki "open $catname\n"; } if (defined $catalog->{data}) @@ -175,17 +175,17 @@ foreach my $catname (@{ $catalogs->{names} }) # Write to postgres.bki my $oid = $row->{oid} ? "OID = $row->{oid} " : ''; - printf BKI "insert %s( %s)\n", $oid, $row->{bki_values}; + printf $bki "insert %s( %s)\n", $oid, $row->{bki_values}; # Write comments to postgres.description and postgres.shdescription if (defined $row->{descr}) { - printf DESCR "%s\t%s\t0\t%s\n", $row->{oid}, $catname, + printf $descr "%s\t%s\t0\t%s\n", $row->{oid}, $catname, $row->{descr}; } if (defined $row->{shdescr}) { - printf SHDESCR "%s\t%s\t%s\n", $row->{oid}, $catname, + printf $shdescr "%s\t%s\t%s\n", $row->{oid}, $catname, $row->{shdescr}; } } @@ -267,7 +267,7 @@ foreach my $catname (@{ $catalogs->{names} }) } } - print BKI "close $catname\n"; + print $bki "close $catname\n"; } # Any information needed for the BKI that is not contained in a pg_*.h header @@ -276,19 +276,19 @@ foreach my $catname (@{ $catalogs->{names} }) # Write out declare toast/index statements foreach my $declaration (@{ $catalogs->{toasting}->{data} }) { - print BKI $declaration; + print $bki $declaration; } foreach my $declaration (@{ $catalogs->{indexing}->{data} }) { - print BKI $declaration; + print $bki $declaration; } # Now generate schemapg.h # Opening boilerplate for schemapg.h -print SCHEMAPG <<EOM; +print $schemapg <<EOM; /*------------------------------------------------------------------------- * * schemapg.h @@ -313,19 +313,19 @@ EOM # Emit schemapg declarations foreach my $table_name (@tables_needing_macros) { - print SCHEMAPG "\n#define Schema_$table_name \\\n"; - print SCHEMAPG join ", \\\n", @{ $schemapg_entries{$table_name} }; - print SCHEMAPG "\n"; + print $schemapg "\n#define Schema_$table_name \\\n"; + print $schemapg join ", \\\n", @{ $schemapg_entries{$table_name} }; + print $schemapg "\n"; } # Closing boilerplate for schemapg.h -print SCHEMAPG "\n#endif /* SCHEMAPG_H */\n"; +print $schemapg "\n#endif /* SCHEMAPG_H */\n"; # We're done emitting data -close BKI; -close SCHEMAPG; -close DESCR; -close SHDESCR; +close $bki; +close $schemapg; +close $descr; +close $shdescr; # Finally, rename the completed files into place. Catalog::RenameTempFile($bkifile, $tmpext); @@ -425,7 +425,7 @@ sub bki_insert my @attnames = @_; my $oid = $row->{oid} ? "OID = $row->{oid} " : ''; my $bki_values = join ' ', map $row->{$_}, @attnames; - printf BKI "insert %s( %s)\n", $oid, $bki_values; + printf $bki "insert %s( %s)\n", $oid, $bki_values; } # The field values of a Schema_pg_xxx declaration are similar, but not @@ -472,15 +472,15 @@ sub find_defined_symbol } my $file = $path . $catalog_header; next if !-f $file; - open(FIND_DEFINED_SYMBOL, '<', $file) || die "$file: $!"; - while (<FIND_DEFINED_SYMBOL>) + open(my $find_defined_symbol, '<', $file) || die "$file: $!"; + while (<$find_defined_symbol>) { if (/^#define\s+\Q$symbol\E\s+(\S+)/) { return $1; } } - close FIND_DEFINED_SYMBOL; + close $find_defined_symbol; die "$file: no definition found for $symbol\n"; } die "$catalog_header: not found in any include directory\n"; diff --git a/src/backend/parser/check_keywords.pl b/src/backend/parser/check_keywords.pl index 45862ce940e..84fef1d95e8 100644 --- a/src/backend/parser/check_keywords.pl +++ b/src/backend/parser/check_keywords.pl @@ -14,7 +14,7 @@ my $kwlist_filename = $ARGV[1]; my $errors = 0; -sub error(@) +sub error { print STDERR @_; $errors = 1; @@ -29,18 +29,18 @@ $keyword_categories{'col_name_keyword'} = 'COL_NAME_KEYWORD'; $keyword_categories{'type_func_name_keyword'} = 'TYPE_FUNC_NAME_KEYWORD'; $keyword_categories{'reserved_keyword'} = 'RESERVED_KEYWORD'; -open(GRAM, $gram_filename) || die("Could not open : $gram_filename"); +open(my $gram, '<', $gram_filename) || die("Could not open : $gram_filename"); -my ($S, $s, $k, $n, $kcat); +my $kcat; my $comment; my @arr; my %keywords; -line: while (<GRAM>) +line: while (my $S = <$gram>) { - chomp; # strip record separator + chomp $S; # strip record separator - $S = $_; + my $s; # Make sure any braces are split $s = '{', $S =~ s/$s/ { /g; @@ -54,7 +54,7 @@ line: while (<GRAM>) { # Is this the beginning of a keyword list? - foreach $k (keys %keyword_categories) + foreach my $k (keys %keyword_categories) { if ($S =~ m/^($k):/) { @@ -66,7 +66,7 @@ line: while (<GRAM>) } # Now split the line into individual fields - $n = (@arr = split(' ', $S)); + my $n = (@arr = split(' ', $S)); # Ok, we're in a keyword list. Go through each field in turn for (my $fieldIndexer = 0; $fieldIndexer < $n; $fieldIndexer++) @@ -109,15 +109,15 @@ line: while (<GRAM>) push @{ $keywords{$kcat} }, $arr[$fieldIndexer]; } } -close GRAM; +close $gram; # Check that each keyword list is in alphabetical order (just for neatnik-ism) -my ($prevkword, $kword, $bare_kword); -foreach $kcat (keys %keyword_categories) +my ($prevkword, $bare_kword); +foreach my $kcat (keys %keyword_categories) { $prevkword = ''; - foreach $kword (@{ $keywords{$kcat} }) + foreach my $kword (@{ $keywords{$kcat} }) { # Some keyword have a _P suffix. Remove it for the comparison. @@ -149,12 +149,12 @@ while (my ($kcat, $kcat_id) = each(%keyword_categories)) # Now read in kwlist.h -open(KWLIST, $kwlist_filename) || die("Could not open : $kwlist_filename"); +open(my $kwlist, '<', $kwlist_filename) || die("Could not open : $kwlist_filename"); my $prevkwstring = ''; my $bare_kwname; my %kwhash; -kwlist_line: while (<KWLIST>) +kwlist_line: while (<$kwlist>) { my ($line) = $_; @@ -219,7 +219,7 @@ kwlist_line: while (<KWLIST>) } } } -close KWLIST; +close $kwlist; # Check that we've paired up all keywords from gram.y with lines in kwlist.h while (my ($kwcat, $kwcat_id) = each(%keyword_categories)) diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl index f80d2c8121e..10d069896f5 100644 --- a/src/backend/storage/lmgr/generate-lwlocknames.pl +++ b/src/backend/storage/lmgr/generate-lwlocknames.pl @@ -9,21 +9,21 @@ use strict; my $lastlockidx = -1; my $continue = "\n"; -open my $lwlocknames, $ARGV[0] or die; +open my $lwlocknames, '<', $ARGV[0] or die; # Include PID in suffix in case parallel make runs this multiple times. my $htmp = "lwlocknames.h.tmp$$"; my $ctmp = "lwlocknames.c.tmp$$"; -open H, '>', $htmp or die "Could not open $htmp: $!"; -open C, '>', $ctmp or die "Could not open $ctmp: $!"; +open my $h, '>', $htmp or die "Could not open $htmp: $!"; +open my $c, '>', $ctmp or die "Could not open $ctmp: $!"; my $autogen = "/* autogenerated from src/backend/storage/lmgr/lwlocknames.txt, do not edit */\n"; -print H $autogen; -print H "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n"; -print C $autogen, "\n"; +print $h $autogen; +print $h "/* there is deliberately not an #ifndef LWLOCKNAMES_H here */\n\n"; +print $c $autogen, "\n"; -print C "char *MainLWLockNames[] = {"; +print $c "char *MainLWLockNames[] = {"; while (<$lwlocknames>) { @@ -44,22 +44,22 @@ while (<$lwlocknames>) while ($lastlockidx < $lockidx - 1) { ++$lastlockidx; - printf C "%s \"<unassigned:%d>\"", $continue, $lastlockidx; + printf $c "%s \"<unassigned:%d>\"", $continue, $lastlockidx; $continue = ",\n"; } - printf C "%s \"%s\"", $continue, $lockname; + printf $c "%s \"%s\"", $continue, $lockname; $lastlockidx = $lockidx; $continue = ",\n"; - print H "#define $lockname (&MainLWLockArray[$lockidx].lock)\n"; + print $h "#define $lockname (&MainLWLockArray[$lockidx].lock)\n"; } -printf C "\n};\n"; -print H "\n"; -printf H "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1; +printf $c "\n};\n"; +print $h "\n"; +printf $h "#define NUM_INDIVIDUAL_LWLOCKS %s\n", $lastlockidx + 1; -close H; -close C; +close $h; +close $c; rename($htmp, 'lwlocknames.h') || die "rename: $htmp: $!"; rename($ctmp, 'lwlocknames.c') || die "rename: $ctmp: $!"; diff --git a/src/backend/utils/Gen_fmgrtab.pl b/src/backend/utils/Gen_fmgrtab.pl index cdd603ab6fe..2af9b355e75 100644 --- a/src/backend/utils/Gen_fmgrtab.pl +++ b/src/backend/utils/Gen_fmgrtab.pl @@ -90,11 +90,11 @@ my $oidsfile = $output_path . 'fmgroids.h'; my $protosfile = $output_path . 'fmgrprotos.h'; my $tabfile = $output_path . 'fmgrtab.c'; -open H, '>', $oidsfile . $tmpext or die "Could not open $oidsfile$tmpext: $!"; -open P, '>', $protosfile . $tmpext or die "Could not open $protosfile$tmpext: $!"; -open T, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!"; +open my $ofh, '>', $oidsfile . $tmpext or die "Could not open $oidsfile$tmpext: $!"; +open my $pfh, '>', $protosfile . $tmpext or die "Could not open $protosfile$tmpext: $!"; +open my $tfh, '>', $tabfile . $tmpext or die "Could not open $tabfile$tmpext: $!"; -print H +print $ofh qq|/*------------------------------------------------------------------------- * * fmgroids.h @@ -132,7 +132,7 @@ qq|/*------------------------------------------------------------------------- */ |; -print P +print $pfh qq|/*------------------------------------------------------------------------- * * fmgrprotos.h @@ -159,7 +159,7 @@ qq|/*------------------------------------------------------------------------- |; -print T +print $tfh qq|/*------------------------------------------------------------------------- * * fmgrtab.c @@ -193,26 +193,26 @@ foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr) { next if $seenit{ $s->{prosrc} }; $seenit{ $s->{prosrc} } = 1; - print H "#define F_" . uc $s->{prosrc} . " $s->{oid}\n"; - print P "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n"; + print $ofh "#define F_" . uc $s->{prosrc} . " $s->{oid}\n"; + print $pfh "extern Datum $s->{prosrc}(PG_FUNCTION_ARGS);\n"; } # Create the fmgr_builtins table -print T "\nconst FmgrBuiltin fmgr_builtins[] = {\n"; +print $tfh "\nconst FmgrBuiltin fmgr_builtins[] = {\n"; my %bmap; $bmap{'t'} = 'true'; $bmap{'f'} = 'false'; foreach my $s (sort { $a->{oid} <=> $b->{oid} } @fmgr) { - print T + print $tfh " { $s->{oid}, \"$s->{prosrc}\", $s->{nargs}, $bmap{$s->{strict}}, $bmap{$s->{retset}}, $s->{prosrc} },\n"; } # And add the file footers. -print H "\n#endif /* FMGROIDS_H */\n"; -print P "\n#endif /* FMGRPROTOS_H */\n"; +print $ofh "\n#endif /* FMGROIDS_H */\n"; +print $pfh "\n#endif /* FMGRPROTOS_H */\n"; -print T +print $tfh qq| /* dummy entry is easier than getting rid of comma after last real one */ /* (not that there has ever been anything wrong with *having* a comma after the last field in an array initializer) */ @@ -223,9 +223,9 @@ qq| /* dummy entry is easier than getting rid of comma after last real one */ const int fmgr_nbuiltins = (sizeof(fmgr_builtins) / sizeof(FmgrBuiltin)) - 1; |; -close(H); -close(P); -close(T); +close($ofh); +close($pfh); +close($tfh); # Finally, rename the completed files into place. Catalog::RenameTempFile($oidsfile, $tmpext); diff --git a/src/backend/utils/generate-errcodes.pl b/src/backend/utils/generate-errcodes.pl index b84c6b0d0fb..6a577f657ab 100644 --- a/src/backend/utils/generate-errcodes.pl +++ b/src/backend/utils/generate-errcodes.pl @@ -10,7 +10,7 @@ print "/* autogenerated from src/backend/utils/errcodes.txt, do not edit */\n"; print "/* there is deliberately not an #ifndef ERRCODES_H here */\n"; -open my $errcodes, $ARGV[0] or die; +open my $errcodes, '<', $ARGV[0] or die; while (<$errcodes>) { |
