File mksh-fix-print--R.patch of Package mksh

Subject: Fix print -R behavior
References: bsc#1023419
Patch-mainline: yes
Git-commit: 287507fb216cdc12e147828a31762db87a030307 (partial backport)

Fix print -R so that it doesn't try to interpret all its arguments as
options.
---
 mksh/funcs.c |   15 ++++++---------
 mksh/mksh.1  |   22 ++++++++++------------
 2 files changed, 16 insertions(+), 21 deletions(-)

--- mksh/funcs.c
+++ mksh/funcs.c	2017-03-24 07:26:25.176847720 +0000
@@ -276,7 +276,6 @@ c_print(const char **wp)
 {
 #define PO_NL		BIT(0)	/* print newline */
 #define PO_EXPAND	BIT(1)	/* expand backslash sequences */
-#define PO_PMINUSMINUS	BIT(2)	/* print a -- argument */
 #define PO_HIST		BIT(3)	/* print to history instead of stdout */
 #define PO_COPROC	BIT(4)	/* printing to coprocess: block SIGPIPE */
 	int fd = 1, c;
@@ -304,6 +303,7 @@ c_print(const char **wp)
 #endif
 		    Flag(FAS_BUILTIN)) {
 			/* Debian Policy 10.4 compliant "echo" builtin */
+ bsd_echo:
 			if (*wp && !strcmp(*wp, "-n")) {
 				/* we recognise "-n" only as the first arg */
 				flags = 0;
@@ -348,16 +348,14 @@ c_print(const char **wp)
 		}
 	} else {
 		int optc;
-		const char *opts = "Rnprsu,";
+		const char *opts = "Renprsu,";
 
 		while ((optc = ksh_getopt(wp, &builtin_opt, opts)) != -1)
 			switch (optc) {
 			case 'R':
-				/* fake BSD echo command */
-				flags |= PO_PMINUSMINUS;
-				flags &= ~PO_EXPAND;
-				opts = "ne";
-				break;
+				/* fake BSD echo but don't reset other flags */
+				wp += builtin_opt.optind;
+				goto bsd_echo;
 			case 'e':
 				flags |= PO_EXPAND;
 				break;
@@ -393,8 +391,7 @@ c_print(const char **wp)
 			if (wp[builtin_opt.optind] &&
 			    ksh_isdash(wp[builtin_opt.optind]))
 				builtin_opt.optind++;
-		} else if (flags & PO_PMINUSMINUS)
-			builtin_opt.optind--;
+		}
 		wp += builtin_opt.optind;
 	}
 
--- mksh/mksh.1
+++ mksh/mksh.1	2017-03-24 07:26:25.180847645 +0000
@@ -3702,8 +3702,8 @@ for further information.
 .Pp
 .It Xo
 .Ic print
-.Oo Fl nprsu Ns Oo Ar n Oc \*(Ba
-.Fl R Op Fl en Oc
+.Oo Fl enprsu Ns Oo Ar n Oc \*(Ba
+.Fl R Op Fl n Oc
 .Op Ar argument ...
 .Xc
 .Ic print
@@ -3712,7 +3712,7 @@ terminated with a newline.
 The
 .Fl n
 option suppresses the newline.
-By default, certain C escapes are translated.
+By default, certain escapes are translated.
 These include these mentioned in
 .Sx Backslash expansion
 above, as well as
@@ -3722,6 +3722,8 @@ which is equivalent to using the
 option.
 Backslash expansion may be inhibited with the
 .Fl r
+option, and restored with the
+.Fl e
 option.
 The
 .Fl s
@@ -3741,17 +3743,13 @@ above).
 .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
+.Sq Fl n
+to suppress the trailing newline.
 .Pp
 .It Ic printf Ar format Op Ar arguments ...
 Formatted output.
openSUSE Build Service is sponsored by