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