|
| 1 | +#!/usr/bin/perl -w |
| 2 | +#---------------------------------------------------------------------- |
| 3 | +# |
| 4 | +# fix-flex-warning.pl |
| 5 | +# |
| 6 | +# flex versions before 2.5.36, with certain option combinations, produce |
| 7 | +# code that causes an "unused variable" warning. That's annoying, so |
| 8 | +# let's suppress it by inserting a dummy reference to the variable. |
| 9 | +# (That's exactly what 2.5.36 and later do ...) |
| 10 | +# |
| 11 | +# Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group |
| 12 | +# Portions Copyright (c) 1994, Regents of the University of California |
| 13 | +# |
| 14 | +# src/tools/fix-flex-warning.pl |
| 15 | +# |
| 16 | +#---------------------------------------------------------------------- |
| 17 | + |
| 18 | +use strict; |
| 19 | +use warnings; |
| 20 | + |
| 21 | +# Get command line argument. |
| 22 | +usage() if $#ARGV != 0; |
| 23 | +my $filename = shift; |
| 24 | + |
| 25 | +# Suck in the whole file. |
| 26 | +local $/ = undef; |
| 27 | +my $cfile; |
| 28 | +open($cfile, $filename) || die "opening $filename for reading: $!"; |
| 29 | +my $ccode = <$cfile>; |
| 30 | +close($cfile); |
| 31 | + |
| 32 | +# No need to do anything if it's not flex 2.5.x for x < 36. |
| 33 | +exit 0 if $ccode !~ m/^#define YY_FLEX_MAJOR_VERSION 2$/m; |
| 34 | +exit 0 if $ccode !~ m/^#define YY_FLEX_MINOR_VERSION 5$/m; |
| 35 | +exit 0 if $ccode !~ m/^#define YY_FLEX_SUBMINOR_VERSION (\d+)$/m; |
| 36 | +exit 0 if $1 >= 36; |
| 37 | + |
| 38 | +# Apply the desired patch. |
| 39 | +$ccode =~ s|(struct yyguts_t \* yyg = \(struct yyguts_t\*\)yyscanner; /\* This var may be unused depending upon options. \*/ |
| 40 | +.*?) |
| 41 | + return yy_is_jam \? 0 : yy_current_state; |
| 42 | +|$1 |
| 43 | + (void) yyg; |
| 44 | + return yy_is_jam ? 0 : yy_current_state; |
| 45 | +|s; |
| 46 | +
|
| 47 | +# Write the modified file back out. |
| 48 | +open($cfile, ">$filename") || die "opening $filename for writing: $!"; |
| 49 | +print $cfile $ccode; |
| 50 | +close($cfile); |
| 51 | +
|
| 52 | +exit 0; |
| 53 | +
|
| 54 | +
|
| 55 | +sub usage |
| 56 | +{ |
| 57 | + die <<EOM; |
| 58 | +Usage: fix-flex-warning.pl c-file-name |
| 59 | +
|
| 60 | +fix-flex-warning.pl modifies a flex output file to suppress |
| 61 | +an unused-variable warning that occurs with older flex versions. |
| 62 | +
|
| 63 | +Report bugs to <pgsql-bugs\@postgresql.org>. |
| 64 | +EOM |
| 65 | +} |
0 commit comments