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.
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.
9 # Currently, only byacc version 1.8 is supported.
11 # Hacks to make it work with Interactive's SysVr3 Version 2.2
12 # doughera@lafvax.lafayette.edu (Andy Dougherty) 3/23/91
14 # Additional information to make the BSD section work with SunOS 4.0.2
15 # tdinger@East.Sun.COM (Tom Dinger) 4/15/1991
21 if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then
23 if test -f perly.c.diff; then
24 patch -F3 $output <perly.c.diff
28 elif grep 'yaccpar 1.9 (Berkeley)' $input >/dev/null 2>&1; then
29 if test -f perly.c.dif9; then
30 patch -F3 $output <perly.c.dif9
34 echo "Diffs from byacc-1.9 are not available."
35 echo "If you wish to proceed anyway, do"
36 echo "cp $input $output"
37 echo "cp y.tab.h perly.h"
38 echo "and re-run make. Otherwise, I will use the old perly.c"
40 # Exit with error status to stop make.
47 # Below, we check for various yaccpar outputs.
49 # Test for BSD 4.3 version.
50 # Also tests for the SunOS 4.0.2 version
51 egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
52 short[ ]*yys\[ *YYMAXDEPTH *\] *;
53 yyps *= *&yys\[ *-1 *\];
54 yypv *= *&yyv\[ *-1 *\];
55 if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
58 if test "$1" = "5"; then
62 if test "$plan" = "unknown"; then
63 # Test for ISC 2.2 version (probably generic SysVr3).
64 egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
65 int[ ]*yys\[ *YYMAXDEPTH *\] *;
66 yyps *= *&yys\[ *-1 *\];
67 yypv *= *&yyv\[ *-1 *\];
68 if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
71 if test "$1" = "5"; then
77 ##################################################################
78 # The SunOS 4.0.2 version has the comparison fixed already.
79 # Also added are out of memory checks (makes porting the generated
80 # code easier) For most systems, it can't hurt. -- TD
82 echo "Patching perly.c to allow dynamic yacc stack allocation"
83 echo "Assuming bsd4.3 yaccpar"
85 /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
86 int yymaxdepth = YYMAXDEPTH;\
87 YYSTYPE *yyv; /* where the values are stored */\
91 /short[ ]*yys\[ *YYMAXDEPTH *\] *;/d
93 /yyps *= *&yys\[ *-1 *\];/d
95 /yypv *= *&yyv\[ *-1 *\];/c\
97 \ yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\
98 \ yys = (short*) safemalloc(yymaxdepth * sizeof(short));\
99 \ if ( !yyv || !yys ) {\
100 \ yyerror( "out of memory" );\
103 \ maxyyps = &yys[yymaxdepth];\
109 /if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\
110 \ if( ++yyps >= maxyyps ) {\
111 \ int tv = yypv - yyv;\
112 \ int ts = yyps - yys;\
115 \ yyv = (YYSTYPE*)realloc((char*)yyv,\
116 \ yymaxdepth*sizeof(YYSTYPE));\
117 \ yys = (short*)realloc((char*)yys,\
118 \ yymaxdepth*sizeof(short));\
119 \ if ( !yyv || !yys ) {\
120 \ yyerror( "yacc stack overflow" );\
125 \ maxyyps = &yys[yymaxdepth];\
128 /yacc stack overflow.*}/d
129 /yacc stack overflow/,/}/d
131 sed -f $tmp <$input >$output ;;
133 #######################################################
134 "isc") # Interactive Systems 2.2 version
135 echo "Patching perly.c to allow dynamic yacc stack allocation"
136 echo "Assuming Interactive SysVr3 2.2 yaccpar"
137 # Easier to simply put whole script here than to modify the
138 # bsd script with sed.
139 # Main changes: yaccpar sometimes uses yy_ps and yy_pv
140 # which are local register variables.
141 # if(++yyps > YYMAXDEPTH) had opening brace on next line.
142 # I've kept that brace in along with a call to yyerror if
143 # realloc fails. (Actually, I just don't know how to do
144 # multi-line matches in sed.)
146 /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
147 int yymaxdepth = YYMAXDEPTH;\
148 YYSTYPE *yyv; /* where the values are stored */\
152 /int[ ]*yys\[ *YYMAXDEPTH *\] *;/d
154 /yyps *= *&yys\[ *-1 *\];/d
156 /yypv *= *&yyv\[ *-1 *\];/c\
158 \ yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\
159 \ yys = (int*) safemalloc(yymaxdepth * sizeof(int));\
160 \ maxyyps = &yys[yymaxdepth];\
165 /if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\
166 \ if( ++yy_ps >= maxyyps ) {\
167 \ int tv = yy_pv - yyv;\
168 \ int ts = yy_ps - yys;\
171 \ yyv = (YYSTYPE*)realloc((char*)yyv,\
172 \ yymaxdepth*sizeof(YYSTYPE));\
173 \ yys = (int*)realloc((char*)yys,\
174 \ yymaxdepth*sizeof(int));\
175 \ yy_ps = yyps = yys + ts;\
176 \ yy_pv = yypv = yyv + tv;\
177 \ maxyyps = &yys[yymaxdepth];\
179 \ if (yyv == NULL || yys == NULL)
181 sed -f $tmp < $input > $output ;;
183 ######################################################
185 *) sed -e 's/Received token/ *** Received token/' $input >$output;