mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Renamed autocomplete function to get list
This commit is contained in:
parent
0afdbfaf03
commit
0b2a1a1bc7
@ -102,13 +102,13 @@ muc_invite_count(void)
|
|||||||
GSList *
|
GSList *
|
||||||
muc_get_invites(void)
|
muc_get_invites(void)
|
||||||
{
|
{
|
||||||
return autocomplete_get_list(invite_ac);
|
return autocomplete_create_list(invite_ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
muc_invites_include(const char * const room)
|
muc_invites_include(const char * const room)
|
||||||
{
|
{
|
||||||
GSList *invites = autocomplete_get_list(invite_ac);
|
GSList *invites = autocomplete_create_list(invite_ac);
|
||||||
GSList *curr = invites;
|
GSList *curr = invites;
|
||||||
while (curr != NULL) {
|
while (curr != NULL) {
|
||||||
if (strcmp(curr->data, room) == 0) {
|
if (strcmp(curr->data, room) == 0) {
|
||||||
|
@ -339,7 +339,7 @@ roster_get_group(const char * const group)
|
|||||||
GSList *
|
GSList *
|
||||||
roster_get_groups(void)
|
roster_get_groups(void)
|
||||||
{
|
{
|
||||||
return autocomplete_get_list(groups_ac);
|
return autocomplete_create_list(groups_ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
|
@ -62,7 +62,7 @@ autocomplete_new(void)
|
|||||||
void
|
void
|
||||||
autocomplete_clear(Autocomplete ac)
|
autocomplete_clear(Autocomplete ac)
|
||||||
{
|
{
|
||||||
if (ac != NULL) {
|
if (ac) {
|
||||||
g_slist_free_full(ac->items, free);
|
g_slist_free_full(ac->items, free);
|
||||||
ac->items = NULL;
|
ac->items = NULL;
|
||||||
|
|
||||||
@ -87,9 +87,9 @@ autocomplete_free(Autocomplete ac)
|
|||||||
gint
|
gint
|
||||||
autocomplete_length(Autocomplete ac)
|
autocomplete_length(Autocomplete ac)
|
||||||
{
|
{
|
||||||
if (ac == NULL) {
|
if (!ac) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (ac->items == NULL) {
|
} else if (!ac->items) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return g_slist_length(ac->items);
|
return g_slist_length(ac->items);
|
||||||
@ -99,25 +99,26 @@ autocomplete_length(Autocomplete ac)
|
|||||||
void
|
void
|
||||||
autocomplete_add(Autocomplete ac, const char *item)
|
autocomplete_add(Autocomplete ac, const char *item)
|
||||||
{
|
{
|
||||||
if (ac != NULL) {
|
if (ac) {
|
||||||
char *item_cpy;
|
char *item_cpy;
|
||||||
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
|
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
|
||||||
|
|
||||||
// if item already exists
|
// if item already exists
|
||||||
if (curr != NULL) {
|
if (curr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
item_cpy = strdup(item);
|
item_cpy = strdup(item);
|
||||||
ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
|
ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
autocomplete_remove(Autocomplete ac, const char * const item)
|
autocomplete_remove(Autocomplete ac, const char * const item)
|
||||||
{
|
{
|
||||||
if (ac != NULL) {
|
if (ac) {
|
||||||
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
|
GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
|
||||||
|
|
||||||
if (!curr) {
|
if (!curr) {
|
||||||
@ -137,7 +138,7 @@ autocomplete_remove(Autocomplete ac, const char * const item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GSList *
|
GSList *
|
||||||
autocomplete_get_list(Autocomplete ac)
|
autocomplete_create_list(Autocomplete ac)
|
||||||
{
|
{
|
||||||
GSList *copy = NULL;
|
GSList *copy = NULL;
|
||||||
GSList *curr = ac->items;
|
GSList *curr = ac->items;
|
||||||
@ -171,36 +172,43 @@ autocomplete_complete(Autocomplete ac, gchar *search_str, gboolean quote)
|
|||||||
gchar *found = NULL;
|
gchar *found = NULL;
|
||||||
|
|
||||||
// no autocomplete to search
|
// no autocomplete to search
|
||||||
if (ac == NULL)
|
if (!ac) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// no items to search
|
// no items to search
|
||||||
if (!ac->items)
|
if (!ac->items) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// first search attempt
|
// first search attempt
|
||||||
if (ac->last_found == NULL) {
|
if (!ac->last_found) {
|
||||||
if (ac->search_str != NULL) {
|
if (ac->search_str) {
|
||||||
FREE_SET_NULL(ac->search_str);
|
FREE_SET_NULL(ac->search_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
ac->search_str = strdup(search_str);
|
ac->search_str = strdup(search_str);
|
||||||
found = _search_from(ac, ac->items, quote);
|
found = _search_from(ac, ac->items, quote);
|
||||||
|
|
||||||
return found;
|
return found;
|
||||||
|
|
||||||
// subsequent search attempt
|
// subsequent search attempt
|
||||||
} else {
|
} else {
|
||||||
// search from here+1 to end
|
// search from here+1 to end
|
||||||
found = _search_from(ac, g_slist_next(ac->last_found), quote);
|
found = _search_from(ac, g_slist_next(ac->last_found), quote);
|
||||||
if (found != NULL)
|
if (found) {
|
||||||
return found;
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
// search from beginning
|
// search from beginning
|
||||||
found = _search_from(ac, ac->items, quote);
|
found = _search_from(ac, ac->items, quote);
|
||||||
if (found != NULL)
|
if (found) {
|
||||||
return found;
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
// we found nothing, reset search
|
// we found nothing, reset search
|
||||||
autocomplete_reset(ac);
|
autocomplete_reset(ac);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -224,7 +232,7 @@ autocomplete_param_with_func(char *input, int *size, char *command,
|
|||||||
inp_cpy[(*size) - len] = '\0';
|
inp_cpy[(*size) - len] = '\0';
|
||||||
|
|
||||||
char *found = func(inp_cpy);
|
char *found = func(inp_cpy);
|
||||||
if (found != NULL) {
|
if (found) {
|
||||||
auto_msg = g_string_new(command_cpy);
|
auto_msg = g_string_new(command_cpy);
|
||||||
g_string_append(auto_msg, found);
|
g_string_append(auto_msg, found);
|
||||||
free(found);
|
free(found);
|
||||||
@ -254,7 +262,7 @@ autocomplete_param_with_ac(char *input, int *size, char *command,
|
|||||||
inp_cpy[(*size) - len] = '\0';
|
inp_cpy[(*size) - len] = '\0';
|
||||||
|
|
||||||
char *found = autocomplete_complete(ac, inp_cpy, quote);
|
char *found = autocomplete_complete(ac, inp_cpy, quote);
|
||||||
if (found != NULL) {
|
if (found) {
|
||||||
auto_msg = g_string_new(command_cpy);
|
auto_msg = g_string_new(command_cpy);
|
||||||
g_string_append(auto_msg, found);
|
g_string_append(auto_msg, found);
|
||||||
free(found);
|
free(found);
|
||||||
@ -292,9 +300,9 @@ autocomplete_param_no_with_func(char *input, int *size, char *command,
|
|||||||
gchar *comp_str = g_strdup(&inp_cpy[strlen(start_str)]);
|
gchar *comp_str = g_strdup(&inp_cpy[strlen(start_str)]);
|
||||||
|
|
||||||
// autocomplete param
|
// autocomplete param
|
||||||
if (comp_str != NULL) {
|
if (comp_str) {
|
||||||
char *found = func(comp_str);
|
char *found = func(comp_str);
|
||||||
if (found != NULL) {
|
if (found) {
|
||||||
result_str = g_string_new("");
|
result_str = g_string_new("");
|
||||||
g_string_append(result_str, start_str);
|
g_string_append(result_str, start_str);
|
||||||
g_string_append(result_str, found);
|
g_string_append(result_str, found);
|
||||||
|
@ -55,7 +55,7 @@ void autocomplete_remove(Autocomplete ac, const char * const item);
|
|||||||
// find the next item prefixed with search string
|
// find the next item prefixed with search string
|
||||||
gchar * autocomplete_complete(Autocomplete ac, gchar *search_str, gboolean quote);
|
gchar * autocomplete_complete(Autocomplete ac, gchar *search_str, gboolean quote);
|
||||||
|
|
||||||
GSList * autocomplete_get_list(Autocomplete ac);
|
GSList * autocomplete_create_list(Autocomplete ac);
|
||||||
gint autocomplete_length(Autocomplete ac);
|
gint autocomplete_length(Autocomplete ac);
|
||||||
|
|
||||||
char * autocomplete_param_with_func(char *input, int *size, char *command,
|
char * autocomplete_param_with_func(char *input, int *size, char *command,
|
||||||
|
@ -142,7 +142,7 @@ _presence_subscription(const char * const jid, const jabber_subscr_t action)
|
|||||||
static GSList *
|
static GSList *
|
||||||
_presence_get_subscription_requests(void)
|
_presence_get_subscription_requests(void)
|
||||||
{
|
{
|
||||||
return autocomplete_get_list(sub_requests_ac);
|
return autocomplete_create_list(sub_requests_ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
@ -167,7 +167,7 @@ static gboolean
|
|||||||
_presence_sub_request_exists(const char * const bare_jid)
|
_presence_sub_request_exists(const char * const bare_jid)
|
||||||
{
|
{
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
GSList *requests_p = autocomplete_get_list(sub_requests_ac);
|
GSList *requests_p = autocomplete_create_list(sub_requests_ac);
|
||||||
GSList *requests = requests_p;
|
GSList *requests = requests_p;
|
||||||
|
|
||||||
while (requests != NULL) {
|
while (requests != NULL) {
|
||||||
|
@ -31,11 +31,12 @@ void find_after_create(void **state)
|
|||||||
void get_after_create_returns_null(void **state)
|
void get_after_create_returns_null(void **state)
|
||||||
{
|
{
|
||||||
Autocomplete ac = autocomplete_new();
|
Autocomplete ac = autocomplete_new();
|
||||||
GSList *result = autocomplete_get_list(ac);
|
GSList *result = autocomplete_create_list(ac);
|
||||||
|
|
||||||
assert_null(result);
|
assert_null(result);
|
||||||
|
|
||||||
autocomplete_clear(ac);
|
autocomplete_clear(ac);
|
||||||
|
g_slist_free_full(result, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_one_and_complete(void **state)
|
void add_one_and_complete(void **state)
|
||||||
@ -79,11 +80,12 @@ void add_two_adds_two(void **state)
|
|||||||
Autocomplete ac = autocomplete_new();
|
Autocomplete ac = autocomplete_new();
|
||||||
autocomplete_add(ac, "Hello");
|
autocomplete_add(ac, "Hello");
|
||||||
autocomplete_add(ac, "Help");
|
autocomplete_add(ac, "Help");
|
||||||
GSList *result = autocomplete_get_list(ac);
|
GSList *result = autocomplete_create_list(ac);
|
||||||
|
|
||||||
assert_int_equal(2, g_slist_length(result));
|
assert_int_equal(2, g_slist_length(result));
|
||||||
|
|
||||||
autocomplete_clear(ac);
|
autocomplete_clear(ac);
|
||||||
|
g_slist_free_full(result, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_two_same_adds_one(void **state)
|
void add_two_same_adds_one(void **state)
|
||||||
@ -91,11 +93,12 @@ void add_two_same_adds_one(void **state)
|
|||||||
Autocomplete ac = autocomplete_new();
|
Autocomplete ac = autocomplete_new();
|
||||||
autocomplete_add(ac, "Hello");
|
autocomplete_add(ac, "Hello");
|
||||||
autocomplete_add(ac, "Hello");
|
autocomplete_add(ac, "Hello");
|
||||||
GSList *result = autocomplete_get_list(ac);
|
GSList *result = autocomplete_create_list(ac);
|
||||||
|
|
||||||
assert_int_equal(1, g_slist_length(result));
|
assert_int_equal(1, g_slist_length(result));
|
||||||
|
|
||||||
autocomplete_clear(ac);
|
autocomplete_clear(ac);
|
||||||
|
g_slist_free_full(result, g_free);
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_two_same_updates(void **state)
|
void add_two_same_updates(void **state)
|
||||||
@ -103,7 +106,7 @@ void add_two_same_updates(void **state)
|
|||||||
Autocomplete ac = autocomplete_new();
|
Autocomplete ac = autocomplete_new();
|
||||||
autocomplete_add(ac, "Hello");
|
autocomplete_add(ac, "Hello");
|
||||||
autocomplete_add(ac, "Hello");
|
autocomplete_add(ac, "Hello");
|
||||||
GSList *result = autocomplete_get_list(ac);
|
GSList *result = autocomplete_create_list(ac);
|
||||||
|
|
||||||
GSList *first = g_slist_nth(result, 0);
|
GSList *first = g_slist_nth(result, 0);
|
||||||
|
|
||||||
@ -112,4 +115,5 @@ void add_two_same_updates(void **state)
|
|||||||
assert_string_equal("Hello", str);
|
assert_string_equal("Hello", str);
|
||||||
|
|
||||||
autocomplete_clear(ac);
|
autocomplete_clear(ac);
|
||||||
|
g_slist_free_full(result, g_free);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user