From 287507fb216cdc12e147828a31762db87a030307 Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 17 Feb 2017 22:28:26 +0000 Subject: [PATCH] =?UTF-8?q?there=E2=80=99s=20no=20evidence=20for=20-e=20in?= =?UTF-8?q?=20any=20BSD=20echo=20(but=20in=20ksh93=20print)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit spotted by Jean Delvare and Werner Fink --- funcs.c | 61 +++++++++++++++++++++++---------------------------------- mksh.1 | 33 ++++++++++++++++--------------- 2 files changed, 41 insertions(+), 53 deletions(-) diff --git a/funcs.c b/funcs.c index 74f3859..e2f57b4 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.320 2017/02/08 15:27:27 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.321 2017/02/17 22:28:25 tg Exp $"); #if HAVE_KILLPG /* @@ -307,8 +307,6 @@ c_print(const char **wp) bool hist; /* print words as wide characters? */ bool chars; - /* print a "--" argument? */ - bool pminusminus; /* writing to a coprocess (SIGPIPE blocked)? */ bool coproc; bool copipe; @@ -323,43 +321,36 @@ c_print(const char **wp) if (wp[0][0] == 'e') { /* "echo" builtin */ - ++wp; -#ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT - if (Flag(FSH)) { - /* - * MidnightBSD /bin/sh needs a BSD echo, that is, - * one that supports -e but does not enable it by - * default - */ - po.exp = false; - } -#endif if (Flag(FPOSIX) || #ifndef MKSH_MIDNIGHTBSD01ASH_COMPAT Flag(FSH) || #endif Flag(FAS_BUILTIN)) { - /* Debian Policy 10.4 compliant "echo" builtin */ + /* BSD "echo" cmd, Debian Policy 10.4 compliant */ + ++wp; + bsd_echo: if (*wp && !strcmp(*wp, "-n")) { - /* recognise "-n" only as the first arg */ po.nl = false; ++wp; } - /* print everything as-is */ po.exp = false; } else { - bool new_exp = po.exp, new_nl = po.nl; + bool new_exp, new_nl = true; - /** - * a compromise between sysV and BSD echo commands: - * escape sequences are enabled by default, and -n, - * -e and -E are recognised if they appear in argu- - * ments with no illegal options (ie, echo -nq will - * print -nq). - * Different from sysV echo since options are reco- - * gnised, different from BSD echo since escape se- - * quences are enabled by default. + /*- + * compromise between various historic echos: only + * recognise -Een if they appear in arguments with + * no illegal options; e.g. echo -nq outputs '-nq' */ +#ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT + /* MidnightBSD /bin/sh needs -e supported but off */ + if (Flag(FSH)) + new_exp = false; + else +#endif + /* otherwise compromise on -e enabled by default */ + new_exp = true; + goto print_tradparse_beg; print_tradparse_arg: if ((s = *wp) && *s++ == '-' && *s) { @@ -375,6 +366,7 @@ c_print(const char **wp) new_nl = false; goto print_tradparse_ch; case '\0': + print_tradparse_beg: po.exp = new_exp; po.nl = new_nl; ++wp; @@ -384,11 +376,9 @@ c_print(const char **wp) } } else { /* "print" builtin */ - const char *opts = "AclNnpRrsu,"; + const char *opts = "AcelNnpRrsu,"; const char *emsg; - po.pminusminus = false; - while ((c = ksh_getopt(wp, &builtin_opt, opts)) != -1) switch (c) { case 'A': @@ -417,11 +407,9 @@ c_print(const char **wp) } break; case 'R': - /* fake BSD echo command */ - po.pminusminus = true; - po.exp = false; - opts = "en"; - break; + /* fake BSD echo but don't reset other flags */ + wp += builtin_opt.optind; + goto bsd_echo; case 'r': po.exp = false; break; @@ -445,8 +433,7 @@ c_print(const char **wp) if (wp[builtin_opt.optind] && ksh_isdash(wp[builtin_opt.optind])) builtin_opt.optind++; - } else if (po.pminusminus) - builtin_opt.optind--; + } wp += builtin_opt.optind; } diff --git a/mksh.1 b/mksh.1 index 8bca4f1..0e6d6e1 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,8 +1,8 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.422 2017/02/17 20:41:56 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.423 2017/02/17 22:28:26 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, -.\" 2010, 2011, 2012, 2013, 2014, 2015, 2016 +.\" 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 .\" mirabilos .\" .\" Provided that these terms and disclaimer and all copyright notices @@ -3421,8 +3421,10 @@ If the .Ic posix or .Ic sh -option is set or this is a direct builtin call, only the first argument -is treated as an option, and only if it is exactly +option is set or this is a direct builtin call or +.Ic print +.Fl R , +only the first argument is treated as an option, and only if it is exactly .Dq Li \-n . Backslash interpretation is disabled. .Pp @@ -3758,12 +3760,12 @@ however, distributors may have added this as builtin as a speed hack. .It Xo .Ic print .Oo Fl AclNnprsu Ns Oo Ar n Oc \*(Ba -.Fl R Op Fl en Oc +.Fl R Op Fl n Oc .Op Ar argument ... .Xc Print the specified argument(s) on the standard output, separated by spaces, terminated with a newline. -The C escapes mentioned in +The escapes mentioned in .Sx Backslash expansion above, as well as .Dq Li \ec , @@ -3789,6 +3791,9 @@ utility, tab completion, the built-in utility and the .Ic select statement do. +.It Fl e +Restore backslash expansion after a previous +.Fl r . .It Fl l Change the output word separator to newline. .It Fl N @@ -3811,17 +3816,13 @@ instead of standard output. .Pp The .Fl R -option is used to emulate, to some degree, the +option mostly emulates the .Bx .Xr echo 1 -command which does not process -.Ql \e -sequences unless the -.Fl e -option is given. -As above, the -.Fl n -option suppresses the trailing newline. +command which does not expand backslashes and interprets +its first argument as option only if it is exactly +.Dq Li \-n +.Pq to suppress the trailing newline . .Pp .It Ic pwd Op Fl LP Print the present working directory. @@ -6696,7 +6697,7 @@ for the in-memory portion of the history is slow, should use .Xr memmove 3 . .Pp This document attempts to describe -.Nm mksh\ R54 +.Nm mksh\ R55 and up, .\" with vendor patches from insert-your-name-here, compiled without any options impacting functionality, such as