This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: Typo in Porting/pumpkin/pod ?
[perl5.git] / perly.fixer
index 98296a7..16ea925 100755 (executable)
@@ -2,33 +2,77 @@
 
 # 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 supported.
+# 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
+#
+# Also edit some practices gcc -Wall finds questionable.
+#  
 
 input=$1
 output=$2
 tmp=/tmp/f$$
 
+inputh=`echo $input|sed 's:\.c$:.h:'`
+if grep '^#ifdef PERL_CORE' $inputh; then
+       : never mind
+else
+       echo "#ifdef PERL_CORE" > $tmp
+       sed -e 's:^typedef union {:#endif /* PERL_CORE */\
+\
+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
-       patch -F3 $output <perly.c.diff
+    # Don't expect the diff to do everything -- do some by hand
+    if test -f perly_c.diff; then
+       patch -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 */|' \
+           < $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 #line"
+       echo "directives yourself."
     fi
     exit
 elif grep 'yaccpar     1.9 (Berkeley)' $input >/dev/null 2>&1; then
     if test -f perly.c.dif9; then
        patch -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 */|' \
+           < $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 #line"
+       echo "directives yourself."
        exit 0
     else
        echo "Diffs from byacc-1.9 are not available."
@@ -44,7 +88,15 @@ fi
 
 plan="unknown"
 
-# Below, we check for various yaccpar outputs.
+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 ""
+
+# Below, we check for various characteristic yaccpar outputs.
 
 #  Test for BSD 4.3 version.
 #  Also tests for the SunOS 4.0.2 version
@@ -73,13 +125,15 @@ if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
     fi
 fi
 
+# ------
+
 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 "Patching perly.c to allow dynamic yacc stack allocation"
+       echo "Attempting to patch perly.c to allow dynamic yacc stack allocation"
        echo "Assuming bsd4.3 yaccpar"
        cat >$tmp <<'END'
 /YYSTYPE[      ]*yyv\[ *YYMAXDEPTH *\];/c\
@@ -94,8 +148,8 @@ short *maxyyps;
 
 /yypv *= *&yyv\[ *-1 *\];/c\
 \      if (!yyv) {\
-\          yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\
-\          yys = (short*) safemalloc(yymaxdepth * sizeof(short));\
+\          New(73, yyv, yymaxdepth, YYSTYPE);\
+\          New(73, yys, yymaxdepth, short);\
 \          if ( !yyv || !yys ) {\
 \              yyerror( "out of memory" );\
 \              return(1);\
@@ -112,10 +166,8 @@ short *maxyyps;
 \                  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);\
@@ -128,11 +180,15 @@ short *maxyyps;
 /yacc stack overflow.*}/d
 /yacc stack overflow/,/}/d
 END
-       sed -f $tmp <$input >$output ;;
+       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 "Patching perly.c to allow dynamic yacc stack allocation"
+       echo "Attempting to patch 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.
@@ -155,8 +211,8 @@ int *maxyyps;
 
 /yypv *= *&yyv\[ *-1 *\];/c\
 \      if (!yyv) {\
-\          yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\
-\          yys = (int*) safemalloc(yymaxdepth * sizeof(int));\
+\          New(73, yyv, yymaxdepth, YYSTYPE);\
+\          New(73, yys, yymaxdepth, int);\
 \          maxyyps = &yys[yymaxdepth];\
 \      }\
 \      yyps = &yys[-1];\
@@ -168,21 +224,28 @@ int *maxyyps;
 \                  int ts = yy_ps - yys;\
 \
 \                  yymaxdepth *= 2;\
-\                  yyv = (YYSTYPE*)realloc((char*)yyv,\
-\                    yymaxdepth*sizeof(YYSTYPE));\
-\                  yys = (int*)realloc((char*)yys,\
-\                    yymaxdepth*sizeof(int));\
+\                  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
-       sed -f $tmp < $input > $output ;;
+       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
-    *) sed -e 's/Received token/ *** Received token/' $input >$output;
+    *)
+       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
 
+echo ""
 rm -rf $tmp $input