From 0b00b1a15e23af3ebac1bc8787ef15cd640ccf84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonathan=20Neusch=C3=A4fer?= Date: Tue, 12 Jun 2012 23:15:44 +0200 Subject: [PATCH] strfsong: evaluate literal text as "true" That is, you can now do things like this: "[%artist%|(artist n/a)] - [%title%|(title n/a)]" --- NEWS | 1 + doc/ncmpc.1 | 7 ++++++- src/strfsong.c | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index 804b6d2..ab2d7b5 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ ncmpc 0.21 - not yet released * add a chat screen for communication with other clients on the same server +* song format: evaluate literal strings as true ncmpc 0.20 - (02/05/2012) diff --git a/doc/ncmpc.1 b/doc/ncmpc.1 index 9f9b166..a298b33 100644 --- a/doc/ncmpc.1 +++ b/doc/ncmpc.1 @@ -248,7 +248,7 @@ ncmpc is running. To edit key bindings press 'K' and use the key editor in ncmpc Format of song display for status and the list window. The metadata delimiters are: %name%, %artist%, %track%, %time%, %file%, %shortfile%. -The [] operators are used to group output such that if no metadata delimiters are found or matched between '[' and ']', then none of the characters between '[' and ']' are output. '&' and '|' are logical operators for AND and OR. '#' is used to escape characters. +The [] operators are used to group output such that if none of the metadata delimiters between '[' and ']' are matched, then none of the characters between '[' and ']' are output; literal text is always output. '&' and '|' are logical operators for AND and OR. '#' is used to escape characters. Some useful examples for format are: @@ -257,6 +257,11 @@ Some useful examples for format are: and "[[%artist% \- ]%title%]|[%file]" + +Another one is: + + "[%artist%|(artist n/a)] - [%title%|(title n/a)]" + .SH "CHAT PROTOCOL" If ncmpc has been compiled with "chat" support, it uses the client-to-client protocol available in MPD 0.17 or higher to communicate with other clients. In order to receive messages it subscribes to the channel with the name "chat", and displays any message sent there as-is. When the user enters a message, it is first with the prefix specified by the \fBchat-prefix\fR option (or the default prefix), and then sent to the "chat" channel for others to read. .SH "BUGS" diff --git a/src/strfsong.c b/src/strfsong.c index 4e9b8d6..35086e8 100644 --- a/src/strfsong.c +++ b/src/strfsong.c @@ -118,6 +118,9 @@ _strfsong(gchar *s, gchar *temp; gsize n, length = 0; gboolean found = FALSE; + /* "missed" helps handling the case of mere literal text like + found==TRUE instead of found==FALSE. */ + gboolean missed = FALSE; s[0] = '\0'; @@ -128,9 +131,10 @@ _strfsong(gchar *s, /* OR */ if (p[0] == '|') { ++p; - if(!found) { + if(missed && !found) { s[0] = '\0'; length = 0; + missed = FALSE; } else { p = skip(p); } @@ -140,10 +144,11 @@ _strfsong(gchar *s, /* AND */ if (p[0] == '&') { ++p; - if(!found) { + if(missed && !found) { p = skip(p); } else { found = FALSE; + missed = FALSE; } continue; } @@ -155,6 +160,8 @@ _strfsong(gchar *s, g_strlcat(s, temp, max); length = strlen(s); found = TRUE; + } else { + missed = TRUE; } g_free(temp); continue; @@ -163,7 +170,7 @@ _strfsong(gchar *s, /* EXPRESSION END */ if (p[0] == ']') { if(last) *last = p+1; - if(!found && length) { + if(missed && !found && length) { s[0] = '\0'; length = 0; } @@ -252,6 +259,8 @@ _strfsong(gchar *s, g_strlcat(s, ident, max); length+=templen; g_free(ident); + + missed = TRUE; } else { gsize templen = strlen(temp); -- 2.30.2