summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorDaniel Carl <danielcarl@gmx.de>2013-07-14 21:56:41 +0200
committerDaniel Carl <danielcarl@gmx.de>2013-07-14 22:55:03 +0200
commit871224a7e74b429011345ffd4d8f0d2a8f903c2b (patch)
treeb1a10bf44bd9eea4d513d333e8de6e11cf31486f /src/util.c
parent401fd0c554ddd2de5af1e08a631e2529d33e0302 (diff)
Save also page title in history file (#46).
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 13128f9..03c81bb 100644
--- a/src/util.c
+++ b/src/util.c
@@ -98,6 +98,44 @@ char **util_get_lines(const char *filename)
return lines;
}
+GList *util_file_to_unique_list(const char *filename, Util_Content_Func func,
+ GCompareFunc unique_func, GDestroyNotify free_func)
+{
+ GList *gl = NULL;
+ char *line, **lines = util_get_lines(filename);
+ void *value;
+ int len;
+
+ len = g_strv_length(lines);
+ if (!len) {
+ return gl;
+ }
+
+ for (int i = 0; i < len; i++) {
+ line = lines[i];
+ g_strstrip(line);
+ if (*line == '\0') {
+ continue;
+ }
+
+ if ((value = func(line))) {
+ /* if the value is already in list, remove this entry */
+ for (GList *l = gl; l; l = l->next) {
+ if (!unique_func(value, l->data)) {
+ free_func(l->data);
+ gl = g_list_delete_link(gl, l);
+ break;
+ }
+ }
+ gl = g_list_prepend(gl, value);
+ }
+ }
+ g_strfreev(lines);
+ gl = g_list_reverse(gl);
+
+ return gl;
+}
+
char *util_strcasestr(const char *haystack, const char *needle)
{
unsigned char c1, c2;