From 8beb3d8a2e264078e43f0c80ff44b14d08d3c49c Mon Sep 17 00:00:00 2001 From: apartfromtime <42292382+apartfromtime@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:27:51 +1100 Subject: [PATCH] Case insensitive sort for player skins Case insensitive compare in quicksort compare function for player names. Closes #1082 --- src/client/menu/menu.c | 2 +- src/common/header/shared.h | 3 +++ src/common/shared/shared.c | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/client/menu/menu.c b/src/client/menu/menu.c index 1783688f..0c77615a 100644 --- a/src/client/menu/menu.c +++ b/src/client/menu/menu.c @@ -5650,7 +5650,7 @@ PlayerModelList(void) } // sort skin names alphabetically - qsort(s_skinnames[mdl].data, s_skinnames[mdl].num, sizeof(char**), Q_sort_strcomp); + qsort(s_skinnames[mdl].data, s_skinnames[mdl].num, sizeof(char**), Q_sort_stricmp); // at this point we have a valid player model s = (char*)malloc(MAX_DISPLAYNAME); diff --git a/src/common/header/shared.h b/src/common/header/shared.h index ed341eb3..89f1eecb 100644 --- a/src/common/header/shared.h +++ b/src/common/header/shared.h @@ -333,6 +333,9 @@ int Q_strlcat(char *dst, const char *src, int size); /* Unicode wrappers that also make sure it's a regular file around fopen(). */ FILE *Q_fopen(const char *file, const char *mode); +/* Comparator function for qsort(), compares case-insensitive strings. */ +int Q_sort_stricmp(const void *s1, const void *s2); + /* Comparator function for qsort(), compares strings. */ int Q_sort_strcomp(const void *s1, const void *s2); diff --git a/src/common/shared/shared.c b/src/common/shared/shared.c index fc066d54..34aa155e 100644 --- a/src/common/shared/shared.c +++ b/src/common/shared/shared.c @@ -1188,6 +1188,12 @@ FILE *Q_fopen(const char *file, const char *mode) } #endif +int +Q_sort_stricmp(const void *s1, const void *s2) +{ + return Q_stricmp(*(char**)s1, *(char**)s2); +} + int Q_sort_strcomp(const void *s1, const void *s2) {