OpenCoverage

echo.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/echo.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is echo.def, from which is created echo.c.-
2It implements the builtin "echo" in Bash.-
3-
4Copyright (C) 1987-2016 Free Software Foundation, Inc.-
5-
6This file is part of GNU Bash, the Bourne Again SHell.-
7-
8Bash is free software: you can redistribute it and/or modify-
9it under the terms of the GNU General Public License as published by-
10the Free Software Foundation, either version 3 of the License, or-
11(at your option) any later version.-
12-
13Bash is distributed in the hope that it will be useful,-
14but WITHOUT ANY WARRANTY; without even the implied warranty of-
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16GNU General Public License for more details.-
17-
18You should have received a copy of the GNU General Public License-
19along 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 ...]-
39Write arguments to the standard output.-
40-
41Display the ARGs, separated by a single space character and followed by a-
42newline, on the standard output.-
43-
44Options:-
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-
66Exit Status:-
67Returns 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 ...]-
74Write arguments to the standard output.-
75-
76Display the ARGs on the standard output followed by a newline.-
77-
78Options:-
79 -n do not append a newline-
80-
81Exit Status:-
82Returns 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)-
97int xpg_echo = 1;-
98#else-
99int 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. */-
105int-
106echo_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)
posixly_correctDescription
TRUEevaluated 179 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 687457 times by 1 test
Evaluated by:
  • Self test
xpg_echoDescription
TRUEnever evaluated
FALSEevaluated 179 times by 1 test
Evaluated by:
  • Self test
0-687457
116 goto just_echo;
never executed: goto just_echo;
0
117-
118 for (; list && (temp = list->word->word) && *temp == '-'; list = list->next)
listDescription
TRUEevaluated 1348375 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 477 times by 1 test
Evaluated by:
  • Self test
(temp = list->word->word)Description
TRUEevaluated 1348375 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*temp == '-'Description
TRUEevaluated 661323 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 687052 times by 1 test
Evaluated by:
  • Self test
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++)
temp[i]Description
TRUEevaluated 661325 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661218 times by 1 test
Evaluated by:
  • Self test
661218-661325
126 {-
127 if (strchr (VALID_ECHO_OPTIONS, temp[i]) == 0)
(__extension__...mp[i] ))) == 0Description
TRUEevaluated 105 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661220 times by 1 test
Evaluated by:
  • Self test
__builtin_cons..._p ( temp[i] )Description
TRUEnever evaluated
FALSEevaluated 661325 times by 1 test
Evaluated by:
  • Self test
!__builtin_con...nt_p ( "neE" )Description
TRUEnever evaluated
FALSEnever evaluated
( temp[i] ) == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-661325
128 break;
executed 105 times by 1 test: break;
Executed by:
  • Self test
105
129 }
executed 661220 times by 1 test: end of block
Executed by:
  • Self test
661220
130-
131 /* echo - and echo -<nonopt> both mean to just echo the arguments. */-
132 if (*temp == 0 || temp[i])
*temp == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661321 times by 1 test
Evaluated by:
  • Self test
temp[i]Description
TRUEevaluated 105 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661216 times by 1 test
Evaluated by:
  • Self test
2-661321
133 break;
executed 107 times by 1 test: break;
Executed by:
  • Self test
107
134-
135 /* All of the options in TEMP are valid options to ECHO.-
136 Handle them. */-
137 while (i = *temp++)
i = *temp++Description
TRUEevaluated 661220 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661216 times by 1 test
Evaluated by:
  • Self test
661216-661220
138 {-
139 switch (i)-
140 {-
141 case 'n':
executed 661155 times by 1 test: case 'n':
Executed by:
  • Self test
661155
142 display_return = 0;-
143 break;
executed 661155 times by 1 test: break;
Executed by:
  • Self test
661155
144#if defined (V9_ECHO)-
145 case 'e':
executed 60 times by 1 test: case 'e':
Executed by:
  • Self test
60
146 do_v9 = 1;-
147 break;
executed 60 times by 1 test: break;
Executed by:
  • Self test
60
148 case 'E':
executed 5 times by 1 test: case 'E':
Executed by:
  • Self test
5
149 do_v9 = 0;-
150 break;
executed 5 times by 1 test: break;
Executed by:
  • Self test
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:
  • Self test
661216
157-
158just_echo:
code before this statement executed 687636 times by 1 test: just_echo:
Executed by:
  • Self test
687636
159-
160 clearerr (stdout); /* clear error before writing and testing success */-
161-
162 while (list)
listDescription
TRUEevaluated 697417 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 687616 times by 1 test
Evaluated by:
  • Self test
687616-697417
163 {-
164 i = len = 0;-
165 temp = do_v9 ? ansicstr (list->word->word, STRLEN (list->word->word), 1, &i, &len)
do_v9Description
TRUEevaluated 79 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 697338 times by 1 test
Evaluated by:
  • Self test
79-697338
166 : list->word->word;-
167 if (temp)
tempDescription
TRUEevaluated 697417 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-697417
168 {-
169 if (do_v9)
do_v9Description
TRUEevaluated 79 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 697338 times by 1 test
Evaluated by:
  • Self test
79-697338
170 {-
171 for (s = temp; len > 0; len--)
len > 0Description
TRUEevaluated 276 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 79 times by 1 test
Evaluated by:
  • Self test
79-276
172 putchar (*s++);
executed 276 times by 1 test: putchar (*s++);
Executed by:
  • Self test
276
173 }
executed 79 times by 1 test: end of block
Executed by:
  • Self test
79
174 else -
175 printf ("%s", temp);
executed 697338 times by 1 test: printf ("%s", temp);
Executed by:
  • Self test
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 ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 697417 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 697417 times by 1 test
Evaluated by:
  • Self test
0-697417
181 if (do_v9 && temp)
do_v9Description
TRUEevaluated 79 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 697338 times by 1 test
Evaluated by:
  • Self test
tempDescription
TRUEevaluated 79 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-697338
182 free (temp);
executed 79 times by 1 test: sh_xfree((temp), "./echo.def", 182);
Executed by:
  • Self test
79
183 list = list->next;-
184 if (i)
iDescription
TRUEevaluated 20 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 697397 times by 1 test
Evaluated by:
  • Self test
20-697397
185 {-
186 display_return = 0;-
187 break;
executed 20 times by 1 test: break;
Executed by:
  • Self test
20
188 }-
189 if (list)
listDescription
TRUEevaluated 10258 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 687139 times by 1 test
Evaluated by:
  • Self test
10258-687139
190 putchar(' ');
executed 10258 times by 1 test: putchar(' ');
Executed by:
  • Self test
10258
191 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 697397 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 697397 times by 1 test
Evaluated by:
  • Self test
0-697397
192 }
executed 697397 times by 1 test: end of block
Executed by:
  • Self test
697397
193-
194 if (display_return)
display_returnDescription
TRUEevaluated 26461 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 661175 times by 1 test
Evaluated by:
  • Self test
26461-661175
195 putchar ('\n);
executed 26461 times by 1 test: putchar ('\n');
Executed by:
  • Self test
26461
196-
197 return (sh_chkwrite (EXECUTION_SUCCESS));
executed 687636 times by 1 test: return (sh_chkwrite (0));
Executed by:
  • Self test
687636
198}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2