summaryrefslogtreecommitdiffstats
path: root/source/ap/ash/patches/ash-echo.patch
blob: 89d93472fd0241a1ae30dc66f0633767d5098813 (about) (plain) (blame)
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
diff -urN netbsd-sh/bltin/echo.c ash-0.3.7.orig/bltin/echo.c
--- netbsd-sh/bltin/echo.c	Sun Nov  3 13:06:22 1996
+++ ash-0.3.7.orig/bltin/echo.c	Mon Apr 23 22:16:46 2001
@@ -44,7 +44,13 @@
 
 #define main echocmd
 
+#ifdef _GNU_SOURCE
+#include <stdio.h>
+
+#include "../mystring.h"
+#else
 #include "bltin.h"
+#endif
 
 /* #define eflag 1 */
 
@@ -53,7 +59,6 @@
 	register char **ap;
 	register char *p;
 	register char c;
-	int count;
 	int nflag = 0;
 #ifndef eflag
 	int eflag = 0;
@@ -62,21 +67,26 @@
 	ap = argv;
 	if (argc)
 		ap++;
-	if ((p = *ap) != NULL) {
+	while ((p = *ap) != NULL && *p == '-') {
 		if (equal(p, "-n")) {
-			nflag++;
-			ap++;
+			nflag = 1;
 		} else if (equal(p, "-e")) {
 #ifndef eflag
-			eflag++;
+			eflag = 1;
+#endif
+		} else if (equal(p, "-E")) {
+#ifndef eflag
+			eflag = 0;
 #endif
-			ap++;
 		}
+		else break;
+		ap++;
 	}
 	while ((p = *ap++) != NULL) {
 		while ((c = *p++) != '\0') {
 			if (c == '\\' && eflag) {
-				switch (*p++) {
+				switch (c = *p++) {
+				case 'a':  c = '\007'; break;
 				case 'b':  c = '\b';  break;
 				case 'c':  return 0;		/* exit */
 				case 'f':  c = '\f';  break;
@@ -85,11 +95,13 @@
 				case 't':  c = '\t';  break;
 				case 'v':  c = '\v';  break;
 				case '\\':  break;		/* c = '\\' */
-				case '0':
-					c = 0;
-					count = 3;
-					while (--count >= 0 && (unsigned)(*p - '0') < 8)
-						c = (c << 3) + (*p++ - '0');
+				case '0': case '1': case '2': case '3':
+				case '4': case '5': case '6': case '7':
+					c -= '0';
+					if (*p >= '0' && *p <= '7')
+						c = c * 8 + (*p++ - '0');
+					if (*p >= '0' && *p <= '7')
+					c = c * 8 + (*p++ - '0');
 					break;
 				default:
 					p--;
@@ -103,5 +115,12 @@
 	}
 	if (! nflag)
 		putchar('\n');
+#ifdef _GNU_SOURCE
+	fflush(stdout);
+	if (ferror(stdout)) {
+		clearerr(stdout);
+		return 1;
+	}
+#endif
 	return 0;
 }