OpenCoverage

history.def

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/builtins/history.def
Source codeSwitch to Preprocessed file
LineSourceCount
1This file is history.def, from which is created history.c.-
2It implements the builtin "history" in Bash.-
3-
4Copyright (C) 1987-2018 Free Software Foundation, Inc.-
5-
6This file is part of GNU Bash, the Bourne Again SHell.-
7-
8Bash is free software: you can redistribute it and/or modify-
9it under the terms of the GNU General Public License as published by-
10the Free Software Foundation, either version 3 of the License, or-
11(at your option) any later version.-
12-
13Bash is distributed in the hope that it will be useful,-
14but WITHOUT ANY WARRANTY; without even the implied warranty of-
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
16GNU General Public License for more details.-
17-
18You should have received a copy of the GNU General Public License-
19along with Bash. If not, see <http://www.gnu.org/licenses/>.-
20-
21$PRODUCES history.c-
22-
23$BUILTIN history-
24$FUNCTION history_builtin-
25$DEPENDS_ON HISTORY-
26$SHORT_DOC history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]-
27Display or manipulate the history list.-
28-
29Display the history list with line numbers, prefixing each modified-
30entry with a `*'. An argument of N lists only the last N entries.-
31-
32Options:-
33 -c clear the history list by deleting all of the entries-
34 -d offset delete the history entry at position OFFSET. Negative-
35 offsets count back from the end of the history list-
36-
37 -a append history lines from this session to the history file-
38 -n read all history lines not already read from the history file-
39 and append them to the history list-
40 -r read the history file and append the contents to the history-
41 list-
42 -w write the current history to the history file-
43-
44 -p perform history expansion on each ARG and display the result-
45 without storing it in the history list-
46 -s append the ARGs to the history list as a single entry-
47-
48If FILENAME is given, it is used as the history file. Otherwise,-
49if HISTFILE has a value, that is used, else ~/.bash_history.-
50-
51If the HISTTIMEFORMAT variable is set and not null, its value is used-
52as a format string for strftime(3) to print the time stamp associated-
53with each displayed history entry. No time stamps are printed otherwise.-
54-
55Exit Status:-
56Returns success unless an invalid option is given or an error occurs.-
57$END-
58-
59#include <config.h>-
60-
61#if defined (HISTORY)-
62#include "../bashtypes.h"-
63#if ! defined(_MINIX) && defined (HAVE_SYS_FILE_H)-
64# include <sys/file.h>-
65#endif-
66#include "posixstat.h"-
67#include "filecntl.h"-
68#include <errno.h>-
69#include <stdio.h>-
70#if defined (HAVE_UNISTD_H)-
71# include <unistd.h>-
72#endif-
73-
74#include "../bashansi.h"-
75#include "../bashintl.h"-
76-
77#include "../shell.h"-
78#include "../parser.h"-
79#include "../bashhist.h"-
80#include <readline/history.h>-
81#include "bashgetopt.h"-
82#include "common.h"-
83-
84#if !defined (errno)-
85extern int errno;-
86#endif-
87-
88static char *histtime __P((HIST_ENTRY *, const char *));-
89static int display_history __P((WORD_LIST *));-
90static void push_history __P((WORD_LIST *));-
91static int expand_and_print_history __P((WORD_LIST *));-
92-
93#define AFLAG 0x01-
94#define RFLAG 0x02-
95#define WFLAG 0x04-
96#define NFLAG 0x08-
97#define SFLAG 0x10-
98#define PFLAG 0x20-
99#define CFLAG 0x40-
100#define DFLAG 0x80-
101-
102int-
103history_builtin (list)-
104 WORD_LIST *list;-
105{-
106 int flags, opt, result, old_history_lines, obase, ind;-
107 char *filename, *delete_arg, *range;-
108 intmax_t delete_offset;-
109-
110 flags = 0;-
111 reset_internal_getopt ();-
112 while ((opt = internal_getopt (list, "acd:npsrw")) != -1)
(opt = interna...npsrw")) != -1Description
TRUEevaluated 32 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 45 times by 1 test
Evaluated by:
  • Self test
32-45
113 {-
114 switch (opt)-
115 {-
116 case 'a':
executed 2 times by 1 test: case 'a':
Executed by:
  • Self test
2
117 flags |= AFLAG;-
118 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
119 case 'c':
executed 6 times by 1 test: case 'c':
Executed by:
  • Self test
6
120 flags |= CFLAG;-
121 break;
executed 6 times by 1 test: break;
Executed by:
  • Self test
6
122 case 'n':
executed 1 time by 1 test: case 'n':
Executed by:
  • Self test
1
123 flags |= NFLAG;-
124 break;
executed 1 time by 1 test: break;
Executed by:
  • Self test
1
125 case 'r':
executed 2 times by 1 test: case 'r':
Executed by:
  • Self test
2
126 flags |= RFLAG;-
127 break;
executed 2 times by 1 test: break;
Executed by:
  • Self test
2
128 case 'w':
executed 3 times by 1 test: case 'w':
Executed by:
  • Self test
3
129 flags |= WFLAG;-
130 break;
executed 3 times by 1 test: break;
Executed by:
  • Self test
3
131 case 's':
executed 3 times by 1 test: case 's':
Executed by:
  • Self test
3
132 flags |= SFLAG;-
133 break;
executed 3 times by 1 test: break;
Executed by:
  • Self test
3
134 case 'd':
executed 7 times by 1 test: case 'd':
Executed by:
  • Self test
7
135 flags |= DFLAG;-
136 delete_arg = list_optarg;-
137 break;
executed 7 times by 1 test: break;
Executed by:
  • Self test
7
138 case 'p':
executed 7 times by 1 test: case 'p':
Executed by:
  • Self test
7
139#if defined (BANG_HISTORY)-
140 flags |= PFLAG;-
141#endif-
142 break;
executed 7 times by 1 test: break;
Executed by:
  • Self test
7
143 CASE_HELPOPT;
never executed: return (258);
never executed: case -99:
0
144 default:
executed 1 time by 1 test: default:
Executed by:
  • Self test
1
145 builtin_usage ();-
146 return (EX_USAGE);
executed 1 time by 1 test: return (258);
Executed by:
  • Self test
1
147 }-
148 }-
149 list = loptend;-
150-
151 opt = flags & (AFLAG|RFLAG|WFLAG|NFLAG);-
152 if (opt && opt != AFLAG && opt != RFLAG && opt != WFLAG && opt != NFLAG)
optDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
opt != 0x01Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
opt != 0x02Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
opt != 0x04Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
opt != 0x08Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1-38
153 {-
154 builtin_error (_("cannot use more than one of -anrw"));-
155 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
156 }-
157-
158 /* clear the history, but allow other arguments to add to it again. */-
159 if (flags & CFLAG)
flags & 0x40Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test
6-38
160 {-
161 bash_clear_history ();-
162 if (list == 0)
list == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
163 return (EXECUTION_SUCCESS);
executed 6 times by 1 test: return (0);
Executed by:
  • Self test
6
164 }
never executed: end of block
0
165-
166 if (flags & SFLAG)
flags & 0x10Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test
3-35
167 {-
168 if (list)
listDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
169 push_history (list);
executed 3 times by 1 test: push_history (list);
Executed by:
  • Self test
3
170 return (EXECUTION_SUCCESS);
executed 3 times by 1 test: return (0);
Executed by:
  • Self test
3
171 }-
172#if defined (BANG_HISTORY)-
173 else if (flags & PFLAG)
flags & 0x20Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test
7-28
174 {-
175 if (list)
listDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7
176 return (expand_and_print_history (list));
executed 7 times by 1 test: return (expand_and_print_history (list));
Executed by:
  • Self test
7
177 return (sh_chkwrite (EXECUTION_SUCCESS));
never executed: return (sh_chkwrite (0));
0
178 }-
179#endif-
180 else if ((flags & DFLAG) && (range = strchr ((delete_arg[0] == '-') ? delete_arg + 1 : delete_arg, '-')))
(flags & 0x80)Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
(range = (__ex...rg , '-' ))) )Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
__builtin_constant_p ( '-' )Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
!__builtin_con...: delete_arg )Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
( '-' ) == '\0'Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
0-21
181 {-
182 intmax_t delete_start, delete_end;-
183 *range++ = '\0';-
184 if (legal_number (delete_arg, &delete_start) == 0 || legal_number (range, &delete_end) == 0)
legal_number (...te_start) == 0Description
TRUEnever evaluated
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
legal_number (...lete_end) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
0-7
185 {-
186 range[-1] = '-';-
187 sh_erange (delete_arg, _("history position"));-
188 return (EXECUTION_FAILURE);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
189 }-
190 if (delete_arg[0] == '-' && delete_start < 0)
delete_arg[0] == '-'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
delete_start < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
191 {-
192 /* the_history[history_length] == 0x0, so this is correct */-
193 delete_start += history_length;-
194 if (delete_start < history_base)
delete_start < history_baseDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
195 {-
196start_error:-
197 sh_erange (delete_arg, _("history position"));-
198 return (EXECUTION_FAILURE);
executed 2 times by 1 test: return (1);
Executed by:
  • Self test
2
199 }-
200 }
never executed: end of block
0
201 /* numbers as displayed by display_history are offset by history_base */-
202 else if (delete_start > 0)
delete_start > 0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
203 delete_start -= history_base;
executed 5 times by 1 test: delete_start -= history_base;
Executed by:
  • Self test
5
204 if (delete_start < 0 || delete_start >= history_length)
delete_start < 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
delete_start >= history_lengthDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
0-5
205 goto start_error;
executed 1 time by 1 test: goto start_error;
Executed by:
  • Self test
1
206 if (range[0] == '-' && delete_end < 0)
range[0] == '-'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
delete_end < 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
207 {-
208 delete_end += history_length;-
209 if (delete_end < history_base)
delete_end < history_baseDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1
210 {-
211range_error:-
212 sh_erange (range, _("history position"));-
213 return (EXECUTION_FAILURE);
executed 2 times by 1 test: return (1);
Executed by:
  • Self test
2
214 }-
215 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
216 else if (delete_end > 0)
delete_end > 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
217 delete_end -= history_base;
executed 2 times by 1 test: delete_end -= history_base;
Executed by:
  • Self test
2
218 if (delete_end < 0 || delete_end >= history_length)
delete_end < 0Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
delete_end >= history_lengthDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-3
219 goto range_error;
executed 1 time by 1 test: goto range_error;
Executed by:
  • Self test
1
220 result = bash_delete_history_range (delete_start, delete_end);-
221 if (where_history () > history_length)
where_history ...history_lengthDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
222 history_set_pos (history_length);
executed 2 times by 1 test: history_set_pos (history_length);
Executed by:
  • Self test
2
223 return (result ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
executed 2 times by 1 test: return (result ? 0 : 1);
Executed by:
  • Self test
2
224 }-
225 else if (flags & DFLAG)
flags & 0x80Description
TRUEnever evaluated
FALSEevaluated 21 times by 1 test
Evaluated by:
  • Self test
0-21
226 {-
227 if (legal_number (delete_arg, &delete_offset) == 0)
legal_number (...e_offset) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
228 {-
229 sh_erange (delete_arg, _("history position"));-
230 return (EXECUTION_FAILURE);
never executed: return (1);
0
231 }-
232 /* check for negative offsets, count back from end of list */-
233 if (delete_arg[0] == '-' && delete_offset < 0)
delete_arg[0] == '-'Description
TRUEnever evaluated
FALSEnever evaluated
delete_offset < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
234 {-
235 /* since the_history[history_length] == 0x0, this calculation means-
236 that history -d -1 will delete the last history entry, which at-
237 this point is the history -d -1 we just added. */-
238 ind = history_length + delete_offset;-
239 if (ind < history_base)
ind < history_baseDescription
TRUEnever evaluated
FALSEnever evaluated
0
240 {-
241 sh_erange (delete_arg, _("history position"));-
242 return (EXECUTION_FAILURE);
never executed: return (1);
0
243 }-
244 opt = ind + history_base; /* compensate for opt - history_base below */-
245 }
never executed: end of block
0
246 else if ((delete_offset < history_base) || (delete_offset > (history_base + history_length)))
(delete_offset < history_base)Description
TRUEnever evaluated
FALSEnever evaluated
(delete_offset...story_length))Description
TRUEnever evaluated
FALSEnever evaluated
0
247 {-
248 sh_erange (delete_arg, _("history position"));-
249 return (EXECUTION_FAILURE);
never executed: return (1);
0
250 }-
251 else-
252 opt = delete_offset;
never executed: opt = delete_offset;
0
253-
254 /* Positive arguments from numbers as displayed by display_history need-
255 to be offset by history_base */-
256 result = bash_delete_histent (opt - history_base);-
257 /* Since remove_history changes history_length, this can happen if-
258 we delete the last history entry. */-
259 if (where_history () > history_length)
where_history ...history_lengthDescription
TRUEnever evaluated
FALSEnever evaluated
0
260 history_set_pos (history_length);
never executed: history_set_pos (history_length);
0
261 return (result ? EXECUTION_SUCCESS : EXECUTION_FAILURE);
never executed: return (result ? 0 : 1);
0
262 }-
263 else if ((flags & (AFLAG|RFLAG|NFLAG|WFLAG|CFLAG)) == 0)
(flags & (0x01...04|0x40)) == 0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
6-15
264 {-
265 result = display_history (list);-
266 return (sh_chkwrite (result));
executed 15 times by 1 test: return (sh_chkwrite (result));
Executed by:
  • Self test
15
267 }-
268-
269 filename = list ? list->word->word : get_string_value ("HISTFILE");
listDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
2-4
270 result = EXECUTION_SUCCESS;-
271-
272 if (flags & AFLAG) /* Append session's history to file. */
flags & 0x01Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
2-4
273 result = maybe_append_history (filename);
executed 2 times by 1 test: result = maybe_append_history (filename);
Executed by:
  • Self test
2
274 else if (flags & WFLAG) /* Write entire history. */
flags & 0x04Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
2
275 result = write_history (filename);
executed 2 times by 1 test: result = write_history (filename);
Executed by:
  • Self test
2
276 else if (flags & RFLAG) /* Read entire file. */
flags & 0x02Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
1
277 {-
278 result = read_history (filename);-
279 history_lines_in_file = history_lines_read_from_file;-
280 /* history_lines_in_file = where_history () + history_base - 1; */-
281 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
282 else if (flags & NFLAG) /* Read `new' history from file. */
flags & 0x08Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
283 {-
284 /* Read all of the lines in the file that we haven't already read. */-
285 old_history_lines = history_lines_in_file;-
286 obase = history_base;-
287-
288 using_history ();-
289 result = read_history_range (filename, history_lines_in_file, -1);-
290 using_history ();-
291-
292 history_lines_in_file = history_lines_read_from_file;-
293 /* history_lines_in_file = where_history () + history_base - 1; */-
294-
295 /* If we're rewriting the history file at shell exit rather than just-
296 appending the lines from this session to it, the question is whether-
297 we reset history_lines_this_session to 0, losing any history entries-
298 we had before we read the new entries from the history file, or-
299 whether we count the new entries we just read from the file as-
300 history lines added during this session.-
301 Right now, we do the latter. This will cause these history entries-
302 to be written to the history file along with any intermediate entries-
303 we add when we do a `history -a', but the alternative is losing-
304 them altogether. */-
305 if (force_append_history == 0)
force_append_history == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
306 history_lines_this_session += history_lines_in_file - old_history_lines +
executed 1 time by 1 test: history_lines_this_session += history_lines_in_file - old_history_lines + history_base - obase;
Executed by:
  • Self test
1
307 history_base - obase;
executed 1 time by 1 test: history_lines_this_session += history_lines_in_file - old_history_lines + history_base - obase;
Executed by:
  • Self test
1
308 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
309-
310 return (result ? EXECUTION_FAILURE : EXECUTION_SUCCESS);
executed 6 times by 1 test: return (result ? 1 : 0);
Executed by:
  • Self test
6
311}-
312-
313/* Accessors for HIST_ENTRY lists that are called HLIST. */-
314#define histline(i) (hlist[(i)]->line)-
315#define histdata(i) (hlist[(i)]->data)-
316-
317static char *-
318histtime (hlist, histtimefmt)-
319 HIST_ENTRY *hlist;-
320 const char *histtimefmt;-
321{-
322 static char timestr[128];-
323 time_t t;-
324 struct tm *tm;-
325-
326 t = history_get_time (hlist);-
327 tm = t ? localtime (&t) : 0;
tDescription
TRUEnever evaluated
FALSEnever evaluated
0
328 if (t && tm)
tDescription
TRUEnever evaluated
FALSEnever evaluated
tmDescription
TRUEnever evaluated
FALSEnever evaluated
0
329 strftime (timestr, sizeof (timestr), histtimefmt, tm);
never executed: strftime (timestr, sizeof (timestr), histtimefmt, tm);
0
330 else if (hlist->timestamp && hlist->timestamp[0])
hlist->timestampDescription
TRUEnever evaluated
FALSEnever evaluated
hlist->timestamp[0]Description
TRUEnever evaluated
FALSEnever evaluated
0
331 snprintf (timestr, sizeof (timestr), _("%s: invalid timestamp"),
never executed: snprintf (timestr, sizeof (timestr), dcgettext (((void *)0), "%s: invalid timestamp" , 5) , (hlist->timestamp[0] == '#') ? hlist->timestamp + 1: hlist->timestamp);
0
332 (hlist->timestamp[0] == '#') ? hlist->timestamp + 1: hlist->timestamp);
never executed: snprintf (timestr, sizeof (timestr), dcgettext (((void *)0), "%s: invalid timestamp" , 5) , (hlist->timestamp[0] == '#') ? hlist->timestamp + 1: hlist->timestamp);
0
333 else-
334 strcpy (timestr, "??");
never executed: strcpy (timestr, "??");
0
335 return timestr;
never executed: return timestr;
0
336}-
337-
338static int-
339display_history (list)-
340 WORD_LIST *list;-
341{-
342 register int i;-
343 intmax_t limit;-
344 HIST_ENTRY **hlist;-
345 char *histtimefmt, *timestr;-
346-
347 if (list)
listDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
1-14
348 {-
349 if (get_numeric_arg (list, 0, &limit) == 0)
get_numeric_ar..., &limit) == 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
350 return (EXECUTION_FAILURE);
never executed: return (1);
0
351-
352 if (limit < 0)
limit < 0Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
0-1
353 limit = -limit;
never executed: limit = -limit;
0
354 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
355 else-
356 limit = -1;
executed 14 times by 1 test: limit = -1;
Executed by:
  • Self test
14
357-
358 hlist = history_list ();-
359-
360 if (hlist)
hlistDescription
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-15
361 {-
362 for (i = 0; hlist[i]; i++)
hlist[i]Description
TRUEevaluated 135 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
15-135
363 ;
executed 135 times by 1 test: ;
Executed by:
  • Self test
135
364-
365 if (0 <= limit && limit < i)
0 <= limitDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test
limit < iDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-14
366 i -= limit;
executed 1 time by 1 test: i -= limit;
Executed by:
  • Self test
1
367 else-
368 i = 0;
executed 14 times by 1 test: i = 0;
Executed by:
  • Self test
14
369-
370 histtimefmt = get_string_value ("HISTTIMEFORMAT");-
371-
372 while (hlist[i])
hlist[i]Description
TRUEevaluated 122 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
15-122
373 {-
374 QUIT;
never executed: termsig_handler (terminating_signal);
never executed: throw_to_top_level ();
terminating_signalDescription
TRUEnever evaluated
FALSEevaluated 122 times by 1 test
Evaluated by:
  • Self test
interrupt_stateDescription
TRUEnever evaluated
FALSEevaluated 122 times by 1 test
Evaluated by:
  • Self test
0-122
375-
376 timestr = (histtimefmt && *histtimefmt) ? histtime (hlist[i], histtimefmt) : (char *)NULL;
histtimefmtDescription
TRUEnever evaluated
FALSEevaluated 122 times by 1 test
Evaluated by:
  • Self test
*histtimefmtDescription
TRUEnever evaluated
FALSEnever evaluated
0-122
377 printf ("%5d%c %s%s\n", i + history_base,-
378 histdata(i) ? '*' : ' ',-
379 ((timestr && *timestr) ? timestr : ""),-
380 histline(i));-
381 i++;-
382 }
executed 122 times by 1 test: end of block
Executed by:
  • Self test
122
383 }
executed 15 times by 1 test: end of block
Executed by:
  • Self test
15
384-
385 return (EXECUTION_SUCCESS);
executed 15 times by 1 test: return (0);
Executed by:
  • Self test
15
386}-
387-
388/* Remove the last entry in the history list and add each argument in-
389 LIST to the history. */-
390static void-
391push_history (list)-
392 WORD_LIST *list;-
393{-
394 char *s;-
395-
396 /* Delete the last history entry if it was a single entry added to the-
397 history list (generally the `history -s' itself), or if `history -s'-
398 is being used in a compound command and the compound command was-
399 added to the history as a single element (command-oriented history).-
400 If you don't want history -s to remove the compound command from the-
401 history, change #if 0 to #if 1 below. */-
402#if 0-
403 if (remember_on_history && hist_last_line_pushed == 0 &&-
404 hist_last_line_added && bash_delete_last_history () == 0)-
405#else-
406 if (remember_on_history && hist_last_line_pushed == 0 &&
remember_on_historyDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
hist_last_line_pushed == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
407 (hist_last_line_added ||
hist_last_line_addedDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
408 (current_command_line_count > 0 && current_command_first_line_saved && command_oriented_history))
current_command_line_count > 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
current_comman...rst_line_savedDescription
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
command_oriented_historyDescription
TRUEnever evaluated
FALSEnever evaluated
0-3
409 && bash_delete_last_history () == 0)
bash_delete_la...istory () == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
410#endif-
411 return;
never executed: return;
0
412-
413 s = string_list (list);-
414 /* Call check_add_history with FORCE set to 1 to skip the check against-
415 current_command_line_count. If history -s is used in a compound-
416 command, the above code will delete the compound command's history-
417 entry and this call will add the line to the history as a separate-
418 entry. Without FORCE=1, if current_command_line_count were > 1, the-
419 line would be appended to the entry before the just-deleted entry. */-
420 check_add_history (s, 1); /* obeys HISTCONTROL, HISTIGNORE */-
421-
422 hist_last_line_pushed = 1; /* XXX */-
423 free (s);-
424}
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
425-
426#if defined (BANG_HISTORY)-
427static int-
428expand_and_print_history (list)-
429 WORD_LIST *list;-
430{-
431 char *s;-
432 int r, result;-
433-
434 if (hist_last_line_pushed == 0 && hist_last_line_added && bash_delete_last_history () == 0)
hist_last_line_pushed == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
hist_last_line_addedDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
bash_delete_la...istory () == 0Description
TRUEnever evaluated
FALSEnever evaluated
0-5
435 return EXECUTION_FAILURE;
never executed: return 1;
0
436 result = EXECUTION_SUCCESS;-
437 while (list)
listDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test
7
438 {-
439 r = history_expand (list->word->word, &s);-
440 if (r < 0)
r < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
1-6
441 {-
442 builtin_error (_("%s: history expansion failed"), list->word->word);-
443 result = EXECUTION_FAILURE;-
444 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
445 else-
446 {-
447 fputs (s, stdout);-
448 putchar ('\n');-
449 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
450 FREE (s);
executed 7 times by 1 test: sh_xfree((s), "./history.def", 450);
Executed by:
  • Self test
sDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-7
451 list = list->next;-
452 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test
7
453 fflush (stdout);-
454 return result;
executed 7 times by 1 test: return result;
Executed by:
  • Self test
7
455}-
456#endif /* BANG_HISTORY */-
457#endif /* HISTORY */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2