|
Lines 334-340
Link Here
|
| 334 |
{ |
334 |
{ |
| 335 |
const char *cp = *cpp, *end; |
335 |
const char *cp = *cpp, *end; |
| 336 |
char quot; |
336 |
char quot; |
| 337 |
int i; |
337 |
int i, j; |
| 338 |
|
338 |
|
| 339 |
cp += strspn(cp, WHITESPACE); |
339 |
cp += strspn(cp, WHITESPACE); |
| 340 |
if (!*cp) { |
340 |
if (!*cp) { |
|
Lines 343-379
Link Here
|
| 343 |
return (0); |
343 |
return (0); |
| 344 |
} |
344 |
} |
| 345 |
|
345 |
|
|
|
346 |
*path = xmalloc(strlen(cp) + 1); |
| 347 |
|
| 346 |
/* Check for quoted filenames */ |
348 |
/* Check for quoted filenames */ |
| 347 |
if (*cp == '\"' || *cp == '\'') { |
349 |
if (*cp == '\"' || *cp == '\'') { |
| 348 |
quot = *cp++; |
350 |
quot = *cp++; |
| 349 |
|
351 |
|
| 350 |
end = strchr(cp, quot); |
352 |
/* Search for terminating quote, unescape some chars */ |
| 351 |
if (end == NULL) { |
353 |
for (i = j = 0; i <= strlen(cp); i++) { |
| 352 |
error("Unterminated quote"); |
354 |
if (cp[i] == quot) { /* Found quote */ |
| 353 |
goto fail; |
355 |
(*path)[j] = '\0'; |
|
|
356 |
break; |
| 357 |
} |
| 358 |
if (cp[i] == '\0') { /* End of string */ |
| 359 |
error("Unterminated quote"); |
| 360 |
goto fail; |
| 361 |
} |
| 362 |
if (cp[i] == '\\') { /* Escaped characters */ |
| 363 |
i++; |
| 364 |
if (cp[i] != '\'' && cp[i] != '\"') { |
| 365 |
error("Bad escaped character '%c'", |
| 366 |
cp[i]); |
| 367 |
goto fail; |
| 368 |
} |
| 369 |
} |
| 370 |
(*path)[j++] = cp[i]; |
| 354 |
} |
371 |
} |
| 355 |
if (cp == end) { |
372 |
|
|
|
373 |
if (j == 0) { |
| 356 |
error("Empty quotes"); |
374 |
error("Empty quotes"); |
| 357 |
goto fail; |
375 |
goto fail; |
| 358 |
} |
376 |
} |
| 359 |
*cpp = end + 1 + strspn(end + 1, WHITESPACE); |
377 |
*cpp = cp + i + strspn(cp + i, WHITESPACE); |
| 360 |
} else { |
378 |
} else { |
| 361 |
/* Read to end of filename */ |
379 |
/* Read to end of filename */ |
| 362 |
end = strpbrk(cp, WHITESPACE); |
380 |
end = strpbrk(cp, WHITESPACE); |
| 363 |
if (end == NULL) |
381 |
if (end == NULL) |
| 364 |
end = strchr(cp, '\0'); |
382 |
end = strchr(cp, '\0'); |
| 365 |
*cpp = end + strspn(end, WHITESPACE); |
383 |
*cpp = end + strspn(end, WHITESPACE); |
| 366 |
} |
|
|
| 367 |
|
| 368 |
i = end - cp; |
| 369 |
|
384 |
|
| 370 |
*path = xmalloc(i + 1); |
385 |
memcpy(*path, cp, end - cp); |
| 371 |
memcpy(*path, cp, i); |
386 |
(*path)[end - cp] = '\0'; |
| 372 |
(*path)[i] = '\0'; |
387 |
} |
| 373 |
return(0); |
388 |
return (0); |
| 374 |
|
389 |
|
| 375 |
fail: |
390 |
fail: |
| 376 |
*path = NULL; |
391 |
xfree(*path); |
|
|
392 |
*path = NULL; |
| 377 |
return (-1); |
393 |
return (-1); |
| 378 |
} |
394 |
} |
| 379 |
|
395 |
|