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]]
This commit is contained in:
parent
8ed3cf3e6b
commit
6f0781f039
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue