Commit | Line | Data |
---|---|---|
fe14fcc3 LW |
1 | #!/bin/sh |
2 | ||
35c8bce7 LW |
3 | # Hacks to make it work with Interactive's SysVr3 Version 2.2 |
4 | # doughera@lafvax.lafayette.edu (Andy Dougherty) 3/23/91 | |
9ef589d8 LW |
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 | |
35c8bce7 | 8 | |
fe14fcc3 LW |
9 | input=$1 |
10 | output=$2 | |
11 | tmp=/tmp/f$$ | |
12 | ||
35c8bce7 LW |
13 | plan="unknown" |
14 | ||
15 | # Test for BSD 4.3 version. | |
9ef589d8 | 16 | # Also tests for the SunOS 4.0.2 version |
fe14fcc3 | 17 | egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\]; |
35c8bce7 | 18 | short[ ]*yys\[ *YYMAXDEPTH *\] *; |
fe14fcc3 LW |
19 | yyps *= *&yys\[ *-1 *\]; |
20 | yypv *= *&yyv\[ *-1 *\]; | |
9ef589d8 | 21 | if *\( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp |
35c8bce7 | 22 | |
fe14fcc3 | 23 | set `wc -l $tmp` |
35c8bce7 LW |
24 | if test "$1" = "5"; then |
25 | plan="bsd43" | |
26 | fi | |
fe14fcc3 | 27 | |
35c8bce7 LW |
28 | if test "$plan" = "unknown"; then |
29 | # Test for ISC 2.2 version. | |
30 | egrep 'YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\]; | |
31 | int[ ]*yys\[ *YYMAXDEPTH *\] *; | |
32 | yyps *= *&yys\[ *-1 *\]; | |
33 | yypv *= *&yyv\[ *-1 *\]; | |
34 | if *\( *\+\+yy_ps *>= *&yys\[ *YYMAXDEPTH *\] *\)' $input >$tmp | |
35 | ||
36 | set `wc -l $tmp` | |
37 | if test "$1" = "5"; then | |
38 | plan="isc" | |
39 | fi | |
40 | fi | |
fe14fcc3 | 41 | |
35c8bce7 | 42 | case "$plan" in |
9ef589d8 LW |
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 | |
35c8bce7 LW |
47 | "bsd43") |
48 | echo "Patching perly.c to allow dynamic yacc stack allocation" | |
49 | echo "Assuming bsd4.3 yaccpar" | |
50 | cat >$tmp <<'END' | |
fe14fcc3 LW |
51 | /YYSTYPE[ ]*yyv\[ *YYMAXDEPTH *\];/c\ |
52 | int yymaxdepth = YYMAXDEPTH;\ | |
53 | YYSTYPE *yyv; /* where the values are stored */\ | |
54 | short *yys;\ | |
55 | short *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));\ | |
9ef589d8 LW |
65 | \ if ( !yyv || !yys ) {\ |
66 | \ yyerror( "out of memory" );\ | |
67 | \ return(1);\ | |
68 | \ }\ | |
fe14fcc3 LW |
69 | \ maxyyps = &yys[yymaxdepth];\ |
70 | \ }\ | |
71 | \ yyps = &yys[-1];\ | |
72 | \ yypv = &yyv[-1]; | |
73 | ||
74 | ||
9ef589d8 | 75 | /if *( *\+\+yyps *>=* *&yys\[ *YYMAXDEPTH *\] *)/c\ |
fe14fcc3 LW |
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));\ | |
9ef589d8 LW |
85 | \ if ( !yyv || !yys ) {\ |
86 | \ yyerror( "yacc stack overflow" );\ | |
87 | \ return(1);\ | |
88 | \ }\ | |
fe14fcc3 LW |
89 | \ yyps = yys + ts;\ |
90 | \ yypv = yyv + tv;\ | |
91 | \ maxyyps = &yys[yymaxdepth];\ | |
92 | \ } | |
93 | ||
94 | /yacc stack overflow.*}/d | |
95 | /yacc stack overflow/,/}/d | |
96 | END | |
35c8bce7 LW |
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\ | |
113 | int yymaxdepth = YYMAXDEPTH;\ | |
114 | YYSTYPE *yyv; /* where the values are stored */\ | |
115 | int *yys;\ | |
116 | int *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) | |
146 | END | |
147 | sed -f $tmp < $input > $output ;; | |
148 | ||
149 | ###################################################### | |
150 | # Plan still unknown | |
151 | *) mv $input $output; | |
152 | esac | |
fe14fcc3 | 153 | |
fe14fcc3 | 154 | rm -rf $tmp $input |