From 46651ce6fe013220ed397add242004d764fc0153 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 14:15:05 +0200 Subject: Adding upstream version 14.5. Signed-off-by: Daniel Baumann --- src/tools/fix-old-flex-code.pl | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/tools/fix-old-flex-code.pl (limited to 'src/tools/fix-old-flex-code.pl') diff --git a/src/tools/fix-old-flex-code.pl b/src/tools/fix-old-flex-code.pl new file mode 100644 index 0000000..62b89e0 --- /dev/null +++ b/src/tools/fix-old-flex-code.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl +#---------------------------------------------------------------------- +# +# fix-old-flex-code.pl +# +# 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 ...) +# +# Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group +# Portions Copyright (c) 1994, Regents of the University of California +# +# src/tools/fix-old-flex-code.pl +# +#---------------------------------------------------------------------- + +use strict; +use warnings; + +# Get command line argument. +usage() if $#ARGV != 0; +my $filename = shift; + +# Suck in the whole file. +local $/ = undef; +my $cfile; +open($cfile, '<', $filename) || die "opening $filename for reading: $!"; +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 =~ + s|(struct yyguts_t \* yyg = \(struct yyguts_t\*\)yyscanner; /\* This var may be unused depending upon options. \*/ +.*?) + 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. +open($cfile, '>', $filename) || die "opening $filename for writing: $!"; +print $cfile $ccode; +close($cfile); + +exit 0; + + +sub usage +{ + die <. +EOM +} -- cgit v1.2.3