summaryrefslogtreecommitdiff
path: root/system/pdksh/patches/115_OpenBSD-echo-posix.patch
blob: 47a9f37826f4648a93b45f7cd0ecb3cd1ec35b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
From OpenBSD:

2009-02-07 15:03  kili

        * c_ksh.c (1.33):
          Ensure that *wp isn't NULL.

          ok otto@

2009-02-07 08:24  guenther

        * c_ksh.c (1.32), ksh.1 (1.124), sh.1 (1.78): Make built-in echo
          behave according to POSIX when set -o posix is in effect: the
          only option is -n, and only one of those is parsed.

          diff from Ingo Schwarze ok otto@ kili@; manpage changes ok jmc@


Index: pdksh-5.2.14/c_ksh.c
===================================================================
--- pdksh-5.2.14.orig/c_ksh.c	2009-09-19 11:22:34.000000000 +0200
+++ pdksh-5.2.14/c_ksh.c	2009-09-19 12:13:54.000000000 +0200
@@ -247,23 +247,30 @@
 		 * by default.
 		 */
 		wp += 1;
-		while ((s = *wp) && *s == '-' && s[1]) {
-			while (*++s)
-				if (*s == 'n')
-					nflags &= ~PO_NL;
-				else if (*s == 'e')
-					nflags |= PO_EXPAND;
-				else if (*s == 'E')
-					nflags &= ~PO_EXPAND;
-				else
-					/* bad option: don't use nflags, print
-					 * argument
-					 */
+		if (Flag(FPOSIX)) {
+			if (*wp && strcmp(*wp, "-n") == 0) {
+				flags &= ~PO_NL;
+				wp++;
+			}
+		} else {
+			while ((s = *wp) && *s == '-' && s[1]) {
+				while (*++s)
+					if (*s == 'n')
+						nflags &= ~PO_NL;
+					else if (*s == 'e')
+						nflags |= PO_EXPAND;
+					else if (*s == 'E')
+						nflags &= ~PO_EXPAND;
+					else
+						/* bad option: don't use
+						 * nflags, print argument
+						 */
+						break;
+				if (*s)
 					break;
-			if (*s)
-				break;
-			wp++;
-			flags = nflags;
+				wp++;
+				flags = nflags;
+			}
 		}
 	} else {
 		int optc;
Index: pdksh-5.2.14/ksh.Man
===================================================================
--- pdksh-5.2.14.orig/ksh.Man	2009-09-19 11:22:34.000000000 +0200
+++ pdksh-5.2.14/ksh.Man	2009-09-19 12:13:54.000000000 +0200
@@ -1521,6 +1521,13 @@
 In future, a new option (\fB\-v\fP perhaps) will be added to distinguish
 the two behaviours.
 .IP \ \ \(bu
+\fBecho\fP
+options.
+In POSIX mode, \fB\-e\fP and \fB\-E\fP
+are not treated as options, but printed like other arguments;
+in non-POSIX mode, these options control the interpretation
+of backslash sequences.
+.IP \ \ \(bu
 \fBfg\fP exit status: in posix mode, the exit status is 0 if no errors occur;
 in non-posix mode, the exit status is that of the last foregrounded job.
 .IP \ \ \(bu
@@ -1780,6 +1787,9 @@
 \fB\-n\fP suppresses the trailing newline, \fB\-e\fP enables backslash
 interpretation (a no-op, since this is normally done), and \fB\-E\fP which
 suppresses backslash interpretation.
+If the \fIposix\fP
+option is set, only the first argument is treated as an option, and only
+if it is exactly \fB-n\fP.
 .\"}}}
 .\"{{{  eval command ...
 .IP "\fBeval\fP \fIcommand ...\fP"
Index: pdksh-5.2.14/tests/debian-115.t
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ pdksh-5.2.14/tests/debian-115.t	2009-09-19 12:18:11.000000000 +0200
@@ -0,0 +1,38 @@
+name: debian-115-1
+description:
+	Check if echo does not accept -e in posix mode
+stdin:
+	set -o posix
+	echo -e test
+expected-stdout:
+	-e test
+---
+name: debian-115-2
+description:
+	Check if echo accepts -e in non-posix mode
+stdin:
+	set +o posix
+	echo -e test
+expected-stdout:
+	test
+---
+name: debian-115-3
+description:
+	Check if echo accepts -n in posix mode
+stdin:
+	set -o posix
+	echo -n test
+	echo " OK"
+expected-stdout:
+	test OK
+---
+name: debian-115-4
+description:
+	Check if echo accepts -n in non-posix mode
+stdin:
+	set +o posix
+	echo -n test
+	echo " OK"
+expected-stdout:
+	test OK
+---