summaryrefslogtreecommitdiff
path: root/Src/sort.c
diff options
context:
space:
mode:
Diffstat (limited to 'Src/sort.c')
-rw-r--r--Src/sort.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/Src/sort.c b/Src/sort.c
index 92ee1c0d4..8faf9349c 100644
--- a/Src/sort.c
+++ b/Src/sort.c
@@ -33,6 +33,9 @@
/* Flag for direction of sort: 1 forwards, -1 reverse */
static int sortdir;
+/* Flag that sort ignores backslashes */
+static int sortnobslash;
+
/* Flag that sort is numeric */
static int sortnumeric;
@@ -113,9 +116,24 @@ eltpcmp(const void *a, const void *b)
bs += (laststarta - as);
as += (laststarta - as);
}
+
+ if (sortnobslash) {
+ while (*as && *bs) {
+ if (*as == '\\')
+ as++;
+ if (*bs == '\\')
+ bs++;
+ if (*as != *bs || !*as)
+ break;
+ as++;
+ bs++;
+ }
+ }
+
#ifdef HAVE_STRCOLL
cmp = strcoll(as, bs);
#endif
+
if (sortnumeric) {
for (; *as == *bs && *as; as++, bs++);
#ifndef HAVE_STRCOLL
@@ -162,7 +180,10 @@ mod_export int
zstrcmp(const char *as, const char *bs, int sortflags)
{
struct sortelt ae, be, *aeptr, *beptr;
- int oldsortdir = sortdir, oldsortnumeric = sortnumeric, ret;
+ int oldsortdir = sortdir;
+ int oldsortnobslash = sortnobslash;
+ int oldsortnumeric = sortnumeric;
+ int ret;
ae.cmp = as;
be.cmp = bs;
@@ -173,11 +194,13 @@ zstrcmp(const char *as, const char *bs, int sortflags)
beptr = &be;
sortdir = 1;
+ sortnobslash = (sortflags & SORTIT_IGNORING_BACKSLASHES) ? 1 : 0;
sortnumeric = (sortflags & SORTIT_NUMERICALLY) ? 1 : 0;
ret = eltpcmp(&aeptr, &beptr);
/* Paranoia: I don't think we ever need to restore these. */
+ sortnobslash = oldsortnobslash;
sortnumeric = oldsortnumeric;
sortdir = oldsortdir;
@@ -227,7 +250,7 @@ strmetasort(char **array, int sortwhat, int *unmetalenp)
if (unmetalenp) {
/*
* Already unmetafied. We just need to check for
- * embededded nulls.
+ * embedded nulls.
*/
int count = unmetalenp[arrptr-array];
/* Remember this length for sorted array */