summaryrefslogtreecommitdiff
path: root/playlist.c
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-07-29 08:17:36 +0200
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-07-29 08:17:36 +0200
commita47247a948e47f6bbadcf15f031af902d1f42551 (patch)
treee4b053672c0eb89b4c22c8fe95c97ef8377664cf /playlist.c
parent87e3b467e0bd62e43d6eb3547574c2378264ef89 (diff)
fixed pl_format_title code duplication in shellexec plugin
Diffstat (limited to 'playlist.c')
-rw-r--r--playlist.c65
1 files changed, 58 insertions, 7 deletions
diff --git a/playlist.c b/playlist.c
index 40d1a671..802605a3 100644
--- a/playlist.c
+++ b/playlist.c
@@ -2436,13 +2436,14 @@ pl_format_elapsed (const char *ret, char *elapsed, int size) {
return elapsed;
}
-int
-pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char *fmt) {
+// this function allows to escape special chars substituted for conversions
+// @escape_chars: list of escapable characters terminated with 0, or NULL if none
+static int
+pl_format_title_int (const char *escape_chars, playItem_t *it, int idx, char *s, int size, int id, const char *fmt) {
char dur[50];
char elp[50];
char fno[50];
char tags[200];
- char artistalbum[1024];
const char *duration = NULL;
const char *elapsed = NULL;
@@ -2480,7 +2481,7 @@ pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char
return 0;
}
int n = size-1;
- while (*fmt && n) {
+ while (*fmt && n > 0) {
if (*fmt != '%') {
*s++ = *fmt;
n--;
@@ -2557,6 +2558,9 @@ pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char
meta++;
}
}
+ else if (*fmt == 'F') {
+ meta = it->fname;
+ }
else if (*fmt == 'T') {
char *t = tags;
char *e = tags + sizeof (tags);
@@ -2607,16 +2611,53 @@ pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char
if (meta) {
const char *value = meta;
- while (n > 0 && *value) {
- *s++ = *value++;
+ if (escape_chars) {
+ // need space for at least 2 single-quotes
+ if (n < 2) {
+ goto error;
+ }
+ *s++ = '\'';
+ n--;
+ while (n > 2 && *value) {
+ const char *e = escape_chars;
+ for (; *e; e++) {
+ if (*value == *e) {
+ if (n < 2) {
+ // doesn't fit into output buffer, return
+ // empty string and error code
+ *ss = 0;
+ return -1;
+ }
+ *s++ = '\\';
+ n--;
+ *s++ = *value++;
+ n--;
+ }
+ else {
+ *s++ = *value++;
+ }
+ }
+ }
+ if (n < 1) {
+ fprintf (stderr, "pl_format_title_int: got unpredicted state while formatting escaped string. please report a bug.\n");
+ *ss = 0; // should never happen
+ return -1;
+ }
+ *s++ = '\'';
n--;
}
+ else {
+ while (n > 0 && *value) {
+ *s++ = *value++;
+ n--;
+ }
+ }
}
}
fmt++;
}
+error:
*s = 0;
-
UNLOCK;
// replace all \n with ;
@@ -2630,6 +2671,16 @@ pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char
return size - n - 1;
}
+int
+pl_format_title (playItem_t *it, int idx, char *s, int size, int id, const char *fmt) {
+ return pl_format_title_int (NULL, it, idx, s, size, id, fmt);
+}
+
+int
+pl_format_title_escaped (playItem_t *it, int idx, char *s, int size, int id, const char *fmt) {
+ return pl_format_title_int ("'", it, idx, s, size, id, fmt);
+}
+
static int pl_sort_is_duration;
static int pl_sort_is_track;
static int pl_sort_ascending;