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

Implemented basic running of alias commands

This commit is contained in:
James Booth 2014-01-23 23:04:00 +00:00
parent e089ffb15c
commit 66631308a5
4 changed files with 35 additions and 7 deletions

View File

@ -1205,7 +1205,33 @@ cmd_execute(const char * const command, const char * const inp)
return result; return result;
} }
} else { } else {
gboolean ran_alias = FALSE;
gboolean alias_result = cmd_execute_alias(inp, &ran_alias);
if (!ran_alias) {
return cmd_execute_default(inp); return cmd_execute_default(inp);
} else {
return alias_result;
}
}
}
gboolean
cmd_execute_alias(const char * const inp, gboolean *ran)
{
if (inp[0] != '/') {
ran = FALSE;
return TRUE;
} else {
char *alias = strdup(inp+1);
char *value = prefs_get_alias(alias);
free(alias);
if (value != NULL) {
*ran = TRUE;
return process_input(value);
} else {
*ran = FALSE;
return TRUE;
}
} }
} }

View File

@ -34,6 +34,7 @@ void cmd_autocomplete(char *input, int *size);
void cmd_reset_autocomplete(void); void cmd_reset_autocomplete(void);
gboolean cmd_execute(const char * const command, const char * const inp); 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_execute_default(const char * const inp);
GSList * cmd_get_basic_help(void); GSList * cmd_get_basic_help(void);

View File

@ -51,7 +51,6 @@
#include "ui/ui.h" #include "ui/ui.h"
#include "xmpp/xmpp.h" #include "xmpp/xmpp.h"
static gboolean _process_input(char *inp);
static void _handle_idle_time(void); static void _handle_idle_time(void);
static void _init(const int disable_tls, char *log_level); static void _init(const int disable_tls, char *log_level);
static void _shutdown(void); static void _shutdown(void);
@ -77,11 +76,11 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
if (account_name != NULL) { if (account_name != NULL) {
char *cmd = "/connect"; char *cmd = "/connect";
snprintf(inp, sizeof(inp), "%s %s", cmd, account_name); snprintf(inp, sizeof(inp), "%s %s", cmd, account_name);
_process_input(inp); process_input(inp);
} else if (prefs_get_string(PREF_CONNECT_ACCOUNT) != NULL) { } else if (prefs_get_string(PREF_CONNECT_ACCOUNT) != NULL) {
char *cmd = "/connect"; char *cmd = "/connect";
snprintf(inp, sizeof(inp), "%s %s", cmd, prefs_get_string(PREF_CONNECT_ACCOUNT)); snprintf(inp, sizeof(inp), "%s %s", cmd, prefs_get_string(PREF_CONNECT_ACCOUNT));
_process_input(inp); process_input(inp);
} }
while(cmd_result == TRUE) { while(cmd_result == TRUE) {
@ -113,7 +112,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
} }
inp[size++] = '\0'; inp[size++] = '\0';
cmd_result = _process_input(inp); cmd_result = process_input(inp);
} }
g_timer_destroy(timer); g_timer_destroy(timer);
@ -172,8 +171,8 @@ prof_handle_activity(void)
* Take a line of input and process it, return TRUE if profanity is to * Take a line of input and process it, return TRUE if profanity is to
* continue, FALSE otherwise * continue, FALSE otherwise
*/ */
static gboolean gboolean
_process_input(char *inp) process_input(char *inp)
{ {
log_debug("Input recieved: %s", inp); log_debug("Input recieved: %s", inp);
gboolean result = FALSE; gboolean result = FALSE;

View File

@ -31,4 +31,6 @@ void prof_run(const int disable_tls, char *log_level, char *account_name);
void prof_handle_idle(void); void prof_handle_idle(void);
void prof_handle_activity(void); void prof_handle_activity(void);
gboolean process_input(char *inp);
#endif #endif