From 4abbe6327931b41aed4388c96615efd16877ee4c Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Fri, 10 Apr 2020 20:44:32 +0200 Subject: [PATCH] Fix lkt --- src/main/lkt.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/lkt.c b/src/main/lkt.c index 52ba9aba..0734beed 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -48,7 +48,7 @@ help(void) " status: get the status of lektor.\n" " current: get the currently playing song.\n" " add <query>: add a kara to the playlist with a query.\n" - " delete <id>: delete the id or a range of ids from the queue.\n" + " delete <arg>: delete the id or a range of ids from the queue.\n" " clear: clear the queue of lektor.\n" " prev: play previous kara in the queue.\n" " next: play the next kara in the queue.\n" @@ -486,21 +486,28 @@ delete__(struct lkt_cmd_args *args) fail("Invalid argument, need onlt one argument"); static const char *cmd_range__ = "delete %s\nclose\n"; - static const char *cmd_id__ = "deleteid %s\nclose\n"; + static const char *cmd_id__ = "deleteid %d\nclose\n"; int dumy1 = 0, dumy2 = 0;; FILE *sock = lkt_connect(); - char buff[3]; + char buff[3], dumy3; - /* Is this a range? matches only `int:` and `int:int` */ + /* Is this a range? matches only `int:int` */ sscanf(args->argv[0], "%d:%d", &dumy1, &dumy2); - if (dumy1 != 0 || dumy2 != 0) { + if (dumy1 != 0 && dumy2 != 0) { write_socket_format(sock, cmd_range__, args->argv[0]); goto check; } /* Ranges, matches `:int`. */ sscanf(args->argv[0], ":%d", &dumy1); - if (dumy1 != 0) { + if (args->argv[0][0] == ':' && dumy1 != 0) { + write_socket_format(sock, cmd_range__, args->argv[0]); + goto check; + } + + /* Ranges, matches `int:`. */ + sscanf(args->argv[0], "%d%c", &dumy1, &dumy3); + if (dumy1 != 0 && dumy3 == ':') { write_socket_format(sock, cmd_range__, args->argv[0]); goto check; } @@ -508,7 +515,7 @@ delete__(struct lkt_cmd_args *args) /* Or only an id? */ sscanf(args->argv[0], "%d", &dumy1); if (dumy1 != 0) { - write_socket_format(sock, cmd_id__, args->argv[0]); + write_socket_format(sock, cmd_id__, dumy1); goto check; } -- GitLab