#!/afs/athena/contrib/perl/p 

# dxfedit.prl -- looks for specific function declarations in lex.yy.c
# and y.tab.c from lex and yacc output and makes them static functions
# so as to avoid conflicts with other lex and yacc output. Also renames
# the input function to lexinput to avoid another conflict. And
# renames the yylex function to dxfyylex whereever it is found to
# assure consistency across files.


# ------------------------------------------------------------
# Load an array with the names of the variables to rename.
# ------------------------------------------------------------
@yy_variables = ('yyact', 'yybgin', 'yychar', 'yychk', 'yycrank', 'yydef', 'yyerrflag', 'yyexca', 'yyextra', 'yyin', 'yylex', 'yylineno', 'yymatch', 'yynerrs', 'yyout', 'yypact', 'yyparse', 'yypgo', 'yyprevious', 'yyr1', 'yyr2', 'yysptr', 'yysvec', 'yytop', 'yyvstop' );

# -------------------------
# Read from standard input.
# -------------------------
open(F, "-") || die "cannot open STDIN: $!";
while (<F>) {

# ----------------------------------------------------------------
# Substitute new names in each line for generalized variable names
# from lex and yacc output.
# ----------------------------------------------------------------
	foreach $i (0 .. $#yy_variables) {
		if ( m/$yy_variables[$i]/ )	{
			$temp = $yy_variables[$i];
			s/$temp/dxf$temp/g;
		}	
	}

# ------------------------------------------------------
# Change declarations to make specific functions static.
# ------------------------------------------------------
	if ( m/^yywrap/ || m/^report/ || m/^yylook/ || m/^yyback/ || m/^dxfyyinput/ || m/^dxfyyoutput/ || m/^yyunput/ || m/^yyerror/ ){
		printf "static $_";
	}
	elsif (m/input()/) {
		s/input\(/lexinput\(/;
		print "$_";
	}
	else	{
		print "$_";
	}
}
