Commit 5078be48 authored by Tom Lane's avatar Tom Lane

Tweak new Perl pgindent for compatibility with middle-aged Perls.

We seem to have a rough policy that our Perl scripts should work with
Perl 5.8, so make this one do so.  Main change is to not use the newfangled
\h character class in regexes; "[ \t]" is a serviceable replacement.
parent eea65943
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
use strict; use strict;
use warnings; use warnings;
use 5.008001;
use Cwd qw(abs_path getcwd); use Cwd qw(abs_path getcwd);
use File::Find; use File::Find;
...@@ -9,11 +10,10 @@ use File::Spec qw(devnull); ...@@ -9,11 +10,10 @@ use File::Spec qw(devnull);
use File::Temp; use File::Temp;
use IO::Handle; use IO::Handle;
use Getopt::Long; use Getopt::Long;
use Readonly;
# Update for pg_bsd_indent version # Update for pg_bsd_indent version
Readonly my $INDENT_VERSION => "1.1"; my $INDENT_VERSION = "1.1";
Readonly my $devnull => File::Spec->devnull; my $devnull = File::Spec->devnull;
# Common indent settings # Common indent settings
my $indent_opts = my $indent_opts =
...@@ -188,12 +188,12 @@ sub pre_indent ...@@ -188,12 +188,12 @@ sub pre_indent
my $source = shift; my $source = shift;
# remove trailing whitespace # remove trailing whitespace
$source =~ s/\h+$//gm; $source =~ s/[ \t]+$//gm;
## Comments ## Comments
# Convert // comments to /* */ # Convert // comments to /* */
$source =~ s!^(\h*)//(.*)$!$1/* $2 */!gm; $source =~ s!^([ \t]*)//(.*)$!$1/* $2 */!gm;
# 'else' followed by a single-line comment, followed by # 'else' followed by a single-line comment, followed by
# a brace on the next line confuses BSD indent, so we push # a brace on the next line confuses BSD indent, so we push
...@@ -204,13 +204,13 @@ sub pre_indent ...@@ -204,13 +204,13 @@ sub pre_indent
# FILE: ../../../src/backend/rewrite/rewriteHandler.c # FILE: ../../../src/backend/rewrite/rewriteHandler.c
# Error@2259: # Error@2259:
# Stuff missing from end of file # Stuff missing from end of file
$source =~ s!(\}|\h)else\h*(/\*)(.*\*/)\h*$!$1else\n $2 _PGMV$3!gm; $source =~ s!(\}|[ \t])else[ \t]*(/\*)(.*\*/)[ \t]*$!$1else\n $2 _PGMV$3!gm;
# Indent multi-line after-'else' comment so BSD indent will move it # Indent multi-line after-'else' comment so BSD indent will move it
# properly. We already moved down single-line comments above. # properly. We already moved down single-line comments above.
# Check for '*' to make sure we are not in a single-line comment that # Check for '*' to make sure we are not in a single-line comment that
# has other text on the line. # has other text on the line.
$source =~ s!(\}|\h)else\h*(/\*[^*]*)\h*$!$1else\n $2!gm; $source =~ s!(\}|[ \t])else[ \t]*(/\*[^*]*)[ \t]*$!$1else\n $2!gm;
# Mark some comments for special treatment later # Mark some comments for special treatment later
$source =~ s!/\* +---!/*---X_X!g; $source =~ s!/\* +---!/*---X_X!g;
...@@ -226,7 +226,7 @@ sub pre_indent ...@@ -226,7 +226,7 @@ sub pre_indent
my $l2 = $srclines[$lno]; my $l2 = $srclines[$lno];
# Line is only a single open brace in column 0 # Line is only a single open brace in column 0
next unless $l2 =~ /^\{\h*$/; next unless $l2 =~ /^\{[ \t]*$/;
# previous line has a closing paren # previous line has a closing paren
next unless $srclines[ $lno - 1 ] =~ /\)/; next unless $srclines[ $lno - 1 ] =~ /\)/;
...@@ -234,7 +234,7 @@ sub pre_indent ...@@ -234,7 +234,7 @@ sub pre_indent
# previous line was struct, etc. # previous line was struct, etc.
next next
if $srclines[ $lno - 1 ] =~ if $srclines[ $lno - 1 ] =~
m!=|^(struct|enum|\h*typedef|extern\h+"C")!; m!=|^(struct|enum|[ \t]*typedef|extern[ \t]+"C")!;
$srclines[$lno] = "$l2\nint pgindent_func_no_var_fix;"; $srclines[$lno] = "$l2\nint pgindent_func_no_var_fix;";
} }
...@@ -245,8 +245,8 @@ sub pre_indent ...@@ -245,8 +245,8 @@ sub pre_indent
my $extern_c_start = '/* Open extern "C" */'; my $extern_c_start = '/* Open extern "C" */';
my $extern_c_stop = '/* Close extern "C" */'; my $extern_c_stop = '/* Close extern "C" */';
$source =~ $source =~
s!(^#ifdef\h+__cplusplus.*\nextern\h+"C"\h*\n)\{\h*$!$1$extern_c_start!gm; s!(^#ifdef[ \t]+__cplusplus.*\nextern[ \t]+"C"[ \t]*\n)\{[ \t]*$!$1$extern_c_start!gm;
$source =~ s!(^#ifdef\h+__cplusplus.*\n)\}\h*$!$1$extern_c_stop!gm; $source =~ s!(^#ifdef[ \t]+__cplusplus.*\n)\}[ \t]*$!$1$extern_c_stop!gm;
return $source; return $source;
} }
...@@ -267,21 +267,21 @@ sub post_indent ...@@ -267,21 +267,21 @@ sub post_indent
$source =~ s!/\*---X_X!/* ---!g; $source =~ s!/\*---X_X!/* ---!g;
# Pull up single-line comment after 'else' that was pulled down above # Pull up single-line comment after 'else' that was pulled down above
$source =~ s!else\n\h+/\* _PGMV!else\t/*!g; $source =~ s!else\n[ \t]+/\* _PGMV!else\t/*!g;
# Indent single-line after-'else' comment by only one tab. # Indent single-line after-'else' comment by only one tab.
$source =~ s!(\}|\h)else\h+(/\*.*\*/)\h*$!$1else\t$2!gm; $source =~ s!(\}|[ \t])else[ \t]+(/\*.*\*/)[ \t]*$!$1else\t$2!gm;
# Add tab before comments with no whitespace before them (on a tab stop) # Add tab before comments with no whitespace before them (on a tab stop)
$source =~ s!(\S)(/\*.*\*/)$!$1\t$2!gm; $source =~ s!(\S)(/\*.*\*/)$!$1\t$2!gm;
# Remove blank line between opening brace and block comment. # Remove blank line between opening brace and block comment.
$source =~ s!(\t*\{\n)\n(\h+/\*)$!$1$2!gm; $source =~ s!(\t*\{\n)\n([ \t]+/\*)$!$1$2!gm;
# cpp conditionals # cpp conditionals
# Reduce whitespace between #endif and comments to one tab # Reduce whitespace between #endif and comments to one tab
$source =~ s!^\#endif\h+/\*!#endif /*!gm; $source =~ s!^\#endif[ \t]+/\*!#endif /*!gm;
# Remove blank line(s) before #else, #elif, and #endif # Remove blank line(s) before #else, #elif, and #endif
$source =~ s!\n\n+(\#else|\#elif|\#endif)!\n$1!g; $source =~ s!\n\n+(\#else|\#elif|\#endif)!\n$1!g;
...@@ -292,10 +292,10 @@ sub post_indent ...@@ -292,10 +292,10 @@ sub post_indent
## Functions ## Functions
# Work around misindenting of function with no variables defined. # Work around misindenting of function with no variables defined.
$source =~ s!^\h*int\h+pgindent_func_no_var_fix;\h*\n{1,2}!!gm; $source =~ s!^[ \t]*int[ \t]+pgindent_func_no_var_fix;[ \t]*\n{1,2}!!gm;
# Use a single space before '*' in function return types # Use a single space before '*' in function return types
$source =~ s!^([A-Za-z_]\S*)\h+\*$!$1 *!gm; $source =~ s!^([A-Za-z_]\S*)[ \t]+\*$!$1 *!gm;
# Move prototype names to the same line as return type. Useful # Move prototype names to the same line as return type. Useful
# for ctags. Indent should do this, but it does not. It formats # for ctags. Indent should do this, but it does not. It formats
...@@ -308,21 +308,21 @@ sub post_indent ...@@ -308,21 +308,21 @@ sub post_indent
(\n$ident[^(\n]*)\n # e.g. static void (\n$ident[^(\n]*)\n # e.g. static void
( (
$ident\(\n? # func_name( $ident\(\n? # func_name(
(.*,(\h*$comment)?\n)* # args b4 final ln (.*,([ \t]*$comment)?\n)* # args b4 final ln
.*\);(\h*$comment)?$ # final line .*\);([ \t]*$comment)?$ # final line
) )
!$1 . (substr($1,-1,1) eq '*' ? '' : ' ') . $2!gmxe; !$1 . (substr($1,-1,1) eq '*' ? '' : ' ') . $2!gmxe;
## Other ## Other
# Remove too much indenting after closing brace. # Remove too much indenting after closing brace.
$source =~ s!^\}\t\h+!}\t!gm; $source =~ s!^\}\t[ \t]+!}\t!gm;
# Workaround indent bug that places excessive space before 'static'. # Workaround indent bug that places excessive space before 'static'.
$source =~ s!^static\h+!static !gm; $source =~ s!^static[ \t]+!static !gm;
# Remove leading whitespace from typedefs # Remove leading whitespace from typedefs
$source =~ s!^\h+typedef enum!typedef enum!gm $source =~ s!^[ \t]+typedef enum!typedef enum!gm
if $source_filename =~ 'libpq-(fe|events).h$'; if $source_filename =~ 'libpq-(fe|events).h$';
# Remove trailing blank lines # Remove trailing blank lines
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment