1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-16 21:35:24 +00:00

slightly improve command_defs[]

* make the struct `const`
* use designated initializers
* remove `CMD_NOxyz` macros
* fix function-pointer correctness of `sub_func[]`

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2022-12-20 09:29:36 +01:00
parent e9aaba938b
commit a45f05a45e
5 changed files with 272 additions and 461 deletions

View File

@ -1315,7 +1315,7 @@ cmd_ac_add_help(const char* const value)
}
void
cmd_ac_add_cmd(Command* command)
cmd_ac_add_cmd(const Command* command)
{
autocomplete_add(commands_ac, command->cmd);
autocomplete_add(help_ac, command->cmd + 1);

View File

@ -47,7 +47,7 @@ gboolean cmd_ac_exists(char* cmd);
void cmd_ac_add(const char* const value);
void cmd_ac_add_help(const char* const value);
void cmd_ac_add_cmd(Command* command);
void cmd_ac_add_cmd(const Command* command);
void cmd_ac_add_alias(ProfAlias* alias);
void cmd_ac_add_alias_value(char* value);

File diff suppressed because it is too large Load Diff

View File

@ -8430,12 +8430,11 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
return TRUE;
}
if (args[0] && cmd->sub_funcs[0][0]) {
if (args[0] && cmd->sub_funcs[0].cmd) {
int i = 0;
while (cmd->sub_funcs[i][0]) {
if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i][0]) == 0) {
gboolean (*func)(ProfWin * window, const char* const command, gchar** args) = cmd->sub_funcs[i][1];
gboolean result = func(window, command, args);
while (cmd->sub_funcs[i].cmd) {
if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i].cmd) == 0) {
gboolean result = cmd->sub_funcs[i].func(window, command, args);
g_strfreev(args);
return result;
}

View File

@ -68,7 +68,11 @@ typedef struct cmd_t
int min_args;
int max_args;
void (*setting_func)(void);
void* sub_funcs[50][2];
struct
{
const char* cmd;
gboolean (*func)(ProfWin* window, const char* const command, gchar** args);
} sub_funcs[50];
gboolean (*func)(ProfWin* window, const char* const command, gchar** args);
CommandHelp help;
} Command;