2 #----------------------------------------------------------------------
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 ...)
11 # Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
12 # Portions Copyright (c) 1994, Regents of the University of California
14 # src/tools/fix-old-flex-code.pl
16 #----------------------------------------------------------------------
21 # Get command line argument.
22 usage
() if $#ARGV != 0;
25 # Suck in the whole file.
28 open($cfile, '<', $filename) || die "opening $filename for reading: $!";
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;
38 # Apply the desired patch.
40 s
|(struct yyguts_t \
* yyg
= \
(struct yyguts_t\
*\
)yyscanner
; /\* This var may be unused depending upon options. \*/
42 return yy_is_jam
\? 0 : yy_current_state
;
45 return yy_is_jam ?
0 : yy_current_state
;
48 # Write the modified file back out.
49 open($cfile, '>', $filename) || die "opening $filename for writing: $!";
59 Usage: fix-old-flex-code.pl c-file-name
61 fix-old-flex-code.pl modifies a flex output file to suppress
62 an unused-variable warning that occurs with older flex versions.
64 Report bugs to <pgsql-bugs\@lists.postgresql.org>.