| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/read.def |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | This file is read.def, from which is created read.c. | - | ||||||||||||||||||||||||||||||||||||
| 2 | It implements the builtin "read" in Bash. | - | ||||||||||||||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||||||||||||||
| 4 | Copyright (C) 1987-2017 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 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 ...] | - | ||||||||||||||||||||||||||||||||||||
| 26 | Read a line from the standard input and split it into fields. | - | ||||||||||||||||||||||||||||||||||||
| 27 | - | |||||||||||||||||||||||||||||||||||||
| 28 | Reads a single line from the standard input, or from file descriptor FD | - | ||||||||||||||||||||||||||||||||||||
| 29 | if the -u option is supplied. The line is split into fields as with word | - | ||||||||||||||||||||||||||||||||||||
| 30 | splitting, and the first word is assigned to the first NAME, the second | - | ||||||||||||||||||||||||||||||||||||
| 31 | word to the second NAME, and so on, with any leftover words assigned to | - | ||||||||||||||||||||||||||||||||||||
| 32 | the last NAME. Only the characters found in $IFS are recognized as word | - | ||||||||||||||||||||||||||||||||||||
| 33 | delimiters. | - | ||||||||||||||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||||||||||||||
| 35 | If no NAMEs are supplied, the line read is stored in the REPLY variable. | - | ||||||||||||||||||||||||||||||||||||
| 36 | - | |||||||||||||||||||||||||||||||||||||
| 37 | Options: | - | ||||||||||||||||||||||||||||||||||||
| 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 | - | |||||||||||||||||||||||||||||||||||||
| 64 | Exit Status: | - | ||||||||||||||||||||||||||||||||||||
| 65 | The 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, | - | ||||||||||||||||||||||||||||||||||||
| 67 | or 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) | - | ||||||||||||||||||||||||||||||||||||
| 112 | extern int errno; | - | ||||||||||||||||||||||||||||||||||||
| 113 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||||||||||||||
| 115 | struct ttsave | - | ||||||||||||||||||||||||||||||||||||
| 116 | { | - | ||||||||||||||||||||||||||||||||||||
| 117 | int fd; | - | ||||||||||||||||||||||||||||||||||||
| 118 | TTYSTRUCT attrs; | - | ||||||||||||||||||||||||||||||||||||
| 119 | }; | - | ||||||||||||||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||||||||||||||
| 121 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 122 | static void reset_attempted_completion_function __P((char *)); | - | ||||||||||||||||||||||||||||||||||||
| 123 | static int set_itext __P((void)); | - | ||||||||||||||||||||||||||||||||||||
| 124 | static char *edit_line __P((char *, char *)); | - | ||||||||||||||||||||||||||||||||||||
| 125 | static void set_eol_delim __P((int)); | - | ||||||||||||||||||||||||||||||||||||
| 126 | static void reset_eol_delim __P((char *)); | - | ||||||||||||||||||||||||||||||||||||
| 127 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 128 | static SHELL_VAR *bind_read_variable __P((char *, char *)); | - | ||||||||||||||||||||||||||||||||||||
| 129 | #if defined (HANDLE_MULTIBYTE) | - | ||||||||||||||||||||||||||||||||||||
| 130 | static int read_mbchar __P((int, char *, int, int, int)); | - | ||||||||||||||||||||||||||||||||||||
| 131 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 132 | static void ttyrestore __P((struct ttsave *)); | - | ||||||||||||||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||||||||||||||
| 134 | static sighandler sigalrm __P((int)); | - | ||||||||||||||||||||||||||||||||||||
| 135 | static void reset_alarm __P((void)); | - | ||||||||||||||||||||||||||||||||||||
| 136 | - | |||||||||||||||||||||||||||||||||||||
| 137 | /* Try this to see what the rest of the shell can do with the information. */ | - | ||||||||||||||||||||||||||||||||||||
| 138 | procenv_t alrmbuf; | - | ||||||||||||||||||||||||||||||||||||
| 139 | int sigalrm_seen; | - | ||||||||||||||||||||||||||||||||||||
| 140 | - | |||||||||||||||||||||||||||||||||||||
| 141 | static int reading, tty_modified; | - | ||||||||||||||||||||||||||||||||||||
| 142 | static SigHandler *old_alrm; | - | ||||||||||||||||||||||||||||||||||||
| 143 | static unsigned char delim; | - | ||||||||||||||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||||||||||||||
| 145 | static 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. */ | - | ||||||||||||||||||||||||||||||||||||
| 153 | static sighandler | - | ||||||||||||||||||||||||||||||||||||
| 154 | sigalrm (s) | - | ||||||||||||||||||||||||||||||||||||
| 155 | int s; | - | ||||||||||||||||||||||||||||||||||||
| 156 | { | - | ||||||||||||||||||||||||||||||||||||
| 157 | sigalrm_seen = 1; | - | ||||||||||||||||||||||||||||||||||||
| 158 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 159 | - | |||||||||||||||||||||||||||||||||||||
| 160 | static void | - | ||||||||||||||||||||||||||||||||||||
| 161 | reset_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 blockExecuted by:
| 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. */ | - | ||||||||||||||||||||||||||||||||||||
| 174 | int | - | ||||||||||||||||||||||||||||||||||||
| 175 | read_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)
| 1322721-2642512 | ||||||||||||||||||||||||||||||||||||
| 246 | { | - | ||||||||||||||||||||||||||||||||||||
| 247 | switch (opt) | - | ||||||||||||||||||||||||||||||||||||
| 248 | { | - | ||||||||||||||||||||||||||||||||||||
| 249 | case 'r': executed 1321231 times by 1 test: case 'r':Executed by:
| 1321231 | ||||||||||||||||||||||||||||||||||||
| 250 | raw = 1; | - | ||||||||||||||||||||||||||||||||||||
| 251 | break; executed 1321231 times by 1 test: break;Executed by:
| 1321231 | ||||||||||||||||||||||||||||||||||||
| 252 | case 'p': executed 9 times by 1 test: case 'p':Executed by:
| 9 | ||||||||||||||||||||||||||||||||||||
| 253 | prompt = list_optarg; | - | ||||||||||||||||||||||||||||||||||||
| 254 | break; executed 9 times by 1 test: break;Executed by:
| 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:
| 27 | ||||||||||||||||||||||||||||||||||||
| 270 | arrayname = list_optarg; | - | ||||||||||||||||||||||||||||||||||||
| 271 | break; executed 27 times by 1 test: break;Executed by:
| 27 | ||||||||||||||||||||||||||||||||||||
| 272 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 273 | case 't': executed 6 times by 1 test: case 't':Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
| 274 | code = uconvert (list_optarg, &ival, &uval); | - | ||||||||||||||||||||||||||||||||||||
| 275 | if (code == 0 || ival < 0 || uval < 0)
| 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:
| 1 | ||||||||||||||||||||||||||||||||||||
| 279 | } | - | ||||||||||||||||||||||||||||||||||||
| 280 | else | - | ||||||||||||||||||||||||||||||||||||
| 281 | { | - | ||||||||||||||||||||||||||||||||||||
| 282 | have_timeout = 1; | - | ||||||||||||||||||||||||||||||||||||
| 283 | tmsec = ival; | - | ||||||||||||||||||||||||||||||||||||
| 284 | tmusec = uval; | - | ||||||||||||||||||||||||||||||||||||
| 285 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 286 | break; executed 5 times by 1 test: break;Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 287 | case 'N': executed 1 time by 1 test: case 'N':Executed by:
| 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:
executed 11 times by 1 test: case 'n':Executed by:
| 1-11 | ||||||||||||||||||||||||||||||||||||
| 291 | nflag = 1; | - | ||||||||||||||||||||||||||||||||||||
| 292 | code = legal_number (list_optarg, &intval); | - | ||||||||||||||||||||||||||||||||||||
| 293 | if (code == 0 || intval < 0 || intval != (int)intval)
| 0-12 | ||||||||||||||||||||||||||||||||||||
| 294 | { | - | ||||||||||||||||||||||||||||||||||||
| 295 | sh_invalidnum (list_optarg); | - | ||||||||||||||||||||||||||||||||||||
| 296 | return (EXECUTION_FAILURE); executed 7 times by 1 test: return (1);Executed by:
| 7 | ||||||||||||||||||||||||||||||||||||
| 297 | } | - | ||||||||||||||||||||||||||||||||||||
| 298 | else | - | ||||||||||||||||||||||||||||||||||||
| 299 | nchars = intval; executed 5 times by 1 test: nchars = intval;Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 300 | break; executed 5 times by 1 test: break;Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 301 | case 'u': executed 1321221 times by 1 test: case 'u':Executed by:
| 1321221 | ||||||||||||||||||||||||||||||||||||
| 302 | code = legal_number (list_optarg, &intval); | - | ||||||||||||||||||||||||||||||||||||
| 303 | if (code == 0 || intval < 0 || intval != (int)intval)
| 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:
| 1321221 | ||||||||||||||||||||||||||||||||||||
| 310 | if (sh_validfd (fd) == 0)
| 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:
| 1 | ||||||||||||||||||||||||||||||||||||
| 314 | } | - | ||||||||||||||||||||||||||||||||||||
| 315 | break; executed 1321220 times by 1 test: break;Executed by:
| 1321220 | ||||||||||||||||||||||||||||||||||||
| 316 | case 'd': executed 6 times by 1 test: case 'd':Executed by:
| 6 | ||||||||||||||||||||||||||||||||||||
| 317 | delim = *list_optarg; | - | ||||||||||||||||||||||||||||||||||||
| 318 | break; executed 6 times by 1 test: break;Executed by:
| 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)
| 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:
| 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)
| 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:
| 2 | ||||||||||||||||||||||||||||||||||||
| 346 | } | - | ||||||||||||||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||||||||||||||
| 348 | /* If we're asked to ignore the delimiter, make sure we do. */ | - | ||||||||||||||||||||||||||||||||||||
| 349 | if (ignore_delim)
| 1-1322715 | ||||||||||||||||||||||||||||||||||||
| 350 | delim = -1; executed 1 time by 1 test: delim = -1;Executed by:
| 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 */
| 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)
| 1-1322715 | ||||||||||||||||||||||||||||||||||||
| 358 | ifs_chars = ""; executed 1 time by 1 test: ifs_chars = "";Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 359 | for (skip_ctlesc = skip_ctlnul = 0, e = ifs_chars; *e; e++)
| 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:
| 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)
| 0-1322711 | ||||||||||||||||||||||||||||||||||||
| 367 | { | - | ||||||||||||||||||||||||||||||||||||
| 368 | retval = read (fd, &c, 0); | - | ||||||||||||||||||||||||||||||||||||
| 369 | retval = (retval >= 0) ? EXECUTION_SUCCESS : EXECUTION_FAILURE;
| 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")))
| 0-1322714 | ||||||||||||||||||||||||||||||||||||
| 375 | { | - | ||||||||||||||||||||||||||||||||||||
| 376 | code = uconvert (e, &ival, &uval); | - | ||||||||||||||||||||||||||||||||||||
| 377 | if (code == 0 || ival < 0 || uval < 0)
| 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))
| 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)
| 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:
| 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)
| 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 blockExecuted by:
| 9 | ||||||||||||||||||||||||||||||||||||
| 415 | - | |||||||||||||||||||||||||||||||||||||
| 416 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 417 | if (edit)
| 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)
| 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))
| 0-2 | ||||||||||||||||||||||||||||||||||||
| 429 | tmsec = tmusec = 0; never executed: tmsec = tmusec = 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 430 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||||||||||||||
| 432 | if (tmsec > 0 || tmusec > 0)
| 0-1322714 | ||||||||||||||||||||||||||||||||||||
| 433 | { | - | ||||||||||||||||||||||||||||||||||||
| 434 | code = setjmp_nosigs (alrmbuf); | - | ||||||||||||||||||||||||||||||||||||
| 435 | if (code)
| 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)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 445 | { | - | ||||||||||||||||||||||||||||||||||||
| 446 | t = (char *)xmalloc (1); | - | ||||||||||||||||||||||||||||||||||||
| 447 | t[0] = 0; | - | ||||||||||||||||||||||||||||||||||||
| 448 | } executed 1 time by 1 test: end of blockExecuted by:
| 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:
| 1 | ||||||||||||||||||||||||||||||||||||
| 456 | } | - | ||||||||||||||||||||||||||||||||||||
| 457 | if (interactive_shell == 0)
| 0-2 | ||||||||||||||||||||||||||||||||||||
| 458 | initialize_terminating_signals (); executed 2 times by 1 test: initialize_terminating_signals ();Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 459 | old_alrm = set_signal_handler (SIGALRM, sigalrm); | - | ||||||||||||||||||||||||||||||||||||
| 460 | add_unwind_protect (reset_alarm, (char *)NULL); | - | ||||||||||||||||||||||||||||||||||||
| 461 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 462 | if (edit)
| 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 blockExecuted by:
| 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')
| 4-1322711 | ||||||||||||||||||||||||||||||||||||
| 475 | { | - | ||||||||||||||||||||||||||||||||||||
| 476 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 477 | if (edit)
| 0-9 | ||||||||||||||||||||||||||||||||||||
| 478 | { | - | ||||||||||||||||||||||||||||||||||||
| 479 | if (nchars > 0)
| 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')
| 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)
| 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);
| 0 | ||||||||||||||||||||||||||||||||||||
| 501 | if (i < 0)
| 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)
| 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 blockExecuted by:
| 9 | ||||||||||||||||||||||||||||||||||||
| 509 | else if (silent) /* turn off echo but leave term in canonical mode */
| 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)
| 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)
| 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));
| 0-1322716 | ||||||||||||||||||||||||||||||||||||
| 532 | if ((nchars > 0) && (input_is_tty == 0) && ignore_delim) /* read -N */
| 0-1322711 | ||||||||||||||||||||||||||||||||||||
| 533 | unbuffered_read = 2; executed 1 time by 1 test: unbuffered_read = 2;Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 534 | else if ((nchars > 0) || (delim != '\n') || input_is_pipe)
| 4-1322711 | ||||||||||||||||||||||||||||||||||||
| 535 | unbuffered_read = 1; executed 1322239 times by 1 test: unbuffered_read = 1;Executed by:
| 1322239 | ||||||||||||||||||||||||||||||||||||
| 536 | - | |||||||||||||||||||||||||||||||||||||
| 537 | if (prompt && edit == 0)
| 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));
| 0-1992911 | ||||||||||||||||||||||||||||||||||||
| 551 | - | |||||||||||||||||||||||||||||||||||||
| 552 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 553 | if (edit)
| 0-1992911 | ||||||||||||||||||||||||||||||||||||
| 554 | { | - | ||||||||||||||||||||||||||||||||||||
| 555 | if (rlbuf && rlbuf[rlind] == '\0')
| 0 | ||||||||||||||||||||||||||||||||||||
| 556 | { | - | ||||||||||||||||||||||||||||||||||||
| 557 | free (rlbuf); | - | ||||||||||||||||||||||||||||||||||||
| 558 | rlbuf = (char *)0; | - | ||||||||||||||||||||||||||||||||||||
| 559 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 560 | if (rlbuf == 0)
| 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)
| 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)
| 0-1992911 | ||||||||||||||||||||||||||||||||||||
| 579 | { | - | ||||||||||||||||||||||||||||||||||||
| 580 | if (ps2 == 0)
| 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));
| 0-1992911 | ||||||||||||||||||||||||||||||||||||
| 589 | if (unbuffered_read == 2)
| 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:
| 0-4 | ||||||||||||||||||||||||||||||||||||
| 591 | else if (unbuffered_read)
| 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:
| 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:
| 0-4530 | ||||||||||||||||||||||||||||||||||||
| 595 | reading = 0; | - | ||||||||||||||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||||||||||||||
| 597 | if (retval <= 0)
| 660676-1332234 | ||||||||||||||||||||||||||||||||||||
| 598 | { | - | ||||||||||||||||||||||||||||||||||||
| 599 | if (retval < 0 && errno == EINTR)
| 0-660675 | ||||||||||||||||||||||||||||||||||||
| 600 | { | - | ||||||||||||||||||||||||||||||||||||
| 601 | check_signals (); /* in case we didn't call zread via zreadc */ | - | ||||||||||||||||||||||||||||||||||||
| 602 | lastsig = LASTSIG();
| 0 | ||||||||||||||||||||||||||||||||||||
| 603 | if (lastsig == 0)
| 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:
| 660676 | ||||||||||||||||||||||||||||||||||||
| 609 | if (terminating_signal && tty_modified)
| 0-660676 | ||||||||||||||||||||||||||||||||||||
| 610 | ttyrestore (&termsave); /* fix terminal before exiting */ never executed: ttyrestore (&termsave); | 0 | ||||||||||||||||||||||||||||||||||||
| 611 | CHECK_TERMSIG; never executed: termsig_handler (terminating_signal);
| 0-660676 | ||||||||||||||||||||||||||||||||||||
| 612 | eof = 1; | - | ||||||||||||||||||||||||||||||||||||
| 613 | break; executed 660676 times by 1 test: break;Executed by:
| 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 ();
| 0-1332234 | ||||||||||||||||||||||||||||||||||||
| 617 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 618 | } executed 1332234 times by 1 test: end of blockExecuted by:
| 1332234 | ||||||||||||||||||||||||||||||||||||
| 619 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||||||||||||||
| 621 | if (retval <= 0) /* XXX shouldn't happen */
| 0-1332234 | ||||||||||||||||||||||||||||||||||||
| 622 | CHECK_ALRM; never executed: siglongjmp((alrmbuf), (1));never executed: end of block
| 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)
| 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)
| 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)
| 3-1332231 | ||||||||||||||||||||||||||||||||||||
| 642 | { | - | ||||||||||||||||||||||||||||||||||||
| 643 | pass_next = 0; | - | ||||||||||||||||||||||||||||||||||||
| 644 | if (c == '\n')
| 1-2 | ||||||||||||||||||||||||||||||||||||
| 645 | { | - | ||||||||||||||||||||||||||||||||||||
| 646 | if (skip_ctlesc == 0 && i > 0)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 647 | i--; /* back up over the CTLESC */ executed 1 time by 1 test: i--;Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 648 | if (interactive && input_is_tty && raw == 0)
| 0-1 | ||||||||||||||||||||||||||||||||||||
| 649 | print_ps2 = 1; never executed: print_ps2 = 1; | 0 | ||||||||||||||||||||||||||||||||||||
| 650 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 651 | else | - | ||||||||||||||||||||||||||||||||||||
| 652 | goto add_char; executed 2 times by 1 test: goto add_char;Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 653 | continue; executed 1 time by 1 test: continue;Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 654 | } | - | ||||||||||||||||||||||||||||||||||||
| 655 | - | |||||||||||||||||||||||||||||||||||||
| 656 | /* This may cause problems if IFS contains CTLESC */ | - | ||||||||||||||||||||||||||||||||||||
| 657 | if (c == '\\' && raw == 0)
| 3-1332218 | ||||||||||||||||||||||||||||||||||||
| 658 | { | - | ||||||||||||||||||||||||||||||||||||
| 659 | pass_next++; | - | ||||||||||||||||||||||||||||||||||||
| 660 | if (skip_ctlesc == 0)
| 0-3 | ||||||||||||||||||||||||||||||||||||
| 661 | { | - | ||||||||||||||||||||||||||||||||||||
| 662 | saw_escape++; | - | ||||||||||||||||||||||||||||||||||||
| 663 | input_string[i++] = CTLESC; | - | ||||||||||||||||||||||||||||||||||||
| 664 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 665 | continue; executed 3 times by 1 test: continue;Executed by:
| 3 | ||||||||||||||||||||||||||||||||||||
| 666 | } | - | ||||||||||||||||||||||||||||||||||||
| 667 | - | |||||||||||||||||||||||||||||||||||||
| 668 | if (ignore_delim == 0 && (unsigned char)c == delim)
| 4-1332224 | ||||||||||||||||||||||||||||||||||||
| 669 | break; executed 662035 times by 1 test: break;Executed by:
| 662035 | ||||||||||||||||||||||||||||||||||||
| 670 | - | |||||||||||||||||||||||||||||||||||||
| 671 | if (c == '\0' && delim != '\0')
| 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))
| 4-670171 | ||||||||||||||||||||||||||||||||||||
| 675 | { | - | ||||||||||||||||||||||||||||||||||||
| 676 | saw_escape++; | - | ||||||||||||||||||||||||||||||||||||
| 677 | input_string[i++] = CTLESC; | - | ||||||||||||||||||||||||||||||||||||
| 678 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||||||||||||||
| 679 | - | |||||||||||||||||||||||||||||||||||||
| 680 | add_char: code before this statement executed 670193 times by 1 test: add_char:Executed by:
| 670193 | ||||||||||||||||||||||||||||||||||||
| 681 | input_string[i++] = c; | - | ||||||||||||||||||||||||||||||||||||
| 682 | CHECK_ALRM; never executed: siglongjmp((alrmbuf), (1));
| 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)
| 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)
| 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)
| 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:
| 90 | ||||||||||||||||||||||||||||||||||||
| 709 | } | - | ||||||||||||||||||||||||||||||||||||
| 710 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 711 | - | |||||||||||||||||||||||||||||||||||||
| 712 | nr++; | - | ||||||||||||||||||||||||||||||||||||
| 713 | - | |||||||||||||||||||||||||||||||||||||
| 714 | if (nchars > 0 && nr >= nchars)
| 4-670180 | ||||||||||||||||||||||||||||||||||||
| 715 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||||||||||||||||||||
| 716 | } executed 670191 times by 1 test: end of blockExecuted by:
| 670191 | ||||||||||||||||||||||||||||||||||||
| 717 | input_string[i] = '\0'; | - | ||||||||||||||||||||||||||||||||||||
| 718 | CHECK_ALRM; never executed: siglongjmp((alrmbuf), (1));
| 0-1322715 | ||||||||||||||||||||||||||||||||||||
| 719 | - | |||||||||||||||||||||||||||||||||||||
| 720 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 721 | if (edit)
| 0-1322715 | ||||||||||||||||||||||||||||||||||||
| 722 | free (rlbuf); never executed: sh_xfree((rlbuf), "./read.def", 722); | 0 | ||||||||||||||||||||||||||||||||||||
| 723 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 724 | - | |||||||||||||||||||||||||||||||||||||
| 725 | if (retval < 0)
| 1-1322714 | ||||||||||||||||||||||||||||||||||||
| 726 | { | - | ||||||||||||||||||||||||||||||||||||
| 727 | t_errno = errno; | - | ||||||||||||||||||||||||||||||||||||
| 728 | if (errno != EINTR)
| 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:
| 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:
| 1 | ||||||||||||||||||||||||||||||||||||
| 732 | } | - | ||||||||||||||||||||||||||||||||||||
| 733 | - | |||||||||||||||||||||||||||||||||||||
| 734 | if (tmsec > 0 || tmusec > 0)
| 0-1322713 | ||||||||||||||||||||||||||||||||||||
| 735 | reset_alarm (); executed 1 time by 1 test: reset_alarm ();Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 736 | - | |||||||||||||||||||||||||||||||||||||
| 737 | if (nchars > 0 || delim != '\n')
| 4-1322709 | ||||||||||||||||||||||||||||||||||||
| 738 | { | - | ||||||||||||||||||||||||||||||||||||
| 739 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 740 | if (edit)
| 0-9 | ||||||||||||||||||||||||||||||||||||
| 741 | { | - | ||||||||||||||||||||||||||||||||||||
| 742 | if (nchars > 0)
| 0 | ||||||||||||||||||||||||||||||||||||
| 743 | rl_num_chars_to_read = 0; never executed: rl_num_chars_to_read = 0; | 0 | ||||||||||||||||||||||||||||||||||||
| 744 | if (delim != '\n')
| 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)
| 0-9 | ||||||||||||||||||||||||||||||||||||
| 750 | ttyrestore (&termsave); never executed: ttyrestore (&termsave); | 0 | ||||||||||||||||||||||||||||||||||||
| 751 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||||||||||||||
| 752 | else if (silent)
| 0-1322705 | ||||||||||||||||||||||||||||||||||||
| 753 | ttyrestore (&termsave); never executed: ttyrestore (&termsave); | 0 | ||||||||||||||||||||||||||||||||||||
| 754 | - | |||||||||||||||||||||||||||||||||||||
| 755 | if (unbuffered_read == 0)
| 475-1322239 | ||||||||||||||||||||||||||||||||||||
| 756 | zsyncfd (fd); executed 475 times by 1 test: zsyncfd (fd);Executed by:
| 475 | ||||||||||||||||||||||||||||||||||||
| 757 | - | |||||||||||||||||||||||||||||||||||||
| 758 | discard_unwind_frame ("read_builtin"); | - | ||||||||||||||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||||||||||||||
| 760 | retval = eof ? EXECUTION_FAILURE : EXECUTION_SUCCESS;
| 660675-662039 | ||||||||||||||||||||||||||||||||||||
| 761 | - | |||||||||||||||||||||||||||||||||||||
| 762 | assign_vars: code before this statement executed 1322714 times by 1 test: assign_vars:Executed by:
| 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)
| 27-1322688 | ||||||||||||||||||||||||||||||||||||
| 768 | { | - | ||||||||||||||||||||||||||||||||||||
| 769 | if (legal_identifier (arrayname) == 0)
| 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)
| 2-25 | ||||||||||||||||||||||||||||||||||||
| 778 | { | - | ||||||||||||||||||||||||||||||||||||
| 779 | free (input_string); | - | ||||||||||||||||||||||||||||||||||||
| 780 | return EXECUTION_FAILURE; /* readonly or noassign */ executed 2 times by 1 test: return 1;Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 781 | } | - | ||||||||||||||||||||||||||||||||||||
| 782 | if (assoc_p (var))
| 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))
| 2-23 | ||||||||||||||||||||||||||||||||||||
| 789 | VUNSETATTR (var, att_invisible); executed 2 times by 1 test: ((var)->attributes &= ~(0x0001000));Executed by:
| 2 | ||||||||||||||||||||||||||||||||||||
| 790 | array_flush (array_cell (var)); | - | ||||||||||||||||||||||||||||||||||||
| 791 | - | |||||||||||||||||||||||||||||||||||||
| 792 | alist = list_string (input_string, ifs_chars, 0); | - | ||||||||||||||||||||||||||||||||||||
| 793 | if (alist)
| 0-25 | ||||||||||||||||||||||||||||||||||||
| 794 | { | - | ||||||||||||||||||||||||||||||||||||
| 795 | if (saw_escape)
| 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:
| 25 | ||||||||||||||||||||||||||||||||||||
| 799 | assign_array_var_from_word_list (var, alist, 0); | - | ||||||||||||||||||||||||||||||||||||
| 800 | dispose_words (alist); | - | ||||||||||||||||||||||||||||||||||||
| 801 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||||||||||||||||||||
| 802 | free (input_string); | - | ||||||||||||||||||||||||||||||||||||
| 803 | return (retval); executed 25 times by 1 test: return (retval);Executed by:
| 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)
| 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)
| 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 blockExecuted by:
| 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:
| 45 | ||||||||||||||||||||||||||||||||||||
| 833 | if (var == 0 || readonly_p (var) || noassign_p (var))
| 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:
| 48 | ||||||||||||||||||||||||||||||||||||
| 837 | - | |||||||||||||||||||||||||||||||||||||
| 838 | free (input_string); | - | ||||||||||||||||||||||||||||||||||||
| 839 | return (retval); executed 48 times by 1 test: return (retval);Executed by:
| 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++)
| 0-1323206 | ||||||||||||||||||||||||||||||||||||
| 849 | ; executed 566 times by 1 test: ;Executed by:
| 566 | ||||||||||||||||||||||||||||||||||||
| 850 | input_string = t; | - | ||||||||||||||||||||||||||||||||||||
| 851 | for (; list->next; list = list->next)
| 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)
| 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)
| 21-998 | ||||||||||||||||||||||||||||||||||||
| 868 | { | - | ||||||||||||||||||||||||||||||||||||
| 869 | /* This call updates INPUT_STRING. */ | - | ||||||||||||||||||||||||||||||||||||
| 870 | t = get_word_from_string (&input_string, ifs_chars, &e); | - | ||||||||||||||||||||||||||||||||||||
| 871 | if (t)
| 0-998 | ||||||||||||||||||||||||||||||||||||
| 872 | *e = '\0'; executed 998 times by 1 test: *e = '\0';Executed by:
| 998 | ||||||||||||||||||||||||||||||||||||
| 873 | /* Don't bother to remove the CTLESC unless we added one | - | ||||||||||||||||||||||||||||||||||||
| 874 | somewhere while reading the string. */ | - | ||||||||||||||||||||||||||||||||||||
| 875 | if (t && saw_escape)
| 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 blockExecuted by:
| 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:
| 988 | ||||||||||||||||||||||||||||||||||||
| 883 | } | - | ||||||||||||||||||||||||||||||||||||
| 884 | else | - | ||||||||||||||||||||||||||||||||||||
| 885 | { | - | ||||||||||||||||||||||||||||||||||||
| 886 | t = (char *)0; | - | ||||||||||||||||||||||||||||||||||||
| 887 | var = bind_read_variable (varname, ""); | - | ||||||||||||||||||||||||||||||||||||
| 888 | } executed 21 times by 1 test: end of blockExecuted by:
| 21 | ||||||||||||||||||||||||||||||||||||
| 889 | - | |||||||||||||||||||||||||||||||||||||
| 890 | FREE (t); executed 998 times by 1 test: sh_xfree((t), "./read.def", 890);Executed by:
| 21-998 | ||||||||||||||||||||||||||||||||||||
| 891 | if (var == 0)
| 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 blockExecuted by:
| 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)
| 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)
| 660797-661843 | ||||||||||||||||||||||||||||||||||||
| 923 | { | - | ||||||||||||||||||||||||||||||||||||
| 924 | t1 = input_string; | - | ||||||||||||||||||||||||||||||||||||
| 925 | t = get_word_from_string (&input_string, ifs_chars, &e); | - | ||||||||||||||||||||||||||||||||||||
| 926 | if (*input_string == 0)
| 389-661454 | ||||||||||||||||||||||||||||||||||||
| 927 | tofree = input_string = t; executed 661454 times by 1 test: tofree = input_string = t;Executed by:
| 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 blockExecuted by:
| 389 | ||||||||||||||||||||||||||||||||||||
| 933 | } | - | ||||||||||||||||||||||||||||||||||||
| 934 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 935 | - | |||||||||||||||||||||||||||||||||||||
| 936 | if (saw_escape && input_string && *input_string)
| 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 blockExecuted by:
| 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:
| 1322636 | ||||||||||||||||||||||||||||||||||||
| 944 | - | |||||||||||||||||||||||||||||||||||||
| 945 | if (var)
| 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 blockExecuted by:
| 1322639 | ||||||||||||||||||||||||||||||||||||
| 950 | else | - | ||||||||||||||||||||||||||||||||||||
| 951 | retval = EXECUTION_FAILURE; executed 1 time by 1 test: retval = 1;Executed by:
| 1 | ||||||||||||||||||||||||||||||||||||
| 952 | - | |||||||||||||||||||||||||||||||||||||
| 953 | FREE (tofree); executed 661843 times by 1 test: sh_xfree((tofree), "./read.def", 953);Executed by:
| 660797-661843 | ||||||||||||||||||||||||||||||||||||
| 954 | free (orig_input_string); | - | ||||||||||||||||||||||||||||||||||||
| 955 | - | |||||||||||||||||||||||||||||||||||||
| 956 | return (retval); executed 1322640 times by 1 test: return (retval);Executed by:
| 1322640 | ||||||||||||||||||||||||||||||||||||
| 957 | } | - | ||||||||||||||||||||||||||||||||||||
| 958 | - | |||||||||||||||||||||||||||||||||||||
| 959 | static SHELL_VAR * | - | ||||||||||||||||||||||||||||||||||||
| 960 | bind_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)
| 2-1323657 | ||||||||||||||||||||||||||||||||||||
| 967 | v = bind_variable (name, value, 0); executed 1323657 times by 1 test: v = bind_variable (name, value, 0);Executed by:
| 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:
| 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:
| 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:
| 1323659 | ||||||||||||||||||||||||||||||||||||
| 975 | } | - | ||||||||||||||||||||||||||||||||||||
| 976 | - | |||||||||||||||||||||||||||||||||||||
| 977 | #if defined (HANDLE_MULTIBYTE) | - | ||||||||||||||||||||||||||||||||||||
| 978 | static int | - | ||||||||||||||||||||||||||||||||||||
| 979 | read_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++)
| 0-116 | ||||||||||||||||||||||||||||||||||||
| 997 | { | - | ||||||||||||||||||||||||||||||||||||
| 998 | ps_back = ps; | - | ||||||||||||||||||||||||||||||||||||
| 999 | ret = mbrtowc (&wc, mbchar, i, &ps); | - | ||||||||||||||||||||||||||||||||||||
| 1000 | if (ret == (size_t)-2)
| 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)
| 0-26 | ||||||||||||||||||||||||||||||||||||
| 1006 | r = zreadn (fd, &c, 1); never executed: r = zreadn (fd, &c, 1); | 0 | ||||||||||||||||||||||||||||||||||||
| 1007 | else if (unbuffered)
| 5-21 | ||||||||||||||||||||||||||||||||||||
| 1008 | r = zread (fd, &c, 1); executed 5 times by 1 test: r = zread (fd, &c, 1);Executed by:
| 5 | ||||||||||||||||||||||||||||||||||||
| 1009 | else | - | ||||||||||||||||||||||||||||||||||||
| 1010 | r = zreadc (fd, &c); executed 21 times by 1 test: r = zreadc (fd, &c);Executed by:
| 21 | ||||||||||||||||||||||||||||||||||||
| 1011 | if (r <= 0)
| 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:
| 26 | ||||||||||||||||||||||||||||||||||||
| 1015 | } | - | ||||||||||||||||||||||||||||||||||||
| 1016 | else if (ret == (size_t)-1 || ret == (size_t)0 || ret > (size_t)0)
| 0-90 | ||||||||||||||||||||||||||||||||||||
| 1017 | break; executed 90 times by 1 test: break;Executed by:
| 90 | ||||||||||||||||||||||||||||||||||||
| 1018 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1019 | - | |||||||||||||||||||||||||||||||||||||
| 1020 | mbchar_return: code before this statement executed 90 times by 1 test: mbchar_return:Executed by:
| 90 | ||||||||||||||||||||||||||||||||||||
| 1021 | if (i > 1) /* read a multibyte char */
| 26-64 | ||||||||||||||||||||||||||||||||||||
| 1022 | /* mbchar[0] is already string[ind-1] */ | - | ||||||||||||||||||||||||||||||||||||
| 1023 | for (r = 1; r < i; r++)
| 26 | ||||||||||||||||||||||||||||||||||||
| 1024 | string[ind+r-1] = mbchar[r]; executed 26 times by 1 test: string[ind+r-1] = mbchar[r];Executed by:
| 26 | ||||||||||||||||||||||||||||||||||||
| 1025 | return i - 1; executed 90 times by 1 test: return i - 1;Executed by:
| 90 | ||||||||||||||||||||||||||||||||||||
| 1026 | } | - | ||||||||||||||||||||||||||||||||||||
| 1027 | #endif | - | ||||||||||||||||||||||||||||||||||||
| 1028 | - | |||||||||||||||||||||||||||||||||||||
| 1029 | - | |||||||||||||||||||||||||||||||||||||
| 1030 | static void | - | ||||||||||||||||||||||||||||||||||||
| 1031 | ttyrestore (ttp) | - | ||||||||||||||||||||||||||||||||||||
| 1032 | struct ttsave *ttp; | - | ||||||||||||||||||||||||||||||||||||
| 1033 | { | - | ||||||||||||||||||||||||||||||||||||
| 1034 | ttsetattr (ttp->fd, &(ttp->attrs)); | - | ||||||||||||||||||||||||||||||||||||
| 1035 | tty_modified = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1036 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||||||||||||||
| 1038 | void | - | ||||||||||||||||||||||||||||||||||||
| 1039 | read_tty_cleanup () | - | ||||||||||||||||||||||||||||||||||||
| 1040 | { | - | ||||||||||||||||||||||||||||||||||||
| 1041 | if (tty_modified)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1042 | ttyrestore (&termsave); never executed: ttyrestore (&termsave); | 0 | ||||||||||||||||||||||||||||||||||||
| 1043 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||||||||
| 1044 | - | |||||||||||||||||||||||||||||||||||||
| 1045 | int | - | ||||||||||||||||||||||||||||||||||||
| 1046 | read_tty_modified () | - | ||||||||||||||||||||||||||||||||||||
| 1047 | { | - | ||||||||||||||||||||||||||||||||||||
| 1048 | return (tty_modified); executed 550 times by 1 test: return (tty_modified);Executed by:
| 550 | ||||||||||||||||||||||||||||||||||||
| 1049 | } | - | ||||||||||||||||||||||||||||||||||||
| 1050 | - | |||||||||||||||||||||||||||||||||||||
| 1051 | #if defined (READLINE) | - | ||||||||||||||||||||||||||||||||||||
| 1052 | static rl_completion_func_t *old_attempted_completion_function = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1053 | static rl_hook_func_t *old_startup_hook; | - | ||||||||||||||||||||||||||||||||||||
| 1054 | static char *deftext; | - | ||||||||||||||||||||||||||||||||||||
| 1055 | - | |||||||||||||||||||||||||||||||||||||
| 1056 | static void | - | ||||||||||||||||||||||||||||||||||||
| 1057 | reset_attempted_completion_function (cp) | - | ||||||||||||||||||||||||||||||||||||
| 1058 | char *cp; | - | ||||||||||||||||||||||||||||||||||||
| 1059 | { | - | ||||||||||||||||||||||||||||||||||||
| 1060 | if (rl_attempted_completion_function == 0 && old_attempted_completion_function)
| 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 | - | |||||||||||||||||||||||||||||||||||||
| 1064 | static int | - | ||||||||||||||||||||||||||||||||||||
| 1065 | set_itext () | - | ||||||||||||||||||||||||||||||||||||
| 1066 | { | - | ||||||||||||||||||||||||||||||||||||
| 1067 | int r1, r2; | - | ||||||||||||||||||||||||||||||||||||
| 1068 | - | |||||||||||||||||||||||||||||||||||||
| 1069 | r1 = r2 = 0; | - | ||||||||||||||||||||||||||||||||||||
| 1070 | if (old_startup_hook)
| 0 | ||||||||||||||||||||||||||||||||||||
| 1071 | r1 = (*old_startup_hook) (); never executed: r1 = (*old_startup_hook) (); | 0 | ||||||||||||||||||||||||||||||||||||
| 1072 | if (deftext)
| 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 | - | |||||||||||||||||||||||||||||||||||||
| 1082 | static char * | - | ||||||||||||||||||||||||||||||||||||
| 1083 | edit_line (p, itext) | - | ||||||||||||||||||||||||||||||||||||
| 1084 | char *p; | - | ||||||||||||||||||||||||||||||||||||
| 1085 | char *itext; | - | ||||||||||||||||||||||||||||||||||||
| 1086 | { | - | ||||||||||||||||||||||||||||||||||||
| 1087 | char *ret; | - | ||||||||||||||||||||||||||||||||||||
| 1088 | int len; | - | ||||||||||||||||||||||||||||||||||||
| 1089 | - | |||||||||||||||||||||||||||||||||||||
| 1090 | if (bash_readline_initialized == 0)
| 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)
| 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)
| 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 | - | |||||||||||||||||||||||||||||||||||||
| 1118 | static int old_delim_ctype; | - | ||||||||||||||||||||||||||||||||||||
| 1119 | static rl_command_func_t *old_delim_func; | - | ||||||||||||||||||||||||||||||||||||
| 1120 | static int old_newline_ctype; | - | ||||||||||||||||||||||||||||||||||||
| 1121 | static rl_command_func_t *old_newline_func; | - | ||||||||||||||||||||||||||||||||||||
| 1122 | - | |||||||||||||||||||||||||||||||||||||
| 1123 | static unsigned char delim_char; | - | ||||||||||||||||||||||||||||||||||||
| 1124 | - | |||||||||||||||||||||||||||||||||||||
| 1125 | static void | - | ||||||||||||||||||||||||||||||||||||
| 1126 | set_eol_delim (c) | - | ||||||||||||||||||||||||||||||||||||
| 1127 | int c; | - | ||||||||||||||||||||||||||||||||||||
| 1128 | { | - | ||||||||||||||||||||||||||||||||||||
| 1129 | Keymap cmap; | - | ||||||||||||||||||||||||||||||||||||
| 1130 | - | |||||||||||||||||||||||||||||||||||||
| 1131 | if (bash_readline_initialized == 0)
| 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 | - | |||||||||||||||||||||||||||||||||||||
| 1150 | static void | - | ||||||||||||||||||||||||||||||||||||
| 1151 | reset_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 code | Switch to Preprocessed file |