From 712e4bd4081234c0bea755b38400e659d2e1738d Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Sat, 15 Oct 2011 18:42:30 +0200 Subject: [PATCH] use the correct sorting function --- bookmarks.c | 15 +++++++++++++++ bookmarks.h | 8 ++++++++ database-plain.c | 3 ++- database-sqlite.c | 4 ++-- zathura.c | 2 +- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/bookmarks.c b/bookmarks.c index 202f29d..557eac9 100644 --- a/bookmarks.c +++ b/bookmarks.c @@ -97,3 +97,18 @@ zathura_bookmarks_load(zathura_t* zathura, const gchar* file) { return true; } +int +zathura_bookmarks_compare(zathura_bookmark_t* lhs, zathura_bookmark_t* rhs) +{ + if (lhs == NULL && rhs == NULL) { + return 0; + } + if (lhs == NULL) { + return -1; + } + if (rhs == NULL) { + return 1; + } + + return g_strcmp0(lhs->id, rhs->id); +} diff --git a/bookmarks.h b/bookmarks.h index 156375a..34bfe84 100644 --- a/bookmarks.h +++ b/bookmarks.h @@ -53,4 +53,12 @@ void zathura_bookmark_free(zathura_bookmark_t* bookmark); */ bool zathura_bookmarks_load(zathura_t* zathura, const gchar* file); +/** + * Compare two bookmarks. + * @param lhs a bookmark + * @param rhs a bookmark + * @returns g_strcmp0(lhs->id, rhs->id) + */ +int zathura_bookmarks_compare(zathura_bookmark_t* lhs, zathura_bookmark_t* rhs); + #endif // BOOKMARKS_H diff --git a/database-plain.c b/database-plain.c index 94435d8..1c3c6b1 100644 --- a/database-plain.c +++ b/database-plain.c @@ -194,7 +194,8 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file) return NULL; } - girara_list_t* result = girara_list_new(); + girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, + (girara_free_function_t) zathura_bookmark_free); if (result == NULL) { return NULL; } diff --git a/database-sqlite.c b/database-sqlite.c index 61e698b..f6ef6cf 100644 --- a/database-sqlite.c +++ b/database-sqlite.c @@ -182,12 +182,12 @@ zathura_db_load_bookmarks(zathura_database_t* db, const char* file) return NULL; } - girara_list_t* result = girara_list_new(); + girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, + (girara_free_function_t) zathura_bookmark_free); if (result == NULL) { sqlite3_finalize(stmt); return NULL; } - girara_list_set_free_function(result, (girara_free_function_t) zathura_bookmark_free); while (sqlite3_step(stmt) == SQLITE_ROW) { zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t)); diff --git a/zathura.c b/zathura.c index f7ede62..9d5c9a7 100644 --- a/zathura.c +++ b/zathura.c @@ -211,7 +211,7 @@ zathura_init(int argc, char* argv[]) } /* bookmarks */ - zathura->bookmarks.bookmarks = girara_sorted_list_new2((girara_compare_function_t) g_strcmp0, + zathura->bookmarks.bookmarks = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, (girara_free_function_t) zathura_bookmark_free); /* open document if passed */