perl 4.0.00: (no release announcement available)
[p5sagit/p5-mst-13.2.git] / perly.fixer
1 #!/bin/sh
2
3 input=$1
4 output=$2
5 tmp=/tmp/f$$
6
7 egrep 'YYSTYPE[         ]*yyv\[ *YYMAXDEPTH *\];
8 short[  ]*yys\[ *YYMAXDEPTH *\] *;
9 yyps *= *&yys\[ *-1 *\];
10 yypv *= *&yyv\[ *-1 *\];
11 if *\( *\+\+yyps *> *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp
12 set `wc -l $tmp`
13
14 case "$1" in
15 5) echo "Patching perly.c to allow dynamic yacc stack allocation";;
16 *) mv $input $output; rm -f $tmp; exit;;
17 esac
18
19 cat >$tmp <<'END'
20 /YYSTYPE[       ]*yyv\[ *YYMAXDEPTH *\];/c\
21 int yymaxdepth = YYMAXDEPTH;\
22 YYSTYPE *yyv; /* where the values are stored */\
23 short *yys;\
24 short *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
57 END
58
59 sed -f $tmp <$input >$output
60 rm -rf $tmp $input