From 5ed882763af2003fcd5b3a945bd4d2a50e340ef9 Mon Sep 17 00:00:00 2001 From: Yamagi Date: Mon, 19 Oct 2020 17:17:09 +0200 Subject: [PATCH] Implement one qsort() comparator function for strings and use it. --- src/common/cmdparser.c | 8 +------- src/common/filesystem.c | 4 +--- src/common/header/shared.h | 3 +++ src/common/shared/shared.c | 6 ++++++ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/common/cmdparser.c b/src/common/cmdparser.c index 7576e304..83026ad3 100644 --- a/src/common/cmdparser.c +++ b/src/common/cmdparser.c @@ -786,12 +786,6 @@ Cmd_Exists(char *cmd_name) return false; } -int -qsort_strcomp(const void *s1, const void *s2) -{ - return strcmp(*(char **)s1, *(char **)s2); -} - char * Cmd_CompleteCommand(char *partial) { @@ -877,7 +871,7 @@ Cmd_CompleteCommand(char *partial) } /* Sort it */ - qsort(pmatch, i, sizeof(pmatch[0]), qsort_strcomp); + qsort(pmatch, i, sizeof(pmatch[0]), Q_sort_strcomp); Com_Printf("\n\n"); diff --git a/src/common/filesystem.c b/src/common/filesystem.c index e937da37..6599fa4f 100644 --- a/src/common/filesystem.c +++ b/src/common/filesystem.c @@ -1802,8 +1802,6 @@ FS_InitFilesystem(void) Com_Printf("Using '%s' for writing.\n", fs_gamedir); } -extern int qsort_strcomp(const void *s1, const void *s2); - /* * Combs all Raw search paths to find game dirs containing PAK/PK2/PK3 files. * Returns an alphabetized array of unique relative dir names. @@ -1894,7 +1892,7 @@ FS_ListMods(int *nummods) modnames[nmods] = 0; - qsort(modnames, nmods, sizeof(modnames[0]), qsort_strcomp); + qsort(modnames, nmods, sizeof(modnames[0]), Q_sort_strcomp); *nummods = nmods; return modnames; diff --git a/src/common/header/shared.h b/src/common/header/shared.h index 26f6eb07..c6c21341 100644 --- a/src/common/header/shared.h +++ b/src/common/header/shared.h @@ -290,6 +290,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 strings. */ +int Q_sort_strcomp(const void *s1, const void *s2); + /* ============================================= */ short BigShort(short l); diff --git a/src/common/shared/shared.c b/src/common/shared/shared.c index 4653b518..d74e2cd7 100644 --- a/src/common/shared/shared.c +++ b/src/common/shared/shared.c @@ -1195,6 +1195,12 @@ FILE *Q_fopen(const char *file, const char *mode) } #endif +int +Q_sort_strcomp(const void *s1, const void *s2) +{ + return strcmp(*(char **)s1, *(char **)s2); +} + /* * ===================================================================== *