Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5078be4

Browse files
committed
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.
1 parent eea6594 commit 5078be4

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/tools/pgindent/pgindent

+22-22
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
use strict;
44
use warnings;
5+
use 5.008001;
56

67
use Cwd qw(abs_path getcwd);
78
use File::Find;
89
use File::Spec qw(devnull);
910
use File::Temp;
1011
use IO::Handle;
1112
use Getopt::Long;
12-
use Readonly;
1313

1414
# Update for pg_bsd_indent version
15-
Readonly my $INDENT_VERSION => "1.1";
16-
Readonly my $devnull => File::Spec->devnull;
15+
my $INDENT_VERSION = "1.1";
16+
my $devnull = File::Spec->devnull;
1717

1818
# Common indent settings
1919
my $indent_opts =
@@ -188,12 +188,12 @@ sub pre_indent
188188
my $source = shift;
189189

190190
# remove trailing whitespace
191-
$source =~ s/\h+$//gm;
191+
$source =~ s/[ \t]+$//gm;
192192

193193
## Comments
194194

195195
# Convert // comments to /* */
196-
$source =~ s!^(\h*)//(.*)$!$1/* $2 */!gm;
196+
$source =~ s!^([ \t]*)//(.*)$!$1/* $2 */!gm;
197197

198198
# 'else' followed by a single-line comment, followed by
199199
# a brace on the next line confuses BSD indent, so we push
@@ -204,13 +204,13 @@ sub pre_indent
204204
# FILE: ../../../src/backend/rewrite/rewriteHandler.c
205205
# Error@2259:
206206
# Stuff missing from end of file
207-
$source =~ s!(\}|\h)else\h*(/\*)(.*\*/)\h*$!$1else\n $2 _PGMV$3!gm;
207+
$source =~ s!(\}|[ \t])else[ \t]*(/\*)(.*\*/)[ \t]*$!$1else\n $2 _PGMV$3!gm;
208208

209209
# Indent multi-line after-'else' comment so BSD indent will move it
210210
# properly. We already moved down single-line comments above.
211211
# Check for '*' to make sure we are not in a single-line comment that
212212
# has other text on the line.
213-
$source =~ s!(\}|\h)else\h*(/\*[^*]*)\h*$!$1else\n $2!gm;
213+
$source =~ s!(\}|[ \t])else[ \t]*(/\*[^*]*)[ \t]*$!$1else\n $2!gm;
214214

