From 6c5d08ea6f08f4892d06a08f41a798bf9bafbd8c Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 26 Aug 2005 22:03:56 +0000 Subject: [PATCH] * add printf(1) as mksh(1) builtin on MirOS (or, more general, all systems using Makefile instead of Build.sh) * document this fact --- Makefile | 11 ++++++++++- check.t | 4 ++-- funcs.c | 25 +++++++++++++++++++++++-- main.c | 6 +++--- mksh.1 | 15 +++++++++++++-- 5 files changed, 51 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 1fcc86f..a5d41c0 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,19 @@ -# $MirOS: src/bin/mksh/Makefile,v 1.3 2005/05/23 14:48:21 tg Exp $ +# $MirOS: src/bin/mksh/Makefile,v 1.4 2005/08/26 22:03:55 tg Exp $ PROG= mksh SRCS= alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c \ jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c CDIAGFLAGS+= -Wno-cast-qual +.include + +.ifndef NO_PRINTF_BUILTIN +.PATH: ${BSDSRCDIR}/usr.bin/printf +SRCS+= printf.c +CFLAGS_printf.o=-DBUILTIN +CPPFLAGS+= -DUSE_PRINTF +.endif + check: @cd ${.CURDIR} && ${MAKE} regress V=-v diff --git a/check.t b/check.t index 8e2257b..70faaec 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.28 2005/08/21 13:02:16 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.29 2005/08/26 22:03:55 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -3701,5 +3701,5 @@ category: pdksh stdin: echo $KSH_VERSION expected-stdout: - @(#)MIRBSD KSH R24 2005/08/21 + @(#)MIRBSD KSH R25 2005/08/26 pre --- diff --git a/funcs.c b/funcs.c index db18fe6..3e51b8b 100644 --- a/funcs.c +++ b/funcs.c @@ -1,4 +1,4 @@ -/** $MirOS: src/bin/mksh/funcs.c,v 1.16 2005/08/21 12:52:29 tg Exp $ */ +/** $MirOS: src/bin/mksh/funcs.c,v 1.17 2005/08/26 22:03:55 tg Exp $ */ /* $OpenBSD: c_ksh.c,v 1.27 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_sh.c,v 1.29 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: c_test.c,v 1.17 2005/03/30 17:16:37 deraadt Exp $ */ @@ -13,7 +13,11 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.16 2005/08/21 12:52:29 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.17 2005/08/26 22:03:55 tg Exp $"); + +#ifdef USE_PRINTF +int c_printf(char **); +#endif int c_cd(char **wp) @@ -1079,6 +1083,20 @@ c_fgbg(char **wp) return bg ? 0 : rv; } +#ifdef USE_PRINTF +int +c_printf(char **wp) +{ + extern int progprintf(int, char *[]); + int argc; + + for (argc = 0; wp[argc]; argc++) + ; + + return progprintf(argc, wp); +} +#endif + struct kill_info { int num_width; int name_width; @@ -1373,6 +1391,9 @@ const struct builtin kshbuiltins [] = { {"+bg", c_fgbg}, {"+fg", c_fgbg}, {"bind", c_bind}, +#ifdef USE_PRINTF + {"printf", c_printf}, +#endif {NULL, NULL} }; diff --git a/main.c b/main.c index 0a14618..bf88d6a 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -/** $MirOS: src/bin/mksh/main.c,v 1.24 2005/08/21 13:02:17 tg Exp $ */ +/** $MirOS: src/bin/mksh/main.c,v 1.25 2005/08/26 22:03:56 tg Exp $ */ /* $OpenBSD: main.c,v 1.38 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: tty.c,v 1.8 2005/03/30 17:16:37 deraadt Exp $ */ /* $OpenBSD: io.c,v 1.21 2005/03/30 17:16:37 deraadt Exp $ */ @@ -13,9 +13,9 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.24 2005/08/21 13:02:17 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.25 2005/08/26 22:03:56 tg Exp $"); -#define MKSH_VERSION "@(#)MIRBSD KSH R24 2005/08/21" +#define MKSH_VERSION "@(#)MIRBSD KSH R25 2005/08/26 pre" extern char **environ; diff --git a/mksh.1 b/mksh.1 index c23ed77..4be657e 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.17 2005/08/26 21:54:05 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.18 2005/08/26 22:03:56 tg Exp $ .\" $OpenBSD: ksh.1,v 1.101 2005/08/01 19:29:57 jmc Exp $ .\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $ .\" @@ -2314,7 +2314,8 @@ Additional regular commands .Pp .Ic \&[ , echo , let , print , -.Ic pwd , test , ulimit , whence +.Ic printf , pwd , test , ulimit , +.Ic whence .Pp In the future, the additional .Nm @@ -2967,6 +2968,15 @@ As above, the .Fl n option suppresses the trailing newline. .Pp +.It Ic printf Ar format Op Ar arguments +This builtin is not included with portable +.Nm +and only available under +.Mx . +It mimics the +.Xr printf 1 +behaviour; see there for a complete reference. +.Pp .It Ic pwd Op Fl LP Print the present working directory. If the @@ -5073,6 +5083,7 @@ Shell database. .Xr ed 1 , .Xr getconf 1 , .Xr getopt 1 , +.Xr printf 1 , .Xr sed 1 , .Xr sh 1 , .Xr stty 1 ,