X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fstrfsong.c;h=b64c350ba6dace76d83b8c70f0dd49d591b1eefc;hb=b3e29d017a77d1cd34bfde94bd7182422e6d695c;hp=35086e85de41afe083d2f43e71f58ebd7453f7a9;hpb=0b00b1a15e23af3ebac1bc8787ef15cd640ccf84;p=ncmpc.git diff --git a/src/strfsong.c b/src/strfsong.c index 35086e8..b64c350 100644 --- a/src/strfsong.c +++ b/src/strfsong.c @@ -1,5 +1,5 @@ /* ncmpc (Ncurses MPD Client) - * (c) 2004-2010 The Music Player Daemon Project + * (c) 2004-2017 The Music Player Daemon Project * Project homepage: http://musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -19,7 +19,7 @@ #include "strfsong.h" #include "charset.h" -#include "utils.h" +#include "time_format.h" #include @@ -62,15 +62,13 @@ song_more_tag_values(const struct mpd_song *song, enum mpd_tag_type tag, const char *first) { const char *p = mpd_song_get_tag(song, tag, 1); - char *buffer, *prev; - if (p == NULL) return NULL; - buffer = concat_tag_values(first, p); + char *buffer = concat_tag_values(first, p); for (unsigned i = 2; (p = mpd_song_get_tag(song, tag, i)) != NULL; ++i) { - prev = buffer; + char *prev = buffer; buffer = concat_tag_values(buffer, p); g_free(prev); } @@ -84,21 +82,16 @@ static char * song_tag_locale(const struct mpd_song *song, enum mpd_tag_type tag) { const char *value = mpd_song_get_tag(song, tag, 0); - char *result; -#ifndef NCMPC_MINI - char *all; -#endif /* !NCMPC_MINI */ - if (value == NULL) return NULL; #ifndef NCMPC_MINI - all = song_more_tag_values(song, tag, value); + char *all = song_more_tag_values(song, tag, value); if (all != NULL) value = all; #endif /* !NCMPC_MINI */ - result = utf8_to_locale(value); + char *result = utf8_to_locale(value); #ifndef NCMPC_MINI g_free(all); @@ -114,19 +107,18 @@ _strfsong(gchar *s, const struct mpd_song *song, const gchar **last) { - const gchar *p, *end; - gchar *temp; - gsize n, length = 0; - gboolean found = FALSE; + bool found = false; /* "missed" helps handling the case of mere literal text like - found==TRUE instead of found==FALSE. */ - gboolean missed = FALSE; + found==true instead of found==false. */ + bool missed = false; s[0] = '\0'; if (song == NULL) return 0; + const char *p; + size_t length = 0; for (p = format; *p != '\0' && length0 ) { g_strlcat(s, temp, max); length = strlen(s); - found = TRUE; + found = true; } else { - missed = TRUE; + missed = true; } g_free(temp); continue; @@ -196,21 +188,34 @@ _strfsong(gchar *s, /* advance past the esc character */ /* find the extent of this format specifier (stop at \0, ' ', or esc) */ - temp = NULL; - end = p+1; + char *temp = NULL; + const char *end = p + 1; while(*end >= 'a' && *end <= 'z') { end++; } - n = end - p + 1; + size_t n = end - p + 1; if(*end != '%') n--; else if (strncmp("%file%", p, n) == 0) temp = utf8_to_locale(mpd_song_get_uri(song)); - else if (strncmp("%artist%", p, n) == 0) + else if (strncmp("%artist%", p, n) == 0) { temp = song_tag_locale(song, MPD_TAG_ARTIST); - else if (strncmp("%title%", p, n) == 0) + if (temp == NULL) { + temp = song_tag_locale(song, MPD_TAG_PERFORMER); + if (temp == NULL) + temp = song_tag_locale(song, MPD_TAG_COMPOSER); + } + } else if (strncmp("%albumartist", p, n) == 0) + temp = song_tag_locale(song, MPD_TAG_ALBUM_ARTIST); + else if (strncmp("%composer%", p, n) == 0) + temp = song_tag_locale(song, MPD_TAG_COMPOSER); + else if (strncmp("%performer%", p, n) == 0) + temp = song_tag_locale(song, MPD_TAG_PERFORMER); + else if (strncmp("%title%", p, n) == 0) { temp = song_tag_locale(song, MPD_TAG_TITLE); - else if (strncmp("%album%", p, n) == 0) + if (temp == NULL) + temp = song_tag_locale(song, MPD_TAG_NAME); + } else if (strncmp("%album%", p, n) == 0) temp = song_tag_locale(song, MPD_TAG_ALBUM); else if (strncmp("%shortalbum%", p, n) == 0) { temp = song_tag_locale(song, MPD_TAG_ALBUM); @@ -227,6 +232,8 @@ _strfsong(gchar *s, } else if (strncmp("%track%", p, n) == 0) temp = song_tag_locale(song, MPD_TAG_TRACK); + else if (strncmp("%disc%", p, n) == 0) + temp = song_tag_locale(song, MPD_TAG_DISC); else if (strncmp("%name%", p, n) == 0) temp = song_tag_locale(song, MPD_TAG_NAME); else if (strncmp("%date%", p, n) == 0) @@ -260,11 +267,11 @@ _strfsong(gchar *s, length+=templen; g_free(ident); - missed = TRUE; + missed = true; } else { gsize templen = strlen(temp); - found = TRUE; + found = true; if( length+templen > max ) templen = max-length; g_strlcat(s, temp, max);