#!/bin/sh
gnupatch=patch
. ./config.sh
input=$1
output=$2
tmp=/tmp/f$$
inputh=`echo $input|sed 's:\.c$:.h:'`
if grep '^ : never mind
else
echo "#ifdef PERL_CORE" > $tmp
sed -e 's:^typedef union {:\
typedef union {:' $inputh >> $tmp
mv -f $tmp $inputh
fi
if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then
cp $input $output
if test -f perly_c.diff; then
$gnupatch -F3 $output <perly_c.diff
sed -e '/^[ ]*printf("yydebug:/s/printf(/PerlIO_printf(Perl_debug_log, /' \
-e '/^#line /s/"y[.]tab[.]c"/"perly.c"/' \
-e '/\[\] *= *[{]/s/^/static /' \
-e '/^static static/s/^static //' \
-e '/^#define.WORD/,/^#define.ARROW/d' \
-e '/^int.yydebug/,/^#define.yystacksize/d' \
-e 's/^yyerrlab:$//' \
-e 's/^ goto yyerrlab;//' \
-e 's/^yynewerror:$//' \
-e 's/^ goto yynewerror;//' \
-e 's|^static char yysccsid\(.*\)|/* static char yysccsid\1 */|' \
-e 's|deprecate(|deprecate_old(|' \
< $output > $tmp && mv -f $tmp $output || exit 1
rm -rf $input
echo "If you need to debug perly.c, you need to fix up the echo "directives yourself."
fi
exit
elif grep 'yaccpar 1.9 (Berkeley)' $input >/dev/null 2>&1; then
if test -f perly.c.dif9; then
$gnupatch -F3 $output <perly.c.dif9
sed -e '/^[ ]*printf("yydebug:/s/printf(/PerlIO_printf(Perl_debug_log, /' \
-e '/^#line /s/"y[.]tab[.]c"/"perly.c"/' \
-e '/\[\] *= *[{]/s/^/static /' \
-e '/^static static/s/^static //' \
-e '/^#define.WORD/,/^#define.ARROW/d' \
-e '/^int.yydebug/,/^#define.yystacksize/d' \
-e 's/^yyerrlab:$//' \
-e 's/^ goto yyerrlab;//' \
-e 's/^yynewerror:$//' \
-e 's/^ goto yynewerror;//' \
-e 's|^static char yysccsid\(.*\)|/* static char yysccsid\1 */|' \
-e 's|deprecate(|deprecate_old(|' \
< $output > $tmp && mv -f $tmp $output || exit 1
rm -rf $input
echo "If you need to debug perly.c, you need to fix up the echo "directives yourself."
exit 0
else
echo "Diffs from byacc-1.9 are not available."
echo "If you wish to proceed anyway, do"
echo "cp $input $output"
echo "cp y.tab.h perly.h"
echo "and re-run make. Otherwise, I will use the old perly.c"
touch perly.c
exit 1
fi
fi
plan="unknown"
echo ""
echo "Warning: the yacc you have used is not directly supported by perl."
echo "The perly.fixer script will attempt to make some changes to the generated"
echo "file. The changes may be incomplete and that might lead to problems later"
echo "(especially with complex scripts). You may need to apply the changes"
echo "embedded in perl.fixer (and/or perly_c.dif*) by hand."
echo ""
egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
short[ ]*yys\[ *YYMAXDEPTH *\] *;
yyps *= *&yys\[ *-1 *\];
yypv *= *&yyv\[ *-1 *\];
if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
set `wc -l $tmp`
if test "$1" = "5"; then
plan="bsd43"
fi
if test "$plan" = "unknown"; then
egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
int[ ]*yys\[ *YYMAXDEPTH *\] *;
yyps *= *&yys\[ *-1 *\];
yypv *= *&yyv\[ *-1 *\];
if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
set `wc -l $tmp`
if test "$1" = "5"; then
plan="isc"
fi
fi
case "$plan" in
"bsd43")
echo "Attempting to patch perly.c to allow dynamic yacc stack allocation"
echo "Assuming bsd4.3 yaccpar"
cat >$tmp <<'END'
/YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
int yymaxdepth = YYMAXDEPTH;\
YYSTYPE *yyv; /* where the values are stored */\
short *yys;\
short *maxyyps;
/short[ ]*yys\[ *YYMAXDEPTH *\] *;/d
/yyps *= *&yys\[ *-1 *\];/d
/yypv *= *&yyv\[ *-1 *\];/c\
\ if (!yyv) {\
\ New(73, yyv, yymaxdepth, YYSTYPE);\
\ New(73, yys, yymaxdepth, short);\
\ if ( !yyv || !yys ) {\
\ yyerror( "out of memory" );\
\ return(1);\
\ }\
\ maxyyps = &yys[yymaxdepth];\
\ }\
\ yyps = &yys[-1];\
\ yypv = &yyv[-1];
/if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\
\ if( ++yyps >= maxyyps ) {\
\ int tv = yypv - yyv;\
\ int ts = yyps - yys;\
\
\ yymaxdepth *= 2;\
\ Renew(yyv, yymaxdepth, YYSTYPE);\
\ Renew(yys, yymaxdepth, short);\
\ if ( !yyv || !yys ) {\
\ yyerror( "yacc stack overflow" );\
\ return(1);\
\ }\
\ yyps = yys + ts;\
\ yypv = yyv + tv;\
\ maxyyps = &yys[yymaxdepth];\
\ }
/yacc stack overflow.*}/d
/yacc stack overflow/,/}/d
END
if sed -f $tmp <$input >$output
then echo "The edit seems to have been applied okay."
else echo "The edit seems to have failed!"
fi
;;
"isc") echo "Attempting to patch perly.c to allow dynamic yacc stack allocation"
echo "Assuming Interactive SysVr3 2.2 yaccpar"
cat > $tmp << 'END'
/YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
int yymaxdepth = YYMAXDEPTH;\
YYSTYPE *yyv; /* where the values are stored */\
int *yys;\
int *maxyyps;
/int[ ]*yys\[ *YYMAXDEPTH *\] *;/d
/yyps *= *&yys\[ *-1 *\];/d
/yypv *= *&yyv\[ *-1 *\];/c\
\ if (!yyv) {\
\ New(73, yyv, yymaxdepth, YYSTYPE);\
\ New(73, yys, yymaxdepth, int);\
\ maxyyps = &yys[yymaxdepth];\
\ }\
\ yyps = &yys[-1];\
\ yypv = &yyv[-1];
/if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\
\ if( ++yy_ps >= maxyyps ) {\
\ int tv = yy_pv - yyv;\
\ int ts = yy_ps - yys;\
\
\ yymaxdepth *= 2;\
\ Renew(yyv, yymaxdepth, YYSTYPE);\
\ Renew(yys, yymaxdepth, int);\
\ yy_ps = yyps = yys + ts;\
\ yy_pv = yypv = yyv + tv;\
\ maxyyps = &yys[yymaxdepth];\
\ }\
\ if (yyv == NULL || yys == NULL)
END
if sed -f $tmp < $input > $output
then echo "The edit seems to have been applied okay."
else echo "The edit seems to have failed!"
fi
;;
*)
echo "Unable to patch perly.c to allow dynamic yacc stack allocation (plan=$plan)"
sed -e 's/Received token/ *** Received token/' $input >$output
;;
esac
echo ""
rm -rf $tmp $input