mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Moved process_input to cmd_process_input
This commit is contained in:
parent
5be47cc5a9
commit
3656c78217
@ -70,6 +70,10 @@
|
||||
|
||||
typedef char*(*autocompleter)(char*, int*);
|
||||
|
||||
static gboolean _cmd_execute(const char * const command, const char * const inp);
|
||||
static gboolean _cmd_execute_default(const char * inp);
|
||||
static gboolean _cmd_execute_alias(const char * const inp, gboolean *ran);
|
||||
|
||||
static void _cmd_complete_parameters(char *input, int *size);
|
||||
|
||||
static char * _sub_autocomplete(char *input, int *size);
|
||||
@ -1728,10 +1732,53 @@ cmd_reset_autocomplete()
|
||||
bookmark_autocomplete_reset();
|
||||
}
|
||||
|
||||
/*
|
||||
* Take a line of input and process it, return TRUE if profanity is to
|
||||
* continue, FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
cmd_process_input(char *inp)
|
||||
{
|
||||
log_debug("Input received: %s", inp);
|
||||
gboolean result = FALSE;
|
||||
g_strstrip(inp);
|
||||
|
||||
// add line to history if something typed
|
||||
if (strlen(inp) > 0) {
|
||||
cmd_history_append(inp);
|
||||
}
|
||||
|
||||
// just carry on if no input
|
||||
if (strlen(inp) == 0) {
|
||||
result = TRUE;
|
||||
|
||||
// handle command if input starts with a '/'
|
||||
} else if (inp[0] == '/') {
|
||||
char *inp_cpy = strdup(inp);
|
||||
char *command = strtok(inp_cpy, " ");
|
||||
result = _cmd_execute(command, inp);
|
||||
free(inp_cpy);
|
||||
|
||||
// call a default handler if input didn't start with '/'
|
||||
} else {
|
||||
result = _cmd_execute_default(inp);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Command execution
|
||||
|
||||
gboolean
|
||||
cmd_execute(const char * const command, const char * const inp)
|
||||
void
|
||||
cmd_execute_connect(const char * const account)
|
||||
{
|
||||
char inp[INP_WIN_MAX];
|
||||
snprintf(inp, sizeof(inp), "%s %s", "/connect", account);
|
||||
cmd_process_input(inp);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_cmd_execute(const char * const command, const char * const inp)
|
||||
{
|
||||
if (g_str_has_prefix(command, "/field") && ui_current_win_type() == WIN_MUC_CONFIG) {
|
||||
gboolean result = FALSE;
|
||||
@ -1765,17 +1812,17 @@ cmd_execute(const char * const command, const char * const inp)
|
||||
}
|
||||
} else {
|
||||
gboolean ran_alias = FALSE;
|
||||
gboolean alias_result = cmd_execute_alias(inp, &ran_alias);
|
||||
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)
|
||||
static gboolean
|
||||
_cmd_execute_alias(const char * const inp, gboolean *ran)
|
||||
{
|
||||
if (inp[0] != '/') {
|
||||
ran = FALSE;
|
||||
@ -1786,7 +1833,7 @@ cmd_execute_alias(const char * const inp, gboolean *ran)
|
||||
free(alias);
|
||||
if (value != NULL) {
|
||||
*ran = TRUE;
|
||||
return process_input(value);
|
||||
return cmd_process_input(value);
|
||||
} else {
|
||||
*ran = FALSE;
|
||||
return TRUE;
|
||||
@ -1794,8 +1841,8 @@ cmd_execute_alias(const char * const inp, gboolean *ran)
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
cmd_execute_default(const char * inp)
|
||||
static gboolean
|
||||
_cmd_execute_default(const char * inp)
|
||||
{
|
||||
jabber_conn_status_t status = jabber_get_connection_status();
|
||||
|
||||
|
@ -53,9 +53,8 @@ void cmd_autocomplete_remove_form_fields(DataForm *form);
|
||||
void cmd_alias_add(char *value);
|
||||
void cmd_alias_remove(char *value);
|
||||
|
||||
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_process_input(char *inp);
|
||||
void cmd_execute_connect(const char * const account);
|
||||
|
||||
gboolean cmd_exists(char *cmd);
|
||||
|
||||
|
@ -68,6 +68,7 @@ static void _handle_idle_time(void);
|
||||
static void _init(const int disable_tls, char *log_level);
|
||||
static void _shutdown(void);
|
||||
static void _create_directories(void);
|
||||
static void _connect_default(const char * const account);
|
||||
|
||||
static gboolean idle = FALSE;
|
||||
|
||||
@ -75,21 +76,10 @@ void
|
||||
prof_run(const int disable_tls, char *log_level, char *account_name)
|
||||
{
|
||||
_init(disable_tls, log_level);
|
||||
|
||||
char inp[INP_WIN_MAX];
|
||||
|
||||
char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT);
|
||||
if (account_name != NULL) {
|
||||
snprintf(inp, sizeof(inp), "%s %s", "/connect", account_name);
|
||||
process_input(inp);
|
||||
} else if (pref_connect_account != NULL) {
|
||||
snprintf(inp, sizeof(inp), "%s %s", "/connect", pref_connect_account);
|
||||
process_input(inp);
|
||||
}
|
||||
prefs_free_string(pref_connect_account);
|
||||
|
||||
_connect_default(account_name);
|
||||
ui_update();
|
||||
|
||||
char inp[INP_WIN_MAX];
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
gboolean read_input = TRUE;
|
||||
gboolean cmd_result = TRUE;
|
||||
@ -113,7 +103,8 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
|
||||
ui_update();
|
||||
}
|
||||
|
||||
cmd_result = process_input(inp);
|
||||
cmd_result = cmd_process_input(inp);
|
||||
ui_input_clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,42 +141,18 @@ prof_handle_activity(void)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Take a line of input and process it, return TRUE if profanity is to
|
||||
* continue, FALSE otherwise
|
||||
*/
|
||||
gboolean
|
||||
process_input(char *inp)
|
||||
static void
|
||||
_connect_default(const char * const account)
|
||||
{
|
||||
log_debug("Input received: %s", inp);
|
||||
gboolean result = FALSE;
|
||||
g_strstrip(inp);
|
||||
|
||||
// add line to history if something typed
|
||||
if (strlen(inp) > 0) {
|
||||
cmd_history_append(inp);
|
||||
}
|
||||
|
||||
// just carry on if no input
|
||||
if (strlen(inp) == 0) {
|
||||
result = TRUE;
|
||||
|
||||
// handle command if input starts with a '/'
|
||||
} else if (inp[0] == '/') {
|
||||
char *inp_cpy = strdup(inp);
|
||||
char *command = strtok(inp_cpy, " ");
|
||||
result = cmd_execute(command, inp);
|
||||
free(inp_cpy);
|
||||
|
||||
// call a default handler if input didn't start with '/'
|
||||
if (account) {
|
||||
cmd_execute_connect(account);
|
||||
} else {
|
||||
result = cmd_execute_default(inp);
|
||||
char *pref_connect_account = prefs_get_string(PREF_CONNECT_ACCOUNT);
|
||||
if (pref_connect_account) {
|
||||
cmd_execute_connect(pref_connect_account);
|
||||
prefs_free_string(pref_connect_account);
|
||||
}
|
||||
}
|
||||
|
||||
ui_input_clear();
|
||||
roster_reset_search_attempts();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user