mirror of
https://github.com/tmux/tmux.git
synced 2026-04-16 03:56:28 +00:00
Do not leak command in list-keys, reported by tb@. Also tidy up some
function names while here.
This commit is contained in:
@@ -93,7 +93,7 @@ cmd_list_keys_get_table_width(struct key_binding **l, u_int n)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct key_binding **
|
static struct key_binding **
|
||||||
cmd_get_root_and_prefix(u_int *n, struct sort_criteria *sort_crit)
|
cmd_list_keys_get_root_and_prefix(u_int *n, struct sort_criteria *sort_crit)
|
||||||
{
|
{
|
||||||
const char *tables[] = { "prefix", "root" };
|
const char *tables[] = { "prefix", "root" };
|
||||||
struct key_table *t;
|
struct key_table *t;
|
||||||
@@ -119,7 +119,7 @@ cmd_get_root_and_prefix(u_int *n, struct sort_criteria *sort_crit)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cmd_filter_key_list(int filter_notes, int filter_key, key_code only,
|
cmd_list_keys_filter_key_list(int filter_notes, int filter_key, key_code only,
|
||||||
struct key_binding **l, u_int *n)
|
struct key_binding **l, u_int *n)
|
||||||
{
|
{
|
||||||
key_code key;
|
key_code key;
|
||||||
@@ -137,10 +137,10 @@ cmd_filter_key_list(int filter_notes, int filter_key, key_code only,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cmd_format_add_key_binding(struct format_tree *ft,
|
cmd_list_keys_format_add_key_binding(struct format_tree *ft,
|
||||||
const struct key_binding *bd, const char *prefix)
|
const struct key_binding *bd, const char *prefix)
|
||||||
{
|
{
|
||||||
const char *s;
|
char *s;
|
||||||
|
|
||||||
if (bd->flags & KEY_BINDING_REPEAT)
|
if (bd->flags & KEY_BINDING_REPEAT)
|
||||||
format_add(ft, "key_repeat", "1");
|
format_add(ft, "key_repeat", "1");
|
||||||
@@ -155,12 +155,12 @@ cmd_format_add_key_binding(struct format_tree *ft,
|
|||||||
format_add(ft, "key_prefix", "%s", prefix);
|
format_add(ft, "key_prefix", "%s", prefix);
|
||||||
format_add(ft, "key_table", "%s", bd->tablename);
|
format_add(ft, "key_table", "%s", bd->tablename);
|
||||||
|
|
||||||
s = key_string_lookup_key(bd->key, 0);
|
format_add(ft, "key_string", "%s", key_string_lookup_key(bd->key, 0));
|
||||||
format_add(ft, "key_string", "%s", s);
|
|
||||||
|
|
||||||
s = cmd_list_print(bd->cmdlist,
|
s = cmd_list_print(bd->cmdlist, CMD_LIST_PRINT_ESCAPED|
|
||||||
CMD_LIST_PRINT_ESCAPED|CMD_LIST_PRINT_NO_GROUPS);
|
CMD_LIST_PRINT_NO_GROUPS);
|
||||||
format_add(ft, "key_command", "%s", s);
|
format_add(ft, "key_command", "%s", s);
|
||||||
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum cmd_retval
|
static enum cmd_retval
|
||||||
@@ -213,14 +213,16 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (table)
|
if (table)
|
||||||
l = sort_get_key_bindings_table(table, &n, &sort_crit);
|
l = sort_get_key_bindings_table(table, &n, &sort_crit);
|
||||||
else if (notes_only)
|
else if (notes_only)
|
||||||
l = cmd_get_root_and_prefix(&n, &sort_crit);
|
l = cmd_list_keys_get_root_and_prefix(&n, &sort_crit);
|
||||||
else
|
else
|
||||||
l = sort_get_key_bindings(&n, &sort_crit);
|
l = sort_get_key_bindings(&n, &sort_crit);
|
||||||
|
|
||||||
filter_notes = notes_only && !args_has(args, 'a');
|
filter_notes = notes_only && !args_has(args, 'a');
|
||||||
filter_key = only != KEYC_UNKNOWN;
|
filter_key = only != KEYC_UNKNOWN;
|
||||||
if (filter_notes || filter_key)
|
if (filter_notes || filter_key) {
|
||||||
cmd_filter_key_list(filter_notes, filter_key, only, l, &n);
|
cmd_list_keys_filter_key_list(filter_notes, filter_key, only, l,
|
||||||
|
&n);
|
||||||
|
}
|
||||||
if (single)
|
if (single)
|
||||||
n = 1;
|
n = 1;
|
||||||
|
|
||||||
@@ -232,7 +234,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
format_add(ft, "key_table_width", "%u",
|
format_add(ft, "key_table_width", "%u",
|
||||||
cmd_list_keys_get_table_width(l, n));
|
cmd_list_keys_get_table_width(l, n));
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
cmd_format_add_key_binding(ft, l[i], prefix);
|
cmd_list_keys_format_add_key_binding(ft, l[i], prefix);
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
line = format_expand(ft, template);
|
||||||
if ((single && tc != NULL) || n == 1)
|
if ((single && tc != NULL) || n == 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user