drop the need for strcasestr: just uppercase a copy and compare with uppercased

This commit is contained in:
tg 2012-04-06 12:59:28 +00:00
parent 5e12953cfe
commit 4a89ae1cd0
4 changed files with 29 additions and 48 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.537 2012/04/06 12:57:53 tg Exp $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.538 2012/04/06 12:59:25 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
# 2011, 2012
@ -1371,7 +1371,7 @@ else
#define EXTERN
#define MKSH_INCLUDES_ONLY
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.537 2012/04/06 12:57:53 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/Build.sh,v 1.538 2012/04/06 12:59:25 tg Exp $");
int main(void) { printf("Hello, World!\n"); return (0); }
EOF
case $cm in
@ -1564,18 +1564,6 @@ ac_test setgroups setresugid 0 <<-'EOF'
int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
EOF
ac_test strcasestr <<-'EOF'
#include <sys/types.h>
#include <stddef.h>
#include <string.h>
#if HAVE_STRINGS_H
#include <strings.h>
#endif
int main(int ac, char *av[]) {
return ((int)(ptrdiff_t)(void *)strcasestr(*av, av[ac]));
}
EOF
ac_test strlcpy <<-'EOF'
#include <string.h>
int main(int ac, char *av[]) { return (strlcpy(*av, av[1],

29
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.214 2012/03/31 17:30:00 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.215 2012/04/06 12:59:26 tg Exp $");
extern char **environ;
@ -46,6 +46,7 @@ extern char **environ;
#define MKSH_DEFAULT_TMPDIR "/tmp"
#endif
static uint8_t isuc(const char *);
static int main_init(int, const char *[], Source **, struct block **);
void chvt_reinit(void);
static void reclaim(void);
@ -160,6 +161,29 @@ static const char *empty_argv[] = {
"mksh", NULL
};
static uint8_t
isuc(const char *cx) {
char *cp, *x;
uint8_t rv = 0;
if (!cx || !*cx)
return (0);
/* uppercase a string duplicate */
strdupx(x, cx, ATEMP);
cp = x;
while ((*cp = ksh_toupper(*cp)))
++cp;
/* check for UTF-8 */
if (strstr(x, "UTF-8") || strstr(x, "UTF8"))
rv = 1;
/* free copy and out */
afree(x, ATEMP);
return (rv);
}
static int
main_init(int argc, const char *argv[], Source **sp, struct block **lp)
{
@ -515,8 +539,6 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
}
/* divine the initial state of the utf8-mode Flag */
#define isuc(x) (((x) != NULL) && \
(stristr((x), "UTF-8") || stristr((x), "utf8")))
ccp = null;
switch (utf_flag) {
@ -558,7 +580,6 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
UTFMODE = utf_flag;
break;
}
#undef isuc
/* Disable during .profile/ENV reading */
restricted = Flag(FRESTRICTED);

22
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.186 2012/04/01 16:55:16 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.187 2012/04/06 12:59:27 tg Exp $");
/* type bits for unsigned char */
unsigned char chtypes[UCHAR_MAX + 1];
@ -2000,26 +2000,6 @@ strstr(char *b, const char *l)
}
#endif
#if !HAVE_STRCASESTR
const char *
stristr(const char *b, const char *l)
{
char first, c;
size_t n;
if ((first = *l++), ((first = ksh_tolower(first)) == '\0'))
return (b);
n = strlen(l);
stristr_look:
while ((c = *b++), ((c = ksh_tolower(c)) != first))
if (c == '\0')
return (NULL);
if (strncasecmp(b, l, n))
goto stristr_look;
return (b - 1);
}
#endif
#ifdef MKSH_SMALL
char *
strndup_i(const char *src, size_t len, Area *ap)

10
sh.h
View File

@ -152,7 +152,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.540 2012/04/06 11:51:43 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.541 2012/04/06 12:59:28 tg Exp $");
#endif
#define MKSH_VERSION "R40 2012/03/29"
@ -331,10 +331,6 @@ extern int revoke(const char *);
int strcasecmp(const char *, const char *);
#endif
#if !HAVE_STRCASESTR
const char *stristr(const char *, const char *);
#endif
#if !HAVE_STRLCPY
size_t strlcpy(char *, const char *, size_t);
#endif
@ -494,10 +490,6 @@ im_sorry_dave(void)
} while (/* CONSTCOND */ 0)
#endif
#if HAVE_STRCASESTR
#define stristr(b,l) ((const char *)strcasestr((b), (l)))
#endif
#ifdef MKSH_SMALL
#ifndef MKSH_CONSERVATIVE_FDS
#define MKSH_CONSERVATIVE_FDS /* defined */