• remove strcasestr.c, use home-grown implementation¹, call it stricmp,
and have it return an API-correct const char * • enhance and stylify comments • a little KNF and simplifications • #ifdef DEBUG: replace strchr and strstr with ucstrchr and ucstrstr that take and return a non-const char *, and fix the violations • new cstrchr, cstrstr (take and give const char *) • new vstrchr, vstrstr (take const or not, give boolean value) • new afreechk(x) = afreechv(x,x) = if (x1) afree(x2, ATEMP) • new ksh_isdash(str) = (str != NULL) && !strcmp(str, "-") • replace the only use of strrchr with inlined code to shrink • minor man page fixes • Minix 3 signames are autogenerated with gcc • rename strlfun.c to strlcpy.c since we don't do strlcat(3) anyway, only strlcpy(3), and shorten it • dot.mkshrc: move MKSH=… down to the export line to not disturb the PS1 visual impression ☺ • dot.mkshrc: Lstripcom(): optimise • bump version ¹) side effect from creating API-correct cstrchr, cstrstr, etc. uses goto so it must be better ☻ tested on mirbsd-current via both Makefile and Build.sh
This commit is contained in:
parent
62b347a1b0
commit
83c2ee87f4
7
Build.sh
7
Build.sh
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# $MirOS: src/bin/mksh/Build.sh,v 1.154 2007/03/03 21:36:06 tg Exp $
|
||||
# $MirOS: src/bin/mksh/Build.sh,v 1.155 2007/03/04 03:04:22 tg Exp $
|
||||
#-
|
||||
# Env: CC, CFLAGS, CPP, CPPFLAGS, LDFLAGS, LIBS, NOWARN, NROFF, TARGET_OS
|
||||
# Environment used: CC CFLAGS CPP CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS
|
||||
# CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NEED_MKNOD MKSH_NOPWNAM
|
||||
|
||||
v()
|
||||
@ -597,8 +597,7 @@ if test 1 = $NEED_MKSH_SIGNAME; then
|
||||
fi
|
||||
|
||||
addsrcs HAVE_SETMODE setmode.c
|
||||
addsrcs HAVE_STRCASESTR strcasestr.c
|
||||
addsrcs HAVE_STRLCPY strlfun.c
|
||||
addsrcs HAVE_STRLCPY strlcpy.c
|
||||
CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H -DCONFIG_H_FILENAME=\\\"sh.h\\\""
|
||||
|
||||
case $s:$HAVE_MKSH_NOPAM in
|
||||
|
4
Makefile
4
Makefile
@ -1,4 +1,6 @@
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.33 2007/03/04 00:13:14 tg Exp $
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.34 2007/03/04 03:04:23 tg Exp $
|
||||
#-
|
||||
# use CPPFLAGS=-DDEBUG __CRAZY=Yes to check for certain more stuff
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
|
16
alloc.c
16
alloc.c
@ -29,7 +29,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.3 2005/11/22 18:40:40 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/alloc.c,v 1.4 2007/03/04 03:04:23 tg Exp $");
|
||||
|
||||
struct link {
|
||||
struct link *prev;
|
||||
@ -40,7 +40,7 @@ Area *
|
||||
ainit(Area *ap)
|
||||
{
|
||||
ap->freelist = NULL;
|
||||
return ap;
|
||||
return (ap);
|
||||
}
|
||||
|
||||
void
|
||||
@ -63,8 +63,7 @@ alloc(size_t size, Area *ap)
|
||||
{
|
||||
struct link *l;
|
||||
|
||||
l = malloc(sizeof(struct link) + size);
|
||||
if (l == NULL)
|
||||
if ((l = malloc(sizeof (struct link) + size)) == NULL)
|
||||
internal_errorf(1, "unable to allocate memory");
|
||||
l->next = ap->freelist;
|
||||
l->prev = NULL;
|
||||
@ -72,7 +71,7 @@ alloc(size_t size, Area *ap)
|
||||
ap->freelist->prev = l;
|
||||
ap->freelist = l;
|
||||
|
||||
return L2P(l);
|
||||
return (L2P(l));
|
||||
}
|
||||
|
||||
void *
|
||||
@ -81,14 +80,13 @@ aresize(void *ptr, size_t size, Area *ap)
|
||||
struct link *l, *l2, *lprev, *lnext;
|
||||
|
||||
if (ptr == NULL)
|
||||
return alloc(size, ap);
|
||||
return (alloc(size, ap));
|
||||
|
||||
l = P2L(ptr);
|
||||
lprev = l->prev;
|
||||
lnext = l->next;
|
||||
|
||||
l2 = realloc(l, sizeof(struct link) + size);
|
||||
if (l2 == NULL)
|
||||
if ((l2 = realloc(l, sizeof (struct link) + size)) == NULL)
|
||||
internal_errorf(1, "unable to allocate memory");
|
||||
if (lprev)
|
||||
lprev->next = l2;
|
||||
@ -97,7 +95,7 @@ aresize(void *ptr, size_t size, Area *ap)
|
||||
if (lnext)
|
||||
lnext->prev = l2;
|
||||
|
||||
return L2P(l2);
|
||||
return (L2P(l2));
|
||||
}
|
||||
|
||||
void
|
||||
|
4
check.t
4
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.91 2007/02/16 17:46:41 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.92 2007/03/04 03:04:23 tg Exp $
|
||||
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
|
||||
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
|
||||
@ -7,7 +7,7 @@
|
||||
# http://www.research.att.com/~gsf/public/ifs.sh
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R29 2007/02/16
|
||||
@(#)MIRBSD KSH R29 2007/03/04
|
||||
description:
|
||||
Check version of shell.
|
||||
category: pdksh
|
||||
|
@ -1,9 +1,9 @@
|
||||
$MirOS: src/bin/mksh/copyright,v 1.19 2007/01/17 01:24:29 tg Exp $
|
||||
$MirOS: src/bin/mksh/copyright,v 1.20 2007/03/04 03:04:23 tg Rel $
|
||||
|
||||
The MirBSD Korn Shell (mksh) is
|
||||
|
||||
Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007
|
||||
Thorsten Glaser <tg@mirbsd.de>
|
||||
Thorsten "mirabilos" Glaser <tg@mirbsd.de>
|
||||
|
||||
Provided that these terms and disclaimer and all copyright notices
|
||||
are retained or reproduced in an accompanying document, permission
|
||||
@ -33,4 +33,4 @@ A number of files that are either always or conditionally included
|
||||
during compilation, depending on the target operating environment,
|
||||
are covered by different (2/3-clause BSD or similar) licences; re-
|
||||
fer to the individual files for details: alloc.c (always included)
|
||||
and setmode.c, strcasestr.c, strlfun.c
|
||||
and setmode.c, strlcpy.c
|
||||
|
11
dot.mkshrc
11
dot.mkshrc
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.6 2007/02/17 06:34:46 tg Exp $
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.7 2007/03/04 03:04:23 tg Exp $
|
||||
#-
|
||||
# Add user-defined additions at the end, to prevent abortion on failure.
|
||||
|
||||
@ -17,8 +17,8 @@ PS1='$(((rv=$?)) && print $rv\|)${USER:=$(id -un)}@${HOSTNAME:=nil}:$(
|
||||
fi
|
||||
done
|
||||
print -r -- "$pfx$wd")'" $(if (( $(id -u) )); then
|
||||
print \$; else print \#; fi) " MKSH=$(whence -p mksh)
|
||||
export EDITOR HOSTNAME MKSH PS1 USER
|
||||
print \$; else print \#; fi) "
|
||||
export EDITOR HOSTNAME MKSH=$(whence -p mksh) PS1 USER
|
||||
|
||||
alias l='/bin/ls -F'
|
||||
alias la='l -a'
|
||||
@ -32,9 +32,8 @@ alias lo='la -lo'
|
||||
# any file(s) given as argument, or stdin if none, and spew to stdout
|
||||
function Lstripcom
|
||||
{
|
||||
cat "$@" | while read _line; do
|
||||
set -o noglob
|
||||
cat "$@" | { set -o noglob; while read _line; do
|
||||
_line=${_line%%#*}
|
||||
[[ -n $_line ]] && print -r -- $_line
|
||||
done
|
||||
done; }
|
||||
}
|
||||
|
17
edit.c
17
edit.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.83 2007/03/04 00:13:14 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.84 2007/03/04 03:04:24 tg Exp $");
|
||||
|
||||
/* tty driver characters we are interested in */
|
||||
typedef struct {
|
||||
@ -133,9 +133,7 @@ x_getc(void)
|
||||
runtraps(0);
|
||||
x_mode(true);
|
||||
}
|
||||
if (n != 1)
|
||||
return -1;
|
||||
return (int)(unsigned char)c;
|
||||
return ((n == 1) ? (int)(unsigned char)c : -1);
|
||||
}
|
||||
|
||||
void
|
||||
@ -484,7 +482,7 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
|
||||
for (p = start - 1; p >= 0 && ksh_isspace(buf[p]);
|
||||
p--)
|
||||
;
|
||||
iscmd = p < 0 || strchr(";|&()`", buf[p]);
|
||||
iscmd = p < 0 || vstrchr(";|&()`", buf[p]);
|
||||
if (iscmd) {
|
||||
/* If command has a /, path, etc. is not searched;
|
||||
* only current directory is searched which is just
|
||||
@ -561,7 +559,7 @@ add_glob(const char *str, int slen)
|
||||
if (*s == '\\' && s[1])
|
||||
s++;
|
||||
else if (*s == '*' || *s == '[' || *s == '?' || *s == '$'
|
||||
|| (s[1] == '(' && strchr("*+?@!", *s)))
|
||||
|| (s[1] == '(' && vstrchr("*+?@!", *s)))
|
||||
break;
|
||||
else if (*s == '/')
|
||||
saw_slash = true;
|
||||
@ -602,7 +600,7 @@ x_free_words(int nwords, char **words)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nwords; i++)
|
||||
afreechk(words[i])
|
||||
afreechk(words[i]);
|
||||
afree(words, ATEMP);
|
||||
}
|
||||
|
||||
@ -672,7 +670,7 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath)
|
||||
Xinit(xs, xp, patlen + 128, ATEMP);
|
||||
while (sp) {
|
||||
xp = Xstring(xs, xp);
|
||||
if (!(p = strchr(sp, ':')))
|
||||
if (!(p = cstrchr(sp, ':')))
|
||||
p = sp + strlen(sp);
|
||||
pathlen = p - sp;
|
||||
if (pathlen) {
|
||||
@ -733,7 +731,8 @@ x_escape(const char *s, size_t len, int (*putbuf_func) (const char *, size_t))
|
||||
int rval = 0;
|
||||
|
||||
for (add = 0, wlen = len; wlen - add > 0; add++) {
|
||||
if (strchr("\\$()[{}*&;#|<>\"'`", s[add]) || strchr(ifs, s[add])) {
|
||||
if (vstrchr("\\$()[{}*&;#|<>\"'`", s[add]) ||
|
||||
vstrchr(ifs, s[add])) {
|
||||
if (putbuf_func(s, add) != 0) {
|
||||
rval = -1;
|
||||
break;
|
||||
|
15
eval.c
15
eval.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.23 2007/03/04 00:13:15 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.24 2007/03/04 03:04:24 tg Exp $");
|
||||
|
||||
#ifdef MKSH_SMALL
|
||||
#define MKSH_NOPWNAM
|
||||
@ -232,7 +232,7 @@ expand(const char *cp, /* input word */
|
||||
type = comsub(&x, sp);
|
||||
if (type == XCOM && (f&DOBLANK))
|
||||
doblank++;
|
||||
sp = strchr(sp, 0) + 1;
|
||||
sp = cstrchr(sp, 0) + 1;
|
||||
newlines = 0;
|
||||
}
|
||||
continue;
|
||||
@ -255,7 +255,7 @@ expand(const char *cp, /* input word */
|
||||
v.name[0] = '\0';
|
||||
v_evaluate(&v, substitute(sp, 0),
|
||||
KSH_UNWIND_ERROR, true);
|
||||
sp = strchr(sp, 0) + 1;
|
||||
sp = cstrchr(sp, 0) + 1;
|
||||
for (p = str_val(&v); *p; ) {
|
||||
Xcheck(ds, dp);
|
||||
*dp++ = *p++;
|
||||
@ -273,7 +273,7 @@ expand(const char *cp, /* input word */
|
||||
int stype;
|
||||
int slen = 0;
|
||||
|
||||
sp = strchr(sp, '\0') + 1; /* skip variable */
|
||||
sp = cstrchr(sp, '\0') + 1; /* skip variable */
|
||||
type = varsub(&x, varname, sp, &stype, &slen);
|
||||
if (type < 0) {
|
||||
char *beg, *end, *str;
|
||||
@ -1102,15 +1102,16 @@ globit(XString *xs, /* dest string */
|
||||
char *
|
||||
debunk(char *dp, const char *sp, size_t dlen)
|
||||
{
|
||||
char *d, *s;
|
||||
char *d;
|
||||
const char *s;
|
||||
|
||||
if ((s = strchr(sp, MAGIC))) {
|
||||
if ((s = cstrchr(sp, MAGIC))) {
|
||||
if (s - sp >= (ssize_t)dlen)
|
||||
return dp;
|
||||
memcpy(dp, sp, s - sp);
|
||||
for (d = dp + (s - sp); *s && (d - dp < (ssize_t)dlen); s++)
|
||||
if (!ISMAGIC(*s) || !(*++s & 0x80) ||
|
||||
!strchr("*+?@! ", *s & 0x7f))
|
||||
!vstrchr("*+?@! ", *s & 0x7f))
|
||||
*d++ = *s;
|
||||
else {
|
||||
/* extended pattern operators: *+?@! */
|
||||
|
10
exec.c
10
exec.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.25 2007/03/04 00:13:15 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.26 2007/03/04 03:04:24 tg Exp $");
|
||||
|
||||
static int comexec(struct op *, struct tbl *volatile, const char **,
|
||||
int volatile);
|
||||
@ -500,7 +500,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
|
||||
rv = subst_exstat;
|
||||
goto Leave;
|
||||
} else if (!tp) {
|
||||
if (Flag(FRESTRICTED) && strchr(cp, '/')) {
|
||||
if (Flag(FRESTRICTED) && vstrchr(cp, '/')) {
|
||||
warningf(true, "%s: restricted", cp);
|
||||
rv = 1;
|
||||
goto Leave;
|
||||
@ -814,7 +814,7 @@ findcom(const char *name, int flags)
|
||||
char *fpath; /* for function autoloading */
|
||||
const char *npath;
|
||||
|
||||
if (strchr(name, '/') != NULL) {
|
||||
if (vstrchr(name, '/')) {
|
||||
insert = 0;
|
||||
/* prevent FPATH search below */
|
||||
flags &= ~FC_FUNC;
|
||||
@ -946,7 +946,7 @@ search(const char *name, const char *lpath,
|
||||
|
||||
if (errnop)
|
||||
*errnop = 0;
|
||||
if (strchr(name, '/')) {
|
||||
if (vstrchr(name, '/')) {
|
||||
if (search_access(name, mode, errnop) == 0)
|
||||
return (name);
|
||||
return NULL;
|
||||
@ -958,7 +958,7 @@ search(const char *name, const char *lpath,
|
||||
sp = lpath;
|
||||
while (sp != NULL) {
|
||||
xp = Xstring(xs, xp);
|
||||
if (!(p = strchr(sp, ':')))
|
||||
if (!(p = cstrchr(sp, ':')))
|
||||
p = sp + strlen(sp);
|
||||
if (p != sp) {
|
||||
XcheckN(xs, xp, p - sp);
|
||||
|
23
expr.c
23
expr.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.9 2007/03/03 21:12:51 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.10 2007/03/04 03:04:25 tg Exp $");
|
||||
|
||||
/* The order of these enums is constrained by the order of opinfo[] */
|
||||
enum token {
|
||||
@ -102,10 +102,9 @@ static const struct opinfo opinfo[] = {
|
||||
{ "(", 1, P_PRIMARY },
|
||||
{ ")", 1, P_PRIMARY },
|
||||
{ ":", 1, P_PRIMARY },
|
||||
{ "", 0, P_PRIMARY } /* end of table */
|
||||
{ "", 0, P_PRIMARY }
|
||||
};
|
||||
|
||||
|
||||
typedef struct expr_state Expr_state;
|
||||
struct expr_state {
|
||||
const char *expression; /* expression being evaluated */
|
||||
@ -148,7 +147,7 @@ evaluate(const char *expr, long int *rval, int error_ok, bool arith)
|
||||
v.type = 0;
|
||||
ret = v_evaluate(&v, expr, error_ok, arith);
|
||||
*rval = v.val.i;
|
||||
return ret;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -178,7 +177,7 @@ v_evaluate(struct tbl *vp, const char *expr, volatile int error_ok,
|
||||
quitenv(NULL);
|
||||
if (i == LAEXPR) {
|
||||
if (error_ok == KSH_RETURN_ERROR)
|
||||
return 0;
|
||||
return (0);
|
||||
errorf(null);
|
||||
}
|
||||
unwind(i);
|
||||
@ -203,7 +202,7 @@ v_evaluate(struct tbl *vp, const char *expr, volatile int error_ok,
|
||||
|
||||
quitenv(NULL);
|
||||
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -304,7 +303,7 @@ evalexpr(Expr_state *es, enum prec prec)
|
||||
vl = do_ppmm(es, es->tok, vl, false);
|
||||
exprtoken(es);
|
||||
}
|
||||
return vl;
|
||||
return (vl);
|
||||
}
|
||||
vl = evalexpr(es, ((int) prec) - 1);
|
||||
for (op = es->tok; IS_BINOP(op) && opinfo[(int) op].prec == prec;
|
||||
@ -437,7 +436,7 @@ evalexpr(Expr_state *es, enum prec prec)
|
||||
} else if (op != O_TERN)
|
||||
vl->val.i = res;
|
||||
}
|
||||
return vl;
|
||||
return (vl);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -526,7 +525,7 @@ do_ppmm(Expr_state *es, enum token op, struct tbl *vasn, bool is_prefix)
|
||||
if (!is_prefix) /* undo the inc/dec */
|
||||
vl->val.i = oval;
|
||||
|
||||
return vl;
|
||||
return (vl);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -549,7 +548,7 @@ tempvar(void)
|
||||
vp->areap = ATEMP;
|
||||
vp->val.i = 0;
|
||||
vp->name[0] = '\0';
|
||||
return vp;
|
||||
return (vp);
|
||||
}
|
||||
|
||||
/* cast (string) variable to temporary integer variable */
|
||||
@ -561,7 +560,7 @@ intvar(Expr_state *es, struct tbl *vp)
|
||||
/* try to avoid replacing a temp var with another temp var */
|
||||
if (vp->name[0] == '\0' &&
|
||||
(vp->flag & (ISSET|INTEGER|EXPRLVALUE)) == (ISSET|INTEGER))
|
||||
return vp;
|
||||
return (vp);
|
||||
|
||||
vq = tempvar();
|
||||
if (setint_v(vq, vp, es->arith) == NULL) {
|
||||
@ -573,5 +572,5 @@ intvar(Expr_state *es, struct tbl *vp)
|
||||
vp->flag &= ~EXPRINEVAL;
|
||||
es->evaling = NULL;
|
||||
}
|
||||
return vq;
|
||||
return (vq);
|
||||
}
|
||||
|
31
funcs.c
31
funcs.c
@ -5,7 +5,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.47 2007/03/04 00:13:15 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.48 2007/03/04 03:04:25 tg Exp $");
|
||||
|
||||
int
|
||||
c_cd(const char **wp)
|
||||
@ -53,7 +53,7 @@ c_cd(const char **wp)
|
||||
} else if (!wp[1]) {
|
||||
/* One argument: - or dir */
|
||||
dir = str_save(wp[0], ATEMP);
|
||||
if (strcmp(dir, "-") == 0) {
|
||||
if (ksh_isdash(dir)) {
|
||||
afree(dir, ATEMP);
|
||||
dir = str_val(oldpwd_s);
|
||||
if (dir == null) {
|
||||
@ -280,7 +280,7 @@ c_print(const char **wp)
|
||||
if (!(builtin_opt.info & GI_MINUSMINUS)) {
|
||||
/* treat a lone - like -- */
|
||||
if (wp[builtin_opt.optind] &&
|
||||
strcmp(wp[builtin_opt.optind], "-") == 0)
|
||||
ksh_isdash(wp[builtin_opt.optind]))
|
||||
builtin_opt.optind++;
|
||||
} else if (flags & PO_PMINUSMINUS)
|
||||
builtin_opt.optind--;
|
||||
@ -1314,7 +1314,8 @@ int
|
||||
c_bind(const char **wp)
|
||||
{
|
||||
int optc, rv = 0, macro = 0, list = 0;
|
||||
char *cp;
|
||||
const char *cp;
|
||||
char *up;
|
||||
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, "lm")) != -1)
|
||||
switch (optc) {
|
||||
@ -1333,11 +1334,15 @@ c_bind(const char **wp)
|
||||
rv = x_bind((char*)NULL, (char*)NULL, 0, list);
|
||||
|
||||
for (; *wp != NULL; wp++) {
|
||||
cp = strchr(*wp, '=');
|
||||
if (cp != NULL)
|
||||
*cp++ = '\0';
|
||||
if (x_bind(*wp, cp, macro, 0))
|
||||
if ((cp = cstrchr(*wp, '=')) == NULL)
|
||||
up = NULL;
|
||||
else {
|
||||
up = str_save(*wp, ATEMP);
|
||||
up[cp++ - *wp] = '\0';
|
||||
}
|
||||
if (x_bind(up ? up : *wp, cp, macro, 0))
|
||||
rv = 1;
|
||||
afreechk(up);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@ -1472,7 +1477,7 @@ c_umask(const char **wp)
|
||||
new_umask = old_umask;
|
||||
positions = 0;
|
||||
while (*cp) {
|
||||
while (*cp && strchr("augo", *cp))
|
||||
while (*cp && vstrchr("augo", *cp))
|
||||
switch (*cp++) {
|
||||
case 'a':
|
||||
positions |= 0111;
|
||||
@ -1489,11 +1494,11 @@ c_umask(const char **wp)
|
||||
}
|
||||
if (!positions)
|
||||
positions = 0111; /* default is a */
|
||||
if (!strchr("=+-", op = *cp))
|
||||
if (!vstrchr("=+-", op = *cp))
|
||||
break;
|
||||
cp++;
|
||||
new_val = 0;
|
||||
while (*cp && strchr("rwxugoXs", *cp))
|
||||
while (*cp && vstrchr("rwxugoXs", *cp))
|
||||
switch (*cp++) {
|
||||
case 'r': new_val |= 04; break;
|
||||
case 'w': new_val |= 02; break;
|
||||
@ -1525,7 +1530,7 @@ c_umask(const char **wp)
|
||||
if (*cp == ',') {
|
||||
positions = 0;
|
||||
cp++;
|
||||
} else if (!strchr("=+-", *cp))
|
||||
} else if (!vstrchr("=+-", *cp))
|
||||
break;
|
||||
}
|
||||
if (*cp) {
|
||||
@ -2033,7 +2038,7 @@ c_unset(const char **wp)
|
||||
bi_errorf("%s is read only", vp->name);
|
||||
return 1;
|
||||
}
|
||||
unset(vp, strchr(id, '[') ? 1 : 0);
|
||||
unset(vp, vstrchr(id, '[') ? 1 : 0);
|
||||
} else { /* unset function */
|
||||
if (define(id, (struct op *) NULL))
|
||||
ret = 1;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.44 2007/03/04 00:13:16 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.45 2007/03/04 03:04:25 tg Exp $");
|
||||
|
||||
Trap sigtraps[NSIG + 1];
|
||||
static struct sigaction Sigact_ign, Sigact_trap;
|
||||
@ -56,7 +56,7 @@ c_fc(const char **wp)
|
||||
switch (optc) {
|
||||
case 'e':
|
||||
p = builtin_opt.optarg;
|
||||
if (strcmp(p, "-") == 0)
|
||||
if (ksh_isdash(p))
|
||||
sflag++;
|
||||
else {
|
||||
size_t len = strlen(p);
|
||||
|
5
jobs.c
5
jobs.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.18 2007/01/12 10:18:21 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.19 2007/03/04 03:04:25 tg Exp $");
|
||||
|
||||
/* Order important! */
|
||||
#define PRUNNING 0
|
||||
@ -83,7 +83,8 @@ static const char *const lookup_msgs[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
struct timeval j_systime, j_usrtime; /* user and system time of last j_waitjed job */
|
||||
/* user and system time of last j_waitjed job */
|
||||
struct timeval j_systime, j_usrtime;
|
||||
|
||||
static Job *job_list; /* job list */
|
||||
static Job *last_job;
|
||||
|
7
lex.c
7
lex.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.25 2007/01/12 10:18:21 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.26 2007/03/04 03:04:26 tg Exp $");
|
||||
|
||||
/* Structure to keep track of the lexing state and the various pieces of info
|
||||
* needed for each particular state. */
|
||||
@ -46,7 +46,6 @@ struct State_info {
|
||||
Lex_state *end;
|
||||
};
|
||||
|
||||
|
||||
static void readhere(struct ioword *);
|
||||
static int getsc__(void);
|
||||
static void getsc_line(Source *);
|
||||
@ -83,10 +82,8 @@ static int ignore_backslash_newline;
|
||||
state = statep->ls_state; \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Lexical analyzer
|
||||
* Lexical analyser
|
||||
*
|
||||
* tokens are not regular expressions, they are LL(1).
|
||||
* for example, "${var:-${PWD}}", and "$(size $(whence ksh))".
|
||||
|
4
main.c
4
main.c
@ -13,7 +13,7 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.72 2007/03/04 00:13:16 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.73 2007/03/04 03:04:26 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -292,7 +292,7 @@ main(int argc, const char *argv[])
|
||||
#ifndef MKSH_ASSUME_UTF8
|
||||
#if HAVE_SETLOCALE_CTYPE
|
||||
#define isuc(x) (((x) != NULL) && \
|
||||
(strcasestr((x), "UTF-8") || strcasestr((x), "utf8")))
|
||||
(stristr((x), "UTF-8") || stristr((x), "utf8")))
|
||||
/* Check if we're in a UTF-8 locale */
|
||||
if (!Flag(FUTFHACK)) {
|
||||
cc = setlocale(LC_CTYPE, "");
|
||||
|
85
misc.c
85
misc.c
@ -6,7 +6,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.51 2007/03/04 00:13:16 tg Exp $\t"
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.52 2007/03/04 03:04:26 tg Exp $\t"
|
||||
MKSH_SH_H_ID);
|
||||
|
||||
#undef USE_CHVT
|
||||
@ -311,12 +311,15 @@ parse_args(const char **argv,
|
||||
}
|
||||
|
||||
if (what == OF_CMDLINE) {
|
||||
char *p;
|
||||
const char *p = argv[0], *q;
|
||||
/* Set FLOGIN before parsing options so user can clear
|
||||
* flag using +l.
|
||||
*/
|
||||
Flag(FLOGIN) = (argv[0][0] == '-' ||
|
||||
((p = strrchr(argv[0], '/')) && *++p == '-'));
|
||||
if (*p != '-')
|
||||
for (q = p; *q; )
|
||||
if (*q++ == '/')
|
||||
p = q;
|
||||
Flag(FLOGIN) = (*p == '-');
|
||||
opts = cmd_opts;
|
||||
} else if (what == OF_FIRSTTIME) {
|
||||
opts = cmd_opts;
|
||||
@ -558,7 +561,7 @@ has_globbing(const char *xp, const char *xpe)
|
||||
return 0;
|
||||
in_bracket = 0;
|
||||
}
|
||||
} else if ((c & 0x80) && strchr("*+?@! ", c & 0x7f)) {
|
||||
} else if ((c & 0x80) && vstrchr("*+?@! ", c & 0x7f)) {
|
||||
saw_glob = 1;
|
||||
if (in_bracket)
|
||||
bnest++;
|
||||
@ -758,7 +761,7 @@ pat_scan(const unsigned char *p, const unsigned char *pe, int match_sep)
|
||||
if ((*++p == /*(*/ ')' && nest-- == 0) ||
|
||||
(*p == '|' && match_sep && nest == 0))
|
||||
return ++p;
|
||||
if ((*p & 0x80) && strchr("*+?@! ", *p & 0x7f))
|
||||
if ((*p & 0x80) && vstrchr("*+?@! ", *p & 0x7f))
|
||||
nest++;
|
||||
}
|
||||
return NULL;
|
||||
@ -811,7 +814,7 @@ int
|
||||
ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
|
||||
{
|
||||
char c;
|
||||
char *o;
|
||||
const char *o;
|
||||
|
||||
if (go->p == 0 || (c = argv[go->optind - 1][go->p]) == '\0') {
|
||||
const char *arg = argv[go->optind], flag = arg ? *arg : '\0';
|
||||
@ -836,7 +839,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
|
||||
}
|
||||
go->p++;
|
||||
if (c == '?' || c == ':' || c == ';' || c == ',' || c == '#' ||
|
||||
!(o = strchr(optionsp, c))) {
|
||||
!(o = cstrchr(optionsp, c))) {
|
||||
if (optionsp[0] == ':') {
|
||||
go->buf[0] = c;
|
||||
go->optarg = go->buf;
|
||||
@ -921,18 +924,18 @@ print_value_quoted(const char *s)
|
||||
}
|
||||
for (p = s; *p; p++) {
|
||||
if (*p == '\'') {
|
||||
shprintf("'\\'" + 1 - inquote);
|
||||
if (inquote)
|
||||
shf_putc('\'', shl_stdout);
|
||||
shf_putc('\\', shl_stdout);
|
||||
inquote = 0;
|
||||
} else {
|
||||
if (!inquote) {
|
||||
shprintf("'");
|
||||
} else if (!inquote) {
|
||||
shf_putc('\'', shl_stdout);
|
||||
inquote = 1;
|
||||
}
|
||||
shf_putc(*p, shl_stdout);
|
||||
}
|
||||
}
|
||||
if (inquote)
|
||||
shprintf("'");
|
||||
shf_putc('\'', shl_stdout);
|
||||
}
|
||||
|
||||
/* Print things in columns and rows - func() is called to format the ith
|
||||
@ -1281,7 +1284,7 @@ do_phys_path(XString *xsp, char *xp, const char *pathl)
|
||||
p++;
|
||||
if (!*p)
|
||||
break;
|
||||
len = (q = strchr(p, '/')) ? q - p : (int)strlen(p);
|
||||
len = (q = cstrchr(p, '/')) ? q - p : (int)strlen(p);
|
||||
if (len == 1 && p[0] == '.')
|
||||
continue;
|
||||
if (len == 2 && p[0] == '.' && p[1] == '.') {
|
||||
@ -1372,3 +1375,55 @@ chvt(const char *fn)
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
char *
|
||||
strchr(char *p, int ch)
|
||||
{
|
||||
for (;; ++p) {
|
||||
if (*p == ch)
|
||||
return (p);
|
||||
if (!*p)
|
||||
return (NULL);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
char *
|
||||
strstr(char *b, const char *l)
|
||||
{
|
||||
char first, c;
|
||||
size_t n;
|
||||
|
||||
if ((first = *l++) == '\0')
|
||||
return (b);
|
||||
n = strlen(l);
|
||||
strstr_look:
|
||||
while ((c = *b++) != first)
|
||||
if (c == '\0')
|
||||
return (NULL);
|
||||
if (strncmp(b, l, n))
|
||||
goto strstr_look;
|
||||
return (b - 1);
|
||||
}
|
||||
#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
|
||||
|
8
mksh.1
8
mksh.1
@ -1,7 +1,7 @@
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.78 2007/01/18 16:23:52 tg Exp $
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.79 2007/03/04 03:04:26 tg Exp $
|
||||
.\" $OpenBSD: ksh.1,v 1.118 2006/11/30 08:47:58 jmc Exp $
|
||||
.\"
|
||||
.Dd January 18, 2007
|
||||
.Dd March 4, 2007
|
||||
.Dt MKSH 1
|
||||
.Os MirBSD
|
||||
.Sh NAME
|
||||
@ -5293,7 +5293,7 @@ Please report bugs in
|
||||
to the
|
||||
.Aq miros-discuss@mirbsd.org
|
||||
mailing list or in the
|
||||
.Li \&#\&!/bin/mksh Pq \&#mksh
|
||||
.Li \&#\&!/bin/mksh
|
||||
or
|
||||
.Li \&#ksh
|
||||
IRC channel at
|
||||
@ -5309,4 +5309,4 @@ is executed in a subshell.
|
||||
This is an
|
||||
.Nm
|
||||
feature which can be depended on by scripts.
|
||||
Use co-routines to work around if necessary and possible.
|
||||
Use co-processes to work around if necessary and possible.
|
||||
|
57
sh.h
57
sh.h
@ -8,14 +8,14 @@
|
||||
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
|
||||
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
|
||||
|
||||
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.114 2007/03/04 00:13:16 tg Exp $"
|
||||
#define MKSH_VERSION "R29 2007/02/16"
|
||||
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.115 2007/03/04 03:04:27 tg Exp $"
|
||||
#define MKSH_VERSION "R29 2007/03/04"
|
||||
|
||||
#if HAVE_SYS_PARAM_H
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#if defined(HAVE_MULTI_IDSTRING) && !HAVE_MULTI_IDSTRING
|
||||
#if !HAVE_MULTI_IDSTRING
|
||||
#undef __RCSID
|
||||
#endif
|
||||
#if !defined(__RCSID) || !defined(__SCCSID)
|
||||
@ -129,6 +129,7 @@ typedef int bool;
|
||||
#define ksh_isupper(c) (((c) >= 'A') && ((c) <= 'Z'))
|
||||
#define ksh_tolower(c) (((c) >= 'A') && ((c) <= 'Z') ? (c) - 'A' + 'a' : (c))
|
||||
#define ksh_toupper(c) (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c))
|
||||
#define ksh_isdash(s) (((s) != NULL) && ((s)[0] == '-') && ((s)[1] == '\0'))
|
||||
|
||||
#if HAVE_ATTRIBUTE
|
||||
#undef __attribute__
|
||||
@ -172,7 +173,7 @@ mode_t getmode(const void *, mode_t);
|
||||
void *setmode(const char *);
|
||||
#endif
|
||||
#if !HAVE_STRCASESTR
|
||||
char *strcasestr(const char *, const char *);
|
||||
const char *stristr(const char *, const char *);
|
||||
#endif
|
||||
#if !HAVE_STRLCPY
|
||||
size_t strlcpy(char *, const char *, size_t);
|
||||
@ -228,7 +229,7 @@ EXTERN int exstat; /* exit status */
|
||||
EXTERN int subst_exstat; /* exit status of last $(..)/`..` */
|
||||
EXTERN const char *safe_prompt; /* safe prompt if PS1 substitution fails */
|
||||
EXTERN const char initvsn[] I__("KSH_VERSION=@(#)MIRBSD KSH " MKSH_VERSION);
|
||||
#define KSH_VERSION (initvsn + 16)
|
||||
#define KSH_VERSION (initvsn + /* "KSH_VERSION=@(#)" */ 16)
|
||||
|
||||
/*
|
||||
* Evil hack for const correctness due to API brokenness
|
||||
@ -241,6 +242,13 @@ union mksh_ccphack {
|
||||
char **rw;
|
||||
const char **ro;
|
||||
};
|
||||
|
||||
/* for const debugging */
|
||||
#ifdef DEBUG
|
||||
char *ucstrchr(char *, int);
|
||||
char *ucstrstr(char *, const char *);
|
||||
#define strchr ucstrchr
|
||||
#define strstr ucstrstr
|
||||
#define cstrchr(s,c) __extension__({ \
|
||||
union mksh_cchack in, out; \
|
||||
\
|
||||
@ -248,6 +256,42 @@ union mksh_ccphack {
|
||||
out.rw = strchr(in.rw, (c)); \
|
||||
(out.ro); \
|
||||
})
|
||||
#define cstrstr(b,l) __extension__({ \
|
||||
union mksh_cchack in, out; \
|
||||
\
|
||||
in.ro = (b); \
|
||||
out.rw = strstr(in.rw, (l)); \
|
||||
(out.ro); \
|
||||
})
|
||||
#define vstrchr(s,c) (cstrchr((s), (c)) != NULL)
|
||||
#define vstrstr(b,l) (cstrstr((b), (l)) != NULL)
|
||||
#if HAVE_STRCASESTR
|
||||
#define stristr(b,l) __extension__({ \
|
||||
union mksh_cchack out; \
|
||||
\
|
||||
out.rw = strcasestr((b), (l)); \
|
||||
(out.ro); \
|
||||
})
|
||||
#endif
|
||||
#else
|
||||
#define cstrchr(s,c) __extension__({ \
|
||||
union mksh_cchack out; \
|
||||
\
|
||||
out.rw = strchr((s), (c)); \
|
||||
(out.ro); \
|
||||
})
|
||||
#define cstrstr(b,l) __extension__({ \
|
||||
union mksh_cchack out; \
|
||||
\
|
||||
out.rw = strstr((b), (l)); \
|
||||
(out.ro); \
|
||||
})
|
||||
#define vstrchr strchr
|
||||
#define vstrstr strstr
|
||||
#if HAVE_STRCASESTR
|
||||
#define stristr strcasestr
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Area-based allocation built on malloc/free
|
||||
@ -702,7 +746,7 @@ struct tbl { /* table item */
|
||||
/* Argument info. Used for $#, $* for shell, functions, includes, etc. */
|
||||
struct arg_info {
|
||||
int flags; /* AF_* */
|
||||
char **argv;
|
||||
const char **argv;
|
||||
int argc_;
|
||||
int skip; /* first arg is argv[0], second is argv[1 + skip] */
|
||||
};
|
||||
@ -734,7 +778,6 @@ struct tstate {
|
||||
struct tbl **next;
|
||||
};
|
||||
|
||||
|
||||
EXTERN struct table taliases; /* tracked aliases */
|
||||
EXTERN struct table builtins; /* built-in commands */
|
||||
EXTERN struct table aliases; /* aliases */
|
||||
|
2
shf.c
2
shf.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.11 2007/01/15 02:48:28 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.12 2007/03/04 03:04:27 tg Exp $");
|
||||
|
||||
/* flags to shf_emptybuf() */
|
||||
#define EB_READSW 0x01 /* about to switch to reading */
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef MKSH_SIGNAMES_CHECK
|
||||
__RCSID("$MirOS: src/bin/mksh/signames.c,v 1.1 2007/01/12 00:25:40 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/signames.c,v 1.2 2007/03/04 03:04:28 tg Exp $");
|
||||
#endif
|
||||
|
||||
static const struct mksh_sigpair {
|
||||
@ -8,7 +8,7 @@ static const struct mksh_sigpair {
|
||||
} mksh_sigpairs[] = {
|
||||
#ifdef __Plan9__
|
||||
...
|
||||
#elif defined(__minix)
|
||||
#elif defined(__minix) && !defined(__GNUC__)
|
||||
...
|
||||
#elif defined(MKSH_SIGNAMES_CHECK)
|
||||
#error no, must be OS supplied
|
||||
|
61
strcasestr.c
61
strcasestr.c
@ -1,61 +0,0 @@
|
||||
/* $OpenBSD: strcasestr.c,v 1.2 2005/08/08 08:05:37 espie Exp $ */
|
||||
/* $NetBSD: strcasestr.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/strcasestr.c,v 1.1 2006/11/12 13:15:27 tg Exp $");
|
||||
|
||||
/*
|
||||
* Find the first occurrence of find in s, ignore case.
|
||||
*/
|
||||
char *
|
||||
strcasestr(const char *s, const char *find)
|
||||
{
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
c = ksh_tolower((unsigned char)c);
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return (NULL);
|
||||
} while ((char)ksh_tolower((unsigned char)sc) != c);
|
||||
} while (strncasecmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return ((char *)s);
|
||||
}
|
@ -1,9 +1,15 @@
|
||||
/* $MirOS: src/bin/mksh/strlfun.c,v 1.9 2007/01/12 01:49:29 tg Exp $ */
|
||||
/* $MirOS: src/bin/mksh/strlcpy.c,v 1.1 2007/03/04 03:04:28 tg Exp $ */
|
||||
/* $miros: src/lib/libc/string/strlfun.c,v 1.14 2007/01/07 02:11:40 tg Exp $ */
|
||||
/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006
|
||||
* Copyright (c) 2006, 2007
|
||||
* Thorsten Glaser <tg@mirbsd.de>
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
|
||||
* the utmost extent permitted by applicable law, neither express nor
|
||||
@ -13,62 +19,12 @@
|
||||
* of dealing in the work, even if advised of the possibility of such
|
||||
* damage or existence of a defect, except proven that it results out
|
||||
* of said person's immediate fault when using the work as intended.
|
||||
*-
|
||||
* The strlcat() code below has been written by Thorsten Glaser. Bodo
|
||||
* Eggert suggested optimising the strlcpy() code, originally written
|
||||
* by Todd C. Miller (see below), which was carried out by Th. Glaser
|
||||
* as well as merging this code with strxfrm() for ISO-10646-only sy-
|
||||
* stems and writing wcslcat(), wcslcpy() and wcsxfrm() equivalents.
|
||||
*/
|
||||
|
||||
#ifdef STRXFRM
|
||||
#undef HAVE_STRLCPY
|
||||
#undef HAVE_STRLCAT
|
||||
#define HAVE_STRLCPY 0
|
||||
#define HAVE_STRLCAT 1
|
||||
#define strlcpy strxfrm
|
||||
#endif
|
||||
#include "sh.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#if defined(_KERNEL) || defined(_STANDALONE)
|
||||
#include <lib/libkern/libkern.h>
|
||||
#undef HAVE_STRLCPY
|
||||
#undef HAVE_STRLCAT
|
||||
#else
|
||||
#if defined(HAVE_CONFIG_H) && (HAVE_CONFIG_H != 0)
|
||||
/* usually when packaged with third-party software */
|
||||
#ifdef CONFIG_H_FILENAME
|
||||
#include CONFIG_H_FILENAME
|
||||
#else
|
||||
#include "config.h"
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
__RCSID("$MirOS: src/bin/mksh/strlcpy.c,v 1.1 2007/03/04 03:04:28 tg Exp $");
|
||||
|
||||
#ifndef __predict_true
|
||||
#define __predict_true(exp) ((exp) != 0)
|
||||
#endif
|
||||
#ifndef __predict_false
|
||||
#define __predict_false(exp) ((exp) != 0)
|
||||
#endif
|
||||
|
||||
#if !defined(_KERNEL) && !defined(_STANDALONE)
|
||||
__RCSID("$MirOS: src/bin/mksh/strlfun.c,v 1.9 2007/01/12 01:49:29 tg Exp $");
|
||||
#endif
|
||||
|
||||
size_t strlcpy(char *, const char *, size_t);
|
||||
|
||||
/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*/
|
||||
|
||||
#if !defined(HAVE_STRLCPY) || (HAVE_STRLCPY == 0)
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
@ -79,7 +35,7 @@ strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
const char *s = src;
|
||||
|
||||
if (__predict_false(siz == 0))
|
||||
if (siz == 0)
|
||||
goto traverse_src;
|
||||
|
||||
/* copy as many chars as will fit */
|
||||
@ -87,7 +43,7 @@ strlcpy(char *dst, const char *src, size_t siz)
|
||||
;
|
||||
|
||||
/* not enough room in dst */
|
||||
if (__predict_false(siz == 0)) {
|
||||
if (siz == 0) {
|
||||
/* safe to NUL-terminate dst since we copied <= siz-1 chars */
|
||||
*dst = '\0';
|
||||
traverse_src:
|
||||
@ -99,4 +55,3 @@ strlcpy(char *dst, const char *src, size_t siz)
|
||||
/* count doesn't include NUL */
|
||||
return (s - src - 1);
|
||||
}
|
||||
#endif /* !HAVE_STRLCPY */
|
2
syn.c
2
syn.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.11 2007/03/04 00:13:17 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.12 2007/03/04 03:04:28 tg Exp $");
|
||||
|
||||
struct nesting_state {
|
||||
int start_token; /* token than began nesting (eg, FOR) */
|
||||
|
2
tree.c
2
tree.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.8 2007/03/04 00:13:17 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.9 2007/03/04 03:04:28 tg Exp $");
|
||||
|
||||
#define INDENT 4
|
||||
|
||||
|
4
var.c
4
var.c
@ -2,7 +2,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.36 2007/03/04 00:13:17 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.37 2007/03/04 03:04:28 tg Exp $");
|
||||
|
||||
/*
|
||||
* Variables
|
||||
@ -1139,7 +1139,7 @@ arrayname(const char *str)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if ((p = strchr(str, '[')) == 0)
|
||||
if ((p = cstrchr(str, '[')) == 0)
|
||||
/* Shouldn't happen, but why worry? */
|
||||
return str_save(str, ATEMP);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user