some rather mechanical KNF, now that style(9) clarified on the status
of sizeof() as a function-like unary operator; use parenthesēs around sizeof and return args consistently too
This commit is contained in:
parent
548a415fa9
commit
6b2ad96bac
50
eval.c
50
eval.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.57 2009/05/16 18:40:05 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.58 2009/06/08 20:06:45 tg Exp $");
|
||||||
|
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
#define MKSH_NOPWNAM
|
#define MKSH_NOPWNAM
|
||||||
@ -115,7 +115,7 @@ substitute(const char *cp, int f)
|
|||||||
internal_errorf("substitute");
|
internal_errorf("substitute");
|
||||||
source = sold;
|
source = sold;
|
||||||
afree(s, ATEMP);
|
afree(s, ATEMP);
|
||||||
return evalstr(yylval.cp, f);
|
return (evalstr(yylval.cp, f));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -137,7 +137,7 @@ eval(const char **ap, int f)
|
|||||||
while (*ap != NULL)
|
while (*ap != NULL)
|
||||||
expand(*ap++, &w, f);
|
expand(*ap++, &w, f);
|
||||||
XPput(w, NULL);
|
XPput(w, NULL);
|
||||||
return (char **) XPclose(w) + 1;
|
return ((char **)XPclose(w) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -346,7 +346,7 @@ expand(const char *cp, /* input word */
|
|||||||
if (!st->next) {
|
if (!st->next) {
|
||||||
SubType *newst;
|
SubType *newst;
|
||||||
|
|
||||||
newst = alloc(sizeof (SubType), ATEMP);
|
newst = alloc(sizeof(SubType), ATEMP);
|
||||||
newst->next = NULL;
|
newst->next = NULL;
|
||||||
newst->prev = st;
|
newst->prev = st;
|
||||||
st->next = newst;
|
st->next = newst;
|
||||||
@ -916,7 +916,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
|||||||
struct tbl *vp;
|
struct tbl *vp;
|
||||||
|
|
||||||
if (sp[0] == '\0') /* Bad variable name */
|
if (sp[0] == '\0') /* Bad variable name */
|
||||||
return -1;
|
return (-1);
|
||||||
|
|
||||||
xp->var = NULL;
|
xp->var = NULL;
|
||||||
|
|
||||||
@ -926,7 +926,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
|||||||
|
|
||||||
/* Can't have any modifiers for ${#...} */
|
/* Can't have any modifiers for ${#...} */
|
||||||
if (*word != CSUBST)
|
if (*word != CSUBST)
|
||||||
return -1;
|
return (-1);
|
||||||
sp++;
|
sp++;
|
||||||
/* Check for size of array */
|
/* Check for size of array */
|
||||||
if ((p = cstrchr(sp, '[')) && (p[1] == '*' || p[1] == '@') &&
|
if ((p = cstrchr(sp, '[')) && (p[1] == '*' || p[1] == '@') &&
|
||||||
@ -951,7 +951,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
|||||||
errorf("%s: parameter not set", sp);
|
errorf("%s: parameter not set", sp);
|
||||||
*stypep = 0; /* unqualified variable/string substitution */
|
*stypep = 0; /* unqualified variable/string substitution */
|
||||||
xp->str = shf_smprintf("%lu", (unsigned long)c);
|
xp->str = shf_smprintf("%lu", (unsigned long)c);
|
||||||
return XSUB;
|
return (XSUB);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for qualifiers in word part */
|
/* Check for qualifiers in word part */
|
||||||
@ -982,9 +982,9 @@ varsub(Expand *xp, const char *sp, const char *word,
|
|||||||
slen += 2;
|
slen += 2;
|
||||||
}
|
}
|
||||||
} else if (stype) /* : is not ok */
|
} else if (stype) /* : is not ok */
|
||||||
return -1;
|
return (-1);
|
||||||
if (!stype && *word != CSUBST)
|
if (!stype && *word != CSUBST)
|
||||||
return -1;
|
return (-1);
|
||||||
*stypep = stype;
|
*stypep = stype;
|
||||||
*slenp = slen;
|
*slenp = slen;
|
||||||
|
|
||||||
@ -994,7 +994,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
|||||||
case '=': /* can't assign to a vector */
|
case '=': /* can't assign to a vector */
|
||||||
case '%': /* can't trim a vector (yet) */
|
case '%': /* can't trim a vector (yet) */
|
||||||
case '#':
|
case '#':
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
if (e->loc->argc == 0) {
|
if (e->loc->argc == 0) {
|
||||||
xp->str = null;
|
xp->str = null;
|
||||||
@ -1016,7 +1016,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
|||||||
case '%': /* can't trim a vector (yet) */
|
case '%': /* can't trim a vector (yet) */
|
||||||
case '#':
|
case '#':
|
||||||
case '?':
|
case '?':
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
XPinit(wv, 32);
|
XPinit(wv, 32);
|
||||||
vp = global(arrayname(sp));
|
vp = global(arrayname(sp));
|
||||||
@ -1040,7 +1040,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
|||||||
/* Can't assign things like $! or $1 */
|
/* Can't assign things like $! or $1 */
|
||||||
if ((stype & 0x7f) == '=' &&
|
if ((stype & 0x7f) == '=' &&
|
||||||
ctype(*sp, C_VAR1 | C_DIGIT))
|
ctype(*sp, C_VAR1 | C_DIGIT))
|
||||||
return -1;
|
return (-1);
|
||||||
xp->var = global(sp);
|
xp->var = global(sp);
|
||||||
xp->str = str_val(xp->var);
|
xp->str = str_val(xp->var);
|
||||||
state = XSUB;
|
state = XSUB;
|
||||||
@ -1056,7 +1056,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
|||||||
if (Flag(FNOUNSET) && xp->str == null &&
|
if (Flag(FNOUNSET) && xp->str == null &&
|
||||||
(ctype(c, C_SUBOP2) || (state != XBASE && c != '+')))
|
(ctype(c, C_SUBOP2) || (state != XBASE && c != '+')))
|
||||||
errorf("%s: parameter not set", sp);
|
errorf("%s: parameter not set", sp);
|
||||||
return state;
|
return (state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1077,7 +1077,7 @@ comsub(Expand *xp, const char *cp)
|
|||||||
source = sold;
|
source = sold;
|
||||||
|
|
||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
return XBASE;
|
return (XBASE);
|
||||||
|
|
||||||
if (t != NULL && t->type == TCOM && /* $(<file) */
|
if (t != NULL && t->type == TCOM && /* $(<file) */
|
||||||
*t->args == NULL && *t->vars == NULL && t->ioact != NULL) {
|
*t->args == NULL && *t->vars == NULL && t->ioact != NULL) {
|
||||||
@ -1108,7 +1108,7 @@ comsub(Expand *xp, const char *cp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
xp->u.shf = shf;
|
xp->u.shf = shf;
|
||||||
return XCOM;
|
return (XCOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1127,7 +1127,7 @@ trimsub(char *str, char *pat, int how)
|
|||||||
c = *p; *p = '\0';
|
c = *p; *p = '\0';
|
||||||
if (gmatchx(str, pat, false)) {
|
if (gmatchx(str, pat, false)) {
|
||||||
*p = c;
|
*p = c;
|
||||||
return p;
|
return (p);
|
||||||
}
|
}
|
||||||
*p = c;
|
*p = c;
|
||||||
}
|
}
|
||||||
@ -1137,7 +1137,7 @@ trimsub(char *str, char *pat, int how)
|
|||||||
c = *p; *p = '\0';
|
c = *p; *p = '\0';
|
||||||
if (gmatchx(str, pat, false)) {
|
if (gmatchx(str, pat, false)) {
|
||||||
*p = c;
|
*p = c;
|
||||||
return p;
|
return (p);
|
||||||
}
|
}
|
||||||
*p = c;
|
*p = c;
|
||||||
}
|
}
|
||||||
@ -1157,7 +1157,7 @@ trimsub(char *str, char *pat, int how)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str; /* no match, return string */
|
return (str); /* no match, return string */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1175,7 +1175,7 @@ glob(char *cp, XPtrV *wp, int markdirs)
|
|||||||
XPput(*wp, debunk(cp, cp, strlen(cp) + 1));
|
XPput(*wp, debunk(cp, cp, strlen(cp) + 1));
|
||||||
else
|
else
|
||||||
qsort(XPptrv(*wp) + oldsize, XPsize(*wp) - oldsize,
|
qsort(XPptrv(*wp) + oldsize, XPsize(*wp) - oldsize,
|
||||||
sizeof (void *), xstrcmp);
|
sizeof(void *), xstrcmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GF_NONE 0
|
#define GF_NONE 0
|
||||||
@ -1197,7 +1197,7 @@ glob_str(char *cp, XPtrV *wp, int markdirs)
|
|||||||
globit(&xs, &xp, cp, wp, markdirs ? GF_MARKDIR : GF_NONE);
|
globit(&xs, &xp, cp, wp, markdirs ? GF_MARKDIR : GF_NONE);
|
||||||
Xfree(xs, xp);
|
Xfree(xs, xp);
|
||||||
|
|
||||||
return XPsize(*wp) - oldsize;
|
return (XPsize(*wp) - oldsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1337,7 +1337,7 @@ debunk(char *dp, const char *sp, size_t dlen)
|
|||||||
|
|
||||||
if ((s = cstrchr(sp, MAGIC))) {
|
if ((s = cstrchr(sp, MAGIC))) {
|
||||||
if (s - sp >= (ssize_t)dlen)
|
if (s - sp >= (ssize_t)dlen)
|
||||||
return dp;
|
return (dp);
|
||||||
memcpy(dp, sp, s - sp);
|
memcpy(dp, sp, s - sp);
|
||||||
for (d = dp + (s - sp); *s && (d - dp < (ssize_t)dlen); s++)
|
for (d = dp + (s - sp); *s && (d - dp < (ssize_t)dlen); s++)
|
||||||
if (!ISMAGIC(*s) || !(*++s & 0x80) ||
|
if (!ISMAGIC(*s) || !(*++s & 0x80) ||
|
||||||
@ -1353,7 +1353,7 @@ debunk(char *dp, const char *sp, size_t dlen)
|
|||||||
*d = '\0';
|
*d = '\0';
|
||||||
} else if (dp != sp)
|
} else if (dp != sp)
|
||||||
strlcpy(dp, sp, dlen);
|
strlcpy(dp, sp, dlen);
|
||||||
return dp;
|
return (dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if p is an unquoted name, possibly followed by a / or :. If so
|
/* Check if p is an unquoted name, possibly followed by a / or :. If so
|
||||||
@ -1390,7 +1390,7 @@ maybe_expand_tilde(const char *p, XString *dsp, char **dpp, int isassign)
|
|||||||
*dpp = dp;
|
*dpp = dp;
|
||||||
r = p;
|
r = p;
|
||||||
}
|
}
|
||||||
return r;
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1436,11 +1436,11 @@ homedir(char *name)
|
|||||||
|
|
||||||
pw = getpwnam(name);
|
pw = getpwnam(name);
|
||||||
if (pw == NULL)
|
if (pw == NULL)
|
||||||
return NULL;
|
return (NULL);
|
||||||
strdupx(ap->val.s, pw->pw_dir, APERM);
|
strdupx(ap->val.s, pw->pw_dir, APERM);
|
||||||
ap->flag |= DEFINED|ISSET|ALLOC;
|
ap->flag |= DEFINED|ISSET|ALLOC;
|
||||||
}
|
}
|
||||||
return ap->val.s;
|
return (ap->val.s);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
82
exec.c
82
exec.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.56 2009/05/16 18:40:05 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.57 2009/06/08 20:06:45 tg Exp $");
|
||||||
|
|
||||||
static int comexec(struct op *, struct tbl *volatile, const char **,
|
static int comexec(struct op *, struct tbl *volatile, const char **,
|
||||||
int volatile, volatile int *);
|
int volatile, volatile int *);
|
||||||
@ -54,7 +54,7 @@ execute(struct op *volatile t,
|
|||||||
struct tbl *tp = NULL;
|
struct tbl *tp = NULL;
|
||||||
|
|
||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
/* Caller doesn't care if XERROK should propagate. */
|
/* Caller doesn't care if XERROK should propagate. */
|
||||||
if (xerrok == NULL)
|
if (xerrok == NULL)
|
||||||
@ -62,7 +62,7 @@ execute(struct op *volatile t,
|
|||||||
|
|
||||||
if ((flags&XFORK) && !(flags&XEXEC) && t->type != TPIPE)
|
if ((flags&XFORK) && !(flags&XEXEC) && t->type != TPIPE)
|
||||||
/* run in sub-process */
|
/* run in sub-process */
|
||||||
return exchild(t, flags & ~XTIME, xerrok, -1);
|
return (exchild(t, flags & ~XTIME, xerrok, -1));
|
||||||
|
|
||||||
newenv(E_EXEC);
|
newenv(E_EXEC);
|
||||||
if (trap)
|
if (trap)
|
||||||
@ -98,9 +98,9 @@ execute(struct op *volatile t,
|
|||||||
flags &= ~XTIME;
|
flags &= ~XTIME;
|
||||||
|
|
||||||
if (t->ioact != NULL || t->type == TPIPE || t->type == TCOPROC) {
|
if (t->ioact != NULL || t->type == TPIPE || t->type == TCOPROC) {
|
||||||
e->savefd = alloc(NUFILE * sizeof (short), ATEMP);
|
e->savefd = alloc(NUFILE * sizeof(short), ATEMP);
|
||||||
/* initialise to not redirected */
|
/* initialise to not redirected */
|
||||||
memset(e->savefd, 0, NUFILE * sizeof (short));
|
memset(e->savefd, 0, NUFILE * sizeof(short));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* do redirection, to be restored in quitenv() */
|
/* do redirection, to be restored in quitenv() */
|
||||||
@ -391,7 +391,7 @@ execute(struct op *volatile t,
|
|||||||
if (Flag(FERREXIT))
|
if (Flag(FERREXIT))
|
||||||
unwind(LERROR);
|
unwind(LERROR);
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -693,7 +693,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
|
|||||||
exstat = rv;
|
exstat = rv;
|
||||||
unwind(LLEAVE);
|
unwind(LLEAVE);
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -718,20 +718,20 @@ scriptexec(struct op *tp, const char **ap)
|
|||||||
#ifndef MKSH_SMALL
|
#ifndef MKSH_SMALL
|
||||||
if ((fd = open(tp->str, O_RDONLY)) >= 0) {
|
if ((fd = open(tp->str, O_RDONLY)) >= 0) {
|
||||||
/* read first MAXINTERP octets from file */
|
/* read first MAXINTERP octets from file */
|
||||||
if (read(fd, buf, sizeof (buf)) <= 0)
|
if (read(fd, buf, sizeof(buf)) <= 0)
|
||||||
/* read error -> no good */
|
/* read error -> no good */
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
close(fd);
|
close(fd);
|
||||||
/* scan for newline (or CR) or NUL _before_ end of buffer */
|
/* scan for newline (or CR) or NUL _before_ end of buffer */
|
||||||
cp = (unsigned char *)buf;
|
cp = (unsigned char *)buf;
|
||||||
while ((char *)cp < (buf + sizeof (buf)))
|
while ((char *)cp < (buf + sizeof(buf)))
|
||||||
if (*cp == '\0' || *cp == '\n' || *cp == '\r') {
|
if (*cp == '\0' || *cp == '\n' || *cp == '\r') {
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
++cp;
|
++cp;
|
||||||
/* if the shebang line is longer than MAXINTERP, bail out */
|
/* if the shebang line is longer than MAXINTERP, bail out */
|
||||||
if ((char *)cp >= (buf + sizeof (buf)))
|
if ((char *)cp >= (buf + sizeof(buf)))
|
||||||
goto noshebang;
|
goto noshebang;
|
||||||
/* skip UTF-8 Byte Order Mark, if present */
|
/* skip UTF-8 Byte Order Mark, if present */
|
||||||
cp = (unsigned char *)buf;
|
cp = (unsigned char *)buf;
|
||||||
@ -820,7 +820,7 @@ findfunc(const char *name, unsigned int h, int create)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tp;
|
return (tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -864,7 +864,7 @@ define(const char *name, struct op *t)
|
|||||||
if (t->u.ksh_func)
|
if (t->u.ksh_func)
|
||||||
tp->flag |= FKSH;
|
tp->flag |= FKSH;
|
||||||
|
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -981,7 +981,7 @@ findcom(const char *name, int flags)
|
|||||||
tp->u.fpath = npath.ro;
|
tp->u.fpath = npath.ro;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tp;
|
return (tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1012,7 +1012,7 @@ search_access(const char *lpath, int mode,
|
|||||||
struct stat statb;
|
struct stat statb;
|
||||||
|
|
||||||
if (stat(lpath, &statb) < 0)
|
if (stat(lpath, &statb) < 0)
|
||||||
return -1;
|
return (-1);
|
||||||
ret = access(lpath, mode);
|
ret = access(lpath, mode);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
err = errno; /* File exists, but we can't access it */
|
err = errno; /* File exists, but we can't access it */
|
||||||
@ -1024,7 +1024,7 @@ search_access(const char *lpath, int mode,
|
|||||||
}
|
}
|
||||||
if (err && errnop && !*errnop)
|
if (err && errnop && !*errnop)
|
||||||
*errnop = err;
|
*errnop = err;
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1045,7 +1045,7 @@ search(const char *name, const char *lpath,
|
|||||||
if (vstrchr(name, '/')) {
|
if (vstrchr(name, '/')) {
|
||||||
if (search_access(name, mode, errnop) == 0)
|
if (search_access(name, mode, errnop) == 0)
|
||||||
return (name);
|
return (name);
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
namelen = strlen(name) + 1;
|
namelen = strlen(name) + 1;
|
||||||
@ -1066,12 +1066,12 @@ search(const char *name, const char *lpath,
|
|||||||
XcheckN(xs, xp, namelen);
|
XcheckN(xs, xp, namelen);
|
||||||
memcpy(xp, name, namelen);
|
memcpy(xp, name, namelen);
|
||||||
if (search_access(Xstring(xs, xp), mode, errnop) == 0)
|
if (search_access(Xstring(xs, xp), mode, errnop) == 0)
|
||||||
return Xclose(xs, xp + namelen);
|
return (Xclose(xs, xp + namelen));
|
||||||
if (*sp++ == '\0')
|
if (*sp++ == '\0')
|
||||||
sp = NULL;
|
sp = NULL;
|
||||||
}
|
}
|
||||||
Xfree(xs, xp);
|
Xfree(xs, xp);
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -1089,7 +1089,7 @@ call_builtin(struct tbl *tp, const char **wp)
|
|||||||
shl_stdout_ok = 0;
|
shl_stdout_ok = 0;
|
||||||
builtin_flag = 0;
|
builtin_flag = 0;
|
||||||
builtin_argv0 = NULL;
|
builtin_argv0 = NULL;
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1161,10 +1161,10 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
|||||||
&emsg)) < 0) {
|
&emsg)) < 0) {
|
||||||
warningf(true, "%s: %s",
|
warningf(true, "%s: %s",
|
||||||
snptreef(NULL, 32, "%R", &iotmp), emsg);
|
snptreef(NULL, 32, "%R", &iotmp), emsg);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
if (u == iop->unit)
|
if (u == iop->unit)
|
||||||
return 0; /* "dup from" == "dup to" */
|
return (0); /* "dup from" == "dup to" */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1172,7 +1172,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
|||||||
if (do_open) {
|
if (do_open) {
|
||||||
if (Flag(FRESTRICTED) && (flags & O_CREAT)) {
|
if (Flag(FRESTRICTED) && (flags & O_CREAT)) {
|
||||||
warningf(true, "%s: restricted", cp);
|
warningf(true, "%s: restricted", cp);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
u = open(cp, flags, 0666);
|
u = open(cp, flags, 0666);
|
||||||
}
|
}
|
||||||
@ -1185,7 +1185,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
|||||||
(iotype == IOREAD || iotype == IOHERE) ?
|
(iotype == IOREAD || iotype == IOHERE) ?
|
||||||
"open" : "create", cp, strerror(u));
|
"open" : "create", cp, strerror(u));
|
||||||
}
|
}
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
/* Do not save if it has already been redirected (i.e. "cat >x >y"). */
|
/* Do not save if it has already been redirected (i.e. "cat >x >y"). */
|
||||||
if (e->savefd[iop->unit] == 0) {
|
if (e->savefd[iop->unit] == 0) {
|
||||||
@ -1215,7 +1215,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
|||||||
strerror(ev));
|
strerror(ev));
|
||||||
if (iotype != IODUP)
|
if (iotype != IODUP)
|
||||||
close(u);
|
close(u);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
if (iotype != IODUP)
|
if (iotype != IODUP)
|
||||||
close(u);
|
close(u);
|
||||||
@ -1231,7 +1231,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
|||||||
}
|
}
|
||||||
if (u == 2) /* Clear any write errors */
|
if (u == 2) /* Clear any write errors */
|
||||||
shf_reopen(2, SHF_WR, shl_out);
|
shf_reopen(2, SHF_WR, shl_out);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1250,7 +1250,7 @@ herein(const char *content, int sub)
|
|||||||
/* ksh -c 'cat << EOF' can cause this... */
|
/* ksh -c 'cat << EOF' can cause this... */
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
warningf(true, "here document missing");
|
warningf(true, "here document missing");
|
||||||
return -2; /* special to iosetup(): don't print error */
|
return (-2); /* special to iosetup(): don't print error */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create temp file to hold content (done before newenv so temp
|
/* Create temp file to hold content (done before newenv so temp
|
||||||
@ -1264,7 +1264,7 @@ herein(const char *content, int sub)
|
|||||||
h->name, strerror(fd));
|
h->name, strerror(fd));
|
||||||
if (shf)
|
if (shf)
|
||||||
shf_close(shf);
|
shf_close(shf);
|
||||||
return -2 /* special to iosetup(): don't print error */;
|
return (-2 /* special to iosetup(): don't print error */);
|
||||||
}
|
}
|
||||||
|
|
||||||
osource = source;
|
osource = source;
|
||||||
@ -1274,7 +1274,7 @@ herein(const char *content, int sub)
|
|||||||
source = osource;
|
source = osource;
|
||||||
quitenv(shf);
|
quitenv(shf);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -2; /* special to iosetup(): don't print error */
|
return (-2); /* special to iosetup(): don't print error */
|
||||||
}
|
}
|
||||||
if (sub) {
|
if (sub) {
|
||||||
/* Do substitutions on the content of heredoc */
|
/* Do substitutions on the content of heredoc */
|
||||||
@ -1296,10 +1296,10 @@ herein(const char *content, int sub)
|
|||||||
fd = errno;
|
fd = errno;
|
||||||
warningf(true, "error writing %s: %s, %s", h->name,
|
warningf(true, "error writing %s: %s, %s", h->name,
|
||||||
strerror(i), strerror(fd));
|
strerror(i), strerror(fd));
|
||||||
return -2; /* special to iosetup(): don't print error */
|
return (-2); /* special to iosetup(): don't print error */
|
||||||
}
|
}
|
||||||
|
|
||||||
return fd;
|
return (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1327,11 +1327,11 @@ do_selectargs(const char **ap, bool print_menu)
|
|||||||
pr_menu(ap);
|
pr_menu(ap);
|
||||||
shellf("%s", str_val(global("PS3")));
|
shellf("%s", str_val(global("PS3")));
|
||||||
if (call_builtin(findcom("read", FC_BI), read_args))
|
if (call_builtin(findcom("read", FC_BI), read_args))
|
||||||
return NULL;
|
return (NULL);
|
||||||
s = str_val(global("REPLY"));
|
s = str_val(global("REPLY"));
|
||||||
if (*s) {
|
if (*s) {
|
||||||
getn(s, &i);
|
getn(s, &i);
|
||||||
return (i >= 1 && i <= argct) ? ap[i - 1] : null;
|
return ((i >= 1 && i <= argct) ? ap[i - 1] : null);
|
||||||
}
|
}
|
||||||
print_menu = 1;
|
print_menu = 1;
|
||||||
}
|
}
|
||||||
@ -1354,7 +1354,7 @@ select_fmt_entry(const void *arg, int i, char *buf, int buflen)
|
|||||||
|
|
||||||
shf_snprintf(buf, buflen, "%*d) %s",
|
shf_snprintf(buf, buflen, "%*d) %s",
|
||||||
smi->num_width, i + 1, smi->args[i]);
|
smi->num_width, i + 1, smi->args[i]);
|
||||||
return buf;
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1395,7 +1395,7 @@ pr_menu(const char *const *ap)
|
|||||||
print_columns(shl_out, n, select_fmt_entry, (void *)&smi,
|
print_columns(shl_out, n, select_fmt_entry, (void *)&smi,
|
||||||
dwidth + nwidth + 2, 1);
|
dwidth + nwidth + 2, 1);
|
||||||
|
|
||||||
return n;
|
return (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: horrible kludge to fit within the framework */
|
/* XXX: horrible kludge to fit within the framework */
|
||||||
@ -1406,7 +1406,7 @@ static char *
|
|||||||
plain_fmt_entry(const void *arg, int i, char *buf, int buflen)
|
plain_fmt_entry(const void *arg, int i, char *buf, int buflen)
|
||||||
{
|
{
|
||||||
shf_snprintf(buf, buflen, "%s", ((char *const *)arg)[i]);
|
shf_snprintf(buf, buflen, "%s", ((char *const *)arg)[i]);
|
||||||
return buf;
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1422,7 +1422,7 @@ pr_list(char *const *ap)
|
|||||||
print_columns(shl_out, n, plain_fmt_entry, (const void *)ap,
|
print_columns(shl_out, n, plain_fmt_entry, (const void *)ap,
|
||||||
nwidth + 1, 0);
|
nwidth + 1, 0);
|
||||||
|
|
||||||
return n;
|
return (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1441,7 +1441,7 @@ dbteste_isa(Test_env *te, Test_meta meta)
|
|||||||
const char *p;
|
const char *p;
|
||||||
|
|
||||||
if (!*te->pos.wp)
|
if (!*te->pos.wp)
|
||||||
return meta == TM_END;
|
return (meta == TM_END);
|
||||||
|
|
||||||
/* unquoted word? */
|
/* unquoted word? */
|
||||||
for (p = *te->pos.wp; *p == CHAR; p += 2)
|
for (p = *te->pos.wp; *p == CHAR; p += 2)
|
||||||
@ -1468,7 +1468,7 @@ dbteste_isa(Test_env *te, Test_meta meta)
|
|||||||
if (ret)
|
if (ret)
|
||||||
te->pos.wp++;
|
te->pos.wp++;
|
||||||
|
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
@ -1477,19 +1477,19 @@ dbteste_getopnd(Test_env *te, Test_op op, bool do_eval)
|
|||||||
const char *s = *te->pos.wp;
|
const char *s = *te->pos.wp;
|
||||||
|
|
||||||
if (!s)
|
if (!s)
|
||||||
return NULL;
|
return (NULL);
|
||||||
|
|
||||||
te->pos.wp++;
|
te->pos.wp++;
|
||||||
|
|
||||||
if (!do_eval)
|
if (!do_eval)
|
||||||
return null;
|
return (null);
|
||||||
|
|
||||||
if (op == TO_STEQL || op == TO_STNEQ)
|
if (op == TO_STEQL || op == TO_STNEQ)
|
||||||
s = evalstr(s, DOTILDE | DOPAT);
|
s = evalstr(s, DOTILDE | DOPAT);
|
||||||
else
|
else
|
||||||
s = evalstr(s, DOTILDE);
|
s = evalstr(s, DOTILDE);
|
||||||
|
|
||||||
return s;
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
4
expr.c
4
expr.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.26 2009/05/16 16:59:35 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.27 2009/06/08 20:06:45 tg Exp $");
|
||||||
|
|
||||||
/* The order of these enums is constrained by the order of opinfo[] */
|
/* The order of these enums is constrained by the order of opinfo[] */
|
||||||
enum token {
|
enum token {
|
||||||
@ -603,7 +603,7 @@ tempvar(void)
|
|||||||
{
|
{
|
||||||
struct tbl *vp;
|
struct tbl *vp;
|
||||||
|
|
||||||
vp = alloc(sizeof (struct tbl), ATEMP);
|
vp = alloc(sizeof(struct tbl), ATEMP);
|
||||||
vp->flag = ISSET|INTEGER;
|
vp->flag = ISSET|INTEGER;
|
||||||
vp->type = 0;
|
vp->type = 0;
|
||||||
vp->areap = ATEMP;
|
vp->areap = ATEMP;
|
||||||
|
314
funcs.c
314
funcs.c
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.109 2009/05/21 14:28:33 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.110 2009/06/08 20:06:46 tg Exp $");
|
||||||
|
|
||||||
/* A leading = means assignments before command are kept;
|
/* A leading = means assignments before command are kept;
|
||||||
* a leading * means a POSIX special builtin;
|
* a leading * means a POSIX special builtin;
|
||||||
@ -172,13 +172,13 @@ c_cd(const char **wp)
|
|||||||
physical = true;
|
physical = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
if (Flag(FRESTRICTED)) {
|
if (Flag(FRESTRICTED)) {
|
||||||
bi_errorf("restricted shell - can't cd");
|
bi_errorf("restricted shell - can't cd");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pwd_s = global("PWD");
|
pwd_s = global("PWD");
|
||||||
@ -188,7 +188,7 @@ c_cd(const char **wp)
|
|||||||
/* No arguments - go home */
|
/* No arguments - go home */
|
||||||
if ((dir = str_val(global("HOME"))) == null) {
|
if ((dir = str_val(global("HOME"))) == null) {
|
||||||
bi_errorf("no home directory (HOME not set)");
|
bi_errorf("no home directory (HOME not set)");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
} else if (!wp[1]) {
|
} else if (!wp[1]) {
|
||||||
/* One argument: - or dir */
|
/* One argument: - or dir */
|
||||||
@ -199,7 +199,7 @@ c_cd(const char **wp)
|
|||||||
dir = str_val(oldpwd_s);
|
dir = str_val(oldpwd_s);
|
||||||
if (dir == null) {
|
if (dir == null) {
|
||||||
bi_errorf("no OLDPWD");
|
bi_errorf("no OLDPWD");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
printpath = true;
|
printpath = true;
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ c_cd(const char **wp)
|
|||||||
|
|
||||||
if (!current_wd[0]) {
|
if (!current_wd[0]) {
|
||||||
bi_errorf("don't know current directory");
|
bi_errorf("don't know current directory");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
/* substitute arg1 for arg2 in current path.
|
/* substitute arg1 for arg2 in current path.
|
||||||
* if the first substitution fails because the cd fails
|
* if the first substitution fails because the cd fails
|
||||||
@ -219,7 +219,7 @@ c_cd(const char **wp)
|
|||||||
*/
|
*/
|
||||||
if ((cp = strstr(current_wd, wp[0])) == NULL) {
|
if ((cp = strstr(current_wd, wp[0])) == NULL) {
|
||||||
bi_errorf("bad substitution");
|
bi_errorf("bad substitution");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
ilen = cp - current_wd;
|
ilen = cp - current_wd;
|
||||||
olen = strlen(wp[0]);
|
olen = strlen(wp[0]);
|
||||||
@ -232,7 +232,7 @@ c_cd(const char **wp)
|
|||||||
printpath = true;
|
printpath = true;
|
||||||
} else {
|
} else {
|
||||||
bi_errorf("too many arguments");
|
bi_errorf("too many arguments");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
XinitN(xs, PATH_MAX, ATEMP);
|
XinitN(xs, PATH_MAX, ATEMP);
|
||||||
@ -254,7 +254,7 @@ c_cd(const char **wp)
|
|||||||
else
|
else
|
||||||
bi_errorf("%s - %s", try, strerror(errno));
|
bi_errorf("%s - %s", try, strerror(errno));
|
||||||
afree(allocd, ATEMP);
|
afree(allocd, ATEMP);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear out tracked aliases with relative paths */
|
/* Clear out tracked aliases with relative paths */
|
||||||
@ -288,7 +288,7 @@ c_cd(const char **wp)
|
|||||||
shprintf("%s\n", pwd);
|
shprintf("%s\n", pwd);
|
||||||
|
|
||||||
afree(allocd, ATEMP);
|
afree(allocd, ATEMP);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -307,13 +307,13 @@ c_pwd(const char **wp)
|
|||||||
physical = true;
|
physical = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
if (wp[0]) {
|
if (wp[0]) {
|
||||||
bi_errorf("too many arguments");
|
bi_errorf("too many arguments");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
p = current_wd[0] ? (physical ? get_phys_path(current_wd) :
|
p = current_wd[0] ? (physical ? get_phys_path(current_wd) :
|
||||||
current_wd) : NULL;
|
current_wd) : NULL;
|
||||||
@ -325,7 +325,7 @@ c_pwd(const char **wp)
|
|||||||
}
|
}
|
||||||
shprintf("%s\n", p);
|
shprintf("%s\n", p);
|
||||||
afree(allocd, ATEMP);
|
afree(allocd, ATEMP);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -399,7 +399,7 @@ c_print(const char **wp)
|
|||||||
case 'p':
|
case 'p':
|
||||||
if ((fd = coproc_getfd(W_OK, &emsg)) < 0) {
|
if ((fd = coproc_getfd(W_OK, &emsg)) < 0) {
|
||||||
bi_errorf("-p: %s", emsg);
|
bi_errorf("-p: %s", emsg);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
@ -413,11 +413,11 @@ c_print(const char **wp)
|
|||||||
fd = 0;
|
fd = 0;
|
||||||
else if ((fd = check_fd(s, W_OK, &emsg)) < 0) {
|
else if ((fd = check_fd(s, W_OK, &emsg)) < 0) {
|
||||||
bi_errorf("-u: %s: %s", s, emsg);
|
bi_errorf("-u: %s: %s", s, emsg);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (!(builtin_opt.info & GI_MINUSMINUS)) {
|
if (!(builtin_opt.info & GI_MINUSMINUS)) {
|
||||||
/* treat a lone - like -- */
|
/* treat a lone - like -- */
|
||||||
@ -560,7 +560,7 @@ c_print(const char **wp)
|
|||||||
opipe = block_pipe();
|
opipe = block_pipe();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
s += n;
|
s += n;
|
||||||
len -= n;
|
len -= n;
|
||||||
@ -569,7 +569,7 @@ c_print(const char **wp)
|
|||||||
restore_pipe(opipe);
|
restore_pipe(opipe);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -594,7 +594,7 @@ c_whence(const char **wp)
|
|||||||
Vflag = true;
|
Vflag = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
@ -684,7 +684,7 @@ c_whence(const char **wp)
|
|||||||
if (vflag || !rv)
|
if (vflag || !rv)
|
||||||
shf_putc('\n', shl_stdout);
|
shf_putc('\n', shl_stdout);
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Deal with command -vV - command -p dealt with in comexec() */
|
/* Deal with command -vV - command -p dealt with in comexec() */
|
||||||
@ -694,7 +694,7 @@ c_command(const char **wp)
|
|||||||
/* Let c_whence do the work. Note that c_command() must be
|
/* Let c_whence do the work. Note that c_command() must be
|
||||||
* a distinct function from c_whence() (tested in comexec()).
|
* a distinct function from c_whence() (tested in comexec()).
|
||||||
*/
|
*/
|
||||||
return c_whence(wp);
|
return (c_whence(wp));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* typeset, export, and readonly */
|
/* typeset, export, and readonly */
|
||||||
@ -791,7 +791,7 @@ c_typeset(const char **wp)
|
|||||||
flag = EXPORT;
|
flag = EXPORT;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (builtin_opt.info & GI_PLUS) {
|
if (builtin_opt.info & GI_PLUS) {
|
||||||
fclr |= flag;
|
fclr |= flag;
|
||||||
@ -806,10 +806,10 @@ c_typeset(const char **wp)
|
|||||||
|
|
||||||
field = 0;
|
field = 0;
|
||||||
if (fieldstr && !bi_getn(fieldstr, &field))
|
if (fieldstr && !bi_getn(fieldstr, &field))
|
||||||
return 1;
|
return (1);
|
||||||
base = 0;
|
base = 0;
|
||||||
if (basestr && !bi_getn(basestr, &base))
|
if (basestr && !bi_getn(basestr, &base))
|
||||||
return 1;
|
return (1);
|
||||||
|
|
||||||
if (!(builtin_opt.info & GI_MINUSMINUS) && wp[builtin_opt.optind] &&
|
if (!(builtin_opt.info & GI_MINUSMINUS) && wp[builtin_opt.optind] &&
|
||||||
(wp[builtin_opt.optind][0] == '-' ||
|
(wp[builtin_opt.optind][0] == '-' ||
|
||||||
@ -821,7 +821,7 @@ c_typeset(const char **wp)
|
|||||||
|
|
||||||
if (func && ((fset|fclr) & ~(TRACE|UCASEV_AL|EXPORT))) {
|
if (func && ((fset|fclr) & ~(TRACE|UCASEV_AL|EXPORT))) {
|
||||||
bi_errorf("only -t, -u and -x options may be used with -f");
|
bi_errorf("only -t, -u and -x options may be used with -f");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (wp[builtin_opt.optind]) {
|
if (wp[builtin_opt.optind]) {
|
||||||
/* Take care of exclusions.
|
/* Take care of exclusions.
|
||||||
@ -871,10 +871,10 @@ c_typeset(const char **wp)
|
|||||||
"%s() %T\n", wp[i], f->val.t);
|
"%s() %T\n", wp[i], f->val.t);
|
||||||
} else if (!typeset(wp[i], fset, fclr, field, base)) {
|
} else if (!typeset(wp[i], fset, fclr, field, base)) {
|
||||||
bi_errorf("%s: not identifier", wp[i]);
|
bi_errorf("%s: not identifier", wp[i]);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* list variables and attributes */
|
/* list variables and attributes */
|
||||||
@ -1011,7 +1011,7 @@ c_typeset(const char **wp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1054,7 +1054,7 @@ c_alias(const char **wp)
|
|||||||
xflag = EXPORT;
|
xflag = EXPORT;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
@ -1076,10 +1076,10 @@ c_alias(const char **wp)
|
|||||||
if (!tflag || *wp) {
|
if (!tflag || *wp) {
|
||||||
shf_puts("alias: -r flag can only be used with -t"
|
shf_puts("alias: -r flag can only be used with -t"
|
||||||
" and without arguments\n", shl_stdout);
|
" and without arguments\n", shl_stdout);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
ksh_getopt_reset(&builtin_opt, GF_ERROR);
|
ksh_getopt_reset(&builtin_opt, GF_ERROR);
|
||||||
return c_unalias(args);
|
return (c_unalias(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*wp == NULL) {
|
if (*wp == NULL) {
|
||||||
@ -1150,7 +1150,7 @@ c_alias(const char **wp)
|
|||||||
afree(xalias, ATEMP);
|
afree(xalias, ATEMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1177,7 +1177,7 @@ c_unalias(const char **wp)
|
|||||||
t = &taliases;
|
t = &taliases;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
@ -1206,7 +1206,7 @@ c_unalias(const char **wp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1224,7 +1224,7 @@ c_let(const char **wp)
|
|||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
rv = val == 0;
|
rv = val == 0;
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1247,7 +1247,7 @@ c_jobs(const char **wp)
|
|||||||
nflag = -1;
|
nflag = -1;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
if (!*wp) {
|
if (!*wp) {
|
||||||
@ -1258,7 +1258,7 @@ c_jobs(const char **wp)
|
|||||||
if (j_jobs(*wp, flag, nflag))
|
if (j_jobs(*wp, flag, nflag))
|
||||||
rv = 1;
|
rv = 1;
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MKSH_UNEMPLOYED
|
#ifndef MKSH_UNEMPLOYED
|
||||||
@ -1270,17 +1270,17 @@ c_fgbg(const char **wp)
|
|||||||
|
|
||||||
if (!Flag(FMONITOR)) {
|
if (!Flag(FMONITOR)) {
|
||||||
bi_errorf("job control not enabled");
|
bi_errorf("job control not enabled");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||||
return 1;
|
return (1);
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
if (*wp)
|
if (*wp)
|
||||||
for (; *wp; wp++)
|
for (; *wp; wp++)
|
||||||
rv = j_resume(*wp, bg);
|
rv = j_resume(*wp, bg);
|
||||||
else
|
else
|
||||||
rv = j_resume("%%", bg);
|
rv = j_resume("%%", bg);
|
||||||
return bg ? 0 : rv;
|
return (bg ? 0 : rv);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1295,7 +1295,7 @@ kill_fmt_entry(const void *arg, int i, char *buf, int buflen)
|
|||||||
ki->num_width, i,
|
ki->num_width, i,
|
||||||
ki->name_width, sigtraps[i].name,
|
ki->name_width, sigtraps[i].name,
|
||||||
sigtraps[i].mess);
|
sigtraps[i].mess);
|
||||||
return buf;
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1311,7 +1311,7 @@ c_kill(const char **wp)
|
|||||||
ksh_isupper(p[1]))) {
|
ksh_isupper(p[1]))) {
|
||||||
if (!(t = gettrap(p + 1, true))) {
|
if (!(t = gettrap(p + 1, true))) {
|
||||||
bi_errorf("bad signal '%s'", p + 1);
|
bi_errorf("bad signal '%s'", p + 1);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
i = (wp[2] && strcmp(wp[2], "--") == 0) ? 3 : 2;
|
i = (wp[2] && strcmp(wp[2], "--") == 0) ? 3 : 2;
|
||||||
} else {
|
} else {
|
||||||
@ -1326,11 +1326,11 @@ c_kill(const char **wp)
|
|||||||
if (!(t = gettrap(builtin_opt.optarg, true))) {
|
if (!(t = gettrap(builtin_opt.optarg, true))) {
|
||||||
bi_errorf("bad signal '%s'",
|
bi_errorf("bad signal '%s'",
|
||||||
builtin_opt.optarg);
|
builtin_opt.optarg);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
i = builtin_opt.optind;
|
i = builtin_opt.optind;
|
||||||
}
|
}
|
||||||
@ -1341,14 +1341,14 @@ c_kill(const char **wp)
|
|||||||
"\tkill -l [exit_status ...]\n", shl_out);
|
"\tkill -l [exit_status ...]\n", shl_out);
|
||||||
#endif
|
#endif
|
||||||
bi_errorfz();
|
bi_errorfz();
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lflag) {
|
if (lflag) {
|
||||||
if (wp[i]) {
|
if (wp[i]) {
|
||||||
for (; wp[i]; i++) {
|
for (; wp[i]; i++) {
|
||||||
if (!bi_getn(wp[i], &n))
|
if (!bi_getn(wp[i], &n))
|
||||||
return 1;
|
return (1);
|
||||||
if (n > 128 && n < 128 + NSIG)
|
if (n > 128 && n < 128 + NSIG)
|
||||||
n -= 128;
|
n -= 128;
|
||||||
if (n > 0 && n < NSIG)
|
if (n > 0 && n < NSIG)
|
||||||
@ -1377,7 +1377,7 @@ c_kill(const char **wp)
|
|||||||
kill_fmt_entry, (void *)&ki,
|
kill_fmt_entry, (void *)&ki,
|
||||||
ki.num_width + ki.name_width + mess_width + 3, 1);
|
ki.num_width + ki.name_width + mess_width + 3, 1);
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
rv = 0;
|
rv = 0;
|
||||||
sig = t ? t->signal : SIGTERM;
|
sig = t ? t->signal : SIGTERM;
|
||||||
@ -1399,7 +1399,7 @@ c_kill(const char **wp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1420,28 +1420,28 @@ c_getopts(const char **wp)
|
|||||||
struct tbl *vq, *voptarg;
|
struct tbl *vq, *voptarg;
|
||||||
|
|
||||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||||
return 1;
|
return (1);
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
opts = *wp++;
|
opts = *wp++;
|
||||||
if (!opts) {
|
if (!opts) {
|
||||||
bi_errorf("missing options argument");
|
bi_errorf("missing options argument");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var = *wp++;
|
var = *wp++;
|
||||||
if (!var) {
|
if (!var) {
|
||||||
bi_errorf("missing name argument");
|
bi_errorf("missing name argument");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (!*var || *skip_varname(var, true)) {
|
if (!*var || *skip_varname(var, true)) {
|
||||||
bi_errorf("%s: is not an identifier", var);
|
bi_errorf("%s: is not an identifier", var);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e->loc->next == NULL) {
|
if (e->loc->next == NULL) {
|
||||||
internal_warningf("c_getopts: no argv");
|
internal_warningf("c_getopts: no argv");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
/* Which arguments are we parsing... */
|
/* Which arguments are we parsing... */
|
||||||
if (*wp == NULL)
|
if (*wp == NULL)
|
||||||
@ -1456,7 +1456,7 @@ c_getopts(const char **wp)
|
|||||||
(user_opt.p != 0 &&
|
(user_opt.p != 0 &&
|
||||||
user_opt.p > strlen(wp[user_opt.optind - 1]))) {
|
user_opt.p > strlen(wp[user_opt.optind - 1]))) {
|
||||||
bi_errorf("arguments changed since last call");
|
bi_errorf("arguments changed since last call");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
user_opt.optarg = NULL;
|
user_opt.optarg = NULL;
|
||||||
@ -1502,7 +1502,7 @@ c_getopts(const char **wp)
|
|||||||
if (Flag(FEXPORT))
|
if (Flag(FEXPORT))
|
||||||
typeset(var, EXPORT, 0, 0, 0);
|
typeset(var, EXPORT, 0, 0, 0);
|
||||||
|
|
||||||
return optc < 0 ? 1 : rv;
|
return (optc < 0 ? 1 : rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1522,7 +1522,7 @@ c_bind(const char **wp)
|
|||||||
macro = true;
|
macro = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
@ -1541,14 +1541,14 @@ c_bind(const char **wp)
|
|||||||
afree(up, ATEMP);
|
afree(up, ATEMP);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* :, false and true */
|
/* :, false and true */
|
||||||
int
|
int
|
||||||
c_label(const char **wp)
|
c_label(const char **wp)
|
||||||
{
|
{
|
||||||
return wp[0][0] == 'f' ? 1 : 0;
|
return (wp[0][0] == 'f' ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1560,7 +1560,7 @@ c_shift(const char **wp)
|
|||||||
const char *arg;
|
const char *arg;
|
||||||
|
|
||||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||||
return 1;
|
return (1);
|
||||||
arg = wp[builtin_opt.optind];
|
arg = wp[builtin_opt.optind];
|
||||||
|
|
||||||
if (arg) {
|
if (arg) {
|
||||||
@ -1579,7 +1579,7 @@ c_shift(const char **wp)
|
|||||||
l->argv[n] = l->argv[0];
|
l->argv[n] = l->argv[0];
|
||||||
l->argv += n;
|
l->argv += n;
|
||||||
l->argc -= n;
|
l->argc -= n;
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1596,7 +1596,7 @@ c_umask(const char **wp)
|
|||||||
symbolic = true;
|
symbolic = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
cp = wp[builtin_opt.optind];
|
cp = wp[builtin_opt.optind];
|
||||||
if (cp == NULL) {
|
if (cp == NULL) {
|
||||||
@ -1628,7 +1628,7 @@ c_umask(const char **wp)
|
|||||||
new_umask = new_umask * 8 + (*cp - '0');
|
new_umask = new_umask * 8 + (*cp - '0');
|
||||||
if (*cp) {
|
if (*cp) {
|
||||||
bi_errorf("bad number");
|
bi_errorf("bad number");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* symbolic format */
|
/* symbolic format */
|
||||||
@ -1699,7 +1699,7 @@ c_umask(const char **wp)
|
|||||||
}
|
}
|
||||||
if (*cp) {
|
if (*cp) {
|
||||||
bi_errorf("bad mask");
|
bi_errorf("bad mask");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
new_umask = ~new_umask;
|
new_umask = ~new_umask;
|
||||||
}
|
}
|
||||||
@ -1751,7 +1751,7 @@ c_wait(const char **wp)
|
|||||||
int rv = 0, sig;
|
int rv = 0, sig;
|
||||||
|
|
||||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||||
return 1;
|
return (1);
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
if (*wp == NULL) {
|
if (*wp == NULL) {
|
||||||
while (waitfor(NULL, &sig) >= 0)
|
while (waitfor(NULL, &sig) >= 0)
|
||||||
@ -1763,7 +1763,7 @@ c_wait(const char **wp)
|
|||||||
if (rv < 0)
|
if (rv < 0)
|
||||||
rv = sig ? sig : 127; /* magic exit code: bad job-id */
|
rv = sig ? sig : 127; /* magic exit code: bad job-id */
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1783,7 +1783,7 @@ c_read(const char **wp)
|
|||||||
case 'p':
|
case 'p':
|
||||||
if ((fd = coproc_getfd(R_OK, &emsg)) < 0) {
|
if ((fd = coproc_getfd(R_OK, &emsg)) < 0) {
|
||||||
bi_errorf("-p: %s", emsg);
|
bi_errorf("-p: %s", emsg);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
@ -1797,11 +1797,11 @@ c_read(const char **wp)
|
|||||||
fd = 0;
|
fd = 0;
|
||||||
else if ((fd = check_fd(cp, R_OK, &emsg)) < 0) {
|
else if ((fd = check_fd(cp, R_OK, &emsg)) < 0) {
|
||||||
bi_errorf("-u: %s: %s", cp, emsg);
|
bi_errorf("-u: %s: %s", cp, emsg);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
@ -1912,14 +1912,14 @@ c_read(const char **wp)
|
|||||||
shf_flush(shf);
|
shf_flush(shf);
|
||||||
bi_errorf("%s is read only", *wp);
|
bi_errorf("%s is read only", *wp);
|
||||||
afree(wpalloc, ATEMP);
|
afree(wpalloc, ATEMP);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (Flag(FEXPORT))
|
if (Flag(FEXPORT))
|
||||||
typeset(*wp, EXPORT, 0, 0, 0);
|
typeset(*wp, EXPORT, 0, 0, 0);
|
||||||
if (!setstr(vp, Xstring(cs, ccp), KSH_RETURN_ERROR)) {
|
if (!setstr(vp, Xstring(cs, ccp), KSH_RETURN_ERROR)) {
|
||||||
shf_flush(shf);
|
shf_flush(shf);
|
||||||
afree(wpalloc, ATEMP);
|
afree(wpalloc, ATEMP);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1937,7 +1937,7 @@ c_read(const char **wp)
|
|||||||
coproc_read_close(fd);
|
coproc_read_close(fd);
|
||||||
|
|
||||||
afree(wpalloc, ATEMP);
|
afree(wpalloc, ATEMP);
|
||||||
return ecode ? ecode : c == EOF;
|
return (ecode ? ecode : c == EOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -1948,7 +1948,7 @@ c_eval(const char **wp)
|
|||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||||
return 1;
|
return (1);
|
||||||
s = pushs(SWORDS, ATEMP);
|
s = pushs(SWORDS, ATEMP);
|
||||||
s->u.strv = wp + builtin_opt.optind;
|
s->u.strv = wp + builtin_opt.optind;
|
||||||
|
|
||||||
@ -1995,7 +1995,7 @@ c_trap(const char **wp)
|
|||||||
Trap *p;
|
Trap *p;
|
||||||
|
|
||||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||||
return 1;
|
return (1);
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
if (*wp == NULL) {
|
if (*wp == NULL) {
|
||||||
@ -2005,7 +2005,7 @@ c_trap(const char **wp)
|
|||||||
print_value_quoted(p->trap);
|
print_value_quoted(p->trap);
|
||||||
shprintf(" %s\n", p->name);
|
shprintf(" %s\n", p->name);
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2022,11 +2022,11 @@ c_trap(const char **wp)
|
|||||||
p = gettrap(*wp++, true);
|
p = gettrap(*wp++, true);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
bi_errorf("bad signal %s", wp[-1]);
|
bi_errorf("bad signal %s", wp[-1]);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
settrap(p, s);
|
settrap(p, s);
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -2036,7 +2036,7 @@ c_exitreturn(const char **wp)
|
|||||||
const char *arg;
|
const char *arg;
|
||||||
|
|
||||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||||
return 1;
|
return (1);
|
||||||
arg = wp[builtin_opt.optind];
|
arg = wp[builtin_opt.optind];
|
||||||
|
|
||||||
if (arg) {
|
if (arg) {
|
||||||
@ -2077,18 +2077,18 @@ c_brkcont(const char **wp)
|
|||||||
const char *arg;
|
const char *arg;
|
||||||
|
|
||||||
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
if (ksh_getopt(wp, &builtin_opt, null) == '?')
|
||||||
return 1;
|
return (1);
|
||||||
arg = wp[builtin_opt.optind];
|
arg = wp[builtin_opt.optind];
|
||||||
|
|
||||||
if (!arg)
|
if (!arg)
|
||||||
n = 1;
|
n = 1;
|
||||||
else if (!bi_getn(arg, &n))
|
else if (!bi_getn(arg, &n))
|
||||||
return 1;
|
return (1);
|
||||||
quit = n;
|
quit = n;
|
||||||
if (quit <= 0) {
|
if (quit <= 0) {
|
||||||
/* at&t ksh does this for non-interactive shells only - weird */
|
/* at&t ksh does this for non-interactive shells only - weird */
|
||||||
bi_errorf("%s: bad value", arg);
|
bi_errorf("%s: bad value", arg);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Stop at E_NONE, E_PARSE, E_FUNC, or E_INCL */
|
/* Stop at E_NONE, E_PARSE, E_FUNC, or E_INCL */
|
||||||
@ -2107,7 +2107,7 @@ c_brkcont(const char **wp)
|
|||||||
*/
|
*/
|
||||||
if (n == quit) {
|
if (n == quit) {
|
||||||
warningf(true, "%s: cannot %s", wp[0], wp[0]);
|
warningf(true, "%s: cannot %s", wp[0], wp[0]);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
/* POSIX says if n is too big, the last enclosing loop
|
/* POSIX says if n is too big, the last enclosing loop
|
||||||
* shall be used. Doesn't say to print an error but we
|
* shall be used. Doesn't say to print an error but we
|
||||||
@ -2132,12 +2132,12 @@ c_set(const char **wp)
|
|||||||
|
|
||||||
if (wp[1] == NULL) {
|
if (wp[1] == NULL) {
|
||||||
static const char *args [] = { "set", "-", NULL };
|
static const char *args [] = { "set", "-", NULL };
|
||||||
return c_typeset(args);
|
return (c_typeset(args));
|
||||||
}
|
}
|
||||||
|
|
||||||
argi = parse_args(wp, OF_SET, &setargs);
|
argi = parse_args(wp, OF_SET, &setargs);
|
||||||
if (argi < 0)
|
if (argi < 0)
|
||||||
return 1;
|
return (1);
|
||||||
/* set $# and $* */
|
/* set $# and $* */
|
||||||
if (setargs) {
|
if (setargs) {
|
||||||
owp = wp += argi - 1;
|
owp = wp += argi - 1;
|
||||||
@ -2145,7 +2145,7 @@ c_set(const char **wp)
|
|||||||
while (*++wp != NULL)
|
while (*++wp != NULL)
|
||||||
strdupx(*wp, *wp, &l->area);
|
strdupx(*wp, *wp, &l->area);
|
||||||
l->argc = wp - owp - 1;
|
l->argc = wp - owp - 1;
|
||||||
l->argv = alloc((l->argc + 2) * sizeof (char *), &l->area);
|
l->argv = alloc((l->argc + 2) * sizeof(char *), &l->area);
|
||||||
for (wp = l->argv; (*wp++ = *owp++) != NULL; )
|
for (wp = l->argv; (*wp++ = *owp++) != NULL; )
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -2155,7 +2155,7 @@ c_set(const char **wp)
|
|||||||
* (subst_exstat is cleared in execute() so that it will be 0
|
* (subst_exstat is cleared in execute() so that it will be 0
|
||||||
* if there are no command substitutions).
|
* if there are no command substitutions).
|
||||||
*/
|
*/
|
||||||
return subst_exstat;
|
return (subst_exstat);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -2221,7 +2221,7 @@ c_times(const char **wp __unused)
|
|||||||
p_time(shl_stdout, false, usage.ru_stime.tv_sec,
|
p_time(shl_stdout, false, usage.ru_stime.tv_sec,
|
||||||
usage.ru_stime.tv_usec, 0, null, "\n");
|
usage.ru_stime.tv_usec, 0, null, "\n");
|
||||||
|
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2346,7 +2346,7 @@ c_exec(const char **wp __unused)
|
|||||||
}
|
}
|
||||||
e->savefd = NULL;
|
e->savefd = NULL;
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HAVE_MKNOD
|
#if HAVE_MKNOD
|
||||||
@ -2443,7 +2443,7 @@ c_mknod(const char **wp)
|
|||||||
int
|
int
|
||||||
c_builtin(const char **wp __unused)
|
c_builtin(const char **wp __unused)
|
||||||
{
|
{
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* test(1) accepts the following grammar:
|
/* test(1) accepts the following grammar:
|
||||||
@ -2487,7 +2487,7 @@ c_test(const char **wp)
|
|||||||
if (strcmp(wp[0], "[") == 0) {
|
if (strcmp(wp[0], "[") == 0) {
|
||||||
if (strcmp(wp[--argc], "]") != 0) {
|
if (strcmp(wp[--argc], "]") != 0) {
|
||||||
bi_errorf("missing ]");
|
bi_errorf("missing ]");
|
||||||
return T_ERR_EXIT;
|
return (T_ERR_EXIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2507,7 +2507,7 @@ c_test(const char **wp)
|
|||||||
|
|
||||||
while (--argc >= 0) {
|
while (--argc >= 0) {
|
||||||
if ((*te.isa)(&te, TM_END))
|
if ((*te.isa)(&te, TM_END))
|
||||||
return !0;
|
return (!0);
|
||||||
if (argc == 3) {
|
if (argc == 3) {
|
||||||
opnd1 = (*te.getopnd)(&te, TO_NONOP, 1);
|
opnd1 = (*te.getopnd)(&te, TO_NONOP, 1);
|
||||||
if ((op = (*te.isa)(&te, TM_BINOP))) {
|
if ((op = (*te.isa)(&te, TM_BINOP))) {
|
||||||
@ -2515,10 +2515,10 @@ c_test(const char **wp)
|
|||||||
res = (*te.eval)(&te, op, opnd1,
|
res = (*te.eval)(&te, op, opnd1,
|
||||||
opnd2, 1);
|
opnd2, 1);
|
||||||
if (te.flags & TEF_ERROR)
|
if (te.flags & TEF_ERROR)
|
||||||
return T_ERR_EXIT;
|
return (T_ERR_EXIT);
|
||||||
if (invert & 1)
|
if (invert & 1)
|
||||||
res = !res;
|
res = !res;
|
||||||
return !res;
|
return (!res);
|
||||||
}
|
}
|
||||||
/* back up to opnd1 */
|
/* back up to opnd1 */
|
||||||
te.pos.wp--;
|
te.pos.wp--;
|
||||||
@ -2531,7 +2531,7 @@ c_test(const char **wp)
|
|||||||
NULL, 1);
|
NULL, 1);
|
||||||
if (invert & 1)
|
if (invert & 1)
|
||||||
res = !res;
|
res = !res;
|
||||||
return !res;
|
return (!res);
|
||||||
}
|
}
|
||||||
if ((*te.isa)(&te, TM_NOT)) {
|
if ((*te.isa)(&te, TM_NOT)) {
|
||||||
invert++;
|
invert++;
|
||||||
@ -2541,7 +2541,7 @@ c_test(const char **wp)
|
|||||||
te.pos.wp = owp + 1;
|
te.pos.wp = owp + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return test_parse(&te);
|
return (test_parse(&te));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2559,9 +2559,9 @@ test_isop(Test_meta meta, const char *s)
|
|||||||
sc1 = s[1];
|
sc1 = s[1];
|
||||||
for (; tbl->op_text[0]; tbl++)
|
for (; tbl->op_text[0]; tbl++)
|
||||||
if (sc1 == tbl->op_text[1] && !strcmp(s, tbl->op_text))
|
if (sc1 == tbl->op_text[1] && !strcmp(s, tbl->op_text))
|
||||||
return tbl->op_num;
|
return (tbl->op_num);
|
||||||
}
|
}
|
||||||
return TO_NONOP;
|
return (TO_NONOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -2574,16 +2574,16 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
|||||||
mksh_ari_t v1, v2;
|
mksh_ari_t v1, v2;
|
||||||
|
|
||||||
if (!do_eval)
|
if (!do_eval)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
switch ((int)op) {
|
switch ((int)op) {
|
||||||
/*
|
/*
|
||||||
* Unary Operators
|
* Unary Operators
|
||||||
*/
|
*/
|
||||||
case TO_STNZE: /* -n */
|
case TO_STNZE: /* -n */
|
||||||
return *opnd1 != '\0';
|
return (*opnd1 != '\0');
|
||||||
case TO_STZER: /* -z */
|
case TO_STZER: /* -z */
|
||||||
return *opnd1 == '\0';
|
return (*opnd1 == '\0');
|
||||||
case TO_OPTION: /* -o */
|
case TO_OPTION: /* -o */
|
||||||
if ((i = *opnd1 == '!'))
|
if ((i = *opnd1 == '!'))
|
||||||
opnd1++;
|
opnd1++;
|
||||||
@ -2594,47 +2594,47 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
|||||||
if (i)
|
if (i)
|
||||||
k = !k;
|
k = !k;
|
||||||
}
|
}
|
||||||
return k;
|
return (k);
|
||||||
case TO_FILRD: /* -r */
|
case TO_FILRD: /* -r */
|
||||||
return test_eaccess(opnd1, R_OK) == 0;
|
return (test_eaccess(opnd1, R_OK) == 0);
|
||||||
case TO_FILWR: /* -w */
|
case TO_FILWR: /* -w */
|
||||||
return test_eaccess(opnd1, W_OK) == 0;
|
return (test_eaccess(opnd1, W_OK) == 0);
|
||||||
case TO_FILEX: /* -x */
|
case TO_FILEX: /* -x */
|
||||||
return test_eaccess(opnd1, X_OK) == 0;
|
return (test_eaccess(opnd1, X_OK) == 0);
|
||||||
case TO_FILAXST: /* -a */
|
case TO_FILAXST: /* -a */
|
||||||
case TO_FILEXST: /* -e */
|
case TO_FILEXST: /* -e */
|
||||||
return stat(opnd1, &b1) == 0;
|
return (stat(opnd1, &b1) == 0);
|
||||||
case TO_FILREG: /* -r */
|
case TO_FILREG: /* -r */
|
||||||
return stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode);
|
return (stat(opnd1, &b1) == 0 && S_ISREG(b1.st_mode));
|
||||||
case TO_FILID: /* -d */
|
case TO_FILID: /* -d */
|
||||||
return stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode);
|
return (stat(opnd1, &b1) == 0 && S_ISDIR(b1.st_mode));
|
||||||
case TO_FILCDEV: /* -c */
|
case TO_FILCDEV: /* -c */
|
||||||
return stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode);
|
return (stat(opnd1, &b1) == 0 && S_ISCHR(b1.st_mode));
|
||||||
case TO_FILBDEV: /* -b */
|
case TO_FILBDEV: /* -b */
|
||||||
return stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode);
|
return (stat(opnd1, &b1) == 0 && S_ISBLK(b1.st_mode));
|
||||||
case TO_FILFIFO: /* -p */
|
case TO_FILFIFO: /* -p */
|
||||||
return stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode);
|
return (stat(opnd1, &b1) == 0 && S_ISFIFO(b1.st_mode));
|
||||||
case TO_FILSYM: /* -h -L */
|
case TO_FILSYM: /* -h -L */
|
||||||
return lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode);
|
return (lstat(opnd1, &b1) == 0 && S_ISLNK(b1.st_mode));
|
||||||
case TO_FILSOCK: /* -S */
|
case TO_FILSOCK: /* -S */
|
||||||
return stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode);
|
return (stat(opnd1, &b1) == 0 && S_ISSOCK(b1.st_mode));
|
||||||
case TO_FILCDF:/* -H HP context dependent files (directories) */
|
case TO_FILCDF:/* -H HP context dependent files (directories) */
|
||||||
return 0;
|
return (0);
|
||||||
case TO_FILSETU: /* -u */
|
case TO_FILSETU: /* -u */
|
||||||
return stat(opnd1, &b1) == 0 &&
|
return (stat(opnd1, &b1) == 0 &&
|
||||||
(b1.st_mode & S_ISUID) == S_ISUID;
|
(b1.st_mode & S_ISUID) == S_ISUID);
|
||||||
case TO_FILSETG: /* -g */
|
case TO_FILSETG: /* -g */
|
||||||
return stat(opnd1, &b1) == 0 &&
|
return (stat(opnd1, &b1) == 0 &&
|
||||||
(b1.st_mode & S_ISGID) == S_ISGID;
|
(b1.st_mode & S_ISGID) == S_ISGID);
|
||||||
case TO_FILSTCK: /* -k */
|
case TO_FILSTCK: /* -k */
|
||||||
#ifdef S_ISVTX
|
#ifdef S_ISVTX
|
||||||
return stat(opnd1, &b1) == 0 &&
|
return (stat(opnd1, &b1) == 0 &&
|
||||||
(b1.st_mode & S_ISVTX) == S_ISVTX;
|
(b1.st_mode & S_ISVTX) == S_ISVTX);
|
||||||
#else
|
#else
|
||||||
return (0);
|
return (0);
|
||||||
#endif
|
#endif
|
||||||
case TO_FILGZ: /* -s */
|
case TO_FILGZ: /* -s */
|
||||||
return stat(opnd1, &b1) == 0 && b1.st_size > 0L;
|
return (stat(opnd1, &b1) == 0 && b1.st_size > 0L);
|
||||||
case TO_FILTT: /* -t */
|
case TO_FILTT: /* -t */
|
||||||
if (opnd1 && !bi_getn(opnd1, &i)) {
|
if (opnd1 && !bi_getn(opnd1, &i)) {
|
||||||
te->flags |= TEF_ERROR;
|
te->flags |= TEF_ERROR;
|
||||||
@ -2643,24 +2643,24 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
|||||||
i = isatty(opnd1 ? i : 0);
|
i = isatty(opnd1 ? i : 0);
|
||||||
return (i);
|
return (i);
|
||||||
case TO_FILUID: /* -O */
|
case TO_FILUID: /* -O */
|
||||||
return stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid;
|
return (stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid);
|
||||||
case TO_FILGID: /* -G */
|
case TO_FILGID: /* -G */
|
||||||
return stat(opnd1, &b1) == 0 && b1.st_gid == getegid();
|
return (stat(opnd1, &b1) == 0 && b1.st_gid == getegid());
|
||||||
/*
|
/*
|
||||||
* Binary Operators
|
* Binary Operators
|
||||||
*/
|
*/
|
||||||
case TO_STEQL: /* = */
|
case TO_STEQL: /* = */
|
||||||
if (te->flags & TEF_DBRACKET)
|
if (te->flags & TEF_DBRACKET)
|
||||||
return gmatchx(opnd1, opnd2, false);
|
return (gmatchx(opnd1, opnd2, false));
|
||||||
return strcmp(opnd1, opnd2) == 0;
|
return (strcmp(opnd1, opnd2) == 0);
|
||||||
case TO_STNEQ: /* != */
|
case TO_STNEQ: /* != */
|
||||||
if (te->flags & TEF_DBRACKET)
|
if (te->flags & TEF_DBRACKET)
|
||||||
return !gmatchx(opnd1, opnd2, false);
|
return (!gmatchx(opnd1, opnd2, false));
|
||||||
return strcmp(opnd1, opnd2) != 0;
|
return (strcmp(opnd1, opnd2) != 0);
|
||||||
case TO_STLT: /* < */
|
case TO_STLT: /* < */
|
||||||
return strcmp(opnd1, opnd2) < 0;
|
return (strcmp(opnd1, opnd2) < 0);
|
||||||
case TO_STGT: /* > */
|
case TO_STGT: /* > */
|
||||||
return strcmp(opnd1, opnd2) > 0;
|
return (strcmp(opnd1, opnd2) > 0);
|
||||||
case TO_INTEQ: /* -eq */
|
case TO_INTEQ: /* -eq */
|
||||||
case TO_INTNE: /* -ne */
|
case TO_INTNE: /* -ne */
|
||||||
case TO_INTGE: /* -ge */
|
case TO_INTGE: /* -ge */
|
||||||
@ -2671,7 +2671,7 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
|||||||
!evaluate(opnd2, &v2, KSH_RETURN_ERROR, false)) {
|
!evaluate(opnd2, &v2, KSH_RETURN_ERROR, false)) {
|
||||||
/* error already printed.. */
|
/* error already printed.. */
|
||||||
te->flags |= TEF_ERROR;
|
te->flags |= TEF_ERROR;
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
switch ((int)op) {
|
switch ((int)op) {
|
||||||
case TO_INTEQ:
|
case TO_INTEQ:
|
||||||
@ -2691,22 +2691,22 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
|
|||||||
/* ksh88/ksh93 succeed if file2 can't be stated
|
/* ksh88/ksh93 succeed if file2 can't be stated
|
||||||
* (subtly different from 'does not exist').
|
* (subtly different from 'does not exist').
|
||||||
*/
|
*/
|
||||||
return stat(opnd1, &b1) == 0 &&
|
return (stat(opnd1, &b1) == 0 &&
|
||||||
(((s = stat(opnd2, &b2)) == 0 &&
|
(((s = stat(opnd2, &b2)) == 0 &&
|
||||||
b1.st_mtime > b2.st_mtime) || s < 0);
|
b1.st_mtime > b2.st_mtime) || s < 0));
|
||||||
case TO_FILOT: /* -ot */
|
case TO_FILOT: /* -ot */
|
||||||
/* ksh88/ksh93 succeed if file1 can't be stated
|
/* ksh88/ksh93 succeed if file1 can't be stated
|
||||||
* (subtly different from 'does not exist').
|
* (subtly different from 'does not exist').
|
||||||
*/
|
*/
|
||||||
return stat(opnd2, &b2) == 0 &&
|
return (stat(opnd2, &b2) == 0 &&
|
||||||
(((s = stat(opnd1, &b1)) == 0 &&
|
(((s = stat(opnd1, &b1)) == 0 &&
|
||||||
b1.st_mtime < b2.st_mtime) || s < 0);
|
b1.st_mtime < b2.st_mtime) || s < 0));
|
||||||
case TO_FILEQ: /* -ef */
|
case TO_FILEQ: /* -ef */
|
||||||
return stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0 &&
|
return (stat (opnd1, &b1) == 0 && stat (opnd2, &b2) == 0 &&
|
||||||
b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino;
|
b1.st_dev == b2.st_dev && b1.st_ino == b2.st_ino);
|
||||||
}
|
}
|
||||||
(*te->error)(te, 0, "internal error: unknown op");
|
(*te->error)(te, 0, "internal error: unknown op");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* On most/all unixen, access() says everything is executable for root... */
|
/* On most/all unixen, access() says everything is executable for root... */
|
||||||
@ -2726,7 +2726,7 @@ test_eaccess(const char *pathl, int mode)
|
|||||||
rv = (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) ?
|
rv = (statb.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) ?
|
||||||
0 : -1;
|
0 : -1;
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -2739,7 +2739,7 @@ test_parse(Test_env *te)
|
|||||||
if (!(te->flags & TEF_ERROR) && !(*te->isa)(te, TM_END))
|
if (!(te->flags & TEF_ERROR) && !(*te->isa)(te, TM_END))
|
||||||
(*te->error)(te, 0, "unexpected operator/operand");
|
(*te->error)(te, 0, "unexpected operator/operand");
|
||||||
|
|
||||||
return (te->flags & TEF_ERROR) ? T_ERR_EXIT : !rv;
|
return ((te->flags & TEF_ERROR) ? T_ERR_EXIT : !rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2750,8 +2750,8 @@ test_oexpr(Test_env *te, bool do_eval)
|
|||||||
if ((rv = test_aexpr(te, do_eval)))
|
if ((rv = test_aexpr(te, do_eval)))
|
||||||
do_eval = false;
|
do_eval = false;
|
||||||
if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_OR))
|
if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_OR))
|
||||||
return test_oexpr(te, do_eval) || rv;
|
return (test_oexpr(te, do_eval) || rv);
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2762,16 +2762,16 @@ test_aexpr(Test_env *te, bool do_eval)
|
|||||||
if (!(rv = test_nexpr(te, do_eval)))
|
if (!(rv = test_nexpr(te, do_eval)))
|
||||||
do_eval = false;
|
do_eval = false;
|
||||||
if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_AND))
|
if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_AND))
|
||||||
return test_aexpr(te, do_eval) && rv;
|
return (test_aexpr(te, do_eval) && rv);
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
test_nexpr(Test_env *te, bool do_eval)
|
test_nexpr(Test_env *te, bool do_eval)
|
||||||
{
|
{
|
||||||
if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_NOT))
|
if (!(te->flags & TEF_ERROR) && (*te->isa)(te, TM_NOT))
|
||||||
return !test_nexpr(te, do_eval);
|
return (!test_nexpr(te, do_eval));
|
||||||
return test_primary(te, do_eval);
|
return (test_primary(te, do_eval));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2782,16 +2782,16 @@ test_primary(Test_env *te, bool do_eval)
|
|||||||
Test_op op;
|
Test_op op;
|
||||||
|
|
||||||
if (te->flags & TEF_ERROR)
|
if (te->flags & TEF_ERROR)
|
||||||
return 0;
|
return (0);
|
||||||
if ((*te->isa)(te, TM_OPAREN)) {
|
if ((*te->isa)(te, TM_OPAREN)) {
|
||||||
rv = test_oexpr(te, do_eval);
|
rv = test_oexpr(te, do_eval);
|
||||||
if (te->flags & TEF_ERROR)
|
if (te->flags & TEF_ERROR)
|
||||||
return 0;
|
return (0);
|
||||||
if (!(*te->isa)(te, TM_CPAREN)) {
|
if (!(*te->isa)(te, TM_CPAREN)) {
|
||||||
(*te->error)(te, 0, "missing closing paren");
|
(*te->error)(te, 0, "missing closing paren");
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Binary should have precedence over unary in this case
|
* Binary should have precedence over unary in this case
|
||||||
@ -2804,28 +2804,28 @@ test_primary(Test_env *te, bool do_eval)
|
|||||||
opnd1 = (*te->getopnd)(te, op, do_eval);
|
opnd1 = (*te->getopnd)(te, op, do_eval);
|
||||||
if (!opnd1) {
|
if (!opnd1) {
|
||||||
(*te->error)(te, -1, "missing argument");
|
(*te->error)(te, -1, "missing argument");
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*te->eval)(te, op, opnd1, NULL, do_eval);
|
return ((*te->eval)(te, op, opnd1, NULL, do_eval));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
opnd1 = (*te->getopnd)(te, TO_NONOP, do_eval);
|
opnd1 = (*te->getopnd)(te, TO_NONOP, do_eval);
|
||||||
if (!opnd1) {
|
if (!opnd1) {
|
||||||
(*te->error)(te, 0, "expression expected");
|
(*te->error)(te, 0, "expression expected");
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
if ((op = (*te->isa)(te, TM_BINOP))) {
|
if ((op = (*te->isa)(te, TM_BINOP))) {
|
||||||
/* binary expression */
|
/* binary expression */
|
||||||
opnd2 = (*te->getopnd)(te, op, do_eval);
|
opnd2 = (*te->getopnd)(te, op, do_eval);
|
||||||
if (!opnd2) {
|
if (!opnd2) {
|
||||||
(*te->error)(te, -1, "missing second argument");
|
(*te->error)(te, -1, "missing second argument");
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (*te->eval)(te, op, opnd1, opnd2, do_eval);
|
return ((*te->eval)(te, op, opnd1, opnd2, do_eval));
|
||||||
}
|
}
|
||||||
return (*te->eval)(te, TO_STNZE, opnd1, NULL, do_eval);
|
return ((*te->eval)(te, TO_STNZE, opnd1, NULL, do_eval));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2846,7 +2846,7 @@ ptest_isa(Test_env *te, Test_meta meta)
|
|||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
if (te->pos.wp >= te->wp_end)
|
if (te->pos.wp >= te->wp_end)
|
||||||
return meta == TM_END;
|
return (meta == TM_END);
|
||||||
|
|
||||||
if (meta == TM_UNOP || meta == TM_BINOP)
|
if (meta == TM_UNOP || meta == TM_BINOP)
|
||||||
rv = test_isop(meta, *te->pos.wp);
|
rv = test_isop(meta, *te->pos.wp);
|
||||||
@ -2859,15 +2859,15 @@ ptest_isa(Test_env *te, Test_meta meta)
|
|||||||
if (rv)
|
if (rv)
|
||||||
te->pos.wp++;
|
te->pos.wp++;
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
ptest_getopnd(Test_env *te, Test_op op, bool do_eval __unused)
|
ptest_getopnd(Test_env *te, Test_op op, bool do_eval __unused)
|
||||||
{
|
{
|
||||||
if (te->pos.wp >= te->wp_end)
|
if (te->pos.wp >= te->wp_end)
|
||||||
return op == TO_FILTT ? "1" : NULL;
|
return (op == TO_FILTT ? "1" : NULL);
|
||||||
return *te->pos.wp++;
|
return (*te->pos.wp++);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
106
histrap.c
106
histrap.c
@ -26,7 +26,7 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.82 2009/05/27 09:58:22 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.83 2009/06/08 20:06:46 tg Exp $");
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* MirOS: This is the default mapping type, and need not be specified.
|
* MirOS: This is the default mapping type, and need not be specified.
|
||||||
@ -79,7 +79,7 @@ c_fc(const char **wp)
|
|||||||
|
|
||||||
if (!Flag(FTALKING_I)) {
|
if (!Flag(FTALKING_I)) {
|
||||||
bi_errorf("history functions not available");
|
bi_errorf("history functions not available");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((optc = ksh_getopt(wp, &builtin_opt,
|
while ((optc = ksh_getopt(wp, &builtin_opt,
|
||||||
@ -122,11 +122,11 @@ c_fc(const char **wp)
|
|||||||
last = p;
|
last = p;
|
||||||
else {
|
else {
|
||||||
bi_errorf("too many arguments");
|
bi_errorf("too many arguments");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
wp += builtin_opt.optind;
|
wp += builtin_opt.optind;
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ c_fc(const char **wp)
|
|||||||
|
|
||||||
if (editor || lflag || nflag || rflag) {
|
if (editor || lflag || nflag || rflag) {
|
||||||
bi_errorf("can't use -e, -l, -n, -r with -s (-e -)");
|
bi_errorf("can't use -e, -l, -n, -r with -s (-e -)");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for pattern replacement argument */
|
/* Check for pattern replacement argument */
|
||||||
@ -151,19 +151,19 @@ c_fc(const char **wp)
|
|||||||
wp++;
|
wp++;
|
||||||
if (last || *wp) {
|
if (last || *wp) {
|
||||||
bi_errorf("too many arguments");
|
bi_errorf("too many arguments");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
hp = first ? hist_get(first, false, false) :
|
hp = first ? hist_get(first, false, false) :
|
||||||
hist_get_newest(false);
|
hist_get_newest(false);
|
||||||
if (!hp)
|
if (!hp)
|
||||||
return 1;
|
return (1);
|
||||||
return hist_replace(hp, pat, rep, gflag);
|
return (hist_replace(hp, pat, rep, gflag));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editor && (lflag || nflag)) {
|
if (editor && (lflag || nflag)) {
|
||||||
bi_errorf("can't use -l, -n with -e");
|
bi_errorf("can't use -l, -n with -e");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!first && (first = *wp))
|
if (!first && (first = *wp))
|
||||||
@ -172,13 +172,13 @@ c_fc(const char **wp)
|
|||||||
wp++;
|
wp++;
|
||||||
if (*wp) {
|
if (*wp) {
|
||||||
bi_errorf("too many arguments");
|
bi_errorf("too many arguments");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (!first) {
|
if (!first) {
|
||||||
hfirst = lflag ? hist_get("-16", true, true) :
|
hfirst = lflag ? hist_get("-16", true, true) :
|
||||||
hist_get_newest(false);
|
hist_get_newest(false);
|
||||||
if (!hfirst)
|
if (!hfirst)
|
||||||
return 1;
|
return (1);
|
||||||
/* can't fail if hfirst didn't fail */
|
/* can't fail if hfirst didn't fail */
|
||||||
hlast = hist_get_newest(false);
|
hlast = hist_get_newest(false);
|
||||||
} else {
|
} else {
|
||||||
@ -189,11 +189,11 @@ c_fc(const char **wp)
|
|||||||
hfirst = hist_get(first, (lflag || last) ? true : false,
|
hfirst = hist_get(first, (lflag || last) ? true : false,
|
||||||
lflag ? true : false);
|
lflag ? true : false);
|
||||||
if (!hfirst)
|
if (!hfirst)
|
||||||
return 1;
|
return (1);
|
||||||
hlast = last ? hist_get(last, true, lflag ? true : false) :
|
hlast = last ? hist_get(last, true, lflag ? true : false) :
|
||||||
(lflag ? hist_get_newest(false) : hfirst);
|
(lflag ? hist_get_newest(false) : hfirst);
|
||||||
if (!hlast)
|
if (!hlast)
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (hfirst > hlast) {
|
if (hfirst > hlast) {
|
||||||
char **temp;
|
char **temp;
|
||||||
@ -223,7 +223,7 @@ c_fc(const char **wp)
|
|||||||
shf_fprintf(shl_stdout, "%s\n", s);
|
shf_fprintf(shl_stdout, "%s\n", s);
|
||||||
}
|
}
|
||||||
shf_flush(shl_stdout);
|
shf_flush(shl_stdout);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run editor on selected lines, then run resulting commands */
|
/* Run editor on selected lines, then run resulting commands */
|
||||||
@ -232,14 +232,14 @@ c_fc(const char **wp)
|
|||||||
if (!(shf = tf->shf)) {
|
if (!(shf = tf->shf)) {
|
||||||
bi_errorf("cannot create temp file %s - %s",
|
bi_errorf("cannot create temp file %s - %s",
|
||||||
tf->name, strerror(errno));
|
tf->name, strerror(errno));
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
for (hp = rflag ? hlast : hfirst;
|
for (hp = rflag ? hlast : hfirst;
|
||||||
hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1)
|
hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1)
|
||||||
shf_fprintf(shf, "%s\n", *hp);
|
shf_fprintf(shf, "%s\n", *hp);
|
||||||
if (shf_close(shf) == EOF) {
|
if (shf_close(shf) == EOF) {
|
||||||
bi_errorf("error writing temporary file - %s", strerror(errno));
|
bi_errorf("error writing temporary file - %s", strerror(errno));
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ignore setstr errors here (arbitrary) */
|
/* Ignore setstr errors here (arbitrary) */
|
||||||
@ -253,7 +253,7 @@ c_fc(const char **wp)
|
|||||||
ret = command(editor ? editor : "${FCEDIT:-/bin/ed} $_");
|
ret = command(editor ? editor : "${FCEDIT:-/bin/ed} $_");
|
||||||
source = sold;
|
source = sold;
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -264,7 +264,7 @@ c_fc(const char **wp)
|
|||||||
|
|
||||||
if (!(shf = shf_open(tf->name, O_RDONLY, 0, 0))) {
|
if (!(shf = shf_open(tf->name, O_RDONLY, 0, 0))) {
|
||||||
bi_errorf("cannot open temp file %s", tf->name);
|
bi_errorf("cannot open temp file %s", tf->name);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
n = stat(tf->name, &statb) < 0 ? 128 : statb.st_size + 1;
|
n = stat(tf->name, &statb) < 0 ? 128 : statb.st_size + 1;
|
||||||
@ -278,12 +278,12 @@ c_fc(const char **wp)
|
|||||||
bi_errorf("error reading temp file %s - %s",
|
bi_errorf("error reading temp file %s - %s",
|
||||||
tf->name, strerror(shf_errno(shf)));
|
tf->name, strerror(shf_errno(shf)));
|
||||||
shf_close(shf);
|
shf_close(shf);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
shf_close(shf);
|
shf_close(shf);
|
||||||
*xp = '\0';
|
*xp = '\0';
|
||||||
strip_nuls(Xstring(xs, xp), Xlength(xs, xp));
|
strip_nuls(Xstring(xs, xp), Xlength(xs, xp));
|
||||||
return hist_execute(Xstring(xs, xp));
|
return (hist_execute(Xstring(xs, xp)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ hist_execute(char *cmd)
|
|||||||
sold = source;
|
sold = source;
|
||||||
ret = command(cmd);
|
ret = command(cmd);
|
||||||
source = sold;
|
source = sold;
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -352,7 +352,7 @@ hist_replace(char **hp, const char *pat, const char *rep, int globr)
|
|||||||
}
|
}
|
||||||
if (!any_subst) {
|
if (!any_subst) {
|
||||||
bi_errorf("substitution failed");
|
bi_errorf("substitution failed");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
len = strlen(s) + 1;
|
len = strlen(s) + 1;
|
||||||
XcheckN(xs, xp, len);
|
XcheckN(xs, xp, len);
|
||||||
@ -360,7 +360,7 @@ hist_replace(char **hp, const char *pat, const char *rep, int globr)
|
|||||||
xp += len;
|
xp += len;
|
||||||
line = Xclose(xs, xp);
|
line = Xclose(xs, xp);
|
||||||
}
|
}
|
||||||
return hist_execute(line);
|
return (hist_execute(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -402,7 +402,7 @@ hist_get(const char *str, int approx, int allow_cur)
|
|||||||
else
|
else
|
||||||
hp = &history[n];
|
hp = &history[n];
|
||||||
}
|
}
|
||||||
return hp;
|
return (hp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return a pointer to the newest command in the history */
|
/* Return a pointer to the newest command in the history */
|
||||||
@ -411,7 +411,7 @@ hist_get_newest(int allow_cur)
|
|||||||
{
|
{
|
||||||
if (histptr < history || (!allow_cur && histptr == history)) {
|
if (histptr < history || (!allow_cur && histptr == history)) {
|
||||||
bi_errorf("no history (yet)");
|
bi_errorf("no history (yet)");
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
return (allow_cur ? histptr : histptr - 1);
|
return (allow_cur ? histptr : histptr - 1);
|
||||||
}
|
}
|
||||||
@ -422,9 +422,9 @@ hist_get_oldest(void)
|
|||||||
{
|
{
|
||||||
if (histptr <= history) {
|
if (histptr <= history) {
|
||||||
bi_errorf("no history (yet)");
|
bi_errorf("no history (yet)");
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
return history;
|
return (history);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************/
|
/******************************/
|
||||||
@ -449,7 +449,7 @@ histbackup(void)
|
|||||||
char **
|
char **
|
||||||
histpos(void)
|
histpos(void)
|
||||||
{
|
{
|
||||||
return current;
|
return (current);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -459,10 +459,10 @@ histnum(int n)
|
|||||||
|
|
||||||
if (n < 0 || n >= last) {
|
if (n < 0 || n >= last) {
|
||||||
current = histptr;
|
current = histptr;
|
||||||
return last;
|
return (last);
|
||||||
} else {
|
} else {
|
||||||
current = &history[n];
|
current = &history[n];
|
||||||
return n;
|
return (n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,9 +486,9 @@ findhist(int start, int fwd, const char *str, int anchored)
|
|||||||
for (; hp >= history && hp <= histptr; hp += incr)
|
for (; hp >= history && hp <= histptr; hp += incr)
|
||||||
if ((anchored && strncmp(*hp, str, len) == 0) ||
|
if ((anchored && strncmp(*hp, str, len) == 0) ||
|
||||||
(!anchored && strstr(*hp, str)))
|
(!anchored && strstr(*hp, str)))
|
||||||
return hp - history;
|
return (hp - history);
|
||||||
|
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -500,15 +500,15 @@ findhistrel(const char *str)
|
|||||||
|
|
||||||
getn(str, &rec);
|
getn(str, &rec);
|
||||||
if (rec == 0)
|
if (rec == 0)
|
||||||
return -1;
|
return (-1);
|
||||||
if (rec > 0) {
|
if (rec > 0) {
|
||||||
if (rec > maxhist)
|
if (rec > maxhist)
|
||||||
return -1;
|
return (-1);
|
||||||
return rec - 1;
|
return (rec - 1);
|
||||||
}
|
}
|
||||||
if (rec > maxhist)
|
if (rec > maxhist)
|
||||||
return -1;
|
return (-1);
|
||||||
return start + rec + 1;
|
return (start + rec + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -527,7 +527,7 @@ sethistsize(int n)
|
|||||||
cursize = n;
|
cursize = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
history = aresize(history, n * sizeof (char *), APERM);
|
history = aresize(history, n * sizeof(char *), APERM);
|
||||||
|
|
||||||
histsize = n;
|
histsize = n;
|
||||||
histptr = history + cursize;
|
histptr = history + cursize;
|
||||||
@ -578,7 +578,7 @@ init_histvec(void)
|
|||||||
{
|
{
|
||||||
if (history == (char **)NULL) {
|
if (history == (char **)NULL) {
|
||||||
histsize = HISTORYSIZE;
|
histsize = HISTORYSIZE;
|
||||||
history = alloc(histsize * sizeof (char *), APERM);
|
history = alloc(histsize * sizeof(char *), APERM);
|
||||||
histptr = history - 1;
|
histptr = history - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -772,7 +772,7 @@ hist_count_lines(unsigned char *base, int bytes)
|
|||||||
}
|
}
|
||||||
base++;
|
base++;
|
||||||
}
|
}
|
||||||
return lines;
|
return (lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -789,9 +789,9 @@ hist_shrink(unsigned char *oldbase, int oldbytes)
|
|||||||
|
|
||||||
nbase = hist_skip_back(nbase, &nbytes, histsize);
|
nbase = hist_skip_back(nbase, &nbytes, histsize);
|
||||||
if (nbase == NULL)
|
if (nbase == NULL)
|
||||||
return 1;
|
return (1);
|
||||||
if (nbase == oldbase)
|
if (nbase == oldbase)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* create temp file
|
* create temp file
|
||||||
@ -845,10 +845,10 @@ hist_skip_back(unsigned char *base, int *bytes, int no)
|
|||||||
break;
|
break;
|
||||||
if (++lines == no) {
|
if (++lines == no) {
|
||||||
*bytes = *bytes - ((char *)ep - (char *)base);
|
*bytes = *bytes - ((char *)ep - (char *)base);
|
||||||
return ep;
|
return (ep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -999,7 +999,7 @@ sprinkle(int fd)
|
|||||||
{
|
{
|
||||||
static const unsigned char mag[] = { HMAGIC1, HMAGIC2 };
|
static const unsigned char mag[] = { HMAGIC1, HMAGIC2 };
|
||||||
|
|
||||||
return(write(fd, mag, 2) != 2);
|
return (write(fd, mag, 2) != 2);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1174,8 +1174,8 @@ fatal_trap_check(void)
|
|||||||
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
|
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
|
||||||
if (p->set && (p->flags & (TF_DFL_INTR|TF_FATAL)))
|
if (p->set && (p->flags & (TF_DFL_INTR|TF_FATAL)))
|
||||||
/* return value is used as an exit code */
|
/* return value is used as an exit code */
|
||||||
return 128 + p->signal;
|
return (128 + p->signal);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the signal number of any pending traps: ie, a signal which has
|
/* Returns the signal number of any pending traps: ie, a signal which has
|
||||||
@ -1191,8 +1191,8 @@ trap_pending(void)
|
|||||||
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
|
for (p = sigtraps, i = NSIG+1; --i >= 0; p++)
|
||||||
if (p->set && ((p->trap && p->trap[0]) ||
|
if (p->set && ((p->trap && p->trap[0]) ||
|
||||||
((p->flags & (TF_DFL_INTR|TF_FATAL)) && !p->trap)))
|
((p->flags & (TF_DFL_INTR|TF_FATAL)) && !p->trap)))
|
||||||
return p->signal;
|
return (p->signal);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1352,7 +1352,7 @@ block_pipe(void)
|
|||||||
setsig(p, SIG_IGN, SS_RESTORE_CURR);
|
setsig(p, SIG_IGN, SS_RESTORE_CURR);
|
||||||
restore_dfl = 1; /* restore to SIG_DFL */
|
restore_dfl = 1; /* restore to SIG_DFL */
|
||||||
}
|
}
|
||||||
return restore_dfl;
|
return (restore_dfl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called by c_print() to undo whatever block_pipe() did */
|
/* Called by c_print() to undo whatever block_pipe() did */
|
||||||
@ -1372,7 +1372,7 @@ setsig(Trap *p, sig_t f, int flags)
|
|||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
|
|
||||||
if (p->signal == SIGEXIT_ || p->signal == SIGERR_)
|
if (p->signal == SIGEXIT_ || p->signal == SIGERR_)
|
||||||
return 1;
|
return (1);
|
||||||
|
|
||||||
/* First time setting this signal? If so, get and note the current
|
/* First time setting this signal? If so, get and note the current
|
||||||
* setting.
|
* setting.
|
||||||
@ -1390,7 +1390,7 @@ setsig(Trap *p, sig_t f, int flags)
|
|||||||
*/
|
*/
|
||||||
if ((p->flags & TF_ORIG_IGN) && !(flags & SS_FORCE) &&
|
if ((p->flags & TF_ORIG_IGN) && !(flags & SS_FORCE) &&
|
||||||
(!(flags & SS_USER) || !Flag(FTALKING)))
|
(!(flags & SS_USER) || !Flag(FTALKING)))
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
setexecsig(p, flags & SS_RESTORE_MASK);
|
setexecsig(p, flags & SS_RESTORE_MASK);
|
||||||
|
|
||||||
@ -1413,7 +1413,7 @@ setsig(Trap *p, sig_t f, int flags)
|
|||||||
sigaction(p->signal, &sigact, NULL);
|
sigaction(p->signal, &sigact, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* control what signal is set to before an exec() */
|
/* control what signal is set to before an exec() */
|
||||||
|
90
jobs.c
90
jobs.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.53 2009/05/16 16:59:36 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.54 2009/06/08 20:06:47 tg Exp $");
|
||||||
|
|
||||||
/* Order important! */
|
/* Order important! */
|
||||||
#define PRUNNING 0
|
#define PRUNNING 0
|
||||||
@ -346,7 +346,7 @@ exchild(struct op *t, int flags,
|
|||||||
/* Clear XFORK|XPCLOSE|XCCLOSE|XCOPROC|XPIPEO|XPIPEI|XXCOM|XBGND
|
/* Clear XFORK|XPCLOSE|XCCLOSE|XCOPROC|XPIPEO|XPIPEI|XXCOM|XBGND
|
||||||
* (also done in another execute() below)
|
* (also done in another execute() below)
|
||||||
*/
|
*/
|
||||||
return execute(t, flags & (XEXEC | XERROK), xerrok);
|
return (execute(t, flags & (XEXEC | XERROK), xerrok));
|
||||||
|
|
||||||
/* no SIGCHLDs while messing with job and process lists */
|
/* no SIGCHLDs while messing with job and process lists */
|
||||||
sigprocmask(SIG_BLOCK, &sm_sigchld, &omask);
|
sigprocmask(SIG_BLOCK, &sm_sigchld, &omask);
|
||||||
@ -514,7 +514,7 @@ exchild(struct op *t, int flags,
|
|||||||
|
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* start the last job: only used for $(command) jobs */
|
/* start the last job: only used for $(command) jobs */
|
||||||
@ -550,14 +550,14 @@ waitlast(void)
|
|||||||
else
|
else
|
||||||
internal_warningf("waitlast: not started");
|
internal_warningf("waitlast: not started");
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
return 125; /* not so arbitrary, non-zero value */
|
return (125); /* not so arbitrary, non-zero value */
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = j_waitj(j, JW_NONE, "jw:waitlast");
|
rv = j_waitj(j, JW_NONE, "jw:waitlast");
|
||||||
|
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait for child, interruptable. */
|
/* wait for child, interruptable. */
|
||||||
@ -584,20 +584,20 @@ waitfor(const char *cp, int *sigp)
|
|||||||
break;
|
break;
|
||||||
if (!j) {
|
if (!j) {
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
} else if ((j = j_lookup(cp, &ecode))) {
|
} else if ((j = j_lookup(cp, &ecode))) {
|
||||||
/* don't report normal job completion */
|
/* don't report normal job completion */
|
||||||
flags &= ~JW_ASYNCNOTIFY;
|
flags &= ~JW_ASYNCNOTIFY;
|
||||||
if (j->ppid != procpid) {
|
if (j->ppid != procpid) {
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
if (ecode != JL_NOSUCH)
|
if (ecode != JL_NOSUCH)
|
||||||
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* at&t ksh will wait for stopped jobs - we don't */
|
/* at&t ksh will wait for stopped jobs - we don't */
|
||||||
@ -608,7 +608,7 @@ waitfor(const char *cp, int *sigp)
|
|||||||
if (rv < 0) /* we were interrupted */
|
if (rv < 0) /* we were interrupted */
|
||||||
*sigp = 128 + -rv;
|
*sigp = 128 + -rv;
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* kill (built-in) a job */
|
/* kill (built-in) a job */
|
||||||
@ -625,7 +625,7 @@ j_kill(const char *cp, int sig)
|
|||||||
if ((j = j_lookup(cp, &ecode)) == NULL) {
|
if ((j = j_lookup(cp, &ecode)) == NULL) {
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j->pgrp == 0) { /* started when !Flag(FMONITOR) */
|
if (j->pgrp == 0) { /* started when !Flag(FMONITOR) */
|
||||||
@ -646,7 +646,7 @@ j_kill(const char *cp, int sig)
|
|||||||
|
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MKSH_UNEMPLOYED
|
#ifndef MKSH_UNEMPLOYED
|
||||||
@ -666,13 +666,13 @@ j_resume(const char *cp, int bg)
|
|||||||
if ((j = j_lookup(cp, &ecode)) == NULL) {
|
if ((j = j_lookup(cp, &ecode)) == NULL) {
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j->pgrp == 0) {
|
if (j->pgrp == 0) {
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
bi_errorf("job not job-controlled");
|
bi_errorf("job not job-controlled");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bg)
|
if (bg)
|
||||||
@ -716,7 +716,7 @@ j_resume(const char *cp, int bg)
|
|||||||
(int) ((j->flags & JF_SAVEDTTYPGRP) ?
|
(int) ((j->flags & JF_SAVEDTTYPGRP) ?
|
||||||
j->saved_ttypgrp : j->pgrp),
|
j->saved_ttypgrp : j->pgrp),
|
||||||
strerror(rv));
|
strerror(rv));
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j->flags |= JF_FG;
|
j->flags |= JF_FG;
|
||||||
@ -740,7 +740,7 @@ j_resume(const char *cp, int bg)
|
|||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
bi_errorf("cannot continue job %s: %s",
|
bi_errorf("cannot continue job %s: %s",
|
||||||
cp, strerror(err));
|
cp, strerror(err));
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (!bg) {
|
if (!bg) {
|
||||||
if (ttypgrp_ok) {
|
if (ttypgrp_ok) {
|
||||||
@ -749,7 +749,7 @@ j_resume(const char *cp, int bg)
|
|||||||
rv = j_waitj(j, JW_NONE, "jw:resume");
|
rv = j_waitj(j, JW_NONE, "jw:resume");
|
||||||
}
|
}
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -774,10 +774,10 @@ j_stopped_running(void)
|
|||||||
which & 1 ? "stopped" : "",
|
which & 1 ? "stopped" : "",
|
||||||
which == 3 ? " and " : "",
|
which == 3 ? " and " : "",
|
||||||
which & 2 ? "running" : "");
|
which & 2 ? "running" : "");
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -792,7 +792,7 @@ j_njobs(void)
|
|||||||
nj++;
|
nj++;
|
||||||
|
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
return nj;
|
return (nj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -818,7 +818,7 @@ j_jobs(const char *cp, int slp,
|
|||||||
if ((j = j_lookup(cp, &ecode)) == NULL) {
|
if ((j = j_lookup(cp, &ecode)) == NULL) {
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
j = job_list;
|
j = job_list;
|
||||||
@ -840,7 +840,7 @@ j_jobs(const char *cp, int slp,
|
|||||||
remove_job(j, "jobs");
|
remove_job(j, "jobs");
|
||||||
}
|
}
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* list jobs for top-level notification */
|
/* list jobs for top-level notification */
|
||||||
@ -884,7 +884,7 @@ j_async(void)
|
|||||||
|
|
||||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
|
|
||||||
return async_pid;
|
return (async_pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make j the last async process
|
/* Make j the last async process
|
||||||
@ -977,7 +977,7 @@ j_waitj(Job *j,
|
|||||||
}
|
}
|
||||||
if ((flags & JW_INTERRUPT) && (rv = trap_pending())) {
|
if ((flags & JW_INTERRUPT) && (rv = trap_pending())) {
|
||||||
j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY);
|
j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY);
|
||||||
return -rv;
|
return (-rv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY);
|
j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY);
|
||||||
@ -1070,7 +1070,7 @@ j_waitj(Job *j,
|
|||||||
(!Flag(FMONITOR) || !(flags & JW_ASYNCNOTIFY)))
|
(!Flag(FMONITOR) || !(flags & JW_ASYNCNOTIFY)))
|
||||||
remove_job(j, where);
|
remove_job(j, where);
|
||||||
|
|
||||||
return rv;
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* SIGCHLD handler to reap children and update job states
|
/* SIGCHLD handler to reap children and update job states
|
||||||
@ -1290,17 +1290,17 @@ j_print(Job *j, int how, struct shf *shf)
|
|||||||
coredumped = 0;
|
coredumped = 0;
|
||||||
switch (p->state) {
|
switch (p->state) {
|
||||||
case PRUNNING:
|
case PRUNNING:
|
||||||
strlcpy(buf, "Running", sizeof buf);
|
strlcpy(buf, "Running", sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case PSTOPPED:
|
case PSTOPPED:
|
||||||
strlcpy(buf, sigtraps[WSTOPSIG(p->status)].mess,
|
strlcpy(buf, sigtraps[WSTOPSIG(p->status)].mess,
|
||||||
sizeof buf);
|
sizeof(buf));
|
||||||
break;
|
break;
|
||||||
case PEXITED:
|
case PEXITED:
|
||||||
if (how == JP_SHORT)
|
if (how == JP_SHORT)
|
||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
else if (WEXITSTATUS(p->status) == 0)
|
else if (WEXITSTATUS(p->status) == 0)
|
||||||
strlcpy(buf, "Done", sizeof buf);
|
strlcpy(buf, "Done", sizeof(buf));
|
||||||
else
|
else
|
||||||
shf_snprintf(buf, sizeof(buf), "Done (%d)",
|
shf_snprintf(buf, sizeof(buf), "Done (%d)",
|
||||||
WEXITSTATUS(p->status));
|
WEXITSTATUS(p->status));
|
||||||
@ -1319,7 +1319,7 @@ j_print(Job *j, int how, struct shf *shf)
|
|||||||
buf[0] = '\0';
|
buf[0] = '\0';
|
||||||
} else
|
} else
|
||||||
strlcpy(buf, sigtraps[WTERMSIG(p->status)].mess,
|
strlcpy(buf, sigtraps[WTERMSIG(p->status)].mess,
|
||||||
sizeof buf);
|
sizeof(buf));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1380,32 +1380,32 @@ j_lookup(const char *cp, int *ecodep)
|
|||||||
/* Look for last_proc->pid (what $! returns) first... */
|
/* Look for last_proc->pid (what $! returns) first... */
|
||||||
for (j = job_list; j != NULL; j = j->next)
|
for (j = job_list; j != NULL; j = j->next)
|
||||||
if (j->last_proc && j->last_proc->pid == job)
|
if (j->last_proc && j->last_proc->pid == job)
|
||||||
return j;
|
return (j);
|
||||||
/* ...then look for process group (this is non-POSIX,
|
/* ...then look for process group (this is non-POSIX,
|
||||||
* but should not break anything */
|
* but should not break anything */
|
||||||
for (j = job_list; j != NULL; j = j->next)
|
for (j = job_list; j != NULL; j = j->next)
|
||||||
if (j->pgrp && j->pgrp == job)
|
if (j->pgrp && j->pgrp == job)
|
||||||
return j;
|
return (j);
|
||||||
if (ecodep)
|
if (ecodep)
|
||||||
*ecodep = JL_NOSUCH;
|
*ecodep = JL_NOSUCH;
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
if (*cp != '%') {
|
if (*cp != '%') {
|
||||||
if (ecodep)
|
if (ecodep)
|
||||||
*ecodep = JL_INVALID;
|
*ecodep = JL_INVALID;
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
switch (*++cp) {
|
switch (*++cp) {
|
||||||
case '\0': /* non-standard */
|
case '\0': /* non-standard */
|
||||||
case '+':
|
case '+':
|
||||||
case '%':
|
case '%':
|
||||||
if (job_list != NULL)
|
if (job_list != NULL)
|
||||||
return job_list;
|
return (job_list);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
if (job_list != NULL && job_list->next)
|
if (job_list != NULL && job_list->next)
|
||||||
return job_list->next;
|
return (job_list->next);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
@ -1413,7 +1413,7 @@ j_lookup(const char *cp, int *ecodep)
|
|||||||
getn(cp, &job);
|
getn(cp, &job);
|
||||||
for (j = job_list; j != NULL; j = j->next)
|
for (j = job_list; j != NULL; j = j->next)
|
||||||
if (j->job == job)
|
if (j->job == job)
|
||||||
return j;
|
return (j);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?': /* %?string */
|
case '?': /* %?string */
|
||||||
@ -1424,12 +1424,12 @@ j_lookup(const char *cp, int *ecodep)
|
|||||||
if (last_match) {
|
if (last_match) {
|
||||||
if (ecodep)
|
if (ecodep)
|
||||||
*ecodep = JL_AMBIG;
|
*ecodep = JL_AMBIG;
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
last_match = j;
|
last_match = j;
|
||||||
}
|
}
|
||||||
if (last_match)
|
if (last_match)
|
||||||
return last_match;
|
return (last_match);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: /* %string */
|
default: /* %string */
|
||||||
@ -1440,17 +1440,17 @@ j_lookup(const char *cp, int *ecodep)
|
|||||||
if (last_match) {
|
if (last_match) {
|
||||||
if (ecodep)
|
if (ecodep)
|
||||||
*ecodep = JL_AMBIG;
|
*ecodep = JL_AMBIG;
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
last_match = j;
|
last_match = j;
|
||||||
}
|
}
|
||||||
if (last_match)
|
if (last_match)
|
||||||
return last_match;
|
return (last_match);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ecodep)
|
if (ecodep)
|
||||||
*ecodep = JL_NOSUCH;
|
*ecodep = JL_NOSUCH;
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Job *free_jobs;
|
static Job *free_jobs;
|
||||||
@ -1470,7 +1470,7 @@ new_job(void)
|
|||||||
newj = free_jobs;
|
newj = free_jobs;
|
||||||
free_jobs = free_jobs->next;
|
free_jobs = free_jobs->next;
|
||||||
} else
|
} else
|
||||||
newj = alloc(sizeof (Job), APERM);
|
newj = alloc(sizeof(Job), APERM);
|
||||||
|
|
||||||
/* brute force method */
|
/* brute force method */
|
||||||
for (i = 1; ; i++) {
|
for (i = 1; ; i++) {
|
||||||
@ -1481,7 +1481,7 @@ new_job(void)
|
|||||||
}
|
}
|
||||||
newj->job = i;
|
newj->job = i;
|
||||||
|
|
||||||
return newj;
|
return (newj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate new process struct
|
/* Allocate new process struct
|
||||||
@ -1497,9 +1497,9 @@ new_proc(void)
|
|||||||
p = free_procs;
|
p = free_procs;
|
||||||
free_procs = free_procs->next;
|
free_procs = free_procs->next;
|
||||||
} else
|
} else
|
||||||
p = alloc(sizeof (Proc), APERM);
|
p = alloc(sizeof(Proc), APERM);
|
||||||
|
|
||||||
return p;
|
return (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Take job out of job_list and put old structures into free list.
|
/* Take job out of job_list and put old structures into free list.
|
||||||
@ -1592,5 +1592,5 @@ kill_job(Job *j, int sig)
|
|||||||
if (p->pid != 0)
|
if (p->pid != 0)
|
||||||
if (kill(p->pid, sig) < 0)
|
if (kill(p->pid, sig) < 0)
|
||||||
rval = -1;
|
rval = -1;
|
||||||
return rval;
|
return (rval);
|
||||||
}
|
}
|
||||||
|
44
lex.c
44
lex.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.85 2009/05/27 19:52:36 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.86 2009/06/08 20:06:47 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* states while lexing word
|
* states while lexing word
|
||||||
@ -791,7 +791,7 @@ yylex(int cf)
|
|||||||
|
|
||||||
dp = Xstring(ws, wp);
|
dp = Xstring(ws, wp);
|
||||||
if ((c == '<' || c == '>' || c == '&') && state == SBASE) {
|
if ((c == '<' || c == '>' || c == '&') && state == SBASE) {
|
||||||
struct ioword *iop = alloc(sizeof (struct ioword), ATEMP);
|
struct ioword *iop = alloc(sizeof(struct ioword), ATEMP);
|
||||||
|
|
||||||
if (Xlength(ws, wp) == 0)
|
if (Xlength(ws, wp) == 0)
|
||||||
iop->unit = c == '<' ? 0 : 1;
|
iop->unit = c == '<' ? 0 : 1;
|
||||||
@ -842,7 +842,7 @@ yylex(int cf)
|
|||||||
iop->heredoc = NULL;
|
iop->heredoc = NULL;
|
||||||
Xfree(ws, wp); /* free word */
|
Xfree(ws, wp); /* free word */
|
||||||
yylval.iop = iop;
|
yylval.iop = iop;
|
||||||
return REDIR;
|
return (REDIR);
|
||||||
no_iop:
|
no_iop:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
@ -879,7 +879,7 @@ yylex(int cf)
|
|||||||
yylval.cp = Xclose(ws, wp);
|
yylval.cp = Xclose(ws, wp);
|
||||||
if (state == SWORD || state == SLETPAREN ||
|
if (state == SWORD || state == SLETPAREN ||
|
||||||
state == SLETARRAY) /* ONEWORD? */
|
state == SLETARRAY) /* ONEWORD? */
|
||||||
return LWORD;
|
return (LWORD);
|
||||||
|
|
||||||
last_terminal_was_bracket = c == '(';
|
last_terminal_was_bracket = c == '(';
|
||||||
ungetsc(c); /* unget terminator */
|
ungetsc(c); /* unget terminator */
|
||||||
@ -910,7 +910,7 @@ yylex(int cf)
|
|||||||
if ((cf & KEYWORD) && (p = ktsearch(&keywords, ident, h)) &&
|
if ((cf & KEYWORD) && (p = ktsearch(&keywords, ident, h)) &&
|
||||||
(!(cf & ESACONLY) || p->val.i == ESAC || p->val.i == '}')) {
|
(!(cf & ESACONLY) || p->val.i == ESAC || p->val.i == '}')) {
|
||||||
afree(yylval.cp, ATEMP);
|
afree(yylval.cp, ATEMP);
|
||||||
return p->val.i;
|
return (p->val.i);
|
||||||
}
|
}
|
||||||
if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
|
if ((cf & ALIAS) && (p = ktsearch(&aliases, ident, h)) &&
|
||||||
(p->flag & ISSET)) {
|
(p->flag & ISSET)) {
|
||||||
@ -922,7 +922,7 @@ yylex(int cf)
|
|||||||
|
|
||||||
while (s->flags & SF_HASALIAS)
|
while (s->flags & SF_HASALIAS)
|
||||||
if (s->u.tblp == p)
|
if (s->u.tblp == p)
|
||||||
return LWORD;
|
return (LWORD);
|
||||||
else
|
else
|
||||||
s = s->next;
|
s = s->next;
|
||||||
/* push alias expansion */
|
/* push alias expansion */
|
||||||
@ -943,7 +943,7 @@ yylex(int cf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return LWORD;
|
return (LWORD);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1057,7 +1057,7 @@ pushs(int type, Area *areap)
|
|||||||
{
|
{
|
||||||
Source *s;
|
Source *s;
|
||||||
|
|
||||||
s = alloc(sizeof (Source), areap);
|
s = alloc(sizeof(Source), areap);
|
||||||
s->type = type;
|
s->type = type;
|
||||||
s->str = null;
|
s->str = null;
|
||||||
s->start = NULL;
|
s->start = NULL;
|
||||||
@ -1071,7 +1071,7 @@ pushs(int type, Area *areap)
|
|||||||
XinitN(s->xs, 256, s->areap);
|
XinitN(s->xs, 256, s->areap);
|
||||||
else
|
else
|
||||||
memset(&s->xs, 0, sizeof(s->xs));
|
memset(&s->xs, 0, sizeof(s->xs));
|
||||||
return s;
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -1086,7 +1086,7 @@ getsc__(void)
|
|||||||
switch (s->type) {
|
switch (s->type) {
|
||||||
case SEOF:
|
case SEOF:
|
||||||
s->str = null;
|
s->str = null;
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
case SSTDIN:
|
case SSTDIN:
|
||||||
case SFILE:
|
case SFILE:
|
||||||
@ -1165,7 +1165,7 @@ getsc__(void)
|
|||||||
if (s->str == NULL) {
|
if (s->str == NULL) {
|
||||||
s->type = SEOF;
|
s->type = SEOF;
|
||||||
s->start = s->str = null;
|
s->start = s->str = null;
|
||||||
return '\0';
|
return ('\0');
|
||||||
}
|
}
|
||||||
if (s->flags & SF_ECHO) {
|
if (s->flags & SF_ECHO) {
|
||||||
shf_puts(s->str, shl_out);
|
shf_puts(s->str, shl_out);
|
||||||
@ -1183,7 +1183,7 @@ getsc__(void)
|
|||||||
goto getsc_again;
|
goto getsc_again;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c;
|
return (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1467,7 +1467,7 @@ get_brace_var(XString *wsp, char *wp)
|
|||||||
Xcheck(*wsp, wp);
|
Xcheck(*wsp, wp);
|
||||||
*wp++ = c;
|
*wp++ = c;
|
||||||
}
|
}
|
||||||
return wp;
|
return (wp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1498,7 +1498,7 @@ arraysub(char **strp)
|
|||||||
*wp++ = '\0';
|
*wp++ = '\0';
|
||||||
*strp = Xclose(ws, wp);
|
*strp = Xclose(ws, wp);
|
||||||
|
|
||||||
return depth == 0 ? 1 : 0;
|
return (depth == 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unget a char: handles case when we are already at the start of the buffer */
|
/* Unget a char: handles case when we are already at the start of the buffer */
|
||||||
@ -1509,7 +1509,7 @@ ungetsc(int c)
|
|||||||
backslash_skip--;
|
backslash_skip--;
|
||||||
/* Don't unget eof... */
|
/* Don't unget eof... */
|
||||||
if (source->str == null && c == '\0')
|
if (source->str == null && c == '\0')
|
||||||
return source->str;
|
return (source->str);
|
||||||
if (source->str > source->start)
|
if (source->str > source->start)
|
||||||
source->str--;
|
source->str--;
|
||||||
else {
|
else {
|
||||||
@ -1521,7 +1521,7 @@ ungetsc(int c)
|
|||||||
s->next = source;
|
s->next = source;
|
||||||
source = s;
|
source = s;
|
||||||
}
|
}
|
||||||
return source->str;
|
return (source->str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1532,11 +1532,11 @@ getsc_bn(void)
|
|||||||
int c, c2;
|
int c, c2;
|
||||||
|
|
||||||
if (ignore_backslash_newline)
|
if (ignore_backslash_newline)
|
||||||
return getsc_();
|
return (getsc_());
|
||||||
|
|
||||||
if (backslash_skip == 1) {
|
if (backslash_skip == 1) {
|
||||||
backslash_skip = 2;
|
backslash_skip = 2;
|
||||||
return getsc_();
|
return (getsc_());
|
||||||
}
|
}
|
||||||
|
|
||||||
backslash_skip = 0;
|
backslash_skip = 0;
|
||||||
@ -1550,19 +1550,19 @@ getsc_bn(void)
|
|||||||
ungetsc(c2);
|
ungetsc(c2);
|
||||||
backslash_skip = 1;
|
backslash_skip = 1;
|
||||||
}
|
}
|
||||||
return c;
|
return (c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Lex_state *
|
static Lex_state *
|
||||||
push_state_(State_info *si, Lex_state *old_end)
|
push_state_(State_info *si, Lex_state *old_end)
|
||||||
{
|
{
|
||||||
Lex_state *new = alloc(STATE_BSIZE * sizeof (Lex_state), ATEMP);
|
Lex_state *new = alloc(STATE_BSIZE * sizeof(Lex_state), ATEMP);
|
||||||
|
|
||||||
new[0].ls_info.base = old_end;
|
new[0].ls_info.base = old_end;
|
||||||
si->base = &new[0];
|
si->base = &new[0];
|
||||||
si->end = &new[STATE_BSIZE];
|
si->end = &new[STATE_BSIZE];
|
||||||
return &new[1];
|
return (&new[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Lex_state *
|
static Lex_state *
|
||||||
@ -1575,5 +1575,5 @@ pop_state_(State_info *si, Lex_state *old_end)
|
|||||||
|
|
||||||
afree(old_base, ATEMP);
|
afree(old_base, ATEMP);
|
||||||
|
|
||||||
return si->base + STATE_BSIZE - 1;
|
return (si->base + STATE_BSIZE - 1);
|
||||||
}
|
}
|
||||||
|
56
main.c
56
main.c
@ -33,7 +33,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.130 2009/06/07 22:28:04 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.131 2009/06/08 20:06:47 tg Exp $");
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ main(int argc, const char *argv[])
|
|||||||
Flag(FTRACKALL) = 1; /* set after ENV */
|
Flag(FTRACKALL) = 1; /* set after ENV */
|
||||||
|
|
||||||
shell(s, true); /* doesn't return */
|
shell(s, true); /* doesn't return */
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -437,7 +437,7 @@ include(const char *name, int argc, const char **argv, int intr_ok)
|
|||||||
|
|
||||||
shf = shf_open(name, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
|
shf = shf_open(name, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
|
||||||
if (shf == NULL)
|
if (shf == NULL)
|
||||||
return -1;
|
return (-1);
|
||||||
|
|
||||||
if (argv) {
|
if (argv) {
|
||||||
old_argv = e->loc->argv;
|
old_argv = e->loc->argv;
|
||||||
@ -457,13 +457,13 @@ include(const char *name, int argc, const char **argv, int intr_ok)
|
|||||||
switch (i) {
|
switch (i) {
|
||||||
case LRETURN:
|
case LRETURN:
|
||||||
case LERROR:
|
case LERROR:
|
||||||
return exstat & 0xff; /* see below */
|
return (exstat & 0xff); /* see below */
|
||||||
case LINTR:
|
case LINTR:
|
||||||
/* intr_ok is set if we are including .profile or $ENV.
|
/* intr_ok is set if we are including .profile or $ENV.
|
||||||
* If user ^Cs out, we don't want to kill the shell...
|
* If user ^Cs out, we don't want to kill the shell...
|
||||||
*/
|
*/
|
||||||
if (intr_ok && (exstat - 128) != SIGTERM)
|
if (intr_ok && (exstat - 128) != SIGTERM)
|
||||||
return 1;
|
return (1);
|
||||||
/* FALLTHRU */
|
/* FALLTHRU */
|
||||||
case LEXIT:
|
case LEXIT:
|
||||||
case LLEAVE:
|
case LLEAVE:
|
||||||
@ -488,7 +488,7 @@ include(const char *name, int argc, const char **argv, int intr_ok)
|
|||||||
e->loc->argv = old_argv;
|
e->loc->argv = old_argv;
|
||||||
e->loc->argc = old_argc;
|
e->loc->argc = old_argc;
|
||||||
}
|
}
|
||||||
return i & 0xff; /* & 0xff to ensure value not -1 */
|
return (i & 0xff); /* & 0xff to ensure value not -1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -498,7 +498,7 @@ command(const char *comm)
|
|||||||
|
|
||||||
s = pushs(SSTRING, ATEMP);
|
s = pushs(SSTRING, ATEMP);
|
||||||
s->start = s->str = comm;
|
s->start = s->str = comm;
|
||||||
return shell(s, false);
|
return (shell(s, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -603,7 +603,7 @@ shell(Source * volatile s, volatile int toplevel)
|
|||||||
}
|
}
|
||||||
quitenv(NULL);
|
quitenv(NULL);
|
||||||
source = old_source;
|
source = old_source;
|
||||||
return exstat;
|
return (exstat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return to closest error handler or shell(), exit if none found */
|
/* return to closest error handler or shell(), exit if none found */
|
||||||
@ -648,7 +648,7 @@ newenv(int type)
|
|||||||
* struct env includes ALLOC_ITEM for alignment constraints
|
* struct env includes ALLOC_ITEM for alignment constraints
|
||||||
* so first get the actually used memory, then assign it
|
* so first get the actually used memory, then assign it
|
||||||
*/
|
*/
|
||||||
cp = alloc(sizeof (struct env) - ALLOC_SIZE, ATEMP);
|
cp = alloc(sizeof(struct env) - ALLOC_SIZE, ATEMP);
|
||||||
ep = (void *)(cp - ALLOC_SIZE); /* undo what alloc() did */
|
ep = (void *)(cp - ALLOC_SIZE); /* undo what alloc() did */
|
||||||
/* initialise public members of struct env (not the ALLOC_ITEM) */
|
/* initialise public members of struct env (not the ALLOC_ITEM) */
|
||||||
ainit(&ep->area);
|
ainit(&ep->area);
|
||||||
@ -982,8 +982,8 @@ can_seek(int fd)
|
|||||||
{
|
{
|
||||||
struct stat statb;
|
struct stat statb;
|
||||||
|
|
||||||
return fstat(fd, &statb) == 0 && !S_ISREG(statb.st_mode) ?
|
return (fstat(fd, &statb) == 0 && !S_ISREG(statb.st_mode) ?
|
||||||
SHF_UNBUF : 0;
|
SHF_UNBUF : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct shf shf_iob[3];
|
struct shf shf_iob[3];
|
||||||
@ -1025,7 +1025,7 @@ savefd(int fd)
|
|||||||
|
|
||||||
if (fd < FDBASE && (nfd = fcntl(fd, F_DUPFD, FDBASE)) < 0 &&
|
if (fd < FDBASE && (nfd = fcntl(fd, F_DUPFD, FDBASE)) < 0 &&
|
||||||
errno == EBADF)
|
errno == EBADF)
|
||||||
return -1;
|
return (-1);
|
||||||
if (nfd < 0 || nfd > SHRT_MAX)
|
if (nfd < 0 || nfd > SHRT_MAX)
|
||||||
errorf("too many files open in shell");
|
errorf("too many files open in shell");
|
||||||
fcntl(nfd, F_SETFD, FD_CLOEXEC);
|
fcntl(nfd, F_SETFD, FD_CLOEXEC);
|
||||||
@ -1159,10 +1159,10 @@ coproc_getfd(int mode, const char **emsgp)
|
|||||||
int fd = (mode & R_OK) ? coproc.read : coproc.write;
|
int fd = (mode & R_OK) ? coproc.read : coproc.write;
|
||||||
|
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
return fd;
|
return (fd);
|
||||||
if (emsgp)
|
if (emsgp)
|
||||||
*emsgp = "no coprocess";
|
*emsgp = "no coprocess";
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called to close file descriptors related to the coprocess (if any)
|
/* called to close file descriptors related to the coprocess (if any)
|
||||||
@ -1204,7 +1204,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist)
|
|||||||
pathname = tempnam(dir, "mksh.");
|
pathname = tempnam(dir, "mksh.");
|
||||||
len = ((pathname == NULL) ? 0 : strlen(pathname)) + 1;
|
len = ((pathname == NULL) ? 0 : strlen(pathname)) + 1;
|
||||||
#endif
|
#endif
|
||||||
tp = alloc(sizeof (struct temp) + len, ap);
|
tp = alloc(sizeof(struct temp) + len, ap);
|
||||||
tp->name = (char *)&tp[1];
|
tp->name = (char *)&tp[1];
|
||||||
#if !HAVE_MKSTEMP
|
#if !HAVE_MKSTEMP
|
||||||
if (pathname == NULL)
|
if (pathname == NULL)
|
||||||
@ -1228,7 +1228,7 @@ maketemp(Area *ap, Temp_type type, struct temp **tlist)
|
|||||||
|
|
||||||
tp->next = *tlist;
|
tp->next = *tlist;
|
||||||
*tlist = tp;
|
*tlist = tp;
|
||||||
return tp;
|
return (tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define INIT_TBLS 8 /* initial table size (power of 2) */
|
#define INIT_TBLS 8 /* initial table size (power of 2) */
|
||||||
@ -1243,7 +1243,7 @@ hash(const char *n)
|
|||||||
|
|
||||||
while (*n != '\0')
|
while (*n != '\0')
|
||||||
h = 2*h + *n++;
|
h = 2*h + *n++;
|
||||||
return h * 32821; /* scatter bits */
|
return (h * 32821); /* scatter bits */
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1264,7 +1264,7 @@ texpand(struct table *tp, int nsize)
|
|||||||
struct tbl **ntblp, **otblp = tp->tbls;
|
struct tbl **ntblp, **otblp = tp->tbls;
|
||||||
int osize = tp->size;
|
int osize = tp->size;
|
||||||
|
|
||||||
ntblp = alloc(nsize * sizeof (struct tbl *), tp->areap);
|
ntblp = alloc(nsize * sizeof(struct tbl *), tp->areap);
|
||||||
for (i = 0; i < nsize; i++)
|
for (i = 0; i < nsize; i++)
|
||||||
ntblp[i] = NULL;
|
ntblp[i] = NULL;
|
||||||
tp->size = nsize;
|
tp->size = nsize;
|
||||||
@ -1297,18 +1297,18 @@ ktsearch(struct table *tp, const char *n, unsigned int h)
|
|||||||
struct tbl **pp, *p;
|
struct tbl **pp, *p;
|
||||||
|
|
||||||
if (tp->size == 0)
|
if (tp->size == 0)
|
||||||
return NULL;
|
return (NULL);
|
||||||
|
|
||||||
/* search for name in hashed table */
|
/* search for name in hashed table */
|
||||||
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
||||||
if (*p->name == *n && strcmp(p->name, n) == 0 &&
|
if (*p->name == *n && strcmp(p->name, n) == 0 &&
|
||||||
(p->flag & DEFINED))
|
(p->flag & DEFINED))
|
||||||
return p;
|
return (p);
|
||||||
if (pp == tp->tbls) /* wrap */
|
if (pp == tp->tbls) /* wrap */
|
||||||
pp += tp->size;
|
pp += tp->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* table */
|
/* table */
|
||||||
@ -1326,7 +1326,7 @@ ktenter(struct table *tp, const char *n, unsigned int h)
|
|||||||
/* search for name in hashed table */
|
/* search for name in hashed table */
|
||||||
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
||||||
if (*p->name == *n && strcmp(p->name, n) == 0)
|
if (*p->name == *n && strcmp(p->name, n) == 0)
|
||||||
return p; /* found */
|
return (p); /* found */
|
||||||
if (pp == tp->tbls) /* wrap */
|
if (pp == tp->tbls) /* wrap */
|
||||||
pp += tp->size;
|
pp += tp->size;
|
||||||
}
|
}
|
||||||
@ -1348,7 +1348,7 @@ ktenter(struct table *tp, const char *n, unsigned int h)
|
|||||||
/* enter in tp->tbls */
|
/* enter in tp->tbls */
|
||||||
tp->nfree--;
|
tp->nfree--;
|
||||||
*pp = p;
|
*pp = p;
|
||||||
return p;
|
return (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1364,9 +1364,9 @@ ktnext(struct tstate *ts)
|
|||||||
while (--ts->left >= 0) {
|
while (--ts->left >= 0) {
|
||||||
struct tbl *p = *ts->next++;
|
struct tbl *p = *ts->next++;
|
||||||
if (p != NULL && (p->flag & DEFINED))
|
if (p != NULL && (p->flag & DEFINED))
|
||||||
return p;
|
return (p);
|
||||||
}
|
}
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -1384,14 +1384,14 @@ ktsort(struct table *tp)
|
|||||||
size_t i;
|
size_t i;
|
||||||
struct tbl **p, **sp, **dp;
|
struct tbl **p, **sp, **dp;
|
||||||
|
|
||||||
p = alloc((tp->size + 1) * sizeof (struct tbl *), ATEMP);
|
p = alloc((tp->size + 1) * sizeof(struct tbl *), ATEMP);
|
||||||
sp = tp->tbls; /* source */
|
sp = tp->tbls; /* source */
|
||||||
dp = p; /* dest */
|
dp = p; /* dest */
|
||||||
for (i = 0; i < (size_t)tp->size; i++)
|
for (i = 0; i < (size_t)tp->size; i++)
|
||||||
if ((*dp = *sp++) != NULL && (((*dp)->flag & DEFINED) ||
|
if ((*dp = *sp++) != NULL && (((*dp)->flag & DEFINED) ||
|
||||||
((*dp)->flag & ARRAY)))
|
((*dp)->flag & ARRAY)))
|
||||||
dp++;
|
dp++;
|
||||||
qsort(p, (i = dp - p), sizeof (void *), tnamecmp);
|
qsort(p, (i = dp - p), sizeof(void *), tnamecmp);
|
||||||
p[i] = NULL;
|
p[i] = NULL;
|
||||||
return p;
|
return (p);
|
||||||
}
|
}
|
||||||
|
114
misc.c
114
misc.c
@ -29,7 +29,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.108 2009/05/31 15:10:07 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.109 2009/06/08 20:06:48 tg Exp $");
|
||||||
|
|
||||||
#undef USE_CHVT
|
#undef USE_CHVT
|
||||||
#if defined(TIOCSCTTY) && !defined(MKSH_SMALL)
|
#if defined(TIOCSCTTY) && !defined(MKSH_SMALL)
|
||||||
@ -95,7 +95,7 @@ Xcheck_grow_(XString *xsp, const char *xp, unsigned int more)
|
|||||||
xsp->len += more > xsp->len ? more : xsp->len;
|
xsp->len += more > xsp->len ? more : xsp->len;
|
||||||
xsp->beg = aresize(xsp->beg, xsp->len + 8, xsp->areap);
|
xsp->beg = aresize(xsp->beg, xsp->len + 8, xsp->areap);
|
||||||
xsp->end = xsp->beg + xsp->len;
|
xsp->end = xsp->beg + xsp->len;
|
||||||
return xsp->beg + (xp - old_beg);
|
return (xsp->beg + (xp - old_beg));
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct shoption options[] = {
|
const struct shoption options[] = {
|
||||||
@ -187,7 +187,7 @@ options_fmt_entry(const void *arg, int i, char *buf, int buflen)
|
|||||||
shf_snprintf(buf, buflen, "%-*s %s",
|
shf_snprintf(buf, buflen, "%-*s %s",
|
||||||
oi->opt_width, options[oi->opts[i]].name,
|
oi->opt_width, options[oi->opts[i]].name,
|
||||||
Flag(oi->opts[i]) ? "on" : "off");
|
Flag(oi->opts[i]) ? "on" : "off");
|
||||||
return buf;
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -402,7 +402,7 @@ parse_args(const char **argv,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
return -1;
|
return (-1);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (what == OF_FIRSTTIME)
|
if (what == OF_FIRSTTIME)
|
||||||
@ -438,12 +438,12 @@ parse_args(const char **argv,
|
|||||||
|
|
||||||
if (arrayset && (!*array || *skip_varname(array, false))) {
|
if (arrayset && (!*array || *skip_varname(array, false))) {
|
||||||
bi_errorf("%s: is not an identifier", array);
|
bi_errorf("%s: is not an identifier", array);
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
if (sortargs) {
|
if (sortargs) {
|
||||||
for (i = go.optind; argv[i]; i++)
|
for (i = go.optind; argv[i]; i++)
|
||||||
;
|
;
|
||||||
qsort(&argv[go.optind], i - go.optind, sizeof (void *),
|
qsort(&argv[go.optind], i - go.optind, sizeof(void *),
|
||||||
xstrcmp);
|
xstrcmp);
|
||||||
}
|
}
|
||||||
if (arrayset) {
|
if (arrayset) {
|
||||||
@ -452,7 +452,7 @@ parse_args(const char **argv,
|
|||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
return go.optind;
|
return (go.optind);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse a decimal number: returns 0 if string isn't a number, 1 otherwise */
|
/* parse a decimal number: returns 0 if string isn't a number, 1 otherwise */
|
||||||
@ -516,7 +516,7 @@ gmatchx(const char *s, const char *p, bool isfile)
|
|||||||
const char *se, *pe;
|
const char *se, *pe;
|
||||||
|
|
||||||
if (s == NULL || p == NULL)
|
if (s == NULL || p == NULL)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
se = s + strlen(s);
|
se = s + strlen(s);
|
||||||
pe = p + strlen(p);
|
pe = p + strlen(p);
|
||||||
@ -528,10 +528,10 @@ gmatchx(const char *s, const char *p, bool isfile)
|
|||||||
char tbuf[64];
|
char tbuf[64];
|
||||||
char *t = len <= sizeof(tbuf) ? tbuf : alloc(len, ATEMP);
|
char *t = len <= sizeof(tbuf) ? tbuf : alloc(len, ATEMP);
|
||||||
debunk(t, p, len);
|
debunk(t, p, len);
|
||||||
return !strcmp(t, s);
|
return (!strcmp(t, s));
|
||||||
}
|
}
|
||||||
return do_gmatch((const unsigned char *) s, (const unsigned char *) se,
|
return (do_gmatch((const unsigned char *) s, (const unsigned char *) se,
|
||||||
(const unsigned char *) p, (const unsigned char *) pe);
|
(const unsigned char *) p, (const unsigned char *) pe));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns if p is a syntacticly correct globbing pattern, false
|
/* Returns if p is a syntacticly correct globbing pattern, false
|
||||||
@ -578,7 +578,7 @@ has_globbing(const char *xp, const char *xpe)
|
|||||||
} else if (c == ']') {
|
} else if (c == ']') {
|
||||||
if (in_bracket) {
|
if (in_bracket) {
|
||||||
if (bnest) /* [a*(b]) */
|
if (bnest) /* [a*(b]) */
|
||||||
return 0;
|
return (0);
|
||||||
in_bracket = 0;
|
in_bracket = 0;
|
||||||
}
|
}
|
||||||
} else if ((c & 0x80) && vstrchr("*+?@! ", c & 0x7f)) {
|
} else if ((c & 0x80) && vstrchr("*+?@! ", c & 0x7f)) {
|
||||||
@ -589,18 +589,18 @@ has_globbing(const char *xp, const char *xpe)
|
|||||||
nest++;
|
nest++;
|
||||||
} else if (c == '|') {
|
} else if (c == '|') {
|
||||||
if (in_bracket && !bnest) /* *(a[foo|bar]) */
|
if (in_bracket && !bnest) /* *(a[foo|bar]) */
|
||||||
return 0;
|
return (0);
|
||||||
} else if (c == /*(*/ ')') {
|
} else if (c == /*(*/ ')') {
|
||||||
if (in_bracket) {
|
if (in_bracket) {
|
||||||
if (!bnest--) /* *(a[b)c] */
|
if (!bnest--) /* *(a[b)c] */
|
||||||
return 0;
|
return (0);
|
||||||
} else if (nest)
|
} else if (nest)
|
||||||
nest--;
|
nest--;
|
||||||
}
|
}
|
||||||
/* else must be a MAGIC-MAGIC, or MAGIC-!, MAGIC--, MAGIC-]
|
/* else must be a MAGIC-MAGIC, or MAGIC-!, MAGIC--, MAGIC-]
|
||||||
MAGIC-{, MAGIC-,, MAGIC-} */
|
MAGIC-{, MAGIC-,, MAGIC-} */
|
||||||
}
|
}
|
||||||
return saw_glob && !in_bracket && !nest;
|
return (saw_glob && !in_bracket && !nest);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function must return either 0 or 1 (assumed by code for 0x80|'!') */
|
/* Function must return either 0 or 1 (assumed by code for 0x80|'!') */
|
||||||
@ -613,36 +613,36 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
|||||||
const unsigned char *srest;
|
const unsigned char *srest;
|
||||||
|
|
||||||
if (s == NULL || p == NULL)
|
if (s == NULL || p == NULL)
|
||||||
return 0;
|
return (0);
|
||||||
while (p < pe) {
|
while (p < pe) {
|
||||||
pc = *p++;
|
pc = *p++;
|
||||||
sc = s < se ? *s : '\0';
|
sc = s < se ? *s : '\0';
|
||||||
s++;
|
s++;
|
||||||
if (!ISMAGIC(pc)) {
|
if (!ISMAGIC(pc)) {
|
||||||
if (sc != pc)
|
if (sc != pc)
|
||||||
return 0;
|
return (0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch (*p++) {
|
switch (*p++) {
|
||||||
case '[':
|
case '[':
|
||||||
if (sc == 0 || (p = cclass(p, sc)) == NULL)
|
if (sc == 0 || (p = cclass(p, sc)) == NULL)
|
||||||
return 0;
|
return (0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
if (sc == 0)
|
if (sc == 0)
|
||||||
return 0;
|
return (0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '*':
|
case '*':
|
||||||
if (p == pe)
|
if (p == pe)
|
||||||
return 1;
|
return (1);
|
||||||
s--;
|
s--;
|
||||||
do {
|
do {
|
||||||
if (do_gmatch(s, se, p, pe))
|
if (do_gmatch(s, se, p, pe))
|
||||||
return 1;
|
return (1);
|
||||||
} while (s++ < se);
|
} while (s++ < se);
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* [*+?@!](pattern|pattern|..)
|
* [*+?@!](pattern|pattern|..)
|
||||||
@ -651,12 +651,12 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
|||||||
case 0x80|'+': /* matches one or more times */
|
case 0x80|'+': /* matches one or more times */
|
||||||
case 0x80|'*': /* matches zero or more times */
|
case 0x80|'*': /* matches zero or more times */
|
||||||
if (!(prest = pat_scan(p, pe, 0)))
|
if (!(prest = pat_scan(p, pe, 0)))
|
||||||
return 0;
|
return (0);
|
||||||
s--;
|
s--;
|
||||||
/* take care of zero matches */
|
/* take care of zero matches */
|
||||||
if (p[-1] == (0x80 | '*') &&
|
if (p[-1] == (0x80 | '*') &&
|
||||||
do_gmatch(s, se, prest, pe))
|
do_gmatch(s, se, prest, pe))
|
||||||
return 1;
|
return (1);
|
||||||
for (psub = p; ; psub = pnext) {
|
for (psub = p; ; psub = pnext) {
|
||||||
pnext = pat_scan(psub, pe, 1);
|
pnext = pat_scan(psub, pe, 1);
|
||||||
for (srest = s; srest <= se; srest++) {
|
for (srest = s; srest <= se; srest++) {
|
||||||
@ -664,39 +664,39 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
|||||||
(do_gmatch(srest, se, prest, pe) ||
|
(do_gmatch(srest, se, prest, pe) ||
|
||||||
(s != srest && do_gmatch(srest,
|
(s != srest && do_gmatch(srest,
|
||||||
se, p - 2, pe))))
|
se, p - 2, pe))))
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (pnext == prest)
|
if (pnext == prest)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
case 0x80|'?': /* matches zero or once */
|
case 0x80|'?': /* matches zero or once */
|
||||||
case 0x80|'@': /* matches one of the patterns */
|
case 0x80|'@': /* matches one of the patterns */
|
||||||
case 0x80|' ': /* simile for @ */
|
case 0x80|' ': /* simile for @ */
|
||||||
if (!(prest = pat_scan(p, pe, 0)))
|
if (!(prest = pat_scan(p, pe, 0)))
|
||||||
return 0;
|
return (0);
|
||||||
s--;
|
s--;
|
||||||
/* Take care of zero matches */
|
/* Take care of zero matches */
|
||||||
if (p[-1] == (0x80 | '?') &&
|
if (p[-1] == (0x80 | '?') &&
|
||||||
do_gmatch(s, se, prest, pe))
|
do_gmatch(s, se, prest, pe))
|
||||||
return 1;
|
return (1);
|
||||||
for (psub = p; ; psub = pnext) {
|
for (psub = p; ; psub = pnext) {
|
||||||
pnext = pat_scan(psub, pe, 1);
|
pnext = pat_scan(psub, pe, 1);
|
||||||
srest = prest == pe ? se : s;
|
srest = prest == pe ? se : s;
|
||||||
for (; srest <= se; srest++) {
|
for (; srest <= se; srest++) {
|
||||||
if (do_gmatch(s, srest, psub, pnext - 2) &&
|
if (do_gmatch(s, srest, psub, pnext - 2) &&
|
||||||
do_gmatch(srest, se, prest, pe))
|
do_gmatch(srest, se, prest, pe))
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
if (pnext == prest)
|
if (pnext == prest)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
case 0x80|'!': /* matches none of the patterns */
|
case 0x80|'!': /* matches none of the patterns */
|
||||||
if (!(prest = pat_scan(p, pe, 0)))
|
if (!(prest = pat_scan(p, pe, 0)))
|
||||||
return 0;
|
return (0);
|
||||||
s--;
|
s--;
|
||||||
for (srest = s; srest <= se; srest++) {
|
for (srest = s; srest <= se; srest++) {
|
||||||
int matched = 0;
|
int matched = 0;
|
||||||
@ -713,17 +713,17 @@ do_gmatch(const unsigned char *s, const unsigned char *se,
|
|||||||
}
|
}
|
||||||
if (!matched &&
|
if (!matched &&
|
||||||
do_gmatch(srest, se, prest, pe))
|
do_gmatch(srest, se, prest, pe))
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (sc != p[-1])
|
if (sc != p[-1])
|
||||||
return 0;
|
return (0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s == se;
|
return (s == se);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const unsigned char *
|
static const unsigned char *
|
||||||
@ -747,7 +747,7 @@ cclass(const unsigned char *p, int sub)
|
|||||||
}
|
}
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
/* No closing ] - act as if the opening [ was quoted */
|
/* No closing ] - act as if the opening [ was quoted */
|
||||||
return sub == '[' ? orig_p : NULL;
|
return (sub == '[' ? orig_p : NULL);
|
||||||
if (ISMAGIC(p[0]) && p[1] == '-' &&
|
if (ISMAGIC(p[0]) && p[1] == '-' &&
|
||||||
(!ISMAGIC(p[2]) || p[3] != ']')) {
|
(!ISMAGIC(p[2]) || p[3] != ']')) {
|
||||||
p += 2; /* MAGIC- */
|
p += 2; /* MAGIC- */
|
||||||
@ -759,14 +759,14 @@ cclass(const unsigned char *p, int sub)
|
|||||||
}
|
}
|
||||||
/* POSIX says this is an invalid expression */
|
/* POSIX says this is an invalid expression */
|
||||||
if (c > d)
|
if (c > d)
|
||||||
return NULL;
|
return (NULL);
|
||||||
} else
|
} else
|
||||||
d = c;
|
d = c;
|
||||||
if (c == sub || (c <= sub && sub <= d))
|
if (c == sub || (c <= sub && sub <= d))
|
||||||
found = 1;
|
found = 1;
|
||||||
} while (!(ISMAGIC(p[0]) && p[1] == ']'));
|
} while (!(ISMAGIC(p[0]) && p[1] == ']'));
|
||||||
|
|
||||||
return (found != not) ? p+2 : NULL;
|
return ((found != not) ? p+2 : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look for next ) or | (if match_sep) in *(foo|bar) pattern */
|
/* Look for next ) or | (if match_sep) in *(foo|bar) pattern */
|
||||||
@ -844,14 +844,14 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
|
|||||||
go->optind++;
|
go->optind++;
|
||||||
go->p = 0;
|
go->p = 0;
|
||||||
go->info |= GI_MINUSMINUS;
|
go->info |= GI_MINUSMINUS;
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
if (arg == NULL ||
|
if (arg == NULL ||
|
||||||
((flag != '-' ) && /* neither a - nor a + (if + allowed) */
|
((flag != '-' ) && /* neither a - nor a + (if + allowed) */
|
||||||
(!(go->flags & GF_PLUSOPT) || flag != '+')) ||
|
(!(go->flags & GF_PLUSOPT) || flag != '+')) ||
|
||||||
(c = arg[1]) == '\0') {
|
(c = arg[1]) == '\0') {
|
||||||
go->p = 0;
|
go->p = 0;
|
||||||
return -1;
|
return (-1);
|
||||||
}
|
}
|
||||||
go->optind++;
|
go->optind++;
|
||||||
go->info &= ~(GI_MINUS|GI_PLUS);
|
go->info &= ~(GI_MINUS|GI_PLUS);
|
||||||
@ -870,7 +870,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
|
|||||||
if (go->flags & GF_ERROR)
|
if (go->flags & GF_ERROR)
|
||||||
bi_errorfz();
|
bi_errorfz();
|
||||||
}
|
}
|
||||||
return '?';
|
return ('?');
|
||||||
}
|
}
|
||||||
/* : means argument must be present, may be part of option argument
|
/* : means argument must be present, may be part of option argument
|
||||||
* or the next argument
|
* or the next argument
|
||||||
@ -888,14 +888,14 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
|
|||||||
if (optionsp[0] == ':') {
|
if (optionsp[0] == ':') {
|
||||||
go->buf[0] = c;
|
go->buf[0] = c;
|
||||||
go->optarg = go->buf;
|
go->optarg = go->buf;
|
||||||
return ':';
|
return (':');
|
||||||
}
|
}
|
||||||
warningf(true, "%s%s-'%c' requires argument",
|
warningf(true, "%s%s-'%c' requires argument",
|
||||||
(go->flags & GF_NONAME) ? "" : argv[0],
|
(go->flags & GF_NONAME) ? "" : argv[0],
|
||||||
(go->flags & GF_NONAME) ? "" : ": ", c);
|
(go->flags & GF_NONAME) ? "" : ": ", c);
|
||||||
if (go->flags & GF_ERROR)
|
if (go->flags & GF_ERROR)
|
||||||
bi_errorfz();
|
bi_errorfz();
|
||||||
return '?';
|
return ('?');
|
||||||
}
|
}
|
||||||
go->p = 0;
|
go->p = 0;
|
||||||
} else if (*o == ',') {
|
} else if (*o == ',') {
|
||||||
@ -921,7 +921,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
|
|||||||
go->optarg = NULL;
|
go->optarg = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return c;
|
return (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print variable/alias value using necessary quotes
|
/* print variable/alias value using necessary quotes
|
||||||
@ -1061,7 +1061,7 @@ blocking_read(int fd, char *buf, int nbytes)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset the non-blocking flag on the specified file descriptor.
|
/* Reset the non-blocking flag on the specified file descriptor.
|
||||||
@ -1074,13 +1074,13 @@ reset_nonblock(int fd)
|
|||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
if ((flags = fcntl(fd, F_GETFL, 0)) < 0)
|
if ((flags = fcntl(fd, F_GETFL, 0)) < 0)
|
||||||
return -1;
|
return (-1);
|
||||||
if (!(flags & O_NONBLOCK))
|
if (!(flags & O_NONBLOCK))
|
||||||
return 0;
|
return (0);
|
||||||
flags &= ~O_NONBLOCK;
|
flags &= ~O_NONBLOCK;
|
||||||
if (fcntl(fd, F_SETFL, flags) < 0)
|
if (fcntl(fd, F_SETFL, flags) < 0)
|
||||||
return -1;
|
return (-1);
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1098,7 +1098,7 @@ ksh_get_wd(size_t *dlen)
|
|||||||
|
|
||||||
if (dlen)
|
if (dlen)
|
||||||
*dlen = len;
|
*dlen = len;
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1183,7 +1183,7 @@ make_path(const char *cwd, const char *file,
|
|||||||
if (!use_cdpath)
|
if (!use_cdpath)
|
||||||
*cdpathp = NULL;
|
*cdpathp = NULL;
|
||||||
|
|
||||||
return rval;
|
return (rval);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1287,13 +1287,13 @@ get_phys_path(const char *pathl)
|
|||||||
xp = do_phys_path(&xs, xp, pathl);
|
xp = do_phys_path(&xs, xp, pathl);
|
||||||
|
|
||||||
if (!xp)
|
if (!xp)
|
||||||
return NULL;
|
return (NULL);
|
||||||
|
|
||||||
if (Xlength(xs, xp) == 0)
|
if (Xlength(xs, xp) == 0)
|
||||||
Xput(xs, xp, '/');
|
Xput(xs, xp, '/');
|
||||||
Xput(xs, xp, '\0');
|
Xput(xs, xp, '\0');
|
||||||
|
|
||||||
return Xclose(xs, xp);
|
return (Xclose(xs, xp));
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@ -1359,7 +1359,7 @@ chvt(const char *fn)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (*fn == '-') {
|
if (*fn == '-') {
|
||||||
memcpy(dv, "-/dev/null", sizeof ("-/dev/null"));
|
memcpy(dv, "-/dev/null", sizeof("-/dev/null"));
|
||||||
fn = dv + 1;
|
fn = dv + 1;
|
||||||
} else {
|
} else {
|
||||||
if (stat(fn, &sb)) {
|
if (stat(fn, &sb)) {
|
||||||
@ -1415,9 +1415,9 @@ chvt(const char *fn)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
char longsizes_are_okay[sizeof (long) == sizeof (unsigned long) ? 1 : -1];
|
char longsizes_are_okay[sizeof(long) == sizeof(unsigned long) ? 1 : -1];
|
||||||
char arisize_is_okay[sizeof (mksh_ari_t) == 4 ? 1 : -1];
|
char arisize_is_okay[sizeof(mksh_ari_t) == 4 ? 1 : -1];
|
||||||
char uarisize_is_okay[sizeof (mksh_uari_t) == 4 ? 1 : -1];
|
char uarisize_is_okay[sizeof(mksh_uari_t) == 4 ? 1 : -1];
|
||||||
|
|
||||||
char *
|
char *
|
||||||
strchr(char *p, int ch)
|
strchr(char *p, int ch)
|
||||||
|
12
sh.h
12
sh.h
@ -122,7 +122,7 @@
|
|||||||
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
#define __SCCSID(x) __IDSTRING(sccsid,x)
|
||||||
|
|
||||||
#ifdef EXTERN
|
#ifdef EXTERN
|
||||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.306 2009/06/07 22:28:05 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.307 2009/06/08 20:06:48 tg Exp $");
|
||||||
#endif
|
#endif
|
||||||
#define MKSH_VERSION "R38 2009/06/07"
|
#define MKSH_VERSION "R38 2009/06/07"
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ extern int __cdecl setegid(gid_t);
|
|||||||
# define EXTERN_DEFINED
|
# define EXTERN_DEFINED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NELEM(a) (sizeof (a) / sizeof ((a)[0]))
|
#define NELEM(a) (sizeof(a) / sizeof((a)[0]))
|
||||||
#define BIT(i) (1 << (i)) /* define bit in flag */
|
#define BIT(i) (1 << (i)) /* define bit in flag */
|
||||||
|
|
||||||
/* Table flag type - needs > 16 and < 32 bits */
|
/* Table flag type - needs > 16 and < 32 bits */
|
||||||
@ -445,7 +445,7 @@ struct lalloc {
|
|||||||
|
|
||||||
/* 2. sizes */
|
/* 2. sizes */
|
||||||
#define ALLOC_ITEM struct lalloc
|
#define ALLOC_ITEM struct lalloc
|
||||||
#define ALLOC_SIZE (sizeof (ALLOC_ITEM))
|
#define ALLOC_SIZE (sizeof(ALLOC_ITEM))
|
||||||
|
|
||||||
/* 3. group structure (only the same for lalloc.c) */
|
/* 3. group structure (only the same for lalloc.c) */
|
||||||
typedef struct lalloc Area;
|
typedef struct lalloc Area;
|
||||||
@ -1187,7 +1187,7 @@ typedef struct XPtrV {
|
|||||||
|
|
||||||
#define XPinit(x, n) do { \
|
#define XPinit(x, n) do { \
|
||||||
void **vp__; \
|
void **vp__; \
|
||||||
vp__ = alloc((n) * sizeof (void *), ATEMP); \
|
vp__ = alloc((n) * sizeof(void *), ATEMP); \
|
||||||
(x).cur = (x).beg = vp__; \
|
(x).cur = (x).beg = vp__; \
|
||||||
(x).end = vp__ + (n); \
|
(x).end = vp__ + (n); \
|
||||||
} while (/* CONSTCOND */ 0)
|
} while (/* CONSTCOND */ 0)
|
||||||
@ -1196,7 +1196,7 @@ typedef struct XPtrV {
|
|||||||
if ((x).cur >= (x).end) { \
|
if ((x).cur >= (x).end) { \
|
||||||
size_t n = XPsize(x); \
|
size_t n = XPsize(x); \
|
||||||
(x).beg = aresize((x).beg, \
|
(x).beg = aresize((x).beg, \
|
||||||
n * 2 * sizeof (void *), ATEMP); \
|
n * 2 * sizeof(void *), ATEMP); \
|
||||||
(x).cur = (x).beg + n; \
|
(x).cur = (x).beg + n; \
|
||||||
(x).end = (x).cur + n; \
|
(x).end = (x).cur + n; \
|
||||||
} \
|
} \
|
||||||
@ -1205,7 +1205,7 @@ typedef struct XPtrV {
|
|||||||
|
|
||||||
#define XPptrv(x) ((x).beg)
|
#define XPptrv(x) ((x).beg)
|
||||||
#define XPsize(x) ((x).cur - (x).beg)
|
#define XPsize(x) ((x).cur - (x).beg)
|
||||||
#define XPclose(x) aresize((x).beg, XPsize(x) * sizeof (void *), ATEMP)
|
#define XPclose(x) aresize((x).beg, XPsize(x) * sizeof(void *), ATEMP)
|
||||||
#define XPfree(x) afree((x).beg, ATEMP)
|
#define XPfree(x) afree((x).beg, ATEMP)
|
||||||
|
|
||||||
#define IDENT 64
|
#define IDENT 64
|
||||||
|
122
shf.c
122
shf.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.28 2009/05/16 16:59:40 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.29 2009/06/08 20:06:49 tg Exp $");
|
||||||
|
|
||||||
/* flags to shf_emptybuf() */
|
/* flags to shf_emptybuf() */
|
||||||
#define EB_READSW 0x01 /* about to switch to reading */
|
#define EB_READSW 0x01 /* about to switch to reading */
|
||||||
@ -49,7 +49,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
/* Done before open so if alloca fails, fd won't be lost. */
|
/* Done before open so if alloca fails, fd won't be lost. */
|
||||||
shf = alloc(sizeof (struct shf) + bsize, ATEMP);
|
shf = alloc(sizeof(struct shf) + bsize, ATEMP);
|
||||||
shf->areap = ATEMP;
|
shf->areap = ATEMP;
|
||||||
shf->buf = (unsigned char *)&shf[1];
|
shf->buf = (unsigned char *)&shf[1];
|
||||||
shf->bsize = bsize;
|
shf->bsize = bsize;
|
||||||
@ -59,7 +59,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
|||||||
fd = open(name, oflags, mode);
|
fd = open(name, oflags, mode);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
afree(shf, shf->areap);
|
afree(shf, shf->areap);
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
if ((sflags & SHF_MAPHI) && fd < FDBASE) {
|
if ((sflags & SHF_MAPHI) && fd < FDBASE) {
|
||||||
int nfd;
|
int nfd;
|
||||||
@ -68,7 +68,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
|||||||
close(fd);
|
close(fd);
|
||||||
if (nfd < 0) {
|
if (nfd < 0) {
|
||||||
afree(shf, shf->areap);
|
afree(shf, shf->areap);
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
fd = nfd;
|
fd = nfd;
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ shf_open(const char *name, int oflags, int mode, int sflags)
|
|||||||
sflags |= (oflags & O_ACCMODE) == O_RDONLY ? SHF_RD :
|
sflags |= (oflags & O_ACCMODE) == O_RDONLY ? SHF_RD :
|
||||||
((oflags & O_ACCMODE) == O_WRONLY ? SHF_WR : SHF_RDWR);
|
((oflags & O_ACCMODE) == O_WRONLY ? SHF_WR : SHF_RDWR);
|
||||||
|
|
||||||
return shf_reopen(fd, sflags, shf);
|
return (shf_reopen(fd, sflags, shf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up the shf structure for a file descriptor. Doesn't fail. */
|
/* Set up the shf structure for a file descriptor. Doesn't fail. */
|
||||||
@ -117,7 +117,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
|
|||||||
} else
|
} else
|
||||||
shf->buf = NULL;
|
shf->buf = NULL;
|
||||||
} else {
|
} else {
|
||||||
shf = alloc(sizeof (struct shf) + bsize, ATEMP);
|
shf = alloc(sizeof(struct shf) + bsize, ATEMP);
|
||||||
shf->buf = (unsigned char *)&shf[1];
|
shf->buf = (unsigned char *)&shf[1];
|
||||||
sflags |= SHF_ALLOCS;
|
sflags |= SHF_ALLOCS;
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
|
|||||||
shf->bsize = bsize;
|
shf->bsize = bsize;
|
||||||
if (sflags & SHF_CLEXEC)
|
if (sflags & SHF_CLEXEC)
|
||||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
return shf;
|
return (shf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up an existing shf (and buffer) to use the given fd */
|
/* Set up an existing shf (and buffer) to use the given fd */
|
||||||
@ -180,7 +180,7 @@ shf_reopen(int fd, int sflags, struct shf *shf)
|
|||||||
shf->errno_ = 0;
|
shf->errno_ = 0;
|
||||||
if (sflags & SHF_CLEXEC)
|
if (sflags & SHF_CLEXEC)
|
||||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
return shf;
|
return (shf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open a string for reading or writing. If reading, bsize is the number
|
/* Open a string for reading or writing. If reading, bsize is the number
|
||||||
@ -199,7 +199,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
|
|||||||
internal_errorf("shf_sopen: flags 0x%x", sflags);
|
internal_errorf("shf_sopen: flags 0x%x", sflags);
|
||||||
|
|
||||||
if (!shf) {
|
if (!shf) {
|
||||||
shf = alloc(sizeof (struct shf), ATEMP);
|
shf = alloc(sizeof(struct shf), ATEMP);
|
||||||
sflags |= SHF_ALLOCS;
|
sflags |= SHF_ALLOCS;
|
||||||
}
|
}
|
||||||
shf->areap = ATEMP;
|
shf->areap = ATEMP;
|
||||||
@ -219,7 +219,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
|
|||||||
shf->errno_ = 0;
|
shf->errno_ = 0;
|
||||||
shf->bsize = bsize;
|
shf->bsize = bsize;
|
||||||
|
|
||||||
return shf;
|
return (shf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flush and close file descriptor, free the shf structure */
|
/* Flush and close file descriptor, free the shf structure */
|
||||||
@ -238,7 +238,7 @@ shf_close(struct shf *shf)
|
|||||||
else if (shf->flags & SHF_ALLOCB)
|
else if (shf->flags & SHF_ALLOCB)
|
||||||
afree(shf->buf, shf->areap);
|
afree(shf->buf, shf->areap);
|
||||||
|
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flush and close file descriptor, don't free file structure */
|
/* Flush and close file descriptor, don't free file structure */
|
||||||
@ -257,7 +257,7 @@ shf_fdclose(struct shf *shf)
|
|||||||
shf->fd = -1;
|
shf->fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close a string - if it was opened for writing, it is null terminated;
|
/* Close a string - if it was opened for writing, it is null terminated;
|
||||||
@ -276,7 +276,7 @@ shf_sclose(struct shf *shf)
|
|||||||
}
|
}
|
||||||
if (shf->flags & SHF_ALLOCS)
|
if (shf->flags & SHF_ALLOCS)
|
||||||
afree(shf, shf->areap);
|
afree(shf, shf->areap);
|
||||||
return (char *) s;
|
return ((char *)s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Un-read what has been read but not examined, or write what has been
|
/* Un-read what has been read but not examined, or write what has been
|
||||||
@ -286,14 +286,14 @@ int
|
|||||||
shf_flush(struct shf *shf)
|
shf_flush(struct shf *shf)
|
||||||
{
|
{
|
||||||
if (shf->flags & SHF_STRING)
|
if (shf->flags & SHF_STRING)
|
||||||
return (shf->flags & SHF_WR) ? EOF : 0;
|
return ((shf->flags & SHF_WR) ? EOF : 0);
|
||||||
|
|
||||||
if (shf->fd < 0)
|
if (shf->fd < 0)
|
||||||
internal_errorf("shf_flush: no fd");
|
internal_errorf("shf_flush: no fd");
|
||||||
|
|
||||||
if (shf->flags & SHF_ERROR) {
|
if (shf->flags & SHF_ERROR) {
|
||||||
errno = shf->errno_;
|
errno = shf->errno_;
|
||||||
return EOF;
|
return (EOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shf->flags & SHF_READING) {
|
if (shf->flags & SHF_READING) {
|
||||||
@ -303,11 +303,11 @@ shf_flush(struct shf *shf)
|
|||||||
shf->rnleft = 0;
|
shf->rnleft = 0;
|
||||||
shf->rp = shf->buf;
|
shf->rp = shf->buf;
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
} else if (shf->flags & SHF_WRITING)
|
} else if (shf->flags & SHF_WRITING)
|
||||||
return shf_emptybuf(shf, 0);
|
return (shf_emptybuf(shf, 0));
|
||||||
|
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write out any buffered data. If currently reading, flushes the read
|
/* Write out any buffered data. If currently reading, flushes the read
|
||||||
@ -323,12 +323,12 @@ shf_emptybuf(struct shf *shf, int flags)
|
|||||||
|
|
||||||
if (shf->flags & SHF_ERROR) {
|
if (shf->flags & SHF_ERROR) {
|
||||||
errno = shf->errno_;
|
errno = shf->errno_;
|
||||||
return EOF;
|
return (EOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shf->flags & SHF_READING) {
|
if (shf->flags & SHF_READING) {
|
||||||
if (flags & EB_READSW) /* doesn't happen */
|
if (flags & EB_READSW) /* doesn't happen */
|
||||||
return 0;
|
return (0);
|
||||||
ret = shf_flush(shf);
|
ret = shf_flush(shf);
|
||||||
shf->flags &= ~SHF_READING;
|
shf->flags &= ~SHF_READING;
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
|||||||
*/
|
*/
|
||||||
if (!(flags & EB_GROW) || !(shf->flags & SHF_DYNAMIC) ||
|
if (!(flags & EB_GROW) || !(shf->flags & SHF_DYNAMIC) ||
|
||||||
!(shf->flags & SHF_ALLOCB))
|
!(shf->flags & SHF_ALLOCB))
|
||||||
return EOF;
|
return (EOF);
|
||||||
/* allocate more space for buffer */
|
/* allocate more space for buffer */
|
||||||
nbuf = aresize(shf->buf, 2 * shf->wbsize, shf->areap);
|
nbuf = aresize(shf->buf, 2 * shf->wbsize, shf->areap);
|
||||||
shf->rp = nbuf + (shf->rp - shf->buf);
|
shf->rp = nbuf + (shf->rp - shf->buf);
|
||||||
@ -371,7 +371,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
|||||||
ntowrite);
|
ntowrite);
|
||||||
shf->wp = shf->buf + ntowrite;
|
shf->wp = shf->buf + ntowrite;
|
||||||
}
|
}
|
||||||
return EOF;
|
return (EOF);
|
||||||
}
|
}
|
||||||
buf += n;
|
buf += n;
|
||||||
ntowrite -= n;
|
ntowrite -= n;
|
||||||
@ -380,7 +380,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
|||||||
shf->wp = shf->buf;
|
shf->wp = shf->buf;
|
||||||
shf->wnleft = 0;
|
shf->wnleft = 0;
|
||||||
shf->flags &= ~SHF_WRITING;
|
shf->flags &= ~SHF_WRITING;
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shf->wp = shf->buf;
|
shf->wp = shf->buf;
|
||||||
@ -388,7 +388,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
|||||||
}
|
}
|
||||||
shf->flags |= SHF_WRITING;
|
shf->flags |= SHF_WRITING;
|
||||||
|
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill up a read buffer. Returns EOF for a read error, 0 otherwise. */
|
/* Fill up a read buffer. Returns EOF for a read error, 0 otherwise. */
|
||||||
@ -396,7 +396,7 @@ static int
|
|||||||
shf_fillbuf(struct shf *shf)
|
shf_fillbuf(struct shf *shf)
|
||||||
{
|
{
|
||||||
if (shf->flags & SHF_STRING)
|
if (shf->flags & SHF_STRING)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
if (shf->fd < 0)
|
if (shf->fd < 0)
|
||||||
internal_errorf("shf_fillbuf: no fd");
|
internal_errorf("shf_fillbuf: no fd");
|
||||||
@ -404,11 +404,11 @@ shf_fillbuf(struct shf *shf)
|
|||||||
if (shf->flags & (SHF_EOF | SHF_ERROR)) {
|
if (shf->flags & (SHF_EOF | SHF_ERROR)) {
|
||||||
if (shf->flags & SHF_ERROR)
|
if (shf->flags & SHF_ERROR)
|
||||||
errno = shf->errno_;
|
errno = shf->errno_;
|
||||||
return EOF;
|
return (EOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF)
|
if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF)
|
||||||
return EOF;
|
return (EOF);
|
||||||
|
|
||||||
shf->flags |= SHF_READING;
|
shf->flags |= SHF_READING;
|
||||||
|
|
||||||
@ -427,11 +427,11 @@ shf_fillbuf(struct shf *shf)
|
|||||||
shf->errno_ = errno;
|
shf->errno_ = errno;
|
||||||
shf->rnleft = 0;
|
shf->rnleft = 0;
|
||||||
shf->rp = shf->buf;
|
shf->rp = shf->buf;
|
||||||
return EOF;
|
return (EOF);
|
||||||
}
|
}
|
||||||
shf->flags |= SHF_EOF;
|
shf->flags |= SHF_EOF;
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read a buffer from shf. Returns the number of bytes read into buf,
|
/* Read a buffer from shf. Returns the number of bytes read into buf,
|
||||||
@ -464,8 +464,8 @@ shf_read(char *buf, int bsize, struct shf *shf)
|
|||||||
shf->rnleft -= ncopy;
|
shf->rnleft -= ncopy;
|
||||||
}
|
}
|
||||||
/* Note: fread(3S) returns 0 for errors - this doesn't */
|
/* Note: fread(3S) returns 0 for errors - this doesn't */
|
||||||
return orig_bsize == bsize ? (shf_error(shf) ? EOF : 0) :
|
return (orig_bsize == bsize ? (shf_error(shf) ? EOF : 0) :
|
||||||
orig_bsize - bsize;
|
orig_bsize - bsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read up to a newline or EOF. The newline is put in buf; buf is always
|
/* Read up to a newline or EOF. The newline is put in buf; buf is always
|
||||||
@ -483,16 +483,16 @@ shf_getse(char *buf, int bsize, struct shf *shf)
|
|||||||
internal_errorf("shf_getse: flags %x", shf->flags);
|
internal_errorf("shf_getse: flags %x", shf->flags);
|
||||||
|
|
||||||
if (bsize <= 0)
|
if (bsize <= 0)
|
||||||
return NULL;
|
return (NULL);
|
||||||
|
|
||||||
--bsize; /* save room for null */
|
--bsize; /* save room for null */
|
||||||
do {
|
do {
|
||||||
if (shf->rnleft == 0) {
|
if (shf->rnleft == 0) {
|
||||||
if (shf_fillbuf(shf) == EOF)
|
if (shf_fillbuf(shf) == EOF)
|
||||||
return NULL;
|
return (NULL);
|
||||||
if (shf->rnleft == 0) {
|
if (shf->rnleft == 0) {
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
return buf == orig_buf ? NULL : buf;
|
return (buf == orig_buf ? NULL : buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end = (unsigned char *)memchr((char *) shf->rp, '\n',
|
end = (unsigned char *)memchr((char *) shf->rp, '\n',
|
||||||
@ -507,7 +507,7 @@ shf_getse(char *buf, int bsize, struct shf *shf)
|
|||||||
bsize -= ncopy;
|
bsize -= ncopy;
|
||||||
} while (!end && bsize);
|
} while (!end && bsize);
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
return buf;
|
return (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the char read. Returns EOF for error and end of file. */
|
/* Returns the char read. Returns EOF for error and end of file. */
|
||||||
@ -518,9 +518,9 @@ shf_getchar(struct shf *shf)
|
|||||||
internal_errorf("shf_getchar: flags %x", shf->flags);
|
internal_errorf("shf_getchar: flags %x", shf->flags);
|
||||||
|
|
||||||
if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
|
if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
|
||||||
return EOF;
|
return (EOF);
|
||||||
--shf->rnleft;
|
--shf->rnleft;
|
||||||
return *shf->rp++;
|
return (*shf->rp++);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Put a character back in the input stream. Returns the character if
|
/* Put a character back in the input stream. Returns the character if
|
||||||
@ -534,10 +534,10 @@ shf_ungetc(int c, struct shf *shf)
|
|||||||
|
|
||||||
if ((shf->flags & SHF_ERROR) || c == EOF ||
|
if ((shf->flags & SHF_ERROR) || c == EOF ||
|
||||||
(shf->rp == shf->buf && shf->rnleft))
|
(shf->rp == shf->buf && shf->rnleft))
|
||||||
return EOF;
|
return (EOF);
|
||||||
|
|
||||||
if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF)
|
if ((shf->flags & SHF_WRITING) && shf_emptybuf(shf, EB_READSW) == EOF)
|
||||||
return EOF;
|
return (EOF);
|
||||||
|
|
||||||
if (shf->rp == shf->buf)
|
if (shf->rp == shf->buf)
|
||||||
shf->rp = shf->buf + shf->rbsize;
|
shf->rp = shf->buf + shf->rbsize;
|
||||||
@ -546,16 +546,16 @@ shf_ungetc(int c, struct shf *shf)
|
|||||||
* don't want to modify a string.
|
* don't want to modify a string.
|
||||||
*/
|
*/
|
||||||
if (shf->rp[-1] != c)
|
if (shf->rp[-1] != c)
|
||||||
return EOF;
|
return (EOF);
|
||||||
shf->flags &= ~SHF_EOF;
|
shf->flags &= ~SHF_EOF;
|
||||||
shf->rp--;
|
shf->rp--;
|
||||||
shf->rnleft++;
|
shf->rnleft++;
|
||||||
return c;
|
return (c);
|
||||||
}
|
}
|
||||||
shf->flags &= ~SHF_EOF;
|
shf->flags &= ~SHF_EOF;
|
||||||
*--(shf->rp) = c;
|
*--(shf->rp) = c;
|
||||||
shf->rnleft++;
|
shf->rnleft++;
|
||||||
return c;
|
return (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a character. Returns the character if successful, EOF if
|
/* Write a character. Returns the character if successful, EOF if
|
||||||
@ -568,7 +568,7 @@ shf_putchar(int c, struct shf *shf)
|
|||||||
internal_errorf("shf_putchar: flags %x", shf->flags);
|
internal_errorf("shf_putchar: flags %x", shf->flags);
|
||||||
|
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
return EOF;
|
return (EOF);
|
||||||
|
|
||||||
if (shf->flags & SHF_UNBUF) {
|
if (shf->flags & SHF_UNBUF) {
|
||||||
unsigned char cc = (unsigned char)c;
|
unsigned char cc = (unsigned char)c;
|
||||||
@ -578,7 +578,7 @@ shf_putchar(int c, struct shf *shf)
|
|||||||
internal_errorf("shf_putchar: no fd");
|
internal_errorf("shf_putchar: no fd");
|
||||||
if (shf->flags & SHF_ERROR) {
|
if (shf->flags & SHF_ERROR) {
|
||||||
errno = shf->errno_;
|
errno = shf->errno_;
|
||||||
return EOF;
|
return (EOF);
|
||||||
}
|
}
|
||||||
while ((n = write(shf->fd, &cc, 1)) != 1)
|
while ((n = write(shf->fd, &cc, 1)) != 1)
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
@ -587,17 +587,17 @@ shf_putchar(int c, struct shf *shf)
|
|||||||
continue;
|
continue;
|
||||||
shf->flags |= SHF_ERROR;
|
shf->flags |= SHF_ERROR;
|
||||||
shf->errno_ = errno;
|
shf->errno_ = errno;
|
||||||
return EOF;
|
return (EOF);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Flush deals with strings and sticky errors */
|
/* Flush deals with strings and sticky errors */
|
||||||
if (shf->wnleft == 0 && shf_emptybuf(shf, EB_GROW) == EOF)
|
if (shf->wnleft == 0 && shf_emptybuf(shf, EB_GROW) == EOF)
|
||||||
return EOF;
|
return (EOF);
|
||||||
shf->wnleft--;
|
shf->wnleft--;
|
||||||
*shf->wp++ = c;
|
*shf->wp++ = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a string. Returns the length of the string if successful, EOF if
|
/* Write a string. Returns the length of the string if successful, EOF if
|
||||||
@ -607,9 +607,9 @@ int
|
|||||||
shf_puts(const char *s, struct shf *shf)
|
shf_puts(const char *s, struct shf *shf)
|
||||||
{
|
{
|
||||||
if (!s)
|
if (!s)
|
||||||
return EOF;
|
return (EOF);
|
||||||
|
|
||||||
return shf_write(s, strlen(s), shf);
|
return (shf_write(s, strlen(s), shf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a buffer. Returns nbytes if successful, EOF if there is an error. */
|
/* Write a buffer. Returns nbytes if successful, EOF if there is an error. */
|
||||||
@ -638,7 +638,7 @@ shf_write(const char *buf, int nbytes, struct shf *shf)
|
|||||||
if (nbytes > 0) {
|
if (nbytes > 0) {
|
||||||
/* Flush deals with strings and sticky errors */
|
/* Flush deals with strings and sticky errors */
|
||||||
if (shf_emptybuf(shf, EB_GROW) == EOF)
|
if (shf_emptybuf(shf, EB_GROW) == EOF)
|
||||||
return EOF;
|
return (EOF);
|
||||||
if (nbytes > shf->wbsize) {
|
if (nbytes > shf->wbsize) {
|
||||||
ncopy = nbytes;
|
ncopy = nbytes;
|
||||||
if (shf->wbsize)
|
if (shf->wbsize)
|
||||||
@ -655,7 +655,7 @@ shf_write(const char *buf, int nbytes, struct shf *shf)
|
|||||||
shf->wnleft = 0;
|
shf->wnleft = 0;
|
||||||
/* Note: fwrite(3S) returns 0 for
|
/* Note: fwrite(3S) returns 0 for
|
||||||
* errors - this doesn't */
|
* errors - this doesn't */
|
||||||
return EOF;
|
return (EOF);
|
||||||
}
|
}
|
||||||
buf += n;
|
buf += n;
|
||||||
ncopy -= n;
|
ncopy -= n;
|
||||||
@ -668,7 +668,7 @@ shf_write(const char *buf, int nbytes, struct shf *shf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return orig_nbytes;
|
return (orig_nbytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -681,7 +681,7 @@ shf_fprintf(struct shf *shf, const char *fmt, ...)
|
|||||||
n = shf_vfprintf(shf, fmt, args);
|
n = shf_vfprintf(shf, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
return n;
|
return (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -699,7 +699,7 @@ shf_snprintf(char *buf, int bsize, const char *fmt, ...)
|
|||||||
n = shf_vfprintf(&shf, fmt, args);
|
n = shf_vfprintf(&shf, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
shf_sclose(&shf); /* null terminates */
|
shf_sclose(&shf); /* null terminates */
|
||||||
return n;
|
return (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@ -712,7 +712,7 @@ shf_smprintf(const char *fmt, ...)
|
|||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
shf_vfprintf(&shf, fmt, args);
|
shf_vfprintf(&shf, fmt, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return shf_sclose(&shf); /* null terminates */
|
return (shf_sclose(&shf)); /* null terminates */
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef FP /* if you want floating point stuff */
|
#undef FP /* if you want floating point stuff */
|
||||||
@ -747,12 +747,12 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
|
|||||||
int tmp = 0, field, precision, len, flags;
|
int tmp = 0, field, precision, len, flags;
|
||||||
unsigned long lnum;
|
unsigned long lnum;
|
||||||
/* %#o produces the longest output */
|
/* %#o produces the longest output */
|
||||||
char numbuf[(8 * sizeof (long) + 2) / 3 + 1];
|
char numbuf[(8 * sizeof(long) + 2) / 3 + 1];
|
||||||
/* this stuff for dealing with the buffer */
|
/* this stuff for dealing with the buffer */
|
||||||
int nwritten = 0;
|
int nwritten = 0;
|
||||||
|
|
||||||
if (!fmt)
|
if (!fmt)
|
||||||
return 0;
|
return (0);
|
||||||
|
|
||||||
while ((c = *fmt++)) {
|
while ((c = *fmt++)) {
|
||||||
if (c != '%') {
|
if (c != '%') {
|
||||||
@ -853,7 +853,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
|
|||||||
case 'u':
|
case 'u':
|
||||||
case 'x':
|
case 'x':
|
||||||
flags |= FL_NUMBER;
|
flags |= FL_NUMBER;
|
||||||
cp = numbuf + sizeof (numbuf);
|
cp = numbuf + sizeof(numbuf);
|
||||||
/*-
|
/*-
|
||||||
* XXX any better way to do this?
|
* XXX any better way to do this?
|
||||||
* XXX hopefully the compiler optimises this out
|
* XXX hopefully the compiler optimises this out
|
||||||
@ -865,7 +865,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
|
|||||||
*/
|
*/
|
||||||
if (flags & FL_LONG)
|
if (flags & FL_LONG)
|
||||||
lnum = va_arg(args, unsigned long);
|
lnum = va_arg(args, unsigned long);
|
||||||
else if ((sizeof (int) < sizeof (long)) && (c == 'd'))
|
else if ((sizeof(int) < sizeof(long)) && (c == 'd'))
|
||||||
lnum = (long)va_arg(args, int);
|
lnum = (long)va_arg(args, int);
|
||||||
else
|
else
|
||||||
lnum = va_arg(args, unsigned int);
|
lnum = va_arg(args, unsigned int);
|
||||||
@ -921,7 +921,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
len = numbuf + sizeof (numbuf) - (s = cp);
|
len = numbuf + sizeof(numbuf) - (s = cp);
|
||||||
if (flags & FL_DOT) {
|
if (flags & FL_DOT) {
|
||||||
if (precision > len) {
|
if (precision > len) {
|
||||||
field = precision;
|
field = precision;
|
||||||
@ -1011,7 +1011,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return shf_error(shf) ? EOF : nwritten;
|
return (shf_error(shf) ? EOF : nwritten);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
|
52
syn.c
52
syn.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.35 2009/05/16 16:59:41 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.36 2009/06/08 20:06:49 tg Exp $");
|
||||||
|
|
||||||
struct nesting_state {
|
struct nesting_state {
|
||||||
int start_token; /* token than began nesting (eg, FOR) */
|
int start_token; /* token than began nesting (eg, FOR) */
|
||||||
@ -156,7 +156,7 @@ c_list(int multi)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
REJECT;
|
REJECT;
|
||||||
return t;
|
return (t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct ioword *
|
static struct ioword *
|
||||||
@ -191,7 +191,7 @@ synio(int cf)
|
|||||||
if (iop->flag & IOBASH) {
|
if (iop->flag & IOBASH) {
|
||||||
char *cp;
|
char *cp;
|
||||||
|
|
||||||
nextiop = alloc(sizeof (*iop), ATEMP);
|
nextiop = alloc(sizeof(*iop), ATEMP);
|
||||||
nextiop->name = cp = alloc(5, ATEMP);
|
nextiop->name = cp = alloc(5, ATEMP);
|
||||||
|
|
||||||
if (iop->unit > 9) {
|
if (iop->unit > 9) {
|
||||||
@ -233,7 +233,7 @@ get_command(int cf)
|
|||||||
XPtrV args, vars;
|
XPtrV args, vars;
|
||||||
struct nesting_state old_nesting;
|
struct nesting_state old_nesting;
|
||||||
|
|
||||||
iops = alloc((NUFILE + 1) * sizeof (struct ioword *), ATEMP);
|
iops = alloc((NUFILE + 1) * sizeof(struct ioword *), ATEMP);
|
||||||
XPinit(args, 16);
|
XPinit(args, 16);
|
||||||
XPinit(vars, 16);
|
XPinit(vars, 16);
|
||||||
|
|
||||||
@ -244,7 +244,7 @@ get_command(int cf)
|
|||||||
afree(iops, ATEMP);
|
afree(iops, ATEMP);
|
||||||
XPfree(args);
|
XPfree(args);
|
||||||
XPfree(vars);
|
XPfree(vars);
|
||||||
return NULL; /* empty line */
|
return (NULL); /* empty line */
|
||||||
|
|
||||||
case LWORD:
|
case LWORD:
|
||||||
case REDIR:
|
case REDIR:
|
||||||
@ -464,7 +464,7 @@ get_command(int cf)
|
|||||||
t->ioact = NULL;
|
t->ioact = NULL;
|
||||||
} else {
|
} else {
|
||||||
iops[iopn++] = NULL;
|
iops[iopn++] = NULL;
|
||||||
iops = aresize(iops, iopn * sizeof (struct ioword *), ATEMP);
|
iops = aresize(iops, iopn * sizeof(struct ioword *), ATEMP);
|
||||||
t->ioact = iops;
|
t->ioact = iops;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,7 +478,7 @@ get_command(int cf)
|
|||||||
XPfree(vars);
|
XPfree(vars);
|
||||||
}
|
}
|
||||||
|
|
||||||
return t;
|
return (t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct op *
|
static struct op *
|
||||||
@ -501,7 +501,7 @@ dogroup(void)
|
|||||||
syntaxerr(NULL);
|
syntaxerr(NULL);
|
||||||
list = c_list(true);
|
list = c_list(true);
|
||||||
musthave(c, KEYWORD|ALIAS);
|
musthave(c, KEYWORD|ALIAS);
|
||||||
return list;
|
return (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct op *
|
static struct op *
|
||||||
@ -538,7 +538,7 @@ elsepart(void)
|
|||||||
default:
|
default:
|
||||||
REJECT;
|
REJECT;
|
||||||
}
|
}
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct op *
|
static struct op *
|
||||||
@ -639,20 +639,20 @@ function_body(char *name,
|
|||||||
* be used as input), we pretend there is a colon here.
|
* be used as input), we pretend there is a colon here.
|
||||||
*/
|
*/
|
||||||
t->left = newtp(TCOM);
|
t->left = newtp(TCOM);
|
||||||
t->left->args = alloc(2 * sizeof (char *), ATEMP);
|
t->left->args = alloc(2 * sizeof(char *), ATEMP);
|
||||||
t->left->args[0] = tv = alloc(3, ATEMP);
|
t->left->args[0] = tv = alloc(3, ATEMP);
|
||||||
tv[0] = CHAR;
|
tv[0] = CHAR;
|
||||||
tv[1] = ':';
|
tv[1] = ':';
|
||||||
tv[2] = EOS;
|
tv[2] = EOS;
|
||||||
t->left->args[1] = NULL;
|
t->left->args[1] = NULL;
|
||||||
t->left->vars = alloc(sizeof (char *), ATEMP);
|
t->left->vars = alloc(sizeof(char *), ATEMP);
|
||||||
t->left->vars[0] = NULL;
|
t->left->vars[0] = NULL;
|
||||||
t->left->lineno = 1;
|
t->left->lineno = 1;
|
||||||
}
|
}
|
||||||
if (!old_func_parse)
|
if (!old_func_parse)
|
||||||
e->flags &= ~EF_FUNC_PARSE;
|
e->flags &= ~EF_FUNC_PARSE;
|
||||||
|
|
||||||
return t;
|
return (t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char **
|
static char **
|
||||||
@ -666,7 +666,7 @@ wordlist(void)
|
|||||||
if ((c = token(CONTIN|KEYWORD|ALIAS)) != IN) {
|
if ((c = token(CONTIN|KEYWORD|ALIAS)) != IN) {
|
||||||
if (c != ';') /* non-POSIX, but at&t ksh accepts a ; here */
|
if (c != ';') /* non-POSIX, but at&t ksh accepts a ; here */
|
||||||
REJECT;
|
REJECT;
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
while ((c = token(0)) == LWORD)
|
while ((c = token(0)) == LWORD)
|
||||||
XPput(args, yylval.cp);
|
XPput(args, yylval.cp);
|
||||||
@ -674,10 +674,10 @@ wordlist(void)
|
|||||||
syntaxerr(NULL);
|
syntaxerr(NULL);
|
||||||
if (XPsize(args) == 0) {
|
if (XPsize(args) == 0) {
|
||||||
XPfree(args);
|
XPfree(args);
|
||||||
return NULL;
|
return (NULL);
|
||||||
} else {
|
} else {
|
||||||
XPput(args, NULL);
|
XPput(args, NULL);
|
||||||
return (char **) XPclose(args);
|
return ((char **)XPclose(args));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -822,7 +822,7 @@ newtp(int type)
|
|||||||
{
|
{
|
||||||
struct op *t;
|
struct op *t;
|
||||||
|
|
||||||
t = alloc(sizeof (struct op), ATEMP);
|
t = alloc(sizeof(struct op), ATEMP);
|
||||||
t->type = type;
|
t->type = type;
|
||||||
t->u.evalflags = 0;
|
t->u.evalflags = 0;
|
||||||
t->args = NULL;
|
t->args = NULL;
|
||||||
@ -841,7 +841,7 @@ compile(Source *s)
|
|||||||
herep = heres;
|
herep = heres;
|
||||||
source = s;
|
source = s;
|
||||||
yyparse();
|
yyparse();
|
||||||
return outtree;
|
return (outtree);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This kludge exists to take care of sh/at&t ksh oddity in which
|
/* This kludge exists to take care of sh/at&t ksh oddity in which
|
||||||
@ -858,11 +858,11 @@ static int
|
|||||||
assign_command(char *s)
|
assign_command(char *s)
|
||||||
{
|
{
|
||||||
if (!*s)
|
if (!*s)
|
||||||
return 0;
|
return (0);
|
||||||
return (strcmp(s, "alias") == 0) ||
|
return ((strcmp(s, "alias") == 0) ||
|
||||||
(strcmp(s, "export") == 0) ||
|
(strcmp(s, "export") == 0) ||
|
||||||
(strcmp(s, "readonly") == 0) ||
|
(strcmp(s, "readonly") == 0) ||
|
||||||
(strcmp(s, "typeset") == 0);
|
(strcmp(s, "typeset") == 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we are in the middle of reading an alias */
|
/* Check if we are in the middle of reading an alias */
|
||||||
@ -871,8 +871,8 @@ inalias(struct source *s)
|
|||||||
{
|
{
|
||||||
for (; s && s->type == SALIAS; s = s->next)
|
for (; s && s->type == SALIAS; s = s->next)
|
||||||
if (!(s->flags & SF_ALIASEND))
|
if (!(s->flags & SF_ALIASEND))
|
||||||
return 1;
|
return (1);
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -936,7 +936,7 @@ dbtestp_isa(Test_env *te, Test_meta meta)
|
|||||||
if (save)
|
if (save)
|
||||||
XPput(*te->pos.av, save);
|
XPput(*te->pos.av, save);
|
||||||
}
|
}
|
||||||
return ret;
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
@ -945,12 +945,12 @@ dbtestp_getopnd(Test_env *te, Test_op op __unused, bool do_eval __unused)
|
|||||||
int c = tpeek(ARRAYVAR);
|
int c = tpeek(ARRAYVAR);
|
||||||
|
|
||||||
if (c != LWORD)
|
if (c != LWORD)
|
||||||
return NULL;
|
return (NULL);
|
||||||
|
|
||||||
ACCEPT;
|
ACCEPT;
|
||||||
XPput(*te->pos.av, yylval.cp);
|
XPput(*te->pos.av, yylval.cp);
|
||||||
|
|
||||||
return null;
|
return (null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -958,7 +958,7 @@ dbtestp_eval(Test_env *te __unused, Test_op op __unused,
|
|||||||
const char *opnd1 __unused, const char *opnd2 __unused,
|
const char *opnd1 __unused, const char *opnd2 __unused,
|
||||||
bool do_eval __unused)
|
bool do_eval __unused)
|
||||||
{
|
{
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
22
tree.c
22
tree.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.26 2009/05/16 16:59:41 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.27 2009/06/08 20:06:49 tg Exp $");
|
||||||
|
|
||||||
#define INDENT 4
|
#define INDENT 4
|
||||||
|
|
||||||
@ -440,9 +440,9 @@ tcopy(struct op *t, Area *ap)
|
|||||||
char **rw;
|
char **rw;
|
||||||
|
|
||||||
if (t == NULL)
|
if (t == NULL)
|
||||||
return NULL;
|
return (NULL);
|
||||||
|
|
||||||
r = alloc(sizeof (struct op), ap);
|
r = alloc(sizeof(struct op), ap);
|
||||||
|
|
||||||
r->type = t->type;
|
r->type = t->type;
|
||||||
r->u.evalflags = t->u.evalflags;
|
r->u.evalflags = t->u.evalflags;
|
||||||
@ -458,7 +458,7 @@ tcopy(struct op *t, Area *ap)
|
|||||||
for (tw = (const char **)t->vars; *tw++ != NULL; )
|
for (tw = (const char **)t->vars; *tw++ != NULL; )
|
||||||
;
|
;
|
||||||
rw = r->vars = alloc((tw - (const char **)t->vars + 1) *
|
rw = r->vars = alloc((tw - (const char **)t->vars + 1) *
|
||||||
sizeof (*tw), ap);
|
sizeof(*tw), ap);
|
||||||
for (tw = (const char **)t->vars; *tw != NULL; )
|
for (tw = (const char **)t->vars; *tw != NULL; )
|
||||||
*rw++ = wdcopy(*tw++, ap);
|
*rw++ = wdcopy(*tw++, ap);
|
||||||
*rw = NULL;
|
*rw = NULL;
|
||||||
@ -470,7 +470,7 @@ tcopy(struct op *t, Area *ap)
|
|||||||
for (tw = t->args; *tw++ != NULL; )
|
for (tw = t->args; *tw++ != NULL; )
|
||||||
;
|
;
|
||||||
r->args = (const char **)(rw = alloc((tw - t->args + 1) *
|
r->args = (const char **)(rw = alloc((tw - t->args + 1) *
|
||||||
sizeof (*tw), ap));
|
sizeof(*tw), ap));
|
||||||
for (tw = t->args; *tw != NULL; )
|
for (tw = t->args; *tw != NULL; )
|
||||||
*rw++ = wdcopy(*tw++, ap);
|
*rw++ = wdcopy(*tw++, ap);
|
||||||
*rw = NULL;
|
*rw = NULL;
|
||||||
@ -482,14 +482,14 @@ tcopy(struct op *t, Area *ap)
|
|||||||
r->right = tcopy(t->right, ap);
|
r->right = tcopy(t->right, ap);
|
||||||
r->lineno = t->lineno;
|
r->lineno = t->lineno;
|
||||||
|
|
||||||
return r;
|
return (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
wdcopy(const char *wp, Area *ap)
|
wdcopy(const char *wp, Area *ap)
|
||||||
{
|
{
|
||||||
size_t len = wdscan(wp, EOS) - wp;
|
size_t len = wdscan(wp, EOS) - wp;
|
||||||
return memcpy(alloc(len, ap), wp, len);
|
return (memcpy(alloc(len, ap), wp, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return the position of prefix c in wp plus 1 */
|
/* return the position of prefix c in wp plus 1 */
|
||||||
@ -567,7 +567,7 @@ wdstrip(const char *wp, bool keepq, bool make_magic)
|
|||||||
while (1)
|
while (1)
|
||||||
switch (*wp++) {
|
switch (*wp++) {
|
||||||
case EOS:
|
case EOS:
|
||||||
return shf_sclose(&shf); /* null terminates */
|
return (shf_sclose(&shf)); /* null terminates */
|
||||||
case ADELIM:
|
case ADELIM:
|
||||||
case CHAR:
|
case CHAR:
|
||||||
c = *wp++;
|
c = *wp++;
|
||||||
@ -639,13 +639,13 @@ iocopy(struct ioword **iow, Area *ap)
|
|||||||
|
|
||||||
for (ior = iow; *ior++ != NULL; )
|
for (ior = iow; *ior++ != NULL; )
|
||||||
;
|
;
|
||||||
ior = alloc((ior - iow + 1) * sizeof (struct ioword *), ap);
|
ior = alloc((ior - iow + 1) * sizeof(struct ioword *), ap);
|
||||||
|
|
||||||
for (i = 0; iow[i] != NULL; i++) {
|
for (i = 0; iow[i] != NULL; i++) {
|
||||||
struct ioword *p, *q;
|
struct ioword *p, *q;
|
||||||
|
|
||||||
p = iow[i];
|
p = iow[i];
|
||||||
q = alloc(sizeof (struct ioword), ap);
|
q = alloc(sizeof(struct ioword), ap);
|
||||||
ior[i] = q;
|
ior[i] = q;
|
||||||
*q = *p;
|
*q = *p;
|
||||||
if (p->name != NULL)
|
if (p->name != NULL)
|
||||||
@ -657,7 +657,7 @@ iocopy(struct ioword **iow, Area *ap)
|
|||||||
}
|
}
|
||||||
ior[i] = NULL;
|
ior[i] = NULL;
|
||||||
|
|
||||||
return ior;
|
return (ior);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
80
var.c
80
var.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.72 2009/05/16 16:59:42 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.73 2009/06/08 20:06:50 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables
|
* Variables
|
||||||
@ -57,7 +57,7 @@ newblock(void)
|
|||||||
struct block *l;
|
struct block *l;
|
||||||
static const char *empty[] = { null };
|
static const char *empty[] = { null };
|
||||||
|
|
||||||
l = alloc(sizeof (struct block), ATEMP);
|
l = alloc(sizeof(struct block), ATEMP);
|
||||||
l->flags = 0;
|
l->flags = 0;
|
||||||
ainit(&l->area); /* todo: could use e->area (l->area => l->areap) */
|
ainit(&l->area); /* todo: could use e->area (l->area => l->areap) */
|
||||||
if (!e->loc) {
|
if (!e->loc) {
|
||||||
@ -159,7 +159,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
|
|||||||
*valp = (uint32_t)rval;
|
*valp = (uint32_t)rval;
|
||||||
afree(sub, ATEMP);
|
afree(sub, ATEMP);
|
||||||
}
|
}
|
||||||
return n;
|
return (n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -194,11 +194,11 @@ global(const char *n)
|
|||||||
/* setstr can't fail here */
|
/* setstr can't fail here */
|
||||||
setstr(vp, l->argv[c], KSH_RETURN_ERROR);
|
setstr(vp, l->argv[c], KSH_RETURN_ERROR);
|
||||||
vp->flag |= RDONLY;
|
vp->flag |= RDONLY;
|
||||||
return vp;
|
return (vp);
|
||||||
}
|
}
|
||||||
vp->flag |= RDONLY;
|
vp->flag |= RDONLY;
|
||||||
if (n[1] != '\0')
|
if (n[1] != '\0')
|
||||||
return vp;
|
return (vp);
|
||||||
vp->flag |= ISSET|INTEGER;
|
vp->flag |= ISSET|INTEGER;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '$':
|
case '$':
|
||||||
@ -222,15 +222,15 @@ global(const char *n)
|
|||||||
default:
|
default:
|
||||||
vp->flag &= ~(ISSET|INTEGER);
|
vp->flag &= ~(ISSET|INTEGER);
|
||||||
}
|
}
|
||||||
return vp;
|
return (vp);
|
||||||
}
|
}
|
||||||
for (l = e->loc; ; l = l->next) {
|
for (l = e->loc; ; l = l->next) {
|
||||||
vp = ktsearch(&l->vars, n, h);
|
vp = ktsearch(&l->vars, n, h);
|
||||||
if (vp != NULL) {
|
if (vp != NULL) {
|
||||||
if (array)
|
if (array)
|
||||||
return arraysearch(vp, val);
|
return (arraysearch(vp, val));
|
||||||
else
|
else
|
||||||
return vp;
|
return (vp);
|
||||||
}
|
}
|
||||||
if (l->next == NULL)
|
if (l->next == NULL)
|
||||||
break;
|
break;
|
||||||
@ -241,7 +241,7 @@ global(const char *n)
|
|||||||
vp->flag |= DEFINED;
|
vp->flag |= DEFINED;
|
||||||
if (special(n))
|
if (special(n))
|
||||||
vp->flag |= SPECIAL;
|
vp->flag |= SPECIAL;
|
||||||
return vp;
|
return (vp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -264,7 +264,7 @@ local(const char *n, bool copy)
|
|||||||
vp->flag = DEFINED|RDONLY;
|
vp->flag = DEFINED|RDONLY;
|
||||||
vp->type = 0;
|
vp->type = 0;
|
||||||
vp->areap = ATEMP;
|
vp->areap = ATEMP;
|
||||||
return vp;
|
return (vp);
|
||||||
}
|
}
|
||||||
vp = ktenter(&l->vars, n, h);
|
vp = ktenter(&l->vars, n, h);
|
||||||
if (copy && !(vp->flag & DEFINED)) {
|
if (copy && !(vp->flag & DEFINED)) {
|
||||||
@ -287,7 +287,7 @@ local(const char *n, bool copy)
|
|||||||
vp->flag |= DEFINED;
|
vp->flag |= DEFINED;
|
||||||
if (special(n))
|
if (special(n))
|
||||||
vp->flag |= SPECIAL;
|
vp->flag |= SPECIAL;
|
||||||
return vp;
|
return (vp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get variable string value */
|
/* get variable string value */
|
||||||
@ -305,7 +305,7 @@ str_val(struct tbl *vp)
|
|||||||
else { /* integer source */
|
else { /* integer source */
|
||||||
/* worst case number length is when base=2, so use BITS(long) */
|
/* worst case number length is when base=2, so use BITS(long) */
|
||||||
/* minus base # number NUL */
|
/* minus base # number NUL */
|
||||||
char strbuf[1 + 2 + 1 + 8 * sizeof (mksh_uari_t) + 1];
|
char strbuf[1 + 2 + 1 + 8 * sizeof(mksh_uari_t) + 1];
|
||||||
const char *digits = (vp->flag & UCASEV_AL) ?
|
const char *digits = (vp->flag & UCASEV_AL) ?
|
||||||
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" :
|
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" :
|
||||||
"0123456789abcdefghijklmnopqrstuvwxyz";
|
"0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
@ -349,7 +349,7 @@ str_val(struct tbl *vp)
|
|||||||
else
|
else
|
||||||
strdupx(s, s, ATEMP);
|
strdupx(s, s, ATEMP);
|
||||||
}
|
}
|
||||||
return s;
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get variable integer value, with error checking */
|
/* get variable integer value, with error checking */
|
||||||
@ -378,7 +378,7 @@ setstr(struct tbl *vq, const char *s, int error_ok)
|
|||||||
warningf(true, "%s: is read only", vq->name);
|
warningf(true, "%s: is read only", vq->name);
|
||||||
if (!error_ok)
|
if (!error_ok)
|
||||||
errorfz();
|
errorfz();
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
if (!(vq->flag&INTEGER)) { /* string dest */
|
if (!(vq->flag&INTEGER)) { /* string dest */
|
||||||
if ((vq->flag&ALLOC)) {
|
if ((vq->flag&ALLOC)) {
|
||||||
@ -442,10 +442,10 @@ getint(struct tbl *vp, mksh_ari_t *nump, bool arith)
|
|||||||
getspec(vp);
|
getspec(vp);
|
||||||
/* XXX is it possible for ISSET to be set and val.s to be 0? */
|
/* XXX is it possible for ISSET to be set and val.s to be 0? */
|
||||||
if (!(vp->flag&ISSET) || (!(vp->flag&INTEGER) && vp->val.s == NULL))
|
if (!(vp->flag&ISSET) || (!(vp->flag&INTEGER) && vp->val.s == NULL))
|
||||||
return -1;
|
return (-1);
|
||||||
if (vp->flag&INTEGER) {
|
if (vp->flag&INTEGER) {
|
||||||
*nump = vp->val.i;
|
*nump = vp->val.i;
|
||||||
return vp->type;
|
return (vp->type);
|
||||||
}
|
}
|
||||||
s = vp->val.s + vp->type;
|
s = vp->val.s + vp->type;
|
||||||
if (s == NULL) /* redundant given initial test */
|
if (s == NULL) /* redundant given initial test */
|
||||||
@ -493,15 +493,15 @@ getint(struct tbl *vp, mksh_ari_t *nump, bool arith)
|
|||||||
else if (ksh_isupper(c))
|
else if (ksh_isupper(c))
|
||||||
c -= 'A' - 10;
|
c -= 'A' - 10;
|
||||||
else
|
else
|
||||||
return -1;
|
return (-1);
|
||||||
if (c < 0 || c >= base)
|
if (c < 0 || c >= base)
|
||||||
return -1;
|
return (-1);
|
||||||
num = num * base + c;
|
num = num * base + c;
|
||||||
}
|
}
|
||||||
if (neg)
|
if (neg)
|
||||||
num = -num;
|
num = -num;
|
||||||
*nump = num;
|
*nump = num;
|
||||||
return base;
|
return (base);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* convert variable vq to integer variable, setting its value from vp
|
/* convert variable vq to integer variable, setting its value from vp
|
||||||
@ -514,7 +514,7 @@ setint_v(struct tbl *vq, struct tbl *vp, bool arith)
|
|||||||
mksh_ari_t num;
|
mksh_ari_t num;
|
||||||
|
|
||||||
if ((base = getint(vp, &num, arith)) == -1)
|
if ((base = getint(vp, &num, arith)) == -1)
|
||||||
return NULL;
|
return (NULL);
|
||||||
if (!(vq->flag & INTEGER) && (vq->flag & ALLOC)) {
|
if (!(vq->flag & INTEGER) && (vq->flag & ALLOC)) {
|
||||||
vq->flag &= ~ALLOC;
|
vq->flag &= ~ALLOC;
|
||||||
afree(vq->val.s, vq->areap);
|
afree(vq->val.s, vq->areap);
|
||||||
@ -525,7 +525,7 @@ setint_v(struct tbl *vq, struct tbl *vp, bool arith)
|
|||||||
vq->flag |= ISSET|INTEGER;
|
vq->flag |= ISSET|INTEGER;
|
||||||
if (vq->flag&SPECIAL)
|
if (vq->flag&SPECIAL)
|
||||||
setspec(vq);
|
setspec(vq);
|
||||||
return vq;
|
return (vq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@ -601,7 +601,7 @@ formatstr(struct tbl *vp, const char *s)
|
|||||||
*q = ksh_tolower(*q);
|
*q = ksh_tolower(*q);
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return (p);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -642,13 +642,13 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
|||||||
/* check for valid variable name, search for value */
|
/* check for valid variable name, search for value */
|
||||||
val = skip_varname(var, false);
|
val = skip_varname(var, false);
|
||||||
if (val == var)
|
if (val == var)
|
||||||
return NULL;
|
return (NULL);
|
||||||
if (*val == '[') {
|
if (*val == '[') {
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
len = array_ref_len(val);
|
len = array_ref_len(val);
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return NULL;
|
return (NULL);
|
||||||
/* IMPORT is only used when the shell starts up and is
|
/* IMPORT is only used when the shell starts up and is
|
||||||
* setting up its environment. Allow only simple array
|
* setting up its environment. Allow only simple array
|
||||||
* references at this time since parameter/command substitution
|
* references at this time since parameter/command substitution
|
||||||
@ -659,7 +659,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
|||||||
int i;
|
int i;
|
||||||
for (i = 1; i < len - 1; i++)
|
for (i = 1; i < len - 1; i++)
|
||||||
if (!ksh_isdigit(val[i]))
|
if (!ksh_isdigit(val[i]))
|
||||||
return NULL;
|
return (NULL);
|
||||||
}
|
}
|
||||||
val += len;
|
val += len;
|
||||||
}
|
}
|
||||||
@ -668,7 +668,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
|||||||
else {
|
else {
|
||||||
/* Importing from original environment: must have an = */
|
/* Importing from original environment: must have an = */
|
||||||
if (set & IMPORT)
|
if (set & IMPORT)
|
||||||
return NULL;
|
return (NULL);
|
||||||
strdupx(tvar, var, ATEMP);
|
strdupx(tvar, var, ATEMP);
|
||||||
val = NULL;
|
val = NULL;
|
||||||
}
|
}
|
||||||
@ -772,7 +772,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
|||||||
vpbase->type == 0)
|
vpbase->type == 0)
|
||||||
export(vpbase, (vpbase->flag&ISSET) ? vpbase->val.s : null);
|
export(vpbase, (vpbase->flag&ISSET) ? vpbase->val.s : null);
|
||||||
|
|
||||||
return vp;
|
return (vp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unset a variable. array_ref is set if there was an array reference in
|
/* Unset a variable. array_ref is set if there was an array reference in
|
||||||
@ -858,7 +858,7 @@ is_wdvarname(const char *s, int aok)
|
|||||||
{
|
{
|
||||||
const char *p = skip_wdvarname(s, aok);
|
const char *p = skip_wdvarname(s, aok);
|
||||||
|
|
||||||
return p != s && p[0] == EOS;
|
return (p != s && p[0] == EOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if coded string s is a variable assignment */
|
/* Check if coded string s is a variable assignment */
|
||||||
@ -867,7 +867,7 @@ is_wdvarassign(const char *s)
|
|||||||
{
|
{
|
||||||
const char *p = skip_wdvarname(s, true);
|
const char *p = skip_wdvarname(s, true);
|
||||||
|
|
||||||
return p != s && p[0] == CHAR && p[1] == '=';
|
return (p != s && p[0] == CHAR && p[1] == '=');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -945,10 +945,10 @@ rnd_get(void)
|
|||||||
if (Flag(FARC4RANDOM)) {
|
if (Flag(FARC4RANDOM)) {
|
||||||
if (rnd_cache[0] || rnd_cache[1])
|
if (rnd_cache[0] || rnd_cache[1])
|
||||||
#if HAVE_ARC4RANDOM_PUSHB
|
#if HAVE_ARC4RANDOM_PUSHB
|
||||||
rv = arc4random_pushb(rnd_cache, sizeof (rnd_cache));
|
rv = arc4random_pushb(rnd_cache, sizeof(rnd_cache));
|
||||||
#else
|
#else
|
||||||
arc4random_addrandom((void *)rnd_cache,
|
arc4random_addrandom((void *)rnd_cache,
|
||||||
sizeof (rnd_cache));
|
sizeof(rnd_cache));
|
||||||
#endif
|
#endif
|
||||||
rnd_cache[0] = rnd_cache[1] = 0;
|
rnd_cache[0] = rnd_cache[1] = 0;
|
||||||
return ((
|
return ((
|
||||||
@ -967,9 +967,9 @@ rnd_set(unsigned long newval)
|
|||||||
{
|
{
|
||||||
#if HAVE_ARC4RANDOM && defined(MKSH_SMALL)
|
#if HAVE_ARC4RANDOM && defined(MKSH_SMALL)
|
||||||
#if HAVE_ARC4RANDOM_PUSHB
|
#if HAVE_ARC4RANDOM_PUSHB
|
||||||
arc4random_pushb(&newval, sizeof (newval));
|
arc4random_pushb(&newval, sizeof(newval));
|
||||||
#else
|
#else
|
||||||
arc4random_addrandom((void *)&newval, sizeof (newval));
|
arc4random_addrandom((void *)&newval, sizeof(newval));
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
#if HAVE_ARC4RANDOM
|
#if HAVE_ARC4RANDOM
|
||||||
@ -1027,7 +1027,7 @@ special(const char *name)
|
|||||||
struct tbl *tp;
|
struct tbl *tp;
|
||||||
|
|
||||||
tp = ktsearch(&specials, name, hash(name));
|
tp = ktsearch(&specials, name, hash(name));
|
||||||
return tp && (tp->flag & ISSET) ? tp->type : V_NONE;
|
return (tp && (tp->flag & ISSET) ? tp->type : V_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a variable non-special */
|
/* Make a variable non-special */
|
||||||
@ -1244,7 +1244,7 @@ arraysearch(struct tbl *vp, uint32_t val)
|
|||||||
vp->index = 0;
|
vp->index = 0;
|
||||||
/* The table entry is always [0] */
|
/* The table entry is always [0] */
|
||||||
if (val == 0)
|
if (val == 0)
|
||||||
return vp;
|
return (vp);
|
||||||
prev = vp;
|
prev = vp;
|
||||||
curr = vp->u.array;
|
curr = vp->u.array;
|
||||||
while (curr && curr->index < val) {
|
while (curr && curr->index < val) {
|
||||||
@ -1253,11 +1253,11 @@ arraysearch(struct tbl *vp, uint32_t val)
|
|||||||
}
|
}
|
||||||
if (curr && curr->index == val) {
|
if (curr && curr->index == val) {
|
||||||
if (curr->flag&ISSET)
|
if (curr->flag&ISSET)
|
||||||
return curr;
|
return (curr);
|
||||||
else
|
else
|
||||||
new = curr;
|
new = curr;
|
||||||
} else
|
} else
|
||||||
new = alloc(sizeof (struct tbl) + namelen, vp->areap);
|
new = alloc(sizeof(struct tbl) + namelen, vp->areap);
|
||||||
strlcpy(new->name, vp->name, namelen);
|
strlcpy(new->name, vp->name, namelen);
|
||||||
new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
|
new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
|
||||||
new->type = vp->type;
|
new->type = vp->type;
|
||||||
@ -1268,7 +1268,7 @@ arraysearch(struct tbl *vp, uint32_t val)
|
|||||||
prev->u.array = new;
|
prev->u.array = new;
|
||||||
new->u.array = curr;
|
new->u.array = curr;
|
||||||
}
|
}
|
||||||
return new;
|
return (new);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the length of an array reference (eg, [1+2]) - cp is assumed
|
/* Return the length of an array reference (eg, [1+2]) - cp is assumed
|
||||||
@ -1286,8 +1286,8 @@ array_ref_len(const char *cp)
|
|||||||
if (c == '[')
|
if (c == '[')
|
||||||
depth++;
|
depth++;
|
||||||
if (!c)
|
if (!c)
|
||||||
return 0;
|
return (0);
|
||||||
return s - cp;
|
return (s - cp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user