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