mirror of
https://github.com/tmux/tmux.git
synced 2024-12-25 02:48:47 +00:00
Sync OpenBSD patchset 479:
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.
This commit is contained in:
parent
bbdf78cd97
commit
012e7106de
25
cmd.c
25
cmd.c
@ -1,4 +1,4 @@
|
|||||||
/* $Id: cmd.c,v 1.126 2009-10-28 23:12:38 tcunha Exp $ */
|
/* $Id: cmd.c,v 1.127 2009-11-02 21:42:27 tcunha Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||||
@ -487,19 +487,25 @@ cmd_lookup_session(const char *name, int *ambiguous)
|
|||||||
*ambiguous = 0;
|
*ambiguous = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look for matches. Session names must be unique so an exact match
|
* Look for matches. First look for exact matches - session names must
|
||||||
* can't be ambigious and can just be returned.
|
* be unique so an exact match can't be ambigious and can just be
|
||||||
|
* returned.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||||
|
if ((s = ARRAY_ITEM(&sessions, i)) == NULL)
|
||||||
|
continue;
|
||||||
|
if (strcmp(name, s->name) == 0)
|
||||||
|
return (s);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Otherwise look for partial matches, returning early if it is found to
|
||||||
|
* be ambiguous.
|
||||||
*/
|
*/
|
||||||
sfound = NULL;
|
sfound = NULL;
|
||||||
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
|
||||||
if ((s = ARRAY_ITEM(&sessions, i)) == NULL)
|
if ((s = ARRAY_ITEM(&sessions, i)) == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Check for an exact match and return it if found. */
|
|
||||||
if (strcmp(name, s->name) == 0)
|
|
||||||
return (s);
|
|
||||||
|
|
||||||
/* Then check for pattern matches. */
|
|
||||||
if (strncmp(name, s->name, strlen(name)) == 0 ||
|
if (strncmp(name, s->name, strlen(name)) == 0 ||
|
||||||
fnmatch(name, s->name, 0) == 0) {
|
fnmatch(name, s->name, 0) == 0) {
|
||||||
if (sfound != NULL) {
|
if (sfound != NULL) {
|
||||||
@ -509,7 +515,6 @@ cmd_lookup_session(const char *name, int *ambiguous)
|
|||||||
sfound = s;
|
sfound = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (sfound);
|
return (sfound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user