aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/command.c9
-rw-r--r--src/playlist.c7
-rw-r--r--src/playlist.h2
3 files changed, 12 insertions, 6 deletions
diff --git a/src/command.c b/src/command.c
index 652d3b3b0..076bc2055 100644
--- a/src/command.c
+++ b/src/command.c
@@ -79,6 +79,7 @@ struct command {
/* this should really be "need a non-negative integer": */
static const char need_positive[] = "need a positive integer"; /* no-op */
+static const char need_range[] = "need a range";
/* FIXME: redundant error messages */
static const char check_integer[] = "\"%s\" is not a integer";
@@ -389,7 +390,7 @@ handle_currentsong(struct client *client,
if (song < 0)
return COMMAND_RETURN_OK;
- result = playlistInfo(client, song);
+ result = playlistInfo(client, song, song);
return print_playlist_result(client, result);
}
@@ -742,13 +743,13 @@ handle_plchangesposid(struct client *client, G_GNUC_UNUSED int argc, char *argv[
static enum command_return
handle_playlistinfo(struct client *client, int argc, char *argv[])
{
- int song = -1;
+ int song = -1, max = -1;
enum playlist_result result;
- if (argc == 2 && !check_int(client, &song, argv[1], need_positive))
+ if (argc == 2 && !check_range(client, &song, &max, argv[1], need_range))
return COMMAND_RETURN_ERROR;
- result = playlistInfo(client, song);
+ result = playlistInfo(client, song, max);
return print_playlist_result(client, result);
}
diff --git a/src/playlist.c b/src/playlist.c
index df60fe99b..e6dd1cac0 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -413,7 +413,7 @@ int playlistChangesPosId(struct client *client, uint32_t version)
return 0;
}
-enum playlist_result playlistInfo(struct client *client, int song)
+enum playlist_result playlistInfo(struct client *client, int song, int max)
{
unsigned begin = 0;
unsigned end = playlist.length;
@@ -424,6 +424,11 @@ enum playlist_result playlistInfo(struct client *client, int song)
}
if (song >= (int)playlist.length)
return PLAYLIST_RESULT_BAD_RANGE;
+ if (max > 0) {
+ end = MIN((unsigned)(max + 1), playlist.length);
+ if (end <= begin)
+ return PLAYLIST_RESULT_BAD_RANGE;
+ }
for (unsigned i = begin; i < end; i++)
printPlaylistSongInfo(client, i);
diff --git a/src/playlist.h b/src/playlist.h
index 59c37a788..87364cb4c 100644
--- a/src/playlist.h
+++ b/src/playlist.h
@@ -95,7 +95,7 @@ enum playlist_result deleteFromPlaylist(unsigned song);
enum playlist_result deleteFromPlaylistById(unsigned song);
-enum playlist_result playlistInfo(struct client *client, int song);
+enum playlist_result playlistInfo(struct client *client, int song, int max);
enum playlist_result playlistId(struct client *client, int song);