X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=perly.fixer;h=afe1a383cfa58e27415088cbffd3264c7738c977;hb=7a66b2869e0f357e64667c2db4e33691b36245f8;hp=b91c0e099b1165ca73d3f66e094fb91035d87ff3;hpb=fe14fcc35f78a371a174a1d14256c2f35ae4262b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/perly.fixer b/perly.fixer old mode 100644 new mode 100755 index b91c0e0..afe1a38 --- a/perly.fixer +++ b/perly.fixer @@ -1,22 +1,98 @@ #!/bin/sh +# Fix up yacc output to allow dynamic allocation. Since perly.c +# is now provided with the perl source, this should not be necessary. +# +# However, if the user wishes to use byacc, or wishes to try another +# compiler compiler (e.g. bison or yacc), this script will get run. +# See makefile run_byacc target for more details. +# +# Currently, only byacc version 1.8 is fully supported. +# +# Hacks to make it work with Interactive's SysVr3 Version 2.2 +# doughera@lafvax.lafayette.edu (Andy Dougherty) 3/23/91 +# +# Additional information to make the BSD section work with SunOS 4.0.2 +# tdinger@East.Sun.COM (Tom Dinger) 4/15/1991 + input=$1 output=$2 tmp=/tmp/f$$ +if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then + cp $input $output + if test -f perly_c.diff; then + patch -F3 $output /dev/null 2>&1; then + if test -f perly.c.dif9; then + patch -F3 $output *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp +if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null + set `wc -l $tmp` +if test "$1" = "5"; then + plan="bsd43" +fi -case "$1" in -5) echo "Patching perly.c to allow dynamic yacc stack allocation";; -*) mv $input $output; rm -f $tmp; exit;; -esac +if test "$plan" = "unknown"; then + # Test for ISC 2.2 version (probably generic SysVr3). +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 -cat >$tmp <<'END' +# ------ + +case "$plan" in + ################################################################## + # The SunOS 4.0.2 version has the comparison fixed already. + # Also added are out of memory checks (makes porting the generated + # code easier) For most systems, it can't hurt. -- TD + "bsd43") + echo "Attempting to path 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 */\ @@ -29,24 +105,30 @@ short *maxyyps; /yypv *= *&yyv\[ *-1 *\];/c\ \ if (!yyv) {\ -\ yyv = (YYSTYPE*) malloc(yymaxdepth * sizeof(YYSTYPE));\ -\ yys = (short*) malloc(yymaxdepth * sizeof(short));\ +\ 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 *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\ \ if( ++yyps >= maxyyps ) {\ \ int tv = yypv - yyv;\ \ int ts = yyps - yys;\ \ \ yymaxdepth *= 2;\ -\ yyv = (YYSTYPE*)realloc((char*)yyv,\ -\ yymaxdepth*sizeof(YYSTYPE));\ -\ yys = (short*)realloc((char*)yys,\ -\ yymaxdepth*sizeof(short));\ +\ 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];\ @@ -55,6 +137,72 @@ short *maxyyps; /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") # Interactive Systems 2.2 version + echo "Attempting to path perly.c to allow dynamic yacc stack allocation" + echo "Assuming Interactive SysVr3 2.2 yaccpar" + # Easier to simply put whole script here than to modify the + # bsd script with sed. + # Main changes: yaccpar sometimes uses yy_ps and yy_pv + # which are local register variables. + # if(++yyps > YYMAXDEPTH) had opening brace on next line. + # I've kept that brace in along with a call to yyerror if + # realloc fails. (Actually, I just don't know how to do + # multi-line matches in sed.) + 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 + ;; + + ###################################################### + # Plan still unknown + *) + echo "Unable to patch perly.c to allow dynamic yacc stack allocation (plan=$plan)" + # just do minimal change to write $output from $input + sed -e 's/Received token/ *** Received token/' $input >$output + ;; +esac -sed -f $tmp <$input >$output +echo "" rm -rf $tmp $input