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