version 1.215, 2019/11/15 11:21:32 |
version 1.216, 2019/11/25 15:02:48 |
|
|
format_replace(struct format_tree *ft, const char *key, size_t keylen, |
format_replace(struct format_tree *ft, const char *key, size_t keylen, |
char **buf, size_t *len, size_t *off) |
char **buf, size_t *len, size_t *off) |
{ |
{ |
struct window_pane *wp = ft->wp; |
struct window_pane *wp = ft->wp; |
const char *errptr, *copy, *cp, *marker = NULL; |
const char *errptr, *copy, *cp, *marker = NULL; |
char *copy0, *condition, *found, *new; |
char *copy0, *condition, *found, *new; |
char *value, *left, *right; |
char *value, *left, *right; |
size_t valuelen; |
size_t valuelen; |
int modifiers = 0, limit = 0, j; |
int modifiers = 0, limit = 0, j; |
struct format_modifier *list, *fm, *cmp = NULL, *search = NULL; |
struct format_modifier *list, *fm, *cmp = NULL, *search = NULL; |
struct format_modifier *sub = NULL; |
struct format_modifier **sub = NULL; |
u_int i, count; |
u_int i, count, nsub = 0; |
|
|
/* Make a copy of the key. */ |
/* Make a copy of the key. */ |
copy = copy0 = xstrndup(key, keylen); |
copy = copy0 = xstrndup(key, keylen); |
|
|
case 's': |
case 's': |
if (fm->argc < 2) |
if (fm->argc < 2) |
break; |
break; |
sub = fm; |
sub = xreallocarray (sub, nsub + 1, |
|
sizeof *sub); |
|
sub[nsub++] = fm; |
break; |
break; |
case '=': |
case '=': |
if (fm->argc < 1) |
if (fm->argc < 1) |
|
|
} |
} |
|
|
/* Perform substitution if any. */ |
/* Perform substitution if any. */ |
if (sub != NULL) { |
for (i = 0; i < nsub; i++) { |
left = format_expand(ft, sub->argv[0]); |
left = format_expand(ft, sub[i]->argv[0]); |
right = format_expand(ft, sub->argv[1]); |
right = format_expand(ft, sub[i]->argv[1]); |
new = format_sub(sub, value, left, right); |
new = format_sub(sub[i], value, left, right); |
format_log(ft, "substitute '%s' to '%s': %s", left, right, new); |
format_log(ft, "substitute '%s' to '%s': %s", left, right, new); |
free(value); |
free(value); |
value = new; |
value = new; |
|
|
format_log(ft, "replaced '%s' with '%s'", copy0, value); |
format_log(ft, "replaced '%s' with '%s'", copy0, value); |
free(value); |
free(value); |
|
|
|
free(sub); |
format_free_modifiers(list, count); |
format_free_modifiers(list, count); |
free(copy0); |
free(copy0); |
return (0); |
return (0); |
|
|
fail: |
fail: |
format_log(ft, "failed %s", copy0); |
format_log(ft, "failed %s", copy0); |
|
|
|
free(sub); |
format_free_modifiers(list, count); |
format_free_modifiers(list, count); |
free(copy0); |
free(copy0); |
return (-1); |
return (-1); |