From b800aa894fcedb2532e9e6c34b1db1ce87c5e2a5 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Sat, 9 Mar 2013 01:36:25 +0100
Subject: [PATCH] Changed url_history_get_all to add the entries to existing
 given list.

This will allow us to combine url history and later to implement bookmarks in
a single completion list.
---
 src/completion.c  |  4 ++--
 src/url_history.c | 10 ++++------
 src/url_history.h |  2 +-
 3 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/completion.c b/src/completion.c
index d34410f..b5a1e8b 100644
--- a/src/completion.c
+++ b/src/completion.c
@@ -77,14 +77,14 @@ gboolean completion_complete(Client* c, gboolean back)
             c->comps.completions, source, (Comp_Func)g_str_has_prefix, &input[5], ":set "
         );
     } else if (!strncmp(input, ":open ", 6)) {
-        source = url_history_get_all();
+        url_history_get_all(&source);
         c->comps.completions = completion_init_completion(
             c,
             c->comps.completions, source, (Comp_Func)util_strcasestr, &input[6], ":open "
         );
         g_list_free(source);
     } else if (!strncmp(input, ":tabopen ", 9)) {
-        source = url_history_get_all();
+        url_history_get_all(&source);
         c->comps.completions = completion_init_completion(
             c,
             c->comps.completions, source, (Comp_Func)util_strcasestr, &input[9], ":tabopen "
diff --git a/src/url_history.c b/src/url_history.c
index 1c0f729..a2bc8b3 100644
--- a/src/url_history.c
+++ b/src/url_history.c
@@ -87,19 +87,17 @@ void url_history_add(const char* url, const char* title)
 }
 
 /**
- * Retrieves the ur history as ne allocated list.
+ * Appends the url history entries to given list.
  */
-GList* url_history_get_all(void)
+void url_history_get_all(GList** list)
 {
-    GList* out = NULL;
     for (GList* link = core.behave.url_history; link; link = link->next) {
         UrlHist* hi = (UrlHist*)link->data;
         /* put only the url in the list - do not allocate new memory */
-        out = g_list_prepend(out, hi->uri);
+        *list = g_list_prepend(*list, hi->uri);
     }
 
-    out = g_list_reverse(out);
-    return out;
+    *list = g_list_reverse(*list);
 }
 
 static void url_history_free(UrlHist* item)
diff --git a/src/url_history.h b/src/url_history.h
index 32bd86a..7e2cabd 100644
--- a/src/url_history.h
+++ b/src/url_history.h
@@ -9,6 +9,6 @@ typedef struct {
 void url_history_init(void);
 void url_history_cleanup(void);
 void url_history_add(const char* url, const char* title);
-GList* url_history_get_all(void);
+void url_history_get_all(GList** list);
 
 #endif /* end of include guard: _URL_HISTORY_H */
-- 
2.20.1