Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/echo.def |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | This file is echo.def, from which is created echo.c. | - | ||||||||||||||||||||||||
2 | It implements the builtin "echo" in Bash. | - | ||||||||||||||||||||||||
3 | - | |||||||||||||||||||||||||
4 | Copyright (C) 1987-2016 Free Software Foundation, Inc. | - | ||||||||||||||||||||||||
5 | - | |||||||||||||||||||||||||
6 | This file is part of GNU Bash, the Bourne Again SHell. | - | ||||||||||||||||||||||||
7 | - | |||||||||||||||||||||||||
8 | Bash is free software: you can redistribute it and/or modify | - | ||||||||||||||||||||||||
9 | it under the terms of the GNU General Public License as published by | - | ||||||||||||||||||||||||
10 | the Free Software Foundation, either version 3 of the License, or | - | ||||||||||||||||||||||||
11 | (at your option) any later version. | - | ||||||||||||||||||||||||
12 | - | |||||||||||||||||||||||||
13 | Bash is distributed in the hope that it will be useful, | - | ||||||||||||||||||||||||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - | ||||||||||||||||||||||||
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - | ||||||||||||||||||||||||
16 | GNU General Public License for more details. | - | ||||||||||||||||||||||||
17 | - | |||||||||||||||||||||||||
18 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||||||||
19 | along with Bash. If not, see <http://www.gnu.org/licenses/>. | - | ||||||||||||||||||||||||
20 | - | |||||||||||||||||||||||||
21 | $PRODUCES echo.c | - | ||||||||||||||||||||||||
22 | #include <config.h> | - | ||||||||||||||||||||||||
23 | - | |||||||||||||||||||||||||
24 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||||||||
25 | # include <unistd.h> | - | ||||||||||||||||||||||||
26 | #endif | - | ||||||||||||||||||||||||
27 | - | |||||||||||||||||||||||||
28 | #include "../bashansi.h" | - | ||||||||||||||||||||||||
29 | - | |||||||||||||||||||||||||
30 | #include <stdio.h> | - | ||||||||||||||||||||||||
31 | #include "../shell.h" | - | ||||||||||||||||||||||||
32 | - | |||||||||||||||||||||||||
33 | #include "common.h" | - | ||||||||||||||||||||||||
34 | - | |||||||||||||||||||||||||
35 | $BUILTIN echo | - | ||||||||||||||||||||||||
36 | $FUNCTION echo_builtin | - | ||||||||||||||||||||||||
37 | $DEPENDS_ON V9_ECHO | - | ||||||||||||||||||||||||
38 | $SHORT_DOC echo [-neE] [arg ...] | - | ||||||||||||||||||||||||
39 | Write arguments to the standard output. | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | Display the ARGs, separated by a single space character and followed by a | - | ||||||||||||||||||||||||
42 | newline, on the standard output. | - | ||||||||||||||||||||||||
43 | - | |||||||||||||||||||||||||
44 | Options: | - | ||||||||||||||||||||||||
45 | -n do not append a newline | - | ||||||||||||||||||||||||
46 | -e enable interpretation of the following backslash escapes | - | ||||||||||||||||||||||||
47 | -E explicitly suppress interpretation of backslash escapes | - | ||||||||||||||||||||||||
48 | - | |||||||||||||||||||||||||
49 | `echo' interprets the following backslash-escaped characters: | - | ||||||||||||||||||||||||
50 | \a alert (bell) | - | ||||||||||||||||||||||||
51 | \b backspace | - | ||||||||||||||||||||||||
52 | \c suppress further output | - | ||||||||||||||||||||||||
53 | \e escape character | - | ||||||||||||||||||||||||
54 | \E escape character | - | ||||||||||||||||||||||||
55 | \f form feed | - | ||||||||||||||||||||||||
56 | \n new line | - | ||||||||||||||||||||||||
57 | \r carriage return | - | ||||||||||||||||||||||||
58 | \t horizontal tab | - | ||||||||||||||||||||||||
59 | \v vertical tab | - | ||||||||||||||||||||||||
60 | \\ backslash | - | ||||||||||||||||||||||||
61 | \0nnn the character whose ASCII code is NNN (octal). NNN can be | - | ||||||||||||||||||||||||
62 | 0 to 3 octal digits | - | ||||||||||||||||||||||||
63 | \xHH the eight-bit character whose value is HH (hexadecimal). HH | - | ||||||||||||||||||||||||
64 | can be one or two hex digits | - | ||||||||||||||||||||||||
65 | - | |||||||||||||||||||||||||
66 | Exit Status: | - | ||||||||||||||||||||||||
67 | Returns success unless a write error occurs. | - | ||||||||||||||||||||||||
68 | $END | - | ||||||||||||||||||||||||
69 | - | |||||||||||||||||||||||||
70 | $BUILTIN echo | - | ||||||||||||||||||||||||
71 | $FUNCTION echo_builtin | - | ||||||||||||||||||||||||
72 | $DEPENDS_ON !V9_ECHO | - | ||||||||||||||||||||||||
73 | $SHORT_DOC echo [-n] [arg ...] | - | ||||||||||||||||||||||||
74 | Write arguments to the standard output. | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | Display the ARGs on the standard output followed by a newline. | - | ||||||||||||||||||||||||
77 | - | |||||||||||||||||||||||||
78 | Options: | - | ||||||||||||||||||||||||
79 | -n do not append a newline | - | ||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||
81 | Exit Status: | - | ||||||||||||||||||||||||
82 | Returns success unless a write error occurs. | - | ||||||||||||||||||||||||
83 | $END | - | ||||||||||||||||||||||||
84 | - | |||||||||||||||||||||||||
85 | #if defined (V9_ECHO) | - | ||||||||||||||||||||||||
86 | # define VALID_ECHO_OPTIONS "neE" | - | ||||||||||||||||||||||||
87 | #else /* !V9_ECHO */ | - | ||||||||||||||||||||||||
88 | # define VALID_ECHO_OPTIONS "n" | - | ||||||||||||||||||||||||
89 | #endif /* !V9_ECHO */ | - | ||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||
91 | /* System V machines already have a /bin/sh with a v9 behaviour. We | - | ||||||||||||||||||||||||
92 | give Bash the identical behaviour for these machines so that the | - | ||||||||||||||||||||||||
93 | existing system shells won't barf. Regrettably, the SUS v2 has | - | ||||||||||||||||||||||||
94 | standardized the Sys V echo behavior. This variable is external | - | ||||||||||||||||||||||||
95 | so that we can have a `shopt' variable to control it at runtime. */ | - | ||||||||||||||||||||||||
96 | #if defined (DEFAULT_ECHO_TO_XPG) || defined (STRICT_POSIX) | - | ||||||||||||||||||||||||
97 | int xpg_echo = 1; | - | ||||||||||||||||||||||||
98 | #else | - | ||||||||||||||||||||||||
99 | int xpg_echo = 0; | - | ||||||||||||||||||||||||
100 | #endif /* DEFAULT_ECHO_TO_XPG */ | - | ||||||||||||||||||||||||
101 | - | |||||||||||||||||||||||||
102 | /* Print the words in LIST to standard output. If the first word is | - | ||||||||||||||||||||||||
103 | `-n', then don't print a trailing newline. We also support the | - | ||||||||||||||||||||||||
104 | echo syntax from Version 9 Unix systems. */ | - | ||||||||||||||||||||||||
105 | int | - | ||||||||||||||||||||||||
106 | echo_builtin (list) | - | ||||||||||||||||||||||||
107 | WORD_LIST *list; | - | ||||||||||||||||||||||||
108 | { | - | ||||||||||||||||||||||||
109 | int display_return, do_v9, i, len; | - | ||||||||||||||||||||||||
110 | char *temp, *s; | - | ||||||||||||||||||||||||
111 | - | |||||||||||||||||||||||||
112 | do_v9 = xpg_echo; | - | ||||||||||||||||||||||||
113 | display_return = 1; | - | ||||||||||||||||||||||||
114 | - | |||||||||||||||||||||||||
115 | if (posixly_correct && xpg_echo)
| 0-687457 | ||||||||||||||||||||||||
116 | goto just_echo; never executed: goto just_echo; | 0 | ||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||
118 | for (; list && (temp = list->word->word) && *temp == '-'; list = list->next)
| 0-1348375 | ||||||||||||||||||||||||
119 | { | - | ||||||||||||||||||||||||
120 | /* If it appears that we are handling options, then make sure that | - | ||||||||||||||||||||||||
121 | all of the options specified are actually valid. Otherwise, the | - | ||||||||||||||||||||||||
122 | string should just be echoed. */ | - | ||||||||||||||||||||||||
123 | temp++; | - | ||||||||||||||||||||||||
124 | - | |||||||||||||||||||||||||
125 | for (i = 0; temp[i]; i++)
| 661218-661325 | ||||||||||||||||||||||||
126 | { | - | ||||||||||||||||||||||||
127 | if (strchr (VALID_ECHO_OPTIONS, temp[i]) == 0)
| 0-661325 | ||||||||||||||||||||||||
128 | break; executed 105 times by 1 test: break; Executed by:
| 105 | ||||||||||||||||||||||||
129 | } executed 661220 times by 1 test: end of block Executed by:
| 661220 | ||||||||||||||||||||||||
130 | - | |||||||||||||||||||||||||
131 | /* echo - and echo -<nonopt> both mean to just echo the arguments. */ | - | ||||||||||||||||||||||||
132 | if (*temp == 0 || temp[i])
| 2-661321 | ||||||||||||||||||||||||
133 | break; executed 107 times by 1 test: break; Executed by:
| 107 | ||||||||||||||||||||||||
134 | - | |||||||||||||||||||||||||
135 | /* All of the options in TEMP are valid options to ECHO. | - | ||||||||||||||||||||||||
136 | Handle them. */ | - | ||||||||||||||||||||||||
137 | while (i = *temp++)
| 661216-661220 | ||||||||||||||||||||||||
138 | { | - | ||||||||||||||||||||||||
139 | switch (i) | - | ||||||||||||||||||||||||
140 | { | - | ||||||||||||||||||||||||
141 | case 'n': executed 661155 times by 1 test: case 'n': Executed by:
| 661155 | ||||||||||||||||||||||||
142 | display_return = 0; | - | ||||||||||||||||||||||||
143 | break; executed 661155 times by 1 test: break; Executed by:
| 661155 | ||||||||||||||||||||||||
144 | #if defined (V9_ECHO) | - | ||||||||||||||||||||||||
145 | case 'e': executed 60 times by 1 test: case 'e': Executed by:
| 60 | ||||||||||||||||||||||||
146 | do_v9 = 1; | - | ||||||||||||||||||||||||
147 | break; executed 60 times by 1 test: break; Executed by:
| 60 | ||||||||||||||||||||||||
148 | case 'E': executed 5 times by 1 test: case 'E': Executed by:
| 5 | ||||||||||||||||||||||||
149 | do_v9 = 0; | - | ||||||||||||||||||||||||
150 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||||||||||||||
151 | #endif /* V9_ECHO */ | - | ||||||||||||||||||||||||
152 | default: never executed: default: | 0 | ||||||||||||||||||||||||
153 | goto just_echo; /* XXX */ never executed: goto just_echo; | 0 | ||||||||||||||||||||||||
154 | } | - | ||||||||||||||||||||||||
155 | } | - | ||||||||||||||||||||||||
156 | } executed 661216 times by 1 test: end of block Executed by:
| 661216 | ||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||
158 | just_echo: code before this statement executed 687636 times by 1 test: just_echo: Executed by:
| 687636 | ||||||||||||||||||||||||
159 | - | |||||||||||||||||||||||||
160 | clearerr (stdout); /* clear error before writing and testing success */ | - | ||||||||||||||||||||||||
161 | - | |||||||||||||||||||||||||
162 | while (list)
| 687616-697417 | ||||||||||||||||||||||||
163 | { | - | ||||||||||||||||||||||||
164 | i = len = 0; | - | ||||||||||||||||||||||||
165 | temp = do_v9 ? ansicstr (list->word->word, STRLEN (list->word->word), 1, &i, &len)
| 79-697338 | ||||||||||||||||||||||||
166 | : list->word->word; | - | ||||||||||||||||||||||||
167 | if (temp)
| 0-697417 | ||||||||||||||||||||||||
168 | { | - | ||||||||||||||||||||||||
169 | if (do_v9)
| 79-697338 | ||||||||||||||||||||||||
170 | { | - | ||||||||||||||||||||||||
171 | for (s = temp; len > 0; len--)
| 79-276 | ||||||||||||||||||||||||
172 | putchar (*s++); executed 276 times by 1 test: putchar (*s++); Executed by:
| 276 | ||||||||||||||||||||||||
173 | } executed 79 times by 1 test: end of block Executed by:
| 79 | ||||||||||||||||||||||||
174 | else | - | ||||||||||||||||||||||||
175 | printf ("%s", temp); executed 697338 times by 1 test: printf ("%s", temp); Executed by:
| 697338 | ||||||||||||||||||||||||
176 | #if defined (SunOS5) | - | ||||||||||||||||||||||||
177 | fflush (stdout); /* Fix for bug in SunOS 5.5 printf(3) */ | - | ||||||||||||||||||||||||
178 | #endif | - | ||||||||||||||||||||||||
179 | } | - | ||||||||||||||||||||||||
180 | QUIT; never executed: termsig_handler (terminating_signal); never executed: throw_to_top_level ();
| 0-697417 | ||||||||||||||||||||||||
181 | if (do_v9 && temp)
| 0-697338 | ||||||||||||||||||||||||
182 | free (temp); executed 79 times by 1 test: sh_xfree((temp), "./echo.def", 182); Executed by:
| 79 | ||||||||||||||||||||||||
183 | list = list->next; | - | ||||||||||||||||||||||||
184 | if (i)
| 20-697397 | ||||||||||||||||||||||||
185 | { | - | ||||||||||||||||||||||||
186 | display_return = 0; | - | ||||||||||||||||||||||||
187 | break; executed 20 times by 1 test: break; Executed by:
| 20 | ||||||||||||||||||||||||
188 | } | - | ||||||||||||||||||||||||
189 | if (list)
| 10258-687139 | ||||||||||||||||||||||||
190 | putchar(' '); executed 10258 times by 1 test: putchar(' '); Executed by:
| 10258 | ||||||||||||||||||||||||
191 | QUIT; never executed: termsig_handler (terminating_signal); never executed: throw_to_top_level ();
| 0-697397 | ||||||||||||||||||||||||
192 | } executed 697397 times by 1 test: end of block Executed by:
| 697397 | ||||||||||||||||||||||||
193 | - | |||||||||||||||||||||||||
194 | if (display_return)
| 26461-661175 | ||||||||||||||||||||||||
195 | putchar ('\n); executed 26461 times by 1 test: putchar ('\n'); Executed by:
| 26461 | ||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||
197 | return (sh_chkwrite (EXECUTION_SUCCESS)); executed 687636 times by 1 test: return (sh_chkwrite (0)); Executed by:
| 687636 | ||||||||||||||||||||||||
198 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |