#!/usr/bin/perl
#
# $Id: fix-bison 8617 2006-02-19 08:36:19Z dajobe $
#
# Format output generated by bison
#
# Usage:
#  bison -b brql_parser -p brql_parser_ -d -v brql_parser.y
#  perl fix-bison brql_parser.tab.c > $tmp
#  mv $tmp brql_parser.tab.c
#
# Copyright (C) 2004-2006, David Beckett http://purl.org/net/dajobe/
# Copyright (C) 2004, University of Bristol, UK http://www.bristol.ac.uk/
#

my $seen_yyerrlab1=0;
while(<>) {
   # Fixup pending filename renaming, see above.
   s/^(\#line \d+) (.*)\.tab\.c/$1 $2.c/;

   # Remove code that causes a warning
   if(/Suppress GCC warning that yyerrlab1/) {
     do {
       $_=<>;
     } while(!/^\#endif/);
     next;
   }

   $seen_yyerrlab1=1 if /goto yyerrlab1/;

   s/^yyerrlab1:// unless $seen_yyerrlab1;

   # Do not use macro name for a temporary variable
   s/unsigned int yylineno = /unsigned int yylineno_tmp = /;
   s/yyrule - 1, yylineno\)/yyrule - 1, yylineno_tmp\)/;

   # Do not (re)define prototypes that the system did better
   next if m%^void \*malloc\s*\(%;
   next if m%^void free\s*\(%;

  print;
}
