diff options
author | Timo Sirainen <cras@irssi.org> | 2001-06-26 15:33:07 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-06-26 15:33:07 +0000 |
commit | 8b733e056874801b8b094f7a456f5548bb84b8f0 (patch) | |
tree | d18008d2fc933f4c026a70630412908a7e385716 /src | |
parent | 0a3a175a7dc8616ba2000973437fcaa4f5cf64d8 (diff) | |
download | irssi-8b733e056874801b8b094f7a456f5548bb84b8f0.zip |
special-vars: added flag PARSE_FLAG_ESCAPE_THEME to escape { and } chars
with % char. Used this with statusbar items - now for example "{error xxx}"
topic won't print it with error color.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1564 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src')
-rw-r--r-- | src/core/special-vars.c | 31 | ||||
-rw-r--r-- | src/core/special-vars.h | 1 | ||||
-rw-r--r-- | src/fe-text/statusbar-items.c | 3 |
3 files changed, 27 insertions, 8 deletions
diff --git a/src/core/special-vars.c b/src/core/special-vars.c index 40372f93..3898fe15 100644 --- a/src/core/special-vars.c +++ b/src/core/special-vars.c @@ -435,11 +435,31 @@ char *parse_special(char **cmd, SERVER_REC *server, void *item, return value; } -static void gstring_append_escaped(GString *str, const char *text) +static void gstring_append_escaped(GString *str, const char *text, int flags) { + char esc[4], *escpos; + + escpos = esc; + if (flags & PARSE_FLAG_ESCAPE_VARS) + *escpos++ = '%'; + if (flags & PARSE_FLAG_ESCAPE_THEME) { + *escpos++ = '{'; + *escpos++ = '}'; + } + + if (escpos == esc) { + g_string_append(str, text); + return; + } + + *escpos = '\0'; while (*text != '\0') { - if (*text == '%') - g_string_append_c(str, '%'); + for (escpos = esc; *escpos != '\0'; escpos++) { + if (*text == *escpos) { + g_string_append_c(str, '%'); + break; + } + } g_string_append_c(str, *text); text++; } @@ -482,10 +502,7 @@ char *parse_special_string(const char *cmd, SERVER_REC *server, void *item, arglist, &need_free, arg_used, flags); if (ret != NULL) { - if ((flags & PARSE_FLAG_ESCAPE_VARS) == 0) - g_string_append(str, ret); - else - gstring_append_escaped(str, ret); + gstring_append_escaped(str, ret, flags); if (need_free) g_free(ret); } code = 0; diff --git a/src/core/special-vars.h b/src/core/special-vars.h index af02e121..45b41f52 100644 --- a/src/core/special-vars.h +++ b/src/core/special-vars.h @@ -6,6 +6,7 @@ #define PARSE_FLAG_GETNAME 0x01 /* return argument name instead of it's value */ #define PARSE_FLAG_ISSET_ANY 0x02 /* arg_used field specifies that at least one of the $variables was non-empty */ #define PARSE_FLAG_ESCAPE_VARS 0x04 /* if any arguments/variables contain % chars, escape them with another % */ +#define PARSE_FLAG_ESCAPE_THEME 0x08 /* if any arguments/variables contain { or } chars, escape them with % */ typedef char* (*SPECIAL_HISTORY_FUNC) (const char *text, void *item, int *free_ret); diff --git a/src/fe-text/statusbar-items.c b/src/fe-text/statusbar-items.c index c3b69725..7c72e47b 100644 --- a/src/fe-text/statusbar-items.c +++ b/src/fe-text/statusbar-items.c @@ -95,7 +95,8 @@ static void item_default(SBAR_ITEM_REC *item, int get_size_only, /* expand $variables */ tmpstr = parse_special_string(str, server, wiitem, data, NULL, - PARSE_FLAG_ESCAPE_VARS); + PARSE_FLAG_ESCAPE_VARS | + PARSE_FLAG_ESCAPE_THEME); /* expand templates */ str = tmpstr; |