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