1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Remove unneeded functions from cmd headers

This commit is contained in:
James Booth 2016-05-23 00:39:36 +01:00
parent eb105e9172
commit d0117cdabe
4 changed files with 168 additions and 167 deletions

View File

@ -105,6 +105,8 @@
GHashTable *commands = NULL; GHashTable *commands = NULL;
static gboolean _cmd_has_tag(Command *pcmd, const char *const tag);
/* /*
* Command list * Command list
*/ */
@ -2226,19 +2228,6 @@ cmd_valid_tag(const char *const str)
(g_strcmp0(str, CMD_TAG_PLUGINS) == 0)); (g_strcmp0(str, CMD_TAG_PLUGINS) == 0));
} }
gboolean
cmd_has_tag(Command *pcmd, const char *const tag)
{
int i = 0;
for (i = 0; pcmd->help.tags[i] != NULL; i++) {
if (g_strcmp0(tag, pcmd->help.tags[i]) == 0) {
return TRUE;
}
}
return FALSE;
}
Command* Command*
cmd_get(const char *const command) cmd_get(const char *const command)
{ {
@ -2262,7 +2251,7 @@ cmd_get_ordered(const char *const tag)
while (g_hash_table_iter_next(&iter, &key, &value)) { while (g_hash_table_iter_next(&iter, &key, &value)) {
Command *pcmd = (Command *)value; Command *pcmd = (Command *)value;
if (tag) { if (tag) {
if (cmd_has_tag(pcmd, tag)) { if (_cmd_has_tag(pcmd, tag)) {
ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0); ordered_commands = g_list_insert_sorted(ordered_commands, pcmd->cmd, (GCompareFunc)g_strcmp0);
} }
} else { } else {
@ -2273,6 +2262,19 @@ cmd_get_ordered(const char *const tag)
return ordered_commands; return ordered_commands;
} }
static gboolean
_cmd_has_tag(Command *pcmd, const char *const tag)
{
int i = 0;
for (i = 0; pcmd->help.tags[i] != NULL; i++) {
if (g_strcmp0(tag, pcmd->help.tags[i]) == 0) {
return TRUE;
}
}
return FALSE;
}
static int static int
_cmp_command(Command *cmd1, Command *cmd2) _cmp_command(Command *cmd1, Command *cmd2)
{ {

View File

@ -46,7 +46,6 @@ Command* cmd_get(const char *const command);
GList* cmd_get_ordered(const char *const tag); GList* cmd_get_ordered(const char *const tag);
gboolean cmd_valid_tag(const char *const str); gboolean cmd_valid_tag(const char *const str);
gboolean cmd_has_tag(Command *pcmd, const char *const tag);
void command_docgen(void); void command_docgen(void);

View File

@ -92,6 +92,7 @@ static void _cmd_set_boolean_preference(gchar *arg, const char *const command,
static void _who_room(ProfWin *window, const char *const command, gchar **args); static void _who_room(ProfWin *window, const char *const command, gchar **args);
static void _who_roster(ProfWin *window, const char *const command, gchar **args); static void _who_roster(ProfWin *window, const char *const command, gchar **args);
static gboolean _cmd_execute(ProfWin *window, const char *const command, const char *const inp); static gboolean _cmd_execute(ProfWin *window, const char *const command, const char *const inp);
static gboolean _cmd_execute_default(ProfWin *window, const char *inp);
static gboolean _cmd_execute_alias(ProfWin *window, const char *const inp, gboolean *ran); static gboolean _cmd_execute_alias(ProfWin *window, const char *const inp, gboolean *ran);
/* /*
@ -128,7 +129,7 @@ cmd_process_input(ProfWin *window, char *inp)
// call a default handler if input didn't start with '/' // call a default handler if input didn't start with '/'
} else { } else {
result = cmd_execute_default(window, inp); result = _cmd_execute_default(window, inp);
} }
return result; return result;
@ -145,156 +146,6 @@ cmd_execute_connect(ProfWin *window, const char *const account)
g_string_free(command, TRUE); g_string_free(command, TRUE);
} }
static gboolean
_cmd_execute(ProfWin *window, const char *const command, const char *const inp)
{
if (g_str_has_prefix(command, "/field") && window->type == WIN_MUC_CONFIG) {
gboolean result = FALSE;
gchar **args = parse_args_with_freetext(inp, 1, 2, &result);
if (!result) {
ui_current_print_formatted_line('!', 0, "Invalid command, see /form help");
result = TRUE;
} else {
gchar **tokens = g_strsplit(inp, " ", 2);
char *field = tokens[0] + 1;
result = cmd_form_field(window, field, args);
g_strfreev(tokens);
}
g_strfreev(args);
return result;
}
Command *cmd = cmd_get(command);
gboolean result = FALSE;
if (cmd) {
gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
if (result == FALSE) {
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
return TRUE;
}
if (args[0] && cmd->sub_funcs[0][0]) {
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);
g_strfreev(args);
return result;
}
i++;
}
}
if (!cmd->func) {
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
return TRUE;
}
gboolean result = cmd->func(window, command, args);
g_strfreev(args);
return result;
} else if (plugins_run_command(inp)) {
return TRUE;
} else {
gboolean ran_alias = FALSE;
gboolean alias_result = _cmd_execute_alias(window, inp, &ran_alias);
if (!ran_alias) {
return cmd_execute_default(window, inp);
} else {
return alias_result;
}
}
}
gboolean
cmd_execute_default(ProfWin *window, const char *inp)
{
// handle escaped commands - treat as normal message
if (g_str_has_prefix(inp, "//")) {
inp++;
// handle unknown commands
} else if ((inp[0] == '/') && (!g_str_has_prefix(inp, "/me "))) {
cons_show("Unknown command: %s", inp);
cons_alert();
return TRUE;
}
// handle non commands in non chat or plugin windows
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE && window->type != WIN_PLUGIN && window->type != WIN_XML) {
cons_show("Unknown command: %s", inp);
return TRUE;
}
// handle plugin window
if (window->type == WIN_PLUGIN) {
ProfPluginWin *pluginwin = (ProfPluginWin*)window;
plugins_win_process_line(pluginwin->tag, inp);
return TRUE;
}
jabber_conn_status_t status = connection_get_status();
if (status != JABBER_CONNECTED) {
ui_current_print_line("You are not currently connected.");
return TRUE;
}
switch (window->type) {
case WIN_CHAT:
{
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
cl_ev_send_msg(chatwin, inp, NULL);
break;
}
case WIN_PRIVATE:
{
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
cl_ev_send_priv_msg(privatewin, inp, NULL);
break;
}
case WIN_MUC:
{
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
cl_ev_send_muc_msg(mucwin, inp, NULL);
break;
}
case WIN_XML:
{
connection_send_stanza(inp);
break;
}
default:
break;
}
return TRUE;
}
static gboolean
_cmd_execute_alias(ProfWin *window, const char *const inp, gboolean *ran)
{
if (inp[0] != '/') {
ran = FALSE;
return TRUE;
}
char *alias = strdup(inp+1);
char *value = prefs_get_alias(alias);
free(alias);
if (value) {
*ran = TRUE;
gboolean result = cmd_process_input(window, value);
prefs_free_string(value);
return result;
}
*ran = FALSE;
return TRUE;
}
gboolean gboolean
cmd_tls_certpath(ProfWin *window, const char *const command, gchar **args) cmd_tls_certpath(ProfWin *window, const char *const command, gchar **args)
{ {
@ -6899,6 +6750,156 @@ cmd_encwarn(ProfWin *window, const char *const command, gchar **args)
return TRUE; return TRUE;
} }
static gboolean
_cmd_execute(ProfWin *window, const char *const command, const char *const inp)
{
if (g_str_has_prefix(command, "/field") && window->type == WIN_MUC_CONFIG) {
gboolean result = FALSE;
gchar **args = parse_args_with_freetext(inp, 1, 2, &result);
if (!result) {
ui_current_print_formatted_line('!', 0, "Invalid command, see /form help");
result = TRUE;
} else {
gchar **tokens = g_strsplit(inp, " ", 2);
char *field = tokens[0] + 1;
result = cmd_form_field(window, field, args);
g_strfreev(tokens);
}
g_strfreev(args);
return result;
}
Command *cmd = cmd_get(command);
gboolean result = FALSE;
if (cmd) {
gchar **args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
if (result == FALSE) {
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
return TRUE;
}
if (args[0] && cmd->sub_funcs[0][0]) {
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);
g_strfreev(args);
return result;
}
i++;
}
}
if (!cmd->func) {
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
return TRUE;
}
gboolean result = cmd->func(window, command, args);
g_strfreev(args);
return result;
} else if (plugins_run_command(inp)) {
return TRUE;
} else {
gboolean ran_alias = FALSE;
gboolean alias_result = _cmd_execute_alias(window, inp, &ran_alias);
if (!ran_alias) {
return _cmd_execute_default(window, inp);
} else {
return alias_result;
}
}
}
static gboolean
_cmd_execute_default(ProfWin *window, const char *inp)
{
// handle escaped commands - treat as normal message
if (g_str_has_prefix(inp, "//")) {
inp++;
// handle unknown commands
} else if ((inp[0] == '/') && (!g_str_has_prefix(inp, "/me "))) {
cons_show("Unknown command: %s", inp);
cons_alert();
return TRUE;
}
// handle non commands in non chat or plugin windows
if (window->type != WIN_CHAT && window->type != WIN_MUC && window->type != WIN_PRIVATE && window->type != WIN_PLUGIN && window->type != WIN_XML) {
cons_show("Unknown command: %s", inp);
return TRUE;
}
// handle plugin window
if (window->type == WIN_PLUGIN) {
ProfPluginWin *pluginwin = (ProfPluginWin*)window;
plugins_win_process_line(pluginwin->tag, inp);
return TRUE;
}
jabber_conn_status_t status = connection_get_status();
if (status != JABBER_CONNECTED) {
ui_current_print_line("You are not currently connected.");
return TRUE;
}
switch (window->type) {
case WIN_CHAT:
{
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
cl_ev_send_msg(chatwin, inp, NULL);
break;
}
case WIN_PRIVATE:
{
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
cl_ev_send_priv_msg(privatewin, inp, NULL);
break;
}
case WIN_MUC:
{
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
cl_ev_send_muc_msg(mucwin, inp, NULL);
break;
}
case WIN_XML:
{
connection_send_stanza(inp);
break;
}
default:
break;
}
return TRUE;
}
static gboolean
_cmd_execute_alias(ProfWin *window, const char *const inp, gboolean *ran)
{
if (inp[0] != '/') {
ran = FALSE;
return TRUE;
}
char *alias = strdup(inp+1);
char *value = prefs_get_alias(alias);
free(alias);
if (value) {
*ran = TRUE;
gboolean result = cmd_process_input(window, value);
prefs_free_string(value);
return result;
}
*ran = FALSE;
return TRUE;
}
// helper function for status change commands // helper function for status change commands
static void static void
_update_presence(const resource_presence_t resource_presence, _update_presence(const resource_presence_t resource_presence,

View File

@ -72,7 +72,6 @@ typedef struct cmd_t {
gboolean cmd_process_input(ProfWin *window, char *inp); gboolean cmd_process_input(ProfWin *window, char *inp);
void cmd_execute_connect(ProfWin *window, const char *const account); void cmd_execute_connect(ProfWin *window, const char *const account);
gboolean cmd_execute_default(ProfWin *window, const char *inp);
gboolean cmd_about(ProfWin *window, const char *const command, gchar **args); gboolean cmd_about(ProfWin *window, const char *const command, gchar **args);
gboolean cmd_autoaway(ProfWin *window, const char *const command, gchar **args); gboolean cmd_autoaway(ProfWin *window, const char *const command, gchar **args);