about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-05-13 23:35:02 +0100
committerJames Booth <boothj5@gmail.com>2012-05-13 23:35:02 +0100
commit718229d08cf78bd37f9bde916b61661cbbe2828b (patch)
tree041ce5782df46d650177e854a503487e79ff1f51
parent6c9cbc446d405fb7d4a3df254f7c3edf6848e658 (diff)
downloadprofani-tty-718229d08cf78bd37f9bde916b61661cbbe2828b.tar.gz
Autocompletion takes NULL str_func parameter
For cases where the list is made of pure strings,
rather than some struct (void *)
-rw-r--r--prof_autocomplete.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/prof_autocomplete.c b/prof_autocomplete.c
index 4bec0f6c..5d4e90d8 100644
--- a/prof_autocomplete.c
+++ b/prof_autocomplete.c
@@ -75,13 +75,15 @@ void p_autocomplete_add(PAutocomplete ac, void *item, PStrFunc str_func,
         while(curr) {
             
             // insert
-            if (g_strcmp0(str_func(curr->data), str_func(item)) > 0) {
+            if ( ((str_func == NULL) && (g_strcmp0(curr->data, item) > 0)) ||
+                 ((g_strcmp0(str_func(curr->data), str_func(item)) > 0)) ) {
                 ac->items = g_slist_insert_before(ac->items,
                     curr, item);
                 return;
             
             // update
-            } else if (g_strcmp0(str_func(curr->data), str_func(item)) == 0) {
+            } else if ( ((str_func == NULL) && (g_strcmp0(curr->data, item) == 0)) ||
+                        ((g_strcmp0(str_func(curr->data), str_func(item)) == 0)) ) {
                 free_func(curr->data);
                 curr->data = item;
                 return;
@@ -102,7 +104,8 @@ void p_autocomplete_remove(PAutocomplete ac, const char * const item,
 {
     // reset last found if it points to the item to be removed
     if (ac->last_found != NULL)
-        if (g_strcmp0(str_func(ac->last_found->data), item) == 0)
+        if ( ((str_func == NULL) && (g_strcmp0(ac->last_found->data, item) == 0)) ||
+             ((g_strcmp0(str_func(ac->last_found->data), item) == 0)) )
             ac->last_found = NULL;
 
     if (!ac->items) {
@@ -111,7 +114,8 @@ void p_autocomplete_remove(PAutocomplete ac, const char * const item,
         GSList *curr = ac->items;
         
         while(curr) {
-            if (g_strcmp0(str_func(curr->data), item) == 0) {
+            if ( ((str_func == NULL) && (g_strcmp0(curr->data, item) == 0)) ||
+                 ((g_strcmp0(str_func(curr->data), item) == 0)) ) {
                 void *current_item = curr->data;
                 ac->items = g_slist_remove(ac->items, curr->data);
                 free_func(current_item);
@@ -180,9 +184,11 @@ static gchar * _search_from(PAutocomplete ac, GSList *curr, PStrFunc str_func)
     while(curr) {
         
         // match found
-        if (strncmp(str_func(curr->data),
+        if ( ( (str_func == NULL) && (strncmp(curr->data, ac->search_str, 
+                                           strlen(ac->search_str)) == 0) ) ||
+             ( (strncmp(str_func(curr->data),
                 ac->search_str,
-                strlen(ac->search_str)) == 0) {
+                strlen(ac->search_str)) == 0) ) ) {
             gchar *result = 
                 (gchar *) malloc((strlen(str_func(curr->data)) + 1) * sizeof(gchar));