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