Rev 2714 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2714 | Rev 2927 | ||
---|---|---|---|
1 | /* $NetBSD: echo.c,v 1.8 1996/11/02 18:26:06 christos Exp $ */ |
1 | /* $NetBSD: echo.c,v 1.8 1996/11/02 18:26:06 christos Exp $ */ |
2 | 2 | ||
3 | /*- |
3 | /*- |
4 | * Copyright (c) 1991, 1993 |
4 | * Copyright (c) 1991, 1993 |
5 | * The Regents of the University of California. All rights reserved. |
5 | * The Regents of the University of California. All rights reserved. |
6 | * |
6 | * |
7 | * This code is derived from software contributed to Berkeley by |
7 | * This code is derived from software contributed to Berkeley by |
8 | * Kenneth Almquist. |
8 | * Kenneth Almquist. |
9 | * |
9 | * |
10 | * Redistribution and use in source and binary forms, with or without |
10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions |
11 | * modification, are permitted provided that the following conditions |
12 | * are met: |
12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright |
13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. |
14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright |
15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the |
16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. |
17 | * documentation and/or other materials provided with the distribution. |
18 | * 3. All advertising materials mentioning features or use of this software |
18 | * 3. All advertising materials mentioning features or use of this software |
19 | * must display the following acknowledgement: |
19 | * must display the following acknowledgement: |
20 | * This product includes software developed by the University of |
20 | * This product includes software developed by the University of |
21 | * California, Berkeley and its contributors. |
21 | * California, Berkeley and its contributors. |
22 | * 4. Neither the name of the University nor the names of its contributors |
22 | * 4. Neither the name of the University nor the names of its contributors |
23 | * may be used to endorse or promote products derived from this software |
23 | * may be used to endorse or promote products derived from this software |
24 | * without specific prior written permission. |
24 | * without specific prior written permission. |
25 | * |
25 | * |
26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
36 | * SUCH DAMAGE. |
36 | * SUCH DAMAGE. |
37 | * |
37 | * |
38 | * @(#)echo.c 8.1 (Berkeley) 5/31/93 |
38 | * @(#)echo.c 8.1 (Berkeley) 5/31/93 |
39 | */ |
39 | */ |
40 | 40 | ||
41 | /* |
41 | /* |
42 | * Echo command. |
42 | * Echo command. |
43 | */ |
43 | */ |
44 | 44 | ||
45 | #define main echocmd |
45 | #define main echocmd |
46 | 46 | ||
47 | #ifdef _GNU_SOURCE |
47 | #ifdef _GNU_SOURCE |
48 | #include <stdio.h> |
48 | #include <stdio.h> |
49 | 49 | ||
50 | #include "../mystring.h" |
50 | #include "../mystring.h" |
51 | #else |
51 | #else |
52 | #include "bltin.h" |
52 | #include "bltin.h" |
53 | #endif |
53 | #endif |
54 | 54 | ||
55 | /* #define eflag 1 */ |
55 | /* #define eflag 1 */ |
56 | 56 | ||
57 | int |
57 | int |
58 | main(argc, argv) char **argv; { |
58 | main(argc, argv) char **argv; { |
59 | register char **ap; |
59 | register char **ap; |
60 | register char *p; |
60 | register char *p; |
61 | register char c; |
61 | register char c; |
62 | int nflag = 0; |
62 | int nflag = 0; |
63 | #ifndef eflag |
63 | #ifndef eflag |
64 | int eflag = 0; |
64 | int eflag = 0; |
65 | #endif |
65 | #endif |
66 | 66 | ||
67 | ap = argv; |
67 | ap = argv; |
68 | if (argc) |
68 | if (argc) |
69 | ap++; |
69 | ap++; |
70 | while ((p = *ap) != NULL && *p == '-') { |
70 | while ((p = *ap) != NULL && *p == '-') { |
71 | if (equal(p, "-n")) { |
71 | if (equal(p, "-n")) { |
72 | nflag = 1; |
72 | nflag = 1; |
73 | } else if (equal(p, "-e")) { |
73 | } else if (equal(p, "-e")) { |
74 | #ifndef eflag |
74 | #ifndef eflag |
75 | eflag = 1; |
75 | eflag = 1; |
76 | #endif |
76 | #endif |
77 | } else if (equal(p, "-E")) { |
77 | } else if (equal(p, "-E")) { |
78 | #ifndef eflag |
78 | #ifndef eflag |
79 | eflag = 0; |
79 | eflag = 0; |
80 | #endif |
80 | #endif |
81 | } |
81 | } |
82 | else break; |
82 | else break; |
83 | ap++; |
83 | ap++; |
84 | } |
84 | } |
85 | while ((p = *ap++) != NULL) { |
85 | while ((p = *ap++) != NULL) { |
86 | while ((c = *p++) != '\0') { |
86 | while ((c = *p++) != '\0') { |
87 | if (c == '\\' && eflag) { |
87 | if (c == '\\' && eflag) { |
88 | switch (c = *p++) { |
88 | switch (c = *p++) { |
89 | case 'a': c = '\007'; break; |
89 | case 'a': c = '\007'; break; |
90 | case 'b': c = '\b'; break; |
90 | case 'b': c = '\b'; break; |
91 | case 'c': return 0; /* exit */ |
91 | case 'c': return 0; /* exit */ |
92 | case 'e': c = '\033'; break; |
92 | case 'e': c = '\033'; break; |
93 | case 'f': c = '\f'; break; |
93 | case 'f': c = '\f'; break; |
94 | case 'n': c = '\n'; break; |
94 | case 'n': c = '\n'; break; |
95 | case 'r': c = '\r'; break; |
95 | case 'r': c = '\r'; break; |
96 | case 't': c = '\t'; break; |
96 | case 't': c = '\t'; break; |
97 | case 'v': c = '\v'; break; |
97 | case 'v': c = '\v'; break; |
98 | case '\\': break; /* c = '\\' */ |
98 | case '\\': break; /* c = '\\' */ |
99 | case '0': case '1': case '2': case '3': |
99 | case '0': case '1': case '2': case '3': |
100 | case '4': case '5': case '6': case '7': |
100 | case '4': case '5': case '6': case '7': |
101 | c -= '0'; |
101 | c -= '0'; |
102 | if (*p >= '0' && *p <= '7') |
102 | if (*p >= '0' && *p <= '7') |
103 | c = c * 8 + (*p++ - '0'); |
103 | c = c * 8 + (*p++ - '0'); |
104 | if (*p >= '0' && *p <= '7') |
104 | if (*p >= '0' && *p <= '7') |
105 | c = c * 8 + (*p++ - '0'); |
105 | c = c * 8 + (*p++ - '0'); |
106 | break; |
106 | break; |
107 | default: |
107 | default: |
108 | p--; |
108 | p--; |
109 | break; |
109 | break; |
110 | } |
110 | } |
111 | } |
111 | } |
112 | putchar(c); |
112 | putchar(c); |
113 | } |
113 | } |
114 | if (*ap) |
114 | if (*ap) |
115 | putchar(' '); |
115 | putchar(' '); |
116 | } |
116 | } |
117 | if (! nflag) |
117 | if (! nflag) |
118 | putchar('\n'); |
118 | putchar('\n'); |
119 | #ifdef _GNU_SOURCE |
119 | #ifdef _GNU_SOURCE |
120 | fflush(stdout); |
120 | fflush(stdout); |
121 | if (ferror(stdout)) { |
121 | if (ferror(stdout)) { |
122 | clearerr(stdout); |
122 | clearerr(stdout); |
123 | return 1; |
123 | return 1; |
124 | } |
124 | } |
125 | #endif |
125 | #endif |
126 | return 0; |
126 | return 0; |
127 | } |
127 | } |
128 | 128 |