about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-26 00:06:50 +0100
committerJames Booth <boothj5@gmail.com>2014-09-26 00:06:50 +0100
commit0b2a1a1bc7247dd41c63e09a84f31211b8d7374b (patch)
tree8480f85f6ef54398222a35b31305950970d97959
parent0afdbfaf03d64522356b0a0abe178ae236057e7e (diff)
downloadprofani-tty-0b2a1a1bc7247dd41c63e09a84f31211b8d7374b.tar.gz
Renamed autocomplete function to get list
-rw-r--r--src/muc.c4
-rw-r--r--src/roster_list.c2
-rw-r--r--src/tools/autocomplete.c42
-rw-r--r--src/tools/autocomplete.h2
-rw-r--r--src/xmpp/presence.c4
-rw-r--r--tests/test_autocomplete.c12
6 files changed, 39 insertions, 27 deletions
diff --git a/src/muc.c b/src/muc.c
index 413ba84c..896a0fa4 100644
--- a/src/muc.c
+++ b/src/muc.c
@@ -102,13 +102,13 @@ muc_invite_count(void)
 GSList *
 muc_get_invites(void)
 {
-    return autocomplete_get_list(invite_ac);
+    return autocomplete_create_list(invite_ac);
 }
 
 gboolean
 muc_invites_include(const char * const room)
 {
-    GSList *invites = autocomplete_get_list(invite_ac);
+    GSList *invites = autocomplete_create_list(invite_ac);
     GSList *curr = invites;
     while (curr != NULL) {
         if (strcmp(curr->data, room) == 0) {
diff --git a/src/roster_list.c b/src/roster_list.c
index aba90d34..f7c865f9 100644
--- a/src/roster_list.c
+++ b/src/roster_list.c
@@ -339,7 +339,7 @@ roster_get_group(const char * const group)
 GSList *
 roster_get_groups(void)
 {
-    return autocomplete_get_list(groups_ac);
+    return autocomplete_create_list(groups_ac);
 }
 
 char *
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c
index 0fe8f166..5dd350e9 100644
--- a/src/tools/autocomplete.c
+++ b/src/tools/autocomplete.c
@@ -62,7 +62,7 @@ autocomplete_new(void)
 void
 autocomplete_clear(Autocomplete ac)
 {
-    if (ac != NULL) {
+    if (ac) {
         g_slist_free_full(ac->items, free);
         ac->items = NULL;
 
@@ -87,9 +87,9 @@ autocomplete_free(Autocomplete ac)
 gint
 autocomplete_length(Autocomplete ac)
 {
-    if (ac == NULL) {
+    if (!ac) {
         return 0;
-    } else if (ac->items == NULL) {
+    } else if (!ac->items) {
         return 0;
     } else {
         return g_slist_length(ac->items);
@@ -99,25 +99,26 @@ autocomplete_length(Autocomplete ac)
 void
 autocomplete_add(Autocomplete ac, const char *item)
 {
-    if (ac != NULL) {
+    if (ac) {
         char *item_cpy;
         GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
 
         // if item already exists
-        if (curr != NULL) {
+        if (curr) {
             return;
         }
 
         item_cpy = strdup(item);
         ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
     }
+
     return;
 }
 
 void
 autocomplete_remove(Autocomplete ac, const char * const item)
 {
-    if (ac != NULL) {
+    if (ac) {
         GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
 
         if (!curr) {
@@ -137,7 +138,7 @@ autocomplete_remove(Autocomplete ac, const char * const item)
 }
 
 GSList *
-autocomplete_get_list(Autocomplete ac)
+autocomplete_create_list(Autocomplete ac)
 {
     GSList *copy = NULL;
     GSList *curr = ac->items;
@@ -171,36 +172,43 @@ autocomplete_complete(Autocomplete ac, gchar *search_str, gboolean quote)
     gchar *found = NULL;
 
     // no autocomplete to search
-    if (ac == NULL)
+    if (!ac) {
         return NULL;
+    }
 
     // no items to search
-    if (!ac->items)
+    if (!ac->items) {
         return NULL;
+    }
 
     // first search attempt
-    if (ac->last_found == NULL) {
-        if (ac->search_str != NULL) {
+    if (!ac->last_found) {
+        if (ac->search_str) {
             FREE_SET_NULL(ac->search_str);
         }
+
         ac->search_str = strdup(search_str);
         found = _search_from(ac, ac->items, quote);
+
         return found;
 
     // subsequent search attempt
     } else {
         // search from here+1 to end
         found = _search_from(ac, g_slist_next(ac->last_found), quote);
-        if (found != NULL)
+        if (found) {
             return found;
+        }
 
         // search from beginning
         found = _search_from(ac, ac->items, quote);
-        if (found != NULL)
+        if (found) {
             return found;
+        }
 
         // we found nothing, reset search
         autocomplete_reset(ac);
+
         return NULL;
     }
 }
@@ -224,7 +232,7 @@ autocomplete_param_with_func(char *input, int *size, char *command,
         inp_cpy[(*size) - len] = '\0';
 
         char *found = func(inp_cpy);
-        if (found != NULL) {
+        if (found) {
             auto_msg = g_string_new(command_cpy);
             g_string_append(auto_msg, found);
             free(found);
@@ -254,7 +262,7 @@ autocomplete_param_with_ac(char *input, int *size, char *command,
         inp_cpy[(*size) - len] = '\0';
 
         char *found = autocomplete_complete(ac, inp_cpy, quote);
-        if (found != NULL) {
+        if (found) {
             auto_msg = g_string_new(command_cpy);
             g_string_append(auto_msg, 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)]);
 
             // autocomplete param
-            if (comp_str != NULL) {
+            if (comp_str) {
                 char *found = func(comp_str);
-                if (found != NULL) {
+                if (found) {
                     result_str = g_string_new("");
                     g_string_append(result_str, start_str);
                     g_string_append(result_str, found);
diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h
index 9e2be30c..a029b7ef 100644
--- a/src/tools/autocomplete.h
+++ b/src/tools/autocomplete.h
@@ -55,7 +55,7 @@ void autocomplete_remove(Autocomplete ac, const char * const item);
 // find the next item prefixed with search string
 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);
 
 char * autocomplete_param_with_func(char *input, int *size, char *command,
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index 54c9d68c..adbb21fb 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -142,7 +142,7 @@ _presence_subscription(const char * const jid, const jabber_subscr_t action)
 static GSList *
 _presence_get_subscription_requests(void)
 {
-    return autocomplete_get_list(sub_requests_ac);
+    return autocomplete_create_list(sub_requests_ac);
 }
 
 static gint
@@ -167,7 +167,7 @@ static gboolean
 _presence_sub_request_exists(const char * const bare_jid)
 {
     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;
 
     while (requests != NULL) {
diff --git a/tests/test_autocomplete.c b/tests/test_autocomplete.c
index 4fdd4e4d..f6ef8653 100644
--- a/tests/test_autocomplete.c
+++ b/tests/test_autocomplete.c
@@ -31,11 +31,12 @@ void find_after_create(void **state)
 void get_after_create_returns_null(void **state)
 {
     Autocomplete ac = autocomplete_new();
-    GSList *result = autocomplete_get_list(ac);
+    GSList *result = autocomplete_create_list(ac);
 
     assert_null(result);
 
     autocomplete_clear(ac);
+    g_slist_free_full(result, g_free);
 }
 
 void add_one_and_complete(void **state)
@@ -79,11 +80,12 @@ void add_two_adds_two(void **state)
     Autocomplete ac = autocomplete_new();
     autocomplete_add(ac, "Hello");
     autocomplete_add(ac, "Help");
-    GSList *result = autocomplete_get_list(ac);
+    GSList *result = autocomplete_create_list(ac);
 
     assert_int_equal(2, g_slist_length(result));
 
     autocomplete_clear(ac);
+    g_slist_free_full(result, g_free);
 }
 
 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_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));
 
     autocomplete_clear(ac);
+    g_slist_free_full(result, g_free);
 }
 
 void add_two_same_updates(void **state)
@@ -103,7 +106,7 @@ void add_two_same_updates(void **state)
     Autocomplete ac = autocomplete_new();
     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);
 
@@ -112,4 +115,5 @@ void add_two_same_updates(void **state)
     assert_string_equal("Hello", str);
 
     autocomplete_clear(ac);
+    g_slist_free_full(result, g_free);
 }