215215
# Mark some comments for special treatment later
216216
$source =~ s!/\* +---!/*---X_X!g;
@@ -226,15 +226,15 @@ sub pre_indent
226226
my $l2 = $srclines[$lno];
227227

228228
# Line is only a single open brace in column 0
229-
next unless $l2 =~ /^\{\h*$/;
229+
next unless $l2 =~ /^\{[ \t]*$/;
230230

231231
# previous line has a closing paren
232232
next unless $srclines[ $lno - 1 ] =~ /\)/;
233233

234234
# previous line was struct, etc.
235235
next
236236
if $srclines[ $lno - 1 ] =~
237-
m!=|^(struct|enum|\h*typedef|extern\h+"C")!;
237+
m!=|^(struct|enum|[ \t]*typedef|extern[ \t]+"C")!;
238238

239239
$srclines[$lno] = "$l2\nint pgindent_func_no_var_fix;";
240240
}
@@ -245,8 +245,8 @@ sub pre_indent
245245
my $extern_c_start = '/* Open extern "C" */';
246246
my $extern_c_stop = '/* Close extern "C" */';
247247
$source =~
248-
s!(^#ifdef\h+__cplusplus.*\nextern\h+"C"\h*\n)\{\h*$!$1$extern_c_start!gm;
249-
$source =~ s!(^#ifdef\h+__cplusplus.*\n)\}\h*$!$1$extern_c_stop!gm;
248+
s!(^#ifdef[ \t]+__cplusplus.*\nextern[ \t]+"C"[ \t]*\n)\{[ \t]*$!$1$extern_c_start!gm;
249+
$source =~ s!(^#ifdef[ \t]+__cplusplus.*\n)\}[ \t]*$!$1$extern_c_stop!gm;
250250

251251
return $source;
252252
}
@@ -267,21 +267,21 @@ sub post_indent
267267
$source =~ s!/\*---X_X!/* ---!g;
268268

269269
# Pull up single-line comment after 'else' that was pulled down above
270-
$source =~ s!else\n\h+/\* _PGMV!else\t/*!g;
270+
$source =~ s!else\n[ \t]+/\* _PGMV!else\t/*!g;
271271

272272
# Indent single-line after-'else' comment by only one tab.
273-
$source =~ s!(\}|\h)else\h+(/\*.*\*/)\h*$!$1else\t$2!gm;
273+
$source =~ s!(\}|[ \t])else[ \t]+(/\*.*\*/)[ \t]*$!$1else\t$2!gm;
274274

275275
# Add tab before comments with no whitespace before them (on a tab stop)
276276
$source =~ s!(\S)(/\*.*\*/)$!$1\t$2!gm;
277277

278278
# Remove blank line between opening brace and block comment.
279-
$source =~ s!(\t*\{\n)\n(\h+/\*)$!$1$2!gm;
279+
$source =~ s!(\t*\{\n)\n([ \t]+/\*)$!$1$2!gm;
280280

281281
# cpp conditionals
282282

283283
# Reduce whitespace between #endif and comments to one tab
284-
$source =~ s!^\#endif\h+/\*!#endif /*!gm;
284+
$source =~ s!^\#endif[ \t]+/\*!#endif /*!gm;
285285

286286
# Remove blank line(s) before #else, #elif, and #endif
287287
$source =~ s!\n\n+(\#else|\#elif|\#endif)!\n$1!g;
@@ -292,10 +292,10 @@ sub post_indent
292292
## Functions
293293

294294
# Work around misindenting of function with no variables defined.
295-
$source =~ s!^\h*int\h+pgindent_func_no_var_fix;\h*\n{1,2}!!gm;
295+
$source =~ s!^[ \t]*int[ \t]+pgindent_func_no_var_fix;[ \t]*\n{1,2}!!gm;
296296

297297
# Use a single space before '*' in function return types
298-
$source =~ s!^([A-Za-z_]\S*)\h+\*$!$1 *!gm;
298+
$source =~ s!^([A-Za-z_]\S*)[ \t]+\*$!$1 *!gm;
299299

300300
# Move prototype names to the same line as return type. Useful
301301
# for ctags. Indent should do this, but it does not. It formats
@@ -308,21 +308,21 @@ sub post_indent
308308
(\n$ident[^(\n]*)\n # e.g. static void
309309
(
310310
$ident\(\n? # func_name(
311-
(.*,(\h*$comment)?\n)* # args b4 final ln
312-
.*\);(\h*$comment)?$ # final line
311+
(.*,([ \t]*$comment)?\n)* # args b4 final ln
312+
.*\);([ \t]*$comment)?$ # final line
313313
)
314314
!$1 . (substr($1,-1,1) eq '*' ? '' : ' ') . $2!gmxe;
315315

316316
## Other
317317

318318
# Remove too much indenting after closing brace.
319-
$source =~ s!^\}\t\h+!}\t!gm;
319+
$source =~ s!^\}\t[ \t]+!}\t!gm;
320320

321321
# Workaround indent bug that places excessive space before 'static'.
322-
$source =~ s!^static\h+!static !gm;
322+
$source =~ s!^static[ \t]+!static !gm;
323323

324324
# Remove leading whitespace from typedefs
325-
$source =~ s!^\h+typedef enum!typedef enum!gm
325+
$source =~ s!^[ \t]+typedef enum!typedef enum!gm
326326
if $source_filename =~ 'libpq-(fe|events).h$';
327327

328328
# Remove trailing blank lines

0 commit comments

Comments
 (0)