rework string pooling; disable our own (rely on compiler’s)…
• if HAVE_STRING_POOLING is set to 1 • if HAVE_STRING_POOLING is set to 2 and not GCC < 4 is used • if HAVE_STRING_POOLING is not set to 0 and LLVM or GCC >= 4 is used Closes: LP#1580348
This commit is contained in:
parent
816614d3ce
commit
c3e794c4d0
14
Build.sh
14
Build.sh
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.698 2016/06/25 23:49:12 tg Exp $'
|
||||
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.699 2016/07/25 00:04:35 tg Exp $'
|
||||
#-
|
||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
# 2011, 2012, 2013, 2014, 2015, 2016
|
||||
@ -1114,6 +1114,7 @@ clang)
|
||||
:*) ;;
|
||||
*:) CCC_LD=$CCC_CC; export CCC_LD ;;
|
||||
esac
|
||||
: "${HAVE_STRING_POOLING=i1}"
|
||||
;;
|
||||
dec)
|
||||
vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS -V"
|
||||
@ -1130,6 +1131,7 @@ gcc)
|
||||
vv '|' 'echo `$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN $LIBS \
|
||||
-dumpmachine` gcc`$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN \
|
||||
$LIBS -dumpversion`'
|
||||
: "${HAVE_STRING_POOLING=i2}"
|
||||
;;
|
||||
hpcc)
|
||||
vv '|' "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -V conftest.c $LIBS"
|
||||
@ -1526,6 +1528,16 @@ if test 1 = $i; then
|
||||
ac_flags 1 fwrapv -fwrapv
|
||||
fi
|
||||
|
||||
# “on demand” means: GCC version >= 4
|
||||
fd='if to rely on compiler for string pooling'
|
||||
ac_cache string_pooling || case $HAVE_STRING_POOLING in
|
||||
2) fx=' (on demand, cached)' ;;
|
||||
i1) fv=1 ;;
|
||||
i2) fv=2; fx=' (on demand)' ;;
|
||||
esac
|
||||
ac_testdone
|
||||
ac_cppflags
|
||||
|
||||
phase=x
|
||||
# The following tests run with -Werror or similar (all compilers) if possible
|
||||
NOWARN=$DOWARN
|
||||
|
6
Makefile
6
Makefile
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.148 2016/03/04 18:28:40 tg Exp $
|
||||
# $MirOS: src/bin/mksh/Makefile,v 1.149 2016/07/25 00:04:37 tg Exp $
|
||||
#-
|
||||
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
# 2011, 2012, 2013, 2014, 2015, 2016
|
||||
@ -186,3 +186,7 @@ d: all
|
||||
dr:
|
||||
p=$$(realpath ${PROG:Q}) && cd ${SRCDIR:Q} && exec ${MKSH} \
|
||||
${BSDSRCDIR:Q}/contrib/hosted/tg/sdmksh "$$p"
|
||||
|
||||
repool:
|
||||
cd ${.CURDIR:Q} && \
|
||||
exec ${MKSH} ${BSDSRCDIR:Q}/scripts/stringpool.sh sh.h
|
||||
|
6
check.t
6
check.t
@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.740 2016/07/12 23:07:06 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.741 2016/07/25 00:04:37 tg Exp $
|
||||
# -*- mode: sh -*-
|
||||
#-
|
||||
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
@ -30,7 +30,7 @@
|
||||
# (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date
|
||||
|
||||
expected-stdout:
|
||||
@(#)MIRBSD KSH R52 2016/07/12
|
||||
@(#)MIRBSD KSH R52 2016/07/24
|
||||
description:
|
||||
Check version of shell.
|
||||
stdin:
|
||||
@ -39,7 +39,7 @@ name: KSH_VERSION
|
||||
category: shell:legacy-no
|
||||
---
|
||||
expected-stdout:
|
||||
@(#)LEGACY KSH R52 2016/07/12
|
||||
@(#)LEGACY KSH R52 2016/07/24
|
||||
description:
|
||||
Check version of legacy shell.
|
||||
stdin:
|
||||
|
26
edit.c
26
edit.c
@ -28,7 +28,7 @@
|
||||
|
||||
#ifndef MKSH_NO_CMDLINE_EDITING
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.297 2016/07/12 23:07:09 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.298 2016/07/25 00:04:39 tg Exp $");
|
||||
|
||||
/*
|
||||
* in later versions we might use libtermcap for this, but since external
|
||||
@ -332,7 +332,7 @@ x_glob_hlp_tilde_and_rem_qchar(char *s, bool magic_flag)
|
||||
*--cp = '/';
|
||||
} else {
|
||||
/* ok, expand and replace */
|
||||
cp = shf_smprintf("%s/%s", dp, cp);
|
||||
cp = shf_smprintf(Tf_sSs, dp, cp);
|
||||
if (magic_flag)
|
||||
afree(s, ATEMP);
|
||||
s = cp;
|
||||
@ -471,7 +471,7 @@ x_command_glob(int flags, char *toglob, char ***wordsp)
|
||||
glob_table(pat, &w, &l->funs);
|
||||
|
||||
glob_path(flags, pat, &w, path);
|
||||
if ((fpath = str_val(global("FPATH"))) != null)
|
||||
if ((fpath = str_val(global(TFPATH))) != null)
|
||||
glob_path(flags, pat, &w, fpath);
|
||||
|
||||
nwords = XPsize(w);
|
||||
@ -1662,7 +1662,7 @@ x_zotc3(char **cp)
|
||||
|
||||
if (c == '\t') {
|
||||
/* Kludge, tabs are always four spaces. */
|
||||
x_e_puts(" ");
|
||||
x_e_puts(T4spaces);
|
||||
(*cp)++;
|
||||
} else if (ISCTRL(c) && /* but not C1 */ c < 0x80) {
|
||||
x_e_putc2('^');
|
||||
@ -2443,7 +2443,7 @@ x_print(int prefix, int key)
|
||||
shprintf("%s%s = ", x_mapout(key), (f & 0x80) ? "~" : "");
|
||||
if (XFUNC_VALUE(f) != XFUNC_ins_string)
|
||||
#endif
|
||||
shprintf("%s\n", x_ftab[XFUNC_VALUE(f)].xf_name);
|
||||
shprintf(Tf_sN, x_ftab[XFUNC_VALUE(f)].xf_name);
|
||||
#ifndef MKSH_SMALL
|
||||
else
|
||||
shprintf("'%s'\n", x_atab[prefix][key]);
|
||||
@ -2475,7 +2475,7 @@ x_bind(const char *a1, const char *a2,
|
||||
if (list) {
|
||||
for (f = 0; f < NELEM(x_ftab); f++)
|
||||
if (!(x_ftab[f].xf_flags & XF_NOBIND))
|
||||
shprintf("%s\n", x_ftab[f].xf_name);
|
||||
shprintf(Tf_sN, x_ftab[f].xf_name);
|
||||
return (0);
|
||||
}
|
||||
if (a1 == NULL) {
|
||||
@ -2709,7 +2709,7 @@ x_expand(int c MKSH_A_UNUSED)
|
||||
i = 0;
|
||||
while (i < nwords) {
|
||||
if (x_escape(words[i], strlen(words[i]), x_do_ins) < 0 ||
|
||||
(++i < nwords && x_ins(" ") < 0)) {
|
||||
(++i < nwords && x_ins(T1space) < 0)) {
|
||||
x_e_putc2(7);
|
||||
return (KSTD);
|
||||
}
|
||||
@ -2794,7 +2794,7 @@ do_complete(
|
||||
*/
|
||||
if (nwords == 1 && words[0][nlen - 1] != '/' &&
|
||||
!(flags & XCF_IS_NOSPACE)) {
|
||||
x_ins(" ");
|
||||
x_ins(T1space);
|
||||
}
|
||||
|
||||
x_free_words(nwords, words);
|
||||
@ -3083,7 +3083,7 @@ x_edit_line(int c MKSH_A_UNUSED)
|
||||
x_arg = source->line - (histptr - x_histp);
|
||||
}
|
||||
if (x_arg)
|
||||
shf_snprintf(xbuf, xend - xbuf, "%s %d",
|
||||
shf_snprintf(xbuf, xend - xbuf, Tf_sd,
|
||||
"fc -e ${VISUAL:-${EDITOR:-vi}} --", x_arg);
|
||||
else
|
||||
strlcpy(xbuf, "fc -e ${VISUAL:-${EDITOR:-vi}} --", xend - xbuf);
|
||||
@ -4371,7 +4371,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
(hlast - hnum);
|
||||
}
|
||||
if (argcnt)
|
||||
shf_snprintf(es->cbuf, es->cbufsize, "%s %d",
|
||||
shf_snprintf(es->cbuf, es->cbufsize, Tf_sd,
|
||||
"fc -e ${VISUAL:-${EDITOR:-vi}} --",
|
||||
argcnt);
|
||||
else
|
||||
@ -4500,7 +4500,7 @@ vi_cmd(int argcnt, const char *cmd)
|
||||
argcnt++;
|
||||
p++;
|
||||
}
|
||||
if (putbuf(" ", 1, false) != 0 ||
|
||||
if (putbuf(T1space, 1, false) != 0 ||
|
||||
putbuf(sp, argcnt, false) != 0) {
|
||||
if (es->cursor != 0)
|
||||
es->cursor--;
|
||||
@ -5318,7 +5318,7 @@ expand_word(int cmd)
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
if (++i < nwords && putbuf(" ", 1, false) != 0) {
|
||||
if (++i < nwords && putbuf(T1space, 1, false) != 0) {
|
||||
rval = -1;
|
||||
break;
|
||||
}
|
||||
@ -5436,7 +5436,7 @@ complete_word(int cmd, int count)
|
||||
*/
|
||||
if (match_len > 0 && match[match_len - 1] != '/' &&
|
||||
!(flags & XCF_IS_NOSPACE))
|
||||
rval = putbuf(" ", 1, false);
|
||||
rval = putbuf(T1space, 1, false);
|
||||
}
|
||||
x_free_words(nwords, words);
|
||||
|
||||
|
36
eval.c
36
eval.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.190 2016/07/24 23:05:52 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.191 2016/07/25 00:04:41 tg Exp $");
|
||||
|
||||
/*
|
||||
* string expansion
|
||||
@ -381,9 +381,9 @@ expand(
|
||||
/* ({) the } or x is already skipped */
|
||||
if (end < wdscan(beg, EOS))
|
||||
*end = EOS;
|
||||
str = snptreef(NULL, 64, "%S", beg);
|
||||
str = snptreef(NULL, 64, Tf_S, beg);
|
||||
afree(beg, ATEMP);
|
||||
errorf("%s: %s", str, Tbadsubst);
|
||||
errorf(Tf_sD_s, str, Tbadsubst);
|
||||
}
|
||||
if (f & DOBLANK)
|
||||
doblank++;
|
||||
@ -568,7 +568,7 @@ expand(
|
||||
p--;
|
||||
}
|
||||
strndupx(end, s, sbeg - s, ATEMP);
|
||||
d = shf_smprintf("%s%s%s", end, rrep, p);
|
||||
d = shf_smprintf(Tf_sss, end, rrep, p);
|
||||
afree(end, ATEMP);
|
||||
sbeg = d + (sbeg - s) + strlen(rrep);
|
||||
afree(s, ATEMP);
|
||||
@ -729,7 +729,7 @@ expand(
|
||||
case '?':
|
||||
dp = Xrestpos(ds, dp, st->base);
|
||||
|
||||
errorf("%s: %s", st->var->name,
|
||||
errorf(Tf_sD_s, st->var->name,
|
||||
debunk(dp, dp, strlen(dp) + 1));
|
||||
break;
|
||||
case '0':
|
||||
@ -1134,10 +1134,10 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
}
|
||||
}
|
||||
if (Flag(FNOUNSET) && c == 0 && !zero_ok)
|
||||
errorf("%s: parameter not set", sp);
|
||||
errorf(Tf_parm, sp);
|
||||
/* unqualified variable/string substitution */
|
||||
*stypep = 0;
|
||||
xp->str = shf_smprintf("%d", c);
|
||||
xp->str = shf_smprintf(Tf_d, c);
|
||||
return (XSUB);
|
||||
}
|
||||
if (stype == '!' && c != '\0' && *word == CSUBST) {
|
||||
@ -1249,7 +1249,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
for (; vp; vp = vp->u.array) {
|
||||
if (!(vp->flag&ISSET))
|
||||
continue;
|
||||
XPput(wv, c == '!' ? shf_smprintf("%lu",
|
||||
XPput(wv, c == '!' ? shf_smprintf(Tf_lu,
|
||||
arrayindex(vp)) :
|
||||
str_val(vp));
|
||||
}
|
||||
@ -1288,7 +1288,7 @@ varsub(Expand *xp, const char *sp, const char *word,
|
||||
state = XBASE;
|
||||
if (Flag(FNOUNSET) && xp->str == null && !zero_ok &&
|
||||
(ctype(c, C_SUBOP2) || (state != XBASE && c != '+')))
|
||||
errorf("%s: parameter not set", sp);
|
||||
errorf(Tf_parm, sp);
|
||||
*stypep = stype;
|
||||
*slenp = slen;
|
||||
return (state);
|
||||
@ -1331,8 +1331,8 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
|
||||
shf = shf_open(name = evalstr(io->ioname, DOTILDE),
|
||||
O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
|
||||
if (shf == NULL)
|
||||
warningf(!Flag(FTALKING), "%s: %s %s: %s",
|
||||
name, "can't open", "$(<...) input",
|
||||
warningf(!Flag(FTALKING), Tf_sD_s_sD_s,
|
||||
name, Tcant_open, "$(<...) input",
|
||||
cstrerror(errno));
|
||||
break;
|
||||
case IOHERE:
|
||||
@ -1348,8 +1348,8 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
|
||||
shf = NULL;
|
||||
break;
|
||||
default:
|
||||
errorf("%s: %s", T_funny_command,
|
||||
snptreef(NULL, 32, "%R", io));
|
||||
errorf(Tf_sD_s, T_funny_command,
|
||||
snptreef(NULL, 32, Tft_R, io));
|
||||
}
|
||||
} else if (fn == FUNSUB) {
|
||||
int ofd1;
|
||||
@ -1361,8 +1361,8 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
|
||||
*/
|
||||
maketemp(ATEMP, TT_FUNSUB, &tf);
|
||||
if (!tf->shf) {
|
||||
errorf("can't %s temporary file %s: %s",
|
||||
"create", tf->tffn, cstrerror(errno));
|
||||
errorf(Tf_temp,
|
||||
Tcreate, tf->tffn, cstrerror(errno));
|
||||
}
|
||||
/* extract shf from temporary file, unlink and free it */
|
||||
shf = tf->shf;
|
||||
@ -1612,7 +1612,7 @@ globit(XString *xs, /* dest string */
|
||||
/* xp = *xpp; copy_non_glob() may have re-alloc'd xs */
|
||||
*xp = '\0';
|
||||
prefix_len = Xlength(*xs, xp);
|
||||
dirp = opendir(prefix_len ? Xstring(*xs, xp) : ".");
|
||||
dirp = opendir(prefix_len ? Xstring(*xs, xp) : Tdot);
|
||||
if (dirp == NULL)
|
||||
goto Nodir;
|
||||
while ((d = readdir(dirp)) != NULL) {
|
||||
@ -1725,9 +1725,9 @@ do_tilde(char *cp)
|
||||
if (cp[0] == '\0')
|
||||
dp = str_val(global("HOME"));
|
||||
else if (cp[0] == '+' && cp[1] == '\0')
|
||||
dp = str_val(global("PWD"));
|
||||
dp = str_val(global(TPWD));
|
||||
else if (ksh_isdash(cp))
|
||||
dp = str_val(global("OLDPWD"));
|
||||
dp = str_val(global(TOLDPWD));
|
||||
#ifndef MKSH_NOPWNAM
|
||||
else {
|
||||
dp = homedir(cp);
|
||||
|
65
exec.c
65
exec.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.177 2016/07/24 23:10:02 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.178 2016/07/25 00:04:41 tg Exp $");
|
||||
|
||||
#ifndef MKSH_DEFAULT_EXECSHELL
|
||||
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
|
||||
@ -107,7 +107,7 @@ execute(struct op * volatile t,
|
||||
|
||||
if ((rv = herein(t->ioact[0], &cp) /*? 1 : 0*/))
|
||||
cp = NULL;
|
||||
dp = shf_smprintf("%s%s", evalstr(t->vars[0],
|
||||
dp = shf_smprintf(Tf_ss, evalstr(t->vars[0],
|
||||
DOASNTILDE | DOSCALAR), rv ? null : cp);
|
||||
typeset(dp, Flag(FEXPORT) ? EXPORT : 0, 0, 0, 0);
|
||||
/* free the expanded value */
|
||||
@ -441,7 +441,7 @@ execute(struct op * volatile t,
|
||||
if (rv == ENOEXEC)
|
||||
scriptexec(t, (const char **)up);
|
||||
else
|
||||
errorf("%s: %s", t->str, cstrerror(rv));
|
||||
errorf(Tf_sD_s, t->str, cstrerror(rv));
|
||||
}
|
||||
Break:
|
||||
exstat = rv & 0xFF;
|
||||
@ -532,7 +532,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
break;
|
||||
}
|
||||
if ((tp = findcom(cp, FC_BI)) == NULL)
|
||||
errorf("%s: %s: %s", Tbuiltin, cp, "not a builtin");
|
||||
errorf(Tf_sD_sD_s, Tbuiltin, cp, Tnot_found);
|
||||
if (tp->type == CSHELL && (tp->flag & LOW_BI))
|
||||
break;
|
||||
continue;
|
||||
@ -573,7 +573,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
fcflags = FC_BI|FC_PATH;
|
||||
if (saw_p) {
|
||||
if (Flag(FRESTRICTED)) {
|
||||
warningf(true, "%s: %s",
|
||||
warningf(true, Tf_sD_s,
|
||||
"command -p", "restricted");
|
||||
rv = 1;
|
||||
goto Leave;
|
||||
@ -674,7 +674,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
goto Leave;
|
||||
} else if (!tp) {
|
||||
if (Flag(FRESTRICTED) && vstrchr(cp, '/')) {
|
||||
warningf(true, "%s: %s", cp, "restricted");
|
||||
warningf(true, Tf_sD_s, cp, "restricted");
|
||||
rv = 1;
|
||||
goto Leave;
|
||||
}
|
||||
@ -705,8 +705,8 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
if (!tp->u.fpath) {
|
||||
fpath_error:
|
||||
rv = (tp->u2.errnov == ENOENT) ? 127 : 126;
|
||||
warningf(true, "%s: %s %s: %s", cp,
|
||||
"can't find", "function definition file",
|
||||
warningf(true, Tf_sD_s_sD_s, cp,
|
||||
Tcant_find, Tfile_fd,
|
||||
cstrerror(tp->u2.errnov));
|
||||
break;
|
||||
}
|
||||
@ -726,7 +726,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
cp = tp->u.fpath;
|
||||
goto fpath_error;
|
||||
}
|
||||
warningf(true, "%s: %s %s", cp,
|
||||
warningf(true, Tf_sD_s_s, cp,
|
||||
"function not defined by", tp->u.fpath);
|
||||
rv = 127;
|
||||
break;
|
||||
@ -807,7 +807,7 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
/* NOTREACHED */
|
||||
default:
|
||||
quitenv(NULL);
|
||||
internal_errorf("%s %d", "CFUNC", i);
|
||||
internal_errorf(Tf_sd, "CFUNC", i);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -819,10 +819,10 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
|
||||
if (!(tp->flag&ISSET)) {
|
||||
if (tp->u2.errnov == ENOENT) {
|
||||
rv = 127;
|
||||
warningf(true, "%s: %s", cp, "not found");
|
||||
warningf(true, Tf_sD_s, cp, Tnot_found);
|
||||
} else {
|
||||
rv = 126;
|
||||
warningf(true, "%s: %s: %s", cp, "can't execute",
|
||||
warningf(true, Tf_sD_sD_s, cp, "can't execute",
|
||||
cstrerror(tp->u2.errnov));
|
||||
}
|
||||
break;
|
||||
@ -876,7 +876,7 @@ scriptexec(struct op *tp, const char **ap)
|
||||
#endif
|
||||
union mksh_ccphack args, cap;
|
||||
|
||||
sh = str_val(global("EXECSHELL"));
|
||||
sh = str_val(global(TEXECSHELL));
|
||||
if (sh && *sh)
|
||||
sh = search_path(sh, path, X_OK, NULL);
|
||||
if (!sh || !*sh)
|
||||
@ -976,7 +976,7 @@ scriptexec(struct op *tp, const char **ap)
|
||||
execve(args.rw[0], args.rw, cap.rw);
|
||||
|
||||
/* report both the programme that was run and the bogus interpreter */
|
||||
errorf("%s: %s: %s", tp->str, sh, cstrerror(errno));
|
||||
errorf(Tf_sD_sD_s, tp->str, sh, cstrerror(errno));
|
||||
}
|
||||
|
||||
int
|
||||
@ -1140,7 +1140,7 @@ findcom(const char *name, int flags)
|
||||
if (!tp && (flags & FC_FUNC)) {
|
||||
tp = findfunc(name, h, false);
|
||||
if (tp && !(tp->flag & ISSET)) {
|
||||
if ((fpath = str_val(global("FPATH"))) == null) {
|
||||
if ((fpath = str_val(global(TFPATH))) == null) {
|
||||
tp->u.fpath = NULL;
|
||||
tp->u2.errnov = ENOENT;
|
||||
} else
|
||||
@ -1185,7 +1185,7 @@ findcom(const char *name, int flags)
|
||||
afree(npath.rw, ATEMP);
|
||||
tp->flag |= ISSET|ALLOC;
|
||||
} else if ((flags & FC_FUNC) &&
|
||||
(fpath = str_val(global("FPATH"))) != null &&
|
||||
(fpath = str_val(global(TFPATH))) != null &&
|
||||
(npath.ro = search_path(name, fpath, R_OK,
|
||||
&tp->u2.errnov)) != NULL) {
|
||||
/*
|
||||
@ -1314,7 +1314,7 @@ call_builtin(struct tbl *tp, const char **wp, const char *where, bool resetspec)
|
||||
int rv;
|
||||
|
||||
if (!tp)
|
||||
internal_errorf("%s: %s", where, wp[0]);
|
||||
internal_errorf(Tf_sD_s, where, wp[0]);
|
||||
builtin_argv0 = wp[0];
|
||||
builtin_spec = tobool(!resetspec &&
|
||||
/*XXX odd use of KEEPASN */
|
||||
@ -1354,7 +1354,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
||||
|
||||
if (Flag(FXTRACE)) {
|
||||
change_xtrace(2, false);
|
||||
fptreef(shl_xtrace, 0, "%R", &iotmp);
|
||||
fptreef(shl_xtrace, 0, Tft_R, &iotmp);
|
||||
change_xtrace(1, false);
|
||||
}
|
||||
|
||||
@ -1415,8 +1415,8 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
||||
&emsg)) < 0) {
|
||||
char *sp;
|
||||
|
||||
warningf(true, "%s: %s",
|
||||
(sp = snptreef(NULL, 32, "%R", &iotmp)), emsg);
|
||||
warningf(true, Tf_sD_s,
|
||||
(sp = snptreef(NULL, 32, Tft_R, &iotmp)), emsg);
|
||||
afree(sp, ATEMP);
|
||||
return (-1);
|
||||
}
|
||||
@ -1429,7 +1429,7 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
||||
|
||||
if (do_open) {
|
||||
if (Flag(FRESTRICTED) && (flags & O_CREAT)) {
|
||||
warningf(true, "%s: %s", cp, "restricted");
|
||||
warningf(true, Tf_sD_s, cp, "restricted");
|
||||
return (-1);
|
||||
}
|
||||
u = binopen3(cp, flags, 0666);
|
||||
@ -1447,10 +1447,10 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
||||
/* herein() may already have printed message */
|
||||
if (u == -1) {
|
||||
u = errno;
|
||||
warningf(true, "can't %s %s: %s",
|
||||
warningf(true, Tf_cant,
|
||||
iotype == IODUP ? "dup" :
|
||||
(iotype == IOREAD || iotype == IOHERE) ?
|
||||
"open" : "create", cp, cstrerror(u));
|
||||
Topen : Tcreate, cp, cstrerror(u));
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
@ -1478,9 +1478,8 @@ iosetup(struct ioword *iop, struct tbl *tp)
|
||||
char *sp;
|
||||
|
||||
eno = errno;
|
||||
warningf(true, "%s %s: %s",
|
||||
"can't finish (dup) redirection",
|
||||
(sp = snptreef(NULL, 32, "%R", &iotmp)),
|
||||
warningf(true, Tf_s_sD_s, Tredirection_dup,
|
||||
(sp = snptreef(NULL, 32, Tft_R, &iotmp)),
|
||||
cstrerror(eno));
|
||||
afree(sp, ATEMP);
|
||||
if (iotype != IODUP)
|
||||
@ -1571,8 +1570,8 @@ herein(struct ioword *iop, char **resbuf)
|
||||
h = maketemp(ATEMP, TT_HEREDOC_EXP, &e->temps);
|
||||
if (!(shf = h->shf) || (fd = binopen3(h->tffn, O_RDONLY, 0)) < 0) {
|
||||
i = errno;
|
||||
warningf(true, "can't %s temporary file %s: %s",
|
||||
!shf ? "create" : "open", h->tffn, cstrerror(i));
|
||||
warningf(true, Tf_temp,
|
||||
!shf ? Tcreate : Topen, h->tffn, cstrerror(i));
|
||||
if (shf)
|
||||
shf_close(shf);
|
||||
/* special to iosetup(): don't print error */
|
||||
@ -1588,8 +1587,8 @@ herein(struct ioword *iop, char **resbuf)
|
||||
if (shf_close(shf) == -1) {
|
||||
i = errno;
|
||||
close(fd);
|
||||
warningf(true, "can't %s temporary file %s: %s",
|
||||
"write", h->tffn, cstrerror(i));
|
||||
warningf(true, Tf_temp,
|
||||
Twrite, h->tffn, cstrerror(i));
|
||||
/* special to iosetup(): don't print error */
|
||||
return (-2);
|
||||
}
|
||||
@ -1605,7 +1604,7 @@ static const char *
|
||||
do_selectargs(const char **ap, bool print_menu)
|
||||
{
|
||||
static const char *read_args[] = {
|
||||
"read", "-r", "REPLY", NULL
|
||||
Tread, "-r", "REPLY", NULL
|
||||
};
|
||||
char *s;
|
||||
int i, argct;
|
||||
@ -1621,8 +1620,8 @@ do_selectargs(const char **ap, bool print_menu)
|
||||
*/
|
||||
if (print_menu || !*str_val(global("REPLY")))
|
||||
pr_menu(ap);
|
||||
shellf("%s", str_val(global("PS3")));
|
||||
if (call_builtin(findcom("read", FC_BI), read_args, Tselect,
|
||||
shellf(Tf_s, str_val(global("PS3")));
|
||||
if (call_builtin(findcom(Tread, FC_BI), read_args, Tselect,
|
||||
false))
|
||||
return (NULL);
|
||||
if (*(s = str_val(global("REPLY"))))
|
||||
|
16
expr.c
16
expr.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.85 2016/05/05 22:56:13 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.86 2016/07/25 00:04:42 tg Exp $");
|
||||
|
||||
/* the order of these enums is constrained by the order of opinfo[] */
|
||||
enum token {
|
||||
@ -274,33 +274,33 @@ evalerr(Expr_state *es, enum error_type type, const char *str)
|
||||
default:
|
||||
s = opinfo[(int)es->tok].name;
|
||||
}
|
||||
warningf(true, "%s: %s '%s'", es->expression,
|
||||
"unexpected", s);
|
||||
warningf(true, Tf_sD_s_qs, es->expression,
|
||||
Tunexpected, s);
|
||||
break;
|
||||
|
||||
case ET_BADLIT:
|
||||
warningf(true, "%s: %s '%s'", es->expression,
|
||||
warningf(true, Tf_sD_s_qs, es->expression,
|
||||
"bad number", str);
|
||||
break;
|
||||
|
||||
case ET_RECURSIVE:
|
||||
warningf(true, "%s: %s '%s'", es->expression,
|
||||
warningf(true, Tf_sD_s_qs, es->expression,
|
||||
"expression recurses on parameter", str);
|
||||
break;
|
||||
|
||||
case ET_LVALUE:
|
||||
warningf(true, "%s: %s %s",
|
||||
warningf(true, Tf_sD_s_s,
|
||||
es->expression, str, "requires lvalue");
|
||||
break;
|
||||
|
||||
case ET_RDONLY:
|
||||
warningf(true, "%s: %s %s",
|
||||
warningf(true, Tf_sD_s_s,
|
||||
es->expression, str, "applied to read-only variable");
|
||||
break;
|
||||
|
||||
default: /* keep gcc happy */
|
||||
case ET_STR:
|
||||
warningf(true, "%s: %s", es->expression, str);
|
||||
warningf(true, Tf_sD_s, es->expression, str);
|
||||
break;
|
||||
}
|
||||
unwind(LAEXPR);
|
||||
|
201
funcs.c
201
funcs.c
@ -38,7 +38,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.299 2016/07/24 23:11:50 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.300 2016/07/25 00:04:42 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
/*
|
||||
@ -73,7 +73,7 @@ bi_getn(const char *as, int *ai)
|
||||
int rv;
|
||||
|
||||
if (!(rv = getn(as, ai)))
|
||||
bi_errorf("%s: %s", as, "bad number");
|
||||
bi_errorf(Tf_sD_s, as, "bad number");
|
||||
return (rv);
|
||||
}
|
||||
|
||||
@ -94,15 +94,15 @@ c_false(const char **wp MKSH_A_UNUSED)
|
||||
* A leading * means a POSIX special builtin.
|
||||
*/
|
||||
const struct builtin mkshbuiltins[] = {
|
||||
{"*=.", c_dot},
|
||||
{Tsgdot, c_dot},
|
||||
{"*=:", c_true},
|
||||
{"[", c_test},
|
||||
{Tbracket, c_test},
|
||||
/* no =: AT&T manual wrong */
|
||||
{Talias, c_alias},
|
||||
{"*=break", c_brkcont},
|
||||
{Tgbuiltin, c_builtin},
|
||||
{"!cat", c_cat},
|
||||
{"cd", c_cd},
|
||||
{Tbcat, c_cat},
|
||||
{Tcd, c_cd},
|
||||
/* dash compatibility hack */
|
||||
{"chdir", c_cd},
|
||||
{Tcommand, c_command},
|
||||
@ -112,32 +112,32 @@ const struct builtin mkshbuiltins[] = {
|
||||
{"*=exec", c_exec},
|
||||
{"*=exit", c_exitreturn},
|
||||
{Tsgexport, c_typeset},
|
||||
{"false", c_false},
|
||||
{Tfalse, c_false},
|
||||
{"fc", c_fc},
|
||||
{"getopts", c_getopts},
|
||||
{Tgetopts, c_getopts},
|
||||
{"=global", c_typeset},
|
||||
{"jobs", c_jobs},
|
||||
{Tjobs, c_jobs},
|
||||
{"kill", c_kill},
|
||||
{"let", c_let},
|
||||
{"let]", c_let},
|
||||
{"print", c_print},
|
||||
{"pwd", c_pwd},
|
||||
{"read", c_read},
|
||||
{Tread, c_read},
|
||||
{Tsgreadonly, c_typeset},
|
||||
{"!realpath", c_realpath},
|
||||
{"rename", c_rename},
|
||||
{Trename, c_rename},
|
||||
{"*=return", c_exitreturn},
|
||||
{Tsgset, c_set},
|
||||
{"*=shift", c_shift},
|
||||
{"=source", c_dot},
|
||||
#if !defined(MKSH_UNEMPLOYED) && HAVE_GETSID
|
||||
{"suspend", c_suspend},
|
||||
{Tsuspend, c_suspend},
|
||||
#endif
|
||||
{"test", c_test},
|
||||
{"*=times", c_times},
|
||||
{"*=trap", c_trap},
|
||||
{"true", c_true},
|
||||
{T_typeset, c_typeset},
|
||||
{Ttrue, c_true},
|
||||
{Tgtypeset, c_typeset},
|
||||
{"ulimit", c_ulimit},
|
||||
{"umask", c_umask},
|
||||
{Tunalias, c_unalias},
|
||||
@ -145,8 +145,8 @@ const struct builtin mkshbuiltins[] = {
|
||||
{"=wait", c_wait},
|
||||
{"whence", c_whence},
|
||||
#ifndef MKSH_UNEMPLOYED
|
||||
{"bg", c_fgbg},
|
||||
{"fg", c_fgbg},
|
||||
{Tbg, c_fgbg},
|
||||
{Tfg, c_fgbg},
|
||||
#endif
|
||||
#ifndef MKSH_NO_CMDLINE_EDITING
|
||||
{"bind", c_bind},
|
||||
@ -255,7 +255,7 @@ c_pwd(const char **wp)
|
||||
wp += builtin_opt.optind;
|
||||
|
||||
if (wp[0]) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
p = current_wd[0] ? (physical ? allocd = do_realpath(current_wd) :
|
||||
@ -264,11 +264,11 @@ c_pwd(const char **wp)
|
||||
if (p && access(p, R_OK) < 0)
|
||||
p = NULL;
|
||||
if (!p && !(p = allocd = ksh_get_wd())) {
|
||||
bi_errorf("%s: %s", "can't determine current directory",
|
||||
bi_errorf(Tf_sD_s, "can't determine current directory",
|
||||
cstrerror(errno));
|
||||
return (1);
|
||||
}
|
||||
shprintf("%s\n", p);
|
||||
shprintf(Tf_sN, p);
|
||||
afree(allocd, ATEMP);
|
||||
return (0);
|
||||
}
|
||||
@ -367,7 +367,7 @@ c_print(const char **wp)
|
||||
break;
|
||||
case 'p':
|
||||
if ((fd = coproc_getfd(W_OK, &emsg)) < 0) {
|
||||
bi_errorf("-p: %s", emsg);
|
||||
bi_errorf(Tf_coproc, emsg);
|
||||
return (1);
|
||||
}
|
||||
break;
|
||||
@ -519,7 +519,7 @@ c_whence(const char **wp)
|
||||
int optc;
|
||||
bool pflag = false, vflag = false;
|
||||
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, "pv")) != -1)
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, Tpv)) != -1)
|
||||
switch (optc) {
|
||||
case 'p':
|
||||
pflag = true;
|
||||
@ -543,8 +543,7 @@ c_command(const char **wp)
|
||||
int optc, fcflags = FC_BI | FC_FUNC | FC_PATH | FC_WHENCE;
|
||||
bool vflag = false;
|
||||
|
||||
/* options not sorted to facilitate string pooling */
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, "Vpv")) != -1)
|
||||
while ((optc = ksh_getopt(wp, &builtin_opt, TpVv)) != -1)
|
||||
switch (optc) {
|
||||
case 'p':
|
||||
fcflags |= FC_DEFPATH;
|
||||
@ -630,7 +629,7 @@ do_whence(const char **wp, int fcflags, bool vflag, bool iscommand)
|
||||
shf_puts(tp->val.s, shl_stdout);
|
||||
} else {
|
||||
if (vflag)
|
||||
shprintf("%s not found", id);
|
||||
shprintf(Tnot_found_s, id);
|
||||
rv = 1;
|
||||
}
|
||||
break;
|
||||
@ -795,7 +794,7 @@ c_typeset(const char **wp)
|
||||
return (1);
|
||||
if (basestr) {
|
||||
if (!getn(basestr, &base)) {
|
||||
bi_errorf("%s: %s", "bad integer base", basestr);
|
||||
bi_errorf(Tf_sD_s, "bad integer base", basestr);
|
||||
return (1);
|
||||
}
|
||||
if (base < 1 || base > 36)
|
||||
@ -878,7 +877,7 @@ c_typeset(const char **wp)
|
||||
shf_putc('\n', shl_stdout);
|
||||
}
|
||||
} else if (!typeset(wp[i], fset, fclr, field, base)) {
|
||||
bi_errorf("%s: %s", wp[i], "is not an identifier");
|
||||
bi_errorf(Tf_sD_s, wp[i], Tnot_ident);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
@ -975,7 +974,7 @@ c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
|
||||
/* no arguments */
|
||||
if (!thing && !flag) {
|
||||
if (any_set == 1) {
|
||||
shprintf("%s %s %s\n", Tset, "-A", vp->name);
|
||||
shprintf(Tf_s_s_sN, Tset, "-A", vp->name);
|
||||
any_set = 2;
|
||||
}
|
||||
/*
|
||||
@ -983,31 +982,31 @@ c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
|
||||
* leftadj, zerofill, etc., but POSIX says must
|
||||
* be suitable for re-entry...
|
||||
*/
|
||||
shprintf("%s %s", Ttypeset, "");
|
||||
shprintf(Tf_s_s, Ttypeset, "");
|
||||
if (((vp->flag & (ARRAY | ASSOC)) == ASSOC))
|
||||
shprintf("-%c ", 'n');
|
||||
shprintf(Tf__c_, 'n');
|
||||
if ((vp->flag & INTEGER))
|
||||
shprintf("-%c ", 'i');
|
||||
shprintf(Tf__c_, 'i');
|
||||
if ((vp->flag & EXPORT))
|
||||
shprintf("-%c ", 'x');
|
||||
shprintf(Tf__c_, 'x');
|
||||
if ((vp->flag & RDONLY))
|
||||
shprintf("-%c ", 'r');
|
||||
shprintf(Tf__c_, 'r');
|
||||
if ((vp->flag & TRACE))
|
||||
shprintf("-%c ", 't');
|
||||
shprintf(Tf__c_, 't');
|
||||
if ((vp->flag & LJUST))
|
||||
shprintf("-L%d ", vp->u2.field);
|
||||
if ((vp->flag & RJUST))
|
||||
shprintf("-R%d ", vp->u2.field);
|
||||
if ((vp->flag & ZEROFIL))
|
||||
shprintf("-%c ", 'Z');
|
||||
shprintf(Tf__c_, 'Z');
|
||||
if ((vp->flag & LCASEV))
|
||||
shprintf("-%c ", 'l');
|
||||
shprintf(Tf__c_, 'l');
|
||||
if ((vp->flag & UCASEV_AL))
|
||||
shprintf("-%c ", 'u');
|
||||
shprintf(Tf__c_, 'u');
|
||||
if ((vp->flag & INT_U))
|
||||
shprintf("-%c ", 'U');
|
||||
shprintf(Tf__c_, 'U');
|
||||
} else if (pflag) {
|
||||
shprintf("%s %s", istset ? Ttypeset :
|
||||
shprintf(Tf_s_s, istset ? Ttypeset :
|
||||
(flag & EXPORT) ? Texport : Treadonly, "");
|
||||
}
|
||||
if (any_set)
|
||||
@ -1113,7 +1112,7 @@ c_alias(const char **wp)
|
||||
for (p = ktsort(t); (ap = *p++) != NULL; )
|
||||
if ((ap->flag & (ISSET|xflag)) == (ISSET|xflag)) {
|
||||
if (pflag)
|
||||
shprintf("%s ", Talias);
|
||||
shprintf(Tf_s_, Talias);
|
||||
shf_puts(ap->name, shl_stdout);
|
||||
if (prefix != '+') {
|
||||
shf_putc('=', shl_stdout);
|
||||
@ -1138,7 +1137,7 @@ c_alias(const char **wp)
|
||||
ap = ktsearch(t, alias, h);
|
||||
if (ap != NULL && (ap->flag&ISSET)) {
|
||||
if (pflag)
|
||||
shprintf("%s ", Talias);
|
||||
shprintf(Tf_s_, Talias);
|
||||
shf_puts(ap->name, shl_stdout);
|
||||
if (prefix != '+') {
|
||||
shf_putc('=', shl_stdout);
|
||||
@ -1146,8 +1145,7 @@ c_alias(const char **wp)
|
||||
}
|
||||
shf_putc('\n', shl_stdout);
|
||||
} else {
|
||||
shprintf("%s %s %s\n", alias, Talias,
|
||||
"not found");
|
||||
shprintf(Tf_s_s_sN, alias, Talias, Tnot_found);
|
||||
rv = 1;
|
||||
}
|
||||
continue;
|
||||
@ -1251,7 +1249,7 @@ c_let(const char **wp)
|
||||
|
||||
if (wp[1] == NULL)
|
||||
/* AT&T ksh does this */
|
||||
bi_errorf("no arguments");
|
||||
bi_errorf(Tno_args);
|
||||
else
|
||||
for (wp++; *wp; wp++)
|
||||
if (!evaluate(*wp, &val, KSH_RETURN_ERROR, true)) {
|
||||
@ -1302,7 +1300,7 @@ c_jobs(const char **wp)
|
||||
int
|
||||
c_fgbg(const char **wp)
|
||||
{
|
||||
bool bg = strcmp(*wp, "bg") == 0;
|
||||
bool bg = strcmp(*wp, Tbg) == 0;
|
||||
int rv = 0;
|
||||
|
||||
if (!Flag(FMONITOR)) {
|
||||
@ -1347,7 +1345,7 @@ c_kill(const char **wp)
|
||||
if ((p = wp[1]) && *p == '-' && (ksh_isdigit(p[1]) ||
|
||||
ksh_isupper(p[1]))) {
|
||||
if (!(t = gettrap(p + 1, false, false))) {
|
||||
bi_errorf("bad signal '%s'", p + 1);
|
||||
bi_errorf(Tbad_sig_s, p + 1);
|
||||
return (1);
|
||||
}
|
||||
i = (wp[2] && strcmp(wp[2], "--") == 0) ? 3 : 2;
|
||||
@ -1362,7 +1360,7 @@ c_kill(const char **wp)
|
||||
case 's':
|
||||
if (!(t = gettrap(builtin_opt.optarg,
|
||||
true, false))) {
|
||||
bi_errorf("bad signal '%s'",
|
||||
bi_errorf(Tbad_sig_s,
|
||||
builtin_opt.optarg);
|
||||
return (1);
|
||||
}
|
||||
@ -1392,9 +1390,9 @@ c_kill(const char **wp)
|
||||
n -= 128;
|
||||
#endif
|
||||
if (n > 0 && n < ksh_NSIG)
|
||||
shprintf("%s\n", sigtraps[n].name);
|
||||
shprintf(Tf_sN, sigtraps[n].name);
|
||||
else
|
||||
shprintf("%d\n", n);
|
||||
shprintf(Tf_dN, n);
|
||||
}
|
||||
} else if (Flag(FPOSIX)) {
|
||||
n = 1;
|
||||
@ -1439,12 +1437,12 @@ c_kill(const char **wp)
|
||||
if (j_kill(p, sig))
|
||||
rv = 1;
|
||||
} else if (!getn(p, &n)) {
|
||||
bi_errorf("%s: %s", p,
|
||||
bi_errorf(Tf_sD_s, p,
|
||||
"arguments must be jobs or process IDs");
|
||||
rv = 1;
|
||||
} else {
|
||||
if (mksh_kill(n, sig) < 0) {
|
||||
bi_errorf("%s: %s", p, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, p, cstrerror(errno));
|
||||
rv = 1;
|
||||
}
|
||||
}
|
||||
@ -1476,22 +1474,22 @@ c_getopts(const char **wp)
|
||||
|
||||
opts = *wp++;
|
||||
if (!opts) {
|
||||
bi_errorf("missing %s argument", "options");
|
||||
bi_errorf(Tf_sD_s, "options", Tno_args);
|
||||
return (1);
|
||||
}
|
||||
|
||||
var = *wp++;
|
||||
if (!var) {
|
||||
bi_errorf("missing %s argument", "name");
|
||||
bi_errorf(Tf_sD_s, Tname, Tno_args);
|
||||
return (1);
|
||||
}
|
||||
if (!*var || *skip_varname(var, true)) {
|
||||
bi_errorf("%s: %s", var, "is not an identifier");
|
||||
bi_errorf(Tf_sD_s, var, Tnot_ident);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (e->loc->next == NULL) {
|
||||
internal_warningf("%s: %s", "c_getopts", "no argv");
|
||||
internal_warningf(Tf_sD_s, Tgetopts, Tno_args);
|
||||
return (1);
|
||||
}
|
||||
/* Which arguments are we parsing... */
|
||||
@ -1636,7 +1634,7 @@ c_shift(const char **wp)
|
||||
/* nothing to do */
|
||||
return (0);
|
||||
} else if (n < 0) {
|
||||
bi_errorf("%s: %s", arg, "bad number");
|
||||
bi_errorf(Tf_sD_s, arg, "bad number");
|
||||
return (1);
|
||||
}
|
||||
if (l->argc < n) {
|
||||
@ -1676,7 +1674,7 @@ c_umask(const char **wp)
|
||||
old_umask = ~old_umask;
|
||||
p = buf;
|
||||
for (i = 0; i < 3; i++) {
|
||||
*p++ = "ugo"[i];
|
||||
*p++ = Tugo[i];
|
||||
*p++ = '=';
|
||||
for (j = 0; j < 3; j++)
|
||||
if (old_umask & (1 << (8 - (3*i + j))))
|
||||
@ -1684,7 +1682,7 @@ c_umask(const char **wp)
|
||||
*p++ = ',';
|
||||
}
|
||||
p[-1] = '\0';
|
||||
shprintf("%s\n", buf);
|
||||
shprintf(Tf_sN, buf);
|
||||
} else
|
||||
shprintf("%#3.3o\n", (unsigned int)old_umask);
|
||||
} else {
|
||||
@ -1712,7 +1710,7 @@ c_umask(const char **wp)
|
||||
new_umask = old_umask;
|
||||
positions = 0;
|
||||
while (*cp) {
|
||||
while (*cp && vstrchr("augo", *cp))
|
||||
while (*cp && vstrchr(Taugo, *cp))
|
||||
switch (*cp++) {
|
||||
case 'a':
|
||||
positions |= 0111;
|
||||
@ -1795,7 +1793,7 @@ c_dot(const char **wp)
|
||||
return (1);
|
||||
|
||||
if ((cp = wp[builtin_opt.optind]) == NULL) {
|
||||
bi_errorf("missing argument");
|
||||
bi_errorf(Tno_args);
|
||||
return (1);
|
||||
}
|
||||
file = search_path(cp, path, R_OK, &errcode);
|
||||
@ -1803,7 +1801,7 @@ c_dot(const char **wp)
|
||||
search_access(cp, R_OK) == 0)
|
||||
file = cp;
|
||||
if (!file) {
|
||||
bi_errorf("%s: %s", cp, cstrerror(errcode));
|
||||
bi_errorf(Tf_sD_s, cp, cstrerror(errcode));
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -1820,7 +1818,7 @@ c_dot(const char **wp)
|
||||
}
|
||||
if ((i = include(file, argc, argv, false)) < 0) {
|
||||
/* should not happen */
|
||||
bi_errorf("%s: %s", cp, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, cp, cstrerror(errno));
|
||||
return (1);
|
||||
}
|
||||
return (i);
|
||||
@ -1901,7 +1899,7 @@ c_read(const char **wp)
|
||||
break;
|
||||
case 'p':
|
||||
if ((fd = coproc_getfd(R_OK, &ccp)) < 0) {
|
||||
bi_errorf("-p: %s", ccp);
|
||||
bi_errorf(Tf_coproc, ccp);
|
||||
return (2);
|
||||
}
|
||||
break;
|
||||
@ -1914,7 +1912,7 @@ c_read(const char **wp)
|
||||
#if HAVE_SELECT
|
||||
case 't':
|
||||
if (parse_usec(builtin_opt.optarg, &tv)) {
|
||||
bi_errorf("%s: %s '%s'", Tsynerr, cstrerror(errno),
|
||||
bi_errorf(Tf_sD_s_qs, Tsynerr, cstrerror(errno),
|
||||
builtin_opt.optarg);
|
||||
return (2);
|
||||
}
|
||||
@ -1925,7 +1923,7 @@ c_read(const char **wp)
|
||||
if (!builtin_opt.optarg[0])
|
||||
fd = 0;
|
||||
else if ((fd = check_fd(builtin_opt.optarg, R_OK, &ccp)) < 0) {
|
||||
bi_errorf("%s: %s: %s", "-u", builtin_opt.optarg, ccp);
|
||||
bi_errorf(Tf_sD_sD_s, "-u", builtin_opt.optarg, ccp);
|
||||
return (2);
|
||||
}
|
||||
break;
|
||||
@ -1937,7 +1935,7 @@ c_read(const char **wp)
|
||||
*--wp = REPLY;
|
||||
|
||||
if (intoarray && wp[1] != NULL) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (2);
|
||||
}
|
||||
|
||||
@ -1997,7 +1995,7 @@ c_read(const char **wp)
|
||||
/* fake EOF read; all cases return 1 */
|
||||
goto c_read_didread;
|
||||
default:
|
||||
bi_errorf("%s: %s", Tselect, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, Tselect, cstrerror(errno));
|
||||
rv = 2;
|
||||
goto c_read_out;
|
||||
}
|
||||
@ -2014,7 +2012,7 @@ c_read(const char **wp)
|
||||
/* pretend the read was killed */
|
||||
} else {
|
||||
/* unexpected error */
|
||||
bi_errorf("%s", cstrerror(errno));
|
||||
bi_errorf(Tf_s, cstrerror(errno));
|
||||
}
|
||||
rv = 2;
|
||||
goto c_read_out;
|
||||
@ -2116,7 +2114,7 @@ c_read(const char **wp)
|
||||
subarray = last_lookup_was_array;
|
||||
if (vp->flag & RDONLY) {
|
||||
c_read_splitro:
|
||||
bi_errorf("read-only: %s", *wp);
|
||||
bi_errorf(Tf_ro, *wp);
|
||||
c_read_spliterr:
|
||||
rv = 2;
|
||||
afree(cp, ATEMP);
|
||||
@ -2344,7 +2342,7 @@ c_trap(const char **wp)
|
||||
if (p->trap) {
|
||||
shf_puts("trap -- ", shl_stdout);
|
||||
print_value_quoted(shl_stdout, p->trap);
|
||||
shprintf(" %s\n", p->name);
|
||||
shprintf(Tf__sN, p->name);
|
||||
}
|
||||
++p;
|
||||
} while (i--);
|
||||
@ -2366,8 +2364,7 @@ c_trap(const char **wp)
|
||||
i = 0;
|
||||
while (*wp)
|
||||
if (!(p = gettrap(*wp++, true, true))) {
|
||||
warningf(true, "%s: bad signal '%s'",
|
||||
builtin_argv0, wp[-1]);
|
||||
warningf(true, Tbad_sig_ss, builtin_argv0, wp[-1]);
|
||||
i = 1;
|
||||
} else
|
||||
settrap(p, s);
|
||||
@ -2412,7 +2409,7 @@ c_exitreturn(const char **wp)
|
||||
/* NOTREACHED */
|
||||
|
||||
c_exitreturn_err:
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -2561,7 +2558,7 @@ c_unset(const char **wp)
|
||||
afree(cp, ATEMP);
|
||||
|
||||
if ((vp->flag&RDONLY)) {
|
||||
warningf(true, "read-only: %s", vp->name);
|
||||
warningf(true, Tf_ro, vp->name);
|
||||
rv = 1;
|
||||
} else
|
||||
unset(vp, optc);
|
||||
@ -2591,13 +2588,13 @@ c_times(const char **wp MKSH_A_UNUSED)
|
||||
|
||||
getrusage(RUSAGE_SELF, &usage);
|
||||
p_time(shl_stdout, false, usage.ru_utime.tv_sec,
|
||||
usage.ru_utime.tv_usec, 0, null, " ");
|
||||
usage.ru_utime.tv_usec, 0, null, T1space);
|
||||
p_time(shl_stdout, false, usage.ru_stime.tv_sec,
|
||||
usage.ru_stime.tv_usec, 0, null, "\n");
|
||||
|
||||
getrusage(RUSAGE_CHILDREN, &usage);
|
||||
p_time(shl_stdout, false, usage.ru_utime.tv_sec,
|
||||
usage.ru_utime.tv_usec, 0, null, " ");
|
||||
usage.ru_utime.tv_usec, 0, null, T1space);
|
||||
p_time(shl_stdout, false, usage.ru_stime.tv_sec,
|
||||
usage.ru_stime.tv_usec, 0, null, "\n");
|
||||
|
||||
@ -2656,17 +2653,17 @@ timex(struct op *t, int f, volatile int *xerrok)
|
||||
timersub(&tv1, &tv0, &tv1);
|
||||
if (tf & TF_POSIX)
|
||||
p_time(shl_out, true, tv1.tv_sec, tv1.tv_usec,
|
||||
5, "real ", "\n");
|
||||
5, Treal_sp1, "\n");
|
||||
else
|
||||
p_time(shl_out, false, tv1.tv_sec, tv1.tv_usec,
|
||||
5, null, " real ");
|
||||
5, null, Treal_sp2);
|
||||
}
|
||||
if (tf & TF_POSIX)
|
||||
p_time(shl_out, true, usrtime.tv_sec, usrtime.tv_usec,
|
||||
5, "user ", "\n");
|
||||
5, Tuser_sp1, "\n");
|
||||
else
|
||||
p_time(shl_out, false, usrtime.tv_sec, usrtime.tv_usec,
|
||||
5, null, " user ");
|
||||
5, null, Tuser_sp2);
|
||||
if (tf & TF_POSIX)
|
||||
p_time(shl_out, true, systime.tv_sec, systime.tv_usec,
|
||||
5, "sys ", "\n");
|
||||
@ -2694,11 +2691,11 @@ timex_hook(struct op *t, char **volatile *app)
|
||||
t->str[0] |= TF_POSIX;
|
||||
break;
|
||||
case '?':
|
||||
errorf("time: -%s %s", opt.optarg,
|
||||
"unknown option");
|
||||
errorf(Tf_optfoo, Ttime, Tcolsp,
|
||||
opt.optarg[0], Tunknown_option);
|
||||
case ':':
|
||||
errorf("time: -%s %s", opt.optarg,
|
||||
"requires an argument");
|
||||
errorf(Tf_optfoo, Ttime, Tcolsp,
|
||||
opt.optarg[0], Treq_arg);
|
||||
}
|
||||
/* Copy command words down over options. */
|
||||
if (opt.optind != 0) {
|
||||
@ -2788,28 +2785,28 @@ c_mknod(const char **wp)
|
||||
|
||||
majnum = strtoul(argv[2], &c, 0);
|
||||
if ((c == argv[2]) || (*c != '\0')) {
|
||||
bi_errorf("non-numeric %s %s '%s'", "device", "major", argv[2]);
|
||||
bi_errorf(Tf_nonnum, "device", "major", argv[2]);
|
||||
goto c_mknod_err;
|
||||
}
|
||||
minnum = strtoul(argv[3], &c, 0);
|
||||
if ((c == argv[3]) || (*c != '\0')) {
|
||||
bi_errorf("non-numeric %s %s '%s'", "device", "minor", argv[3]);
|
||||
bi_errorf(Tf_nonnum, "device", "minor", argv[3]);
|
||||
goto c_mknod_err;
|
||||
}
|
||||
dv = makedev(majnum, minnum);
|
||||
if ((unsigned long)(major(dv)) != majnum) {
|
||||
bi_errorf("%s %s too large: %lu", "device", "major", majnum);
|
||||
bi_errorf(Tf_toolarge, "device", "major", majnum);
|
||||
goto c_mknod_err;
|
||||
}
|
||||
if ((unsigned long)(minor(dv)) != minnum) {
|
||||
bi_errorf("%s %s too large: %lu", "device", "minor", minnum);
|
||||
bi_errorf(Tf_toolarge, "device", "minor", minnum);
|
||||
goto c_mknod_err;
|
||||
}
|
||||
if (mknod(argv[0], mode, dv))
|
||||
goto c_mknod_failed;
|
||||
} else if (mkfifo(argv[0], mode)) {
|
||||
c_mknod_failed:
|
||||
bi_errorf("%s: %s", argv[0], cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, argv[0], cstrerror(errno));
|
||||
c_mknod_err:
|
||||
rv = 1;
|
||||
}
|
||||
@ -2867,7 +2864,7 @@ c_test(const char **wp)
|
||||
for (argc = 0; wp[argc]; argc++)
|
||||
;
|
||||
|
||||
if (strcmp(wp[0], "[") == 0) {
|
||||
if (strcmp(wp[0], Tbracket) == 0) {
|
||||
if (strcmp(wp[--argc], "]") != 0) {
|
||||
bi_errorf("missing ]");
|
||||
return (T_ERR_EXIT);
|
||||
@ -3344,7 +3341,7 @@ test_primary(Test_env *te, bool do_eval)
|
||||
/* unary expression */
|
||||
opnd1 = (*te->getopnd)(te, op, do_eval);
|
||||
if (!opnd1) {
|
||||
(*te->error)(te, -1, "missing argument");
|
||||
(*te->error)(te, -1, Tno_args);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -3420,9 +3417,9 @@ ptest_error(Test_env *te, int ofs, const char *msg)
|
||||
|
||||
te->flags |= TEF_ERROR;
|
||||
if ((op = te->pos.wp + ofs >= te->wp_end ? NULL : te->pos.wp[ofs]))
|
||||
bi_errorf("%s: %s", op, msg);
|
||||
bi_errorf(Tf_sD_s, op, msg);
|
||||
else
|
||||
bi_errorf("%s", msg);
|
||||
bi_errorf(Tf_s, msg);
|
||||
}
|
||||
|
||||
#ifndef MKSH_NO_LIMITS
|
||||
@ -3550,7 +3547,7 @@ c_ulimit(const char **wp)
|
||||
found:
|
||||
if (wp[builtin_opt.optind]) {
|
||||
if (all || wp[builtin_opt.optind + 1]) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
return (set_ulimit(rlimits[i], wp[builtin_opt.optind], how));
|
||||
@ -3651,7 +3648,7 @@ c_rename(const char **wp)
|
||||
bi_errorf(Tsynerr);
|
||||
else if ((rv = rename(wp[0], wp[1])) != 0) {
|
||||
rv = errno;
|
||||
bi_errorf("%s: %s", "failed", cstrerror(rv));
|
||||
bi_errorf(Tf_sD_s, "failed", cstrerror(rv));
|
||||
}
|
||||
|
||||
return (rv);
|
||||
@ -3674,11 +3671,11 @@ c_realpath(const char **wp)
|
||||
bi_errorf(Tsynerr);
|
||||
else if ((buf = do_realpath(wp[0])) == NULL) {
|
||||
rv = errno;
|
||||
bi_errorf("%s: %s", wp[0], cstrerror(rv));
|
||||
bi_errorf(Tf_sD_s, wp[0], cstrerror(rv));
|
||||
if ((unsigned int)rv > 255)
|
||||
rv = 255;
|
||||
} else {
|
||||
shprintf("%s\n", buf);
|
||||
shprintf(Tf_sN, buf);
|
||||
afree(buf, ATEMP);
|
||||
rv = 0;
|
||||
}
|
||||
@ -3724,7 +3721,7 @@ c_cat(const char **wp)
|
||||
if (ksh_isdash(fn))
|
||||
fd = STDIN_FILENO;
|
||||
else if ((fd = binopen2(fn, O_RDONLY)) < 0) {
|
||||
bi_errorf("%s: %s", fn, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, fn, cstrerror(errno));
|
||||
rv = 1;
|
||||
continue;
|
||||
}
|
||||
@ -3741,7 +3738,7 @@ c_cat(const char **wp)
|
||||
continue;
|
||||
}
|
||||
/* an error occured during reading */
|
||||
bi_errorf("%s: %s", fn, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, fn, cstrerror(errno));
|
||||
rv = 1;
|
||||
break;
|
||||
} else if (n == 0)
|
||||
@ -3766,7 +3763,7 @@ c_cat(const char **wp)
|
||||
rv = ksh_sigmask(SIGPIPE);
|
||||
} else {
|
||||
/* an error occured during writing */
|
||||
bi_errorf("%s: %s", "<stdout>",
|
||||
bi_errorf(Tf_sD_s, "<stdout>",
|
||||
cstrerror(errno));
|
||||
rv = 1;
|
||||
}
|
||||
@ -3801,7 +3798,7 @@ c_sleep(const char **wp)
|
||||
if (!wp[0] || wp[1])
|
||||
bi_errorf(Tsynerr);
|
||||
else if (parse_usec(wp[0], &tv))
|
||||
bi_errorf("%s: %s '%s'", Tsynerr, cstrerror(errno), wp[0]);
|
||||
bi_errorf(Tf_sD_s_qs, Tsynerr, cstrerror(errno), wp[0]);
|
||||
else {
|
||||
#ifndef MKSH_NOPROSPECTOFWORK
|
||||
sigset_t omask, bmask;
|
||||
@ -3831,7 +3828,7 @@ c_sleep(const char **wp)
|
||||
*/
|
||||
rv = 0;
|
||||
else
|
||||
bi_errorf("%s: %s", Tselect, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, Tselect, cstrerror(errno));
|
||||
#ifndef MKSH_NOPROSPECTOFWORK
|
||||
/* this will re-schedule signal delivery */
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
@ -3846,7 +3843,7 @@ static int
|
||||
c_suspend(const char **wp)
|
||||
{
|
||||
if (wp[1] != NULL) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
if (Flag(FLOGIN)) {
|
||||
|
53
histrap.c
53
histrap.c
@ -27,7 +27,7 @@
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.156 2016/03/04 14:26:13 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.157 2016/07/25 00:04:43 tg Exp $");
|
||||
|
||||
Trap sigtraps[ksh_NSIG + 1];
|
||||
static struct sigaction Sigact_ign;
|
||||
@ -69,12 +69,6 @@ static int histfd = -1;
|
||||
static off_t histfsize;
|
||||
#endif
|
||||
|
||||
static const char Tnot_in_history[] = "not in history";
|
||||
#define Thistory (Tnot_in_history + 7)
|
||||
|
||||
static const char TFCEDIT_dollaru[] = "${FCEDIT:-/bin/ed} $_";
|
||||
#define Tspdollaru (TFCEDIT_dollaru + 18)
|
||||
|
||||
/* HISTSIZE default: size of saved history, persistent or standard */
|
||||
#ifdef MKSH_SMALL
|
||||
#define MKSH_DEFHISTSIZE 255
|
||||
@ -153,7 +147,7 @@ c_fc(const char **wp)
|
||||
else if (!last)
|
||||
last = p;
|
||||
else {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
break;
|
||||
@ -183,7 +177,7 @@ c_fc(const char **wp)
|
||||
if (!first && (first = *wp))
|
||||
wp++;
|
||||
if (last || *wp) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -239,7 +233,7 @@ c_fc(const char **wp)
|
||||
if (!last && (last = *wp))
|
||||
wp++;
|
||||
if (*wp) {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (1);
|
||||
}
|
||||
if (!first) {
|
||||
@ -278,7 +272,7 @@ c_fc(const char **wp)
|
||||
for (hp = rflag ? hlast : hfirst;
|
||||
hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1) {
|
||||
if (!nflag)
|
||||
shf_fprintf(shl_stdout, "%lu",
|
||||
shf_fprintf(shl_stdout, Tf_lu,
|
||||
(unsigned long)hist_source->line -
|
||||
(unsigned long)(histptr - hp));
|
||||
shf_putc('\t', shl_stdout);
|
||||
@ -290,7 +284,7 @@ c_fc(const char **wp)
|
||||
*t++ = '\n';
|
||||
s = t;
|
||||
}
|
||||
shf_fprintf(shl_stdout, "%s\n", s);
|
||||
shf_fprintf(shl_stdout, Tf_sN, s);
|
||||
}
|
||||
shf_flush(shl_stdout);
|
||||
return (0);
|
||||
@ -300,16 +294,14 @@ c_fc(const char **wp)
|
||||
|
||||
tf = maketemp(ATEMP, TT_HIST_EDIT, &e->temps);
|
||||
if (!(shf = tf->shf)) {
|
||||
bi_errorf("can't %s temporary file %s: %s",
|
||||
"create", tf->tffn, cstrerror(errno));
|
||||
bi_errorf(Tf_temp, Tcreate, tf->tffn, cstrerror(errno));
|
||||
return (1);
|
||||
}
|
||||
for (hp = rflag ? hlast : hfirst;
|
||||
hp >= hfirst && hp <= hlast; hp += rflag ? -1 : 1)
|
||||
shf_fprintf(shf, "%s\n", *hp);
|
||||
shf_fprintf(shf, Tf_sN, *hp);
|
||||
if (shf_close(shf) == -1) {
|
||||
bi_errorf("can't %s temporary file %s: %s",
|
||||
"write", tf->tffn, cstrerror(errno));
|
||||
bi_errorf(Tf_temp, Twrite, tf->tffn, cstrerror(errno));
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -334,16 +326,15 @@ c_fc(const char **wp)
|
||||
ssize_t n;
|
||||
|
||||
if (!(shf = shf_open(tf->tffn, O_RDONLY, 0, 0))) {
|
||||
bi_errorf("can't %s temporary file %s: %s",
|
||||
"open", tf->tffn, cstrerror(errno));
|
||||
bi_errorf(Tf_temp, Topen, tf->tffn, cstrerror(errno));
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (stat(tf->tffn, &statb) < 0)
|
||||
n = 128;
|
||||
else if ((off_t)statb.st_size > MKSH_MAXHISTFSIZE) {
|
||||
bi_errorf("%s %s too large: %lu", Thistory,
|
||||
"file", (unsigned long)statb.st_size);
|
||||
bi_errorf(Tf_toolarge, Thistory,
|
||||
Tfile, (unsigned long)statb.st_size);
|
||||
goto errout;
|
||||
} else
|
||||
n = (size_t)statb.st_size + 1;
|
||||
@ -354,8 +345,8 @@ c_fc(const char **wp)
|
||||
XcheckN(xs, xp, Xlength(xs, xp));
|
||||
}
|
||||
if (n < 0) {
|
||||
bi_errorf("can't %s temporary file %s: %s",
|
||||
"read", tf->tffn, cstrerror(shf_errno(shf)));
|
||||
bi_errorf(Tf_temp, Tread, tf->tffn,
|
||||
cstrerror(shf_errno(shf)));
|
||||
errout:
|
||||
shf_close(shf);
|
||||
return (1);
|
||||
@ -388,7 +379,7 @@ hist_execute(char *cmd, Area *areap)
|
||||
afree(cmd, areap);
|
||||
cmd = *histptr;
|
||||
/* pdksh says POSIX doesn’t say this is done, testsuite needs it */
|
||||
shellf("%s\n", cmd);
|
||||
shellf(Tf_sN, cmd);
|
||||
|
||||
/*-
|
||||
* Commands are executed here instead of pushing them onto the
|
||||
@ -420,18 +411,18 @@ hist_get(const char *str, bool approx, bool allow_cur)
|
||||
if (approx)
|
||||
hp = hist_get_oldest();
|
||||
else {
|
||||
bi_errorf("%s: %s", str, Tnot_in_history);
|
||||
bi_errorf(Tf_sD_s, str, Tnot_in_history);
|
||||
hp = NULL;
|
||||
}
|
||||
} else if ((size_t)hp > (size_t)histptr) {
|
||||
if (approx)
|
||||
hp = hist_get_newest(allow_cur);
|
||||
else {
|
||||
bi_errorf("%s: %s", str, Tnot_in_history);
|
||||
bi_errorf(Tf_sD_s, str, Tnot_in_history);
|
||||
hp = NULL;
|
||||
}
|
||||
} else if (!allow_cur && hp == histptr) {
|
||||
bi_errorf("%s: %s", str, "invalid range");
|
||||
bi_errorf(Tf_sD_s, str, "invalid range");
|
||||
hp = NULL;
|
||||
}
|
||||
} else {
|
||||
@ -439,7 +430,7 @@ hist_get(const char *str, bool approx, bool allow_cur)
|
||||
|
||||
/* the -1 is to avoid the current fc command */
|
||||
if ((n = findhist(histptr - history - 1, 0, str, anchored)) < 0)
|
||||
bi_errorf("%s: %s", str, Tnot_in_history);
|
||||
bi_errorf(Tf_sD_s, str, Tnot_in_history);
|
||||
else
|
||||
hp = &history[n];
|
||||
}
|
||||
@ -852,7 +843,7 @@ hist_init(Source *s)
|
||||
goto retry;
|
||||
}
|
||||
if (hs != hist_init_retry)
|
||||
bi_errorf("can't %s %s: %s",
|
||||
bi_errorf(Tf_cant,
|
||||
"unlink HISTFILE", hname, cstrerror(errno));
|
||||
histfsize = 0;
|
||||
return;
|
||||
@ -1063,7 +1054,7 @@ inittraps(void)
|
||||
}
|
||||
}
|
||||
if (sigtraps[i].name == null)
|
||||
sigtraps[i].name = shf_smprintf("%d", i);
|
||||
sigtraps[i].name = shf_smprintf(Tf_d, i);
|
||||
#if HAVE_SYS_SIGLIST
|
||||
sigtraps[i].mess = sys_siglist[i];
|
||||
#elif HAVE_STRSIGNAL
|
||||
@ -1073,7 +1064,7 @@ inittraps(void)
|
||||
#endif
|
||||
if ((sigtraps[i].mess == NULL) ||
|
||||
(sigtraps[i].mess[0] == '\0'))
|
||||
sigtraps[i].mess = shf_smprintf("%s %d",
|
||||
sigtraps[i].mess = shf_smprintf(Tf_sd,
|
||||
"Signal", i);
|
||||
}
|
||||
sigtraps[ksh_SIGEXIT].signal = ksh_SIGEXIT;
|
||||
|
80
jobs.c
80
jobs.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.120 2016/03/04 14:26:13 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.121 2016/07/25 00:04:44 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
#define mksh_killpg killpg
|
||||
@ -238,11 +238,11 @@ j_suspend(void)
|
||||
mksh_tcset(tty_fd, &tty_state);
|
||||
if (restore_ttypgrp >= 0) {
|
||||
if (tcsetpgrp(tty_fd, restore_ttypgrp) < 0) {
|
||||
warningf(false, "%s: %s failed: %s",
|
||||
"j_suspend", "tcsetpgrp", cstrerror(errno));
|
||||
warningf(false, Tf_ssfaileds,
|
||||
Tj_suspend, "tcsetpgrp", cstrerror(errno));
|
||||
} else if (setpgid(0, restore_ttypgrp) < 0) {
|
||||
warningf(false, "%s: %s failed: %s",
|
||||
"j_suspend", "setpgid", cstrerror(errno));
|
||||
warningf(false, Tf_ssfaileds,
|
||||
Tj_suspend, "setpgid", cstrerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -259,12 +259,12 @@ j_suspend(void)
|
||||
if (ttypgrp_ok) {
|
||||
if (restore_ttypgrp >= 0) {
|
||||
if (setpgid(0, kshpid) < 0) {
|
||||
warningf(false, "%s: %s failed: %s",
|
||||
"j_suspend", "setpgid", cstrerror(errno));
|
||||
warningf(false, Tf_ssfaileds,
|
||||
Tj_suspend, "setpgid", cstrerror(errno));
|
||||
ttypgrp_ok = false;
|
||||
} else if (tcsetpgrp(tty_fd, kshpid) < 0) {
|
||||
warningf(false, "%s: %s failed: %s",
|
||||
"j_suspend", "tcsetpgrp", cstrerror(errno));
|
||||
warningf(false, Tf_ssfaileds,
|
||||
Tj_suspend, "tcsetpgrp", cstrerror(errno));
|
||||
ttypgrp_ok = false;
|
||||
}
|
||||
}
|
||||
@ -349,7 +349,7 @@ j_change(void)
|
||||
pid_t ttypgrp;
|
||||
|
||||
if ((ttypgrp = tcgetpgrp(tty_fd)) < 0) {
|
||||
warningf(false, "%s: %s failed: %s",
|
||||
warningf(false, Tf_ssfaileds,
|
||||
"j_init", "tcgetpgrp",
|
||||
cstrerror(errno));
|
||||
ttypgrp_ok = false;
|
||||
@ -365,12 +365,12 @@ j_change(void)
|
||||
SS_RESTORE_DFL|SS_FORCE);
|
||||
if (ttypgrp_ok && kshpgrp != kshpid) {
|
||||
if (setpgid(0, kshpid) < 0) {
|
||||
warningf(false, "%s: %s failed: %s",
|
||||
warningf(false, Tf_ssfaileds,
|
||||
"j_init", "setpgid", cstrerror(errno));
|
||||
ttypgrp_ok = false;
|
||||
} else {
|
||||
if (tcsetpgrp(tty_fd, kshpid) < 0) {
|
||||
warningf(false, "%s: %s failed: %s",
|
||||
warningf(false, Tf_ssfaileds,
|
||||
"j_init", "tcsetpgrp",
|
||||
cstrerror(errno));
|
||||
ttypgrp_ok = false;
|
||||
@ -381,7 +381,7 @@ j_change(void)
|
||||
}
|
||||
#ifndef MKSH_DISABLE_TTY_WARNING
|
||||
if (use_tty && !ttypgrp_ok)
|
||||
warningf(false, "%s: %s", "warning",
|
||||
warningf(false, Tf_sD_s, "warning",
|
||||
"won't have full job control");
|
||||
#endif
|
||||
} else {
|
||||
@ -415,7 +415,7 @@ ksh_nice(int ness)
|
||||
errno = 0;
|
||||
/* this is gonna annoy users; complain to your distro, people! */
|
||||
if (nice(ness) == -1 && (eno = errno) != 0)
|
||||
warningf(false, "%s: %s", "bgnice", cstrerror(eno));
|
||||
warningf(false, Tf_sD_s, "bgnice", cstrerror(eno));
|
||||
#else
|
||||
(void)nice(ness);
|
||||
#endif
|
||||
@ -625,7 +625,7 @@ exchild(struct op *t, int flags,
|
||||
if (Flag(FTALKING)) {
|
||||
shf_fprintf(shl_out, "[%d]", j->job);
|
||||
for (p = j->proc_list; p; p = p->next)
|
||||
shf_fprintf(shl_out, " %d",
|
||||
shf_fprintf(shl_out, Tf__d,
|
||||
(int)p->pid);
|
||||
shf_putchar('\n', shl_out);
|
||||
shf_flush(shl_out);
|
||||
@ -677,9 +677,9 @@ waitlast(void)
|
||||
j = last_job;
|
||||
if (!j || !(j->flags & JF_STARTED)) {
|
||||
if (!j)
|
||||
warningf(true, "%s: %s", "waitlast", "no last job");
|
||||
warningf(true, Tf_sD_s, "waitlast", "no last job");
|
||||
else
|
||||
internal_warningf("%s: %s", "waitlast", "not started");
|
||||
internal_warningf(Tf_sD_s, "waitlast", Tnot_started);
|
||||
#ifndef MKSH_NOPROSPECTOFWORK
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
#endif
|
||||
@ -739,7 +739,7 @@ waitfor(const char *cp, int *sigp)
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
#endif
|
||||
if (ecode != JL_NOSUCH)
|
||||
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
||||
bi_errorf(Tf_sD_s, cp, lookup_msgs[ecode]);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@ -773,14 +773,14 @@ j_kill(const char *cp, int sig)
|
||||
#ifndef MKSH_NOPROSPECTOFWORK
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
#endif
|
||||
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
||||
bi_errorf(Tf_sD_s, cp, lookup_msgs[ecode]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (j->pgrp == 0) {
|
||||
/* started when !Flag(FMONITOR) */
|
||||
if (kill_job(j, sig) < 0) {
|
||||
bi_errorf("%s: %s", cp, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, cp, cstrerror(errno));
|
||||
rv = 1;
|
||||
}
|
||||
} else {
|
||||
@ -789,7 +789,7 @@ j_kill(const char *cp, int sig)
|
||||
mksh_killpg(j->pgrp, SIGCONT);
|
||||
#endif
|
||||
if (mksh_killpg(j->pgrp, sig) < 0) {
|
||||
bi_errorf("%s: %s", cp, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, cp, cstrerror(errno));
|
||||
rv = 1;
|
||||
}
|
||||
}
|
||||
@ -816,7 +816,7 @@ j_resume(const char *cp, int bg)
|
||||
|
||||
if ((j = j_lookup(cp, &ecode)) == NULL) {
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
||||
bi_errorf(Tf_sD_s, cp, lookup_msgs[ecode]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -861,7 +861,7 @@ j_resume(const char *cp, int bg)
|
||||
if (j->flags & JF_SAVEDTTY)
|
||||
mksh_tcset(tty_fd, &tty_state);
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
bi_errorf("%s %s(%d, %ld) failed: %s",
|
||||
bi_errorf(Tf_ldfailed,
|
||||
"fg: 1st", "tcsetpgrp", tty_fd,
|
||||
(long)((j->flags & JF_SAVEDTTYPGRP) ?
|
||||
j->saved_ttypgrp : j->pgrp),
|
||||
@ -883,12 +883,12 @@ j_resume(const char *cp, int bg)
|
||||
if (ttypgrp_ok && (j->flags & JF_SAVEDTTY))
|
||||
mksh_tcset(tty_fd, &tty_state);
|
||||
if (ttypgrp_ok && tcsetpgrp(tty_fd, kshpgrp) < 0)
|
||||
warningf(true, "%s %s(%d, %ld) failed: %s",
|
||||
warningf(true, Tf_ldfailed,
|
||||
"fg: 2nd", "tcsetpgrp", tty_fd,
|
||||
(long)kshpgrp, cstrerror(errno));
|
||||
}
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
bi_errorf("%s %s: %s", "can't continue job",
|
||||
bi_errorf(Tf_s_sD_s, "can't continue job",
|
||||
cp, cstrerror(eno));
|
||||
return (1);
|
||||
}
|
||||
@ -957,7 +957,7 @@ j_jobs(const char *cp, int slp,
|
||||
#ifndef MKSH_NOPROSPECTOFWORK
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
#endif
|
||||
bi_errorf("%s: %s", cp, lookup_msgs[ecode]);
|
||||
bi_errorf(Tf_sD_s, cp, lookup_msgs[ecode]);
|
||||
return (1);
|
||||
}
|
||||
} else
|
||||
@ -977,7 +977,7 @@ j_jobs(const char *cp, int slp,
|
||||
for (j = job_list; j; j = tmp) {
|
||||
tmp = j->next;
|
||||
if (j->flags & JF_REMOVE)
|
||||
remove_job(j, "jobs");
|
||||
remove_job(j, Tjobs);
|
||||
}
|
||||
#ifndef MKSH_NOPROSPECTOFWORK
|
||||
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||
@ -1051,7 +1051,7 @@ j_set_async(Job *j)
|
||||
if (async_job && (async_job->flags & (JF_KNOWN|JF_ZOMBIE)) == JF_ZOMBIE)
|
||||
remove_job(async_job, "async");
|
||||
if (!(j->flags & JF_STARTED)) {
|
||||
internal_warningf("%s: %s", "j_async", "job not started");
|
||||
internal_warningf(Tf_sD_s, "j_async", Tjob_not_started);
|
||||
return;
|
||||
}
|
||||
async_job = j;
|
||||
@ -1175,7 +1175,7 @@ j_waitj(Job *j,
|
||||
(j->saved_ttypgrp = tcgetpgrp(tty_fd)) >= 0)
|
||||
j->flags |= JF_SAVEDTTYPGRP;
|
||||
if (tcsetpgrp(tty_fd, kshpgrp) < 0)
|
||||
warningf(true, "%s %s(%d, %ld) failed: %s",
|
||||
warningf(true, Tf_ldfailed,
|
||||
"j_waitj:", "tcsetpgrp", tty_fd,
|
||||
(long)kshpgrp, cstrerror(errno));
|
||||
if (j->state == PSTOPPED) {
|
||||
@ -1538,7 +1538,7 @@ j_print(Job *j, int how, struct shf *shf)
|
||||
* group leader (ie, !FMONITOR). We arbitrarily return
|
||||
* last pid (which is what $! returns).
|
||||
*/
|
||||
shf_fprintf(shf, "%d\n", (int)(j->pgrp ? j->pgrp :
|
||||
shf_fprintf(shf, Tf_dN, (int)(j->pgrp ? j->pgrp :
|
||||
(j->last_proc ? j->last_proc->pid : 0)));
|
||||
return;
|
||||
}
|
||||
@ -1626,10 +1626,10 @@ j_print(Job *j, int how, struct shf *shf)
|
||||
while (p && p->state == state && p->status == status) {
|
||||
if (how == JP_LONG)
|
||||
shf_fprintf(shf, "%s%5d %-20s %s%s", filler,
|
||||
(int)p->pid, " ", p->command,
|
||||
(int)p->pid, T1space, p->command,
|
||||
p->next ? "|" : null);
|
||||
else if (how == JP_MEDIUM)
|
||||
shf_fprintf(shf, " %s%s", p->command,
|
||||
shf_fprintf(shf, Tf__ss, p->command,
|
||||
p->next ? "|" : null);
|
||||
p = p->next;
|
||||
}
|
||||
@ -1803,7 +1803,7 @@ remove_job(Job *j, const char *where)
|
||||
curr = *prev;
|
||||
}
|
||||
if (curr != j) {
|
||||
internal_warningf("remove_job: job %s (%s)", "not found", where);
|
||||
internal_warningf("remove_job: job %s (%s)", Tnot_found, where);
|
||||
return;
|
||||
}
|
||||
*prev = curr->next;
|
||||
@ -1892,22 +1892,22 @@ tty_init_talking(void)
|
||||
break;
|
||||
case 1:
|
||||
#ifndef MKSH_DISABLE_TTY_WARNING
|
||||
warningf(false, "%s: %s %s: %s",
|
||||
"No controlling tty", "open", "/dev/tty",
|
||||
cstrerror(errno));
|
||||
warningf(false, Tf_sD_s_sD_s,
|
||||
"No controlling tty", Topen, T_devtty, cstrerror(errno));
|
||||
#endif
|
||||
break;
|
||||
case 2:
|
||||
#ifndef MKSH_DISABLE_TTY_WARNING
|
||||
warningf(false, "%s: %s", "can't find tty fd", cstrerror(errno));
|
||||
warningf(false, Tf_sD_s_s, Tcant_find, Ttty_fd,
|
||||
cstrerror(errno));
|
||||
#endif
|
||||
break;
|
||||
case 3:
|
||||
warningf(false, "%s: %s failed: %s", "j_ttyinit",
|
||||
"dup of tty fd", cstrerror(errno));
|
||||
warningf(false, Tf_ssfaileds, "j_ttyinit",
|
||||
Ttty_fd_dupof, cstrerror(errno));
|
||||
break;
|
||||
case 4:
|
||||
warningf(false, "%s: %s: %s", "j_ttyinit",
|
||||
warningf(false, Tf_sD_sD_s, "j_ttyinit",
|
||||
"can't set close-on-exec flag", cstrerror(errno));
|
||||
break;
|
||||
}
|
||||
|
10
lex.c
10
lex.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.225 2016/06/25 23:55:00 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.226 2016/07/25 00:04:44 tg Exp $");
|
||||
|
||||
/*
|
||||
* states while lexing word
|
||||
@ -988,7 +988,7 @@ yylex(int cf)
|
||||
++p;
|
||||
else
|
||||
/* ksh -c 'cat <<EOF' can cause this */
|
||||
yyerror("here document '%s' unclosed\n",
|
||||
yyerror(Tf_heredoc,
|
||||
evalstr((*p)->delim, 0));
|
||||
}
|
||||
return (c);
|
||||
@ -1163,7 +1163,7 @@ readhere(struct ioword *iop)
|
||||
while (c != '\n') {
|
||||
if (!c)
|
||||
/* oops, reached EOF */
|
||||
yyerror("here document '%s' unclosed\n", eof);
|
||||
yyerror(Tf_heredoc, eof);
|
||||
/* store character */
|
||||
Xcheck(xs, xp);
|
||||
Xput(xs, xp, c);
|
||||
@ -1263,7 +1263,7 @@ getsc_uu(void)
|
||||
s->start = s->str = "\n";
|
||||
s->type = SEOF;
|
||||
} else {
|
||||
s->start = s->str = " ";
|
||||
s->start = s->str = T1space;
|
||||
s->type = SWORDS;
|
||||
}
|
||||
break;
|
||||
@ -1474,7 +1474,7 @@ set_prompt(int to, Source *s)
|
||||
if (*ps1 != '!' || *++ps1 == '!')
|
||||
shf_putchar(*ps1++, shf);
|
||||
else
|
||||
shf_fprintf(shf, "%lu", s ?
|
||||
shf_fprintf(shf, Tf_lu, s ?
|
||||
(unsigned long)s->line + 1 : 0UL);
|
||||
ps1 = shf_sclose(shf);
|
||||
saved_lineno = current_lineno;
|
||||
|
32
main.c
32
main.c
@ -34,7 +34,7 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.311 2016/07/24 23:10:03 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.312 2016/07/25 00:04:45 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -63,7 +63,7 @@ static const char initsubs[] =
|
||||
|
||||
static const char *initcoms[] = {
|
||||
Ttypeset, "-r", initvsn, NULL,
|
||||
Ttypeset, "-x", "HOME", "PATH", "SHELL", NULL,
|
||||
Ttypeset, "-x", "HOME", TPATH, TSHELL, NULL,
|
||||
Ttypeset, "-i10", "COLUMNS", "LINES", "SECONDS", "TMOUT", NULL,
|
||||
Talias,
|
||||
"integer=\\typeset -i",
|
||||
@ -82,12 +82,12 @@ static const char *initcoms[] = {
|
||||
/* this is what AT&T ksh seems to track, with the addition of emacs */
|
||||
Talias, "-tU",
|
||||
Tcat, "cc", "chmod", "cp", "date", "ed", "emacs", "grep", "ls",
|
||||
"make", "mv", "pr", "rm", "sed", "sh", "vi", "who", NULL,
|
||||
"make", "mv", "pr", "rm", "sed", Tsh, "vi", "who", NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *restr_com[] = {
|
||||
Ttypeset, "-r", "PATH", "ENV", "SHELL", NULL
|
||||
Ttypeset, "-r", TPATH, "ENV", TSHELL, NULL
|
||||
};
|
||||
|
||||
static bool initio_done;
|
||||
@ -149,7 +149,7 @@ chvt_reinit(void)
|
||||
}
|
||||
|
||||
static const char *empty_argv[] = {
|
||||
"mksh", NULL
|
||||
Tmksh, NULL
|
||||
};
|
||||
|
||||
static uint8_t
|
||||
@ -333,7 +333,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
|
||||
* Set PATH to def_path (will set the path global variable).
|
||||
* (import of environment below will probably change this setting).
|
||||
*/
|
||||
vp = global("PATH");
|
||||
vp = global(TPATH);
|
||||
/* setstr can't fail here */
|
||||
setstr(vp, def_path, KSH_RETURN_ERROR);
|
||||
|
||||
@ -366,11 +366,11 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
|
||||
substitute(initsubs, 0);
|
||||
|
||||
/* Figure out the current working directory and set $PWD */
|
||||
vp = global("PWD");
|
||||
vp = global(TPWD);
|
||||
cp = str_val(vp);
|
||||
/* Try to use existing $PWD if it is valid */
|
||||
set_current_wd((mksh_abspath(cp) && test_eval(NULL, TO_FILEQ, cp, ".",
|
||||
true)) ? cp : NULL);
|
||||
set_current_wd((mksh_abspath(cp) && test_eval(NULL, TO_FILEQ, cp,
|
||||
Tdot, true)) ? cp : NULL);
|
||||
if (current_wd[0])
|
||||
simplify_path(current_wd);
|
||||
/* Only set pwd if we know where we are or if it had a bogus value */
|
||||
@ -440,7 +440,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
|
||||
} else if (Flag(FCOMMAND)) {
|
||||
s = pushs(SSTRINGCMDLINE, ATEMP);
|
||||
if (!(s->start = s->str = argv[argi++]))
|
||||
errorf("-c %s", "requires an argument");
|
||||
errorf(Tf_optfoo, "", "", 'c', Treq_arg);
|
||||
while (*s->str) {
|
||||
if (*s->str != ' ' && ctype(*s->str, C_QUOTE))
|
||||
break;
|
||||
@ -475,7 +475,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
|
||||
SHF_MAPHI | SHF_CLEXEC);
|
||||
if (s->u.shf == NULL) {
|
||||
shl_stdout_ok = false;
|
||||
warningf(true, "%s: %s", s->file, cstrerror(errno));
|
||||
warningf(true, Tf_sD_s, s->file, cstrerror(errno));
|
||||
/* mandated by SUSv4 */
|
||||
exstat = 127;
|
||||
unwind(LERROR);
|
||||
@ -1129,7 +1129,7 @@ tty_init_fd(void)
|
||||
goto got_fd;
|
||||
}
|
||||
#endif
|
||||
if ((fd = open("/dev/tty", O_RDWR, 0)) >= 0) {
|
||||
if ((fd = open(T_devtty, O_RDWR, 0)) >= 0) {
|
||||
do_close = true;
|
||||
goto got_fd;
|
||||
}
|
||||
@ -1186,13 +1186,13 @@ vwarningf(unsigned int flags, const char *fmt, va_list ap)
|
||||
{
|
||||
if (fmt) {
|
||||
if (flags & VWARNINGF_INTERNAL)
|
||||
shf_fprintf(shl_out, "internal error: ");
|
||||
shf_fprintf(shl_out, Tf_sD_, "internal error");
|
||||
if (flags & VWARNINGF_ERRORPREFIX)
|
||||
error_prefix(tobool(flags & VWARNINGF_FILELINE));
|
||||
if ((flags & VWARNINGF_BUILTIN) &&
|
||||
/* not set when main() calls parse_args() */
|
||||
builtin_argv0 && builtin_argv0 != kshname)
|
||||
shf_fprintf(shl_out, "%s: ", builtin_argv0);
|
||||
shf_fprintf(shl_out, Tf_sD_, builtin_argv0);
|
||||
shf_vfprintf(shl_out, fmt, ap);
|
||||
shf_putchar('\n', shl_out);
|
||||
}
|
||||
@ -1301,7 +1301,7 @@ error_prefix(bool fileline)
|
||||
/* Avoid foo: foo[2]: ... */
|
||||
if (!fileline || !source || !source->file ||
|
||||
strcmp(source->file, kshname) != 0)
|
||||
shf_fprintf(shl_out, "%s: ", kshname + (*kshname == '-'));
|
||||
shf_fprintf(shl_out, Tf_sD_, kshname + (*kshname == '-'));
|
||||
if (fileline && source && source->file != NULL) {
|
||||
shf_fprintf(shl_out, "%s[%lu]: ", source->file,
|
||||
(unsigned long)(source->errline ?
|
||||
@ -1371,7 +1371,7 @@ initio(void)
|
||||
if ((lfp = getenv("SDMKSH_PATH")) == NULL) {
|
||||
if ((lfp = getenv("HOME")) == NULL || !mksh_abspath(lfp))
|
||||
errorf("cannot get home directory");
|
||||
lfp = shf_smprintf("%s/mksh-dbg.txt", lfp);
|
||||
lfp = shf_smprintf(Tf_sSs, lfp, "mksh-dbg.txt");
|
||||
}
|
||||
|
||||
if ((shl_dbg_fd = open(lfp, O_WRONLY | O_APPEND | O_CREAT, 0600)) < 0)
|
||||
|
55
misc.c
55
misc.c
@ -30,7 +30,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.242 2016/03/04 14:26:13 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.243 2016/07/25 00:04:45 tg Exp $");
|
||||
|
||||
#define KSH_CHVT_FLAG
|
||||
#ifdef MKSH_SMALL
|
||||
@ -443,7 +443,8 @@ parse_args(const char **argv,
|
||||
else if ((i != (size_t)-1) && (OFF(i) & what))
|
||||
change_flag((enum sh_flag)i, what, set);
|
||||
else {
|
||||
bi_errorf("%s: %s", go.optarg, "bad option");
|
||||
bi_errorf(Tf_sD_s, go.optarg,
|
||||
Tunknown_option);
|
||||
return (-1);
|
||||
}
|
||||
break;
|
||||
@ -504,7 +505,7 @@ parse_args(const char **argv,
|
||||
if (*array)
|
||||
ccp = skip_varname(array, false);
|
||||
if (!ccp || !(!ccp[0] || (ccp[0] == '+' && !ccp[1]))) {
|
||||
bi_errorf("%s: %s", array, "is not an identifier");
|
||||
bi_errorf(Tf_sD_s, array, Tnot_ident);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
@ -1038,10 +1039,10 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
|
||||
go->buf[0] = c;
|
||||
go->optarg = go->buf;
|
||||
} else {
|
||||
warningf(true, "%s%s-%c: %s",
|
||||
warningf(true, Tf_optfoo,
|
||||
(go->flags & GF_NONAME) ? "" : argv[0],
|
||||
(go->flags & GF_NONAME) ? "" : ": ", c,
|
||||
"unknown option");
|
||||
(go->flags & GF_NONAME) ? "" : Tcolsp,
|
||||
c, Tunknown_option);
|
||||
if (go->flags & GF_ERROR)
|
||||
bi_errorfz();
|
||||
}
|
||||
@ -1066,10 +1067,10 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
|
||||
go->optarg = go->buf;
|
||||
return (':');
|
||||
}
|
||||
warningf(true, "%s%s-%c: %s",
|
||||
warningf(true, Tf_optfoo,
|
||||
(go->flags & GF_NONAME) ? "" : argv[0],
|
||||
(go->flags & GF_NONAME) ? "" : ": ", c,
|
||||
"requires an argument");
|
||||
(go->flags & GF_NONAME) ? "" : Tcolsp,
|
||||
c, Treq_arg);
|
||||
if (go->flags & GF_ERROR)
|
||||
bi_errorfz();
|
||||
return ('?');
|
||||
@ -1419,7 +1420,7 @@ do_realpath(const char *upath)
|
||||
/* upath is a relative pathname, prepend cwd */
|
||||
if ((tp = ksh_get_wd()) == NULL || !mksh_abspath(tp))
|
||||
return (NULL);
|
||||
ipath = shf_smprintf("%s%s%s", tp, "/", upath);
|
||||
ipath = shf_smprintf(Tf_sss, tp, "/", upath);
|
||||
afree(tp, ATEMP);
|
||||
}
|
||||
|
||||
@ -1517,7 +1518,7 @@ do_realpath(const char *upath)
|
||||
* otherwise continue with currently resolved prefix
|
||||
*/
|
||||
/* append rest of current input path to link target */
|
||||
tp = shf_smprintf("%s%s%s", ldest, *ip ? "/" : "", ip);
|
||||
tp = shf_smprintf(Tf_sss, ldest, *ip ? "/" : "", ip);
|
||||
afree(ipath, ATEMP);
|
||||
ip = ipath = tp;
|
||||
if (!mksh_abspath(ldest)) {
|
||||
@ -1819,12 +1820,12 @@ c_cd(const char **wp)
|
||||
wp += builtin_opt.optind;
|
||||
|
||||
if (Flag(FRESTRICTED)) {
|
||||
bi_errorf("restricted shell - can't cd");
|
||||
bi_errorf(Tcant_cd);
|
||||
return (2);
|
||||
}
|
||||
|
||||
pwd_s = global("PWD");
|
||||
oldpwd_s = global("OLDPWD");
|
||||
pwd_s = global(TPWD);
|
||||
oldpwd_s = global(TOLDPWD);
|
||||
|
||||
if (!wp[0]) {
|
||||
/* No arguments - go home */
|
||||
@ -1840,7 +1841,7 @@ c_cd(const char **wp)
|
||||
allocd = NULL;
|
||||
dir = str_val(oldpwd_s);
|
||||
if (dir == null) {
|
||||
bi_errorf("no OLDPWD");
|
||||
bi_errorf(Tno_OLDPWD);
|
||||
return (2);
|
||||
}
|
||||
printpath = true;
|
||||
@ -1880,7 +1881,7 @@ c_cd(const char **wp)
|
||||
memcpy(dir + ilen + nlen, current_wd + ilen + olen, elen);
|
||||
printpath = true;
|
||||
} else {
|
||||
bi_errorf("too many arguments");
|
||||
bi_errorf(Ttoo_many_args);
|
||||
return (2);
|
||||
}
|
||||
|
||||
@ -1904,9 +1905,9 @@ c_cd(const char **wp)
|
||||
|
||||
if (rv < 0) {
|
||||
if (cdnode)
|
||||
bi_errorf("%s: %s", dir, "bad directory");
|
||||
bi_errorf(Tf_sD_s, dir, "bad directory");
|
||||
else
|
||||
bi_errorf("%s: %s", tryp, cstrerror(errno));
|
||||
bi_errorf(Tf_sD_s, tryp, cstrerror(errno));
|
||||
afree(allocd, ATEMP);
|
||||
Xfree(xs, xp);
|
||||
return (2);
|
||||
@ -1955,7 +1956,7 @@ c_cd(const char **wp)
|
||||
rv = 1;
|
||||
}
|
||||
if (printpath || cdnode)
|
||||
shprintf("%s\n", pwd);
|
||||
shprintf(Tf_sN, pwd);
|
||||
|
||||
afree(allocd, ATEMP);
|
||||
Xfree(xs, xp);
|
||||
@ -1990,18 +1991,18 @@ chvt(const Getopt *go)
|
||||
memmove(cp + 1, cp, /* /dev/tty */ 8);
|
||||
dv = cp + 1;
|
||||
if (stat(dv, &sb)) {
|
||||
errorf("%s: %s: %s", "chvt",
|
||||
errorf(Tf_sD_sD_s, "chvt",
|
||||
"can't find tty", go->optarg);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(sb.st_mode & S_IFCHR))
|
||||
errorf("%s: %s: %s", "chvt", "not a char device", dv);
|
||||
errorf(Tf_sD_sD_s, "chvt", "not a char device", dv);
|
||||
#ifndef MKSH_DISABLE_REVOKE_WARNING
|
||||
#if HAVE_REVOKE
|
||||
if (revoke(dv))
|
||||
#endif
|
||||
warningf(false, "%s: %s %s", "chvt",
|
||||
warningf(false, Tf_sD_s_s, "chvt",
|
||||
"new shell is potentially insecure, can't revoke",
|
||||
dv);
|
||||
#endif
|
||||
@ -2010,13 +2011,13 @@ chvt(const Getopt *go)
|
||||
if ((fd = binopen2(dv, O_RDWR)) < 0) {
|
||||
sleep(1);
|
||||
if ((fd = binopen2(dv, O_RDWR)) < 0) {
|
||||
errorf("%s: %s %s", "chvt", "can't open", dv);
|
||||
errorf(Tf_sD_s_s, "chvt", Tcant_open, dv);
|
||||
}
|
||||
}
|
||||
if (go->optarg[0] != '!') {
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
errorf("%s: %s %s", "chvt", "fork", "failed");
|
||||
errorf(Tf_sD_s_s, "chvt", "fork", "failed");
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
@ -2024,12 +2025,12 @@ chvt(const Getopt *go)
|
||||
}
|
||||
}
|
||||
if (setsid() == -1)
|
||||
errorf("%s: %s %s", "chvt", "setsid", "failed");
|
||||
errorf(Tf_sD_s_s, "chvt", "setsid", "failed");
|
||||
if (go->optarg[0] != '-') {
|
||||
if (ioctl(fd, TIOCSCTTY, NULL) == -1)
|
||||
errorf("%s: %s %s", "chvt", "TIOCSCTTY", "failed");
|
||||
errorf(Tf_sD_s_s, "chvt", "TIOCSCTTY", "failed");
|
||||
if (tcflush(fd, TCIOFLUSH))
|
||||
errorf("%s: %s %s", "chvt", "TCIOFLUSH", "failed");
|
||||
errorf(Tf_sD_s_s, "chvt", "TCIOFLUSH", "failed");
|
||||
}
|
||||
ksh_dup2(fd, 0, false);
|
||||
ksh_dup2(fd, 1, false);
|
||||
|
345
sh.h
345
sh.h
@ -175,9 +175,9 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.776 2016/07/24 23:10:04 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.777 2016/07/25 00:04:46 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R52 2016/07/12"
|
||||
#define MKSH_VERSION "R52 2016/07/24"
|
||||
|
||||
/* arithmetic types: C implementation */
|
||||
#if !HAVE_CAN_INTTYPES
|
||||
@ -844,49 +844,322 @@ EXTERN struct {
|
||||
#define OF_FIRSTTIME 0x10 /* as early as possible, once */
|
||||
#define OF_ANY (OF_CMDLINE | OF_SET | OF_SPECIAL | OF_INTERNAL)
|
||||
|
||||
/* trust GCC to have string pooling; -Wformat bitches otherwise */
|
||||
/*XXX TODO: make this with a .gen file plus not imake-style */
|
||||
|
||||
/* null value for variable; comparison pointer for unset */
|
||||
EXTERN char null[] E_INIT("");
|
||||
/* helpers for string pooling */
|
||||
#if defined(__GNUC__)
|
||||
#define Tsynerr "syntax error"
|
||||
#define Tintovfl "integer overflow %zu %c %zu prevented"
|
||||
#define Toomem "can't allocate %zu data bytes"
|
||||
#else
|
||||
EXTERN const char Tintovfl[] E_INIT("integer overflow %zu %c %zu prevented");
|
||||
EXTERN const char Toomem[] E_INIT("can't allocate %zu data bytes");
|
||||
EXTERN const char Tsynerr[] E_INIT("syntax error");
|
||||
|
||||
/* string pooling: do we rely on the compiler? */
|
||||
#ifndef HAVE_STRING_POOLING
|
||||
/* no, we use our own, saves quite some space */
|
||||
#elif HAVE_STRING_POOLING == 2
|
||||
/* “on demand” */
|
||||
#ifdef __GNUC__
|
||||
/* only for GCC 4 or later, older ones can get by without */
|
||||
#if __GNUC__ < 4
|
||||
#undef HAVE_STRING_POOLING
|
||||
#endif
|
||||
EXTERN const char Tselect[] E_INIT("select");
|
||||
EXTERN const char T_typeset[] E_INIT("=typeset");
|
||||
#define Ttypeset (T_typeset + 1) /* "typeset" */
|
||||
#else
|
||||
/* not GCC, default to on */
|
||||
#endif
|
||||
#elif HAVE_STRING_POOLING == 0
|
||||
/* default to on, unless explicitly set to 0 */
|
||||
#undef HAVE_STRING_POOLING
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRING_POOLING /* helpers for pooled strings */
|
||||
EXTERN const char T4spaces[] E_INIT(" ");
|
||||
#define T1space (T4spaces + 3)
|
||||
EXTERN const char Tcolsp[] E_INIT(": ");
|
||||
EXTERN const char TC_LEX1[] E_INIT("|&;<>() \t\n");
|
||||
#define TC_IFSWS (TC_LEX1 + 7)
|
||||
EXTERN const char TFCEDIT_dollaru[] E_INIT("${FCEDIT:-/bin/ed} $_");
|
||||
#define Tspdollaru (TFCEDIT_dollaru + 18)
|
||||
EXTERN const char Tsgdot[] E_INIT("*=.");
|
||||
EXTERN const char Taugo[] E_INIT("augo");
|
||||
EXTERN const char Tbracket[] E_INIT("[");
|
||||
#define Tdot (Tsgdot + 2)
|
||||
EXTERN const char Talias[] E_INIT("alias");
|
||||
EXTERN const char Tunalias[] E_INIT("unalias");
|
||||
EXTERN const char Tbadsubst[] E_INIT("bad substitution");
|
||||
EXTERN const char Tbg[] E_INIT("bg");
|
||||
EXTERN const char Tbad_bsize[] E_INIT("bad shf/buf/bsize");
|
||||
#define Tbsize (Tbad_bsize + 12)
|
||||
EXTERN const char Tbad_sig_ss[] E_INIT("%s: bad signal '%s'");
|
||||
#define Tbad_sig_s (Tbad_sig_ss + 4)
|
||||
EXTERN const char Tgbuiltin[] E_INIT("=builtin");
|
||||
#define Tbuiltin (Tgbuiltin + 1)
|
||||
EXTERN const char Toomem[] E_INIT("can't allocate %zu data bytes");
|
||||
EXTERN const char Tcant_cd[] E_INIT("restricted shell - can't cd");
|
||||
EXTERN const char Tcant_find[] E_INIT("can't find");
|
||||
EXTERN const char Tcant_open[] E_INIT("can't open");
|
||||
#define Tbytes (Toomem + 24)
|
||||
EXTERN const char Tbcat[] E_INIT("!cat");
|
||||
#define Tcat (Tbcat + 1)
|
||||
#define Tcd (Tcant_cd + 25)
|
||||
EXTERN const char Tcommand[] E_INIT("command");
|
||||
EXTERN const char Tcreate[] E_INIT("create");
|
||||
EXTERN const char TELIF_unexpected[] E_INIT("TELIF unexpected");
|
||||
EXTERN const char TEXECSHELL[] E_INIT("EXECSHELL");
|
||||
EXTERN const char Tsgexport[] E_INIT("*=export");
|
||||
#define Texport (Tsgexport + 2)
|
||||
#ifdef __OS2__
|
||||
EXTERN const char Textproc[] E_INIT("extproc");
|
||||
#endif
|
||||
EXTERN const char Tsgset[] E_INIT("*=set");
|
||||
#define Tset (Tsgset + 2) /* "set" */
|
||||
EXTERN const char Tsgexport[] E_INIT("*=export");
|
||||
#define Texport (Tsgexport + 2) /* "export" */
|
||||
EXTERN const char Tsgreadonly[] E_INIT("*=readonly");
|
||||
#define Treadonly (Tsgreadonly + 2) /* "readonly" */
|
||||
EXTERN const char Tgbuiltin[] E_INIT("=builtin");
|
||||
#define Tbuiltin (Tgbuiltin + 1) /* "builtin" */
|
||||
EXTERN const char T_function[] E_INIT(" function");
|
||||
#define Tfunction (T_function + 1) /* "function" */
|
||||
EXTERN const char T_funny_command[] E_INIT("funny $() command");
|
||||
#define Tcommand (T_funny_command + 10) /* "command" */
|
||||
#if defined(__GNUC__)
|
||||
#define Tfg_badsubst "fileglob: bad substitution"
|
||||
#else
|
||||
EXTERN const char Tfalse[] E_INIT("false");
|
||||
EXTERN const char Tfg[] E_INIT("fg");
|
||||
EXTERN const char Tfg_badsubst[] E_INIT("fileglob: bad substitution");
|
||||
EXTERN const char Tfile[] E_INIT("file");
|
||||
EXTERN const char Tfile_fd[] E_INIT("function definition file");
|
||||
EXTERN const char TFPATH[] E_INIT("FPATH");
|
||||
EXTERN const char T_function[] E_INIT(" function");
|
||||
#define Tfunction (T_function + 1)
|
||||
EXTERN const char T_funny_command[] E_INIT("funny $() command");
|
||||
EXTERN const char Tgetopts[] E_INIT("getopts");
|
||||
EXTERN const char Thistory[] E_INIT("history");
|
||||
EXTERN const char Tintovfl[] E_INIT("integer overflow %zu %c %zu prevented");
|
||||
EXTERN const char Tjobs[] E_INIT("jobs");
|
||||
EXTERN const char Tjob_not_started[] E_INIT("job not started");
|
||||
EXTERN const char Tmksh[] E_INIT("mksh");
|
||||
EXTERN const char Tname[] E_INIT("name");
|
||||
EXTERN const char Tno_args[] E_INIT("missing argument");
|
||||
EXTERN const char Tno_OLDPWD[] E_INIT("no OLDPWD");
|
||||
EXTERN const char Tnot_ident[] E_INIT("is not an identifier");
|
||||
EXTERN const char Tnot_in_history[] E_INIT("not in history");
|
||||
EXTERN const char Tnot_found_s[] E_INIT("%s not found");
|
||||
#define Tnot_found (Tnot_found_s + 3)
|
||||
#define Tnot_started (Tjob_not_started + 4)
|
||||
#define TOLDPWD (Tno_OLDPWD + 3)
|
||||
#define Topen (Tcant_open + 6)
|
||||
#define TPATH (TFPATH + 1)
|
||||
EXTERN const char Tpv[] E_INIT("pv");
|
||||
EXTERN const char TpVv[] E_INIT("Vpv");
|
||||
#define TPWD (Tno_OLDPWD + 6)
|
||||
EXTERN const char Tread[] E_INIT("read");
|
||||
EXTERN const char Tsgreadonly[] E_INIT("*=readonly");
|
||||
#define Treadonly (Tsgreadonly + 2)
|
||||
EXTERN const char Tredirection_dup[] E_INIT("can't finish (dup) redirection");
|
||||
#define Tredirection (Tredirection_dup + 19)
|
||||
EXTERN const char Treal_sp1[] E_INIT("real ");
|
||||
EXTERN const char Treal_sp2[] E_INIT(" real ");
|
||||
EXTERN const char Trename[] E_INIT("rename");
|
||||
EXTERN const char Treq_arg[] E_INIT("requires an argument");
|
||||
EXTERN const char Tselect[] E_INIT("select");
|
||||
EXTERN const char Tsgset[] E_INIT("*=set");
|
||||
#define Tset (Tsgset + 2)
|
||||
#define Tsh (Tmksh + 2)
|
||||
#define TSHELL (TEXECSHELL + 4)
|
||||
EXTERN const char Tshf_read[] E_INIT("shf_read");
|
||||
EXTERN const char Tshf_write[] E_INIT("shf_write");
|
||||
EXTERN const char Tj_suspend[] E_INIT("j_suspend");
|
||||
#define Tsuspend (Tj_suspend + 2)
|
||||
EXTERN const char Tsynerr[] E_INIT("syntax error");
|
||||
EXTERN const char Ttime[] E_INIT("time");
|
||||
EXTERN const char Ttoo_many_args[] E_INIT("too many arguments");
|
||||
EXTERN const char Ttrue[] E_INIT("true");
|
||||
EXTERN const char Ttty_fd_dupof[] E_INIT("dup of tty fd");
|
||||
#define Ttty_fd (Ttty_fd_dupof + 7)
|
||||
EXTERN const char Tgtypeset[] E_INIT("=typeset");
|
||||
#define Ttypeset (Tgtypeset + 1)
|
||||
#define Tugo (Taugo + 1)
|
||||
EXTERN const char Tunalias[] E_INIT("unalias");
|
||||
#define Tunexpected (TELIF_unexpected + 6)
|
||||
EXTERN const char Tunknown_option[] E_INIT("unknown option");
|
||||
EXTERN const char Tuser_sp1[] E_INIT("user ");
|
||||
EXTERN const char Tuser_sp2[] E_INIT(" user ");
|
||||
#define Twrite (Tshf_write + 4)
|
||||
EXTERN const char Tf__S[] E_INIT(" %S");
|
||||
EXTERN const char Tf__d[] E_INIT(" %d");
|
||||
EXTERN const char Tf__ss[] E_INIT(" %s%s");
|
||||
EXTERN const char Tf__sN[] E_INIT(" %s\n");
|
||||
EXTERN const char Tf_sSs[] E_INIT("%s/%s");
|
||||
EXTERN const char Tf_T[] E_INIT("%T");
|
||||
EXTERN const char Tf_dN[] E_INIT("%d\n");
|
||||
EXTERN const char Tf_s_[] E_INIT("%s ");
|
||||
EXTERN const char Tf_s_T[] E_INIT("%s %T");
|
||||
EXTERN const char Tf_s_s_sN[] E_INIT("%s %s %s\n");
|
||||
EXTERN const char Tf_s_s[] E_INIT("%s %s");
|
||||
EXTERN const char Tf_s_sD_s[] E_INIT("%s %s: %s");
|
||||
EXTERN const char Tf_optfoo[] E_INIT("%s%s-%c: %s");
|
||||
EXTERN const char Tf_sD_[] E_INIT("%s: ");
|
||||
EXTERN const char Tf_szs[] E_INIT("%s: %zd %s");
|
||||
EXTERN const char Tf_parm[] E_INIT("%s: parameter not set");
|
||||
EXTERN const char Tf_coproc[] E_INIT("-p: %s");
|
||||
EXTERN const char Tf_cant[] E_INIT("can't %s %s: %s");
|
||||
EXTERN const char Tf_heredoc[] E_INIT("here document '%s' unclosed\n");
|
||||
#if HAVE_MKNOD
|
||||
EXTERN const char Tf_nonnum[] E_INIT("non-numeric %s %s '%s'");
|
||||
#endif
|
||||
#define Tbadsubst (Tfg_badsubst + 10) /* "bad substitution" */
|
||||
EXTERN const char TC_LEX1[] E_INIT("|&;<>() \t\n");
|
||||
#define TC_IFSWS (TC_LEX1 + 7) /* space tab newline */
|
||||
EXTERN const char Tf_S_[] E_INIT("%S ");
|
||||
#define Tf_S (Tf__S + 1)
|
||||
EXTERN const char Tf_lu[] E_INIT("%lu");
|
||||
EXTERN const char Tf_toolarge[] E_INIT("%s %s too large: %lu");
|
||||
EXTERN const char Tf_ldfailed[] E_INIT("%s %s(%d, %ld) failed: %s");
|
||||
#define Tf_ss (Tf__ss + 1)
|
||||
EXTERN const char Tf_sss[] E_INIT("%s%s%s");
|
||||
EXTERN const char Tf_sD_s_sD_s[] E_INIT("%s: %s %s: %s");
|
||||
EXTERN const char Tf_toomany[] E_INIT("too many %ss\n");
|
||||
EXTERN const char Tf_sd[] E_INIT("%s %d");
|
||||
#define Tf_s (Tf__ss + 3)
|
||||
EXTERN const char Tft_end[] E_INIT("%;");
|
||||
EXTERN const char Tft_R[] E_INIT("%R");
|
||||
#define Tf_d (Tf__d + 1)
|
||||
EXTERN const char Tf_sD_s_qs[] E_INIT("%s: %s '%s'");
|
||||
EXTERN const char Tf_ro[] E_INIT("read-only: %s");
|
||||
EXTERN const char Tf_flags[] E_INIT("%s: flags 0x%X");
|
||||
EXTERN const char Tf_temp[] E_INIT("can't %s temporary file %s: %s");
|
||||
EXTERN const char Tf_ssfaileds[] E_INIT("%s: %s failed: %s");
|
||||
EXTERN const char Tf_sD_sD_s[] E_INIT("%s: %s: %s");
|
||||
EXTERN const char Tf__c_[] E_INIT("-%c ");
|
||||
EXTERN const char Tf_sD_s_s[] E_INIT("%s: %s %s");
|
||||
#define Tf_sN (Tf__sN + 1)
|
||||
#define Tf_sD_s (Tf_s_sD_s + 3)
|
||||
EXTERN const char T_devtty[] E_INIT("/dev/tty");
|
||||
#else /* helpers for string pooling */
|
||||
#define T4spaces " "
|
||||
#define T1space " "
|
||||
#define Tcolsp ": "
|
||||
#define TC_LEX1 "|&;<>() \t\n"
|
||||
#define TC_IFSWS " \t\n"
|
||||
#define TFCEDIT_dollaru "${FCEDIT:-/bin/ed} $_"
|
||||
#define Tspdollaru " $_"
|
||||
#define Tsgdot "*=."
|
||||
#define Taugo "augo"
|
||||
#define Tbracket "["
|
||||
#define Tdot "."
|
||||
#define Talias "alias"
|
||||
#define Tbadsubst "bad substitution"
|
||||
#define Tbg "bg"
|
||||
#define Tbad_bsize "bad shf/buf/bsize"
|
||||
#define Tbsize "bsize"
|
||||
#define Tbad_sig_ss "%s: bad signal '%s'"
|
||||
#define Tbad_sig_s "bad signal '%s'"
|
||||
#define Tgbuiltin "=builtin"
|
||||
#define Tbuiltin "builtin"
|
||||
#define Toomem "can't allocate %zu data bytes"
|
||||
#define Tcant_cd "restricted shell - can't cd"
|
||||
#define Tcant_find "can't find"
|
||||
#define Tcant_open "can't open"
|
||||
#define Tbytes "bytes"
|
||||
#define Tbcat "!cat"
|
||||
#define Tcat "cat"
|
||||
#define Tcd "cd"
|
||||
#define Tcommand "command"
|
||||
#define Tcreate "create"
|
||||
#define TELIF_unexpected "TELIF unexpected"
|
||||
#define TEXECSHELL "EXECSHELL"
|
||||
#define Tsgexport "*=export"
|
||||
#define Texport "export"
|
||||
#ifdef __OS2__
|
||||
#define Textproc "extproc"
|
||||
#endif
|
||||
#define Tfalse "false"
|
||||
#define Tfg "fg"
|
||||
#define Tfg_badsubst "fileglob: bad substitution"
|
||||
#define Tfile "file"
|
||||
#define Tfile_fd "function definition file"
|
||||
#define TFPATH "FPATH"
|
||||
#define T_function " function"
|
||||
#define Tfunction "function"
|
||||
#define T_funny_command "funny $() command"
|
||||
#define Tgetopts "getopts"
|
||||
#define Thistory "history"
|
||||
#define Tintovfl "integer overflow %zu %c %zu prevented"
|
||||
#define Tjobs "jobs"
|
||||
#define Tjob_not_started "job not started"
|
||||
#define Tmksh "mksh"
|
||||
#define Tname "name"
|
||||
#define Tno_args "missing argument"
|
||||
#define Tno_OLDPWD "no OLDPWD"
|
||||
#define Tnot_ident "is not an identifier"
|
||||
#define Tnot_in_history "not in history"
|
||||
#define Tnot_found_s "%s not found"
|
||||
#define Tnot_found "not found"
|
||||
#define Tnot_started "not started"
|
||||
#define TOLDPWD "OLDPWD"
|
||||
#define Topen "open"
|
||||
#define TPATH "PATH"
|
||||
#define Tpv "pv"
|
||||
#define TpVv "Vpv"
|
||||
#define TPWD "PWD"
|
||||
#define Tread "read"
|
||||
#define Tsgreadonly "*=readonly"
|
||||
#define Treadonly "readonly"
|
||||
#define Tredirection_dup "can't finish (dup) redirection"
|
||||
#define Tredirection "redirection"
|
||||
#define Treal_sp1 "real "
|
||||
#define Treal_sp2 " real "
|
||||
#define Trename "rename"
|
||||
#define Treq_arg "requires an argument"
|
||||
#define Tselect "select"
|
||||
#define Tsgset "*=set"
|
||||
#define Tset "set"
|
||||
#define Tsh "sh"
|
||||
#define TSHELL "SHELL"
|
||||
#define Tshf_read "shf_read"
|
||||
#define Tshf_write "shf_write"
|
||||
#define Tj_suspend "j_suspend"
|
||||
#define Tsuspend "suspend"
|
||||
#define Tsynerr "syntax error"
|
||||
#define Ttime "time"
|
||||
#define Ttoo_many_args "too many arguments"
|
||||
#define Ttrue "true"
|
||||
#define Ttty_fd_dupof "dup of tty fd"
|
||||
#define Ttty_fd "tty fd"
|
||||
#define Tgtypeset "=typeset"
|
||||
#define Ttypeset "typeset"
|
||||
#define Tugo "ugo"
|
||||
#define Tunalias "unalias"
|
||||
#define Tunexpected "unexpected"
|
||||
#define Tunknown_option "unknown option"
|
||||
#define Tuser_sp1 "user "
|
||||
#define Tuser_sp2 " user "
|
||||
#define Twrite "write"
|
||||
#define Tf__S " %S"
|
||||
#define Tf__d " %d"
|
||||
#define Tf__ss " %s%s"
|
||||
#define Tf__sN " %s\n"
|
||||
#define Tf_sSs "%s/%s"
|
||||
#define Tf_T "%T"
|
||||
#define Tf_dN "%d\n"
|
||||
#define Tf_s_ "%s "
|
||||
#define Tf_s_T "%s %T"
|
||||
#define Tf_s_s_sN "%s %s %s\n"
|
||||
#define Tf_s_s "%s %s"
|
||||
#define Tf_s_sD_s "%s %s: %s"
|
||||
#define Tf_optfoo "%s%s-%c: %s"
|
||||
#define Tf_sD_ "%s: "
|
||||
#define Tf_szs "%s: %zd %s"
|
||||
#define Tf_parm "%s: parameter not set"
|
||||
#define Tf_coproc "-p: %s"
|
||||
#define Tf_cant "can't %s %s: %s"
|
||||
#define Tf_heredoc "here document '%s' unclosed\n"
|
||||
#if HAVE_MKNOD
|
||||
#define Tf_nonnum "non-numeric %s %s '%s'"
|
||||
#endif
|
||||
#define Tf_S_ "%S "
|
||||
#define Tf_S "%S"
|
||||
#define Tf_lu "%lu"
|
||||
#define Tf_toolarge "%s %s too large: %lu"
|
||||
#define Tf_ldfailed "%s %s(%d, %ld) failed: %s"
|
||||
#define Tf_ss "%s%s"
|
||||
#define Tf_sss "%s%s%s"
|
||||
#define Tf_sD_s_sD_s "%s: %s %s: %s"
|
||||
#define Tf_toomany "too many %ss\n"
|
||||
#define Tf_sd "%s %d"
|
||||
#define Tf_s "%s"
|
||||
#define Tft_end "%;"
|
||||
#define Tft_R "%R"
|
||||
#define Tf_d "%d"
|
||||
#define Tf_sD_s_qs "%s: %s '%s'"
|
||||
#define Tf_ro "read-only: %s"
|
||||
#define Tf_flags "%s: flags 0x%X"
|
||||
#define Tf_temp "can't %s temporary file %s: %s"
|
||||
#define Tf_ssfaileds "%s: %s failed: %s"
|
||||
#define Tf_sD_sD_s "%s: %s: %s"
|
||||
#define Tf__c_ "-%c "
|
||||
#define Tf_sD_s_s "%s: %s %s"
|
||||
#define Tf_sN "%s\n"
|
||||
#define Tf_sD_s "%s: %s"
|
||||
#define T_devtty "/dev/tty"
|
||||
#endif /* end of string pooling */
|
||||
|
||||
typedef uint8_t Temp_type;
|
||||
/* expanded heredoc */
|
||||
|
32
shf.c
32
shf.c
@ -25,7 +25,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.75 2016/07/24 23:07:19 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.76 2016/07/25 00:04:47 tg Exp $");
|
||||
|
||||
/* flags to shf_emptybuf() */
|
||||
#define EB_READSW 0x01 /* about to switch to reading */
|
||||
@ -119,7 +119,7 @@ shf_open_hlp(int fd, int *sflagsp, const char *where)
|
||||
}
|
||||
|
||||
if (!(sflags & (SHF_RD | SHF_WR)))
|
||||
internal_errorf("%s: %s", where, "missing read/write");
|
||||
internal_errorf(Tf_sD_s, where, "missing read/write");
|
||||
}
|
||||
|
||||
/* Set up the shf structure for a file descriptor. Doesn't fail. */
|
||||
@ -167,7 +167,7 @@ shf_reopen(int fd, int sflags, struct shf *shf)
|
||||
|
||||
shf_open_hlp(fd, &sflags, "shf_reopen");
|
||||
if (!shf || !shf->buf || shf->bsize < bsize)
|
||||
internal_errorf("%s: %s", "shf_reopen", "bad shf/buf/bsize");
|
||||
internal_errorf(Tf_sD_s, "shf_reopen", Tbad_bsize);
|
||||
|
||||
/* assumes shf->buf and shf->bsize already set up */
|
||||
shf->fd = fd;
|
||||
@ -197,7 +197,7 @@ shf_sopen(char *buf, ssize_t bsize, int sflags, struct shf *shf)
|
||||
{
|
||||
/* can't have a read+write string */
|
||||
if (!(!(sflags & SHF_RD) ^ !(sflags & SHF_WR)))
|
||||
internal_errorf("%s: flags 0x%X", "shf_sopen",
|
||||
internal_errorf(Tf_flags, "shf_sopen",
|
||||
(unsigned int)sflags);
|
||||
|
||||
if (!shf) {
|
||||
@ -293,7 +293,7 @@ shf_flush(struct shf *shf)
|
||||
return ((shf->flags & SHF_WR) ? -1 : 0);
|
||||
|
||||
if (shf->fd < 0)
|
||||
internal_errorf("%s: %s", "shf_flush", "no fd");
|
||||
internal_errorf(Tf_sD_s, "shf_flush", "no fd");
|
||||
|
||||
if (shf->flags & SHF_ERROR) {
|
||||
errno = shf->errnosv;
|
||||
@ -324,7 +324,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
||||
int ret = 0;
|
||||
|
||||
if (!(shf->flags & SHF_STRING) && shf->fd < 0)
|
||||
internal_errorf("%s: %s", "shf_emptybuf", "no fd");
|
||||
internal_errorf(Tf_sD_s, "shf_emptybuf", "no fd");
|
||||
|
||||
if (shf->flags & SHF_ERROR) {
|
||||
errno = shf->errnosv;
|
||||
@ -410,7 +410,7 @@ shf_fillbuf(struct shf *shf)
|
||||
return (0);
|
||||
|
||||
if (shf->fd < 0)
|
||||
internal_errorf("%s: %s", "shf_fillbuf", "no fd");
|
||||
internal_errorf(Tf_sD_s, "shf_fillbuf", "no fd");
|
||||
|
||||
if (shf->flags & (SHF_EOF | SHF_ERROR)) {
|
||||
if (shf->flags & SHF_ERROR)
|
||||
@ -453,11 +453,11 @@ shf_read(char *buf, ssize_t bsize, struct shf *shf)
|
||||
ssize_t ncopy, orig_bsize = bsize;
|
||||
|
||||
if (!(shf->flags & SHF_RD))
|
||||
internal_errorf("%s: flags 0x%X", "shf_read",
|
||||
internal_errorf(Tf_flags, Tshf_read,
|
||||
(unsigned int)shf->flags);
|
||||
|
||||
if (bsize <= 0)
|
||||
internal_errorf("%s: %s %zd", "shf_read", "bsize", bsize);
|
||||
internal_errorf(Tf_szs, Tshf_read, bsize, Tbsize);
|
||||
|
||||
while (bsize > 0) {
|
||||
if (shf->rnleft == 0 &&
|
||||
@ -491,7 +491,7 @@ shf_getse(char *buf, ssize_t bsize, struct shf *shf)
|
||||
char *orig_buf = buf;
|
||||
|
||||
if (!(shf->flags & SHF_RD))
|
||||
internal_errorf("%s: flags 0x%X", "shf_getse",
|
||||
internal_errorf(Tf_flags, "shf_getse",
|
||||
(unsigned int)shf->flags);
|
||||
|
||||
if (bsize <= 0)
|
||||
@ -528,7 +528,7 @@ int
|
||||
shf_getchar(struct shf *shf)
|
||||
{
|
||||
if (!(shf->flags & SHF_RD))
|
||||
internal_errorf("%s: flags 0x%X", "shf_getchar",
|
||||
internal_errorf(Tf_flags, "shf_getchar",
|
||||
(unsigned int)shf->flags);
|
||||
|
||||
if (shf->rnleft == 0 && (shf_fillbuf(shf) == -1 || shf->rnleft == 0))
|
||||
@ -545,7 +545,7 @@ int
|
||||
shf_ungetc(int c, struct shf *shf)
|
||||
{
|
||||
if (!(shf->flags & SHF_RD))
|
||||
internal_errorf("%s: flags 0x%X", "shf_ungetc",
|
||||
internal_errorf(Tf_flags, "shf_ungetc",
|
||||
(unsigned int)shf->flags);
|
||||
|
||||
if ((shf->flags & SHF_ERROR) || c == -1 ||
|
||||
@ -583,7 +583,7 @@ int
|
||||
shf_putchar(int c, struct shf *shf)
|
||||
{
|
||||
if (!(shf->flags & SHF_WR))
|
||||
internal_errorf("%s: flags 0x%X", "shf_putchar",
|
||||
internal_errorf(Tf_flags, "shf_putchar",
|
||||
(unsigned int)shf->flags);
|
||||
|
||||
if (c == -1)
|
||||
@ -594,7 +594,7 @@ shf_putchar(int c, struct shf *shf)
|
||||
ssize_t n;
|
||||
|
||||
if (shf->fd < 0)
|
||||
internal_errorf("%s: %s", "shf_putchar", "no fd");
|
||||
internal_errorf(Tf_sD_s, "shf_putchar", "no fd");
|
||||
if (shf->flags & SHF_ERROR) {
|
||||
errno = shf->errnosv;
|
||||
return (-1);
|
||||
@ -639,11 +639,11 @@ shf_write(const char *buf, ssize_t nbytes, struct shf *shf)
|
||||
ssize_t n, ncopy, orig_nbytes = nbytes;
|
||||
|
||||
if (!(shf->flags & SHF_WR))
|
||||
internal_errorf("%s: flags 0x%X", "shf_write",
|
||||
internal_errorf(Tf_flags, Tshf_write,
|
||||
(unsigned int)shf->flags);
|
||||
|
||||
if (nbytes < 0)
|
||||
internal_errorf("%s: %s %zd", "shf_write", "nbytes", nbytes);
|
||||
internal_errorf(Tf_szs, Tshf_write, nbytes, Tbytes);
|
||||
|
||||
/* Don't buffer if buffer is empty and we're writting a large amount. */
|
||||
if ((ncopy = shf->wnleft) &&
|
||||
|
20
syn.c
20
syn.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.111 2016/02/26 21:24:58 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.112 2016/07/25 00:04:48 tg Exp $");
|
||||
|
||||
struct nesting_state {
|
||||
int start_token; /* token than began nesting (eg, FOR) */
|
||||
@ -208,7 +208,7 @@ synio(int cf)
|
||||
iop->ioflag |= IOEVAL;
|
||||
}
|
||||
if (herep > &heres[HERES - 1])
|
||||
yyerror("too many %ss\n", "<<");
|
||||
yyerror(Tf_toomany, "<<");
|
||||
*herep++ = iop;
|
||||
} else
|
||||
iop->ioname = yylval.cp;
|
||||
@ -312,8 +312,8 @@ get_command(int cf)
|
||||
case REDIR:
|
||||
while ((iop = synio(cf)) != NULL) {
|
||||
if (iopn >= NUFILE)
|
||||
yyerror("too many %ss\n",
|
||||
"redirection");
|
||||
yyerror(Tf_toomany,
|
||||
Tredirection);
|
||||
iops[iopn++] = iop;
|
||||
}
|
||||
break;
|
||||
@ -512,7 +512,7 @@ get_command(int cf)
|
||||
|
||||
while ((iop = synio(syniocf)) != NULL) {
|
||||
if (iopn >= NUFILE)
|
||||
yyerror("too many %ss\n", "redirection");
|
||||
yyerror(Tf_toomany, Tredirection);
|
||||
iops[iopn++] = iop;
|
||||
}
|
||||
|
||||
@ -813,7 +813,7 @@ static const struct tokeninfo {
|
||||
{ "done", DONE, true },
|
||||
{ "in", IN, true },
|
||||
{ Tfunction, FUNCTION, true },
|
||||
{ "time", TIME, true },
|
||||
{ Ttime, TIME, true },
|
||||
{ "{", '{', true },
|
||||
{ Tcbrace, '}', true },
|
||||
{ "!", BANG, true },
|
||||
@ -860,7 +860,7 @@ syntaxerr(const char *what)
|
||||
int c;
|
||||
|
||||
if (!what)
|
||||
what = "unexpected";
|
||||
what = Tunexpected;
|
||||
REJECT;
|
||||
c = token(0);
|
||||
Again:
|
||||
@ -877,11 +877,11 @@ syntaxerr(const char *what)
|
||||
/* NOTREACHED */
|
||||
|
||||
case LWORD:
|
||||
s = snptreef(NULL, 32, "%S", yylval.cp);
|
||||
s = snptreef(NULL, 32, Tf_S, yylval.cp);
|
||||
break;
|
||||
|
||||
case REDIR:
|
||||
s = snptreef(redir, sizeof(redir), "%R", yylval.iop);
|
||||
s = snptreef(redir, sizeof(redir), Tft_R, yylval.iop);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -1188,7 +1188,7 @@ yyrecursive(int subtype MKSH_A_UNUSED)
|
||||
yyrecursive_pop(false);
|
||||
|
||||
/* t->left because nested(TPAREN, ...) hides our goodies there */
|
||||
cp = snptreef(NULL, 0, "%T", t->left);
|
||||
cp = snptreef(NULL, 0, Tf_T, t->left);
|
||||
tfree(t, ATEMP);
|
||||
|
||||
return (cp);
|
||||
|
42
tree.c
42
tree.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.85 2016/06/26 00:09:35 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.86 2016/07/25 00:04:48 tg Exp $");
|
||||
|
||||
#define INDENT 8
|
||||
|
||||
@ -74,20 +74,20 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
ccp[0] == CHAR && ((ccp[1] == '=' && ccp[2] == EOS) ||
|
||||
/* or "varname+=" */ (ccp[1] == '+' && ccp[2] == CHAR &&
|
||||
ccp[3] == '=' && ccp[4] == EOS))) {
|
||||
fptreef(shf, indent, "%S", t->vars[0]);
|
||||
fptreef(shf, indent, Tf_S, t->vars[0]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (t->vars) {
|
||||
w = (const char **)t->vars;
|
||||
while (*w)
|
||||
fptreef(shf, indent, "%S ", *w++);
|
||||
fptreef(shf, indent, Tf_S_, *w++);
|
||||
} else
|
||||
shf_puts("#no-vars# ", shf);
|
||||
if (t->args) {
|
||||
w = t->args;
|
||||
while (*w)
|
||||
fptreef(shf, indent, "%S ", *w++);
|
||||
fptreef(shf, indent, Tf_S_, *w++);
|
||||
} else
|
||||
shf_puts("#no-args# ", shf);
|
||||
break;
|
||||
@ -119,7 +119,7 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
w = t->args;
|
||||
shf_puts("[[", shf);
|
||||
while (*w)
|
||||
fptreef(shf, indent, " %S", *w++);
|
||||
fptreef(shf, indent, Tf__S, *w++);
|
||||
shf_puts(" ]] ", shf);
|
||||
break;
|
||||
case TSELECT:
|
||||
@ -130,8 +130,8 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
shf_puts("in ", shf);
|
||||
w = (const char **)t->vars;
|
||||
while (*w)
|
||||
fptreef(shf, indent, "%S ", *w++);
|
||||
fptreef(shf, indent, "%;");
|
||||
fptreef(shf, indent, Tf_S_, *w++);
|
||||
fptreef(shf, indent, Tft_end);
|
||||
}
|
||||
fptreef(shf, indent + INDENT, "do%N%T", t->left);
|
||||
fptreef(shf, indent, "%;done ");
|
||||
@ -151,11 +151,9 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
}
|
||||
fptreef(shf, indent, "%Nesac ");
|
||||
break;
|
||||
#ifdef DEBUG
|
||||
case TELIF:
|
||||
internal_errorf("TELIF in tree.c:ptree() unexpected");
|
||||
internal_errorf(TELIF_unexpected);
|
||||
/* FALLTHROUGH */
|
||||
#endif
|
||||
case TIF:
|
||||
i = 2;
|
||||
t1 = t;
|
||||
@ -163,19 +161,19 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
do {
|
||||
t1 = t1->right;
|
||||
i = 0;
|
||||
fptreef(shf, indent, "%;");
|
||||
fptreef(shf, indent, Tft_end);
|
||||
process_TIF:
|
||||
/* 5 == strlen("elif ") */
|
||||
fptreef(shf, indent + 5 - i, Telif_pT + i, t1->left);
|
||||
t1 = t1->right;
|
||||
if (t1->left != NULL) {
|
||||
fptreef(shf, indent, "%;");
|
||||
fptreef(shf, indent, Tft_end);
|
||||
fptreef(shf, indent + INDENT, "%s%N%T",
|
||||
"then", t1->left);
|
||||
}
|
||||
} while (t1->right && t1->right->type == TELIF);
|
||||
if (t1->right != NULL) {
|
||||
fptreef(shf, indent, "%;");
|
||||
fptreef(shf, indent, Tft_end);
|
||||
fptreef(shf, indent + INDENT, "%s%N%T",
|
||||
"else", t1->right);
|
||||
}
|
||||
@ -184,10 +182,10 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
case TWHILE:
|
||||
case TUNTIL:
|
||||
/* 6 == strlen("while "/"until ") */
|
||||
fptreef(shf, indent + 6, "%s %T",
|
||||
fptreef(shf, indent + 6, Tf_s_T,
|
||||
(t->type == TWHILE) ? "while" : "until",
|
||||
t->left);
|
||||
fptreef(shf, indent, "%;");
|
||||
fptreef(shf, indent, Tft_end);
|
||||
fptreef(shf, indent + INDENT, "do%N%T", t->right);
|
||||
fptreef(shf, indent, "%;done ");
|
||||
break;
|
||||
@ -207,7 +205,7 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
fpFUNCTf(shf, indent, tobool(t->u.ksh_func), t->str, t->left);
|
||||
break;
|
||||
case TTIME:
|
||||
fptreef(shf, indent, "%s %T", "time", t->left);
|
||||
fptreef(shf, indent, Tf_s_T, Ttime, t->left);
|
||||
break;
|
||||
default:
|
||||
shf_puts("<botch>", shf);
|
||||
@ -229,7 +227,7 @@ ptree(struct op *t, int indent, struct shf *shf)
|
||||
iop->heredoc) {
|
||||
shf_putc('\n', shf);
|
||||
shf_puts(iop->heredoc, shf);
|
||||
fptreef(shf, indent, "%s",
|
||||
fptreef(shf, indent, Tf_s,
|
||||
evalstr(iop->delim, 0));
|
||||
need_nl = true;
|
||||
}
|
||||
@ -258,7 +256,7 @@ pioact(struct shf *shf, struct ioword *iop)
|
||||
(type == IODUP && (iop->unit == !(flag & IORDUP))) ? iop->unit :
|
||||
iop->unit + 1;
|
||||
if (iop->unit != expected)
|
||||
shf_fprintf(shf, "%d", (int)iop->unit);
|
||||
shf_fprintf(shf, Tf_d, (int)iop->unit);
|
||||
|
||||
switch (type) {
|
||||
case IOREAD:
|
||||
@ -472,7 +470,7 @@ vfptreef(struct shf *shf, int indent, const char *fmt, va_list va)
|
||||
break;
|
||||
case 'd':
|
||||
/* signed decimal */
|
||||
shf_fprintf(shf, "%d", va_arg(va, int));
|
||||
shf_fprintf(shf, Tf_d, va_arg(va, int));
|
||||
break;
|
||||
case 'u':
|
||||
/* unsigned decimal */
|
||||
@ -768,7 +766,7 @@ vistree(char *dst, size_t sz, struct op *t)
|
||||
size_t n;
|
||||
|
||||
buf = alloc(sz + 16, ATEMP);
|
||||
snptreef(buf, sz + 16, "%T", t);
|
||||
snptreef(buf, sz + 16, Tf_T, t);
|
||||
cp = buf;
|
||||
vist_loop:
|
||||
if (UTFMODE && (n = utf_mbtowc(&c, cp)) != (size_t)-1) {
|
||||
@ -1107,7 +1105,7 @@ dumptree(struct shf *shf, struct op *t)
|
||||
goto dumpleftandout;
|
||||
OPEN(TFUNCT)
|
||||
shf_fprintf(shf, " str<%s> ksh<%s>", t->str,
|
||||
t->u.ksh_func ? "true" : "false");
|
||||
t->u.ksh_func ? Ttrue : Tfalse);
|
||||
goto dumpleftandout;
|
||||
OPEN(TTIME)
|
||||
goto dumpleftandout;
|
||||
@ -1134,7 +1132,7 @@ dumptree(struct shf *shf, struct op *t)
|
||||
break;
|
||||
OPEN(TEOF)
|
||||
dumpunexpected:
|
||||
shf_puts("unexpected", shf);
|
||||
shf_puts(Tunexpected, shf);
|
||||
break;
|
||||
OPEN(TELIF)
|
||||
goto dumpunexpected;
|
||||
|
30
var.c
30
var.c
@ -28,7 +28,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.203 2016/07/12 23:06:26 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.204 2016/07/25 00:04:48 tg Exp $");
|
||||
|
||||
/*-
|
||||
* Variables
|
||||
@ -193,7 +193,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
|
||||
char *cp;
|
||||
|
||||
/* gotcha! */
|
||||
cp = shf_smprintf("%s%s", str_val(vp), p);
|
||||
cp = shf_smprintf(Tf_ss, str_val(vp), p);
|
||||
afree(ap, ATEMP);
|
||||
n = ap = cp;
|
||||
goto redo_from_ref;
|
||||
@ -249,7 +249,7 @@ global(const char *n)
|
||||
if (ksh_isdigit(c)) {
|
||||
if (getn(vn, &c)) {
|
||||
/* main.c:main_init() says 12 */
|
||||
shf_snprintf(vp->name, 12, "%d", c);
|
||||
shf_snprintf(vp->name, 12, Tf_d, c);
|
||||
if (c <= l->argc) {
|
||||
/* setstr can't fail here */
|
||||
setstr(vp, l->argv[c],
|
||||
@ -441,7 +441,7 @@ setstr(struct tbl *vq, const char *s, int error_ok)
|
||||
|
||||
error_ok &= ~0x4;
|
||||
if ((vq->flag & RDONLY) && !no_ro_check) {
|
||||
warningf(true, "read-only: %s", vq->name);
|
||||
warningf(true, Tf_ro, vq->name);
|
||||
if (!error_ok)
|
||||
errorfxz(2);
|
||||
return (0);
|
||||
@ -768,7 +768,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
|
||||
}
|
||||
if (*val == '[') {
|
||||
if (new_refflag != SRF_NOP)
|
||||
errorf("%s: %s", var,
|
||||
errorf(Tf_sD_s, var,
|
||||
"reference variable can't be an array");
|
||||
len = array_ref_len(val);
|
||||
if (len == 0)
|
||||
@ -844,7 +844,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
|
||||
goto nameref_rhs_checked;
|
||||
}
|
||||
nameref_empty:
|
||||
errorf("%s: %s", var, "empty nameref target");
|
||||
errorf(Tf_sD_s, var, "empty nameref target");
|
||||
}
|
||||
len = (*ccp == '[') ? array_ref_len(ccp) : 0;
|
||||
if (ccp[len]) {
|
||||
@ -853,14 +853,14 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
|
||||
* junk after it" and "invalid array"; in the
|
||||
* latter case, len is also 0 and points to '['
|
||||
*/
|
||||
errorf("%s: %s", qval,
|
||||
errorf(Tf_sD_s, qval,
|
||||
"nameref target not a valid parameter name");
|
||||
}
|
||||
nameref_rhs_checked:
|
||||
/* prevent nameref loops */
|
||||
while (qval) {
|
||||
if (!strcmp(qval, tvar))
|
||||
errorf("%s: %s", qval,
|
||||
errorf(Tf_sD_s, qval,
|
||||
"expression recurses on parameter");
|
||||
varsearch(e->loc, &vp, qval, hash(qval));
|
||||
qval = NULL;
|
||||
@ -870,9 +870,9 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
|
||||
}
|
||||
|
||||
/* prevent typeset from creating a local PATH/ENV/SHELL */
|
||||
if (Flag(FRESTRICTED) && (strcmp(tvar, "PATH") == 0 ||
|
||||
strcmp(tvar, "ENV") == 0 || strcmp(tvar, "SHELL") == 0))
|
||||
errorf("%s: %s", tvar, "restricted");
|
||||
if (Flag(FRESTRICTED) && (strcmp(tvar, TPATH) == 0 ||
|
||||
strcmp(tvar, "ENV") == 0 || strcmp(tvar, TSHELL) == 0))
|
||||
errorf(Tf_sD_s, tvar, "restricted");
|
||||
|
||||
innermost_refflag = new_refflag;
|
||||
vp = (set & LOCAL) ? local(tvar, tobool(set & LOCAL_COPY)) :
|
||||
@ -909,7 +909,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
|
||||
if ((vpbase->flag & RDONLY) &&
|
||||
(val || clr || (set & ~EXPORT)))
|
||||
/* XXX check calls - is error here ok by POSIX? */
|
||||
errorfx(2, "read-only: %s", tvar);
|
||||
errorfx(2, Tf_ro, tvar);
|
||||
afree(tvar, ATEMP);
|
||||
|
||||
/* most calls are with set/clr == 0 */
|
||||
@ -982,7 +982,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
|
||||
char *tval;
|
||||
|
||||
if (vappend) {
|
||||
tval = shf_smprintf("%s%s", str_val(vp), val);
|
||||
tval = shf_smprintf(Tf_ss, str_val(vp), val);
|
||||
val = tval;
|
||||
} else
|
||||
tval = NULL;
|
||||
@ -1327,7 +1327,7 @@ setspec(struct tbl *vp)
|
||||
if (getint(vp, &num, false) == -1) {
|
||||
s = str_val(vp);
|
||||
if (st != V_RANDOM)
|
||||
errorf("%s: %s: %s", vp->name, "bad number", s);
|
||||
errorf(Tf_sD_sD_s, vp->name, "bad number", s);
|
||||
num.u = hash(s);
|
||||
}
|
||||
vp->flag |= SPECIAL;
|
||||
@ -1531,7 +1531,7 @@ set_array(const char *var, bool reset, const char **vals)
|
||||
|
||||
/* Note: AT&T ksh allows set -A but not set +A of a read-only var */
|
||||
if ((vp->flag&RDONLY))
|
||||
errorfx(2, "read-only: %s", ccp);
|
||||
errorfx(2, Tf_ro, ccp);
|
||||
/* This code is quite non-optimal */
|
||||
if (reset) {
|
||||
/* trash existing values and attributes */
|
||||
|
Loading…
x
Reference in New Issue
Block a user