mirror of
https://git.code.sf.net/p/quake/quakeforge-old
synced 2025-02-12 14:55:58 +00:00
The sorting works perfectly now!
This commit is contained in:
parent
f8d071a6fd
commit
4ee2355a9e
2 changed files with 29 additions and 26 deletions
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
============================================================================
|
============================================================================
|
||||||
|
@ -175,33 +176,33 @@ float Q_atof (char *str)
|
||||||
|
|
||||||
// Note, this is /NOT/ a work-alike strcmp, this groups numbers sanely.
|
// 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 *val, const char *ref)
|
||||||
int Q_qstrcmp(const char *ref, const char *val)
|
int Q_qstrcmp(char **os1, char **os2)
|
||||||
{
|
{
|
||||||
int vc, rc;
|
int in1, in2, n1, n2;
|
||||||
long vl, rl;
|
char *s1, *s2;
|
||||||
const char *vp, *rp;
|
s1 = *os1;
|
||||||
|
s2 = *os2;
|
||||||
|
|
||||||
if (!val) val= "";
|
while (1) {
|
||||||
if (!ref) ref= "";
|
in1 = in2 = n1 = n2 = 0;
|
||||||
for (;;) {
|
|
||||||
vp= val; while (*vp && !isdigit(*vp)) vp++;
|
if ((in1 = isdigit(*s1)))
|
||||||
rp= ref; while (*rp && !isdigit(*rp)) rp++;
|
n1 = strtol(s1, &s1, 10);
|
||||||
for (;;) {
|
|
||||||
vc= val == vp ? 0 : *val++;
|
if ((in2 = isdigit(*s2)))
|
||||||
rc= ref == rp ? 0 : *ref++;
|
n2 = strtol(s2, &s2, 10);
|
||||||
if (!rc && !vc) break;
|
|
||||||
if (vc && !isalpha(vc)) vc += 256; /* assumes ASCII character set */
|
if (in1 && in2) {
|
||||||
if (rc && !isalpha(rc)) rc += 256;
|
if (n1 != n2)
|
||||||
if (vc != rc) return vc - rc;
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -756,8 +756,10 @@ COM_LoadGameDirectory(char *dir)
|
||||||
}
|
}
|
||||||
closedir(dir_ptr);
|
closedir(dir_ptr);
|
||||||
|
|
||||||
qsort(pakfiles, count - 1, sizeof(char *),
|
// XXX WARNING!!! This is /NOT/ subtable for strcmp!!!!!
|
||||||
(int (*)(const void *, const void *)) 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++) {
|
for (i = 0; i < count; i++) {
|
||||||
pak = COM_LoadPackFile(pakfiles[i]);
|
pak = COM_LoadPackFile(pakfiles[i]);
|
||||||
|
|
Loading…
Reference in a new issue