diff --git a/src/commands.c b/src/commands.c index 03baf866f4a48fac22a5241007d86fcf7f08d79c..69bbec25cae7fdb3e181f1920cfcf17c7c5fc6b2 100644 --- a/src/commands.c +++ b/src/commands.c @@ -884,10 +884,9 @@ command_shuffle(sqlite3 *db, enum mpd_idle_flag *watch_mask_ptr) bool command_queue_list(struct lkt_state *srv, size_t c, char *args[LKT_MESSAGE_ARGS_MAX]) { - unsigned int count, from, to, tmp_switch; + unsigned int from, to, tmp_switch; long val; char *endptr, *str; - struct lkt_queue_state state; struct lkt_callback callback = { .call = lkt_callback_send_row_v1, .srv = srv, @@ -915,16 +914,15 @@ command_queue_list(struct lkt_state *srv, size_t c, char *args[LKT_MESSAGE_ARGS_ return false; } - if (*endptr == '\0') { - /* There is nothing after, is is the relative forme of the command. */ - count = labs(val); - goto is_relative; - } + from = labs(val); + + /* There is nothing after, is is the song pos version. */ + if (*endptr == '\0') + goto only_one; + /* There is something after, this is the absolute forme of the command. Then + parse the second value. Skip the supposed ':' character. */ else { - /* There is something after, this is the absolute forme of the command. Then - parse the second value. Skip the supposed ':' character. */ - from = labs(val); str = endptr + strspn(endptr, "-+: "); // NO NEGATIVE! // val = strtol(str, &endptr, 0); @@ -948,37 +946,25 @@ command_queue_list(struct lkt_state *srv, size_t c, char *args[LKT_MESSAGE_ARGS_ from = tmp_switch; } - goto is_absolute; + goto is_a_range; } return false; /* The command is used in its relative forme, display elements from the current one. */ -is_relative: - if (!database_queue_state(srv->db, &state)) { - fprintf(stderr, " . command_queue_list: Could not get current position in queue\n"); - return false; - } - - if (count < lkt_remaining_msg(srv, c) - 1) { - lkt_set_continuation(srv, c, 0); - return database_queue_list(srv->db, state.current, state.current + count, &callback); - } else { - count = lkt_remaining_msg(srv, c) - 2; /* One for `continue: i` and one for OK/ACK. */ - lkt_set_continuation(srv, c, state.current + count); - return database_queue_list(srv->db, state.current, state.current + count, &callback); - } +only_one: + return database_queue_list(srv->db, from, from, &callback); /* The command is used with a range specifier. */ -is_absolute: +is_a_range: if (to - from < lkt_remaining_msg(srv, c) - 1) { lkt_set_continuation(srv, c, 0); return database_queue_list(srv->db, from, to, &callback); } else { - count = lkt_remaining_msg(srv, c) - 2 + from; - lkt_set_continuation(srv, c, count); - return database_queue_list(srv->db, from, count, &callback); + to = from + lkt_remaining_msg(srv, c) - 2; + lkt_set_continuation(srv, c, to + 1); + return database_queue_list(srv->db, from, to, &callback); } } diff --git a/src/main/lkt.c b/src/main/lkt.c index 834aa48311818e785cfbc4133b37aed220fef297..db26aea6ff0eec94ead577d82f76a00d1f8b88ae 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -598,6 +598,7 @@ list__(struct lkt_cmd_args *args) FILE *sock = NULL; redo: + printf("%ld:%ld\n", continuation, up); sock = lkt_connect(); if (up != 0) write_socket_format(sock, "playlist %d:%d\n", continuation, up);