Commit 7fdd8014 authored by Max Kellermann's avatar Max Kellermann

DatabaseCommands: simplify the handle_list() argument parser

parent 27002ad1
...@@ -179,16 +179,20 @@ handle_listall(Client &client, gcc_unused int argc, char *argv[]) ...@@ -179,16 +179,20 @@ handle_listall(Client &client, gcc_unused int argc, char *argv[])
CommandResult CommandResult
handle_list(Client &client, int argc, char *argv[]) handle_list(Client &client, int argc, char *argv[])
{ {
unsigned tagType = locate_parse_type(argv[1]); ConstBuffer<const char *> args(argv + 1, argc - 1);
const char *tag_name = args.shift();
unsigned tagType = locate_parse_type(tag_name);
if (tagType >= TAG_NUM_OF_ITEM_TYPES && if (tagType >= TAG_NUM_OF_ITEM_TYPES &&
tagType != LOCATE_TAG_FILE_TYPE) { tagType != LOCATE_TAG_FILE_TYPE) {
command_error(client, ACK_ERROR_ARG, "\"%s\" is not known", argv[1]); command_error(client, ACK_ERROR_ARG,
"Unknown tag type: %s", tag_name);
return CommandResult::ERROR; return CommandResult::ERROR;
} }
SongFilter *filter; SongFilter *filter = nullptr;
if (argc == 3) {
if (args.size == 1) {
/* for compatibility with < 0.12.0 */ /* for compatibility with < 0.12.0 */
if (tagType != TAG_ALBUM) { if (tagType != TAG_ALBUM) {
command_error(client, ACK_ERROR_ARG, command_error(client, ACK_ERROR_ARG,
...@@ -197,10 +201,10 @@ handle_list(Client &client, int argc, char *argv[]) ...@@ -197,10 +201,10 @@ handle_list(Client &client, int argc, char *argv[])
return CommandResult::ERROR; return CommandResult::ERROR;
} }
filter = new SongFilter((unsigned)TAG_ARTIST, argv[2]); filter = new SongFilter((unsigned)TAG_ARTIST, args.shift());
} else if (argc > 2) { }
ConstBuffer<const char *> args(argv + 2, argc - 2);
if (!args.IsEmpty()) {
filter = new SongFilter(); filter = new SongFilter();
if (!filter->Parse(args, false)) { if (!filter->Parse(args, false)) {
delete filter; delete filter;
...@@ -208,8 +212,7 @@ handle_list(Client &client, int argc, char *argv[]) ...@@ -208,8 +212,7 @@ handle_list(Client &client, int argc, char *argv[])
"not able to parse args"); "not able to parse args");
return CommandResult::ERROR; return CommandResult::ERROR;
} }
} else }
filter = nullptr;
Error error; Error error;
CommandResult ret = CommandResult ret =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment