1
0
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:
James Booth 2015-01-15 20:34:45 +00:00
parent 5be47cc5a9
commit 3656c78217
3 changed files with 72 additions and 59 deletions

View File

@ -70,6 +70,10 @@
typedef char*(*autocompleter)(char*, int*); 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 void _cmd_complete_parameters(char *input, int *size);
static char * _sub_autocomplete(char *input, int *size); static char * _sub_autocomplete(char *input, int *size);
@ -1728,10 +1732,53 @@ cmd_reset_autocomplete()
bookmark_autocomplete_reset(); 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 // Command execution
gboolean void
cmd_execute(const char * const command, const char * const inp) 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) { if (g_str_has_prefix(command, "/field") && ui_current_win_type() == WIN_MUC_CONFIG) {
gboolean result = FALSE; gboolean result = FALSE;
@ -1765,17 +1812,17 @@ cmd_execute(const char * const command, const char * const inp)
} }
} else { } else {
gboolean ran_alias = FALSE; 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) { if (!ran_alias) {
return cmd_execute_default(inp); return _cmd_execute_default(inp);
} else { } else {
return alias_result; return alias_result;
} }
} }
} }
gboolean static gboolean
cmd_execute_alias(const char * const inp, gboolean *ran) _cmd_execute_alias(const char * const inp, gboolean *ran)
{ {
if (inp[0] != '/') { if (inp[0] != '/') {
ran = FALSE; ran = FALSE;
@ -1786,7 +1833,7 @@ cmd_execute_alias(const char * const inp, gboolean *ran)
free(alias); free(alias);
if (value != NULL) { if (value != NULL) {
*ran = TRUE; *ran = TRUE;
return process_input(value); return cmd_process_input(value);
} else { } else {
*ran = FALSE; *ran = FALSE;
return TRUE; return TRUE;
@ -1794,8 +1841,8 @@ cmd_execute_alias(const char * const inp, gboolean *ran)
} }
} }
gboolean static gboolean
cmd_execute_default(const char * inp) _cmd_execute_default(const char * inp)
{ {
jabber_conn_status_t status = jabber_get_connection_status(); jabber_conn_status_t status = jabber_get_connection_status();

View File

@ -53,9 +53,8 @@ void cmd_autocomplete_remove_form_fields(DataForm *form);
void cmd_alias_add(char *value); void cmd_alias_add(char *value);
void cmd_alias_remove(char *value); void cmd_alias_remove(char *value);
gboolean cmd_execute(const char * const command, const char * const inp); gboolean cmd_process_input(char *inp);
gboolean cmd_execute_alias(const char * const inp, gboolean *ran); void cmd_execute_connect(const char * const account);
gboolean cmd_execute_default(const char * const inp);
gboolean cmd_exists(char *cmd); gboolean cmd_exists(char *cmd);

View File

@ -68,6 +68,7 @@ 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);
static void _create_directories(void); static void _create_directories(void);
static void _connect_default(const char * const account);
static gboolean idle = FALSE; static gboolean idle = FALSE;
@ -75,21 +76,10 @@ void
prof_run(const int disable_tls, char *log_level, char *account_name) prof_run(const int disable_tls, char *log_level, char *account_name)
{ {
_init(disable_tls, log_level); _init(disable_tls, log_level);
_connect_default(account_name);
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);
ui_update(); ui_update();
char inp[INP_WIN_MAX];
jabber_conn_status_t conn_status = jabber_get_connection_status(); jabber_conn_status_t conn_status = jabber_get_connection_status();
gboolean read_input = TRUE; gboolean read_input = TRUE;
gboolean cmd_result = TRUE; gboolean cmd_result = TRUE;
@ -113,7 +103,8 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
ui_update(); ui_update();
} }
cmd_result = process_input(inp); cmd_result = cmd_process_input(inp);
ui_input_clear();
} }
} }
@ -150,42 +141,18 @@ prof_handle_activity(void)
} }
} }
/* static void
* Take a line of input and process it, return TRUE if profanity is to _connect_default(const char * const account)
* continue, FALSE otherwise
*/
gboolean
process_input(char *inp)
{ {
log_debug("Input received: %s", inp); if (account) {
gboolean result = FALSE; cmd_execute_connect(account);
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 { } 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 static void