2
2
3
3
use strict;
4
4
use warnings;
5
+ use 5.008001;
5
6
6
7
use Cwd qw( abs_path getcwd) ;
7
8
use File::Find;
8
9
use File::Spec qw( devnull) ;
9
10
use File::Temp;
10
11
use IO::Handle;
11
12
use Getopt::Long;
12
- use Readonly;
13
13
14
14
# 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;
17
17
18
18
# Common indent settings
19
19
my $indent_opts =
@@ -188,12 +188,12 @@ sub pre_indent
188
188
my $source = shift ;
189
189
190
190
# remove trailing whitespace
191
- $source =~ s /\h +$// gm ;
191
+ $source =~ s /[ \t ] +$// gm ;
192
192
193
193
# # Comments
194
194
195
195
# Convert // comments to /* */
196
- $source =~ s ! ^(\h *)//(.*)$! $1 /* $2 */! gm ;
196
+ $source =~ s ! ^([ \t ] *)//(.*)$! $1 /* $2 */! gm ;
197
197
198
198
# 'else' followed by a single-line comment, followed by
199
199
# a brace on the next line confuses BSD indent, so we push
@@ -204,13 +204,13 @@ sub pre_indent
204
204
# FILE: ../../../src/backend/rewrite/rewriteHandler.c
205
205
# Error@2259:
206
206
# 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 ;
208
208
209
209
# Indent multi-line after-'else' comment so BSD indent will move it
210
210
# properly. We already moved down single-line comments above.
211
211
# Check for '*' to make sure we are not in a single-line comment that
212
212
# 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 ;
214
214
215
215
# Mark some comments for special treatment later
216
216
$source =~ s ! /\* +---! /*---X_X! g ;
@@ -226,15 +226,15 @@ sub pre_indent
226
226
my $l2 = $srclines [$lno ];
227
227
228
228
# Line is only a single open brace in column 0
229
- next unless $l2 =~ / ^\{\h *$ / ;
229
+ next unless $l2 =~ / ^\{ [ \t ] *$ / ;
230
230
231
231
# previous line has a closing paren
232
232
next unless $srclines [ $lno - 1 ] =~ / \) / ;
233
233
234
234
# previous line was struct, etc.
235
235
next
236
236
if $srclines [ $lno - 1 ] =~
237
- m ! =|^(struct|enum|\h *typedef|extern\h +"C")! ;
237
+ m ! =|^(struct|enum|[ \t ] *typedef|extern[ \t ] +"C")! ;
238
238
239
239
$srclines [$lno ] = " $l2 \n int pgindent_func_no_var_fix;" ;
240
240
}
@@ -245,8 +245,8 @@ sub pre_indent
245
245
my $extern_c_start = ' /* Open extern "C" */' ;
246
246
my $extern_c_stop = ' /* Close extern "C" */' ;
247
247
$source =~
248
- s ! (^#ifdef\h +__cplusplus.*\n extern\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.*\n extern[ \t ] +"C"[ \t ] *\n )\{ [ \t ] *$! $1 $extern_c_start ! gm ;
249
+ $source =~ s ! (^#ifdef[ \t ] +__cplusplus.*\n )\} [ \t ] *$! $1 $extern_c_stop ! gm ;
250
250
251
251
return $source ;
252
252
}
@@ -267,21 +267,21 @@ sub post_indent
267
267
$source =~ s ! /\* ---X_X! /* ---! g ;
268
268
269
269
# 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 ;
271
271
272
272
# 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 ;
274
274
275
275
# Add tab before comments with no whitespace before them (on a tab stop)
276
276
$source =~ s ! (\S )(/\* .*\* /)$! $1 \t $2 ! gm ;
277
277
278
278
# 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 ;
280
280
281
281
# cpp conditionals
282
282
283
283
# Reduce whitespace between #endif and comments to one tab
284
- $source =~ s ! ^\# endif\h +/\* ! #endif /*! gm ;
284
+ $source =~ s ! ^\# endif[ \t ] +/\* ! #endif /*! gm ;
285
285
286
286
# Remove blank line(s) before #else, #elif, and #endif
287
287
$source =~ s !\n\n +(\# else|\# elif|\# endif)! \n $1 ! g ;
@@ -292,10 +292,10 @@ sub post_indent
292
292
# # Functions
293
293
294
294
# 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 ;
296
296
297
297
# 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 ;
299
299
300
300
# Move prototype names to the same line as return type. Useful
301
301
# for ctags. Indent should do this, but it does not. It formats
@@ -308,21 +308,21 @@ sub post_indent
308
308
(\n $ident[^(\n ]*)\n # e.g. static void
309
309
(
310
310
$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
313
313
)
314
314
! $1 . (substr($1 ,-1,1) eq '*' ? '' : ' ') . $2 ! gmxe ;
315
315
316
316
# # Other
317
317
318
318
# Remove too much indenting after closing brace.
319
- $source =~ s ! ^\}\t\h +! }\t ! gm ;
319
+ $source =~ s ! ^\}\t [ \t ] +! }\t ! gm ;
320
320
321
321
# Workaround indent bug that places excessive space before 'static'.
322
- $source =~ s ! ^static\h +! static ! gm ;
322
+ $source =~ s ! ^static[ \t ] +! static ! gm ;
323
323
324
324
# Remove leading whitespace from typedefs
325
- $source =~ s ! ^\h +typedef enum! typedef enum! gm
325
+ $source =~ s ! ^[ \t ] +typedef enum! typedef enum! gm
326
326
if $source_filename =~ ' libpq-(fe|events).h$' ;
327
327
328
328
# Remove trailing blank lines
0 commit comments