summaryrefslogtreecommitdiffstats
path: root/cmd.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-11-02 16:24:29 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-11-02 16:24:29 +0000
commit1c853c68602cf713fe3de98ae2ea5a48a1120abc (patch)
treecd2082dde92d37f51ea842e556970491ccb51ce9 /cmd.c
parent2a585dc4ed3ad605487d00148b906325ff915a5c (diff)
When matching the session names with -t, look for exact matches first before
trying partial matches. Avoids problems where two ambiguous matches are present before an exact match (eg foo1, foo2, foo would give an error on trying -tfoo), reported by Natacha Port? natbsd at instinctive dot eu.
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/cmd.c b/cmd.c
index 96a06b6c..7ce88f47 100644
--- a/cmd.c
+++ b/cmd.c
@@ -488,19 +488,25 @@ cmd_lookup_session(const char *name, int *ambiguous)
*ambiguous = 0;
/*
- * Look for matches. Session names must be unique so an exact match
- * can't be ambigious and can just be returned.
+ * Look for matches. First look for exact matches - session names must
+ * be unique so an exact match can't be ambigious and can just be
+ * returned.
*/
- sfound = NULL;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
if ((s = ARRAY_ITEM(&sessions, i)) == NULL)
continue;
-
- /* Check for an exact match and return it if found. */
if (strcmp(name, s->name) == 0)
return (s);
-
- /* Then check for pattern matches. */
+ }
+
+ /*
+ * Otherwise look for partial matches, returning early if it is found to
+ * be ambiguous.
+ */
+ sfound = NULL;
+ for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
+ if ((s = ARRAY_ITEM(&sessions, i)) == NULL)
+ continue;
if (strncmp(name, s->name, strlen(name)) == 0 ||
fnmatch(name, s->name, 0) == 0) {
if (sfound != NULL) {
@@ -510,7 +516,6 @@ cmd_lookup_session(const char *name, int *ambiguous)
sfound = s;
}
}
-
return (sfound);
}