now actually do comparisons for sorting ASCIIbetically

This commit is contained in:
tg 2017-04-21 20:06:06 +00:00
parent e18a509a80
commit d3be19ac69
5 changed files with 29 additions and 14 deletions

6
edit.c
View File

@ -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];

4
eval.c
View File

@ -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

4
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#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 **

24
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#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 */

5
sh.h
View File

@ -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 *);