add “\builtin” utility

This commit is contained in:
tg 2017-03-11 23:22:36 +00:00
parent ff72ba8399
commit 950df6491d
3 changed files with 12 additions and 12 deletions

11
exec.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.188 2017/03/11 22:58:51 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/exec.c,v 1.189 2017/03/11 23:22:34 tg Exp $");
#ifndef MKSH_DEFAULT_EXECSHELL #ifndef MKSH_DEFAULT_EXECSHELL
#define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh"
@ -978,13 +978,12 @@ scriptexec(struct op *tp, const char **ap)
errorf(Tf_sD_sD_s, tp->str, sh, cstrerror(errno)); errorf(Tf_sD_sD_s, tp->str, sh, cstrerror(errno));
} }
/* actual 'builtin' built-in utility call is handled in comexec() */
int int
shcomexec(const char **wp) c_builtin(const char **wp)
{ {
struct tbl *tp; return (call_builtin(ktsearch(&builtins, *wp, hash(*wp)), wp,
Tbuiltin, false));
tp = ktsearch(&builtins, *wp, hash(*wp));
return (call_builtin(tp, wp, "shcomexec", false));
} }
/* /*

View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.324 2017/03/11 23:10:40 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.325 2017/03/11 23:22:35 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -100,6 +100,7 @@ const struct builtin mkshbuiltins[] = {
/* no =: AT&T manual wrong */ /* no =: AT&T manual wrong */
{Talias, c_alias}, {Talias, c_alias},
{"*=break", c_brkcont}, {"*=break", c_brkcont},
{T_builtin, c_builtin},
{Tbuiltin, c_builtin}, {Tbuiltin, c_builtin},
{Tbcat, c_cat}, {Tbcat, c_cat},
{Tcd, c_cd}, {Tcd, c_cd},

10
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h> #include <locale.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.323 2017/03/11 22:58:51 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/main.c,v 1.324 2017/03/11 23:22:36 tg Exp $");
extern char **environ; extern char **environ;
@ -257,7 +257,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
/* define built-in commands and see if we were called as one */ /* define built-in commands and see if we were called as one */
ktinit(APERM, &builtins, ktinit(APERM, &builtins,
/* currently up to 54 builtins: 75% of 128 = 2^7 */ /* currently up to 55 builtins: 75% of 128 = 2^7 */
7); 7);
for (i = 0; mkshbuiltins[i].name != NULL; i++) for (i = 0; mkshbuiltins[i].name != NULL; i++)
if (!strcmp(ccp, builtin(mkshbuiltins[i].name, if (!strcmp(ccp, builtin(mkshbuiltins[i].name,
@ -382,7 +382,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
setstr(vp, current_wd, KSH_RETURN_ERROR); setstr(vp, current_wd, KSH_RETURN_ERROR);
for (wp = initcoms; *wp != NULL; wp++) { for (wp = initcoms; *wp != NULL; wp++) {
shcomexec(wp); c_builtin(wp);
while (*wp != NULL) while (*wp != NULL)
wp++; wp++;
} }
@ -627,7 +627,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
} }
if (restricted_shell) { if (restricted_shell) {
shcomexec(restr_com); c_builtin(restr_com);
/* After typeset command... */ /* After typeset command... */
Flag(FRESTRICTED) = 1; Flag(FRESTRICTED) = 1;
} }
@ -657,7 +657,7 @@ main(int argc, const char *argv[])
if ((rv = main_init(argc, argv, &s, &l)) == 0) { if ((rv = main_init(argc, argv, &s, &l)) == 0) {
if (Flag(FAS_BUILTIN)) { if (Flag(FAS_BUILTIN)) {
rv = shcomexec(l->argv); rv = c_builtin(l->argv);
} else { } else {
shell(s, true); shell(s, true);
/* NOTREACHED */ /* NOTREACHED */