From 4ee2355a9e242cb45f9bebfbc4b932b0a98b0172 Mon Sep 17 00:00:00 2001 From: "Zephaniah E. Hull" Date: Sun, 2 Apr 2000 12:13:19 +0000 Subject: [PATCH] The sorting works perfectly now! --- common/lib_replace.c | 49 ++++++++++++++++++++++---------------------- common/quakefs.c | 6 ++++-- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/common/lib_replace.c b/common/lib_replace.c index 11f77d3..3725b35 100644 --- a/common/lib_replace.c +++ b/common/lib_replace.c @@ -30,6 +30,7 @@ #include #include +#include /* ============================================================================ @@ -175,33 +176,33 @@ float Q_atof (char *str) // Note, this is /NOT/ a work-alike strcmp, this groups numbers sanely. //int Q_qstrcmp(const char *val, const char *ref) -int Q_qstrcmp(const char *ref, const char *val) +int Q_qstrcmp(char **os1, char **os2) { - int vc, rc; - long vl, rl; - const char *vp, *rp; + int in1, in2, n1, n2; + char *s1, *s2; + s1 = *os1; + s2 = *os2; - if (!val) val= ""; - if (!ref) ref= ""; - for (;;) { - vp= val; while (*vp && !isdigit(*vp)) vp++; - rp= ref; while (*rp && !isdigit(*rp)) rp++; - for (;;) { - vc= val == vp ? 0 : *val++; - rc= ref == rp ? 0 : *ref++; - if (!rc && !vc) break; - if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */ - if (rc && !isalpha(rc)) rc += 256; - if (vc != rc) return vc - rc; + while (1) { + in1 = in2 = n1 = n2 = 0; + + if ((in1 = isdigit(*s1))) + n1 = strtol(s1, &s1, 10); + + if ((in2 = isdigit(*s2))) + n2 = strtol(s2, &s2, 10); + + if (in1 && in2) { + if (n1 != n2) + return n1-n2; + } else { + if (*s1 != *s2) + return *s1 - *s2; + else if (*s1 == '\0') + return *s1 - *s2; + s1++; + s2++; } - val= vp; - ref= rp; - vl=0; if (isdigit(*vp)) vl= strtol(val,(char**)&val,10); - rl=0; if (isdigit(*rp)) rl= strtol(ref,(char**)&ref,10); - if (vl != rl) return vl - rl; - if (!*val && !*ref) return 0; - if (!*val) return -1; - if (!*ref) return +1; } } diff --git a/common/quakefs.c b/common/quakefs.c index 8d7a160..48bd0c8 100644 --- a/common/quakefs.c +++ b/common/quakefs.c @@ -756,8 +756,10 @@ COM_LoadGameDirectory(char *dir) } closedir(dir_ptr); - qsort(pakfiles, count - 1, sizeof(char *), - (int (*)(const void *, const void *)) strcmp); + // XXX WARNING!!! This is /NOT/ subtable for strcmp!!!!! + // This passes 'char **' instead of 'char *' to the cmp function! + qsort(pakfiles, count, sizeof(char *), + (int (*)(const void *, const void *)) Q_qstrcmp); for (i = 0; i < count; i++) { pak = COM_LoadPackFile(pakfiles[i]);