diff options
author | Thomas Jansen <mithi@mithi.net> | 2009-01-09 17:06:44 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-10 16:50:34 +0100 |
commit | 6f0781f0396ab5e4bc8aece6986381dac8f03081 (patch) | |
tree | d20b32323c25d86c81f43af106952efbbdd5d3bb /src | |
parent | 8ed3cf3e6b31e48369a2007da8c95d686c62d184 (diff) | |
download | mpd-6f0781f0396ab5e4bc8aece6986381dac8f03081.tar.gz mpd-6f0781f0396ab5e4bc8aece6986381dac8f03081.tar.xz mpd-6f0781f0396ab5e4bc8aece6986381dac8f03081.zip |
command: playlistinfo now uses a range argument rather than just a song id
Loosely based on a patch provided by lesion in bug #1766. The playlistinfo
command can now retrieve ranges of the playlist. The new argument indicates
which entry is the last one that will be displayed. The number of displayed
entries may be smaller than expected if the end of the playlist is reached.
Previous usage:
playlistinfo [start]
New usage:
playlistinfo [start[:end]]
Diffstat (limited to 'src')
-rw-r--r-- | src/command.c | 9 | ||||
-rw-r--r-- | src/playlist.c | 7 | ||||
-rw-r--r-- | src/playlist.h | 2 |
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); |