nbtree VACUUM: cope with topparent inconsistencies.
[pgsql.git] / src / tools / mark_pgdllimport.pl
blob45b4e73bff1acd281e0939f950d39bb6ba805689
1 #!/usr/bin/perl
3 #----------------------------------------------------------------------
5 # mark_pgdllimport.pl
6 # Perl script that tries to add PGDLLIMPORT markings to PostgreSQL
7 # header files.
9 # This relies on a few idiosyncrasies of the PostgreSQL coding style,
10 # such as the fact that we always use "extern" in function
11 # declarations, and that we don't use // comments. It's not very
12 # smart and may not catch all cases.
14 # It's probably a good idea to run pgindent on any files that this
15 # script modifies before committing. This script uses as arguments
16 # a list of the header files to scan for the markings.
18 # Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
19 # Portions Copyright (c) 1994, Regents of the University of California
21 # src/tools/mark_pgdllimport.pl
23 #----------------------------------------------------------------------
25 use strict;
26 use warnings;
28 for my $include_file (@ARGV)
30 open(my $rfh, '<', $include_file) || die "$include_file: $!";
31 my $buffer = '';
32 my $num_pgdllimport_added = 0;
34 while (my $raw_line = <$rfh>)
36 my $needs_pgdllimport = 1;
38 # By convention we declare global variables explicitly extern. We're
39 # looking for those not already marked with PGDLLIMPORT.
40 $needs_pgdllimport = 0
41 if $raw_line !~ /^extern\s+/
42 || $raw_line =~ /PGDLLIMPORT/;
44 # Make a copy of the line and perform a simple-minded comment strip.
45 # Also strip trailing whitespace.
46 my $stripped_line = $raw_line;
47 $stripped_line =~ s/\/\*.*\*\///g;
48 $stripped_line =~ s/\s+$//;
50 # Variable declarations should end in a semicolon. If we see an
51 # opening parenthesis, it's probably a function declaration.
52 $needs_pgdllimport = 0
53 if $stripped_line !~ /;$/
54 || $stripped_line =~ /\(/;
56 # Add PGDLLIMPORT marker, if required.
57 if ($needs_pgdllimport)
59 $raw_line =~ s/^extern/extern PGDLLIMPORT/;
60 ++$num_pgdllimport_added;
63 # Add line to buffer.
64 $buffer .= $raw_line;
67 close($rfh);
69 # If we added any PGDLLIMPORT markers, rewrite the file.
70 if ($num_pgdllimport_added > 0)
72 printf "%s: adding %d PGDLLIMPORT markers\n",
73 $include_file, $num_pgdllimport_added;
74 open(my $wfh, '>', $include_file) || die "$include_file: $!";
75 print $wfh $buffer;
76 close($wfh);