blob: 89d93472fd0241a1ae30dc66f0633767d5098813 (
plain) (
tree)
|
|
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;
}
|