From 6c628db56a265115438cab865832455d12e42d5c Mon Sep 17 00:00:00 2001 From: Logan Aerl Arias Date: Wed, 3 Apr 2024 00:54:35 -0400 Subject: [PATCH 1/2] 1st try around sorting the lumps by name --- src/filesrch.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/filesrch.c b/src/filesrch.c index 944e8447f..7ccf532c8 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -699,6 +699,13 @@ static void initdirpath(char *dirpath, size_t *dirpathindex, int depthleft) dirpathindex[depthleft]--; } +//sortdir by name? +static int lumpnamecompare( const void *A, const void *B ) +{ + return strcmp( (((lumpinfo_t *)A)->fullname), (((lumpinfo_t *)B)->fullname)); + +} + lumpinfo_t *getdirectoryfiles(const char *path, UINT16 *nlmp, UINT16 *nfolders) { DIR **dirhandle; @@ -889,6 +896,9 @@ lumpinfo_t *getdirectoryfiles(const char *path, UINT16 *nlmp, UINT16 *nfolders) free(dirpathindex); free(dirhandle); + //sort files and directories + qsort ( lumpinfo, numlumps, sizeof( lumpinfo_t ), lumpnamecompare ); + (*nlmp) = numlumps; return lumpinfo; } From aab11cd87385b399826e2d97dee47cf3b202a218 Mon Sep 17 00:00:00 2001 From: Logan Aerl Arias Date: Wed, 3 Apr 2024 18:42:36 -0400 Subject: [PATCH 2/2] reformat the compare func used in qsort --- src/d_main.c | 12 ++++++++---- src/filesrch.c | 8 +++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index c139650d1..6ced36624 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1842,17 +1842,21 @@ static boolean check_top_dir(const char **path, const char *top) return true; } -static int cmp_strlen_desc(const void *a, const void *b) +static int cmp_strlen_desc(const void *A, const void *B) { - return ((int)strlen(*(const char*const*)b) - (int)strlen(*(const char*const*)a)); + const char *pA = A; + const char *pB = B; + size_t As = strlen(pA); + size_t Bs = strlen(pB); + return ((int)Bs - (int)As); } boolean D_IsPathAllowed(const char *path) { - const char *paths[] = { + char *paths[] = { srb2home, srb2path, - cv_addons_folder.string + cv_addons_folder.zstring }; const size_t n_paths = sizeof paths / sizeof *paths; diff --git a/src/filesrch.c b/src/filesrch.c index 7ccf532c8..3a729a9c8 100644 --- a/src/filesrch.c +++ b/src/filesrch.c @@ -700,9 +700,11 @@ static void initdirpath(char *dirpath, size_t *dirpathindex, int depthleft) } //sortdir by name? -static int lumpnamecompare( const void *A, const void *B ) +static int lumpnamecompare(const void *A, const void *B) { - return strcmp( (((lumpinfo_t *)A)->fullname), (((lumpinfo_t *)B)->fullname)); + const lumpinfo_t *pA = A; + const lumpinfo_t *pB = B; + return strcmp((pA->fullname), (pB->fullname)); } @@ -897,7 +899,7 @@ lumpinfo_t *getdirectoryfiles(const char *path, UINT16 *nlmp, UINT16 *nfolders) free(dirhandle); //sort files and directories - qsort ( lumpinfo, numlumps, sizeof( lumpinfo_t ), lumpnamecompare ); + qsort (lumpinfo, numlumps, sizeof(lumpinfo_t), lumpnamecompare); (*nlmp) = numlumps; return lumpinfo;