You are correct. I've added another strncmp which seems to fix this. New patch attached.
I apologise if I reply to this incorrectly. Rory On 11 November 2014 16:53, Ben Boeckel <maths...@gmail.com> wrote: > On Tue, Nov 11, 2014 at 16:15:55 +0000, Rory McNamara wrote: > > Hi, I've written a patch to allow you to run a command based on the least > > unambiguous portion of the command name. For example, prev can be called > with > > pr, pre or prev, but not p becuase of play and playlist. > > > > The patch is attached. > > From the code, it looks like "precious" would also trigger "prev" (via > "pre") since it tries common prefixes *first*. I think it should always > do `strncmp(name, cmd, strlen(name))` to avoid such issues. > > --Ben >
From 96eba0ce0bfdb9051fd81617f5d231fd0fbeecbf Mon Sep 17 00:00:00 2001 From: PsychoMario <pink.banana.f...@gmail.com> Date: Tue, 11 Nov 2014 13:05:15 +0000 Subject: [PATCH 1/3] added least unambiguous to find_command --- src/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 7c30ff6..fb87cbe 100644 --- a/src/main.c +++ b/src/main.c @@ -214,8 +214,18 @@ setup_connection(void) static struct command * find_command(const char *name) { + int matches, len = 0; + do { + matches = 0; + len += 1; + for (unsigned i = 0; mpc_table[i].command != NULL; ++i) + if (strncmp(name, mpc_table[i].command, len) == 0) + matches += 1; + } while (matches > 1); + if (matches == 0) + return NULL; for (unsigned i = 0; mpc_table[i].command != NULL; ++i) - if (strcmp(name, mpc_table[i].command) == 0) + if (strncmp(name, mpc_table[i].command, len) == 0) return &mpc_table[i]; return NULL; -- 2.1.2 From 4c80442f71c2c99e7eb4d281d4e62a4d900c9cfc Mon Sep 17 00:00:00 2001 From: PsychoMario <pink.banana.f...@gmail.com> Date: Tue, 11 Nov 2014 14:15:40 +0000 Subject: [PATCH 2/3] added least unambiguous info to manpage --- doc/mpc.1 | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/mpc.1 b/doc/mpc.1 index 2bea9a6..b119c81 100644 --- a/doc/mpc.1 +++ b/doc/mpc.1 @@ -96,6 +96,7 @@ If you specify an absolute path, mpc attempts a connection via Unix Domain Socke The port to connect to; if not given, the value of the environment variable MPD_PORT is checked before defaulting to 6600. This default can be changed at compile-time. .br .SH COMMANDS +Commands can be used from the least unambiguous prefix (e.g insert or ins) .TP .B add <file> Adds a song from the music database to the playlist. Can also read input from pipes. Use "mpc ls | mpc add" to add all files to the playlist. -- 2.1.2 From 1045dba56cb1bebdb681aaaf75be2e2e5bcb4923 Mon Sep 17 00:00:00 2001 From: PsychoMario <pink.banana.f...@gmail.com> Date: Tue, 11 Nov 2014 17:02:17 +0000 Subject: [PATCH 3/3] disallow overlength but matching commands --- src/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index fb87cbe..91b4e86 100644 --- a/src/main.c +++ b/src/main.c @@ -225,7 +225,7 @@ find_command(const char *name) if (matches == 0) return NULL; for (unsigned i = 0; mpc_table[i].command != NULL; ++i) - if (strncmp(name, mpc_table[i].command, len) == 0) + if (strncmp(name, mpc_table[i].command, len) == 0 && strncmp(name, mpc_table[i].command, strlen(name)) == 0) return &mpc_table[i]; return NULL; -- 2.1.2
_______________________________________________ mpd-devel mailing list mpd-devel@musicpd.org http://mailman.blarg.de/listinfo/mpd-devel