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

Merge branch 'master' into osx-functional

This commit is contained in:
James Booth 2016-06-01 00:48:01 +01:00
commit 672a398b37
2 changed files with 195 additions and 166 deletions

View File

@ -1527,66 +1527,76 @@ _blocked_autocomplete(ProfWin *window, const char *const input)
return NULL;
}
static char*
_bookmark_autocomplete(ProfWin *window, const char *const input)
{
char *found = NULL;
gboolean result;
gchar **args = parse_args(input, 3, 8, &result);
gboolean handle_options = result && (g_strv_length(args) > 2);
gchar **args = parse_args(input, 2, 8, &result);
if (handle_options && ((strcmp(args[0], "add") == 0) || (strcmp(args[0], "update") == 0)) ) {
if (result && ((strcmp(args[0], "add") == 0) || (strcmp(args[0], "update") == 0)) ) {
gboolean space_at_end = g_str_has_suffix(input, " ");
GString *beginning = g_string_new("/bookmark");
gboolean autojoin = FALSE;
int num_args = g_strv_length(args);
g_string_append(beginning, " ");
g_string_append(beginning, args[0]);
g_string_append(beginning, " ");
g_string_append(beginning, args[1]);
if (num_args == 4 && g_strcmp0(args[2], "autojoin") == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
autojoin = TRUE;
}
if (num_args > 4) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
g_string_append(beginning, " ");
g_string_append(beginning, args[3]);
if (num_args == 6 && g_strcmp0(args[4], "autojoin") == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[4]);
autojoin = TRUE;
}
}
if (num_args > 6) {
g_string_append(beginning, " ");
g_string_append(beginning, args[4]);
g_string_append(beginning, " ");
g_string_append(beginning, args[5]);
if (num_args == 8 && g_strcmp0(args[6], "autojoin") == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[6]);
autojoin = TRUE;
}
}
if (autojoin) {
found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice);
} else {
if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) {
g_string_append_printf(beginning, " %s %s", args[0], args[1]);
found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE);
}
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "autojoin") == 0))
|| (num_args == 4 && (g_strcmp0(args[2], "autojoin") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 4 && space_at_end) || (num_args == 5 && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s %s", args[0], args[1], args[2], args[3]);
found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 5 && space_at_end && (g_strcmp0(args[4], "autojoin") == 0))
|| (num_args == 6 && (g_strcmp0(args[4], "autojoin") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4]);
found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 6 && space_at_end) || (num_args == 7 && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5]);
found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 7 && space_at_end && (g_strcmp0(args[6], "autojoin") == 0))
|| (num_args == 8 && (g_strcmp0(args[6], "autojoin") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
}
g_strfreev(args);
@ -1709,13 +1719,11 @@ _log_autocomplete(ProfWin *window, const char *const input)
{
char *result = NULL;
result = autocomplete_param_with_func(input, "/log rotate",
prefs_autocomplete_boolean_choice);
result = autocomplete_param_with_func(input, "/log rotate", prefs_autocomplete_boolean_choice);
if (result) {
return result;
}
result = autocomplete_param_with_func(input, "/log shared",
prefs_autocomplete_boolean_choice);
result = autocomplete_param_with_func(input, "/log shared", prefs_autocomplete_boolean_choice);
if (result) {
return result;
}
@ -1767,12 +1775,14 @@ _otr_autocomplete(ProfWin *window, const char *const input)
// /otr policy always user@server.com
if (conn_status == JABBER_CONNECTED) {
gboolean result;
gchar **args = parse_args(input, 3, 3, &result);
gchar **args = parse_args(input, 2, 3, &result);
if (result && (strcmp(args[0], "policy") == 0)) {
GString *beginning = g_string_new("/otr ");
g_string_append(beginning, args[0]);
g_string_append(beginning, " ");
if (args[1]) {
g_string_append(beginning, args[1]);
}
found = autocomplete_param_with_func(input, beginning->str, roster_contact_autocomplete);
g_string_free(beginning, TRUE);
@ -1855,7 +1865,7 @@ static char*
_plugins_autocomplete(ProfWin *window, const char *const input)
{
char *result = NULL;
if ((strncmp(input, "/plugins load ", 14) == 0) && (strlen(input) > 14)) {
if (strncmp(input, "/plugins load ", 14) == 0) {
if (plugins_load_ac == NULL) {
plugins_load_ac = autocomplete_new();
GSList *plugins = plugins_unloaded_list();
@ -1883,7 +1893,7 @@ static char*
_theme_autocomplete(ProfWin *window, const char *const input)
{
char *result = NULL;
if ((strncmp(input, "/theme load ", 12) == 0) && (strlen(input) > 12)) {
if (strncmp(input, "/theme load ", 12) == 0) {
if (theme_load_ac == NULL) {
theme_load_ac = autocomplete_new();
GSList *themes = theme_list();
@ -1930,14 +1940,14 @@ static char*
_script_autocomplete(ProfWin *window, const char *const input)
{
char *result = NULL;
if ((strncmp(input, "/script show ", 13) == 0) && (strlen(input) > 13)) {
if (strncmp(input, "/script show ", 13) == 0) {
result = autocomplete_param_with_func(input, "/script show", _script_autocomplete_func);
if (result) {
return result;
}
}
if ((strncmp(input, "/script run ", 12) == 0) && (strlen(input) > 12)) {
if (strncmp(input, "/script run ", 12) == 0) {
result = autocomplete_param_with_func(input, "/script run", _script_autocomplete_func);
if (result) {
return result;
@ -2270,13 +2280,15 @@ _affiliation_autocomplete(ProfWin *window, const char *const input)
gboolean parse_result;
Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid);
gchar **args = parse_args(input, 3, 3, &parse_result);
gchar **args = parse_args(input, 2, 3, &parse_result);
if ((strncmp(input, "/affiliation", 12) == 0) && (parse_result == TRUE)) {
GString *beginning = g_string_new("/affiliation ");
g_string_append(beginning, args[0]);
g_string_append(beginning, " ");
if (args[1]) {
g_string_append(beginning, args[1]);
}
result = autocomplete_param_with_ac(input, beginning->str, jid_ac, TRUE);
g_string_free(beginning, TRUE);
@ -2318,13 +2330,15 @@ _role_autocomplete(ProfWin *window, const char *const input)
gboolean parse_result;
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
gchar **args = parse_args(input, 3, 3, &parse_result);
gchar **args = parse_args(input, 2, 3, &parse_result);
if ((strncmp(input, "/role", 5) == 0) && (parse_result == TRUE)) {
GString *beginning = g_string_new("/role ");
g_string_append(beginning, args[0]);
g_string_append(beginning, " ");
if (args[1]) {
g_string_append(beginning, args[1]);
}
result = autocomplete_param_with_ac(input, beginning->str, nick_ac, TRUE);
g_string_free(beginning, TRUE);
@ -2453,23 +2467,14 @@ _connect_autocomplete(ProfWin *window, const char *const input)
char *found = NULL;
gboolean result = FALSE;
gchar **args = parse_args(input, 2, 6, &result);
gchar **args = parse_args(input, 1, 7, &result);
if ((strncmp(input, "/connect", 8) == 0) && (result == TRUE)) {
if (result) {
gboolean space_at_end = g_str_has_suffix(input, " ");
GString *beginning = g_string_new("/connect");
g_string_append(beginning, args[0]);
if (args[1] && args[2]) {
g_string_append(beginning, " ");
g_string_append(beginning, args[1]);
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
if (args[3] && args[4]) {
g_string_append(beginning, " ");
g_string_append(beginning, args[3]);
g_string_append(beginning, " ");
g_string_append(beginning, args[4]);
}
}
int num_args = g_strv_length(args);
if ((num_args == 1 && space_at_end) || (num_args == 2 && !space_at_end)) {
g_string_append_printf(beginning, " %s", args[0]);
found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
@ -2477,44 +2482,53 @@ _connect_autocomplete(ProfWin *window, const char *const input)
return found;
}
}
g_strfreev(args);
result = FALSE;
args = parse_args(input, 2, 7, &result);
if ((strncmp(input, "/connect", 8) == 0) && (result == TRUE)) {
GString *beginning = g_string_new("/connect ");
g_string_append(beginning, args[0]);
int curr = 0;
if (args[1]) {
g_string_append(beginning, " ");
g_string_append(beginning, args[1]);
curr = 1;
if (args[2] && args[3]) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
g_string_append(beginning, " ");
g_string_append(beginning, args[3]);
curr = 3;
if (args[4] && args[5]) {
g_string_append(beginning, " ");
g_string_append(beginning, args[4]);
g_string_append(beginning, " ");
g_string_append(beginning, args[5]);
curr = 5;
}
}
}
if (curr != 0 && (g_strcmp0(args[curr], "tls") == 0)) {
if ((num_args == 2 && space_at_end && (g_strcmp0(args[1], "tls") == 0))
|| (num_args == 3 && (g_strcmp0(args[1], "tls") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s", args[0], args[1]);
found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
} else {
}
if ((num_args == 3 && space_at_end) || (num_args == 4 && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 4 && space_at_end && (g_strcmp0(args[3], "tls") == 0))
|| (num_args == 5 && (g_strcmp0(args[3], "tls") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s %s", args[0], args[1], args[2], args[3]);
found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 5 && space_at_end) || (num_args == 6 && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4]);
found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 6 && space_at_end && (g_strcmp0(args[5], "tls") == 0))
|| (num_args == 7 && (g_strcmp0(args[5], "tls") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5]);
found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
}
@ -2552,22 +2566,14 @@ _join_autocomplete(ProfWin *window, const char *const input)
char *found = NULL;
gboolean result = FALSE;
found = autocomplete_param_with_func(input, "/join", bookmark_find);
if (found) {
return found;
}
gchar **args = parse_args(input, 1, 5, &result);
gchar **args = parse_args(input, 2, 4, &result);
if ((strncmp(input, "/join", 5) == 0) && (result == TRUE)) {
if (result) {
gboolean space_at_end = g_str_has_suffix(input, " ");
GString *beginning = g_string_new("/join");
g_string_append(beginning, args[0]);
if (args[1] && args[2]) {
g_string_append(beginning, " ");
g_string_append(beginning, args[1]);
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
int num_args = g_strv_length(args);
if ((num_args == 1 && space_at_end) || (num_args == 2 && !space_at_end)) {
g_string_append_printf(beginning, " %s", args[0]);
found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
@ -2575,9 +2581,24 @@ _join_autocomplete(ProfWin *window, const char *const input)
return found;
}
}
if ((num_args == 3 && space_at_end) || (num_args == 4 && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
}
g_strfreev(args);
found = autocomplete_param_with_func(input, "/join", bookmark_find);
if (found) {
return found;
}
return NULL;
}
@ -2781,50 +2802,63 @@ _account_autocomplete(ProfWin *window, const char *const input)
char *found = NULL;
gboolean result = FALSE;
gchar **args = parse_args(input, 3, 4, &result);
if ((strncmp(input, "/account set", 12) == 0) && (result == TRUE)) {
GString *beginning = g_string_new("/account set ");
g_string_append(beginning, args[1]);
if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "otr")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
gchar **args = parse_args(input, 2, 4, &result);
if (result && (strcmp(args[0], "set") == 0)) {
gboolean space_at_end = g_str_has_suffix(input, " ");
GString *beginning = g_string_new("/account");
int num_args = g_strv_length(args);
if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) {
g_string_append_printf(beginning, " %s %s", args[0], args[1]);
found = autocomplete_param_with_ac(input, beginning->str, account_set_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "otr") == 0))
|| (num_args == 4 && (g_strcmp0(args[2], "otr") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_ac(input, beginning->str, otr_policy_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "status")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "status") == 0))
|| (num_args == 4 && (g_strcmp0(args[2], "status") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_ac(input, beginning->str, account_status_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "tls")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "tls") == 0))
|| (num_args == 4 && (g_strcmp0(args[2], "tls") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "startscript")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "startscript") == 0))
|| (num_args == 4 && (g_strcmp0(args[2], "startscript") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_func(input, beginning->str, _script_autocomplete_func);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "theme")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "theme") == 0))
|| (num_args == 4 && (g_strcmp0(args[2], "theme") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
if (theme_load_ac == NULL) {
theme_load_ac = autocomplete_new();
GSList *themes = theme_list();
@ -2839,27 +2873,22 @@ _account_autocomplete(ProfWin *window, const char *const input)
found = autocomplete_param_with_ac(input, beginning->str, theme_load_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
#ifdef HAVE_LIBGPGME
} else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "pgpkeyid")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "pgpkeyid") == 0))
|| (num_args == 4 && (g_strcmp0(args[2], "pgpkeyid") == 0) && !space_at_end)) {
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
found = autocomplete_param_with_func(input, beginning->str, p_gpg_autocomplete_key);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
#endif
} else {
found = autocomplete_param_with_ac(input, beginning->str, account_set_ac, TRUE);
g_string_free(beginning, TRUE);
if (found) {
g_strfreev(args);
return found;
}
}
}
if ((strncmp(input, "/account clear", 14) == 0) && (result == TRUE)) {

View File

@ -224,7 +224,7 @@ autocomplete_param_with_func(const char *const input, char *command, autocomplet
sprintf(command_cpy, "%s ", command);
int len = strlen(command_cpy);
if ((strncmp(input, command_cpy, len) == 0) && (strlen(input) > len)) {
if (strncmp(input, command_cpy, len) == 0) {
int i;
int inp_len = strlen(input);
char prefix[inp_len];
@ -255,7 +255,7 @@ autocomplete_param_with_ac(const char *const input, char *command, Autocomplete
sprintf(command_cpy, "%s ", command);
int len = strlen(command_cpy);
int inp_len = strlen(input);
if ((strncmp(input, command_cpy, len) == 0) && (strlen(input) > len)) {
if (strncmp(input, command_cpy, len) == 0) {
int i;
char prefix[inp_len];
for(i = len; i < inp_len; i++) {
@ -280,7 +280,7 @@ autocomplete_param_with_ac(const char *const input, char *command, Autocomplete
char*
autocomplete_param_no_with_func(const char *const input, char *command, int arg_number, autocomplete_func func)
{
if (strncmp(input, command, strlen(command)) == 0 && (strlen(input) > strlen(command))) {
if (strncmp(input, command, strlen(command)) == 0) {
GString *result_str = NULL;
// count tokens properly