From b5c78cf68bbcc33f2facab4b35528c86f01d9573 Mon Sep 17 00:00:00 2001 From: Dylan G <1565516+Helloman892@users.noreply.github.com> Date: Sun, 15 Oct 2017 13:18:53 +0100 Subject: [PATCH] Implemented alphanum quicksort --- include/themes.h | 1 + source/themes.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/include/themes.h b/include/themes.h index 6224fe9..b5f82eb 100644 --- a/include/themes.h +++ b/include/themes.h @@ -51,6 +51,7 @@ int theme_count; void load_theme_preview(Theme_s *theme); Result get_themes(Theme_s **themes_list, int *theme_count); +int themecmp(const void* a, const void* b); void del_theme(u16 *path); Result single_install(Theme_s theme); Result shuffle_install(Theme_s *themes_list, int theme_count); diff --git a/source/themes.c b/source/themes.c index 9d4febb..e2f9094 100644 --- a/source/themes.c +++ b/source/themes.c @@ -201,10 +201,20 @@ Result get_themes(Theme_s **themes_list, int *theme_count) } FSDIR_Close(dir_handle); + + qsort(*themes_list, (long)*theme_count, sizeof(Theme_s), themecmp); //alphabet sort return res; } +int themecmp(const void* a, const void* b) //essentially a memcmp alias, so that it can be used properly with qsort +{ + Theme_s *theme_a = (Theme_s *)a; + Theme_s *theme_b = (Theme_s *)b; + + return memcmp(theme_a, theme_b, 0x40*sizeof(u16)); +} + void del_theme(u16 *path) { Handle dir_handle;