This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 4.0 patch 1: (combined patch)
[perl5.git] / perly.fixer
CommitLineData
fe14fcc3
LW
1#!/bin/sh
2
3input=$1
4output=$2
5tmp=/tmp/f$$
6
7egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
8short[ ]*yys\[ *YYMAXDEPTH *\] *;
9yyps *= *&yys\[ *-1 *\];
10yypv *= *&yyv\[ *-1 *\];
11if *\( *\+\+yyps *> *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp
12set `wc -l $tmp`
13
14case "$1" in
155) echo "Patching perly.c to allow dynamic yacc stack allocation";;
16*) mv $input $output; rm -f $tmp; exit;;
17esac
18
19cat >$tmp <<'END'
20/YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
21int yymaxdepth = YYMAXDEPTH;\
22YYSTYPE *yyv; /* where the values are stored */\
23short *yys;\
24short *maxyyps;
25
26/short[ ]*yys\[ *YYMAXDEPTH *\] *;/d
27
28/yyps *= *&yys\[ *-1 *\];/d
29
30/yypv *= *&yyv\[ *-1 *\];/c\
31\ if (!yyv) {\
32\ yyv = (YYSTYPE*) malloc(yymaxdepth * sizeof(YYSTYPE));\
33\ yys = (short*) malloc(yymaxdepth * sizeof(short));\
34\ maxyyps = &yys[yymaxdepth];\
35\ }\
36\ yyps = &yys[-1];\
37\ yypv = &yyv[-1];
38
39
40/if *( *\+\+yyps *> *&yys\[ *YYMAXDEPTH *\] *)/c\
41\ if( ++yyps >= maxyyps ) {\
42\ int tv = yypv - yyv;\
43\ int ts = yyps - yys;\
44\
45\ yymaxdepth *= 2;\
46\ yyv = (YYSTYPE*)realloc((char*)yyv,\
47\ yymaxdepth*sizeof(YYSTYPE));\
48\ yys = (short*)realloc((char*)yys,\
49\ yymaxdepth*sizeof(short));\
50\ yyps = yys + ts;\
51\ yypv = yyv + tv;\
52\ maxyyps = &yys[yymaxdepth];\
53\ }
54
55/yacc stack overflow.*}/d
56/yacc stack overflow/,/}/d
57END
58
59sed -f $tmp <$input >$output
60rm -rf $tmp $input