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