diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command/command.c | 10 | ||||
-rw-r--r-- | src/command/command.h | 2 | ||||
-rw-r--r-- | src/command/commands.c | 23 | ||||
-rw-r--r-- | src/tools/autocomplete.c | 15 | ||||
-rw-r--r-- | src/tools/autocomplete.h | 2 |
5 files changed, 42 insertions, 10 deletions
diff --git a/src/command/command.c b/src/command/command.c index 68c2c6dc..2393a734 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1120,6 +1120,16 @@ cmd_uninit(void) autocomplete_free(aliases_ac); } +gboolean +cmd_exists(char *cmd) +{ + if (commands_ac == NULL) { + return FALSE; + } else { + return autocomplete_contains(commands_ac, cmd); + } +} + void cmd_autocomplete_add(char *value) { diff --git a/src/command/command.h b/src/command/command.h index 046fda64..9e67d928 100644 --- a/src/command/command.h +++ b/src/command/command.h @@ -41,6 +41,8 @@ gboolean cmd_execute(const char * const command, const char * const inp); gboolean cmd_execute_alias(const char * const inp, gboolean *ran); gboolean cmd_execute_default(const char * const inp); +gboolean cmd_exists(char *cmd); + GSList * cmd_get_basic_help(void); GSList * cmd_get_settings_help(void); GSList * cmd_get_presence_help(void); diff --git a/src/command/commands.c b/src/command/commands.c index 76f85210..b282f525 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -1830,21 +1830,24 @@ cmd_alias(gchar **args, struct cmd_help_t help) cons_show("Usage: %s", help.usage); return TRUE; } else { + GString *ac_value = g_string_new("/"); + g_string_append(ac_value, alias); + char *value = args[2]; if (value == NULL) { cons_show("Usage: %s", help.usage); + g_string_free(ac_value, TRUE); + return TRUE; + } else if (cmd_exists(ac_value->str)) { + cons_show("Command or alias '%s' already exists."); + g_string_free(ac_value, TRUE); return TRUE; } else { - if (prefs_add_alias(alias, value) == TRUE) { - GString *ac_value = g_string_new("/"); - g_string_append(ac_value, alias); - cmd_autocomplete_add(ac_value->str); - cmd_alias_add(alias); - g_string_free(ac_value, TRUE); - cons_show("Command alias added /%s -> %s", alias, value); - } else { - cons_show("Command alias /%s already exists.", alias); - } + prefs_add_alias(alias, value); + cmd_autocomplete_add(ac_value->str); + cmd_alias_add(alias); + cons_show("Command alias added /%s -> %s", alias, value); + g_string_free(ac_value, TRUE); return TRUE; } } diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index ee8b5437..4981b690 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -132,6 +132,21 @@ autocomplete_get_list(Autocomplete ac) return copy; } +gboolean +autocomplete_contains(Autocomplete ac, char *value) +{ + GSList *curr = ac->items; + + while(curr) { + if (strcmp(curr->data, value) == 0) { + return TRUE; + } + curr = g_slist_next(curr); + } + + return FALSE; +} + gchar * autocomplete_complete(Autocomplete ac, gchar *search_str) { diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index 0a3b5b88..fadd6e88 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -56,4 +56,6 @@ char * autocomplete_param_no_with_func(char *input, int *size, char *command, int arg_number, autocomplete_func func); void autocomplete_reset(Autocomplete ac); + +gboolean autocomplete_contains(Autocomplete ac, char *value); #endif |