From ef6515f07852d6a353e853e0382cfec1d0a329a5 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Dec 2013 23:44:11 +0000 Subject: [PATCH 1/4] Removed unused prototypes from autocomplete.h --- src/tools/autocomplete.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index 908e273e..b14d48b8 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -27,14 +27,8 @@ typedef char*(*autocomplete_func)(char *); typedef struct autocomplete_t *Autocomplete; -typedef const char * (*PStrFunc)(const void *obj); -typedef void * (*PCopyFunc)(const void *obj); -typedef int (*PEqualFunc)(const void *o1, const void *o2); -typedef int (*PEqualDeepFunc)(const void *o1, const void *o2); Autocomplete autocomplete_new(void); -Autocomplete obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func, - PEqualDeepFunc equal_deep_func, GDestroyNotify free_func); void autocomplete_clear(Autocomplete ac); void autocomplete_reset(Autocomplete ac); void autocomplete_free(Autocomplete ac); From 0de1ff9b4de65ddca37186c943abf49a03cf8c30 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Dec 2013 23:51:13 +0000 Subject: [PATCH 2/4] Removed unused boolean result from autocomplete add and remove --- src/tools/autocomplete.c | 12 ++++++------ src/tools/autocomplete.h | 4 ++-- tests/test_autocomplete.c | 37 ------------------------------------- 3 files changed, 8 insertions(+), 45 deletions(-) diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index 438b48b7..ee8b5437 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -82,7 +82,7 @@ autocomplete_length(Autocomplete ac) } } -gboolean +void autocomplete_add(Autocomplete ac, const char *item) { char *item_cpy; @@ -90,21 +90,21 @@ autocomplete_add(Autocomplete ac, const char *item) // if item already exists if (curr != NULL) { - return FALSE; + return; } item_cpy = strdup(item); ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp); - return TRUE; + return; } -gboolean +void autocomplete_remove(Autocomplete ac, const char * const item) { GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp); if (!curr) { - return FALSE; + return; } // reset last found if it points to the item to be removed @@ -115,7 +115,7 @@ autocomplete_remove(Autocomplete ac, const char * const item) free(curr->data); ac->items = g_slist_delete_link(ac->items, curr); - return TRUE; + return; } GSList * diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index b14d48b8..dd7a0699 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -32,8 +32,8 @@ Autocomplete autocomplete_new(void); void autocomplete_clear(Autocomplete ac); void autocomplete_reset(Autocomplete ac); void autocomplete_free(Autocomplete ac); -gboolean autocomplete_add(Autocomplete ac, const char *item); -gboolean autocomplete_remove(Autocomplete ac, const char * const item); +void autocomplete_add(Autocomplete ac, const char *item); +void autocomplete_remove(Autocomplete ac, const char * const item); GSList * autocomplete_get_list(Autocomplete ac); gchar * autocomplete_complete(Autocomplete ac, gchar *search_str); gint autocomplete_length(Autocomplete ac); diff --git a/tests/test_autocomplete.c b/tests/test_autocomplete.c index 77525035..58a0e596 100644 --- a/tests/test_autocomplete.c +++ b/tests/test_autocomplete.c @@ -113,40 +113,6 @@ static void add_two_same_updates(void) autocomplete_clear(ac); } -static void add_one_returns_true(void) -{ - Autocomplete ac = autocomplete_new(); - int result = autocomplete_add(ac, "Hello"); - - assert_true(result); - - autocomplete_clear(ac); -} - -static void add_two_different_returns_true(void) -{ - Autocomplete ac = autocomplete_new(); - int result1 = autocomplete_add(ac, "Hello"); - int result2 = autocomplete_add(ac, "Hello there"); - - assert_true(result1); - assert_true(result2); - - autocomplete_clear(ac); -} - -static void add_two_same_returns_false(void) -{ - Autocomplete ac = autocomplete_new(); - int result1 = autocomplete_add(ac, "Hello"); - int result2 = autocomplete_add(ac, "Hello"); - - assert_true(result1); - assert_false(result2); - - autocomplete_clear(ac); -} - void register_autocomplete_tests(void) { TEST_MODULE("autocomplete tests"); @@ -160,7 +126,4 @@ void register_autocomplete_tests(void) TEST(add_two_adds_two); TEST(add_two_same_adds_one); TEST(add_two_same_updates); - TEST(add_one_returns_true); - TEST(add_two_different_returns_true); - TEST(add_two_same_returns_false); } From 67dead32af7fe8a69543130e4bb1e405830a94c6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 9 Dec 2013 23:53:52 +0000 Subject: [PATCH 3/4] Tidy autocomplete.h --- src/tools/autocomplete.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index dd7a0699..bf20020a 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -29,18 +29,24 @@ typedef char*(*autocomplete_func)(char *); typedef struct autocomplete_t *Autocomplete; Autocomplete autocomplete_new(void); + void autocomplete_clear(Autocomplete ac); void autocomplete_reset(Autocomplete ac); void autocomplete_free(Autocomplete ac); + void autocomplete_add(Autocomplete ac, const char *item); void autocomplete_remove(Autocomplete ac, const char * const item); -GSList * autocomplete_get_list(Autocomplete ac); gchar * autocomplete_complete(Autocomplete ac, gchar *search_str); + +GSList * autocomplete_get_list(Autocomplete ac); gint autocomplete_length(Autocomplete ac); + char * autocomplete_param_with_func(char *input, int *size, char *command, autocomplete_func func); + char * autocomplete_param_with_ac(char *input, int *size, char *command, Autocomplete ac); + char * autocomplete_param_no_with_func(char *input, int *size, char *command, int arg_number, autocomplete_func func); From e27061b131d9ec9e37690e4759d7264d0393a547 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 10 Dec 2013 00:06:00 +0000 Subject: [PATCH 4/4] Added comments to autocomplete.h --- src/tools/autocomplete.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools/autocomplete.h b/src/tools/autocomplete.h index bf20020a..0a3b5b88 100644 --- a/src/tools/autocomplete.h +++ b/src/tools/autocomplete.h @@ -28,14 +28,19 @@ typedef char*(*autocomplete_func)(char *); typedef struct autocomplete_t *Autocomplete; +// allocate new autocompleter with no items Autocomplete autocomplete_new(void); +// Remove all items from the autocompleter void autocomplete_clear(Autocomplete ac); -void autocomplete_reset(Autocomplete ac); + +// free all memory used by the autocompleter void autocomplete_free(Autocomplete ac); void autocomplete_add(Autocomplete ac, const char *item); 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); GSList * autocomplete_get_list(Autocomplete ac); @@ -50,4 +55,5 @@ char * autocomplete_param_with_ac(char *input, int *size, char *command, char * autocomplete_param_no_with_func(char *input, int *size, char *command, int arg_number, autocomplete_func func); +void autocomplete_reset(Autocomplete ac); #endif