From 74a63e13c10274dc5a7d38d4a823d9e1e811871f Mon Sep 17 00:00:00 2001 From: "p.kosyh" Date: Tue, 9 Feb 2010 19:07:49 +0000 Subject: [PATCH] games and themes sorting --- src/sdl-instead/game.c | 13 +++++++++++++ src/sdl-instead/themes.c | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/sdl-instead/game.c b/src/sdl-instead/game.c index 861a6f3..bad727d 100644 --- a/src/sdl-instead/game.c +++ b/src/sdl-instead/game.c @@ -97,6 +97,18 @@ err: return strdup(d_name); } +static int cmp_game(const void *p1, const void *p2) +{ + const struct game *g1 = (const struct game*)p1; + const struct game *g2 = (const struct game*)p2; + return strcmp(g1->name, g2->name); +} + +static void games_sort() +{ + qsort(games, games_nr, sizeof(struct game), cmp_game); +} + int games_lookup(const char *path) { char *p; @@ -136,6 +148,7 @@ int games_lookup(const char *path) } out: closedir(d); + games_sort(); return 0; } diff --git a/src/sdl-instead/themes.c b/src/sdl-instead/themes.c index 4d60a70..8c86aa6 100644 --- a/src/sdl-instead/themes.c +++ b/src/sdl-instead/themes.c @@ -475,6 +475,18 @@ err: return strdup(d_name); } +static int cmp_theme(const void *p1, const void *p2) +{ + const struct theme *t1 = (const struct theme*)p1; + const struct theme *t2 = (const struct theme*)p2; + return strcmp(t1->name, t2->name); +} + +static void themes_sort() +{ + qsort(themes, themes_nr, sizeof(struct theme), cmp_theme); +} + int themes_lookup(const char *path) { char *p; @@ -512,6 +524,7 @@ int themes_lookup(const char *path) } out: closedir(d); + themes_sort(); return 0; }