| 496 | } |
| 497 | |
| 498 | static char *__expand_string(const char **str, bool (*is_end)(char c), |
| 499 | int argc, char *argv[]) |
| 500 | { |
| 501 | const char *in, *p; |
| 502 | char *expansion, *out; |
| 503 | size_t in_len, out_len; |
| 504 | |
| 505 | out = xmalloc(1); |
| 506 | *out = 0; |
| 507 | out_len = 1; |
| 508 | |
| 509 | p = in = *str; |
| 510 | |
| 511 | while (1) { |
| 512 | if (*p == '$') { |
| 513 | in_len = p - in; |
| 514 | p++; |
| 515 | expansion = expand_dollar_with_args(&p, argc, argv); |
| 516 | out_len += in_len + strlen(expansion); |
| 517 | out = xrealloc(out, out_len); |
| 518 | strncat(out, in, in_len); |
| 519 | strcat(out, expansion); |
| 520 | free(expansion); |
| 521 | in = p; |
| 522 | continue; |
| 523 | } |
| 524 | |
| 525 | if (is_end(*p)) |
| 526 | break; |
| 527 | |
| 528 | p++; |
| 529 | } |
| 530 | |
| 531 | in_len = p - in; |
| 532 | out_len += in_len; |
| 533 | out = xrealloc(out, out_len); |
| 534 | strncat(out, in, in_len); |
| 535 | |
| 536 | /* Advance 'str' to the end character */ |
| 537 | *str = p; |
| 538 | |
| 539 | return out; |
| 540 | } |
| 541 | |
| 542 | static bool is_end_of_str(char c) |
| 543 | { |
no test coverage detected