source: trunk/third/perl/perly.fixer @ 9009

Revision 9009, 4.2 KB checked in by ghudson, 28 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r9008, which included commits to RCS files with non-trunk default branches.
Line 
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
9input=$1
10output=$2
11tmp=/tmp/f$$
12
13plan="unknown"
14
15#  Test for BSD 4.3 version.
16#  Also tests for the SunOS 4.0.2 version
17egrep 'YYSTYPE[         ]*yyv\[ *YYMAXDEPTH *\];
18short[  ]*yys\[ *YYMAXDEPTH *\] *;
19yyps *= *&yys\[ *-1 *\];
20yypv *= *&yyv\[ *-1 *\];
21if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp
22
23set `wc -l $tmp`
24if test "$1" = "5"; then
25      plan="bsd43"
26fi
27
28if test "$plan" = "unknown"; then
29    #   Test for ISC 2.2 version.
30egrep 'YYSTYPE[         ]*yyv\[ *YYMAXDEPTH *\];
31int[    ]*yys\[ *YYMAXDEPTH *\] *;
32yyps *= *&yys\[ *-1 *\];
33yypv *= *&yyv\[ *-1 *\];
34if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp
35
36    set `wc -l $tmp`
37    if test "$1" = "5"; then
38        plan="isc"
39    fi
40fi
41
42case "$plan" in
43    ##################################################################
44    # The SunOS 4.0.2 version has the comparison fixed already.
45    # Also added are out of memory checks (makes porting the generated
46    # code easier) For most systems, it can't hurt. -- TD
47    "bsd43")
48        echo "Patching perly.c to allow dynamic yacc stack allocation"
49        echo "Assuming bsd4.3 yaccpar"
50        cat >$tmp <<'END'
51/YYSTYPE[       ]*yyv\[ *YYMAXDEPTH *\];/c\
52int yymaxdepth = YYMAXDEPTH;\
53YYSTYPE *yyv; /* where the values are stored */\
54short *yys;\
55short *maxyyps;
56
57/short[         ]*yys\[ *YYMAXDEPTH *\] *;/d
58
59/yyps *= *&yys\[ *-1 *\];/d
60
61/yypv *= *&yyv\[ *-1 *\];/c\
62\       if (!yyv) {\
63\           yyv = (YYSTYPE*) malloc(yymaxdepth * sizeof(YYSTYPE));\
64\           yys = (short*) malloc(yymaxdepth * sizeof(short));\
65\           if ( !yyv || !yys ) {\
66\               yyerror( "out of memory" );\
67\               return(1);\
68\           }\
69\           maxyyps = &yys[yymaxdepth];\
70\       }\
71\       yyps = &yys[-1];\
72\       yypv = &yyv[-1];
73
74
75/if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\
76\               if( ++yyps >= maxyyps ) {\
77\                   int tv = yypv - yyv;\
78\                   int ts = yyps - yys;\
79\
80\                   yymaxdepth *= 2;\
81\                   yyv = (YYSTYPE*)realloc((char*)yyv,\
82\                     yymaxdepth*sizeof(YYSTYPE));\
83\                   yys = (short*)realloc((char*)yys,\
84\                     yymaxdepth*sizeof(short));\
85\                   if ( !yyv || !yys ) {\
86\                       yyerror( "yacc stack overflow" );\
87\                       return(1);\
88\                   }\
89\                   yyps = yys + ts;\
90\                   yypv = yyv + tv;\
91\                   maxyyps = &yys[yymaxdepth];\
92\               }
93
94/yacc stack overflow.*}/d
95/yacc stack overflow/,/}/d
96END
97        sed -f $tmp <$input >$output ;;
98
99    #######################################################
100    "isc") # Interactive Systems 2.2  version
101        echo "Patching perly.c to allow dynamic yacc stack allocation"
102        echo "Assuming Interactive SysVr3 2.2 yaccpar"
103        # Easier to simply put whole script here than to modify the
104        # bsd script with sed.
105        # Main changes:  yaccpar sometimes uses yy_ps and yy_pv
106        # which are local register variables.
107        #  if(++yyps > YYMAXDEPTH) had opening brace on next line.
108        # I've kept that brace in along with a call to yyerror if
109        # realloc fails. (Actually, I just don't know how to do
110        # multi-line matches in sed.)
111        cat > $tmp << 'END'
112/YYSTYPE[       ]*yyv\[ *YYMAXDEPTH *\];/c\
113int yymaxdepth = YYMAXDEPTH;\
114YYSTYPE *yyv; /* where the values are stored */\
115int *yys;\
116int *maxyyps;
117
118/int[   ]*yys\[ *YYMAXDEPTH *\] *;/d
119
120/yyps *= *&yys\[ *-1 *\];/d
121
122/yypv *= *&yyv\[ *-1 *\];/c\
123\       if (!yyv) {\
124\           yyv = (YYSTYPE*) malloc(yymaxdepth * sizeof(YYSTYPE));\
125\           yys = (int*) malloc(yymaxdepth * sizeof(int));\
126\           maxyyps = &yys[yymaxdepth];\
127\       }\
128\       yyps = &yys[-1];\
129\       yypv = &yyv[-1];
130
131/if *( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *)/c\
132\               if( ++yy_ps >= maxyyps ) {\
133\                   int tv = yy_pv - yyv;\
134\                   int ts = yy_ps - yys;\
135\
136\                   yymaxdepth *= 2;\
137\                   yyv = (YYSTYPE*)realloc((char*)yyv,\
138\                     yymaxdepth*sizeof(YYSTYPE));\
139\                   yys = (int*)realloc((char*)yys,\
140\                     yymaxdepth*sizeof(int));\
141\                   yy_ps = yyps = yys + ts;\
142\                   yy_pv = yypv = yyv + tv;\
143\                   maxyyps = &yys[yymaxdepth];\
144\               }\
145\               if (yyv == NULL || yys == NULL)
146END
147        sed -f $tmp < $input > $output ;;
148
149    ######################################################
150    # Plan still unknown
151    *) mv $input $output;
152esac
153
154rm -rf $tmp $input
Note: See TracBrowser for help on using the repository browser.