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