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. |
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. |
8 | # |
9 | # Currently, only byacc version 1.8 is supported. |
10 | # |
35c8bce7 |
11 | # Hacks to make it work with Interactive's SysVr3 Version 2.2 |
12 | # doughera@lafvax.lafayette.edu (Andy Dougherty) 3/23/91 |
9ef589d8 |
13 | # |
14 | # Additional information to make the BSD section work with SunOS 4.0.2 |
15 | # tdinger@East.Sun.COM (Tom Dinger) 4/15/1991 |
35c8bce7 |
16 | |
fe14fcc3 |
17 | input=$1 |
18 | output=$2 |
19 | tmp=/tmp/f$$ |
20 | |
a0d0e21e |
21 | if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then |
93a17b20 |
22 | cp $input $output |
a0d0e21e |
23 | if test -f perly.c.diff; then |
24 | patch -F3 $output <perly.c.diff |
25 | rm -rf $input |
26 | fi |
93a17b20 |
27 | exit |
a0d0e21e |
28 | elif grep 'yaccpar 1.9 (Berkeley)' $input >/dev/null 2>&1; then |
29 | if test -f perly.c.dif9; then |
30 | patch -F3 $output <perly.c.dif9 |
31 | rm -rf $input |
32 | exit 0 |
33 | else |
34 | echo "Diffs from byacc-1.9 are not available." |
35 | echo "If you wish to proceed anyway, do" |
36 | echo "cp $input $output" |
37 | echo "cp y.tab.h perly.h" |
38 | echo "and re-run make. Otherwise, I will use the old perly.c" |
39 | touch perly.c |
40 | # Exit with error status to stop make. |
41 | exit 1 |
42 | fi |
93a17b20 |
43 | fi |
44 | |
35c8bce7 |
45 | plan="unknown" |
46 | |
a0d0e21e |
47 | # Below, we check for various yaccpar outputs. |
48 | |
35c8bce7 |
49 | # Test for BSD 4.3 version. |
9ef589d8 |
50 | # Also tests for the SunOS 4.0.2 version |
fe14fcc3 |
51 | egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\]; |
35c8bce7 |
52 | short[ ]*yys\[ *YYMAXDEPTH *\] *; |
fe14fcc3 |
53 | yyps *= *&yys\[ *-1 *\]; |
54 | yypv *= *&yyv\[ *-1 *\]; |
a0d0e21e |
55 | if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null |
35c8bce7 |
56 | |
fe14fcc3 |
57 | set `wc -l $tmp` |
35c8bce7 |
58 | if test "$1" = "5"; then |
59 | plan="bsd43" |
60 | fi |
fe14fcc3 |
61 | |
35c8bce7 |
62 | if test "$plan" = "unknown"; then |
a0d0e21e |
63 | # Test for ISC 2.2 version (probably generic SysVr3). |
35c8bce7 |
64 | egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\]; |
65 | int[ ]*yys\[ *YYMAXDEPTH *\] *; |
66 | yyps *= *&yys\[ *-1 *\]; |
67 | yypv *= *&yyv\[ *-1 *\]; |
a0d0e21e |
68 | if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null |
35c8bce7 |
69 | |
70 | set `wc -l $tmp` |
71 | if test "$1" = "5"; then |
72 | plan="isc" |
73 | fi |
74 | fi |
fe14fcc3 |
75 | |
35c8bce7 |
76 | case "$plan" in |
9ef589d8 |
77 | ################################################################## |
78 | # The SunOS 4.0.2 version has the comparison fixed already. |
79 | # Also added are out of memory checks (makes porting the generated |
80 | # code easier) For most systems, it can't hurt. -- TD |
35c8bce7 |
81 | "bsd43") |
82 | echo "Patching perly.c to allow dynamic yacc stack allocation" |
83 | echo "Assuming bsd4.3 yaccpar" |
84 | cat >$tmp <<'END' |
fe14fcc3 |
85 | /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\ |
86 | int yymaxdepth = YYMAXDEPTH;\ |
87 | YYSTYPE *yyv; /* where the values are stored */\ |
88 | short *yys;\ |
89 | short *maxyyps; |
90 | |
91 | /short[ ]*yys\[ *YYMAXDEPTH *\] *;/d |
92 | |
93 | /yyps *= *&yys\[ *-1 *\];/d |
94 | |
95 | /yypv *= *&yyv\[ *-1 *\];/c\ |
96 | \ if (!yyv) {\ |
a0d0e21e |
97 | \ yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\ |
98 | \ yys = (short*) safemalloc(yymaxdepth * sizeof(short));\ |
9ef589d8 |
99 | \ if ( !yyv || !yys ) {\ |
100 | \ yyerror( "out of memory" );\ |
101 | \ return(1);\ |
102 | \ }\ |
fe14fcc3 |
103 | \ maxyyps = &yys[yymaxdepth];\ |
104 | \ }\ |
105 | \ yyps = &yys[-1];\ |
106 | \ yypv = &yyv[-1]; |
107 | |
108 | |
9ef589d8 |
109 | /if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\ |
fe14fcc3 |
110 | \ if( ++yyps >= maxyyps ) {\ |
111 | \ int tv = yypv - yyv;\ |
112 | \ int ts = yyps - yys;\ |
113 | \ |
114 | \ yymaxdepth *= 2;\ |
115 | \ yyv = (YYSTYPE*)realloc((char*)yyv,\ |
116 | \ yymaxdepth*sizeof(YYSTYPE));\ |
117 | \ yys = (short*)realloc((char*)yys,\ |
118 | \ yymaxdepth*sizeof(short));\ |
9ef589d8 |
119 | \ if ( !yyv || !yys ) {\ |
120 | \ yyerror( "yacc stack overflow" );\ |
121 | \ return(1);\ |
122 | \ }\ |
fe14fcc3 |
123 | \ yyps = yys + ts;\ |
124 | \ yypv = yyv + tv;\ |
125 | \ maxyyps = &yys[yymaxdepth];\ |
126 | \ } |
127 | |
128 | /yacc stack overflow.*}/d |
129 | /yacc stack overflow/,/}/d |
130 | END |
35c8bce7 |
131 | sed -f $tmp <$input >$output ;; |
132 | |
133 | ####################################################### |
134 | "isc") # Interactive Systems 2.2 version |
135 | echo "Patching perly.c to allow dynamic yacc stack allocation" |
136 | echo "Assuming Interactive SysVr3 2.2 yaccpar" |
137 | # Easier to simply put whole script here than to modify the |
138 | # bsd script with sed. |
139 | # Main changes: yaccpar sometimes uses yy_ps and yy_pv |
140 | # which are local register variables. |
141 | # if(++yyps > YYMAXDEPTH) had opening brace on next line. |
142 | # I've kept that brace in along with a call to yyerror if |
143 | # realloc fails. (Actually, I just don't know how to do |
144 | # multi-line matches in sed.) |
145 | cat > $tmp << 'END' |
146 | /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\ |
147 | int yymaxdepth = YYMAXDEPTH;\ |
148 | YYSTYPE *yyv; /* where the values are stored */\ |
149 | int *yys;\ |
150 | int *maxyyps; |
151 | |
152 | /int[ ]*yys\[ *YYMAXDEPTH *\] *;/d |
153 | |
154 | /yyps *= *&yys\[ *-1 *\];/d |
155 | |
156 | /yypv *= *&yyv\[ *-1 *\];/c\ |
157 | \ if (!yyv) {\ |
a0d0e21e |
158 | \ yyv = (YYSTYPE*) safemalloc(yymaxdepth * sizeof(YYSTYPE));\ |
159 | \ yys = (int*) safemalloc(yymaxdepth * sizeof(int));\ |
35c8bce7 |
160 | \ maxyyps = &yys[yymaxdepth];\ |
161 | \ }\ |
162 | \ yyps = &yys[-1];\ |
163 | \ yypv = &yyv[-1]; |
164 | |
165 | /if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\ |
166 | \ if( ++yy_ps >= maxyyps ) {\ |
167 | \ int tv = yy_pv - yyv;\ |
168 | \ int ts = yy_ps - yys;\ |
169 | \ |
170 | \ yymaxdepth *= 2;\ |
171 | \ yyv = (YYSTYPE*)realloc((char*)yyv,\ |
172 | \ yymaxdepth*sizeof(YYSTYPE));\ |
173 | \ yys = (int*)realloc((char*)yys,\ |
174 | \ yymaxdepth*sizeof(int));\ |
175 | \ yy_ps = yyps = yys + ts;\ |
176 | \ yy_pv = yypv = yyv + tv;\ |
177 | \ maxyyps = &yys[yymaxdepth];\ |
178 | \ }\ |
179 | \ if (yyv == NULL || yys == NULL) |
180 | END |
181 | sed -f $tmp < $input > $output ;; |
182 | |
183 | ###################################################### |
184 | # Plan still unknown |
79072805 |
185 | *) sed -e 's/Received token/ *** Received token/' $input >$output; |
35c8bce7 |
186 | esac |
fe14fcc3 |
187 | |
fe14fcc3 |
188 | rm -rf $tmp $input |