Hide struct args behind a couple of accessor functions.

This commit is contained in:
nicm
2021-08-20 19:50:16 +00:00
parent de94a344f6
commit 5f32b7d961
41 changed files with 355 additions and 306 deletions

View File

@ -150,7 +150,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = cmd_get_args(self);
struct key_table *table;
struct key_binding *bd;
const char *tablename, *r;
const char *tablename, *r, *keystr;
char *key, *cp, *tmp, *start, *empty;
key_code prefix, only = KEYC_UNKNOWN;
int repeat, width, tablewidth, keywidth, found = 0;
@ -159,10 +159,10 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
if (cmd_get_entry(self) == &cmd_list_commands_entry)
return (cmd_list_keys_commands(self, item));
if (args->argc != 0) {
only = key_string_lookup_string(args->argv[0]);
if ((keystr = args_string(args, 0)) != NULL) {
only = key_string_lookup_string(keystr);
if (only == KEYC_UNKNOWN) {
cmdq_error(item, "invalid key: %s", args->argv[0]);
cmdq_error(item, "invalid key: %s", keystr);
return (CMD_RETURN_ERROR);
}
only &= (KEYC_MASK_KEY|KEYC_MASK_MODIFIERS);
@ -243,6 +243,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
tmpsize = 256;
tmp = xmalloc(tmpsize);
table = key_bindings_first_table();
while (table != NULL) {
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
@ -307,7 +308,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
out:
if (only != KEYC_UNKNOWN && !found) {
cmdq_error(item, "unknown key: %s", args->argv[0]);
cmdq_error(item, "unknown key: %s", args_string(args, 0));
return (CMD_RETURN_ERROR);
}
return (CMD_RETURN_NORMAL);
@ -320,12 +321,9 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
const struct cmd_entry **entryp;
const struct cmd_entry *entry;
struct format_tree *ft;
const char *template, *s, *command = NULL;
const char *template, *s, *command;
char *line;
if (args->argc != 0)
command = args->argv[0];
if ((template = args_get(args, 'F')) == NULL) {
template = "#{command_list_name}"
"#{?command_list_alias, (#{command_list_alias}),} "
@ -335,6 +333,7 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
format_defaults(ft, NULL, NULL, NULL, NULL);
command = args_string(args, 0);
for (entryp = cmd_table; *entryp != NULL; entryp++) {
entry = *entryp;
if (command != NULL &&