|
| 1 | +#!/usr/bin/perl |
| 2 | + |
| 3 | +#---------------------------------------------------------------------- |
| 4 | +# |
| 5 | +# mark_pgdllimport.pl |
| 6 | +#Perl script that tries to add PGDLLIMPORT markings to PostgreSQL |
| 7 | +#header files. |
| 8 | +# |
| 9 | +# This relies on a few idiosyncracies of the PostgreSQL cding 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. |
| 13 | +# |
| 14 | +# It's probably a good idea to run pgindent on any files that this |
| 15 | +# script modifies before committing. |
| 16 | +# |
| 17 | +# Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group |
| 18 | +# Portions Copyright (c) 1994, Regents of the University of California |
| 19 | +# |
| 20 | +# src/tools/mark_pgdllimport.pl |
| 21 | +# |
| 22 | +#---------------------------------------------------------------------- |
| 23 | + |
| 24 | +use strict; |
| 25 | +use warnings; |
| 26 | + |
| 27 | +formy$include_file (@ARGV) |
| 28 | +{ |
| 29 | +open(my$rfh,'<',$include_file) ||die"$include_file:$!"; |
| 30 | +my$buffer =''; |
| 31 | +my$num_pgdllimport_added = 0; |
| 32 | + |
| 33 | +while (my$raw_line = <$rfh>) |
| 34 | +{ |
| 35 | +my$needs_pgdllimport = 1; |
| 36 | + |
| 37 | +# By convention we declare global variables explicitly extern. We're |
| 38 | +# looking for those not already marked with PGDLLIMPORT. |
| 39 | +$needs_pgdllimport = 0if$raw_line !~/^extern\s+/ |
| 40 | +||$raw_line =~/PGDLLIMPORT/; |
| 41 | + |
| 42 | +# Make a copy of the line and perform a simple-minded comment strip. |
| 43 | +# Also strip trailing whitespace. |
| 44 | +my$stripped_line =$raw_line; |
| 45 | +$stripped_line =~s/\/\*.*\*\///g; |
| 46 | +$stripped_line =~s/\s+$//; |
| 47 | + |
| 48 | +# Variable declarations should end in a semicolon. If we see an |
| 49 | +# opening parenthesis, it's probably a function declaration. |
| 50 | +$needs_pgdllimport = 0if$stripped_line !~/;$/ |
| 51 | +||$stripped_line =~/\(/; |
| 52 | + |
| 53 | +# Add PGDLLIMPORT marker, if required. |
| 54 | +if ($needs_pgdllimport) |
| 55 | +{ |
| 56 | +$raw_line =~s/^extern/extern PGDLLIMPORT/; |
| 57 | +++$num_pgdllimport_added; |
| 58 | +} |
| 59 | + |
| 60 | +# Add line to buffer. |
| 61 | +$buffer .=$raw_line; |
| 62 | +} |
| 63 | + |
| 64 | +close($rfh); |
| 65 | + |
| 66 | +# If we added any PGDLLIMPORT markers, rewrite the file. |
| 67 | +if ($num_pgdllimport_added > 0) |
| 68 | +{ |
| 69 | +printf"%s: adding%d PGDLLIMPORT markers\n", |
| 70 | +$include_file,$num_pgdllimport_added; |
| 71 | +open(my$wfh,'>',$include_file) ||die"$include_file:$!"; |
| 72 | +print$wfh$buffer; |
| 73 | +close($wfh); |
| 74 | +} |
| 75 | +} |