From d3be19ac6980129bc9d5dab08793afec0f125f84 Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 21 Apr 2017 20:06:06 +0000 Subject: [PATCH] now actually do comparisons for sorting ASCIIbetically --- edit.c | 6 +++--- eval.c | 4 ++-- main.c | 4 ++-- misc.c | 24 +++++++++++++++++++----- sh.h | 5 +++-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/edit.c b/edit.c index e1ed209..1d60306 100644 --- a/edit.c +++ b/edit.c @@ -28,7 +28,7 @@ #ifndef MKSH_NO_CMDLINE_EDITING -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.323 2017/04/21 19:50:06 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.324 2017/04/21 20:06:03 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -468,7 +468,7 @@ path_order_cmp(const void *aa, const void *bb) const struct path_order_info *b = (const struct path_order_info *)bb; int t; - if ((t = strcmp(a->word + a->base, b->word + b->base))) + if ((t = ascstrcmp(a->word + a->base, b->word + b->base))) return (t); if (a->path_order > b->path_order) return (1); @@ -536,7 +536,7 @@ x_command_glob(int flags, char *toglob, char ***wordsp) char **words = (char **)XPptrv(w); size_t i, j; - qsort(words, nwords, sizeof(void *), xstrcmp); + qsort(words, nwords, sizeof(void *), ascpstrcmp); for (i = j = 0; i < nwords - 1; i++) { if (strcmp(words[i], words[i + 1])) words[j++] = words[i]; diff --git a/eval.c b/eval.c index 23894d6..0b1c7c5 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.201 2017/04/06 01:59:54 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.202 2017/04/21 20:06:04 tg Exp $"); /* * string expansion @@ -1555,7 +1555,7 @@ glob(char *cp, XPtrV *wp, bool markdirs) XPput(*wp, debunk(cp, cp, strlen(cp) + 1)); else qsort(XPptrv(*wp) + oldsize, XPsize(*wp) - oldsize, - sizeof(void *), xstrcmp); + sizeof(void *), ascpstrcmp); } #define GF_NONE 0 diff --git a/main.c b/main.c index a556d5d..36dd2be 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.332 2017/04/12 16:01:45 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.333 2017/04/21 20:06:04 tg Exp $"); extern char **environ; @@ -1887,7 +1887,7 @@ tnamecmp(const void *p1, const void *p2) const struct tbl *a = *((const struct tbl * const *)p1); const struct tbl *b = *((const struct tbl * const *)p2); - return (strcmp(a->name, b->name)); + return (ascstrcmp(a->name, b->name)); } struct tbl ** diff --git a/misc.c b/misc.c index 8ab4c49..d072862 100644 --- a/misc.c +++ b/misc.c @@ -30,7 +30,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.257 2017/04/21 19:50:08 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.258 2017/04/21 20:06:05 tg Exp $"); #define KSH_CHVT_FLAG #ifdef MKSH_SMALL @@ -512,7 +512,7 @@ parse_args(const char **argv, for (i = go.optind; argv[i]; i++) ; qsort(&argv[go.optind], i - go.optind, sizeof(void *), - xstrcmp); + ascpstrcmp); } if (arrayset) go.optind += set_array(array, tobool(arrayset > 0), @@ -661,7 +661,7 @@ gmatchx(const char *s, const char *p, bool isfile) pe = p + strlen(p); /* * isfile is false iff no syntax check has been done on - * the pattern. If check fails, just to a strcmp(). + * the pattern. If check fails, just do a strcmp(). */ if (!isfile && !has_globbing(p, pe)) { size_t len = pe - p + 1; @@ -957,9 +957,23 @@ pat_scan(const unsigned char *p, const unsigned char *pe, bool match_sep) } int -xstrcmp(const void *p1, const void *p2) +ascstrcmp(const void *s1, const void *s2) { - return (strcmp(*(const char * const *)p1, *(const char * const *)p2)); + const uint8_t *cp1 = s1, *cp2 = s2; + + while (*cp1 == *cp2) { + if (*cp1++ == '\0') + return (0); + ++cp2; + } + return (asc(*cp1) - asc(*cp2)); +} + +int +ascpstrcmp(const void *pstr1, const void *pstr2) +{ + return (ascstrcmp(*(const char * const *)pstr1, + *(const char * const *)pstr2)); } /* Initialise a Getopt structure */ diff --git a/sh.h b/sh.h index 1c7c2d4..151c7c7 100644 --- a/sh.h +++ b/sh.h @@ -175,7 +175,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.812 2017/04/21 19:50:09 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.813 2017/04/21 20:06:06 tg Exp $"); #endif #define MKSH_VERSION "R55 2017/04/20" @@ -2289,7 +2289,8 @@ int parse_args(const char **, int, bool *); int getn(const char *, int *); int gmatchx(const char *, const char *, bool); int has_globbing(const char *, const char *) MKSH_A_PURE; -int xstrcmp(const void *, const void *) MKSH_A_PURE; +int ascstrcmp(const void *, const void *) MKSH_A_PURE; +int ascpstrcmp(const void *, const void *) MKSH_A_PURE; void ksh_getopt_reset(Getopt *, int); int ksh_getopt(const char **, Getopt *, const char *); void print_value_quoted(struct shf *, const char *);