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:
parent
e089ffb15c
commit
66631308a5
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user