perl 4.0 patch 2: Patch 1 continued
[p5sagit/p5-mst-13.2.git] / perly.fixer
CommitLineData
fe14fcc3 1#!/bin/sh
2
35c8bce7 3# Hacks to make it work with Interactive's SysVr3 Version 2.2
4# doughera@lafvax.lafayette.edu (Andy Dougherty) 3/23/91
5
fe14fcc3 6input=$1
7output=$2
8tmp=/tmp/f$$
9
35c8bce7 10plan="unknown"
11
12# Test for BSD 4.3 version.
fe14fcc3 13egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
35c8bce7 14short[ ]*yys\[ *YYMAXDEPTH *\] *;
fe14fcc3 15yyps *= *&yys\[ *-1 *\];
16yypv *= *&yyv\[ *-1 *\];
17if *\( *\+\+yyps *> *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp
35c8bce7 18
fe14fcc3 19set `wc -l $tmp`
35c8bce7 20if test "$1" = "5"; then
21 plan="bsd43"
22fi
fe14fcc3 23
35c8bce7 24if test "$plan" = "unknown"; then
25 # Test for ISC 2.2 version.
26egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];
27int[ ]*yys\[ *YYMAXDEPTH *\] *;
28yyps *= *&yys\[ *-1 *\];
29yypv *= *&yyv\[ *-1 *\];
30if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp
31
32 set `wc -l $tmp`
33 if test "$1" = "5"; then
34 plan="isc"
35 fi
36fi
fe14fcc3 37
35c8bce7 38case "$plan" in
39 #######################################################
40 "bsd43")
41 echo "Patching perly.c to allow dynamic yacc stack allocation"
42 echo "Assuming bsd4.3 yaccpar"
43 cat >$tmp <<'END'
fe14fcc3 44/YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
45int yymaxdepth = YYMAXDEPTH;\
46YYSTYPE *yyv; /* where the values are stored */\
47short *yys;\
48short *maxyyps;
49
50/short[ ]*yys\[ *YYMAXDEPTH *\] *;/d
51
52/yyps *= *&yys\[ *-1 *\];/d
53
54/yypv *= *&yyv\[ *-1 *\];/c\
55\ if (!yyv) {\
56\ yyv = (YYSTYPE*) malloc(yymaxdepth * sizeof(YYSTYPE));\
57\ yys = (short*) malloc(yymaxdepth * sizeof(short));\
58\ maxyyps = &yys[yymaxdepth];\
59\ }\
60\ yyps = &yys[-1];\
61\ yypv = &yyv[-1];
62
63
64/if *( *\+\+yyps *> *&yys\[ *YYMAXDEPTH *\] *)/c\
65\ if( ++yyps >= maxyyps ) {\
66\ int tv = yypv - yyv;\
67\ int ts = yyps - yys;\
68\
69\ yymaxdepth *= 2;\
70\ yyv = (YYSTYPE*)realloc((char*)yyv,\
71\ yymaxdepth*sizeof(YYSTYPE));\
72\ yys = (short*)realloc((char*)yys,\
73\ yymaxdepth*sizeof(short));\
74\ yyps = yys + ts;\
75\ yypv = yyv + tv;\
76\ maxyyps = &yys[yymaxdepth];\
77\ }
78
79/yacc stack overflow.*}/d
80/yacc stack overflow/,/}/d
81END
35c8bce7 82 sed -f $tmp <$input >$output ;;
83
84 #######################################################
85 "isc") # Interactive Systems 2.2 version
86 echo "Patching perly.c to allow dynamic yacc stack allocation"
87 echo "Assuming Interactive SysVr3 2.2 yaccpar"
88 # Easier to simply put whole script here than to modify the
89 # bsd script with sed.
90 # Main changes: yaccpar sometimes uses yy_ps and yy_pv
91 # which are local register variables.
92 # if(++yyps > YYMAXDEPTH) had opening brace on next line.
93 # I've kept that brace in along with a call to yyerror if
94 # realloc fails. (Actually, I just don't know how to do
95 # multi-line matches in sed.)
96 cat > $tmp << 'END'
97/YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\
98int yymaxdepth = YYMAXDEPTH;\
99YYSTYPE *yyv; /* where the values are stored */\
100int *yys;\
101int *maxyyps;
102
103/int[ ]*yys\[ *YYMAXDEPTH *\] *;/d
104
105/yyps *= *&yys\[ *-1 *\];/d
106
107/yypv *= *&yyv\[ *-1 *\];/c\
108\ if (!yyv) {\
109\ yyv = (YYSTYPE*) malloc(yymaxdepth * sizeof(YYSTYPE));\
110\ yys = (int*) malloc(yymaxdepth * sizeof(int));\
111\ maxyyps = &yys[yymaxdepth];\
112\ }\
113\ yyps = &yys[-1];\
114\ yypv = &yyv[-1];
115
116/if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\
117\ if( ++yy_ps >= maxyyps ) {\
118\ int tv = yy_pv - yyv;\
119\ int ts = yy_ps - yys;\
120\
121\ yymaxdepth *= 2;\
122\ yyv = (YYSTYPE*)realloc((char*)yyv,\
123\ yymaxdepth*sizeof(YYSTYPE));\
124\ yys = (int*)realloc((char*)yys,\
125\ yymaxdepth*sizeof(int));\
126\ yy_ps = yyps = yys + ts;\
127\ yy_pv = yypv = yyv + tv;\
128\ maxyyps = &yys[yymaxdepth];\
129\ }\
130\ if (yyv == NULL || yys == NULL)
131END
132 sed -f $tmp < $input > $output ;;
133
134 ######################################################
135 # Plan still unknown
136 *) mv $input $output;
137esac
fe14fcc3 138
fe14fcc3 139rm -rf $tmp $input