summaryrefslogtreecommitdiffstats
path: root/format.c
diff options
context:
space:
mode:
authornicm <nicm>2019-03-13 14:19:54 +0000
committernicm <nicm>2019-03-13 14:19:54 +0000
commit9032ac2a05e0b769056a0d5a5814cc00ba065825 (patch)
tree49a5ec65d8f772d13bb3b83a7ef956262978ec13 /format.c
parent71e00c718ca5b573686e70c72eac8989c21b71b5 (diff)
Add E: format to expand a format twice (useful to expand the value of an
option).
Diffstat (limited to 'format.c')
-rw-r--r--format.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/format.c b/format.c
index cb196351..55cb5028 100644
--- a/format.c
+++ b/format.c
@@ -94,6 +94,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_DIRNAME 0x4
#define FORMAT_QUOTE 0x8
#define FORMAT_LITERAL 0x10
+#define FORMAT_EXPAND 0x20
/* Entry in format tree. */
struct format_entry {
@@ -1012,7 +1013,7 @@ format_build_modifiers(struct format_tree *ft, const char **s, u_int *count)
cp++;
/* Check single character modifiers with no arguments. */
- if (strchr("lmCbdtq", cp[0]) != NULL && format_is_end(cp[1])) {
+ if (strchr("lmCbdtqE", cp[0]) != NULL && format_is_end(cp[1])) {
format_add_modifier(&list, count, cp, 1, NULL, 0);
cp++;
continue;
@@ -1189,6 +1190,9 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
case 'q':
modifiers |= FORMAT_QUOTE;
break;
+ case 'E':
+ modifiers |= FORMAT_EXPAND;
+ break;
}
} else if (fm->size == 2) {
if (strcmp(fm->modifier, "||") == 0 ||
@@ -1289,6 +1293,13 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
value = xstrdup("");
}
+ /* Expand again if required. */
+ if (modifiers & FORMAT_EXPAND) {
+ new = format_expand(ft, value);
+ free(value);
+ value = new;
+ }
+
/* Perform substitution if any. */
if (sub != NULL) {
new = format_substitute(value, sub->argv[0], sub->argv[1]);