]>
Commit | Line | Data |
---|---|---|
cf7098dd MM |
1 | diff -urN netbsd-sh/mksyntax.c ash-0.3.7.orig/mksyntax.c |
2 | --- netbsd-sh/mksyntax.c Fri Jan 12 17:50:38 2001 | |
3 | +++ ash-0.3.7.orig/mksyntax.c Mon Apr 23 22:16:46 2001 | |
4 | @@ -238,14 +238,14 @@ | |
5 | add("$", "CVAR"); | |
6 | add("}", "CENDVAR"); | |
7 | /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ | |
8 | - add("!*?[=~:/-", "CCTL"); | |
9 | + add("!*?[=~:/-]", "CCTL"); | |
10 | print("dqsyntax"); | |
11 | init(); | |
12 | fputs("\n/* syntax table used when in single quotes */\n", cfile); | |
13 | add("\n", "CNL"); | |
14 | add("'", "CENDQUOTE"); | |
15 | /* ':/' for tilde expansion, '-' for [a\-x] pattern ranges */ | |
16 | - add("!*?[=~:/-", "CCTL"); | |
17 | + add("!*?[=~:/-]\\", "CCTL"); | |
18 | print("sqsyntax"); | |
19 | init(); | |
20 | fputs("\n/* syntax table used when in arithmetic */\n", cfile); | |
21 | diff -urN netbsd-sh/parser.c ash-0.3.7.orig/parser.c | |
22 | --- netbsd-sh/parser.c Fri Jan 12 17:50:39 2001 | |
23 | +++ ash-0.3.7.orig/parser.c Mon Apr 23 22:16:46 2001 | |
24 | @@ -221,6 +221,7 @@ | |
25 | union node *n1, *n2, *n3; | |
26 | int t; | |
27 | ||
28 | + checkkwd = 1; | |
29 | n1 = pipeline(); | |
30 | for (;;) { | |
31 | if ((t = readtoken()) == TAND) { | |
32 | @@ -231,6 +232,7 @@ | |
33 | tokpushback++; | |
34 | return n1; | |
35 | } | |
36 | + checkkwd = 2; | |
37 | n2 = pipeline(); | |
38 | n3 = (union node *)stalloc(sizeof (struct nbinary)); | |
39 | n3->type = t; | |
40 | @@ -250,9 +252,11 @@ | |
41 | ||
42 | negate = 0; | |
43 | TRACE(("pipeline: entered\n")); | |
44 | - while (readtoken() == TNOT) | |
45 | + if (readtoken() == TNOT) { | |
46 | negate = !negate; | |
47 | - tokpushback++; | |
48 | + checkkwd = 1; | |
49 | + } else | |
50 | + tokpushback++; | |
51 | n1 = command(); | |
52 | if (readtoken() == TPIPE) { | |
53 | pipenode = (union node *)stalloc(sizeof (struct npipe)); | |
54 | @@ -264,6 +268,7 @@ | |
55 | do { | |
56 | prev = lp; | |
57 | lp = (struct nodelist *)stalloc(sizeof (struct nodelist)); | |
58 | + checkkwd = 2; | |
59 | lp->n = command(); | |
60 | prev->next = lp; | |
61 | } while (readtoken() == TPIPE); | |
62 | @@ -288,9 +293,8 @@ | |
63 | union node *ap, **app; | |
64 | union node *cp, **cpp; | |
65 | union node *redir, **rpp; | |
66 | - int t, negate = 0; | |
67 | + int t; | |
68 | ||
69 | - checkkwd = 2; | |
70 | redir = NULL; | |
71 | n1 = NULL; | |
72 | rpp = &redir; | |
73 | @@ -303,12 +307,6 @@ | |
74 | } | |
75 | tokpushback++; | |
76 | ||
77 | - while (readtoken() == TNOT) { | |
78 | - TRACE(("command: TNOT recognized\n")); | |
79 | - negate = !negate; | |
80 | - } | |
81 | - tokpushback++; | |
82 | - | |
83 | switch (readtoken()) { | |
84 | case TIF: | |
85 | n1 = (union node *)stalloc(sizeof (struct nif)); | |
86 | @@ -417,6 +415,8 @@ | |
87 | cpp = &n1->ncase.cases; | |
88 | checkkwd = 2, readtoken(); | |
89 | do { | |
90 | + if (lasttoken == TLP) | |
91 | + readtoken(); | |
92 | *cpp = cp = (union node *)stalloc(sizeof (struct nclist)); | |
93 | cp->type = NCLIST; | |
94 | app = &cp->nclist.pattern; | |
95 | @@ -464,21 +464,22 @@ | |
96 | break; | |
97 | /* Handle an empty command like other simple commands. */ | |
98 | case TSEMI: | |
99 | + case TAND: | |
100 | + case TOR: | |
101 | + case TNL: | |
102 | + case TEOF: | |
103 | + case TRP: | |
104 | + case TBACKGND: | |
105 | /* | |
106 | * An empty command before a ; doesn't make much sense, and | |
107 | * should certainly be disallowed in the case of `if ;'. | |
108 | */ | |
109 | if (!redir) | |
110 | synexpect(-1); | |
111 | - case TAND: | |
112 | - case TOR: | |
113 | - case TNL: | |
114 | - case TEOF: | |
115 | case TWORD: | |
116 | - case TRP: | |
117 | tokpushback++; | |
118 | n1 = simplecmd(rpp, redir); | |
119 | - goto checkneg; | |
120 | + return n1; | |
121 | default: | |
122 | synexpect(-1); | |
123 | /* NOTREACHED */ | |
124 | @@ -502,15 +503,7 @@ | |
125 | n1->nredir.redirect = redir; | |
126 | } | |
127 | ||
128 | -checkneg: | |
129 | - if (negate) { | |
130 | - n2 = (union node *)stalloc(sizeof (struct nnot)); | |
131 | - n2->type = NNOT; | |
132 | - n2->nnot.com = n1; | |
133 | - return n2; | |
134 | - } | |
135 | - else | |
136 | - return n1; | |
137 | + return n1; | |
138 | } | |
139 | ||
140 | ||
141 | @@ -520,8 +513,7 @@ | |
142 | { | |
143 | union node *args, **app; | |
144 | union node **orig_rpp = rpp; | |
145 | - union node *n = NULL, *n2; | |
146 | - int negate = 0; | |
147 | + union node *n = NULL; | |
148 | ||
149 | /* If we don't have any redirections already, then we must reset */ | |
150 | /* rpp to be the address of the local redir variable. */ | |
151 | @@ -537,12 +529,6 @@ | |
152 | */ | |
153 | orig_rpp = rpp; | |
154 | ||
155 | - while (readtoken() == TNOT) { | |
156 | - TRACE(("command: TNOT recognized\n")); | |
157 | - negate = !negate; | |
158 | - } | |
159 | - tokpushback++; | |
160 | - | |
161 | for (;;) { | |
162 | if (readtoken() == TWORD) { | |
163 | n = (union node *)stalloc(sizeof (struct narg)); | |
164 | @@ -565,8 +551,9 @@ | |
165 | synerror("Bad function name"); | |
166 | #endif | |
167 | n->type = NDEFUN; | |
168 | + checkkwd = 2; | |
169 | n->narg.next = command(); | |
170 | - goto checkneg; | |
171 | + return n; | |
172 | } else { | |
173 | tokpushback++; | |
174 | break; | |
175 | @@ -579,16 +566,7 @@ | |
176 | n->ncmd.backgnd = 0; | |
177 | n->ncmd.args = args; | |
178 | n->ncmd.redirect = redir; | |
179 | - | |
180 | -checkneg: | |
181 | - if (negate) { | |
182 | - n2 = (union node *)stalloc(sizeof (struct nnot)); | |
183 | - n2->type = NNOT; | |
184 | - n2->nnot.com = n; | |
185 | - return n2; | |
186 | - } | |
187 | - else | |
188 | - return n; | |
189 | + return n; | |
190 | } | |
191 | ||
192 | STATIC union node * | |
193 | @@ -743,7 +721,7 @@ | |
194 | } | |
195 | } | |
196 | out: | |
197 | - checkkwd = (t == TNOT) ? savecheckkwd : 0; | |
198 | + checkkwd = 0; | |
199 | } | |
200 | #ifdef DEBUG | |
201 | if (!alreadyseen) | |
202 | @@ -882,6 +860,7 @@ | |
203 | int varnest; /* levels of variables expansion */ | |
204 | int arinest; /* levels of arithmetic expansion */ | |
205 | int parenlevel; /* levels of parens in arithmetic */ | |
206 | + int dqvarnest; /* levels of variables expansion within double quotes */ | |
207 | int oldstyle; | |
208 | char const *prevsyntax; /* syntax before arithmetic */ | |
209 | #if __GNUC__ | |
210 | @@ -892,6 +871,7 @@ | |
211 | (void) &varnest; | |
212 | (void) &arinest; | |
213 | (void) &parenlevel; | |
214 | + (void) &dqvarnest; | |
215 | (void) &oldstyle; | |
216 | (void) &prevsyntax; | |
217 | (void) &syntax; | |
218 | @@ -906,6 +886,7 @@ | |
219 | varnest = 0; | |
220 | arinest = 0; | |
221 | parenlevel = 0; | |
222 | + dqvarnest = 0; | |
223 | ||
224 | STARTSTACKSTR(out); | |
225 | loop: { /* for each line, until end of word */ | |
226 | @@ -938,7 +919,8 @@ | |
227 | USTPUTC(c, out); | |
228 | break; | |
229 | case CCTL: | |
230 | - if (eofmark == NULL || dblquote) | |
231 | + if ((eofmark == NULL || dblquote) && | |
232 | + dqvarnest == 0) | |
233 | USTPUTC(CTLESC, out); | |
234 | USTPUTC(c, out); | |
235 | break; | |
236 | @@ -983,7 +965,8 @@ | |
237 | if (arinest) { | |
238 | syntax = ARISYNTAX; | |
239 | dblquote = 0; | |
240 | - } else if (eofmark == NULL) { | |
241 | + } else if (eofmark == NULL && | |
242 | + dqvarnest == 0) { | |
243 | syntax = BASESYNTAX; | |
244 | dblquote = 0; | |
245 | } | |
246 | @@ -996,6 +979,9 @@ | |
247 | case CENDVAR: /* '}' */ | |
248 | if (varnest > 0) { | |
249 | varnest--; | |
250 | + if (dqvarnest > 0) { | |
251 | + dqvarnest--; | |
252 | + } | |
253 | USTPUTC(CTLENDVAR, out); | |
254 | } else { | |
255 | USTPUTC(c, out); | |
256 | @@ -1260,8 +1248,12 @@ | |
257 | if (dblquote || arinest) | |
258 | flags |= VSQUOTE; | |
259 | *(stackblock() + typeloc) = subtype | flags; | |
260 | - if (subtype != VSNORMAL) | |
261 | + if (subtype != VSNORMAL) { | |
262 | varnest++; | |
263 | + if (dblquote) { | |
264 | + dqvarnest++; | |
265 | + } | |
266 | + } | |
267 | } | |
268 | goto parsesub_return; | |
269 | } | |
270 |