Socket::my_inet_aton() tweak
[p5sagit/p5-mst-13.2.git] / perly.fixer
CommitLineData
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.
7b57b0ea 5#
a0d0e21e 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 12# Hacks to make it work with Interactive's SysVr3 Version 2.2
13# doughera@lafvax.lafayette.edu (Andy Dougherty) 3/23/91
9ef589d8 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
7b57b0ea 17#
18# Also edit some practices gcc -Wall finds questionable.
19#
35c8bce7 20
fe14fcc3 21input=$1
22output=$2
23tmp=/tmp/f$$
24
dae2d13f 25inputh=`echo $input|sed 's:\.c$:.h:'`
26if grep '^#ifdef PERL_CORE' $inputh; then
27 : never mind
28else
29 echo "#ifdef PERL_CORE" > $tmp
30 sed -e 's:^typedef union {:#endif /* PERL_CORE */\
31\
32typedef union {:' $inputh >> $tmp
33 mv -f $tmp $inputh
34fi
35
a0d0e21e 36if grep 'yaccpar 1.8 (Berkeley)' $input >/dev/null 2>&1; then
93a17b20 37 cp $input $output
09bef843 38 # Don't expect the diff to do everything -- do some by hand
e262e9be 39 if test -f perly_c.diff; then
40 patch -F3 $output <perly_c.diff
09bef843 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' \
7b57b0ea 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 */|' \
09bef843 52 < $output > $tmp && mv -f $tmp $output || exit 1
a0d0e21e 53 rm -rf $input
09bef843 54 echo "If you need to debug perly.c, you need to fix up the #line"
55 echo "directives yourself."
a0d0e21e 56 fi
93a17b20 57 exit
a0d0e21e 58elif 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
09bef843 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' \
7b57b0ea 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 */|' \
09bef843 72 < $output > $tmp && mv -f $tmp $output || exit 1
a0d0e21e 73 rm -rf $input
09bef843 74 echo "If you need to debug perly.c, you need to fix up the #line"
75 echo "directives yourself."
a0d0e21e 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
93a17b20 87fi
88
35c8bce7 89plan="unknown"
90
25c49cb6 91echo ""
92echo "Warning: the yacc you have used is not directly supported by perl."
93echo "The perly.fixer script will attempt to make some changes to the generated"
94echo "file. The changes may be incomplete and that might lead to problems later"
95echo "(especially with complex scripts). You may need to apply the changes"
e262e9be 96echo "embedded in perl.fixer (and/or perly_c.dif*) by hand."
25c49cb6 97echo ""
98
99# Below, we check for various characteristic yaccpar outputs.
a0d0e21e 100
35c8bce7 101# Test for BSD 4.3 version.
9ef589d8 102# Also tests for the SunOS 4.0.2 version
fe14fcc3 103egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
35c8bce7 104short[ ]*yys\[ *YYMAXDEPTH *\] *;
fe14fcc3 105yyps *= *&yys\[ *-1 *\];
106yypv *= *&yyv\[ *-1 *\];
a0d0e21e 107if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
35c8bce7 108
fe14fcc3 109set `wc -l $tmp`
35c8bce7 110if test "$1" = "5"; then
111 plan="bsd43"
112fi
fe14fcc3 113
35c8bce7 114if test "$plan" = "unknown"; then
a0d0e21e 115 # Test for ISC 2.2 version (probably generic SysVr3).
35c8bce7 116egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
117int[ ]*yys\[ *YYMAXDEPTH *\] *;
118yyps *= *&yys\[ *-1 *\];
119yypv *= *&yyv\[ *-1 *\];
a0d0e21e 120if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp 2>/dev/null
35c8bce7 121
122 set `wc -l $tmp`
123 if test "$1" = "5"; then
124 plan="isc"
125 fi
126fi
fe14fcc3 127
25c49cb6 128# ------
129
35c8bce7 130case "$plan" in
9ef589d8 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
35c8bce7 135 "bsd43")
09bef843 136 echo "Attempting to patch perly.c to allow dynamic yacc stack allocation"
35c8bce7 137 echo "Assuming bsd4.3 yaccpar"
138 cat >$tmp <<'END'
fe14fcc3 139/YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
140int yymaxdepth = YYMAXDEPTH;\
141YYSTYPE *yyv; /* where the values are stored */\
142short *yys;\
143short *maxyyps;
144
145/short[ ]*yys\[ *YYMAXDEPTH *\] *;/d
146
147/yyps *= *&yys\[ *-1 *\];/d
148
149/yypv *= *&yyv\[ *-1 *\];/c\
150\ if (!yyv) {\
8c52afec 151\ New(73, yyv, yymaxdepth, YYSTYPE);\
152\ New(73, yys, yymaxdepth, short);\
9ef589d8 153\ if ( !yyv || !yys ) {\
154\ yyerror( "out of memory" );\
155\ return(1);\
156\ }\
fe14fcc3 157\ maxyyps = &yys[yymaxdepth];\
158\ }\
159\ yyps = &yys[-1];\
160\ yypv = &yyv[-1];
161
162
9ef589d8 163/if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\
fe14fcc3 164\ if( ++yyps >= maxyyps ) {\
165\ int tv = yypv - yyv;\
166\ int ts = yyps - yys;\
167\
168\ yymaxdepth *= 2;\
8c52afec 169\ Renew(yyv, yymaxdepth, YYSTYPE);\
170\ Renew(yys, yymaxdepth, short);\
9ef589d8 171\ if ( !yyv || !yys ) {\
172\ yyerror( "yacc stack overflow" );\
173\ return(1);\
174\ }\
fe14fcc3 175\ yyps = yys + ts;\
176\ yypv = yyv + tv;\
177\ maxyyps = &yys[yymaxdepth];\
178\ }
179
180/yacc stack overflow.*}/d
181/yacc stack overflow/,/}/d
182END
25c49cb6 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 ;;
35c8bce7 188
189 #######################################################
190 "isc") # Interactive Systems 2.2 version
09bef843 191 echo "Attempting to patch perly.c to allow dynamic yacc stack allocation"
35c8bce7 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\
203int yymaxdepth = YYMAXDEPTH;\
204YYSTYPE *yyv; /* where the values are stored */\
205int *yys;\
206int *maxyyps;
207
208/int[ ]*yys\[ *YYMAXDEPTH *\] *;/d
209
210/yyps *= *&yys\[ *-1 *\];/d
211
212/yypv *= *&yyv\[ *-1 *\];/c\
213\ if (!yyv) {\
8c52afec 214\ New(73, yyv, yymaxdepth, YYSTYPE);\
215\ New(73, yys, yymaxdepth, int);\
35c8bce7 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;\
8c52afec 227\ Renew(yyv, yymaxdepth, YYSTYPE);\
228\ Renew(yys, yymaxdepth, int);\
35c8bce7 229\ yy_ps = yyps = yys + ts;\
230\ yy_pv = yypv = yyv + tv;\
231\ maxyyps = &yys[yymaxdepth];\
232\ }\
233\ if (yyv == NULL || yys == NULL)
234END
25c49cb6 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 ;;
35c8bce7 240
241 ######################################################
242 # Plan still unknown
25c49cb6 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 ;;
35c8bce7 248esac
fe14fcc3 249
25c49cb6 250echo ""
fe14fcc3 251rm -rf $tmp $input