apply the new cat hack to printf, too, to prefer it over the builtin

This commit is contained in:
tg 2015-07-09 20:20:45 +00:00
parent f274f18223
commit dcd8b6389b
4 changed files with 35 additions and 6 deletions

29
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.157 2015/07/09 19:59:14 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.158 2015/07/09 20:20:42 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL "/bin/sh"
@ -551,7 +551,11 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
}
if ((tp = findcom(cp, FC_BI)) == NULL)
errorf("%s: %s: %s", Tbuiltin, cp, "not a builtin");
if (tp->type == CSHELL && tp->val.f == c_cat)
if (tp->type == CSHELL && (tp->val.f == c_cat
#ifdef MKSH_PRINTF_BUILTIN
|| tp->val.f == c_printf
#endif
))
break;
continue;
} else if (tp->val.f == c_exec) {
@ -622,6 +626,16 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
tp = ext_cat;
}
break;
#ifdef MKSH_PRINTF_BUILTIN
} else if (tp->val.f == c_printf) {
struct tbl *ext_printf;
ext_printf = findcom(Tprintf, FC_PATH | FC_FUNC);
if (ext_printf && (ext_printf->type != CTALIAS ||
(ext_printf->flag & ISSET)))
tp = ext_printf;
break;
#endif
} else if (tp->val.f == c_trap) {
t->u.evalflags &= ~DOTCOMEXEC;
break;
@ -731,6 +745,13 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
tp = findcom(Tcat, FC_BI);
goto do_call_builtin;
}
#ifdef MKSH_PRINTF_BUILTIN
if (!strcmp(cp, Tprintf)) {
no_printf_in_FPATH:
tp = findcom(Tprintf, FC_BI);
goto do_call_builtin;
}
#endif
warningf(true, "%s: %s %s %s: %s", cp,
"can't open", "function definition file",
tp->u.fpath, cstrerror(errno));
@ -741,6 +762,10 @@ comexec(struct op *t, struct tbl * volatile tp, const char **ap,
!(ftp->flag & ISSET)) {
if (!strcmp(cp, Tcat))
goto no_cat_in_FPATH;
#ifdef MKSH_PRINTF_BUILTIN
if (!strcmp(cp, Tprintf))
goto no_printf_in_FPATH;
#endif
warningf(true, "%s: %s %s", cp,
"function not defined by", tp->u.fpath);
rv = 127;

View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.278 2015/07/09 19:46:41 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.279 2015/07/09 20:20:42 tg Exp $");
#if HAVE_KILLPG
/*
@ -152,7 +152,7 @@ const struct builtin mkshbuiltins[] = {
{"mknod", c_mknod},
#endif
#ifdef MKSH_PRINTF_BUILTIN
{"printf", c_printf},
{Tprintf, c_printf},
#endif
#if HAVE_SELECT
{"sleep", c_sleep},

3
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.374 2015/07/09 19:50:44 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.375 2015/07/09 20:20:43 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
@ -3756,6 +3756,7 @@ utility, except it uses the same
.Sx Backslash expansion
and I/O code and does not handle floating point as the rest of
.Nm mksh .
An external utility is preferred over the builtin.
This is not normally part of
.Nm mksh ;
however, distributors may have added this as builtin as a speed hack.

5
sh.h
View File

@ -169,7 +169,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.736 2015/07/09 19:46:43 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.737 2015/07/09 20:20:45 tg Exp $");
#endif
#define MKSH_VERSION "R51 2015/07/06"
@ -833,6 +833,9 @@ EXTERN const char Tcat[] E_INIT("cat");
#ifdef __OS2__
EXTERN const char Textproc[] E_INIT("extproc");
#endif
#ifdef MKSH_PRINTF_BUILTIN
EXTERN const char Tprintf[] E_INIT("printf");
#endif
EXTERN const char Tsgset[] E_INIT("*=set");
#define Tset (Tsgset + 2) /* "set" */
EXTERN const char Tsgexport[] E_INIT("*=export");