2020-04-13 17:55:45 +02:00
|
|
|
#!/usr/bin/perl
|
2017-02-19 19:04:30 +01:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
#
|
2017-02-19 22:41:51 +01:00
|
|
|
# fix-old-flex-code.pl
|
2017-02-19 19:04:30 +01:00
|
|
|
#
|
|
|
|
# flex versions before 2.5.36, with certain option combinations, produce
|
|
|
|
# code that causes an "unused variable" warning. That's annoying, so
|
|
|
|
# let's suppress it by inserting a dummy reference to the variable.
|
|
|
|
# (That's exactly what 2.5.36 and later do ...)
|
|
|
|
#
|
2021-01-02 19:06:25 +01:00
|
|
|
# Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
|
2017-02-19 19:04:30 +01:00
|
|
|
# Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
#
|
2017-02-19 22:41:51 +01:00
|
|
|
# src/tools/fix-old-flex-code.pl
|
2017-02-19 19:04:30 +01:00
|
|
|
#
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
# Get command line argument.
|
|
|
|
usage() if $#ARGV != 0;
|
|
|
|
my $filename = shift;
|
|
|
|
|
|
|
|
# Suck in the whole file.
|
|
|
|
local $/ = undef;
|
|
|
|
my $cfile;
|
2017-03-27 04:24:13 +02:00
|
|
|
open($cfile, '<', $filename) || die "opening $filename for reading: $!";
|
2017-02-19 19:04:30 +01:00
|
|
|
my $ccode = <$cfile>;
|
|
|
|
close($cfile);
|
|
|
|
|
|
|
|
# No need to do anything if it's not flex 2.5.x for x < 36.
|
|
|
|
exit 0 if $ccode !~ m/^#define YY_FLEX_MAJOR_VERSION 2$/m;
|
|
|
|
exit 0 if $ccode !~ m/^#define YY_FLEX_MINOR_VERSION 5$/m;
|
|
|
|
exit 0 if $ccode !~ m/^#define YY_FLEX_SUBMINOR_VERSION (\d+)$/m;
|
|
|
|
exit 0 if $1 >= 36;
|
|
|
|
|
|
|
|
# Apply the desired patch.
|
|
|
|
$ccode =~
|
2018-04-26 17:52:52 +02:00
|
|
|
s|(struct yyguts_t \* yyg = \(struct yyguts_t\*\)yyscanner; /\* This var may be unused depending upon options. \*/
|
2017-02-19 19:04:30 +01:00
|
|
|
.*?)
|
|
|
|
return yy_is_jam \? 0 : yy_current_state;
|
|
|
|
|$1
|
|
|
|
(void) yyg;
|
|
|
|
return yy_is_jam ? 0 : yy_current_state;
|
|
|
|
|s;
|
|
|
|
|
|
|
|
# Write the modified file back out.
|
2017-03-27 04:24:13 +02:00
|
|
|
open($cfile, '>', $filename) || die "opening $filename for writing: $!";
|
2017-02-19 19:04:30 +01:00
|
|
|
print $cfile $ccode;
|
|
|
|
close($cfile);
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
|
|
|
|
sub usage
|
|
|
|
{
|
|
|
|
die <<EOM;
|
2017-02-19 22:41:51 +01:00
|
|
|
Usage: fix-old-flex-code.pl c-file-name
|
2017-02-19 19:04:30 +01:00
|
|
|
|
2017-02-19 22:41:51 +01:00
|
|
|
fix-old-flex-code.pl modifies a flex output file to suppress
|
2017-02-19 19:04:30 +01:00
|
|
|
an unused-variable warning that occurs with older flex versions.
|
|
|
|
|
2019-01-19 19:06:35 +01:00
|
|
|
Report bugs to <pgsql-bugs\@lists.postgresql.org>.
|
2017-02-19 19:04:30 +01:00
|
|
|
EOM
|
|
|
|
}
|