source: trunk/third/perl/perly.fixer @ 10724

Revision 10724, 6.1 KB checked in by ghudson, 27 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r10723, which included commits to RCS files with non-trunk default branches.
Line 
1#!/bin/sh
2
3# Fix up yacc output to allow dynamic allocation.  Since perly.c
4# is now provided with the perl source, this should not be necessary.
5
6# However, if the user wishes to use byacc, or wishes to try another
7# compiler compiler (e.g. bison or yacc), this script will get run.
8# See makefile run_byacc target for more details.
9#
10# Currently, only byacc version 1.8 is fully supported.
11#
12#  Hacks to make it work with Interactive's SysVr3 Version 2.2
13#   doughera@lafvax.lafayette.edu (Andy Dougherty)   3/23/91
14#
15# Additional information to make the BSD section work with SunOS 4.0.2
16#   tdinger@East.Sun.COM (Tom Dinger)   4/15/1991
17
18input=$1
19output=$2
20tmp=/tmp/f$$
21
22if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then
23    cp $input $output
24    if test -f perly.c.diff; then
25        patch -F3 $output <perly.c.diff
26        rm -rf $input
27    fi
28    exit
29elif grep 'yaccpar      1.9 (Berkeley)' $input >/dev/null 2>&1; then
30    if test -f perly.c.dif9; then
31        patch -F3 $output <perly.c.dif9
32        rm -rf $input
33        exit 0
34    else
35        echo "Diffs from byacc-1.9 are not available."
36        echo "If you wish to proceed anyway, do"
37        echo "cp $input $output"
38        echo "cp y.tab.h perly.h"
39        echo "and re-run make. Otherwise, I will use the old perly.c"
40        touch perly.c
41        # Exit with error status to stop make.
42        exit 1
43    fi
44fi
45
46plan="unknown"
47
48echo ""
49echo "Warning: the yacc you have used is not directly supported by perl."
50echo "The perly.fixer script will attempt to make some changes to the generated"
51echo "file. The changes may be incomplete and that might lead to problems later"
52echo "(especially with complex scripts). You may need to apply the changes"
53echo "embedded in perl.fixer (and/or perly.c.dif*) by hand."
54echo ""
55
56# Below, we check for various characteristic yaccpar outputs.
57
58#  Test for BSD 4.3 version.
59#  Also tests for the SunOS 4.0.2 version
60egrep 'YYSTYPE[         ]*yyv\[ *YYMAXDEPTH *\];
61short[  ]*yys\[ *YYMAXDEPTH *\] *;
62yyps *= *&yys\[ *-1 *\];
63yypv *= *&yyv\[ *-1 *\];
64if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
65
66set `wc -l $tmp`
67if test "$1" = "5"; then
68      plan="bsd43"
69fi
70
71if test "$plan" = "unknown"; then
72    #   Test for ISC 2.2 version (probably generic SysVr3).
73egrep 'YYSTYPE[         ]*yyv\[ *YYMAXDEPTH *\];
74int[    ]*yys\[ *YYMAXDEPTH *\] *;
75yyps *= *&yys\[ *-1 *\];
76yypv *= *&yyv\[ *-1 *\];
77if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
78
79    set `wc -l $tmp`
80    if test "$1" = "5"; then
81        plan="isc"
82    fi
83fi
84
85# ------
86
87case "$plan" in
88    ##################################################################
89    # The SunOS 4.0.2 version has the comparison fixed already.
90    # Also added are out of memory checks (makes porting the generated
91    # code easier) For most systems, it can't hurt. -- TD
92    "bsd43")
93        echo "Attempting to path perly.c to allow dynamic yacc stack allocation"
94        echo "Assuming bsd4.3 yaccpar"
95        cat >$tmp <<'END'
96/YYSTYPE[       ]*yyv\[ *YYMAXDEPTH *\];/c\
97int yymaxdepth = YYMAXDEPTH;\
98YYSTYPE *yyv; /* where the values are stored */\
99short *yys;\
100short *maxyyps;
101
102/short[         ]*yys\[ *YYMAXDEPTH *\] *;/d
103
104/yyps *= *&yys\[ *-1 *\];/d
105
106/yypv *= *&yyv\[ *-1 *\];/c\
107\       if (!yyv) {\
108\           yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\
109\           yys = (short*) safemalloc(yymaxdepth * sizeof(short));\
110\           if ( !yyv || !yys ) {\
111\               yyerror( "out of memory" );\
112\               return(1);\
113\           }\
114\           maxyyps = &yys[yymaxdepth];\
115\       }\
116\       yyps = &yys[-1];\
117\       yypv = &yyv[-1];
118
119
120/if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\
121\               if( ++yyps >= maxyyps ) {\
122\                   int tv = yypv - yyv;\
123\                   int ts = yyps - yys;\
124\
125\                   yymaxdepth *= 2;\
126\                   yyv = (YYSTYPE*)realloc((char*)yyv,\
127\                     yymaxdepth*sizeof(YYSTYPE));\
128\                   yys = (short*)realloc((char*)yys,\
129\                     yymaxdepth*sizeof(short));\
130\                   if ( !yyv || !yys ) {\
131\                       yyerror( "yacc stack overflow" );\
132\                       return(1);\
133\                   }\
134\                   yyps = yys + ts;\
135\                   yypv = yyv + tv;\
136\                   maxyyps = &yys[yymaxdepth];\
137\               }
138
139/yacc stack overflow.*}/d
140/yacc stack overflow/,/}/d
141END
142        if sed -f $tmp <$input >$output
143        then echo "The edit seems to have been applied okay."
144        else echo "The edit seems to have failed!"
145        fi
146        ;;
147
148    #######################################################
149    "isc") # Interactive Systems 2.2  version
150        echo "Attempting to path perly.c to allow dynamic yacc stack allocation"
151        echo "Assuming Interactive SysVr3 2.2 yaccpar"
152        # Easier to simply put whole script here than to modify the
153        # bsd script with sed.
154        # Main changes:  yaccpar sometimes uses yy_ps and yy_pv
155        # which are local register variables.
156        #  if(++yyps > YYMAXDEPTH) had opening brace on next line.
157        # I've kept that brace in along with a call to yyerror if
158        # realloc fails. (Actually, I just don't know how to do
159        # multi-line matches in sed.)
160        cat > $tmp << 'END'
161/YYSTYPE[       ]*yyv\[ *YYMAXDEPTH *\];/c\
162int yymaxdepth = YYMAXDEPTH;\
163YYSTYPE *yyv; /* where the values are stored */\
164int *yys;\
165int *maxyyps;
166
167/int[   ]*yys\[ *YYMAXDEPTH *\] *;/d
168
169/yyps *= *&yys\[ *-1 *\];/d
170
171/yypv *= *&yyv\[ *-1 *\];/c\
172\       if (!yyv) {\
173\           yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\
174\           yys = (int*) safemalloc(yymaxdepth * sizeof(int));\
175\           maxyyps = &yys[yymaxdepth];\
176\       }\
177\       yyps = &yys[-1];\
178\       yypv = &yyv[-1];
179
180/if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\
181\               if( ++yy_ps >= maxyyps ) {\
182\                   int tv = yy_pv - yyv;\
183\                   int ts = yy_ps - yys;\
184\
185\                   yymaxdepth *= 2;\
186\                   yyv = (YYSTYPE*)realloc((char*)yyv,\
187\                     yymaxdepth*sizeof(YYSTYPE));\
188\                   yys = (int*)realloc((char*)yys,\
189\                     yymaxdepth*sizeof(int));\
190\                   yy_ps = yyps = yys + ts;\
191\                   yy_pv = yypv = yyv + tv;\
192\                   maxyyps = &yys[yymaxdepth];\
193\               }\
194\               if (yyv == NULL || yys == NULL)
195END
196        if sed -f $tmp < $input > $output
197        then echo "The edit seems to have been applied okay."
198        else echo "The edit seems to have failed!"
199        fi
200        ;;
201
202    ######################################################
203    # Plan still unknown
204    *)
205        echo "Unable to patch perly.c to allow dynamic yacc stack allocation (plan=$plan)"
206        # just do minimal change to write $output from $input
207        sed -e 's/Received token/ *** Received token/' $input >$output
208        ;;
209esac
210
211echo ""
212rm -rf $tmp $input
Note: See TracBrowser for help on using the repository browser.