OpenCoverage

read.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/read.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is read.def, from which is created read.c.-
2It implements the builtin "read" in Bash.-
3-
4Copyright (C) 1987-2017 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 read.c-
22-
23$BUILTIN read-
24$FUNCTION read_builtin-
25$SHORT_DOC read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]-
26Read a line from the standard input and split it into fields.-
27-
28Reads a single line from the standard input, or from file descriptor FD-
29if the -u option is supplied. The line is split into fields as with word-
30splitting, and the first word is assigned to the first NAME, the second-
31word to the second NAME, and so on, with any leftover words assigned to-
32the last NAME. Only the characters found in $IFS are recognized as word-
33delimiters.-
34-
35If no NAMEs are supplied, the line read is stored in the REPLY variable.-
36-
37Options:-
38 -a array assign the words read to sequential indices of the array-
39 variable ARRAY, starting at zero-
40 -d delim continue until the first character of DELIM is read, rather-
41 than newline-
42 -e use Readline to obtain the line-
43 -i text use TEXT as the initial text for Readline-
44 -n nchars return after reading NCHARS characters rather than waiting-
45 for a newline, but honor a delimiter if fewer than-
46 NCHARS characters are read before the delimiter-
47 -N nchars return only after reading exactly NCHARS characters, unless-
48 EOF is encountered or read times out, ignoring any-
49 delimiter-
50 -p prompt output the string PROMPT without a trailing newline before-
51 attempting to read-
52 -r do not allow backslashes to escape any characters-
53 -s do not echo input coming from a terminal-
54 -t timeout time out and return failure if a complete line of-
55 input is not read within TIMEOUT seconds. The value of the-
56 TMOUT variable is the default timeout. TIMEOUT may be a-
57 fractional number. If TIMEOUT is 0, read returns-
58 immediately, without trying to read any data, returning-
59 success only if input is available on the specified-
60 file descriptor. The exit status is greater than 128-
61 if the timeout is exceeded-
62 -u fd read from file descriptor FD instead of the standard input-
63-
64Exit Status:-
65The return code is zero, unless end-of-file is encountered, read times out-
66(in which case it's greater than 128), a variable assignment error occurs,-
67or an invalid file descriptor is supplied as the argument to -u.-
68$END-
69-
70#include <config.h>-
71-
72#include "bashtypes.h"-
73#include "posixstat.h"-
74-
75#include <stdio.h>-
76-
77#include "bashansi.h"-
78-
79#if defined (HAVE_UNISTD_H)-
80# include <unistd.h>-
81#endif-
82-
83#include <signal.h>-
84#include <errno.h>-
85-
86#ifdef __CYGWIN__-
87# include <fcntl.h>-
88# include <io.h>-
89#endif-
90-
91#include "../bashintl.h"-
92-
93#include "../shell.h"-
94#include "common.h"-
95#include "bashgetopt.h"-
96#include "trap.h"-
97-
98#include <shtty.h>-
99-
100#if defined (READLINE)-
101#include "../bashline.h"-
102#include <readline/readline.h>-
103#endif-
104-
105#if defined (BUFFERED_INPUT)-
106# include "input.h"-
107#endif-
108-
109#include "shmbutil.h"-
110-
111#if !defined(errno)-
112extern int errno;-
113#endif-
114-
115struct ttsave-
116{-
117 int fd;-
118 TTYSTRUCT attrs;-
119};-
120-
121#if defined (READLINE)-
122static void reset_attempted_completion_function __P((char *));-
123static int set_itext __P((void));-
124static char *edit_line __P((char *, char *));-
125static void set_eol_delim __P((int));-
126static void reset_eol_delim __P((char *));-
127#endif-
128static SHELL_VAR *bind_read_variable __P((char *, char *));-
129#if defined (HANDLE_MULTIBYTE)-
130static int read_mbchar __P((int, char *, int, int, int));-
131#endif-
132static void ttyrestore __P((struct ttsave *));-
133-
134static sighandler sigalrm __P((int));-
135static void reset_alarm __P((void));-
136-
137/* Try this to see what the rest of the shell can do with the information. */-
138procenv_t alrmbuf;-
139int sigalrm_seen;-
140-
141static int reading, tty_modified;-
142static SigHandler *old_alrm;-
143static unsigned char delim;-
144-
145static struct ttsave termsave;-
146-
147/* In all cases, SIGALRM just sets a flag that we check periodically. This-
148 avoids problems with the semi-tricky stuff we do with the xfree of-
149 input_string at the top of the unwind-protect list (see below). */-
150-
151/* Set a flag that CHECK_ALRM can check. This relies on zread or read_builtin-
152 calling trap.c:check_signals(), which knows about sigalrm_seen and alrmbuf. */-
153static sighandler-
154sigalrm (s)-
155 int s;-
156{-
157 sigalrm_seen = 1;-
158}
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
159-
160static void-
161reset_alarm ()-
162{-
163 /* Cancel alarm before restoring signal handler. */-
164 falarm (0, 0);-
165 set_signal_handler (SIGALRM, old_alrm);-
166}
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
167-
168/* Read the value of the shell variables whose names follow.-
169 The reading is done from the current input stream, whatever-
170 that may be. Successive words of the input line are assigned-
171 to the variables mentioned in LIST. The last variable in LIST-
172 gets the remainder of the words on the line. If no variables-
173 are mentioned in LIST, then the default variable is $REPLY. */-
174int-
175read_builtin (list)-
176 WORD_LIST *list;-
177{-
178 register char *varname;-
179 int size, nr, pass_next, saw_escape, eof, opt, retval, code, print_ps2, nflag;-
180 volatile int i;-
181 int input_is_tty, input_is_pipe, unbuffered_read, skip_ctlesc, skip_ctlnul;-
182 int raw, edit, nchars, silent, have_timeout, ignore_delim, fd, lastsig, t_errno;-
183 int mb_cur_max;-
184 unsigned int tmsec, tmusec;-
185 long ival, uval;-
186 intmax_t intval;-
187 char c;-
188 char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname;-
189 char *e, *t, *t1, *ps2, *tofree;-
190 struct stat tsb;-
191 SHELL_VAR *var;-
192 TTYSTRUCT ttattrs, ttset;-
193#if defined (ARRAY_VARS)-
194 WORD_LIST *alist;-
195#endif-
196#if defined (READLINE)-
197 char *rlbuf, *itext;-
198 int rlind;-
199#endif-
200-
201 USE_VAR(size);-
202 USE_VAR(i);-
203 USE_VAR(pass_next);-
204 USE_VAR(print_ps2);-
205 USE_VAR(saw_escape);-
206 USE_VAR(input_is_pipe);-
207/* USE_VAR(raw); */-
208 USE_VAR(edit);-
209 USE_VAR(tmsec);-
210 USE_VAR(tmusec);-
211 USE_VAR(nchars);-
212 USE_VAR(silent);-
213 USE_VAR(ifs_chars);-
214 USE_VAR(prompt);-
215 USE_VAR(arrayname);-
216#if defined (READLINE)-
217 USE_VAR(rlbuf);-
218 USE_VAR(rlind);-
219 USE_VAR(itext);-
220#endif-
221 USE_VAR(list);-
222 USE_VAR(ps2);-
223 USE_VAR(lastsig);-
224-
225 sigalrm_seen = reading = tty_modified = 0;-
226-
227 i = 0; /* Index into the string that we are reading. */-
228 raw = edit = 0; /* Not reading raw input by default. */-
229 silent = 0;-
230 arrayname = prompt = (char *)NULL;-
231 fd = 0; /* file descriptor to read from */-
232-
233#if defined (READLINE)-
234 rlbuf = itext = (char *)0;-
235 rlind = 0;-
236#endif-
237-
238 mb_cur_max = MB_CUR_MAX;-
239 tmsec = tmusec = 0; /* no timeout */-
240 nr = nchars = input_is_tty = input_is_pipe = unbuffered_read = have_timeout = 0;-
241 delim = '\n'; /* read until newline */-
242 ignore_delim = nflag = 0;-
243-
244 reset_internal_getopt ();-
245 while ((opt = internal_getopt (list, "ersa:d:i:n:p:t:u:N:")) != -1)
(opt = interna...:u:N:")) != -1Description
TRUEevaluated 2642512 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322721 times by 1 test
Evaluated by:
  • Self test
1322721-2642512
246 {-
247 switch (opt)-
248 {-
249 case 'r':
executed 1321231 times by 1 test: case 'r':
Executed by:
  • Self test
1321231
250 raw = 1;-
251 break;
executed 1321231 times by 1 test: break;
Executed by:
  • Self test
1321231
252 case 'p':
executed 9 times by 1 test: case 'p':
Executed by:
  • Self test
9
253 prompt = list_optarg;-
254 break;
executed 9 times by 1 test: break;
Executed by:
  • Self test
9
255 case 's':
never executed: case 's':
0
256 silent = 1;-
257 break;
never executed: break;
0
258 case 'e':
never executed: case 'e':
0
259#if defined (READLINE)-
260 edit = 1;-
261#endif-
262 break;
never executed: break;
0
263 case 'i':
never executed: case 'i':
0
264#if defined (READLINE)-
265 itext = list_optarg;-
266#endif-
267 break;
never executed: break;
0
268#if defined (ARRAY_VARS)-
269 case 'a':
executed 27 times by 1 test: case 'a':
Executed by:
  • Self test
27
270 arrayname = list_optarg;-
271 break;
executed 27 times by 1 test: break;
Executed by:
  • Self test
27
272#endif-
273 case 't':
executed 6 times by 1 test: case 't':
Executed by:
  • Self test
6
274 code = uconvert (list_optarg, &ival, &uval);-
275 if (code == 0 || ival < 0 || uval < 0)
code == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
ival < 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
uval < 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
276 {-
277 builtin_error (_("%s: invalid timeout specification"), list_optarg);-
278 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
279 }-
280 else-
281 {-
282 have_timeout = 1;-
283 tmsec = ival;-
284 tmusec = uval;-
285 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
286 break;
executed 5 times by 1 test: break;
Executed by:
  • Self test
5
287 case 'N':
executed 1 time by 1 test: case 'N':
Executed by:
  • Self test
1
288 ignore_delim = 1;-
289 delim = -1;-
290 case 'n':
code before this statement executed 1 time by 1 test: case 'n':
Executed by:
  • Self test
executed 11 times by 1 test: case 'n':
Executed by:
  • Self test
1-11
291 nflag = 1;-
292 code = legal_number (list_optarg, &intval);-
293 if (code == 0 || intval < 0 || intval != (int)intval)
code == 0Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
intval < 0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
intval != (int)intvalDescription
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-12
294 {-
295 sh_invalidnum (list_optarg);-
296 return (EXECUTION_FAILURE);
executed 7 times by 1 test: return (1);
Executed by:
  • Self test
7
297 }-
298 else-
299 nchars = intval;
executed 5 times by 1 test: nchars = intval;
Executed by:
  • Self test
5
300 break;
executed 5 times by 1 test: break;
Executed by:
  • Self test
5
301 case 'u':
executed 1321221 times by 1 test: case 'u':
Executed by:
  • Self test
1321221
302 code = legal_number (list_optarg, &intval);-
303 if (code == 0 || intval < 0 || intval != (int)intval)
code == 0Description
TRUEnever evaluated
FALSEevaluated 1321221 times by 1 test
Evaluated by:
  • Self test
intval < 0Description
TRUEnever evaluated
FALSEevaluated 1321221 times by 1 test
Evaluated by:
  • Self test
intval != (int)intvalDescription
TRUEnever evaluated
FALSEevaluated 1321221 times by 1 test
Evaluated by:
  • Self test
0-1321221
304 {-
305 builtin_error (_("%s: invalid file descriptor specification"), list_optarg);-
306 return (EXECUTION_FAILURE);
never executed: return (1);
0
307 }-
308 else-
309 fd = intval;
executed 1321221 times by 1 test: fd = intval;
Executed by:
  • Self test
1321221
310 if (sh_validfd (fd) == 0)
sh_validfd (fd) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1321220 times by 1 test
Evaluated by:
  • Self test
1-1321220
311 {-
312 builtin_error (_("%d: invalid file descriptor: %s"), fd, strerror (errno));-
313 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
314 }-
315 break;
executed 1321220 times by 1 test: break;
Executed by:
  • Self test
1321220
316 case 'd':
executed 6 times by 1 test: case 'd':
Executed by:
  • Self test
6
317 delim = *list_optarg;-
318 break;
executed 6 times by 1 test: break;
Executed by:
  • Self test
6
319 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
320 default:
never executed: default:
0
321 builtin_usage ();-
322 return (EX_USAGE);
never executed: return (258);
0
323 }-
324 }-
325 list = loptend;-
326-
327 /* `read -t 0 var' tests whether input is available with select/FIONREAD,-
328 and fails if those are unavailable */-
329 if (have_timeout && tmsec == 0 && tmusec == 0)
have_timeoutDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322716 times by 1 test
Evaluated by:
  • Self test
tmsec == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
tmusec == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1322716
330#if 0-
331 return (EXECUTION_FAILURE);-
332#else-
333 return (input_avail (fd) ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
executed 3 times by 1 test: return (input_avail (fd) ? 0 : 1);
Executed by:
  • Self test
3
334#endif-
335-
336 /* Convenience: check early whether or not the first of possibly several-
337 variable names is a valid identifier, and bail early if so. */-
338#if defined (ARRAY_VARS)-
339 if (list && legal_identifier (list->word->word) == 0 && valid_array_reference (list->word->word, assoc_expand_once) == 0)
listDescription
TRUEevaluated 1322643 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 75 times by 1 test
Evaluated by:
  • Self test
legal_identifi...rd->word) == 0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322639 times by 1 test
Evaluated by:
  • Self test
valid_array_re...and_once) == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-1322643
340#else-
341 if (list && legal_identifier (list->word->word) == 0)-
342#endif-
343 {-
344 sh_invalidid (list->word->word);-
345 return (EXECUTION_FAILURE);
executed 2 times by 1 test: return (1);
Executed by:
  • Self test
2
346 }-
347-
348 /* If we're asked to ignore the delimiter, make sure we do. */-
349 if (ignore_delim)
ignore_delimDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322715 times by 1 test
Evaluated by:
  • Self test
1-1322715
350 delim = -1;
executed 1 time by 1 test: delim = -1;
Executed by:
  • Self test
1
351-
352 /* IF IFS is unset, we use the default of " \t\n". */-
353 ifs_chars = getifs ();-
354 if (ifs_chars == 0) /* XXX - shouldn't happen */
ifs_chars == 0Description
TRUEnever evaluated
FALSEevaluated 1322716 times by 1 test
Evaluated by:
  • Self test
0-1322716
355 ifs_chars = "";
never executed: ifs_chars = "";
0
356 /* If we want to read exactly NCHARS chars, don't split on IFS */-
357 if (ignore_delim)
ignore_delimDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322715 times by 1 test
Evaluated by:
  • Self test
1-1322715
358 ifs_chars = "";
executed 1 time by 1 test: ifs_chars = "";
Executed by:
  • Self test
1
359 for (skip_ctlesc = skip_ctlnul = 0, e = ifs_chars; *e; e++)
*eDescription
TRUEevaluated 3967306 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322716 times by 1 test
Evaluated by:
  • Self test
1322716-3967306
360 skip_ctlesc |= *e == CTLESC, skip_ctlnul |= *e == CTLNUL;
executed 3967306 times by 1 test: skip_ctlesc |= *e == '\001', skip_ctlnul |= *e == '\177';
Executed by:
  • Self test
3967306
361-
362 input_string = (char *)xmalloc (size = 112); /* XXX was 128 */-
363 input_string[0] = '\0';-
364-
365 /* More input and options validation */-
366 if (nflag == 1 && nchars == 0)
nflag == 1Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322711 times by 1 test
Evaluated by:
  • Self test
nchars == 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-1322711
367 {-
368 retval = read (fd, &c, 0);-
369 retval = (retval >= 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE;
(retval >= 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
370 goto assign_vars; /* bail early if asked to read 0 chars */
never executed: goto assign_vars;
0
371 }-
372-
373 /* $TMOUT, if set, is the default timeout for read. */-
374 if (have_timeout == 0 && (e = get_string_value ("TMOUT")))
have_timeout == 0Description
TRUEevaluated 1322714 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(e = get_strin...lue ("TMOUT"))Description
TRUEnever evaluated
FALSEevaluated 1322714 times by 1 test
Evaluated by:
  • Self test
0-1322714
375 {-
376 code = uconvert (e, &ival, &uval);-
377 if (code == 0 || ival < 0 || uval < 0)
code == 0Description
TRUEnever evaluated
FALSEnever evaluated
ival < 0Description
TRUEnever evaluated
FALSEnever evaluated
uval < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
378 tmsec = tmusec = 0;
never executed: tmsec = tmusec = 0;
0
379 else-
380 {-
381 tmsec = ival;-
382 tmusec = uval;-
383 }
never executed: end of block
0
384 }-
385-
386 begin_unwind_frame ("read_builtin");-
387-
388#if defined (BUFFERED_INPUT)-
389 if (interactive == 0 && default_buffered_input >= 0 && fd_is_bash_input (fd))
interactive == 0Description
TRUEevaluated 1322716 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
default_buffered_input >= 0Description
TRUEevaluated 1321908 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 808 times by 1 test
Evaluated by:
  • Self test
fd_is_bash_input (fd)Description
TRUEnever evaluated
FALSEevaluated 1321908 times by 1 test
Evaluated by:
  • Self test
0-1322716
390 sync_buffered_stream (default_buffered_input);
never executed: sync_buffered_stream (default_buffered_input);
0
391#endif-
392-
393#if 1-
394 input_is_tty = isatty (fd);-
395#else-
396 input_is_tty = 1;-
397#endif-
398 if (input_is_tty == 0)
input_is_tty == 0Description
TRUEevaluated 1322716 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1322716
399#ifndef __CYGWIN__-
400 input_is_pipe = (lseek (fd, 0L, SEEK_CUR) < 0) && (errno == ESPIPE);
executed 1322716 times by 1 test: input_is_pipe = (lseek (fd, 0L, 1 ) < 0) && ( (*__errno_location ()) == 29 );
Executed by:
  • Self test
(lseek (fd, 0L, 1 ) < 0)Description
TRUEevaluated 1322238 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 478 times by 1 test
Evaluated by:
  • Self test
( (*__errno_lo...on ()) == 29 )Description
TRUEevaluated 1322237 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-1322716
401#else-
402 input_is_pipe = 1;-
403#endif-
404-
405 /* If the -p, -e or -s flags were given, but input is not coming from the-
406 terminal, turn them off. */-
407 if ((prompt || edit || silent) && input_is_tty == 0)
promptDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322707 times by 1 test
Evaluated by:
  • Self test
editDescription
TRUEnever evaluated
FALSEevaluated 1322707 times by 1 test
Evaluated by:
  • Self test
silentDescription
TRUEnever evaluated
FALSEevaluated 1322707 times by 1 test
Evaluated by:
  • Self test
input_is_tty == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1322707
408 {-
409 prompt = (char *)NULL;-
410#if defined (READLINE)-
411 itext = (char *)NULL;-
412#endif-
413 edit = silent = 0;-
414 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
415-
416#if defined (READLINE)-
417 if (edit)
editDescription
TRUEnever evaluated
FALSEevaluated 1322716 times by 1 test
Evaluated by:
  • Self test
0-1322716
418 add_unwind_protect (xfree, rlbuf);
never executed: add_unwind_protect (xfree, rlbuf);
0
419#endif-
420-
421 pass_next = 0; /* Non-zero signifies last char was backslash. */-
422 saw_escape = 0; /* Non-zero signifies that we saw an escape char */-
423-
424 if (tmsec > 0 || tmusec > 0)
tmsec > 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322714 times by 1 test
Evaluated by:
  • Self test
tmusec > 0Description
TRUEnever evaluated
FALSEevaluated 1322714 times by 1 test
Evaluated by:
  • Self test
0-1322714
425 {-
426 /* Turn off the timeout if stdin is a regular file (e.g. from-
427 input redirection). */-
428 if ((fstat (fd, &tsb) < 0) || S_ISREG (tsb.st_mode))
(fstat (fd, &tsb) < 0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(((( tsb.st_mo... == (0100000))Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
429 tmsec = tmusec = 0;
never executed: tmsec = tmusec = 0;
0
430 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
431-
432 if (tmsec > 0 || tmusec > 0)
tmsec > 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322714 times by 1 test
Evaluated by:
  • Self test
tmusec > 0Description
TRUEnever evaluated
FALSEevaluated 1322714 times by 1 test
Evaluated by:
  • Self test
0-1322714
433 {-
434 code = setjmp_nosigs (alrmbuf);-
435 if (code)
codeDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
1-2
436 {-
437 sigalrm_seen = 0;-
438 /* Tricky. The top of the unwind-protect stack is the free of-
439 input_string. We want to run all the rest and use input_string,-
440 so we have to save input_string temporarily, run the unwind--
441 protects, then restore input_string so we can use it later */-
442 orig_input_string = 0;-
443 input_string[i] = '\0'; /* make sure it's terminated */-
444 if (i == 0)
i == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
445 {-
446 t = (char *)xmalloc (1);-
447 t[0] = 0;-
448 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
449 else-
450 t = savestring (input_string);
never executed: t = (char *)strcpy (sh_xmalloc((1 + strlen (input_string)), "./read.def", 450), (input_string));
0
451-
452 run_unwind_frame ("read_builtin");-
453 input_string = t;-
454 retval = 128+SIGALRM;-
455 goto assign_vars;
executed 1 time by 1 test: goto assign_vars;
Executed by:
  • Self test
1
456 }-
457 if (interactive_shell == 0)
interactive_shell == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
458 initialize_terminating_signals ();
executed 2 times by 1 test: initialize_terminating_signals ();
Executed by:
  • Self test
2
459 old_alrm = set_signal_handler (SIGALRM, sigalrm);-
460 add_unwind_protect (reset_alarm, (char *)NULL);-
461#if defined (READLINE)-
462 if (edit)
editDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
463 {-
464 add_unwind_protect (reset_attempted_completion_function, (char *)NULL);-
465 add_unwind_protect (bashline_reset_event_hook, (char *)NULL);-
466 }
never executed: end of block
0
467#endif-
468 falarm (tmsec, tmusec);-
469 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
470-
471 /* If we've been asked to read only NCHARS chars, or we're using some-
472 character other than newline to terminate the line, do the right-
473 thing to readline or the tty. */-
474 if (nchars > 0 || delim != '\n')
nchars > 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322711 times by 1 test
Evaluated by:
  • Self test
delim != '\n'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322707 times by 1 test
Evaluated by:
  • Self test
4-1322711
475 {-
476#if defined (READLINE)-
477 if (edit)
editDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
478 {-
479 if (nchars > 0)
nchars > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
480 {-
481 unwind_protect_int (rl_num_chars_to_read);-
482 rl_num_chars_to_read = nchars;-
483 }
never executed: end of block
0
484 if (delim != '\n')
delim != '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
485 {-
486 set_eol_delim (delim);-
487 add_unwind_protect (reset_eol_delim, (char *)NULL);-
488 }
never executed: end of block
0
489 }
never executed: end of block
0
490 else-
491#endif-
492 if (input_is_tty)
input_is_ttyDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
493 {-
494 /* ttsave() */-
495 termsave.fd = fd;-
496 ttgetattr (fd, &ttattrs);-
497 termsave.attrs = ttattrs;-
498-
499 ttset = ttattrs; -
500 i = silent ? ttfd_cbreak (fd, &ttset) : ttfd_onechar (fd, &ttset);
silentDescription
TRUEnever evaluated
FALSEnever evaluated
0
501 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
502 sh_ttyerror (1);
never executed: sh_ttyerror (1);
0
503 tty_modified = 1;-
504 add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);-
505 if (interactive_shell == 0)
interactive_shell == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
506 initialize_terminating_signals ();
never executed: initialize_terminating_signals ();
0
507 }
never executed: end of block
0
508 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
509 else if (silent) /* turn off echo but leave term in canonical mode */
silentDescription
TRUEnever evaluated
FALSEevaluated 1322707 times by 1 test
Evaluated by:
  • Self test
0-1322707
510 {-
511 /* ttsave (); */-
512 termsave.fd = fd;-
513 ttgetattr (fd, &ttattrs);-
514 termsave.attrs = ttattrs;-
515-
516 ttset = ttattrs;-
517 i = ttfd_noecho (fd, &ttset); /* ttnoecho (); */-
518 if (i < 0)
i < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
519 sh_ttyerror (1);
never executed: sh_ttyerror (1);
0
520-
521 tty_modified = 1;-
522 add_unwind_protect ((Function *)ttyrestore, (char *)&termsave);-
523 if (interactive_shell == 0)
interactive_shell == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
524 initialize_terminating_signals ();
never executed: initialize_terminating_signals ();
0
525 }
never executed: end of block
0
526-
527 /* This *must* be the top unwind-protect on the stack, so the manipulation-
528 of the unwind-protect stack after the realloc() works right. */-
529 add_unwind_protect (xfree, input_string);-
530-
531 CHECK_ALRM;
never executed: siglongjmp((alrmbuf), (1));
sigalrm_seenDescription
TRUEnever evaluated
FALSEevaluated 1322716 times by 1 test
Evaluated by:
  • Self test
0-1322716
532 if ((nchars > 0) && (input_is_tty == 0) && ignore_delim) /* read -N */
(nchars > 0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322711 times by 1 test
Evaluated by:
  • Self test
(input_is_tty == 0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
ignore_delimDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-1322711
533 unbuffered_read = 2;
executed 1 time by 1 test: unbuffered_read = 2;
Executed by:
  • Self test
1
534 else if ((nchars > 0) || (delim != '\n') || input_is_pipe)
(nchars > 0)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322711 times by 1 test
Evaluated by:
  • Self test
(delim != '\n')Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322707 times by 1 test
Evaluated by:
  • Self test
input_is_pipeDescription
TRUEevaluated 1322231 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 476 times by 1 test
Evaluated by:
  • Self test
4-1322711
535 unbuffered_read = 1;
executed 1322239 times by 1 test: unbuffered_read = 1;
Executed by:
  • Self test
1322239
536-
537 if (prompt && edit == 0)
promptDescription
TRUEnever evaluated
FALSEevaluated 1322716 times by 1 test
Evaluated by:
  • Self test
edit == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1322716
538 {-
539 fprintf (stderr, "%s", prompt);-
540 fflush (stderr);-
541 }
never executed: end of block
0
542-
543#if defined (__CYGWIN__) && defined (O_TEXT)-
544 setmode (0, O_TEXT);-
545#endif-
546-
547 ps2 = 0;-
548 for (print_ps2 = eof = retval = 0;;)-
549 {-
550 CHECK_ALRM;
never executed: siglongjmp((alrmbuf), (1));
sigalrm_seenDescription
TRUEnever evaluated
FALSEevaluated 1992911 times by 1 test
Evaluated by:
  • Self test
0-1992911
551-
552#if defined (READLINE)-
553 if (edit)
editDescription
TRUEnever evaluated
FALSEevaluated 1992911 times by 1 test
Evaluated by:
  • Self test
0-1992911
554 {-
555 if (rlbuf && rlbuf[rlind] == '\0')
rlbufDescription
TRUEnever evaluated
FALSEnever evaluated
rlbuf[rlind] == '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0
556 {-
557 free (rlbuf);-
558 rlbuf = (char *)0;-
559 }
never executed: end of block
0
560 if (rlbuf == 0)
rlbuf == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
561 {-
562 reading = 1;-
563 rlbuf = edit_line (prompt ? prompt : "", itext);-
564 reading = 0;-
565 rlind = 0;-
566 }
never executed: end of block
0
567 if (rlbuf == 0)
rlbuf == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
568 {-
569 eof = 1;-
570 break;
never executed: break;
0
571 }-
572 c = rlbuf[rlind++];-
573 }
never executed: end of block
0
574 else-
575 {-
576#endif-
577-
578 if (print_ps2)
print_ps2Description
TRUEnever evaluated
FALSEevaluated 1992911 times by 1 test
Evaluated by:
  • Self test
0-1992911
579 {-
580 if (ps2 == 0)
ps2 == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
581 ps2 = get_string_value ("PS2");
never executed: ps2 = get_string_value ("PS2");
0
582 fprintf (stderr, "%s", ps2 ? ps2 : "");-
583 fflush (stderr);-
584 print_ps2 = 0;-
585 }
never executed: end of block
0
586-
587 reading = 1;-
588 CHECK_ALRM;
never executed: siglongjmp((alrmbuf), (1));
sigalrm_seenDescription
TRUEnever evaluated
FALSEevaluated 1992911 times by 1 test
Evaluated by:
  • Self test
0-1992911
589 if (unbuffered_read == 2)
unbuffered_read == 2Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1992907 times by 1 test
Evaluated by:
  • Self test
4-1992907
590 retval = posixly_correct ? zreadintr (fd, &c, 1) : zreadn (fd, &c, nchars - nr);
executed 4 times by 1 test: retval = posixly_correct ? zreadintr (fd, &c, 1) : zreadn (fd, &c, nchars - nr);
Executed by:
  • Self test
posixly_correctDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-4
591 else if (unbuffered_read)
unbuffered_readDescription
TRUEevaluated 1988377 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4530 times by 1 test
Evaluated by:
  • Self test
4530-1988377
592 retval = posixly_correct ? zreadintr (fd, &c, 1) : zread (fd, &c, 1);
executed 1988377 times by 1 test: retval = posixly_correct ? zreadintr (fd, &c, 1) : zread (fd, &c, 1);
Executed by:
  • Self test
posixly_correctDescription
TRUEnever evaluated
FALSEevaluated 1988377 times by 1 test
Evaluated by:
  • Self test
0-1988377
593 else-
594 retval = posixly_correct ? zreadcintr (fd, &c) : zreadc (fd, &c);
executed 4530 times by 1 test: retval = posixly_correct ? zreadcintr (fd, &c) : zreadc (fd, &c);
Executed by:
  • Self test
posixly_correctDescription
TRUEnever evaluated
FALSEevaluated 4530 times by 1 test
Evaluated by:
  • Self test
0-4530
595 reading = 0;-
596-
597 if (retval <= 0)
retval <= 0Description
TRUEevaluated 660676 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1332234 times by 1 test
Evaluated by:
  • Self test
660676-1332234
598 {-
599 if (retval < 0 && errno == EINTR)
retval < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 660675 times by 1 test
Evaluated by:
  • Self test
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-660675
600 {-
601 check_signals (); /* in case we didn't call zread via zreadc */-
602 lastsig = LASTSIG();
terminating_signalDescription
TRUEnever evaluated
FALSEnever evaluated
interrupt_stateDescription
TRUEnever evaluated
FALSEnever evaluated
0
603 if (lastsig == 0)
lastsig == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
604 lastsig = trapped_signal_received;
never executed: lastsig = trapped_signal_received;
0
605 run_pending_traps (); /* because interrupt_immediately is not set */-
606 }
never executed: end of block
0
607 else-
608 lastsig = 0;
executed 660676 times by 1 test: lastsig = 0;
Executed by:
  • Self test
660676
609 if (terminating_signal && tty_modified)
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 660676 times by 1 test
Evaluated by:
  • Self test
tty_modifiedDescription
TRUEnever evaluated
FALSEnever evaluated
0-660676
610 ttyrestore (&termsave); /* fix terminal before exiting */
never executed: ttyrestore (&termsave);
0
611 CHECK_TERMSIG;
never executed: termsig_handler (terminating_signal);
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 660676 times by 1 test
Evaluated by:
  • Self test
0-660676
612 eof = 1;-
613 break;
executed 660676 times by 1 test: break;
Executed by:
  • Self test
660676
614 }-
615-
616 QUIT; /* in case we didn't call check_signals() */
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 1332234 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 1332234 times by 1 test
Evaluated by:
  • Self test
0-1332234
617#if defined (READLINE)-
618 }
executed 1332234 times by 1 test: end of block
Executed by:
  • Self test
1332234
619#endif-
620-
621 if (retval <= 0) /* XXX shouldn't happen */
retval <= 0Description
TRUEnever evaluated
FALSEevaluated 1332234 times by 1 test
Evaluated by:
  • Self test
0-1332234
622 CHECK_ALRM;
never executed: siglongjmp((alrmbuf), (1));
never executed: end of block
sigalrm_seenDescription
TRUEnever evaluated
FALSEnever evaluated
0
623-
624 /* XXX -- use i + mb_cur_max (at least 4) for multibyte/read_mbchar */-
625 if (i + (mb_cur_max > 4 ? mb_cur_max : 4) >= size)
i + (mb_cur_ma...x : 4) >= sizeDescription
TRUEnever evaluated
FALSEevaluated 1332234 times by 1 test
Evaluated by:
  • Self test
mb_cur_max > 4Description
TRUEevaluated 1279622 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 52612 times by 1 test
Evaluated by:
  • Self test
0-1332234
626 {-
627 char *t;-
628 t = (char *)xrealloc (input_string, size += 128);-
629-
630 /* Only need to change unwind-protect if input_string changes */-
631 if (t != input_string)
t != input_stringDescription
TRUEnever evaluated
FALSEnever evaluated
0
632 {-
633 input_string = t;-
634 remove_unwind_protect ();-
635 add_unwind_protect (xfree, input_string);-
636 }
never executed: end of block
0
637 }
never executed: end of block
0
638-
639 /* If the next character is to be accepted verbatim, a backslash-
640 newline pair still disappears from the input. */-
641 if (pass_next)
pass_nextDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1332231 times by 1 test
Evaluated by:
  • Self test
3-1332231
642 {-
643 pass_next = 0;-
644 if (c == '\n')
c == '\n'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
1-2
645 {-
646 if (skip_ctlesc == 0 && i > 0)
skip_ctlesc == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
i > 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
647 i--; /* back up over the CTLESC */
executed 1 time by 1 test: i--;
Executed by:
  • Self test
1
648 if (interactive && input_is_tty && raw == 0)
interactiveDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
input_is_ttyDescription
TRUEnever evaluated
FALSEnever evaluated
raw == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1
649 print_ps2 = 1;
never executed: print_ps2 = 1;
0
650 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
651 else-
652 goto add_char;
executed 2 times by 1 test: goto add_char;
Executed by:
  • Self test
2
653 continue;
executed 1 time by 1 test: continue;
Executed by:
  • Self test
1
654 }-
655-
656 /* This may cause problems if IFS contains CTLESC */-
657 if (c == '\\' && raw == 0)
c == '\\'Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1332218 times by 1 test
Evaluated by:
  • Self test
raw == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
3-1332218
658 {-
659 pass_next++;-
660 if (skip_ctlesc == 0)
skip_ctlesc == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
661 {-
662 saw_escape++;-
663 input_string[i++] = CTLESC;-
664 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
665 continue;
executed 3 times by 1 test: continue;
Executed by:
  • Self test
3
666 }-
667-
668 if (ignore_delim == 0 && (unsigned char)c == delim)
ignore_delim == 0Description
TRUEevaluated 1332224 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
(unsigned char)c == delimDescription
TRUEevaluated 662035 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 670189 times by 1 test
Evaluated by:
  • Self test
4-1332224
669 break;
executed 662035 times by 1 test: break;
Executed by:
  • Self test
662035
670-
671 if (c == '\0' && delim != '\0')
c == '\0'Description
TRUEnever evaluated
FALSEevaluated 670193 times by 1 test
Evaluated by:
  • Self test
delim != '\0'Description
TRUEnever evaluated
FALSEnever evaluated
0-670193
672 continue; /* skip NUL bytes in input */
never executed: continue;
0
673-
674 if ((skip_ctlesc == 0 && c == CTLESC) || (skip_ctlnul == 0 && c == CTLNUL))
skip_ctlesc == 0Description
TRUEevaluated 670145 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
c == '\001'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 670141 times by 1 test
Evaluated by:
  • Self test
skip_ctlnul == 0Description
TRUEevaluated 670171 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
c == '\177'Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 670165 times by 1 test
Evaluated by:
  • Self test
4-670171
675 {-
676 saw_escape++;-
677 input_string[i++] = CTLESC;-
678 }
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
679-
680add_char:
code before this statement executed 670193 times by 1 test: add_char:
Executed by:
  • Self test
670193
681 input_string[i++] = c;-
682 CHECK_ALRM;
never executed: siglongjmp((alrmbuf), (1));
sigalrm_seenDescription
TRUEnever evaluated
FALSEevaluated 670195 times by 1 test
Evaluated by:
  • Self test
0-670195
683-
684#if defined (HANDLE_MULTIBYTE)-
685 /* XXX - what if C == 127? Can DEL introduce a multibyte sequence? */-
686 if (mb_cur_max > 1 && is_basic (c) == 0)
mb_cur_max > 1Description
TRUEevaluated 643740 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26455 times by 1 test
Evaluated by:
  • Self test
is_basic (c) == 0Description
TRUEevaluated 90 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 643650 times by 1 test
Evaluated by:
  • Self test
90-643740
687 {-
688 input_string[i] = '\0'; /* for simplicity and debugging */-
689 /* If we got input from readline, grab the next multibyte char from-
690 rlbuf. */-
691# if defined (READLINE)-
692 if (edit)
editDescription
TRUEnever evaluated
FALSEevaluated 90 times by 1 test
Evaluated by:
  • Self test
0-90
693 {-
694 size_t clen;-
695 clen = mbrlen (rlbuf + rlind - 1, mb_cur_max, (mbstate_t *)NULL);-
696 /* We only deal with valid multibyte sequences longer than one-
697 byte. If we get anything else, we leave the one character-
698 copied and move on to the next. */-
699 if ((int)clen > 1)
(int)clen > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
700 {-
701 memcpy (input_string+i, rlbuf+rlind, clen-1);-
702 i += clen - 1;-
703 rlind += clen - 1;-
704 }
never executed: end of block
0
705 }
never executed: end of block
0
706 else-
707# endif-
708 i += read_mbchar (fd, input_string, i, c, unbuffered_read);
executed 90 times by 1 test: i += read_mbchar (fd, input_string, i, c, unbuffered_read);
Executed by:
  • Self test
90
709 }-
710#endif-
711-
712 nr++;-
713-
714 if (nchars > 0 && nr >= nchars)
nchars > 0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 670180 times by 1 test
Evaluated by:
  • Self test
nr >= ncharsDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
4-670180
715 break;
executed 4 times by 1 test: break;
Executed by:
  • Self test
4
716 }
executed 670191 times by 1 test: end of block
Executed by:
  • Self test
670191
717 input_string[i] = '\0';-
718 CHECK_ALRM;
never executed: siglongjmp((alrmbuf), (1));
sigalrm_seenDescription
TRUEnever evaluated
FALSEevaluated 1322715 times by 1 test
Evaluated by:
  • Self test
0-1322715
719-
720#if defined (READLINE)-
721 if (edit)
editDescription
TRUEnever evaluated
FALSEevaluated 1322715 times by 1 test
Evaluated by:
  • Self test
0-1322715
722 free (rlbuf);
never executed: sh_xfree((rlbuf), "./read.def", 722);
0
723#endif-
724-
725 if (retval < 0)
retval < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322714 times by 1 test
Evaluated by:
  • Self test
1-1322714
726 {-
727 t_errno = errno;-
728 if (errno != EINTR)
(*__errno_location ()) != 4Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
729 builtin_error (_("read error: %d: %s"), fd, strerror (errno));
executed 1 time by 1 test: builtin_error ( dcgettext (((void *)0), "read error: %d: %s" , 5) , fd, strerror ( (*__errno_location ()) ));
Executed by:
  • Self test
1
730 run_unwind_frame ("read_builtin");-
731 return ((t_errno != EINTR) ? EXECUTION_FAILURE : 128+lastsig);
executed 1 time by 1 test: return ((t_errno != 4 ) ? 1 : 128+lastsig);
Executed by:
  • Self test
1
732 }-
733-
734 if (tmsec > 0 || tmusec > 0)
tmsec > 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322713 times by 1 test
Evaluated by:
  • Self test
tmusec > 0Description
TRUEnever evaluated
FALSEevaluated 1322713 times by 1 test
Evaluated by:
  • Self test
0-1322713
735 reset_alarm ();
executed 1 time by 1 test: reset_alarm ();
Executed by:
  • Self test
1
736-
737 if (nchars > 0 || delim != '\n')
nchars > 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322709 times by 1 test
Evaluated by:
  • Self test
delim != '\n'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322705 times by 1 test
Evaluated by:
  • Self test
4-1322709
738 {-
739#if defined (READLINE)-
740 if (edit)
editDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
741 {-
742 if (nchars > 0)
nchars > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
743 rl_num_chars_to_read = 0;
never executed: rl_num_chars_to_read = 0;
0
744 if (delim != '\n')
delim != '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0
745 reset_eol_delim ((char *)NULL);
never executed: reset_eol_delim ((char *) ((void *)0) );
0
746 }
never executed: end of block
0
747 else-
748#endif-
749 if (input_is_tty)
input_is_ttyDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
750 ttyrestore (&termsave);
never executed: ttyrestore (&termsave);
0
751 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
752 else if (silent)
silentDescription
TRUEnever evaluated
FALSEevaluated 1322705 times by 1 test
Evaluated by:
  • Self test
0-1322705
753 ttyrestore (&termsave);
never executed: ttyrestore (&termsave);
0
754-
755 if (unbuffered_read == 0)
unbuffered_read == 0Description
TRUEevaluated 475 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322239 times by 1 test
Evaluated by:
  • Self test
475-1322239
756 zsyncfd (fd);
executed 475 times by 1 test: zsyncfd (fd);
Executed by:
  • Self test
475
757-
758 discard_unwind_frame ("read_builtin");-
759-
760 retval = eof ? EXECUTION_FAILURE : EXECUTION_SUCCESS;
eofDescription
TRUEevaluated 660675 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 662039 times by 1 test
Evaluated by:
  • Self test
660675-662039
761-
762assign_vars:
code before this statement executed 1322714 times by 1 test: assign_vars:
Executed by:
  • Self test
1322714
763-
764#if defined (ARRAY_VARS)-
765 /* If -a was given, take the string read, break it into a list of words,-
766 an assign them to `arrayname' in turn. */-
767 if (arrayname)
arraynameDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322688 times by 1 test
Evaluated by:
  • Self test
27-1322688
768 {-
769 if (legal_identifier (arrayname) == 0)
legal_identifi...rrayname) == 0Description
TRUEnever evaluated
FALSEevaluated 27 times by 1 test
Evaluated by:
  • Self test
0-27
770 {-
771 sh_invalidid (arrayname);-
772 free (input_string);-
773 return (EXECUTION_FAILURE);
never executed: return (1);
0
774 }-
775-
776 var = find_or_make_array_variable (arrayname, 1);-
777 if (var == 0)
var == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
2-25
778 {-
779 free (input_string);-
780 return EXECUTION_FAILURE; /* readonly or noassign */
executed 2 times by 1 test: return 1;
Executed by:
  • Self test
2
781 }-
782 if (assoc_p (var))
((((var)->attr... (0x0000040)))Description
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
0-25
783 {-
784 builtin_error (_("%s: cannot convert associative to indexed array"), arrayname);-
785 free (input_string);-
786 return EXECUTION_FAILURE; /* existing associative array */
never executed: return 1;
0
787 }-
788 else if (invisible_p (var))
((((var)->attr... (0x0001000)))Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 23 times by 1 test
Evaluated by:
  • Self test
2-23
789 VUNSETATTR (var, att_invisible);
executed 2 times by 1 test: ((var)->attributes &= ~(0x0001000));
Executed by:
  • Self test
2
790 array_flush (array_cell (var));-
791-
792 alist = list_string (input_string, ifs_chars, 0);-
793 if (alist)
alistDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-25
794 {-
795 if (saw_escape)
saw_escapeDescription
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
0-25
796 dequote_list (alist);
never executed: dequote_list (alist);
0
797 else-
798 word_list_remove_quoted_nulls (alist);
executed 25 times by 1 test: word_list_remove_quoted_nulls (alist);
Executed by:
  • Self test
25
799 assign_array_var_from_word_list (var, alist, 0);-
800 dispose_words (alist);-
801 }
executed 25 times by 1 test: end of block
Executed by:
  • Self test
25
802 free (input_string);-
803 return (retval);
executed 25 times by 1 test: return (retval);
Executed by:
  • Self test
25
804 }-
805#endif /* ARRAY_VARS */ -
806-
807 /* If there are no variables, save the text of the line read to the-
808 variable $REPLY. ksh93 strips leading and trailing IFS whitespace,-
809 so that `read x ; echo "$x"' and `read ; echo "$REPLY"' behave the-
810 same way, but I believe that the difference in behaviors is useful-
811 enough to not do it. Without the bash behavior, there is no way-
812 to read a line completely without interpretation or modification-
813 unless you mess with $IFS (e.g., setting it to the empty string).-
814 If you disagree, change the occurrences of `#if 0' to `#if 1' below. */-
815 if (list == 0)
list == 0Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322640 times by 1 test
Evaluated by:
  • Self test
48-1322640
816 {-
817#if 0-
818 orig_input_string = input_string;-
819 for (t = input_string; ifs_chars && *ifs_chars && spctabnl(*t) && isifs(*t); t++)-
820 ;-
821 input_string = t;-
822 input_string = strip_trailing_ifs_whitespace (input_string, ifs_chars, saw_escape);-
823#endif-
824-
825 if (saw_escape)
saw_escapeDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 45 times by 1 test
Evaluated by:
  • Self test
3-45
826 {-
827 t = dequote_string (input_string);-
828 var = bind_variable ("REPLY", t, 0);-
829 free (t);-
830 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
831 else-
832 var = bind_variable ("REPLY", input_string, 0);
executed 45 times by 1 test: var = bind_variable ("REPLY", input_string, 0);
Executed by:
  • Self test
45
833 if (var == 0 || readonly_p (var) || noassign_p (var))
var == 0Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0000002)))Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
((((var)->attr... (0x0004000)))Description
TRUEnever evaluated
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
0-48
834 retval = EXECUTION_FAILURE;
never executed: retval = 1;
0
835 else-
836 VUNSETATTR (var, att_invisible);
executed 48 times by 1 test: ((var)->attributes &= ~(0x0001000));
Executed by:
  • Self test
48
837-
838 free (input_string);-
839 return (retval);
executed 48 times by 1 test: return (retval);
Executed by:
  • Self test
48
840 }-
841-
842 /* This code implements the Posix.2 spec for splitting the words-
843 read and assigning them to variables. */-
844 orig_input_string = input_string;-
845-
846 /* Remove IFS white space at the beginning of the input string. If-
847 $IFS is null, no field splitting is performed. */-
848 for (t = input_string; ifs_chars && *ifs_chars && spctabnl(*t) && isifs(*t); t++)
ifs_charsDescription
TRUEevaluated 1323206 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*ifs_charsDescription
TRUEevaluated 1323194 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
(*t) == ' 'Description
TRUEevaluated 566 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322628 times by 1 test
Evaluated by:
  • Self test
(*t) == '\t'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322626 times by 1 test
Evaluated by:
  • Self test
(*t) == '\n'Description
TRUEnever evaluated
FALSEevaluated 1322626 times by 1 test
Evaluated by:
  • Self test
(ifs_cmap[(uns...ar)(*t)] != 0)Description
TRUEevaluated 566 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-1323206
849 ;
executed 566 times by 1 test: ;
Executed by:
  • Self test
566
850 input_string = t;-
851 for (; list->next; list = list->next)
list->nextDescription
TRUEevaluated 1019 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322640 times by 1 test
Evaluated by:
  • Self test
1019-1322640
852 {-
853 varname = list->word->word;-
854#if defined (ARRAY_VARS)-
855 if (legal_identifier (varname) == 0 && valid_array_reference (varname, assoc_expand_once) == 0)
legal_identifi...(varname) == 0Description
TRUEnever evaluated
FALSEevaluated 1019 times by 1 test
Evaluated by:
  • Self test
valid_array_re...and_once) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1019
856#else-
857 if (legal_identifier (varname) == 0)-
858#endif-
859 {-
860 sh_invalidid (varname);-
861 free (orig_input_string);-
862 return (EXECUTION_FAILURE);
never executed: return (1);
0
863 }-
864-
865 /* If there are more variables than words read from the input,-
866 the remaining variables are set to the empty string. */-
867 if (*input_string)
*input_stringDescription
TRUEevaluated 998 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
21-998
868 {-
869 /* This call updates INPUT_STRING. */-
870 t = get_word_from_string (&input_string, ifs_chars, &e);-
871 if (t)
tDescription
TRUEevaluated 998 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-998
872 *e = '\0';
executed 998 times by 1 test: *e = '\0';
Executed by:
  • Self test
998
873 /* Don't bother to remove the CTLESC unless we added one-
874 somewhere while reading the string. */-
875 if (t && saw_escape)
tDescription
TRUEevaluated 998 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
saw_escapeDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 988 times by 1 test
Evaluated by:
  • Self test
0-998
876 {-
877 t1 = dequote_string (t);-
878 var = bind_read_variable (varname, t1);-
879 free (t1);-
880 }
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
881 else-
882 var = bind_read_variable (varname, t ? t : "");
executed 988 times by 1 test: var = bind_read_variable (varname, t ? t : "");
Executed by:
  • Self test
988
883 }-
884 else-
885 {-
886 t = (char *)0;-
887 var = bind_read_variable (varname, "");-
888 }
executed 21 times by 1 test: end of block
Executed by:
  • Self test
21
889-
890 FREE (t);
executed 998 times by 1 test: sh_xfree((t), "./read.def", 890);
Executed by:
  • Self test
tDescription
TRUEevaluated 998 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
21-998
891 if (var == 0)
var == 0Description
TRUEnever evaluated
FALSEevaluated 1019 times by 1 test
Evaluated by:
  • Self test
0-1019
892 {-
893 free (orig_input_string);-
894 return (EXECUTION_FAILURE);
never executed: return (1);
0
895 }-
896-
897 stupidly_hack_special_variables (varname);-
898 VUNSETATTR (var, att_invisible);-
899 }
executed 1019 times by 1 test: end of block
Executed by:
  • Self test
1019
900-
901 /* Now assign the rest of the line to the last variable argument. */-
902#if defined (ARRAY_VARS)-
903 if (legal_identifier (list->word->word) == 0 && valid_array_reference (list->word->word, assoc_expand_once) == 0)
legal_identifi...rd->word) == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322638 times by 1 test
Evaluated by:
  • Self test
valid_array_re...and_once) == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-1322638
904#else-
905 if (legal_identifier (list->word->word) == 0)-
906#endif-
907 {-
908 sh_invalidid (list->word->word);-
909 free (orig_input_string);-
910 return (EXECUTION_FAILURE);
never executed: return (1);
0
911 }-
912-
913#if 0-
914 /* This has to be done this way rather than using string_list-
915 and list_string because Posix.2 says that the last variable gets the-
916 remaining words and their intervening separators. */-
917 input_string = strip_trailing_ifs_whitespace (input_string, ifs_chars, saw_escape);-
918#else-
919 /* Check whether or not the number of fields is exactly the same as the-
920 number of variables. */-
921 tofree = NULL;-
922 if (*input_string)
*input_stringDescription
TRUEevaluated 661843 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 660797 times by 1 test
Evaluated by:
  • Self test
660797-661843
923 {-
924 t1 = input_string;-
925 t = get_word_from_string (&input_string, ifs_chars, &e);-
926 if (*input_string == 0)
*input_string == 0Description
TRUEevaluated 661454 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 389 times by 1 test
Evaluated by:
  • Self test
389-661454
927 tofree = input_string = t;
executed 661454 times by 1 test: tofree = input_string = t;
Executed by:
  • Self test
661454
928 else-
929 {-
930 input_string = strip_trailing_ifs_whitespace (t1, ifs_chars, saw_escape);-
931 tofree = t;-
932 }
executed 389 times by 1 test: end of block
Executed by:
  • Self test
389
933 }-
934#endif-
935-
936 if (saw_escape && input_string && *input_string)
saw_escapeDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1322633 times by 1 test
Evaluated by:
  • Self test
input_stringDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*input_stringDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-1322633
937 {-
938 t = dequote_string (input_string);-
939 var = bind_read_variable (list->word->word, t);-
940 free (t);-
941 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
942 else-
943 var = bind_read_variable (list->word->word, input_string ? input_string : "");
executed 1322636 times by 1 test: var = bind_read_variable (list->word->word, input_string ? input_string : "");
Executed by:
  • Self test
1322636
944-
945 if (var)
varDescription
TRUEevaluated 1322639 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-1322639
946 {-
947 stupidly_hack_special_variables (list->word->word);-
948 VUNSETATTR (var, att_invisible);-
949 }
executed 1322639 times by 1 test: end of block
Executed by:
  • Self test
1322639
950 else-
951 retval = EXECUTION_FAILURE;
executed 1 time by 1 test: retval = 1;
Executed by:
  • Self test
1
952-
953 FREE (tofree);
executed 661843 times by 1 test: sh_xfree((tofree), "./read.def", 953);
Executed by:
  • Self test
tofreeDescription
TRUEevaluated 661843 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 660797 times by 1 test
Evaluated by:
  • Self test
660797-661843
954 free (orig_input_string);-
955-
956 return (retval);
executed 1322640 times by 1 test: return (retval);
Executed by:
  • Self test
1322640
957}-
958-
959static SHELL_VAR *-
960bind_read_variable (name, value)-
961 char *name, *value;-
962{-
963 SHELL_VAR *v;-
964-
965#if defined (ARRAY_VARS)-
966 if (valid_array_reference (name, assoc_expand_once) == 0)
valid_array_re...and_once) == 0Description
TRUEevaluated 1323657 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-1323657
967 v = bind_variable (name, value, 0);
executed 1323657 times by 1 test: v = bind_variable (name, value, 0);
Executed by:
  • Self test
1323657
968 else-
969 v = assign_array_element (name, value, assoc_expand_once ? ASS_NOEXPAND : 0);
executed 2 times by 1 test: v = assign_array_element (name, value, assoc_expand_once ? 0x0080 : 0);
Executed by:
  • Self test
2
970#else /* !ARRAY_VARS */-
971 v = bind_variable (name, value, 0);-
972#endif /* !ARRAY_VARS */-
973 return (v == 0 ? v
executed 1323659 times by 1 test: return (v == 0 ? v : ((((((v)->attributes) & (0x0000002))) || ((((v)->attributes) & (0x0004000)))) ? (SHELL_VAR *) ((void *)0) : v));
Executed by:
  • Self test
1323659
974 : ((readonly_p (v) || noassign_p (v)) ? (SHELL_VAR *)NULL : v));
executed 1323659 times by 1 test: return (v == 0 ? v : ((((((v)->attributes) & (0x0000002))) || ((((v)->attributes) & (0x0004000)))) ? (SHELL_VAR *) ((void *)0) : v));
Executed by:
  • Self test
1323659
975}-
976-
977#if defined (HANDLE_MULTIBYTE)-
978static int-
979read_mbchar (fd, string, ind, ch, unbuffered)-
980 int fd;-
981 char *string;-
982 int ind, ch, unbuffered;-
983{-
984 char mbchar[MB_LEN_MAX + 1];-
985 int i, n, r;-
986 char c;-
987 size_t ret;-
988 mbstate_t ps, ps_back;-
989 wchar_t wc;-
990-
991 memset (&ps, '\0', sizeof (mbstate_t));-
992 memset (&ps_back, '\0', sizeof (mbstate_t));-
993 -
994 mbchar[0] = ch;-
995 i = 1;-
996 for (n = 0; n <= MB_LEN_MAX; n++)
n <= 16Description
TRUEevaluated 116 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-116
997 {-
998 ps_back = ps;-
999 ret = mbrtowc (&wc, mbchar, i, &ps);-
1000 if (ret == (size_t)-2)
ret == (size_t)-2Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 90 times by 1 test
Evaluated by:
  • Self test
26-90
1001 {-
1002 ps = ps_back;-
1003-
1004 /* We don't want to be interrupted during a multibyte char read */-
1005 if (unbuffered == 2)
unbuffered == 2Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-26
1006 r = zreadn (fd, &c, 1);
never executed: r = zreadn (fd, &c, 1);
0
1007 else if (unbuffered)
unbufferedDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
5-21
1008 r = zread (fd, &c, 1);
executed 5 times by 1 test: r = zread (fd, &c, 1);
Executed by:
  • Self test
5
1009 else-
1010 r = zreadc (fd, &c);
executed 21 times by 1 test: r = zreadc (fd, &c);
Executed by:
  • Self test
21
1011 if (r <= 0)
r <= 0Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-26
1012 goto mbchar_return;
never executed: goto mbchar_return;
0
1013 mbchar[i++] = c; -
1014 continue;
executed 26 times by 1 test: continue;
Executed by:
  • Self test
26
1015 }-
1016 else if (ret == (size_t)-1 || ret == (size_t)0 || ret > (size_t)0)
ret == (size_t)-1Description
TRUEnever evaluated
FALSEevaluated 90 times by 1 test
Evaluated by:
  • Self test
ret == (size_t)0Description
TRUEnever evaluated
FALSEevaluated 90 times by 1 test
Evaluated by:
  • Self test
ret > (size_t)0Description
TRUEevaluated 90 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-90
1017 break;
executed 90 times by 1 test: break;
Executed by:
  • Self test
90
1018 }
never executed: end of block
0
1019-
1020mbchar_return:
code before this statement executed 90 times by 1 test: mbchar_return:
Executed by:
  • Self test
90
1021 if (i > 1) /* read a multibyte char */
i > 1Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 64 times by 1 test
Evaluated by:
  • Self test
26-64
1022 /* mbchar[0] is already string[ind-1] */-
1023 for (r = 1; r < i; r++)
r < iDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26
1024 string[ind+r-1] = mbchar[r];
executed 26 times by 1 test: string[ind+r-1] = mbchar[r];
Executed by:
  • Self test
26
1025 return i - 1;
executed 90 times by 1 test: return i - 1;
Executed by:
  • Self test
90
1026}-
1027#endif-
1028-
1029-
1030static void-
1031ttyrestore (ttp)-
1032 struct ttsave *ttp;-
1033{-
1034 ttsetattr (ttp->fd, &(ttp->attrs));-
1035 tty_modified = 0;-
1036}
never executed: end of block
0
1037-
1038void-
1039read_tty_cleanup ()-
1040{-
1041 if (tty_modified)
tty_modifiedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1042 ttyrestore (&termsave);
never executed: ttyrestore (&termsave);
0
1043}
never executed: end of block
0
1044-
1045int-
1046read_tty_modified ()-
1047{-
1048 return (tty_modified);
executed 550 times by 1 test: return (tty_modified);
Executed by:
  • Self test
550
1049}-
1050-
1051#if defined (READLINE)-
1052static rl_completion_func_t *old_attempted_completion_function = 0;-
1053static rl_hook_func_t *old_startup_hook;-
1054static char *deftext;-
1055-
1056static void-
1057reset_attempted_completion_function (cp)-
1058 char *cp;-
1059{-
1060 if (rl_attempted_completion_function == 0 && old_attempted_completion_function)
rl_attempted_c..._function == 0Description
TRUEnever evaluated
FALSEnever evaluated
old_attempted_...etion_functionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1061 rl_attempted_completion_function = old_attempted_completion_function;
never executed: rl_attempted_completion_function = old_attempted_completion_function;
0
1062}
never executed: end of block
0
1063-
1064static int-
1065set_itext ()-
1066{-
1067 int r1, r2;-
1068-
1069 r1 = r2 = 0;-
1070 if (old_startup_hook)
old_startup_hookDescription
TRUEnever evaluated
FALSEnever evaluated
0
1071 r1 = (*old_startup_hook) ();
never executed: r1 = (*old_startup_hook) ();
0
1072 if (deftext)
deftextDescription
TRUEnever evaluated
FALSEnever evaluated
0
1073 {-
1074 r2 = rl_insert_text (deftext);-
1075 deftext = (char *)NULL;-
1076 rl_startup_hook = old_startup_hook;-
1077 old_startup_hook = (rl_hook_func_t *)NULL;-
1078 }
never executed: end of block
0
1079 return (r1 || r2);
never executed: return (r1 || r2);
0
1080}-
1081-
1082static char *-
1083edit_line (p, itext)-
1084 char *p;-
1085 char *itext;-
1086{-
1087 char *ret;-
1088 int len;-
1089-
1090 if (bash_readline_initialized == 0)
bash_readline_initialized == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1091 initialize_readline ();
never executed: initialize_readline ();
0
1092-
1093 old_attempted_completion_function = rl_attempted_completion_function;-
1094 rl_attempted_completion_function = (rl_completion_func_t *)NULL;-
1095 bashline_set_event_hook ();-
1096 if (itext)
itextDescription
TRUEnever evaluated
FALSEnever evaluated
0
1097 {-
1098 old_startup_hook = rl_startup_hook;-
1099 rl_startup_hook = set_itext;-
1100 deftext = itext;-
1101 }
never executed: end of block
0
1102-
1103 ret = readline (p);-
1104-
1105 rl_attempted_completion_function = old_attempted_completion_function;-
1106 old_attempted_completion_function = (rl_completion_func_t *)NULL;-
1107 bashline_reset_event_hook ();-
1108-
1109 if (ret == 0)
ret == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1110 return ret;
never executed: return ret;
0
1111 len = strlen (ret);-
1112 ret = (char *)xrealloc (ret, len + 2);-
1113 ret[len++] = delim;-
1114 ret[len] = '\0';-
1115 return ret;
never executed: return ret;
0
1116}-
1117-
1118static int old_delim_ctype;-
1119static rl_command_func_t *old_delim_func;-
1120static int old_newline_ctype;-
1121static rl_command_func_t *old_newline_func;-
1122-
1123static unsigned char delim_char;-
1124-
1125static void-
1126set_eol_delim (c)-
1127 int c;-
1128{-
1129 Keymap cmap;-
1130-
1131 if (bash_readline_initialized == 0)
bash_readline_initialized == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1132 initialize_readline ();
never executed: initialize_readline ();
0
1133 cmap = rl_get_keymap ();-
1134-
1135 /* Change newline to self-insert */-
1136 old_newline_ctype = cmap[RETURN].type;-
1137 old_newline_func = cmap[RETURN].function;-
1138 cmap[RETURN].type = ISFUNC;-
1139 cmap[RETURN].function = rl_insert;-
1140-
1141 /* Bind the delimiter character to accept-line. */-
1142 old_delim_ctype = cmap[c].type;-
1143 old_delim_func = cmap[c].function;-
1144 cmap[c].type = ISFUNC;-
1145 cmap[c].function = rl_newline;-
1146-
1147 delim_char = c;-
1148}
never executed: end of block
0
1149-
1150static void-
1151reset_eol_delim (cp)-
1152 char *cp;-
1153{-
1154 Keymap cmap;-
1155-
1156 cmap = rl_get_keymap ();-
1157-
1158 cmap[RETURN].type = old_newline_ctype;-
1159 cmap[RETURN].function = old_newline_func;-
1160-
1161 cmap[delim_char].type = old_delim_ctype;-
1162 cmap[delim_char].function = old_delim_func;-
1163}
never executed: end of block
0
1164#endif-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2