On Tue, Nov 11, 2014 at 18:13:53 +0000, Rory McNamara wrote: > I've probably used format-patch wrong, but there are three commits there. The > new bit is at the bottom. > I've rebased, and the whole patch is now attached.
Ah, I see now, sorry about that. Easier to see the changes now anyways. Comments inline. --Ben > From 4d9b77a0443d49da4fc35a9c2543af9465d2e3ac 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] added least unambiguous to find_command > > added least unambiguous info to manpage > > disallow overlength but matching commands > --- > doc/mpc.1 | 1 + > src/main.c | 12 +++++++++++- > 2 files changed, 12 insertions(+), 1 deletion(-) > > 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. > diff --git a/src/main.c b/src/main.c > index 7c30ff6..91b4e86 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); This loop is excessive. Why not just do a single loop over all the commands with len = strlen(name) since there's a restriction below? In fact, a single loop with a local struct command * which saves any matches and then do: return (matches == 1) ? cmd : NULL; > + 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 && > 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