OpenCoverage

histexpand.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/lib/readline/histexpand.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* histexpand.c -- history expansion. */-
2-
3/* Copyright (C) 1989-2017 Free Software Foundation, Inc.-
4-
5 This file contains the GNU History Library (History), a set of-
6 routines for managing the text of previously typed lines.-
7-
8 History 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 History 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 History. If not, see <http://www.gnu.org/licenses/>.-
20*/-
21-
22#define READLINE_LIBRARY-
23-
24#if defined (HAVE_CONFIG_H)-
25# include <config.h>-
26#endif-
27-
28#include <stdio.h>-
29-
30#if defined (HAVE_STDLIB_H)-
31# include <stdlib.h>-
32#else-
33# include "ansi_stdlib.h"-
34#endif /* HAVE_STDLIB_H */-
35-
36#if defined (HAVE_UNISTD_H)-
37# ifndef _MINIX-
38# include <sys/types.h>-
39# endif-
40# include <unistd.h>-
41#endif-
42-
43#include "rlmbutil.h"-
44-
45#include "history.h"-
46#include "histlib.h"-
47#include "chardefs.h"-
48-
49#include "rlshell.h"-
50#include "xmalloc.h"-
51-
52#define HISTORY_WORD_DELIMITERS " \t\n;&()|<>"-
53#define HISTORY_QUOTE_CHARACTERS "\"'`"-
54#define HISTORY_EVENT_DELIMITERS "^$*%-"-
55-
56#define slashify_in_quotes "\\`\"$"-
57-
58typedef int _hist_search_func_t PARAMS((const char *, int));-
59-
60static char error_pointer;-
61-
62static char *subst_lhs;-
63static char *subst_rhs;-
64static int subst_lhs_len;-
65static int subst_rhs_len;-
66-
67/* Characters that delimit history event specifications and separate event-
68 specifications from word designators. Static for now */-
69static char *history_event_delimiter_chars = HISTORY_EVENT_DELIMITERS;-
70-
71static char *get_history_word_specifier PARAMS((char *, char *, int *));-
72static int history_tokenize_word PARAMS((const char *, int));-
73static char **history_tokenize_internal PARAMS((const char *, int, int *));-
74static char *history_substring PARAMS((const char *, int, int));-
75static void freewords PARAMS((char **, int));-
76static char *history_find_word PARAMS((char *, int));-
77-
78static char *quote_breaks PARAMS((char *));-
79-
80/* Variables exported by this file. */-
81/* The character that represents the start of a history expansion-
82 request. This is usually `!'. */-
83char history_expansion_char = '!';-
84-
85/* The character that invokes word substitution if found at the start of-
86 a line. This is usually `^'. */-
87char history_subst_char = '^';-
88-
89/* During tokenization, if this character is seen as the first character-
90 of a word, then it, and all subsequent characters upto a newline are-
91 ignored. For a Bourne shell, this should be '#'. Bash special cases-
92 the interactive comment character to not be a comment delimiter. */-
93char history_comment_char = '\0';-
94-
95/* The list of characters which inhibit the expansion of text if found-
96 immediately following history_expansion_char. */-
97char *history_no_expand_chars = " \t\n\r=";-
98-
99/* If set to a non-zero value, single quotes inhibit history expansion.-
100 The default is 0. */-
101int history_quotes_inhibit_expansion = 0;-
102-
103/* Used to split words by history_tokenize_internal. */-
104char *history_word_delimiters = HISTORY_WORD_DELIMITERS;-
105-
106/* If set, this points to a function that is called to verify that a-
107 particular history expansion should be performed. */-
108rl_linebuf_func_t *history_inhibit_expansion_function;-
109-
110/* **************************************************************** */-
111/* */-
112/* History Expansion */-
113/* */-
114/* **************************************************************** */-
115-
116/* Hairy history expansion on text, not tokens. This is of general-
117 use, and thus belongs in this library. */-
118-
119/* The last string searched for by a !?string? search. */-
120static char *search_string;-
121/* The last string matched by a !?string? search. */-
122static char *search_match;-
123-
124/* Return the event specified at TEXT + OFFSET modifying OFFSET to-
125 point to after the event specifier. Just a pointer to the history-
126 line is returned; NULL is returned in the event of a bad specifier.-
127 You pass STRING with *INDEX equal to the history_expansion_char that-
128 begins this specification.-
129 DELIMITING_QUOTE is a character that is allowed to end the string-
130 specification for what to search for in addition to the normal-
131 characters `:', ` ', `\t', `\n', and sometimes `?'.-
132 So you might call this function like:-
133 line = get_history_event ("!echo:p", &index, 0); */-
134char *-
135get_history_event (const char *string, int *caller_index, int delimiting_quote)-
136{-
137 register int i;-
138 register char c;-
139 HIST_ENTRY *entry;-
140 int which, sign, local_index, substring_okay;-
141 _hist_search_func_t *search_func;-
142 char *temp;-
143-
144 /* The event can be specified in a number of ways.-
145-
146 !! the previous command-
147 !n command line N-
148 !-n current command-line minus N-
149 !str the most recent command starting with STR-
150 !?str[?]-
151 the most recent command containing STR-
152-
153 All values N are determined via HISTORY_BASE. */-
154-
155 i = *caller_index;-
156-
157 if (string[i] != history_expansion_char)
string[i] != h...expansion_charDescription
TRUEnever evaluated
FALSEevaluated 135 times by 1 test
Evaluated by:
  • Self test
0-135
158 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
159-
160 /* Move on to the specification. */-
161 i++;-
162-
163 sign = 1;-
164 substring_okay = 0;-
165-
166#define RETURN_ENTRY(e, w) \-
167 return ((e = history_get (w)) ? e->line : (char *)NULL)-
168-
169 /* Handle !! case. */-
170 if (string[i] == history_expansion_char)
string[i] == h...expansion_charDescription
TRUEevaluated 109 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-109
171 {-
172 i++;-
173 which = history_base + (history_length - 1);-
174 *caller_index = i;-
175 RETURN_ENTRY (entry, which);
executed 109 times by 1 test: return ((entry = history_get (which)) ? entry->line : (char *) ((void *)0) );
Executed by:
  • Self test
109
176 }-
177-
178 /* Hack case of numeric line specification. */-
179 if (string[i] == '-')
string[i] == '-'Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
13
180 {-
181 sign = -1;-
182 i++;-
183 }
executed 13 times by 1 test: end of block
Executed by:
  • Self test
13
184-
185 if (_rl_digit_p (string[i]))
(string[i]) >= '0'Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
(string[i]) <= '9'Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
1-25
186 {-
187 /* Get the extent of the digits and compute the value. */-
188 for (which = 0; _rl_digit_p (string[i]); i++)
(string[i]) >= '0'Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(string[i]) <= '9'Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
2-26
189 which = (which * 10) + _rl_digit_value (string[i]);
executed 14 times by 1 test: which = (which * 10) + ((string[i]) - '0');
Executed by:
  • Self test
14
190-
191 *caller_index = i;-
192-
193 if (sign < 0)
sign < 0Description
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-13
194 which = (history_length + history_base) - which;
executed 13 times by 1 test: which = (history_length + history_base) - which;
Executed by:
  • Self test
13
195-
196 RETURN_ENTRY (entry, which);
executed 14 times by 1 test: return ((entry = history_get (which)) ? entry->line : (char *) ((void *)0) );
Executed by:
  • Self test
14
197 }-
198-
199 /* This must be something to search for. If the spec begins with-
200 a '?', then the string may be anywhere on the line. Otherwise,-
201 the string must be found at the start of a line. */-
202 if (string[i] == '?')
string[i] == '?'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
5-7
203 {-
204 substring_okay++;-
205 i++;-
206 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
207-
208 /* Only a closing `?' or a newline delimit a substring search string. */-
209 for (local_index = i; c = string[i]; i++)
c = string[i]Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-31
210 {-
211#if defined (HANDLE_MULTIBYTE)-
212 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
(__ctype_get_m...ur_max ()) > 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 29 times by 1 test
Evaluated by:
  • Self test
rl_byte_oriented == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-29
213 {-
214 int v;-
215 mbstate_t ps;-
216-
217 memset (&ps, 0, sizeof (mbstate_t));-
218 /* These produce warnings because we're passing a const string to a-
219 function that takes a non-const string. */-
220 _rl_adjust_point ((char *)string, i, &ps);-
221 if ((v = _rl_get_char_len ((char *)string + i, &ps)) > 1)
(v = _rl_get_c...+ i, &ps)) > 1Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
222 {-
223 i += v - 1;-
224 continue;
never executed: continue;
0
225 }-
226 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
227-
228#endif /* HANDLE_MULTIBYTE */-
229 if ((!substring_okay && (whitespace (c) || c == ':' ||
!substring_okayDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test
((c) == ' ')Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
((c) == '\t')Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
c == ':'Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
0-18
230 (history_event_delimiter_chars && member (c, history_event_delimiter_chars)) ||
(c)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
history_event_delimiter_charsDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((c) ? ((char ...id *)0) ) : 0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
0-18
231 (history_search_delimiter_chars && member (c, history_search_delimiter_chars)) ||
(c)Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
history_search_delimiter_charsDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
((c) ? ((char ...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
0-14
232 string[i] == delimiting_quote)) ||
string[i] == delimiting_quoteDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
1-15
233 string[i] == '\n' ||
string[i] == '\n'Description
TRUEnever evaluated
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
0-28
234 (substring_okay && string[i] == '?'))
substring_okayDescription
TRUEevaluated 13 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
string[i] == '?'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
5-15
235 break;
executed 8 times by 1 test: break;
Executed by:
  • Self test
8
236 }
executed 23 times by 1 test: end of block
Executed by:
  • Self test
23
237-
238 which = i - local_index;-
239 temp = (char *)xmalloc (1 + which);-
240 if (which)
whichDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-12
241 strncpy (temp, string + local_index, which);
executed 12 times by 1 test: __builtin_strncpy ( temp , string + local_index , which ) ;
Executed by:
  • Self test
12
242 temp[which] = '\0';-
243-
244 if (substring_okay && string[i] == '?')
substring_okayDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
string[i] == '?'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7
245 i++;
executed 5 times by 1 test: i++;
Executed by:
  • Self test
5
246-
247 *caller_index = i;-
248-
249#define FAIL_SEARCH() \-
250 do { \-
251 history_offset = history_length; xfree (temp) ; return (char *)NULL; \-
252 } while (0)-
253-
254 /* If there is no search string, try to use the previous search string,-
255 if one exists. If not, fail immediately. */-
256 if (*temp == '\0' && substring_okay)
*temp == '\0'Description
TRUEnever evaluated
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
substring_okayDescription
TRUEnever evaluated
FALSEnever evaluated
0-12
257 {-
258 if (search_string)
search_stringDescription
TRUEnever evaluated
FALSEnever evaluated
0
259 {-
260 xfree (temp);-
261 temp = savestring (search_string);-
262 }
never executed: end of block
0
263 else-
264 FAIL_SEARCH ();
never executed: return (char *) ((void *)0) ;
never executed: end of block
0
265 }-
266-
267 search_func = substring_okay ? history_search : history_search_prefix;
substring_okayDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
5-7
268 while (1)-
269 {-
270 local_index = (*search_func) (temp, -1);-
271-
272 if (local_index < 0)
local_index < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
1-11
273 FAIL_SEARCH ();
executed 1 time by 1 test: return (char *) ((void *)0) ;
Executed by:
  • Self test
never executed: end of block
0-1
274-
275 if (local_index == 0 || substring_okay)
local_index == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
substring_okayDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
276 {-
277 entry = current_history ();-
278 if (entry == 0)
entry == 0Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
0-11
279 FAIL_SEARCH ();
never executed: return (char *) ((void *)0) ;
never executed: end of block
0
280 history_offset = history_length;-
281 -
282 /* If this was a substring search, then remember the-
283 string that we matched for word substitution. */-
284 if (substring_okay)
substring_okayDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
5-6
285 {-
286 FREE (search_string);
executed 4 times by 1 test: free (search_string);
Executed by:
  • Self test
search_stringDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-4
287 search_string = temp;-
288-
289 FREE (search_match);
executed 4 times by 1 test: free (search_match);
Executed by:
  • Self test
search_matchDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-4
290 search_match = history_find_word (entry->line, local_index);-
291 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
292 else-
293 xfree (temp);
executed 6 times by 1 test: xfree (temp);
Executed by:
  • Self test
6
294-
295 return (entry->line);
executed 11 times by 1 test: return (entry->line);
Executed by:
  • Self test
11
296 }-
297-
298 if (history_offset)
history_offsetDescription
TRUEnever evaluated
FALSEnever evaluated
0
299 history_offset--;
never executed: history_offset--;
0
300 else-
301 FAIL_SEARCH ();
never executed: return (char *) ((void *)0) ;
never executed: end of block
0
302 }-
303#undef FAIL_SEARCH-
304#undef RETURN_ENTRY-
305}
never executed: end of block
0
306-
307/* Function for extracting single-quoted strings. Used for inhibiting-
308 history expansion within single quotes. */-
309-
310/* Extract the contents of STRING as if it is enclosed in single quotes.-
311 SINDEX, when passed in, is the offset of the character immediately-
312 following the opening single quote; on exit, SINDEX is left pointing-
313 to the closing single quote. FLAGS currently used to allow backslash-
314 to escape a single quote (e.g., for bash $'...'). */-
315static void-
316hist_string_extract_single_quoted (char *string, int *sindex, int flags)-
317{-
318 register int i;-
319-
320 for (i = *sindex; string[i] && string[i] != '\''; i++)
string[i]Description
TRUEevaluated 226 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
string[i] != '\''Description
TRUEevaluated 171 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 55 times by 1 test
Evaluated by:
  • Self test
0-226
321 {-
322 if ((flags & 1) && string[i] == '\\' && string[i+1])
(flags & 1)Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 146 times by 1 test
Evaluated by:
  • Self test
string[i] == '\\'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
string[i+1]Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-146
323 i++;
executed 1 time by 1 test: i++;
Executed by:
  • Self test
1
324 }
executed 171 times by 1 test: end of block
Executed by:
  • Self test
171
325-
326 *sindex = i;-
327}
executed 55 times by 1 test: end of block
Executed by:
  • Self test
55
328-
329static char *-
330quote_breaks (char *s)-
331{-
332 register char *p, *r;-
333 char *ret;-
334 int len = 3;-
335-
336 for (p = s; p && *p; p++, len++)
pDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*pDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-10
337 {-
338 if (*p == '\'')
*p == '\''Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
339 len += 3;
never executed: len += 3;
0
340 else if (whitespace (*p) || *p == '\n')
((*p) == ' ')Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
((*p) == '\t')Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
*p == '\n'Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
341 len += 2;
executed 4 times by 1 test: len += 2;
Executed by:
  • Self test
4
342 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
343-
344 r = ret = (char *)xmalloc (len);-
345 *r++ = '\'';-
346 for (p = s; p && *p; )
pDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*pDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-10
347 {-
348 if (*p == '\'')
*p == '\''Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
349 {-
350 *r++ = '\'';-
351 *r++ = '\\';-
352 *r++ = '\'';-
353 *r++ = '\'';-
354 p++;-
355 }
never executed: end of block
0
356 else if (whitespace (*p) || *p == '\n')
((*p) == ' ')Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
((*p) == '\t')Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
*p == '\n'Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
357 {-
358 *r++ = '\'';-
359 *r++ = *p++;-
360 *r++ = '\'';-
361 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
362 else-
363 *r++ = *p++;
executed 5 times by 1 test: *r++ = *p++;
Executed by:
  • Self test
5
364 }-
365 *r++ = '\'';-
366 *r = '\0';-
367 return ret;
executed 1 time by 1 test: return ret;
Executed by:
  • Self test
1
368}-
369-
370static char *-
371hist_error(char *s, int start, int current, int errtype)-
372{-
373 char *temp;-
374 const char *emsg;-
375 int ll, elen;-
376-
377 ll = current - start;-
378-
379 switch (errtype)-
380 {-
381 case EVENT_NOT_FOUND:
executed 1 time by 1 test: case 0:
Executed by:
  • Self test
1
382 emsg = "event not found";-
383 elen = 15;-
384 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
385 case BAD_WORD_SPEC:
never executed: case 1:
0
386 emsg = "bad word specifier";-
387 elen = 18;-
388 break;
never executed: break;
0
389 case SUBST_FAILED:
never executed: case 2:
0
390 emsg = "substitution failed";-
391 elen = 19;-
392 break;
never executed: break;
0
393 case BAD_MODIFIER:
executed 1 time by 1 test: case 3:
Executed by:
  • Self test
1
394 emsg = "unrecognized history modifier";-
395 elen = 29;-
396 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
397 case NO_PREV_SUBST:
never executed: case 4:
0
398 emsg = "no previous substitution";-
399 elen = 24;-
400 break;
never executed: break;
0
401 default:
never executed: default:
0
402 emsg = "unknown expansion error";-
403 elen = 23;-
404 break;
never executed: break;
0
405 }-
406-
407 temp = (char *)xmalloc (ll + elen + 3);-
408 strncpy (temp, s + start, ll);-
409 temp[ll] = ':';-
410 temp[ll + 1] = ' ';-
411 strcpy (temp + ll + 2, emsg);-
412 return (temp);
executed 2 times by 1 test: return (temp);
Executed by:
  • Self test
2
413}-
414-
415/* Get a history substitution string from STR starting at *IPTR-
416 and return it. The length is returned in LENPTR.-
417-
418 A backslash can quote the delimiter. If the string is the-
419 empty string, the previous pattern is used. If there is-
420 no previous pattern for the lhs, the last history search-
421 string is used.-
422-
423 If IS_RHS is 1, we ignore empty strings and set the pattern-
424 to "" anyway. subst_lhs is not changed if the lhs is empty;-
425 subst_rhs is allowed to be set to the empty string. */-
426-
427static char *-
428get_subst_pattern (char *str, int *iptr, int delimiter, int is_rhs, int *lenptr)-
429{-
430 register int si, i, j, k;-
431 char *s;-
432#if defined (HANDLE_MULTIBYTE)-
433 mbstate_t ps;-
434#endif-
435-
436 s = (char *)NULL;-
437 i = *iptr;-
438-
439#if defined (HANDLE_MULTIBYTE)-
440 memset (&ps, 0, sizeof (mbstate_t));-
441 _rl_adjust_point (str, i, &ps);-
442#endif-
443-
444 for (si = i; str[si] && str[si] != delimiter; si++)
str[si]Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
str[si] != delimiterDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
1-35
445#if defined (HANDLE_MULTIBYTE)-
446 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
(__ctype_get_m...ur_max ()) > 1Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
rl_byte_oriented == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-26
447 {-
448 int v;-
449 if ((v = _rl_get_char_len (str + si, &ps)) > 1)
(v = _rl_get_c... si, &ps)) > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
450 si += v - 1;
never executed: si += v - 1;
0
451 else if (str[si] == '\\' && str[si + 1] == delimiter)
str[si] == '\\'Description
TRUEnever evaluated
FALSEnever evaluated
str[si + 1] == delimiterDescription
TRUEnever evaluated
FALSEnever evaluated
0
452 si++;
never executed: si++;
0
453 }
never executed: end of block
0
454 else-
455#endif /* HANDLE_MULTIBYTE */-
456 if (str[si] == '\\' && str[si + 1] == delimiter)
str[si] == '\\'Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
str[si + 1] == delimiterDescription
TRUEnever evaluated
FALSEnever evaluated
0-26
457 si++;
never executed: si++;
0
458-
459 if (si > i || is_rhs)
si > iDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
is_rhsDescription
TRUEnever evaluated
FALSEnever evaluated
0-10
460 {-
461 s = (char *)xmalloc (si - i + 1);-
462 for (j = 0, k = i; k < si; j++, k++)
k < siDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
10-26
463 {-
464 /* Remove a backslash quoting the search string delimiter. */-
465 if (str[k] == '\\' && str[k + 1] == delimiter)
str[k] == '\\'Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
str[k + 1] == delimiterDescription
TRUEnever evaluated
FALSEnever evaluated
0-26
466 k++;
never executed: k++;
0
467 s[j] = str[k];-
468 }
executed 26 times by 1 test: end of block
Executed by:
  • Self test
26
469 s[j] = '\0';-
470 if (lenptr)
lenptrDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-10
471 *lenptr = j;
executed 10 times by 1 test: *lenptr = j;
Executed by:
  • Self test
10
472 }
executed 10 times by 1 test: end of block
Executed by:
  • Self test
10
473-
474 i = si;-
475 if (str[i])
str[i]Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-9
476 i++;
executed 9 times by 1 test: i++;
Executed by:
  • Self test
9
477 *iptr = i;-
478-
479 return s;
executed 10 times by 1 test: return s;
Executed by:
  • Self test
10
480}-
481-
482static void-
483postproc_subst_rhs (void)-
484{-
485 char *new;-
486 int i, j, new_size;-
487-
488 new = (char *)xmalloc (new_size = subst_rhs_len + subst_lhs_len);-
489 for (i = j = 0; i < subst_rhs_len; i++)
i < subst_rhs_lenDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-2
490 {-
491 if (subst_rhs[i] == '&')
subst_rhs[i] == '&'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1
492 {-
493 if (j + subst_lhs_len >= new_size)
j + subst_lhs_len >= new_sizeDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
494 new = (char *)xrealloc (new, (new_size = new_size * 2 + subst_lhs_len));
never executed: new = (char *)xrealloc (new, (new_size = new_size * 2 + subst_lhs_len));
0
495 strcpy (new + j, subst_lhs);-
496 j += subst_lhs_len;-
497 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
498 else-
499 {-
500 /* a single backslash protects the `&' from lhs interpolation */-
501 if (subst_rhs[i] == '\\' && subst_rhs[i + 1] == '&')
subst_rhs[i] == '\\'Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
subst_rhs[i + 1] == '&'Description
TRUEnever evaluated
FALSEnever evaluated
0-1
502 i++;
never executed: i++;
0
503 if (j >= new_size)
j >= new_sizeDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
504 new = (char *)xrealloc (new, new_size *= 2);
never executed: new = (char *)xrealloc (new, new_size *= 2);
0
505 new[j++] = subst_rhs[i];-
506 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
507 }-
508 new[j] = '\0';-
509 xfree (subst_rhs);-
510 subst_rhs = new;-
511 subst_rhs_len = j;-
512}
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
513-
514/* Expand the bulk of a history specifier starting at STRING[START].-
515 Returns 0 if everything is OK, -1 if an error occurred, and 1-
516 if the `p' modifier was supplied and the caller should just print-
517 the returned string. Returns the new index into string in-
518 *END_INDEX_PTR, and the expanded specifier in *RET_STRING. */-
519/* need current line for !# */-
520static int-
521history_expand_internal (char *string, int start, int qc, int *end_index_ptr, char **ret_string, char *current_line)-
522{-
523 int i, n, starting_index;-
524 int substitute_globally, subst_bywords, want_quotes, print_only;-
525 char *event, *temp, *result, *tstr, *t, c, *word_spec;-
526 int result_len;-
527#if defined (HANDLE_MULTIBYTE)-
528 mbstate_t ps;-
529-
530 memset (&ps, 0, sizeof (mbstate_t));-
531#endif-
532-
533 result = (char *)xmalloc (result_len = 128);-
534-
535 i = start;-
536-
537 /* If it is followed by something that starts a word specifier,-
538 then !! is implied as the event specifier. */-
539-
540 if (member (string[i + 1], ":$*%^"))
((string[i + 1...id *)0) ) : 0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 130 times by 1 test
Evaluated by:
  • Self test
(string[i + 1])Description
TRUEevaluated 135 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-135
541 {-
542 char fake_s[3];-
543 int fake_i = 0;-
544 i++;-
545 fake_s[0] = fake_s[1] = history_expansion_char;-
546 fake_s[2] = '\0';-
547 event = get_history_event (fake_s, &fake_i, 0);-
548 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
549 else if (string[i + 1] == '#')
string[i + 1] == '#'Description
TRUEnever evaluated
FALSEevaluated 130 times by 1 test
Evaluated by:
  • Self test
0-130
550 {-
551 i += 2;-
552 event = current_line;-
553 }
never executed: end of block
0
554 else-
555 event = get_history_event (string, &i, qc);
executed 130 times by 1 test: event = get_history_event (string, &i, qc);
Executed by:
  • Self test
130
556 -
557 if (event == 0)
event == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 134 times by 1 test
Evaluated by:
  • Self test
1-134
558 {-
559 *ret_string = hist_error (string, start, i, EVENT_NOT_FOUND);-
560 xfree (result);-
561 return (-1);
executed 1 time by 1 test: return (-1);
Executed by:
  • Self test
1
562 }-
563-
564 /* If a word specifier is found, then do what that requires. */-
565 starting_index = i;-
566 word_spec = get_history_word_specifier (string, event, &i);-
567-
568 /* There is no such thing as a `malformed word specifier'. However,-
569 it is possible for a specifier that has no match. In that case,-
570 we complain. */-
571 if (word_spec == (char *)&error_pointer)
word_spec == (...&error_pointerDescription
TRUEnever evaluated
FALSEevaluated 134 times by 1 test
Evaluated by:
  • Self test
0-134
572 {-
573 *ret_string = hist_error (string, starting_index, i, BAD_WORD_SPEC);-
574 xfree (result);-
575 return (-1);
never executed: return (-1);
0
576 }-
577-
578 /* If no word specifier, than the thing of interest was the event. */-
579 temp = word_spec ? savestring (word_spec) : savestring (event);
word_specDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 106 times by 1 test
Evaluated by:
  • Self test
28-106
580 FREE (word_spec);
executed 28 times by 1 test: free (word_spec);
Executed by:
  • Self test
word_specDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 106 times by 1 test
Evaluated by:
  • Self test
28-106
581-
582 /* Perhaps there are other modifiers involved. Do what they say. */-
583 want_quotes = substitute_globally = subst_bywords = print_only = 0;-
584 starting_index = i;-
585-
586 while (string[i] == ':')
string[i] == ':'Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 133 times by 1 test
Evaluated by:
  • Self test
25-133
587 {-
588 c = string[i + 1];-
589-
590 if (c == 'g' || c == 'a')
c == 'g'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
c == 'a'Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
0-21
591 {-
592 substitute_globally = 1;-
593 i++;-
594 c = string[i + 1];-
595 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test
4
596 else if (c == 'G')
c == 'G'Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
0-21
597 {-
598 subst_bywords = 1;-
599 i++;-
600 c = string[i + 1];-
601 }
never executed: end of block
0
602-
603 switch (c)-
604 {-
605 default:
executed 1 time by 1 test: default:
Executed by:
  • Self test
1
606 *ret_string = hist_error (string, i+1, i+2, BAD_MODIFIER);-
607 xfree (result);-
608 xfree (temp);-
609 return -1;
executed 1 time by 1 test: return -1;
Executed by:
  • Self test
1
610-
611 case 'q':
executed 5 times by 1 test: case 'q':
Executed by:
  • Self test
5
612 want_quotes = 'q';-
613 break;
executed 5 times by 1 test: break;
Executed by:
  • Self test
5
614-
615 case 'x':
executed 1 time by 1 test: case 'x':
Executed by:
  • Self test
1
616 want_quotes = 'x';-
617 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
618-
619 /* :p means make this the last executed line. So we-
620 return an error state after adding this line to the-
621 history. */-
622 case 'p':
executed 3 times by 1 test: case 'p':
Executed by:
  • Self test
3
623 print_only++;-
624 break;
executed 3 times by 1 test: break;
Executed by:
  • Self test
3
625-
626 /* :t discards all but the last part of the pathname. */-
627 case 't':
executed 1 time by 1 test: case 't':
Executed by:
  • Self test
1
628 tstr = strrchr (temp, '/');-
629 if (tstr)
tstrDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
630 {-
631 tstr++;-
632 t = savestring (tstr);-
633 xfree (temp);-
634 temp = t;-
635 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
636 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
637-
638 /* :h discards the last part of a pathname. */-
639 case 'h':
executed 1 time by 1 test: case 'h':
Executed by:
  • Self test
1
640 tstr = strrchr (temp, '/');-
641 if (tstr)
tstrDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
642 *tstr = '\0';
executed 1 time by 1 test: *tstr = '\0';
Executed by:
  • Self test
1
643 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
644-
645 /* :r discards the suffix. */-
646 case 'r':
executed 5 times by 1 test: case 'r':
Executed by:
  • Self test
5
647 tstr = strrchr (temp, '.');-
648 if (tstr)
tstrDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
649 *tstr = '\0';
executed 5 times by 1 test: *tstr = '\0';
Executed by:
  • Self test
5
650 break;
executed 5 times by 1 test: break;
Executed by:
  • Self test
5
651-
652 /* :e discards everything but the suffix. */-
653 case 'e':
executed 2 times by 1 test: case 'e':
Executed by:
  • Self test
2
654 tstr = strrchr (temp, '.');-
655 if (tstr)
tstrDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
656 {-
657 t = savestring (tstr);-
658 xfree (temp);-
659 temp = t;-
660 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
661 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
662-
663 /* :s/this/that substitutes `that' for the first-
664 occurrence of `this'. :gs/this/that substitutes `that'-
665 for each occurrence of `this'. :& repeats the last-
666 substitution. :g& repeats the last substitution-
667 globally. */-
668-
669 case '&':
executed 1 time by 1 test: case '&':
Executed by:
  • Self test
1
670 case 's':
executed 5 times by 1 test: case 's':
Executed by:
  • Self test
5
671 {-
672 char *new_event;-
673 int delimiter, failed, si, l_temp, ws, we;-
674-
675 if (c == 's')
c == 's'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-5
676 {-
677 if (i + 2 < (int)strlen (string))
i + 2 < (int)strlen (string)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
678 {-
679#if defined (HANDLE_MULTIBYTE)-
680 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
(__ctype_get_m...ur_max ()) > 1Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
rl_byte_oriented == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-5
681 {-
682 _rl_adjust_point (string, i + 2, &ps);-
683 if (_rl_get_char_len (string + i + 2, &ps) > 1)
_rl_get_char_l... + 2, &ps) > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
684 delimiter = 0;
never executed: delimiter = 0;
0
685 else-
686 delimiter = string[i + 2];
never executed: delimiter = string[i + 2];
0
687 }-
688 else-
689#endif /* HANDLE_MULTIBYTE */-
690 delimiter = string[i + 2];
executed 5 times by 1 test: delimiter = string[i + 2];
Executed by:
  • Self test
5
691 }-
692 else-
693 break; /* no search delimiter */
never executed: break;
0
694-
695 i += 3;-
696-
697 t = get_subst_pattern (string, &i, delimiter, 0, &subst_lhs_len);-
698 /* An empty substitution lhs with no previous substitution-
699 uses the last search string as the lhs. */-
700 if (t)
tDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
701 {-
702 FREE (subst_lhs);
executed 4 times by 1 test: free (subst_lhs);
Executed by:
  • Self test
subst_lhsDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-4
703 subst_lhs = t;-
704 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
705 else if (!subst_lhs)
!subst_lhsDescription
TRUEnever evaluated
FALSEnever evaluated
0
706 {-
707 if (search_string && *search_string)
search_stringDescription
TRUEnever evaluated
FALSEnever evaluated
*search_stringDescription
TRUEnever evaluated
FALSEnever evaluated
0
708 {-
709 subst_lhs = savestring (search_string);-
710 subst_lhs_len = strlen (subst_lhs);-
711 }
never executed: end of block
0
712 else-
713 {-
714 subst_lhs = (char *) NULL;-
715 subst_lhs_len = 0;-
716 }
never executed: end of block
0
717 }-
718-
719 FREE (subst_rhs);
executed 4 times by 1 test: free (subst_rhs);
Executed by:
  • Self test
subst_rhsDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-4
720 subst_rhs = get_subst_pattern (string, &i, delimiter, 1, &subst_rhs_len);-
721-
722 /* If `&' appears in the rhs, it's supposed to be replaced-
723 with the lhs. */-
724 if (member ('&', subst_rhs))
(('&') ? ((cha...id *)0) ) : 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
('&')Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
725 postproc_subst_rhs ();
executed 1 time by 1 test: postproc_subst_rhs ();
Executed by:
  • Self test
1
726 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
727 else-
728 i += 2;
executed 1 time by 1 test: i += 2;
Executed by:
  • Self test
1
729-
730 /* If there is no lhs, the substitution can't succeed. */-
731 if (subst_lhs_len == 0)
subst_lhs_len == 0Description
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
732 {-
733 *ret_string = hist_error (string, starting_index, i, NO_PREV_SUBST);-
734 xfree (result);-
735 xfree (temp);-
736 return -1;
never executed: return -1;
0
737 }-
738-
739 l_temp = strlen (temp);-
740 /* Ignore impossible cases. */-
741 if (subst_lhs_len > l_temp)
subst_lhs_len > l_tempDescription
TRUEnever evaluated
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-6
742 {-
743 *ret_string = hist_error (string, starting_index, i, SUBST_FAILED);-
744 xfree (result);-
745 xfree (temp);-
746 return (-1);
never executed: return (-1);
0
747 }-
748-
749 /* Find the first occurrence of THIS in TEMP. */-
750 /* Substitute SUBST_RHS for SUBST_LHS in TEMP. There are three-
751 cases to consider:-
752-
753 1. substitute_globally == subst_bywords == 0-
754 2. substitute_globally == 1 && subst_bywords == 0-
755 3. substitute_globally == 0 && subst_bywords == 1-
756-
757 In the first case, we substitute for the first occurrence only.-
758 In the second case, we substitute for every occurrence.-
759 In the third case, we tokenize into words and substitute the-
760 first occurrence of each word. */-
761-
762 si = we = 0;-
763 for (failed = 1; (si + subst_lhs_len) <= l_temp; si++)
(si + subst_lhs_len) <= l_tempDescription
TRUEevaluated 105 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-105
764 {-
765 /* First skip whitespace and find word boundaries if-
766 we're past the end of the word boundary we found-
767 the last time. */-
768 if (subst_bywords && si > we)
subst_bywordsDescription
TRUEnever evaluated
FALSEevaluated 105 times by 1 test
Evaluated by:
  • Self test
si > weDescription
TRUEnever evaluated
FALSEnever evaluated
0-105
769 {-
770 for (; temp[si] && whitespace (temp[si]); si++)
temp[si]Description
TRUEnever evaluated
FALSEnever evaluated
((temp[si]) == ' ')Description
TRUEnever evaluated
FALSEnever evaluated
((temp[si]) == '\t')Description
TRUEnever evaluated
FALSEnever evaluated
0
771 ;
never executed: ;
0
772 ws = si;-
773 we = history_tokenize_word (temp, si);-
774 }
never executed: end of block
0
775-
776 if (STREQN (temp+si, subst_lhs, subst_lhs_len))
never executed: __result = (((const unsigned char *) (const char *) ( (temp+si) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( (subst_lhs) ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(((subst_lhs_l...en) ))) == 0))Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87 times by 1 test
Evaluated by:
  • Self test
((subst_lhs_len) == 0)Description
TRUEnever evaluated
FALSEevaluated 105 times by 1 test
Evaluated by:
  • Self test
((temp+si)[0] ...subst_lhs)[0])Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87 times by 1 test
Evaluated by:
  • Self test
( (__extension...len) ))) == 0)Description
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_cons...bst_lhs_len) )Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test
__builtin_cons... ( (temp+si) )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( (temp...st_lhs_len) ))Description
TRUEnever evaluated
FALSEnever evaluated
__builtin_cons... (subst_lhs) )Description
TRUEnever evaluated
FALSEnever evaluated
strlen ( (subs...st_lhs_len) ))Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s1_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 0Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 1Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
__s2_len > 2Description
TRUEnever evaluated
FALSEnever evaluated
__result == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-105
777 {-
778 int len = subst_rhs_len - subst_lhs_len + l_temp;-
779 new_event = (char *)xmalloc (1 + len);-
780 strncpy (new_event, temp, si);-
781 strncpy (new_event + si, subst_rhs, subst_rhs_len);-
782 strncpy (new_event + si + subst_rhs_len,-
783 temp + si + subst_lhs_len,-
784 l_temp - (si + subst_lhs_len));-
785 new_event[len] = '\0';-
786 xfree (temp);-
787 temp = new_event;-
788-
789 failed = 0;-
790-
791 if (substitute_globally)
substitute_globallyDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-16
792 {-
793 /* Reported to fix a bug that causes it to skip every-
794 other match when matching a single character. Was-
795 si += subst_rhs_len previously. */-
796 si += subst_rhs_len - 1;-
797 l_temp = strlen (temp);-
798 substitute_globally++;-
799 continue;
executed 16 times by 1 test: continue;
Executed by:
  • Self test
16
800 }-
801 else if (subst_bywords)
subst_bywordsDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
802 {-
803 si = we;-
804 l_temp = strlen (temp);-
805 continue;
never executed: continue;
0
806 }-
807 else-
808 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
809 }-
810 }
executed 87 times by 1 test: end of block
Executed by:
  • Self test
87
811-
812 if (substitute_globally > 1)
substitute_globally > 1Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2-4
813 {-
814 substitute_globally = 0;-
815 continue; /* don't want to increment i */
executed 4 times by 1 test: continue;
Executed by:
  • Self test
4
816 }-
817-
818 if (failed == 0)
failed == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
819 continue; /* don't want to increment i */
executed 2 times by 1 test: continue;
Executed by:
  • Self test
2
820-
821 *ret_string = hist_error (string, starting_index, i, SUBST_FAILED);-
822 xfree (result);-
823 xfree (temp);-
824 return (-1);
never executed: return (-1);
0
825 }-
826 }-
827 i += 2;-
828 }
executed 18 times by 1 test: end of block
Executed by:
  • Self test
18
829 /* Done with modifiers. */-
830 /* Believe it or not, we have to back the pointer up by one. */-
831 --i;-
832-
833 if (want_quotes)
want_quotesDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 127 times by 1 test
Evaluated by:
  • Self test
6-127
834 {-
835 char *x;-
836-
837 if (want_quotes == 'q')
want_quotes == 'q'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-5
838 x = sh_single_quote (temp);
executed 5 times by 1 test: x = sh_single_quote (temp);
Executed by:
  • Self test
5
839 else if (want_quotes == 'x')
want_quotes == 'x'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
840 x = quote_breaks (temp);
executed 1 time by 1 test: x = quote_breaks (temp);
Executed by:
  • Self test
1
841 else-
842 x = savestring (temp);
never executed: x = strcpy (xmalloc (1 + strlen (temp)), (temp));
0
843-
844 xfree (temp);-
845 temp = x;-
846 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
847-
848 n = strlen (temp);-
849 if (n >= result_len)
n >= result_lenDescription
TRUEnever evaluated
FALSEevaluated 133 times by 1 test
Evaluated by:
  • Self test
0-133
850 result = (char *)xrealloc (result, n + 2);
never executed: result = (char *)xrealloc (result, n + 2);
0
851 strcpy (result, temp);-
852 xfree (temp);-
853-
854 *end_index_ptr = i;-
855 *ret_string = result;-
856 return (print_only);
executed 133 times by 1 test: return (print_only);
Executed by:
  • Self test
133
857}-
858-
859/* Expand the string STRING, placing the result into OUTPUT, a pointer-
860 to a string. Returns:-
861-
862 -1) If there was an error in expansion.-
863 0) If no expansions took place (or, if the only change in-
864 the text was the de-slashifying of the history expansion-
865 character)-
866 1) If expansions did take place-
867 2) If the `p' modifier was given and the caller should print the result-
868-
869 If an error occurred in expansion, then OUTPUT contains a descriptive-
870 error message. */-
871-
872#define ADD_STRING(s) \-
873 do \-
874 { \-
875 int sl = strlen (s); \-
876 j += sl; \-
877 if (j >= result_len) \-
878 { \-
879 while (j >= result_len) \-
880 result_len += 128; \-
881 result = (char *)xrealloc (result, result_len); \-
882 } \-
883 strcpy (result + j - sl, s); \-
884 } \-
885 while (0)-
886-
887#define ADD_CHAR(c) \-
888 do \-
889 { \-
890 if (j >= result_len - 1) \-
891 result = (char *)xrealloc (result, result_len += 64); \-
892 result[j++] = c; \-
893 result[j] = '\0'; \-
894 } \-
895 while (0)-
896-
897int-
898history_expand (char *hstring, char **output)-
899{-
900 register int j;-
901 int i, r, l, passc, cc, modified, eindex, only_printing, dquote, squote, flag;-
902 char *string;-
903-
904 /* The output string, and its length. */-
905 int result_len;-
906 char *result;-
907-
908#if defined (HANDLE_MULTIBYTE)-
909 char mb[MB_LEN_MAX];-
910 mbstate_t ps;-
911#endif-
912-
913 /* Used when adding the string. */-
914 char *temp;-
915-
916 if (output == 0)
output == 0Description
TRUEnever evaluated
FALSEevaluated 213 times by 1 test
Evaluated by:
  • Self test
0-213
917 return 0;
never executed: return 0;
0
918-
919 /* Setting the history expansion character to 0 inhibits all-
920 history expansion. */-
921 if (history_expansion_char == 0)
history_expansion_char == 0Description
TRUEnever evaluated
FALSEevaluated 213 times by 1 test
Evaluated by:
  • Self test
0-213
922 {-
923 *output = savestring (hstring);-
924 return (0);
never executed: return (0);
0
925 }-
926 -
927 /* Prepare the buffer for printing error messages. */-
928 result = (char *)xmalloc (result_len = 256);-
929 result[0] = '\0';-
930-
931 only_printing = modified = 0;-
932 l = strlen (hstring);-
933-
934 /* Grovel the string. Only backslash and single quotes can quote the-
935 history escape character. We also handle arg specifiers. */-
936-
937 /* Before we grovel forever, see if the history_expansion_char appears-
938 anywhere within the text. */-
939-
940 /* The quick substitution character is a history expansion all right. That-
941 is to say, "^this^that^" is equivalent to "!!:s^this^that^", and in fact,-
942 that is the substitution that we do. */-
943 if (hstring[0] == history_subst_char)
hstring[0] == ...ory_subst_charDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 212 times by 1 test
Evaluated by:
  • Self test
1-212
944 {-
945 string = (char *)xmalloc (l + 5);-
946-
947 string[0] = string[1] = history_expansion_char;-
948 string[2] = ':';-
949 string[3] = 's';-
950 strcpy (string + 4, hstring);-
951 l += 4;-
952 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
953 else-
954 {-
955#if defined (HANDLE_MULTIBYTE)-
956 memset (&ps, 0, sizeof (mbstate_t));-
957#endif-
958-
959 string = hstring;-
960 /* If not quick substitution, still maybe have to do expansion. */-
961-
962 /* `!' followed by one of the characters in history_no_expand_chars-
963 is NOT an expansion. */-
964 for (i = dquote = squote = 0; string[i]; i++)
string[i]Description
TRUEevaluated 2131 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 108 times by 1 test
Evaluated by:
  • Self test
108-2131
965 {-
966#if defined (HANDLE_MULTIBYTE)-
967 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
(__ctype_get_m...ur_max ()) > 1Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2112 times by 1 test
Evaluated by:
  • Self test
rl_byte_oriented == 0Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2112
968 {-
969 int v;-
970 v = _rl_get_char_len (string + i, &ps);-
971 if (v > 1)
v > 1Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
0-19
972 {-
973 i += v - 1;-
974 continue;
never executed: continue;
0
975 }-
976 }
executed 19 times by 1 test: end of block
Executed by:
  • Self test
19
977#endif /* HANDLE_MULTIBYTE */-
978-
979 cc = string[i + 1];-
980 /* The history_comment_char, if set, appearing at the beginning-
981 of a word signifies that the rest of the line should not have-
982 history expansion performed on it.-
983 Skip the rest of the line and break out of the loop. */-
984 if (history_comment_char && string[i] == history_comment_char &&
history_comment_charDescription
TRUEevaluated 2128 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
string[i] == h...y_comment_charDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2126 times by 1 test
Evaluated by:
  • Self test
2-2128
985 dquote == 0 &&
dquote == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1
986 (i == 0 || member (string[i - 1], history_word_delimiters)))
(string[i - 1])Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
i == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
((string[i - 1...id *)0) ) : 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
987 {-
988 while (string[i])
string[i]Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-7
989 i++;
executed 7 times by 1 test: i++;
Executed by:
  • Self test
7
990 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
991 }-
992 else if (string[i] == history_expansion_char)
string[i] == h...expansion_charDescription
TRUEevaluated 165 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1965 times by 1 test
Evaluated by:
  • Self test
165-1965
993 {-
994 if (cc == 0 || member (cc, history_no_expand_chars))
(cc)Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
cc == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 156 times by 1 test
Evaluated by:
  • Self test
((cc) ? ((char...id *)0) ) : 0)Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 145 times by 1 test
Evaluated by:
  • Self test
0-156
995 continue;
executed 20 times by 1 test: continue;
Executed by:
  • Self test
20
996 /* DQUOTE won't be set unless history_quotes_inhibit_expansion-
997 is set. The idea here is to treat double-quoted strings the-
998 same as the word outside double quotes; in effect making the-
999 double quote part of history_no_expand_chars when DQUOTE is-
1000 set. */-
1001 else if (dquote && cc == '"')
dquoteDescription
TRUEevaluated 51 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 94 times by 1 test
Evaluated by:
  • Self test
cc == '"'Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test
16-94
1002 continue;
executed 16 times by 1 test: continue;
Executed by:
  • Self test
16
1003 /* If the calling application has set-
1004 history_inhibit_expansion_function to a function that checks-
1005 for special cases that should not be history expanded,-
1006 call the function and skip the expansion if it returns a-
1007 non-zero value. */-
1008 else if (history_inhibit_expansion_function &&
history_inhibi...nsion_functionDescription
TRUEevaluated 129 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-129
1009 (*history_inhibit_expansion_function) (string, i))
(*history_inhi...n) (string, i)Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 103 times by 1 test
Evaluated by:
  • Self test
26-103
1010 continue;
executed 26 times by 1 test: continue;
Executed by:
  • Self test
26
1011 else-
1012 break;
executed 103 times by 1 test: break;
Executed by:
  • Self test
103
1013 }-
1014 /* Shell-like quoting: allow backslashes to quote double quotes-
1015 inside a double-quoted string. */-
1016 else if (dquote && string[i] == '\\' && cc == '"')
dquoteDescription
TRUEevaluated 443 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1522 times by 1 test
Evaluated by:
  • Self test
string[i] == '\\'Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 439 times by 1 test
Evaluated by:
  • Self test
cc == '"'Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-1522
1017 i++;
never executed: i++;
0
1018 /* More shell-like quoting: if we're paying attention to single-
1019 quotes and letting them quote the history expansion character,-
1020 then we need to pay attention to double quotes, because single-
1021 quotes are not special inside double-quoted strings. */-
1022 else if (history_quotes_inhibit_expansion && string[i] == '"')
history_quotes...ibit_expansionDescription
TRUEevaluated 1965 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
string[i] == '"'Description
TRUEevaluated 156 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1809 times by 1 test
Evaluated by:
  • Self test
0-1965
1023 {-
1024 dquote = 1 - dquote;-
1025 }
executed 156 times by 1 test: end of block
Executed by:
  • Self test
156
1026 else if (dquote == 0 && history_quotes_inhibit_expansion && string[i] == '\'')
dquote == 0Description
TRUEevaluated 1433 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 376 times by 1 test
Evaluated by:
  • Self test
history_quotes...ibit_expansionDescription
TRUEevaluated 1433 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
string[i] == '\''Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1379 times by 1 test
Evaluated by:
  • Self test
0-1433
1027 {-
1028 /* If this is bash, single quotes inhibit history expansion. */-
1029 flag = (i > 0 && string[i - 1] == '$');
i > 0Description
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
string[i - 1] == '$'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 52 times by 1 test
Evaluated by:
  • Self test
0-54
1030 i++;-
1031 hist_string_extract_single_quoted (string, &i, flag);-
1032 }
executed 54 times by 1 test: end of block
Executed by:
  • Self test
54
1033 else if (history_quotes_inhibit_expansion && string[i] == '\\')
history_quotes...ibit_expansionDescription
TRUEevaluated 1755 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
string[i] == '\\'Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1738 times by 1 test
Evaluated by:
  • Self test
0-1755
1034 {-
1035 /* If this is bash, allow backslashes to quote single-
1036 quotes and the history expansion character. */-
1037 if (cc == '\'' || cc == history_expansion_char)
cc == '\''Description
TRUEnever evaluated
FALSEevaluated 17 times by 1 test
Evaluated by:
  • Self test
cc == history_expansion_charDescription
TRUEevaluated 17 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-17
1038 i++;
executed 17 times by 1 test: i++;
Executed by:
  • Self test
17
1039 }
executed 17 times by 1 test: end of block
Executed by:
  • Self test
17
1040 -
1041 }
executed 1965 times by 1 test: end of block
Executed by:
  • Self test
1965
1042 -
1043 if (string[i] != history_expansion_char)
string[i] != h...expansion_charDescription
TRUEevaluated 109 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 103 times by 1 test
Evaluated by:
  • Self test
103-109
1044 {-
1045 xfree (result);-
1046 *output = savestring (string);-
1047 return (0);
executed 109 times by 1 test: return (0);
Executed by:
  • Self test
109
1048 }-
1049 }
executed 103 times by 1 test: end of block
Executed by:
  • Self test
103
1050-
1051 /* Extract and perform the substitution. */-
1052 for (passc = dquote = squote = i = j = 0; i < l; i++)
i < lDescription
TRUEevaluated 1088 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
102-1088
1053 {-
1054 int qc, tchar = string[i];-
1055-
1056 if (passc)
passcDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1080 times by 1 test
Evaluated by:
  • Self test
8-1080
1057 {-
1058 passc = 0;-
1059 ADD_CHAR (tchar);
never executed: result = (char *)xrealloc (result, result_len += 64);
j >= result_len - 1Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
0-8
1060 continue;
executed 8 times by 1 test: continue;
Executed by:
  • Self test
8
1061 }-
1062-
1063#if defined (HANDLE_MULTIBYTE)-
1064 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
(__ctype_get_m...ur_max ()) > 1Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1075 times by 1 test
Evaluated by:
  • Self test
rl_byte_oriented == 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1075
1065 {-
1066 int k, c;-
1067-
1068 c = tchar;-
1069 memset (mb, 0, sizeof (mb));-
1070 for (k = 0; k < MB_LEN_MAX; k++)
k < 16Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
1071 {-
1072 mb[k] = (char)c;-
1073 memset (&ps, 0, sizeof (mbstate_t));-
1074 if (_rl_get_char_len (mb, &ps) == -2)
_rl_get_char_l...mb, &ps) == -2Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
1075 c = string[++i];
never executed: c = string[++i];
0
1076 else-
1077 break;
executed 5 times by 1 test: break;
Executed by:
  • Self test
5
1078 }-
1079 if (strlen (mb) > 1)
strlen (mb) > 1Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
1080 {-
1081 ADD_STRING (mb);
never executed: result_len += 128;
never executed: end of block
j >= result_lenDescription
TRUEnever evaluated
FALSEnever evaluated
j >= result_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1082 continue;
never executed: continue;
0
1083 }-
1084 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
1085#endif /* HANDLE_MULTIBYTE */-
1086-
1087 if (tchar == history_expansion_char)
tchar == histo...expansion_charDescription
TRUEevaluated 136 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 944 times by 1 test
Evaluated by:
  • Self test
136-944
1088 tchar = -3;
executed 136 times by 1 test: tchar = -3;
Executed by:
  • Self test
136
1089 else if (tchar == history_comment_char)
tchar == history_comment_charDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 943 times by 1 test
Evaluated by:
  • Self test
1-943
1090 tchar = -2;
executed 1 time by 1 test: tchar = -2;
Executed by:
  • Self test
1
1091-
1092 switch (tchar)-
1093 {-
1094 default:
executed 862 times by 1 test: default:
Executed by:
  • Self test
862
1095 ADD_CHAR (string[i]);
never executed: result = (char *)xrealloc (result, result_len += 64);
j >= result_len - 1Description
TRUEnever evaluated
FALSEevaluated 862 times by 1 test
Evaluated by:
  • Self test
0-862
1096 break;
executed 862 times by 1 test: break;
Executed by:
  • Self test
862
1097-
1098 case '\\':
executed 8 times by 1 test: case '\\':
Executed by:
  • Self test
8
1099 passc++;-
1100 ADD_CHAR (tchar);
never executed: result = (char *)xrealloc (result, result_len += 64);
j >= result_len - 1Description
TRUEnever evaluated
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
0-8
1101 break;
executed 8 times by 1 test: break;
Executed by:
  • Self test
8
1102-
1103 case '"':
executed 71 times by 1 test: case '"':
Executed by:
  • Self test
71
1104 dquote = 1 - dquote;-
1105 ADD_CHAR (tchar);
never executed: result = (char *)xrealloc (result, result_len += 64);
j >= result_len - 1Description
TRUEnever evaluated
FALSEevaluated 71 times by 1 test
Evaluated by:
  • Self test
0-71
1106 break;
executed 71 times by 1 test: break;
Executed by:
  • Self test
71
1107 -
1108 case '\'':
executed 2 times by 1 test: case '\'':
Executed by:
  • Self test
2
1109 {-
1110 /* If history_quotes_inhibit_expansion is set, single quotes-
1111 inhibit history expansion, otherwise they are treated like-
1112 double quotes. */-
1113 if (squote)
squoteDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
1114 {-
1115 squote = 0;-
1116 ADD_CHAR (tchar);
never executed: result = (char *)xrealloc (result, result_len += 64);
j >= result_len - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1117 }
never executed: end of block
0
1118 else if (dquote == 0 && history_quotes_inhibit_expansion)
dquote == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
history_quotes...ibit_expansionDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
1119 {-
1120 int quote, slen;-
1121-
1122 flag = (i > 0 && string[i - 1] == '$');
i > 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
string[i - 1] == '$'Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
1123 quote = i++;-
1124 hist_string_extract_single_quoted (string, &i, flag);-
1125-
1126 slen = i - quote + 2;-
1127 temp = (char *)xmalloc (slen);-
1128 strncpy (temp, string + quote, slen);-
1129 temp[slen - 1] = '\0';-
1130 ADD_STRING (temp);
never executed: result_len += 128;
never executed: end of block
j >= result_lenDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
j >= result_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0-1
1131 xfree (temp);-
1132 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
1133 else if (dquote == 0 && squote == 0 && history_quotes_inhibit_expansion == 0)
dquote == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
squote == 0Description
TRUEnever evaluated
FALSEnever evaluated
history_quotes...expansion == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-1
1134 {-
1135 squote = 1;-
1136 ADD_CHAR (string[i]);
never executed: result = (char *)xrealloc (result, result_len += 64);
j >= result_len - 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1137 }
never executed: end of block
0
1138 else-
1139 ADD_CHAR (string[i]);
never executed: result = (char *)xrealloc (result, result_len += 64);
executed 1 time by 1 test: end of block
Executed by:
  • Self test
j >= result_len - 1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
1140 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
1141 }-
1142-
1143 case -2: /* history_comment_char */
executed 1 time by 1 test: case -2:
Executed by:
  • Self test
1
1144 if ((dquote == 0 || history_quotes_inhibit_expansion == 0) &&
dquote == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
history_quotes...expansion == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
1145 (i == 0 || member (string[i - 1], history_word_delimiters)))
(string[i - 1])Description
TRUEnever evaluated
FALSEnever evaluated
i == 0Description
TRUEnever evaluated
FALSEnever evaluated
((string[i - 1...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1146 {-
1147 temp = (char *)xmalloc (l - i + 1);-
1148 strcpy (temp, string + i);-
1149 ADD_STRING (temp);
never executed: result_len += 128;
never executed: end of block
j >= result_lenDescription
TRUEnever evaluated
FALSEnever evaluated
j >= result_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0
1150 xfree (temp);-
1151 i = l;-
1152 }
never executed: end of block
0
1153 else-
1154 ADD_CHAR (string[i]);
never executed: result = (char *)xrealloc (result, result_len += 64);
executed 1 time by 1 test: end of block
Executed by:
  • Self test
j >= result_len - 1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
1155 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
1156-
1157 case -3: /* history_expansion_char */
executed 136 times by 1 test: case -3:
Executed by:
  • Self test
136
1158 cc = string[i + 1];-
1159-
1160 /* If the history_expansion_char is followed by one of the-
1161 characters in history_no_expand_chars, then it is not a-
1162 candidate for expansion of any kind. */-
1163 if (cc == 0 || member (cc, history_no_expand_chars) ||
(cc)Description
TRUEevaluated 136 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
cc == 0Description
TRUEnever evaluated
FALSEevaluated 136 times by 1 test
Evaluated by:
  • Self test
((cc) ? ((char...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEevaluated 136 times by 1 test
Evaluated by:
  • Self test
0-136
1164 (dquote && cc == '"') ||
dquoteDescription
TRUEevaluated 36 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 100 times by 1 test
Evaluated by:
  • Self test
cc == '"'Description
TRUEnever evaluated
FALSEevaluated 36 times by 1 test
Evaluated by:
  • Self test
0-100
1165 (history_inhibit_expansion_function && (*history_inhibit_expansion_function) (string, i)))
history_inhibi...nsion_functionDescription
TRUEevaluated 136 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(*history_inhi...n) (string, i)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 135 times by 1 test
Evaluated by:
  • Self test
0-136
1166 {-
1167 ADD_CHAR (string[i]);
never executed: result = (char *)xrealloc (result, result_len += 64);
j >= result_len - 1Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
1168 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
1169 }-
1170-
1171#if defined (NO_BANG_HASH_MODIFIERS)-
1172 /* There is something that is listed as a `word specifier' in csh-
1173 documentation which means `the expanded text to this point'.-
1174 That is not a word specifier, it is an event specifier. If we-
1175 don't want to allow modifiers with `!#', just stick the current-
1176 output line in again. */-
1177 if (cc == '#')-
1178 {-
1179 if (result)-
1180 {-
1181 temp = (char *)xmalloc (1 + strlen (result));-
1182 strcpy (temp, result);-
1183 ADD_STRING (temp);-
1184 xfree (temp);-
1185 }-
1186 i++;-
1187 break;-
1188 }-
1189#endif-
1190 qc = squote ? '\'' : (dquote ? '"' : 0);
squoteDescription
TRUEnever evaluated
FALSEevaluated 135 times by 1 test
Evaluated by:
  • Self test
dquoteDescription
TRUEevaluated 35 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 100 times by 1 test
Evaluated by:
  • Self test
0-135
1191 r = history_expand_internal (string, i, qc, &eindex, &temp, result);-
1192 if (r < 0)
r < 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 133 times by 1 test
Evaluated by:
  • Self test
2-133
1193 {-
1194 *output = temp;-
1195 xfree (result);-
1196 if (string != hstring)
string != hstringDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
1197 xfree (string);
never executed: xfree (string);
0
1198 return -1;
executed 2 times by 1 test: return -1;
Executed by:
  • Self test
2
1199 }-
1200 else-
1201 {-
1202 if (temp)
tempDescription
TRUEevaluated 133 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-133
1203 {-
1204 modified++;-
1205 if (*temp)
*tempDescription
TRUEevaluated 133 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-133
1206 ADD_STRING (temp);
never executed: result_len += 128;
never executed: end of block
executed 133 times by 1 test: end of block
Executed by:
  • Self test
j >= result_lenDescription
TRUEnever evaluated
FALSEevaluated 133 times by 1 test
Evaluated by:
  • Self test
j >= result_lenDescription
TRUEnever evaluated
FALSEnever evaluated
0-133
1207 xfree (temp);-
1208 }
executed 133 times by 1 test: end of block
Executed by:
  • Self test
133
1209 only_printing += r == 1;-
1210 i = eindex;-
1211 }
executed 133 times by 1 test: end of block
Executed by:
  • Self test
133
1212 break;
executed 133 times by 1 test: break;
Executed by:
  • Self test
133
1213 }-
1214 }-
1215-
1216 *output = result;-
1217 if (string != hstring)
string != hstringDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 101 times by 1 test
Evaluated by:
  • Self test
1-101
1218 xfree (string);
executed 1 time by 1 test: xfree (string);
Executed by:
  • Self test
1
1219-
1220 if (only_printing)
only_printingDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 99 times by 1 test
Evaluated by:
  • Self test
3-99
1221 {-
1222#if 0-
1223 add_history (result);-
1224#endif-
1225 return (2);
executed 3 times by 1 test: return (2);
Executed by:
  • Self test
3
1226 }-
1227-
1228 return (modified != 0);
executed 99 times by 1 test: return (modified != 0);
Executed by:
  • Self test
99
1229}-
1230-
1231/* Return a consed string which is the word specified in SPEC, and found-
1232 in FROM. NULL is returned if there is no spec. The address of-
1233 ERROR_POINTER is returned if the word specified cannot be found.-
1234 CALLER_INDEX is the offset in SPEC to start looking; it is updated-
1235 to point to just after the last character parsed. */-
1236static char *-
1237get_history_word_specifier (char *spec, char *from, int *caller_index)-
1238{-
1239 register int i = *caller_index;-
1240 int first, last;-
1241 int expecting_word_spec = 0;-
1242 char *result;-
1243-
1244 /* The range of words to return doesn't exist yet. */-
1245 first = last = 0;-
1246 result = (char *)NULL;-
1247-
1248 /* If we found a colon, then this *must* be a word specification. If-
1249 it isn't, then it is an error. */-
1250 if (spec[i] == ':')
spec[i] == ':'Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 102 times by 1 test
Evaluated by:
  • Self test
32-102
1251 {-
1252 i++;-
1253 expecting_word_spec++;-
1254 }
executed 32 times by 1 test: end of block
Executed by:
  • Self test
32
1255-
1256 /* Handle special cases first. */-
1257-
1258 /* `%' is the word last searched for. */-
1259 if (spec[i] == '%')
spec[i] == '%'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 132 times by 1 test
Evaluated by:
  • Self test
2-132
1260 {-
1261 *caller_index = i + 1;-
1262 return (search_match ? savestring (search_match) : savestring (""));
executed 2 times by 1 test: return (search_match ? strcpy (xmalloc (1 + strlen (search_match)), (search_match)) : strcpy (xmalloc (1 + strlen ("")), ("")));
Executed by:
  • Self test
2
1263 }-
1264-
1265 /* `*' matches all of the arguments, but not the command. */-
1266 if (spec[i] == '*')
spec[i] == '*'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 129 times by 1 test
Evaluated by:
  • Self test
3-129
1267 {-
1268 *caller_index = i + 1;-
1269 result = history_arg_extract (1, '$', from);-
1270 return (result ? result : savestring (""));
executed 3 times by 1 test: return (result ? result : strcpy (xmalloc (1 + strlen ("")), ("")));
Executed by:
  • Self test
3
1271 }-
1272-
1273 /* `$' is last arg. */-
1274 if (spec[i] == '$')
spec[i] == '$'Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 122 times by 1 test
Evaluated by:
  • Self test
7-122
1275 {-
1276 *caller_index = i + 1;-
1277 return (history_arg_extract ('$', '$', from));
executed 7 times by 1 test: return (history_arg_extract ('$', '$', from));
Executed by:
  • Self test
7
1278 }-
1279-
1280 /* Try to get FIRST and LAST figured out. */-
1281-
1282 if (spec[i] == '-')
spec[i] == '-'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 119 times by 1 test
Evaluated by:
  • Self test
3-119
1283 first = 0;
executed 3 times by 1 test: first = 0;
Executed by:
  • Self test
3
1284 else if (spec[i] == '^')
spec[i] == '^'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 118 times by 1 test
Evaluated by:
  • Self test
1-118
1285 {-
1286 first = 1;-
1287 i++;-
1288 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
1289 else if (_rl_digit_p (spec[i]) && expecting_word_spec)
(spec[i]) >= '0'Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87 times by 1 test
Evaluated by:
  • Self test
(spec[i]) <= '9'Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
expecting_word_specDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-87
1290 {-
1291 for (first = 0; _rl_digit_p (spec[i]); i++)
(spec[i]) >= '0'Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
(spec[i]) <= '9'Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
4-16
1292 first = (first * 10) + _rl_digit_value (spec[i]);
executed 12 times by 1 test: first = (first * 10) + ((spec[i]) - '0');
Executed by:
  • Self test
12
1293 }
executed 12 times by 1 test: end of block
Executed by:
  • Self test
12
1294 else-
1295 return ((char *)NULL); /* no valid `first' for word specifier */
executed 106 times by 1 test: return ((char *) ((void *)0) );
Executed by:
  • Self test
106
1296-
1297 if (spec[i] == '^' || spec[i] == '*')
spec[i] == '^'Description
TRUEnever evaluated
FALSEevaluated 16 times by 1 test
Evaluated by:
  • Self test
spec[i] == '*'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
0-16
1298 {-
1299 last = (spec[i] == '^') ? 1 : '$'; /* x* abbreviates x-$ */
(spec[i] == '^')Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
1300 i++;-
1301 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
1302 else if (spec[i] != '-')
spec[i] != '-'Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 8 times by 1 test
Evaluated by:
  • Self test
7-8
1303 last = first;
executed 7 times by 1 test: last = first;
Executed by:
  • Self test
7
1304 else-
1305 {-
1306 i++;-
1307-
1308 if (_rl_digit_p (spec[i]))
(spec[i]) >= '0'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
(spec[i]) <= '9'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
1309 {-
1310 for (last = 0; _rl_digit_p (spec[i]); i++)
(spec[i]) >= '0'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
(spec[i]) <= '9'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
1311 last = (last * 10) + _rl_digit_value (spec[i]);
executed 2 times by 1 test: last = (last * 10) + ((spec[i]) - '0');
Executed by:
  • Self test
2
1312 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
1313 else if (spec[i] == '$')
spec[i] == '$'Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-5
1314 {-
1315 i++;-
1316 last = '$';-
1317 }
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
1318#if 0-
1319 else if (!spec[i] || spec[i] == ':')-
1320 /* check against `:' because there could be a modifier separator */-
1321#else-
1322 else-
1323 /* csh seems to allow anything to terminate the word spec here,-
1324 leaving it as an abbreviation. */-
1325#endif-
1326 last = -1; /* x- abbreviates x-$ omitting word `$' */
executed 1 time by 1 test: last = -1;
Executed by:
  • Self test
1
1327 }-
1328-
1329 *caller_index = i;-
1330-
1331 if (last >= first || last == '$' || last < 0)
last >= firstDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
last == '$'Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
last < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-15
1332 result = history_arg_extract (first, last, from);
executed 16 times by 1 test: result = history_arg_extract (first, last, from);
Executed by:
  • Self test
16
1333-
1334 return (result ? result : (char *)&error_pointer);
executed 16 times by 1 test: return (result ? result : (char *)&error_pointer);
Executed by:
  • Self test
16
1335}-
1336-
1337/* Extract the args specified, starting at FIRST, and ending at LAST.-
1338 The args are taken from STRING. If either FIRST or LAST is < 0,-
1339 then make that arg count from the right (subtract from the number of-
1340 tokens, so that FIRST = -1 means the next to last token on the line).-
1341 If LAST is `$' the last arg from STRING is used. */-
1342char *-
1343history_arg_extract (int first, int last, const char *string)-
1344{-
1345 register int i, len;-
1346 char *result;-
1347 int size, offset;-
1348 char **list;-
1349-
1350 /* XXX - think about making history_tokenize return a struct array,-
1351 each struct in array being a string and a length to avoid the-
1352 calls to strlen below. */-
1353 if ((list = history_tokenize (string)) == NULL)
(list = histor...== ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-26
1354 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
1355-
1356 for (len = 0; list[len]; len++)
list[len]Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-104
1357 ;
executed 104 times by 1 test: ;
Executed by:
  • Self test
104
1358-
1359 if (last < 0)
last < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 25 times by 1 test
Evaluated by:
  • Self test
1-25
1360 last = len + last - 1;
executed 1 time by 1 test: last = len + last - 1;
Executed by:
  • Self test
1
1361-
1362 if (first < 0)
first < 0Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-26
1363 first = len + first - 1;
never executed: first = len + first - 1;
0
1364-
1365 if (last == '$')
last == '$'Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test
10-16
1366 last = len - 1;
executed 16 times by 1 test: last = len - 1;
Executed by:
  • Self test
16
1367-
1368 if (first == '$')
first == '$'Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test
7-19
1369 first = len - 1;
executed 7 times by 1 test: first = len - 1;
Executed by:
  • Self test
7
1370-
1371 last++;-
1372-
1373 if (first >= len || last > len || first < 0 || last < 0 || first > last)
first >= lenDescription
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
last > lenDescription
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
first < 0Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
last < 0Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
first > lastDescription
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-26
1374 result = ((char *)NULL);
never executed: result = ((char *) ((void *)0) );
0
1375 else-
1376 {-
1377 for (size = 0, i = first; i < last; i++)
i < lastDescription
TRUEevaluated 51 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-51
1378 size += strlen (list[i]) + 1;
executed 51 times by 1 test: size += strlen (list[i]) + 1;
Executed by:
  • Self test
51
1379 result = (char *)xmalloc (size + 1);-
1380 result[0] = '\0';-
1381-
1382 for (i = first, offset = 0; i < last; i++)
i < lastDescription
TRUEevaluated 51 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-51
1383 {-
1384 strcpy (result + offset, list[i]);-
1385 offset += strlen (list[i]);-
1386 if (i + 1 < last)
i + 1 < lastDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
25-26
1387 {-
1388 result[offset++] = ' ';-
1389 result[offset] = 0;-
1390 }
executed 25 times by 1 test: end of block
Executed by:
  • Self test
25
1391 }
executed 51 times by 1 test: end of block
Executed by:
  • Self test
51
1392 }
executed 26 times by 1 test: end of block
Executed by:
  • Self test
26
1393-
1394 for (i = 0; i < len; i++)
i < lenDescription
TRUEevaluated 104 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
26-104
1395 xfree (list[i]);
executed 104 times by 1 test: xfree (list[i]);
Executed by:
  • Self test
104
1396 xfree (list);-
1397-
1398 return (result);
executed 26 times by 1 test: return (result);
Executed by:
  • Self test
26
1399}-
1400-
1401static int-
1402history_tokenize_word (const char *string, int ind)-
1403{-
1404 register int i, j;-
1405 int delimiter, nestdelim, delimopen;-
1406-
1407 i = ind;-
1408 delimiter = nestdelim = 0;-
1409-
1410 if (member (string[i], "()\n"))
((string[i]) ?...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEevaluated 132 times by 1 test
Evaluated by:
  • Self test
(string[i])Description
TRUEevaluated 132 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-132
1411 {-
1412 i++;-
1413 return i;
never executed: return i;
0
1414 }-
1415-
1416 if (ISDIGIT (string[i]))
((*__ctype_b_l...int) _ISdigit)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 130 times by 1 test
Evaluated by:
  • Self test
2-130
1417 {-
1418 j = i;-
1419 while (string[j] && ISDIGIT (string[j]))
string[j]Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((*__ctype_b_l...int) _ISdigit)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-4
1420 j++;
executed 2 times by 1 test: j++;
Executed by:
  • Self test
2
1421 if (string[j] == 0)
string[j] == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
1422 return (j);
never executed: return (j);
0
1423 if (string[j] == '<' || string[j] == '>')
string[j] == '<'Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
string[j] == '>'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
1424 i = j; /* digit sequence is a file descriptor */
executed 2 times by 1 test: i = j;
Executed by:
  • Self test
2
1425 else-
1426 {-
1427 i = j;-
1428 goto get_word; /* digit sequence is part of a word */
never executed: goto get_word;
0
1429 }-
1430 }-
1431-
1432 if (member (string[i], "<>;&|$"))
((string[i]) ?...id *)0) ) : 0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 127 times by 1 test
Evaluated by:
  • Self test
(string[i])Description
TRUEevaluated 132 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-132
1433 {-
1434 int peek = string[i + 1];-
1435-
1436 if (peek == string[i] && peek != '$')
peek == string[i]Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
peek != '$'Description
TRUEnever evaluated
FALSEnever evaluated
0-5
1437 {-
1438 if (peek == '<' && string[i + 2] == '-')
peek == '<'Description
TRUEnever evaluated
FALSEnever evaluated
string[i + 2] == '-'Description
TRUEnever evaluated
FALSEnever evaluated
0
1439 i++;
never executed: i++;
0
1440 else if (peek == '<' && string[i + 2] == '<')
peek == '<'Description
TRUEnever evaluated
FALSEnever evaluated
string[i + 2] == '<'Description
TRUEnever evaluated
FALSEnever evaluated
0
1441 i++;
never executed: i++;
0
1442 i += 2;-
1443 return i;
never executed: return i;
0
1444 }-
1445 else if (peek == '&' && (string[i] == '>' || string[i] == '<'))
peek == '&'Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
string[i] == '>'Description
TRUEnever evaluated
FALSEnever evaluated
string[i] == '<'Description
TRUEnever evaluated
FALSEnever evaluated
0-5
1446 {-
1447 j = i + 2;-
1448 while (string[j] && ISDIGIT (string[j])) /* file descriptor */
string[j]Description
TRUEnever evaluated
FALSEnever evaluated
((*__ctype_b_l...int) _ISdigit)Description
TRUEnever evaluated
FALSEnever evaluated
0
1449 j++;
never executed: j++;
0
1450 if (string[j] =='-') /* <&[digits]-, >&[digits]- */
string[j] =='-'Description
TRUEnever evaluated
FALSEnever evaluated
0
1451 j++;
never executed: j++;
0
1452 return j;
never executed: return j;
0
1453 }-
1454 else if ((peek == '>' && string[i] == '&') || (peek == '|' && string[i] == '>'))
peek == '>'Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
string[i] == '&'Description
TRUEnever evaluated
FALSEnever evaluated
peek == '|'Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
string[i] == '>'Description
TRUEnever evaluated
FALSEnever evaluated
0-5
1455 {-
1456 i += 2;-
1457 return i;
never executed: return i;
0
1458 }-
1459 /* XXX - separated out for later -- bash-4.2 */-
1460 else if ((peek == '(' && (string[i] == '>' || string[i] == '<')) || /* ) */
peek == '('Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
string[i] == '>'Description
TRUEnever evaluated
FALSEnever evaluated
string[i] == '<'Description
TRUEnever evaluated
FALSEnever evaluated
0-5
1461 (peek == '(' && string[i] == '$')) /*)*/
peek == '('Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
string[i] == '$'Description
TRUEnever evaluated
FALSEnever evaluated
0-5
1462 {-
1463 i += 2;-
1464 delimopen = '(';-
1465 delimiter = ')';-
1466 nestdelim = 1;-
1467 goto get_word;
never executed: goto get_word;
0
1468 }-
1469#if 0-
1470 else if (peek == '\'' && string[i] == '$')-
1471 {-
1472 i += 2; /* XXX */-
1473 return i;-
1474 }-
1475#endif-
1476-
1477 if (string[i] != '$')
string[i] != '$'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
2-3
1478 {-
1479 i++;-
1480 return i;
executed 2 times by 1 test: return i;
Executed by:
  • Self test
2
1481 }-
1482 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
1483-
1484 /* same code also used for $(...)/<(...)/>(...) above */-
1485 if (member (string[i], "!@?+*"))
((string[i]) ?...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEevaluated 130 times by 1 test
Evaluated by:
  • Self test
(string[i])Description
TRUEevaluated 130 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-130
1486 {-
1487 int peek = string[i + 1];-
1488-
1489 if (peek == '(') /*)*/
peek == '('Description
TRUEnever evaluated
FALSEnever evaluated
0
1490 {-
1491 /* Shell extended globbing patterns */-
1492 i += 2;-
1493 delimopen = '(';-
1494 delimiter = ')'; /* XXX - not perfect */-
1495 nestdelim = 1;-
1496 }
never executed: end of block
0
1497 }
never executed: end of block
0
1498-
1499get_word:
code before this statement executed 130 times by 1 test: get_word:
Executed by:
  • Self test
130
1500 /* Get word from string + i; */-
1501-
1502 if (delimiter == 0 && member (string[i], HISTORY_QUOTE_CHARACTERS))
(string[i])Description
TRUEevaluated 130 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
delimiter == 0Description
TRUEevaluated 130 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((string[i]) ?...id *)0) ) : 0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 125 times by 1 test
Evaluated by:
  • Self test
0-130
1503 delimiter = string[i++];
executed 5 times by 1 test: delimiter = string[i++];
Executed by:
  • Self test
5
1504-
1505 for (; string[i]; i++)
string[i]Description
TRUEevaluated 529 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31 times by 1 test
Evaluated by:
  • Self test
31-529
1506 {-
1507 if (string[i] == '\\' && string[i + 1] == '\n')
string[i] == '\\'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 527 times by 1 test
Evaluated by:
  • Self test
string[i + 1] == '\n'Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-527
1508 {-
1509 i++;-
1510 continue;
never executed: continue;
0
1511 }-
1512-
1513 if (string[i] == '\\' && delimiter != '\'' &&
string[i] == '\\'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 527 times by 1 test
Evaluated by:
  • Self test
delimiter != '\''Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-527
1514 (delimiter != '"' || member (string[i], slashify_in_quotes)))
(string[i])Description
TRUEnever evaluated
FALSEnever evaluated
delimiter != '"'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((string[i]) ?...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
0-2
1515 {-
1516 i++;-
1517 continue;
executed 2 times by 1 test: continue;
Executed by:
  • Self test
2
1518 }-
1519-
1520 /* delimiter must be set and set to something other than a quote if-
1521 nestdelim is set, so these tests are safe. */-
1522 if (nestdelim && string[i] == delimopen)
nestdelimDescription
TRUEnever evaluated
FALSEevaluated 527 times by 1 test
Evaluated by:
  • Self test
string[i] == delimopenDescription
TRUEnever evaluated
FALSEnever evaluated
0-527
1523 {-
1524 nestdelim++;-
1525 continue;
never executed: continue;
0
1526 }-
1527 if (nestdelim && string[i] == delimiter)
nestdelimDescription
TRUEnever evaluated
FALSEevaluated 527 times by 1 test
Evaluated by:
  • Self test
string[i] == delimiterDescription
TRUEnever evaluated
FALSEnever evaluated
0-527
1528 {-
1529 nestdelim--;-
1530 if (nestdelim == 0)
nestdelim == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1531 delimiter = 0;
never executed: delimiter = 0;
0
1532 continue;
never executed: continue;
0
1533 }-
1534 -
1535 if (delimiter && string[i] == delimiter)
delimiterDescription
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 473 times by 1 test
Evaluated by:
  • Self test
string[i] == delimiterDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 49 times by 1 test
Evaluated by:
  • Self test
5-473
1536 {-
1537 delimiter = 0;-
1538 continue;
executed 5 times by 1 test: continue;
Executed by:
  • Self test
5
1539 }-
1540-
1541 if (delimiter == 0 && (member (string[i], history_word_delimiters)))
(string[i])Description
TRUEevaluated 473 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
delimiter == 0Description
TRUEevaluated 473 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 49 times by 1 test
Evaluated by:
  • Self test
(((string[i]) ...d *)0) ) : 0))Description
TRUEevaluated 99 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 374 times by 1 test
Evaluated by:
  • Self test
0-473
1542 break;
executed 99 times by 1 test: break;
Executed by:
  • Self test
99
1543-
1544 if (delimiter == 0 && member (string[i], HISTORY_QUOTE_CHARACTERS))
(string[i])Description
TRUEevaluated 374 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
delimiter == 0Description
TRUEevaluated 374 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 49 times by 1 test
Evaluated by:
  • Self test
((string[i]) ?...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEevaluated 374 times by 1 test
Evaluated by:
  • Self test
0-374
1545 delimiter = string[i];
never executed: delimiter = string[i];
0
1546 }
executed 423 times by 1 test: end of block
Executed by:
  • Self test
423
1547-
1548 return i;
executed 130 times by 1 test: return i;
Executed by:
  • Self test
130
1549}-
1550-
1551static char *-
1552history_substring (const char *string, int start, int end)-
1553{-
1554 register int len;-
1555 register char *result;-
1556-
1557 len = end - start;-
1558 result = (char *)xmalloc (len + 1);-
1559 strncpy (result, string + start, len);-
1560 result[len] = '\0';-
1561 return result;
executed 132 times by 1 test: return result;
Executed by:
  • Self test
132
1562}-
1563-
1564/* Parse STRING into tokens and return an array of strings. If WIND is-
1565 not -1 and INDP is not null, we also want the word surrounding index-
1566 WIND. The position in the returned array of strings is returned in-
1567 *INDP. */-
1568static char **-
1569history_tokenize_internal (const char *string, int wind, int *indp)-
1570{-
1571 char **result;-
1572 register int i, start, result_index, size;-
1573-
1574 /* If we're searching for a string that's not part of a word (e.g., " "),-
1575 make sure we set *INDP to a reasonable value. */-
1576 if (indp && wind != -1)
indpDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
wind != -1Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-26
1577 *indp = -1;
executed 5 times by 1 test: *indp = -1;
Executed by:
  • Self test
5
1578-
1579 /* Get a token, and stuff it into RESULT. The tokens are split-
1580 exactly where the shell would split them. */-
1581 for (i = result_index = size = 0, result = (char **)NULL; string[i]; )
string[i]Description
TRUEevaluated 132 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 31 times by 1 test
Evaluated by:
  • Self test
31-132
1582 {-
1583 /* Skip leading whitespace. */-
1584 for (; string[i] && whitespace (string[i]); i++)
string[i]Description
TRUEevaluated 231 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((string[i]) == ' ')Description
TRUEevaluated 99 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 132 times by 1 test
Evaluated by:
  • Self test
((string[i]) == '\t')Description
TRUEnever evaluated
FALSEevaluated 132 times by 1 test
Evaluated by:
  • Self test
0-231
1585 ;
executed 99 times by 1 test: ;
Executed by:
  • Self test
99
1586 if (string[i] == 0 || string[i] == history_comment_char)
string[i] == 0Description
TRUEnever evaluated
FALSEevaluated 132 times by 1 test
Evaluated by:
  • Self test
string[i] == h...y_comment_charDescription
TRUEnever evaluated
FALSEevaluated 132 times by 1 test
Evaluated by:
  • Self test
0-132
1587 return (result);
never executed: return (result);
0
1588-
1589 start = i;-
1590-
1591 i = history_tokenize_word (string, start);-
1592-
1593 /* If we have a non-whitespace delimiter character (which would not be-
1594 skipped by the loop above), use it and any adjacent delimiters to-
1595 make a separate field. Any adjacent white space will be skipped the-
1596 next time through the loop. */-
1597 if (i == start && history_word_delimiters)
i == startDescription
TRUEnever evaluated
FALSEevaluated 132 times by 1 test
Evaluated by:
  • Self test
history_word_delimitersDescription
TRUEnever evaluated
FALSEnever evaluated
0-132
1598 {-
1599 i++;-
1600 while (string[i] && member (string[i], history_word_delimiters))
(string[i])Description
TRUEnever evaluated
FALSEnever evaluated
string[i]Description
TRUEnever evaluated
FALSEnever evaluated
((string[i]) ?...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
1601 i++;
never executed: i++;
0
1602 }
never executed: end of block
0
1603-
1604 /* If we are looking for the word in which the character at a-
1605 particular index falls, remember it. */-
1606 if (indp && wind != -1 && wind >= start && wind < i)
indpDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 104 times by 1 test
Evaluated by:
  • Self test
wind != -1Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
wind >= startDescription
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test
wind < iDescription
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
0-104
1607 *indp = result_index;
executed 5 times by 1 test: *indp = result_index;
Executed by:
  • Self test
5
1608-
1609 if (result_index + 2 >= size)
result_index + 2 >= sizeDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 101 times by 1 test
Evaluated by:
  • Self test
31-101
1610 result = (char **)xrealloc (result, ((size += 10) * sizeof (char *)));
executed 31 times by 1 test: result = (char **)xrealloc (result, ((size += 10) * sizeof (char *)));
Executed by:
  • Self test
31
1611-
1612 result[result_index++] = history_substring (string, start, i);-
1613 result[result_index] = (char *)NULL;-
1614 }
executed 132 times by 1 test: end of block
Executed by:
  • Self test
132
1615-
1616 return (result);
executed 31 times by 1 test: return (result);
Executed by:
  • Self test
31
1617}-
1618-
1619/* Return an array of tokens, much as the shell might. The tokens are-
1620 parsed out of STRING. */-
1621char **-
1622history_tokenize (const char *string)-
1623{-
1624 return (history_tokenize_internal (string, -1, (int *)NULL));
executed 26 times by 1 test: return (history_tokenize_internal (string, -1, (int *) ((void *)0) ));
Executed by:
  • Self test
26
1625}-
1626-
1627/* Free members of WORDS from START to an empty string */-
1628static void-
1629freewords (char **words, int start)-
1630{-
1631 register int i;-
1632-
1633 for (i = start; words[i]; i++)
words[i]Description
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-12
1634 xfree (words[i]);
executed 12 times by 1 test: xfree (words[i]);
Executed by:
  • Self test
12
1635}
executed 5 times by 1 test: end of block
Executed by:
  • Self test
5
1636-
1637/* Find and return the word which contains the character at index IND-
1638 in the history line LINE. Used to save the word matched by the-
1639 last history !?string? search. */-
1640static char *-
1641history_find_word (char *line, int ind)-
1642{-
1643 char **words, *s;-
1644 int i, wind;-
1645-
1646 words = history_tokenize_internal (line, ind, &wind);-
1647 if (wind == -1 || words == 0)
wind == -1Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
words == 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-5
1648 {-
1649 if (words)
wordsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1650 freewords (words, 0);
never executed: freewords (words, 0);
0
1651 FREE (words);
never executed: free (words);
wordsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1652 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
1653 }-
1654 s = words[wind];-
1655 for (i = 0; i < wind; i++)
i < windDescription
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
5-11
1656 xfree (words[i]);
executed 11 times by 1 test: xfree (words[i]);
Executed by:
  • Self test
11
1657 freewords (words, wind + 1);-
1658 xfree (words);-
1659 return s;
executed 5 times by 1 test: return s;
Executed by:
  • Self test
5
1660}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2