summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-04-19 12:01:05 +0100
committerVincent Sanders <vince@kyllikki.org>2016-04-19 12:01:05 +0100
commitafea659fefe263040088e6dc8813cb18a6f3d219 (patch)
treed8d9e7cd71fa3019622b63bcb0f264a372074065
parent1bc010665e53bdf226370ab12a7ae3f87250df4d (diff)
downloadnetsurf-afea659fefe263040088e6dc8813cb18a6f3d219.tar.gz
netsurf-afea659fefe263040088e6dc8813cb18a6f3d219.tar.bz2
move dir_sort_alpha function from generic utils to one specific place it is used
-rw-r--r--content/fetchers/file.c43
-rw-r--r--utils/utils.c35
-rw-r--r--utils/utils.h11
3 files changed, 43 insertions, 46 deletions
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index ff40386fe..d13b4d56a 100644
--- a/content/fetchers/file.c
+++ b/content/fetchers/file.c
@@ -24,6 +24,7 @@
#include "utils/config.h"
+#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -601,6 +602,48 @@ process_dir_ent(struct fetch_file_context *ctx,
return NSERROR_OK;
}
+/**
+ * Comparison function for sorting directories.
+ *
+ * Correctly orders non zero-padded numerical parts.
+ * ie. produces "file1, file2, file10" rather than "file1, file10, file2".
+ *
+ * \param d1 first directory entry
+ * \param d2 second directory entry
+ */
+static int dir_sort_alpha(const struct dirent **d1, const struct dirent **d2)
+{
+ const char *s1 = (*d1)->d_name;
+ const char *s2 = (*d2)->d_name;
+
+ while (*s1 != '\0' && *s2 != '\0') {
+ if ((*s1 >= '0' && *s1 <= '9') &&
+ (*s2 >= '0' && *s2 <= '9')) {
+ int n1 = 0, n2 = 0;
+ while (*s1 >= '0' && *s1 <= '9') {
+ n1 = n1 * 10 + (*s1) - '0';
+ s1++;
+ }
+ while (*s2 >= '0' && *s2 <= '9') {
+ n2 = n2 * 10 + (*s2) - '0';
+ s2++;
+ }
+ if (n1 != n2) {
+ return n1 - n2;
+ }
+ if (*s1 == '\0' || *s2 == '\0')
+ break;
+ }
+ if (tolower(*s1) != tolower(*s2))
+ break;
+
+ s1++;
+ s2++;
+ }
+
+ return tolower(*s1) - tolower(*s2);
+}
+
static void fetch_file_process_dir(struct fetch_file_context *ctx,
struct stat *fdstat)
{
diff --git a/utils/utils.c b/utils/utils.c
index a332f88f7..37839dc48 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -365,41 +365,6 @@ char *strndup(const char *s, size_t n)
#endif
-/* Exported interface, documented in utils.h */
-int dir_sort_alpha(const struct dirent **d1, const struct dirent **d2)
-{
- const char *s1 = (*d1)->d_name;
- const char *s2 = (*d2)->d_name;
-
- while (*s1 != '\0' && *s2 != '\0') {
- if ((*s1 >= '0' && *s1 <= '9') &&
- (*s2 >= '0' && *s2 <= '9')) {
- int n1 = 0, n2 = 0;
- while (*s1 >= '0' && *s1 <= '9') {
- n1 = n1 * 10 + (*s1) - '0';
- s1++;
- }
- while (*s2 >= '0' && *s2 <= '9') {
- n2 = n2 * 10 + (*s2) - '0';
- s2++;
- }
- if (n1 != n2) {
- return n1 - n2;
- }
- if (*s1 == '\0' || *s2 == '\0')
- break;
- }
- if (tolower(*s1) != tolower(*s2))
- break;
-
- s1++;
- s2++;
- }
-
- return tolower(*s1) - tolower(*s2);
-}
-
-
#ifndef HAVE_SCANDIR
/* exported function documented in utils/dirent.h */
diff --git a/utils/utils.h b/utils/utils.h
index ce3158de1..5fa521c01 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -231,17 +231,6 @@ nserror vsnstrjoin(char **str, size_t *size, char sep, size_t nelm, va_list ap);
*/
nserror snstrjoin(char **str, size_t *size, char sep, size_t nelm, ...);
-/**
- * Comparison function for sorting directories.
- *
- * Correctly orders non zero-padded numerical parts.
- * ie. produces "file1, file2, file10" rather than "file1, file10, file2".
- *
- * d1 first directory entry
- * d2 second directory entry
- */
-int dir_sort_alpha(const struct dirent **d1, const struct dirent **d2);
-
/* Platform specific functions */
void warn_user(const char *warning, const char *detail);