MCPcopy Create free account
hub / github.com/Entware/Entware / __expand_string

Function __expand_string

scripts/config/preprocess.c:498–540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496}
497
498static 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
542static bool is_end_of_str(char c)
543{

Callers 2

expand_string_with_argsFunction · 0.85
expand_one_tokenFunction · 0.85

Calls 3

xmallocFunction · 0.85
expand_dollar_with_argsFunction · 0.85
xreallocFunction · 0.85

Tested by

no test coverage detected