From bbeb6fa6d18cb93088f1f2d832cb52c584cb2236 Mon Sep 17 00:00:00 2001 From: nyamatongwe Date: Sun, 27 Aug 2000 09:20:56 +0000 Subject: Fixed sorting to use qsort by implementing a string comparison function rather than passing strcmp in directly. --- src/PropSet.cxx | 38 ++++++-------------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/PropSet.cxx b/src/PropSet.cxx index 60e6922a6..df669a88b 100644 --- a/src/PropSet.cxx +++ b/src/PropSet.cxx @@ -393,41 +393,15 @@ void WordList::SetFromAllocated() { words = ArrayFromWordList(list, &len, onlyLineEnds); } -#ifdef __MINGW32__ -// Shell sort based upon public domain C implementation by Raymond Gardner 1991 -// Used here because of problems with mingw qsort. -static void SortWordList(char **words, unsigned int len) { - unsigned int gap = len / 2; - - while (gap > 0) { - unsigned int i = gap; - while (i < len) { - unsigned int j = i; - char **a = words + j; - do { - j -= gap; - char **b = a; - a -= gap; - if (strcmp(*a, *b) > 0) { - char *tmp = *a; - *a = *b; - *b = tmp; - } else { - break; - } - } while (j >= gap); - i++; - } - gap = gap / 2; - } +int cmpString(const void *a1, const void *a2) { + // Can't work out the correct incantation to use modern casts here + return strcmp(*(char**)(a1), *(char**)(a2)); } -#else -// traditional qsort - hope it works elsewhere... + static void SortWordList(char **words, unsigned int len) { - qsort (reinterpret_cast(words), len, sizeof(*words), - reinterpret_cast(strcmp)); + qsort(reinterpret_cast(words), len, sizeof(*words), + cmpString); } -#endif bool WordList::InList(const char *s) { if (0 == words) -- cgit v1.2.3