summaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-11-29 22:40:59 +0000
committerEric Andersen <andersen@codepoet.org>2000-11-29 22:40:59 +0000
commit8fff78d66ee5cc34dae71f89ee20e8215287132c (patch)
tree1427ff8820063f838fb3e97ac4e0ffd1231a7cab /coreutils
parentddea368dbe50bd9bb3ca129037aa4ca1e28515ed (diff)
downloadbusybox-w32-8fff78d66ee5cc34dae71f89ee20e8215287132c.tar.gz
busybox-w32-8fff78d66ee5cc34dae71f89ee20e8215287132c.tar.bz2
busybox-w32-8fff78d66ee5cc34dae71f89ee20e8215287132c.zip
Apply the BSD echo version submitted by Jonas Holmberg <jonas.holmberg@axis.com>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/echo.c96
1 files changed, 67 insertions, 29 deletions
diff --git a/coreutils/echo.c b/coreutils/echo.c
index 8d25be7a5..a6b5152d8 100644
--- a/coreutils/echo.c
+++ b/coreutils/echo.c
@@ -28,47 +28,86 @@
28extern int 28extern int
29echo_main(int argc, char** argv) 29echo_main(int argc, char** argv)
30{ 30{
31 register char **ap;
32 char *p;
33 int c;
34 int nflag = 0; 31 int nflag = 0;
35 int eflag = 0; 32 int eflag = 0;
36 33
34 /* Skip argv[0]. */
35 argc--;
36 argv++;
37 37
38 while ((c = getopt(argc, argv, "neE")) != EOF) { 38 while (argc > 0 && *argv[0] == '-')
39 switch (c) { 39 {
40 case 'n': 40 register char *temp;
41 nflag = 1; 41 register int index;
42 break; 42
43 case 'e': 43 /*
44 eflag = 1; 44 * If it appears that we are handling options, then make sure
45 break; 45 * that all of the options specified are actually valid.
46 case 'E': 46 * Otherwise, the string should just be echoed.
47 eflag = 0; 47 */
48 break; 48 temp = argv[0] + 1;
49 default: 49
50 usage(echo_usage); 50 for (index = 0; temp[index]; index++)
51 {
52 if (strrchr("neE", temp[index]) == 0)
53 goto just_echo;
54 }
55
56 if (!*temp)
57 goto just_echo;
58
59 /*
60 * All of the options in temp are valid options to echo.
61 * Handle them.
62 */
63 while (*temp)
64 {
65 if (*temp == 'n')
66 nflag = 1;
67 else if (*temp == 'e')
68 eflag = 1;
69 else if (*temp == 'E')
70 eflag = 0;
71 else
72 goto just_echo;
73
74 temp++;
51 } 75 }
76 argc--;
77 argv++;
52 } 78 }
53 79
54 ap = &argv[optind]; 80just_echo:
55 while ((p = *ap++) != NULL) { 81 while (argc > 0) {
56 while ((c = *p++) != '\0') { 82 char *arg = argv[0];
57 if (c == '\\' && eflag) { 83 register int c;
58 if (*p == 'c') 84
59 exit(0); 85 while ((c = *arg++)) {
60 else 86
61 c = process_escape_sequence(&p); 87 /* Check for escape sequence. */
88 if (c == '\\' && eflag && *arg) {
89 if (*arg == 'c') {
90 /* '\c' means cancel newline. */
91 nflag = 1;
92 arg++;
93 continue;
94 } else {
95 c = process_escape_sequence(&arg);
96 }
62 } 97 }
98
63 putchar(c); 99 putchar(c);
64 } 100 }
65 if (*ap) 101 argc--;
102 argv++;
103 if (argc > 0)
66 putchar(' '); 104 putchar(' ');
67 } 105 }
68 if (! nflag) 106 if (!nflag)
69 putchar('\n'); 107 putchar('\n');
70 fflush(stdout); 108 fflush(stdout);
71 return( 0); 109
110 return 0;
72} 111}
73 112
74/*- 113/*-
@@ -90,6 +129,7 @@ echo_main(int argc, char** argv)
90 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change 129 * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
91 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> 130 * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
92 * 131 *
132 * California, Berkeley and its contributors.
93 * 4. Neither the name of the University nor the names of its contributors 133 * 4. Neither the name of the University nor the names of its contributors
94 * may be used to endorse or promote products derived from this software 134 * may be used to endorse or promote products derived from this software
95 * without specific prior written permission. 135 * without specific prior written permission.
@@ -108,5 +148,3 @@ echo_main(int argc, char** argv)
108 * 148 *
109 * @(#)echo.c 8.1 (Berkeley) 5/31/93 149 * @(#)echo.c 8.1 (Berkeley) 5/31/93
110 */ 150 */
111
112