Lines 67-73
Link Here
|
67 |
{ |
67 |
{ |
68 |
register int ch; |
68 |
register int ch; |
69 |
register char *p, *bbp, *ebp, **bxp, **exp, **xp; |
69 |
register char *p, *bbp, *ebp, **bxp, **exp, **xp; |
70 |
int cnt, indouble, insingle, nargs, nflag, nline, xflag; |
70 |
int cnt, indouble, insingle, nargs, nflag, nline, xflag, wasquoted; |
71 |
char **av, *argp, **ep = env; |
71 |
char **av, *argp, **ep = env; |
72 |
|
72 |
|
73 |
/* |
73 |
/* |
Lines 172-183
Link Here
|
172 |
if (p == bbp) |
172 |
if (p == bbp) |
173 |
exit(rval); |
173 |
exit(rval); |
174 |
|
174 |
|
175 |
/* Nothing since end of last argument. */ |
|
|
176 |
if (argp == p) { |
177 |
*xp = NULL; |
178 |
run(av); |
179 |
exit(rval); |
180 |
} |
181 |
goto arg1; |
175 |
goto arg1; |
182 |
case ' ': |
176 |
case ' ': |
183 |
case '\t': |
177 |
case '\t': |
Lines 193-216
Link Here
|
193 |
if (zflag) |
187 |
if (zflag) |
194 |
goto addch; |
188 |
goto addch; |
195 |
|
189 |
|
196 |
/* Empty lines are skipped. */ |
|
|
197 |
if (argp == p) |
198 |
continue; |
199 |
|
200 |
/* Quotes do not escape newlines. */ |
190 |
/* Quotes do not escape newlines. */ |
201 |
arg1: if (insingle || indouble) |
191 |
arg1: if (insingle || indouble) |
202 |
err("unterminated quote"); |
192 |
err("unterminated quote"); |
203 |
|
193 |
arg2: |
204 |
arg2: *p = '\0'; |
194 |
/* Do not make empty args unless they are quoted */ |
205 |
*xp++ = argp; |
195 |
if (argp != p || wasquoted) { |
|
|
196 |
*p++ = '\0'; |
197 |
*xp++ = argp; |
198 |
} |
206 |
|
199 |
|
207 |
/* |
200 |
/* |
208 |
* If max'd out on args or buffer, or reached EOF, |
201 |
* If max'd out on args or buffer, or reached EOF, |
209 |
* run the command. If xflag and max'd out on buffer |
202 |
* run the command. If xflag and max'd out on buffer |
210 |
* but not on args, object. |
203 |
* but not on args, object. |
211 |
*/ |
204 |
*/ |
212 |
if (xp == exp || p == ebp || ch == EOF) { |
205 |
if (xp == exp || p > ebp || ch == EOF) { |
213 |
if (xflag && xp != exp && p == ebp) |
206 |
if (xflag && xp != exp && p > ebp) |
214 |
err("insufficient space for arguments"); |
207 |
err("insufficient space for arguments"); |
215 |
*xp = NULL; |
208 |
*xp = NULL; |
216 |
run(av); |
209 |
run(av); |
Lines 218-236
Link Here
|
218 |
exit(rval); |
211 |
exit(rval); |
219 |
p = bbp; |
212 |
p = bbp; |
220 |
xp = bxp; |
213 |
xp = bxp; |
221 |
} else |
214 |
} |
222 |
++p; |
|
|
223 |
argp = p; |
215 |
argp = p; |
|
|
216 |
wasquoted = 0; |
224 |
break; |
217 |
break; |
225 |
case '\'': |
218 |
case '\'': |
226 |
if (indouble || zflag) |
219 |
if (indouble || zflag) |
227 |
goto addch; |
220 |
goto addch; |
228 |
insingle = !insingle; |
221 |
insingle = !insingle; |
|
|
222 |
wasquoted = 1; |
229 |
break; |
223 |
break; |
230 |
case '"': |
224 |
case '"': |
231 |
if (insingle || zflag) |
225 |
if (insingle || zflag) |
232 |
goto addch; |
226 |
goto addch; |
233 |
indouble = !indouble; |
227 |
indouble = !indouble; |
|
|
228 |
wasquoted = 1; |
234 |
break; |
229 |
break; |
235 |
case '\\': |
230 |
case '\\': |
236 |
if (zflag) |
231 |
if (zflag) |