/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
- * 2011, 2012, 2013, 2014, 2015
+ * 2011, 2012, 2013, 2014, 2015, 2016
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
#include <grp.h>
#endif
-__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.240 2015/10/09 16:11:17 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.245 2016/08/01 18:42:42 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
void
setctypes(const char *s, int t)
{
- unsigned int i;
-
if (t & C_IFS) {
- for (i = 0; i < UCHAR_MAX + 1; i++)
+ unsigned int i = 0;
+
+ while (++i <= UCHAR_MAX)
chtypes[i] &= ~C_IFS;
- /* include \0 in C_IFS */
+ /* include '\0' in C_IFS */
chtypes[0] |= C_IFS;
}
while (*s != 0)
*/
int
parse_args(const char **argv,
- /* OF_CMDLINE or OF_SET */
+ /* OF_FIRSTTIME, OF_CMDLINE, or OF_SET */
int what,
bool *setargsp)
{
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;
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);
}
}
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();
}
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 ('?');
shf_puts(str, shf);
else
shf_fprintf(shf, "%*s%*s",
- max_col, str, nspace, null);
+ (int)max_col, str, (int)nspace, null);
}
shf_putchar('\n', shf);
}
/* 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);
}
* 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)) {
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 */
allocd = NULL;
dir = str_val(oldpwd_s);
if (dir == null) {
- bi_errorf("no OLDPWD");
+ bi_errorf(Tno_OLDPWD);
return (2);
}
printpath = true;
* we don't
*/
if ((cp = strstr(current_wd, wp[0])) == NULL) {
- bi_errorf("bad substitution");
+ bi_errorf(Tbadsubst);
return (2);
}
/*-
memcpy(dir + ilen + nlen, current_wd + ilen + olen, elen);
printpath = true;
} else {
- bi_errorf("too many arguments");
+ bi_errorf(Ttoo_many_args);
return (2);
}
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);
rv = 1;
}
if (printpath || cdnode)
- shprintf("%s\n", pwd);
+ shprintf(Tf_sN, pwd);
afree(allocd, ATEMP);
Xfree(xs, xp);
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
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:
}
}
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);