Commit | Line | Data |
---|---|---|
fe14fcc3 LW |
1 | #!/bin/sh |
2 | ||
a0d0e21e LW |
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. | |
7b57b0ea | 5 | # |
a0d0e21e LW |
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. | |
25c49cb6 | 8 | # See makefile run_byacc target for more details. |
a0d0e21e | 9 | # |
25c49cb6 | 10 | # Currently, only byacc version 1.8 is fully supported. |
a0d0e21e | 11 | # |
35c8bce7 | 12 | # Hacks to make it work with Interactive's SysVr3 Version 2.2 |
36816da2 | 13 | # doughera@lafayette.edu (Andy Dougherty) 3/23/91 |
9ef589d8 LW |
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 | |
7b57b0ea JH |
17 | # |
18 | # Also edit some practices gcc -Wall finds questionable. | |
19 | # | |
35c8bce7 | 20 | |
2b21cd67 | 21 | gnupatch=patch |
0ddaf513 | 22 | . ./config.sh |
2b21cd67 | 23 | |
fe14fcc3 LW |
24 | input=$1 |
25 | output=$2 | |
26 | tmp=/tmp/f$$ | |
27 | ||
dae2d13f JH |
28 | inputh=`echo $input|sed 's:\.c$:.h:'` |
29 | if grep '^#ifdef PERL_CORE' $inputh; then | |
30 | : never mind | |
31 | else | |
32 | echo "#ifdef PERL_CORE" > $tmp | |
33 | sed -e 's:^typedef union {:#endif /* PERL_CORE */\ | |
34 | \ | |
35 | typedef union {:' $inputh >> $tmp | |
36 | mv -f $tmp $inputh | |
37 | fi | |
38 | ||
a0d0e21e | 39 | if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then |
93a17b20 | 40 | cp $input $output |
09bef843 | 41 | # Don't expect the diff to do everything -- do some by hand |
e262e9be | 42 | if test -f perly_c.diff; then |
2b21cd67 | 43 | $gnupatch -F3 $output <perly_c.diff |
09bef843 SB |
44 | sed -e '/^[ ]*printf("yydebug:/s/printf(/PerlIO_printf(Perl_debug_log, /' \ |
45 | -e '/^#line /s/"y[.]tab[.]c"/"perly.c"/' \ | |
46 | -e '/\[\] *= *[{]/s/^/static /' \ | |
47 | -e '/^static static/s/^static //' \ | |
48 | -e '/^#define.WORD/,/^#define.ARROW/d' \ | |
49 | -e '/^int.yydebug/,/^#define.yystacksize/d' \ | |
7b57b0ea JH |
50 | -e 's/^yyerrlab:$//' \ |
51 | -e 's/^ goto yyerrlab;//' \ | |
52 | -e 's/^yynewerror:$//' \ | |
53 | -e 's/^ goto yynewerror;//' \ | |
54 | -e 's|^static char yysccsid\(.*\)|/* static char yysccsid\1 */|' \ | |
0ddaf513 | 55 | -e 's|deprecate(|deprecate_old(|' \ |
09bef843 | 56 | < $output > $tmp && mv -f $tmp $output || exit 1 |
a0d0e21e | 57 | rm -rf $input |
09bef843 SB |
58 | echo "If you need to debug perly.c, you need to fix up the #line" |
59 | echo "directives yourself." | |
a0d0e21e | 60 | fi |
93a17b20 | 61 | exit |
a0d0e21e LW |
62 | elif grep 'yaccpar 1.9 (Berkeley)' $input >/dev/null 2>&1; then |
63 | if test -f perly.c.dif9; then | |
2b21cd67 | 64 | $gnupatch -F3 $output <perly.c.dif9 |
09bef843 SB |
65 | sed -e '/^[ ]*printf("yydebug:/s/printf(/PerlIO_printf(Perl_debug_log, /' \ |
66 | -e '/^#line /s/"y[.]tab[.]c"/"perly.c"/' \ | |
67 | -e '/\[\] *= *[{]/s/^/static /' \ | |
68 | -e '/^static static/s/^static //' \ | |
69 | -e '/^#define.WORD/,/^#define.ARROW/d' \ | |
70 | -e '/^int.yydebug/,/^#define.yystacksize/d' \ | |
7b57b0ea JH |
71 | -e 's/^yyerrlab:$//' \ |
72 | -e 's/^ goto yyerrlab;//' \ | |
73 | -e 's/^yynewerror:$//' \ | |
74 | -e 's/^ goto yynewerror;//' \ | |
75 | -e 's|^static char yysccsid\(.*\)|/* static char yysccsid\1 */|' \ | |
0ddaf513 | 76 | -e 's|deprecate(|deprecate_old(|' \ |
09bef843 | 77 | < $output > $tmp && mv -f $tmp $output || exit 1 |
a0d0e21e | 78 | rm -rf $input |
09bef843 SB |
79 | echo "If you need to debug perly.c, you need to fix up the #line" |
80 | echo "directives yourself." | |
a0d0e21e LW |
81 | exit 0 |
82 | else | |
83 | echo "Diffs from byacc-1.9 are not available." | |
84 | echo "If you wish to proceed anyway, do" | |
85 | echo "cp $input $output" | |
86 | echo "cp y.tab.h perly.h" | |
87 | echo "and re-run make. Otherwise, I will use the old perly.c" | |
88 | touch perly.c | |
89 | # Exit with error status to stop make. | |
90 | exit 1 | |
91 | fi | |
93a17b20 LW |
92 | fi |
93 | ||
35c8bce7 LW |
94 | plan="unknown" |
95 | ||
25c49cb6 TB |
96 | echo "" |
97 | echo "Warning: the yacc you have used is not directly supported by perl." | |
98 | echo "The perly.fixer script will attempt to make some changes to the generated" | |
99 | echo "file. The changes may be incomplete and that might lead to problems later" | |
100 | echo "(especially with complex scripts). You may need to apply the changes" | |
e262e9be | 101 | echo "embedded in perl.fixer (and/or perly_c.dif*) by hand." |
25c49cb6 TB |
102 | echo "" |
103 | ||
104 | # Below, we check for various characteristic yaccpar outputs. | |
a0d0e21e | 105 | |
35c8bce7 | 106 | # Test for BSD 4.3 version. |
9ef589d8 | 107 | # Also tests for the SunOS 4.0.2 version |
fe14fcc3 | 108 | egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\]; |
35c8bce7 | 109 | short[ ]*yys\[ *YYMAXDEPTH *\] *; |
fe14fcc3 LW |
110 | yyps *= *&yys\[ *-1 *\]; |
111 | yypv *= *&yyv\[ *-1 *\]; | |
a0d0e21e | 112 | if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null |
35c8bce7 | 113 | |
fe14fcc3 | 114 | set `wc -l $tmp` |
35c8bce7 LW |
115 | if test "$1" = "5"; then |
116 | plan="bsd43" | |
117 | fi | |
fe14fcc3 | 118 | |
35c8bce7 | 119 | if test "$plan" = "unknown"; then |
a0d0e21e | 120 | # Test for ISC 2.2 version (probably generic SysVr3). |
35c8bce7 LW |
121 | egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\]; |
122 | int[ ]*yys\[ *YYMAXDEPTH *\] *; | |
123 | yyps *= *&yys\[ *-1 *\]; | |
124 | yypv *= *&yyv\[ *-1 *\]; | |
a0d0e21e | 125 | if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null |
35c8bce7 LW |
126 | |
127 | set `wc -l $tmp` | |
128 | if test "$1" = "5"; then | |
129 | plan="isc" | |
130 | fi | |
131 | fi | |
fe14fcc3 | 132 | |
25c49cb6 TB |
133 | # ------ |
134 | ||
35c8bce7 | 135 | case "$plan" in |
9ef589d8 LW |
136 | ################################################################## |
137 | # The SunOS 4.0.2 version has the comparison fixed already. | |
138 | # Also added are out of memory checks (makes porting the generated | |
139 | # code easier) For most systems, it can't hurt. -- TD | |
35c8bce7 | 140 | "bsd43") |
09bef843 | 141 | echo "Attempting to patch perly.c to allow dynamic yacc stack allocation" |
35c8bce7 LW |
142 | echo "Assuming bsd4.3 yaccpar" |
143 | cat >$tmp <<'END' | |
fe14fcc3 LW |
144 | /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\ |
145 | int yymaxdepth = YYMAXDEPTH;\ | |
146 | YYSTYPE *yyv; /* where the values are stored */\ | |
147 | short *yys;\ | |
148 | short *maxyyps; | |
149 | ||
150 | /short[ ]*yys\[ *YYMAXDEPTH *\] *;/d | |
151 | ||
152 | /yyps *= *&yys\[ *-1 *\];/d | |
153 | ||
154 | /yypv *= *&yyv\[ *-1 *\];/c\ | |
155 | \ if (!yyv) {\ | |
8c52afec IZ |
156 | \ New(73, yyv, yymaxdepth, YYSTYPE);\ |
157 | \ New(73, yys, yymaxdepth, short);\ | |
9ef589d8 LW |
158 | \ if ( !yyv || !yys ) {\ |
159 | \ yyerror( "out of memory" );\ | |
160 | \ return(1);\ | |
161 | \ }\ | |
fe14fcc3 LW |
162 | \ maxyyps = &yys[yymaxdepth];\ |
163 | \ }\ | |
164 | \ yyps = &yys[-1];\ | |
165 | \ yypv = &yyv[-1]; | |
166 | ||
167 | ||
9ef589d8 | 168 | /if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\ |
fe14fcc3 LW |
169 | \ if( ++yyps >= maxyyps ) {\ |
170 | \ int tv = yypv - yyv;\ | |
171 | \ int ts = yyps - yys;\ | |
172 | \ | |
173 | \ yymaxdepth *= 2;\ | |
8c52afec IZ |
174 | \ Renew(yyv, yymaxdepth, YYSTYPE);\ |
175 | \ Renew(yys, yymaxdepth, short);\ | |
9ef589d8 LW |
176 | \ if ( !yyv || !yys ) {\ |
177 | \ yyerror( "yacc stack overflow" );\ | |
178 | \ return(1);\ | |
179 | \ }\ | |
fe14fcc3 LW |
180 | \ yyps = yys + ts;\ |
181 | \ yypv = yyv + tv;\ | |
182 | \ maxyyps = &yys[yymaxdepth];\ | |
183 | \ } | |
184 | ||
185 | /yacc stack overflow.*}/d | |
186 | /yacc stack overflow/,/}/d | |
187 | END | |
25c49cb6 TB |
188 | if sed -f $tmp <$input >$output |
189 | then echo "The edit seems to have been applied okay." | |
190 | else echo "The edit seems to have failed!" | |
191 | fi | |
192 | ;; | |
35c8bce7 LW |
193 | |
194 | ####################################################### | |
195 | "isc") # Interactive Systems 2.2 version | |
09bef843 | 196 | echo "Attempting to patch perly.c to allow dynamic yacc stack allocation" |
35c8bce7 LW |
197 | echo "Assuming Interactive SysVr3 2.2 yaccpar" |
198 | # Easier to simply put whole script here than to modify the | |
199 | # bsd script with sed. | |
200 | # Main changes: yaccpar sometimes uses yy_ps and yy_pv | |
201 | # which are local register variables. | |
202 | # if(++yyps > YYMAXDEPTH) had opening brace on next line. | |
203 | # I've kept that brace in along with a call to yyerror if | |
204 | # realloc fails. (Actually, I just don't know how to do | |
205 | # multi-line matches in sed.) | |
206 | cat > $tmp << 'END' | |
207 | /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\ | |
208 | int yymaxdepth = YYMAXDEPTH;\ | |
209 | YYSTYPE *yyv; /* where the values are stored */\ | |
210 | int *yys;\ | |
211 | int *maxyyps; | |
212 | ||
213 | /int[ ]*yys\[ *YYMAXDEPTH *\] *;/d | |
214 | ||
215 | /yyps *= *&yys\[ *-1 *\];/d | |
216 | ||
217 | /yypv *= *&yyv\[ *-1 *\];/c\ | |
218 | \ if (!yyv) {\ | |
8c52afec IZ |
219 | \ New(73, yyv, yymaxdepth, YYSTYPE);\ |
220 | \ New(73, yys, yymaxdepth, int);\ | |
35c8bce7 LW |
221 | \ maxyyps = &yys[yymaxdepth];\ |
222 | \ }\ | |
223 | \ yyps = &yys[-1];\ | |
224 | \ yypv = &yyv[-1]; | |
225 | ||
226 | /if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\ | |
227 | \ if( ++yy_ps >= maxyyps ) {\ | |
228 | \ int tv = yy_pv - yyv;\ | |
229 | \ int ts = yy_ps - yys;\ | |
230 | \ | |
231 | \ yymaxdepth *= 2;\ | |
8c52afec IZ |
232 | \ Renew(yyv, yymaxdepth, YYSTYPE);\ |
233 | \ Renew(yys, yymaxdepth, int);\ | |
35c8bce7 LW |
234 | \ yy_ps = yyps = yys + ts;\ |
235 | \ yy_pv = yypv = yyv + tv;\ | |
236 | \ maxyyps = &yys[yymaxdepth];\ | |
237 | \ }\ | |
238 | \ if (yyv == NULL || yys == NULL) | |
239 | END | |
25c49cb6 TB |
240 | if sed -f $tmp < $input > $output |
241 | then echo "The edit seems to have been applied okay." | |
242 | else echo "The edit seems to have failed!" | |
243 | fi | |
244 | ;; | |
35c8bce7 LW |
245 | |
246 | ###################################################### | |
247 | # Plan still unknown | |
25c49cb6 TB |
248 | *) |
249 | echo "Unable to patch perly.c to allow dynamic yacc stack allocation (plan=$plan)" | |
250 | # just do minimal change to write $output from $input | |
251 | sed -e 's/Received token/ *** Received token/' $input >$output | |
252 | ;; | |
35c8bce7 | 253 | esac |
fe14fcc3 | 254 | |
25c49cb6 | 255 | echo "" |
fe14fcc3 | 256 | rm -rf $tmp $input |