Reshuffle and slightly simplify menu_complete_path(), removing an
allocation, for tab-completion; checked by Alexander Polakov as well.
This commit is contained in:
parent
f345dc8f9a
commit
d42a248920
@ -16,7 +16,7 @@
|
|||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*
|
*
|
||||||
* $OpenBSD: menu.c,v 1.78 2015/01/19 14:54:16 okan Exp $
|
* $OpenBSD: menu.c,v 1.79 2015/03/28 22:09:10 okan Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -189,9 +189,7 @@ menu_complete_path(struct menu_ctx *mc)
|
|||||||
{
|
{
|
||||||
struct menu *mi, *mr;
|
struct menu *mi, *mr;
|
||||||
struct menu_q menuq;
|
struct menu_q menuq;
|
||||||
char *path = NULL;
|
|
||||||
|
|
||||||
path = xcalloc(1, sizeof(mr->text));
|
|
||||||
mr = xcalloc(1, sizeof(*mr));
|
mr = xcalloc(1, sizeof(*mr));
|
||||||
|
|
||||||
TAILQ_INIT(&menuq);
|
TAILQ_INIT(&menuq);
|
||||||
@ -200,17 +198,15 @@ menu_complete_path(struct menu_ctx *mc)
|
|||||||
CWM_MENU_DUMMY, search_match_path_any, NULL)) != NULL) {
|
CWM_MENU_DUMMY, search_match_path_any, NULL)) != NULL) {
|
||||||
mr->abort = mi->abort;
|
mr->abort = mi->abort;
|
||||||
mr->dummy = mi->dummy;
|
mr->dummy = mi->dummy;
|
||||||
strlcpy(path, mi->text, sizeof(mi->text));
|
if (mi->text[0] != '\0')
|
||||||
|
snprintf(mr->text, sizeof(mr->text), "%s \"%s\"",
|
||||||
|
mc->searchstr, mi->text);
|
||||||
|
else if (!mr->abort)
|
||||||
|
strlcpy(mr->text, mc->searchstr, sizeof(mr->text));
|
||||||
}
|
}
|
||||||
|
|
||||||
menuq_clear(&menuq);
|
menuq_clear(&menuq);
|
||||||
|
|
||||||
if (path[0] != '\0')
|
|
||||||
snprintf(mr->text, sizeof(mr->text), "%s \"%s\"",
|
|
||||||
mc->searchstr, path);
|
|
||||||
else if (!mr->abort)
|
|
||||||
strlcpy(mr->text, mc->searchstr, sizeof(mr->text));
|
|
||||||
free(path);
|
|
||||||
return(mr);
|
return(mr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user