OpenCoverage

bashhist.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/bash/src/bashhist.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/* bashhist.c -- bash interface to the GNU history library. */-
2-
3/* Copyright (C) 1993-2015 Free Software Foundation, Inc.-
4-
5 This file is part of GNU Bash, the Bourne Again SHell.-
6-
7 Bash is free software: you can redistribute it and/or modify-
8 it under the terms of the GNU General Public License as published by-
9 the Free Software Foundation, either version 3 of the License, or-
10 (at your option) any later version.-
11-
12 Bash is distributed in the hope that it will be useful,-
13 but WITHOUT ANY WARRANTY; without even the implied warranty of-
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the-
15 GNU General Public License for more details.-
16-
17 You should have received a copy of the GNU General Public License-
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.-
19*/-
20-
21#include "config.h"-
22-
23#if defined (HISTORY)-
24-
25#if defined (HAVE_UNISTD_H)-
26# ifdef _MINIX-
27 # include <sys/types.h>-
28# endif-
29# include <unistd.h>-
30#endif-
31-
32#include "bashtypes.h"-
33#include <stdio.h>-
34#include <errno.h>-
35#include "bashansi.h"-
36#include "posixstat.h"-
37#include "filecntl.h"-
38-
39#include "bashintl.h"-
40-
41#if defined (SYSLOG_HISTORY)-
42# include <syslog.h>-
43#endif-
44-
45#include "shell.h"-
46#include "flags.h"-
47#include "parser.h"-
48#include "input.h"-
49#include "parser.h" /* for the struct dstack stuff. */-
50#include "pathexp.h" /* for the struct ignorevar stuff */-
51#include "bashhist.h" /* matching prototypes and declarations */-
52#include "builtins/common.h"-
53-
54#include <readline/history.h>-
55#include <glob/glob.h>-
56#include <glob/strmatch.h>-
57-
58#if defined (READLINE)-
59# include "bashline.h"-
60extern int rl_done, rl_dispatching; /* should really include readline.h */-
61#endif-
62-
63#if !defined (errno)-
64extern int errno;-
65#endif-
66-
67static int histignore_item_func __P((struct ign *));-
68static int check_history_control __P((char *));-
69static void hc_erasedups __P((char *));-
70static void really_add_history __P((char *));-
71-
72static struct ignorevar histignore =-
73{-
74 "HISTIGNORE",-
75 (struct ign *)0,-
76 0,-
77 (char *)0,-
78 (sh_iv_item_func_t *)histignore_item_func,-
79};-
80-
81#define HIGN_EXPAND 0x01-
82-
83/* Declarations of bash history variables. */-
84/* Non-zero means to remember lines typed to the shell on the history-
85 list. This is different than the user-controlled behaviour; this-
86 becomes zero when we read lines from a file, for example. */-
87int remember_on_history = 0;-
88int enable_history_list = 0; /* value for `set -o history' */-
89-
90/* The number of lines that Bash has added to this history session. The-
91 difference between the number of the top element in the history list-
92 (offset from history_base) and the number of lines in the history file.-
93 Appending this session's history to the history file resets this to 0. */-
94int history_lines_this_session;-
95-
96/* The number of lines that Bash has read from the history file. */-
97int history_lines_in_file;-
98-
99#if defined (BANG_HISTORY)-
100/* Non-zero means do no history expansion on this line, regardless-
101 of what history_expansion says. */-
102int history_expansion_inhibited;-
103/* If non-zero, double quotes can quote the history expansion character. */-
104int double_quotes_inhibit_history_expansion = 0;-
105#endif-
106-
107/* With the old default, every line was saved in the history individually.-
108 I.e., if the user enters:-
109 bash$ for i in a b c-
110 > do-
111 > echo $i-
112 > done-
113 Each line will be individually saved in the history.-
114 bash$ history-
115 10 for i in a b c-
116 11 do-
117 12 echo $i-
118 13 done-
119 14 history-
120 If the variable command_oriented_history is set, multiple lines-
121 which form one command will be saved as one history entry.-
122 bash$ for i in a b c-
123 > do-
124 > echo $i-
125 > done-
126 bash$ history-
127 10 for i in a b c-
128 do-
129 echo $i-
130 done-
131 11 history-
132 The user can then recall the whole command all at once instead-
133 of just being able to recall one line at a time.-
134-
135 This is now enabled by default.-
136 */-
137int command_oriented_history = 1;-
138-
139/* Set to 1 if the first line of a possibly-multi-line command was saved-
140 in the history list. Managed by maybe_add_history(), but global so-
141 the history-manipluating builtins can see it. */-
142int current_command_first_line_saved = 0;-
143-
144/* Set to the number of the most recent line of a possibly-multi-line command-
145 that contains a shell comment. Used by bash_add_history() to determine-
146 whether to add a newline or a semicolon. */-
147int current_command_line_comment = 0;-
148-
149/* Non-zero means to store newlines in the history list when using-
150 command_oriented_history rather than trying to use semicolons. */-
151int literal_history;-
152-
153/* Non-zero means to append the history to the history file at shell-
154 exit, even if the history has been stifled. */-
155int force_append_history;-
156-
157/* A nit for picking at history saving. Flags have the following values:-
158-
159 Value == 0 means save all lines parsed by the shell on the history.-
160 Value & HC_IGNSPACE means save all lines that do not start with a space.-
161 Value & HC_IGNDUPS means save all lines that do not match the last-
162 line saved.-
163 Value & HC_ERASEDUPS means to remove all other matching lines from the-
164 history list before saving the latest line. */-
165int history_control;-
166-
167/* Set to 1 if the last command was added to the history list successfully-
168 as a separate history entry; set to 0 if the line was ignored or added-
169 to a previous entry as part of command-oriented-history processing. */-
170int hist_last_line_added;-
171-
172/* Set to 1 if builtins/history.def:push_history added the last history-
173 entry. */-
174int hist_last_line_pushed;-
175-
176#if defined (READLINE)-
177/* If non-zero, and readline is being used, the user is offered the-
178 chance to re-edit a failed history expansion. */-
179int history_reediting;-
180-
181/* If non-zero, and readline is being used, don't directly execute a-
182 line with history substitution. Reload it into the editing buffer-
183 instead and let the user further edit and confirm with a newline. */-
184int hist_verify;-
185-
186#endif /* READLINE */-
187-
188/* Non-zero means to not save function definitions in the history list. */-
189int dont_save_function_defs;-
190-
191#if defined (BANG_HISTORY)-
192static int bash_history_inhibit_expansion __P((char *, int));-
193#endif-
194#if defined (READLINE)-
195static void re_edit __P((char *));-
196#endif-
197static int history_expansion_p __P((char *));-
198static int shell_comment __P((char *));-
199static int should_expand __P((char *));-
200static HIST_ENTRY *last_history_entry __P((void));-
201static char *expand_histignore_pattern __P((char *));-
202static int history_should_ignore __P((char *));-
203-
204#if defined (BANG_HISTORY)-
205/* Is the history expansion starting at string[i] one that should not-
206 be expanded? */-
207static int-
208bash_history_inhibit_expansion (string, i)-
209 char *string;-
210 int i;-
211{-
212 int t;-
213 char hx[2];-
214-
215 hx[0] = history_expansion_char;-
216 hx[1] = '\0';-
217-
218 /* The shell uses ! as a pattern negation character in globbing [...]-
219 expressions, so let those pass without expansion. */-
220 if (i > 0 && (string[i - 1] == '[') && member (']', string + i + 1))
(']')Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
i > 0Description
TRUEevaluated 218 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
(string[i - 1] == '[')Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 217 times by 1 test
Evaluated by:
  • Self test
((']') ? ((cha...id *)0) ) : 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-218
221 return (1);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
222 /* The shell uses ! as the indirect expansion character, so let those-
223 expansions pass as well. */-
224 else if (i > 1 && string[i - 1] == '{' && string[i - 2] == '$' &&
i > 1Description
TRUEevaluated 217 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
string[i - 1] == '{'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 216 times by 1 test
Evaluated by:
  • Self test
string[i - 2] == '$'Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-217
225 member ('}', string + i + 1))
('}')Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(('}') ? ((cha...id *)0) ) : 0)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
226 return (1);
executed 1 time by 1 test: return (1);
Executed by:
  • Self test
1
227 /* The shell uses $! as a defined parameter expansion. */-
228 else if (i > 1 && string[i - 1] == '$' && string[i] == '!')
i > 1Description
TRUEevaluated 216 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 47 times by 1 test
Evaluated by:
  • Self test
string[i - 1] == '$'Description
TRUEnever evaluated
FALSEevaluated 216 times by 1 test
Evaluated by:
  • Self test
string[i] == '!'Description
TRUEnever evaluated
FALSEnever evaluated
0-216
229 return (1);
never executed: return (1);
0
230#if defined (EXTENDED_GLOB)-
231 else if (extended_glob && i > 1 && string[i+1] == '(' && member (')', string + i + 2))
(')')Description
TRUEnever evaluated
FALSEnever evaluated
extended_globDescription
TRUEnever evaluated
FALSEevaluated 263 times by 1 test
Evaluated by:
  • Self test
i > 1Description
TRUEnever evaluated
FALSEnever evaluated
string[i+1] == '('Description
TRUEnever evaluated
FALSEnever evaluated
((')') ? ((cha...id *)0) ) : 0)Description
TRUEnever evaluated
FALSEnever evaluated
0-263
232 return (1);
never executed: return (1);
0
233#endif-
234-
235 /* Make sure the history expansion should not be skipped by quoting or-
236 command/process substitution. */-
237 else if ((t = skip_to_histexp (string, 0, hx, SD_NOJMP|SD_HISTEXP)) > 0)
(t = skip_to_h...01|0x200)) > 0Description
TRUEevaluated 215 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test
48-215
238 {-
239 /* Skip instances of history expansion appearing on the line before-
240 this one. */-
241 while (t < i)
t < iDescription
TRUEevaluated 58 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 215 times by 1 test
Evaluated by:
  • Self test
58-215
242 {-
243 t = skip_to_histexp (string, t+1, hx, SD_NOJMP|SD_HISTEXP);-
244 if (t <= 0)
t <= 0Description
TRUEnever evaluated
FALSEevaluated 58 times by 1 test
Evaluated by:
  • Self test
0-58
245 return 0;
never executed: return 0;
0
246 }
executed 58 times by 1 test: end of block
Executed by:
  • Self test
58
247 return (t > i);
executed 215 times by 1 test: return (t > i);
Executed by:
  • Self test
215
248 }-
249 else-
250 return (0);
executed 48 times by 1 test: return (0);
Executed by:
  • Self test
48
251}-
252#endif-
253-
254void-
255bash_initialize_history ()-
256{-
257 history_quotes_inhibit_expansion = 1;-
258 history_search_delimiter_chars = ";&()|<>";-
259#if defined (BANG_HISTORY)-
260 history_inhibit_expansion_function = bash_history_inhibit_expansion;-
261 sv_histchars ("histchars");-
262#endif-
263}
executed 31 times by 1 test: end of block
Executed by:
  • Self test
31
264-
265void-
266bash_history_reinit (interact)-
267 int interact;-
268{-
269#if defined (BANG_HISTORY)-
270 history_expansion = (interact == 0) ? histexp_flag : HISTEXPAND_DEFAULT;
(interact == 0)Description
TRUEevaluated 5461 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5461
271 history_expansion_inhibited = (interact == 0) ? 1 - histexp_flag : 0; /* changed in bash_history_enable() */
(interact == 0)Description
TRUEevaluated 5461 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5461
272 history_inhibit_expansion_function = bash_history_inhibit_expansion;-
273#endif-
274 remember_on_history = enable_history_list;-
275}
executed 5461 times by 1 test: end of block
Executed by:
  • Self test
5461
276-
277void-
278bash_history_disable ()-
279{-
280 remember_on_history = 0;-
281#if defined (BANG_HISTORY)-
282 history_expansion_inhibited = 1;-
283#endif-
284}
executed 727083 times by 1 test: end of block
Executed by:
  • Self test
727083
285-
286void-
287bash_history_enable ()-
288{-
289 remember_on_history = enable_history_list = 1;-
290#if defined (BANG_HISTORY)-
291 history_expansion_inhibited = 0;-
292 history_inhibit_expansion_function = bash_history_inhibit_expansion;-
293#endif-
294 sv_history_control ("HISTCONTROL");-
295 sv_histignore ("HISTIGNORE");-
296}
executed 33 times by 1 test: end of block
Executed by:
  • Self test
33
297-
298/* Load the history list from the history file. */-
299void-
300load_history ()-
301{-
302 char *hf;-
303-
304 /* Truncate history file for interactive shells which desire it.-
305 Note that the history file is automatically truncated to the-
306 size of HISTSIZE if the user does not explicitly set the size-
307 differently. */-
308 set_if_not ("HISTSIZE", "500");-
309 sv_histsize ("HISTSIZE");-
310-
311 set_if_not ("HISTFILESIZE", get_string_value ("HISTSIZE"));-
312 sv_histsize ("HISTFILESIZE");-
313-
314 /* Read the history in HISTFILE into the history list. */-
315 hf = get_string_value ("HISTFILE");-
316-
317 if (hf && *hf && file_exists (hf))
hfDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
*hfDescription
TRUEevaluated 18 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
file_exists (hf)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test
0-18
318 {-
319 read_history (hf);-
320 /* We have read all of the lines from the history file, even if we-
321 read more lines than $HISTSIZE. Remember the total number of lines-
322 we read so we don't count the last N lines as new over and over-
323 again. */-
324 history_lines_in_file = history_lines_read_from_file;-
325 using_history ();-
326 /* history_lines_in_file = where_history () + history_base - 1; */-
327 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
328}
executed 33 times by 1 test: end of block
Executed by:
  • Self test
33
329-
330void-
331bash_clear_history ()-
332{-
333 clear_history ();-
334 history_lines_this_session = 0;-
335 /* XXX - reset history_lines_read_from_file? */-
336}
executed 6 times by 1 test: end of block
Executed by:
  • Self test
6
337-
338/* Delete and free the history list entry at offset I. */-
339int-
340bash_delete_histent (i)-
341 int i;-
342{-
343 HIST_ENTRY *discard;-
344-
345 discard = remove_history (i);-
346 if (discard)
discardDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
347 free_history_entry (discard);
executed 3 times by 1 test: free_history_entry (discard);
Executed by:
  • Self test
3
348 history_lines_this_session--;-
349-
350 return 1;
executed 3 times by 1 test: return 1;
Executed by:
  • Self test
3
351}-
352-
353int-
354bash_delete_history_range (first, last)-
355 int first, last;-
356{-
357 register int i;-
358 HIST_ENTRY **discard_list;-
359-
360 discard_list = remove_history_range (first, last);-
361 for (i = 0; discard_list && discard_list[i]; i++)
discard_listDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
discard_list[i]Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-10
362 free_history_entry (discard_list[i]);
executed 8 times by 1 test: free_history_entry (discard_list[i]);
Executed by:
  • Self test
8
363 history_lines_this_session -= i;-
364-
365 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • Self test
2
366}-
367-
368int-
369bash_delete_last_history ()-
370{-
371 register int i;-
372 HIST_ENTRY **hlist, *histent;-
373 int r;-
374-
375 hlist = history_list ();-
376 if (hlist == NULL)
hlist == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
377 return 0;
never executed: return 0;
0
378-
379 for (i = 0; hlist[i]; i++)
hlist[i]Description
TRUEevaluated 48 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
3-48
380 ;
executed 48 times by 1 test: ;
Executed by:
  • Self test
48
381 i--;-
382-
383 /* History_get () takes a parameter that must be offset by history_base. */-
384 histent = history_get (history_base + i); /* Don't free this */-
385 if (histent == NULL)
histent == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-3
386 return 0;
never executed: return 0;
0
387-
388 r = bash_delete_histent (i);-
389-
390 if (where_history () > history_length)
where_history ...history_lengthDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
391 history_set_pos (history_length);
executed 3 times by 1 test: history_set_pos (history_length);
Executed by:
  • Self test
3
392-
393 return r;
executed 3 times by 1 test: return r;
Executed by:
  • Self test
3
394}-
395-
396#ifdef INCLUDE_UNUSED-
397/* Write the existing history out to the history file. */-
398void-
399save_history ()-
400{-
401 char *hf;-
402 int r;-
403-
404 hf = get_string_value ("HISTFILE");-
405 if (hf && *hf && file_exists (hf))-
406 {-
407 /* Append only the lines that occurred this session to-
408 the history file. */-
409 using_history ();-
410-
411 if (history_lines_this_session <= where_history () || force_append_history)-
412 r = append_history (history_lines_this_session, hf);-
413 else-
414 r = write_history (hf);-
415 sv_histsize ("HISTFILESIZE");-
416 }-
417}-
418#endif-
419-
420int-
421maybe_append_history (filename)-
422 char *filename;-
423{-
424 int fd, result;-
425 struct stat buf;-
426-
427 result = EXECUTION_SUCCESS;-
428 if (history_lines_this_session > 0 && (history_lines_this_session <= where_history ()))
history_lines_this_session > 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(history_lines...re_history ())Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
429 {-
430 /* If the filename was supplied, then create it if necessary. */-
431 if (stat (filename, &buf) == -1 && errno == ENOENT)
stat (filename, &buf) == -1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
(*__errno_location ()) == 2Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-2
432 {-
433 fd = open (filename, O_WRONLY|O_CREAT, 0600);-
434 if (fd < 0)
fd < 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
0-2
435 {-
436 builtin_error (_("%s: cannot create: %s"), filename, strerror (errno));-
437 return (EXECUTION_FAILURE);
never executed: return (1);
0
438 }-
439 close (fd);-
440 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
441 result = append_history (history_lines_this_session, filename);-
442 /* Pretend we already read these lines from the file because we just-
443 added them */-
444 history_lines_in_file += history_lines_this_session;-
445 history_lines_this_session = 0;-
446 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test
2
447 else-
448 history_lines_this_session = 0; /* reset if > where_history() */
never executed: history_lines_this_session = 0;
0
449-
450 return (result);
executed 2 times by 1 test: return (result);
Executed by:
  • Self test
2
451}-
452-
453/* If this is an interactive shell, then append the lines executed-
454 this session to the history file. */-
455int-
456maybe_save_shell_history ()-
457{-
458 int result;-
459 char *hf;-
460-
461 result = 0;-
462 if (history_lines_this_session > 0)
history_lines_this_session > 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
463 {-
464 hf = get_string_value ("HISTFILE");-
465-
466 if (hf && *hf)
hfDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
*hfDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-6
467 {-
468 /* If the file doesn't exist, then create it. */-
469 if (file_exists (hf) == 0)
file_exists (hf) == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test
1-2
470 {-
471 int file;-
472 file = open (hf, O_CREAT | O_TRUNC | O_WRONLY, 0600);-
473 if (file != -1)
file != -1Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-1
474 close (file);
executed 1 time by 1 test: close (file);
Executed by:
  • Self test
1
475 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test
1
476-
477 /* Now actually append the lines if the history hasn't been-
478 stifled. If the history has been stifled, rewrite the-
479 history file. */-
480 using_history ();-
481 if (history_lines_this_session <= where_history () || force_append_history)
history_lines_...ere_history ()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
force_append_historyDescription
TRUEnever evaluated
FALSEnever evaluated
0-3
482 {-
483 result = append_history (history_lines_this_session, hf);-
484 history_lines_in_file += history_lines_this_session;-
485 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
486 else-
487 {-
488 result = write_history (hf);-
489 history_lines_in_file = history_lines_written_to_file;-
490 /* history_lines_in_file = where_history () + history_base - 1; */-
491 }
never executed: end of block
0
492 history_lines_this_session = 0;-
493-
494 sv_histsize ("HISTFILESIZE");-
495 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
496 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
497 return (result);
executed 9 times by 1 test: return (result);
Executed by:
  • Self test
9
498}-
499-
500#if defined (READLINE)-
501/* Tell readline () that we have some text for it to edit. */-
502static void-
503re_edit (text)-
504 char *text;-
505{-
506 if (bash_input.type == st_stdin)
bash_input.type == st_stdinDescription
TRUEnever evaluated
FALSEnever evaluated
0
507 bash_re_edit (text);
never executed: bash_re_edit (text);
0
508}
never executed: end of block
0
509#endif /* READLINE */-
510-
511/* Return 1 if this line needs history expansion. */-
512static int-
513history_expansion_p (line)-
514 char *line;-
515{-
516 register char *s;-
517-
518 for (s = line; *s; s++)
*sDescription
TRUEevaluated 4393 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 176 times by 1 test
Evaluated by:
  • Self test
176-4393
519 if (*s == history_expansion_char || *s == history_subst_char)
*s == history_expansion_charDescription
TRUEevaluated 205 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4188 times by 1 test
Evaluated by:
  • Self test
*s == history_subst_charDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 4187 times by 1 test
Evaluated by:
  • Self test
1-4188
520 return 1;
executed 206 times by 1 test: return 1;
Executed by:
  • Self test
206
521 return 0;
executed 176 times by 1 test: return 0;
Executed by:
  • Self test
176
522}-
523-
524/* Do pre-processing on LINE. If PRINT_CHANGES is non-zero, then-
525 print the results of expanding the line if there were any changes.-
526 If there is an error, return NULL, otherwise the expanded line is-
527 returned. If ADDIT is non-zero the line is added to the history-
528 list after history expansion. ADDIT is just a suggestion;-
529 REMEMBER_ON_HISTORY can veto, and does.-
530 Right now this does history expansion. */-
531char *-
532pre_process_line (line, print_changes, addit)-
533 char *line;-
534 int print_changes, addit;-
535{-
536 char *history_value;-
537 char *return_value;-
538 int expanded;-
539-
540 return_value = line;-
541 expanded = 0;-
542-
543# if defined (BANG_HISTORY)-
544 /* History expand the line. If this results in no errors, then-
545 add that line to the history if ADDIT is non-zero. */-
546 if (!history_expansion_inhibited && history_expansion && history_expansion_p (line))
!history_expansion_inhibitedDescription
TRUEevaluated 491 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
history_expansionDescription
TRUEevaluated 382 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 109 times by 1 test
Evaluated by:
  • Self test
history_expansion_p (line)Description
TRUEevaluated 206 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 176 times by 1 test
Evaluated by:
  • Self test
0-491
547 {-
548 expanded = history_expand (line, &history_value);-
549-
550 if (expanded)
expandedDescription
TRUEevaluated 97 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 109 times by 1 test
Evaluated by:
  • Self test
97-109
551 {-
552 if (print_changes)
print_changesDescription
TRUEevaluated 97 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-97
553 {-
554 if (expanded < 0)
expanded < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 96 times by 1 test
Evaluated by:
  • Self test
1-96
555 internal_error ("%s", history_value);
executed 1 time by 1 test: internal_error ("%s", history_value);
Executed by:
  • Self test
1
556#if defined (READLINE)-
557 else if (hist_verify == 0 || expanded == 2)
hist_verify == 0Description
TRUEevaluated 96 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
expanded == 2Description
TRUEnever evaluated
FALSEnever evaluated
0-96
558#else-
559 else-
560#endif-
561 fprintf (stderr, "%s\n", history_value);
executed 96 times by 1 test: fprintf ( stderr , "%s\n", history_value);
Executed by:
  • Self test
96
562 }
executed 97 times by 1 test: end of block
Executed by:
  • Self test
97
563-
564 /* If there was an error, return NULL. */-
565 if (expanded < 0 || expanded == 2) /* 2 == print only */
expanded < 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 96 times by 1 test
Evaluated by:
  • Self test
expanded == 2Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 93 times by 1 test
Evaluated by:
  • Self test
1-96
566 {-
567# if defined (READLINE)-
568 if (expanded == 2 && rl_dispatching == 0 && *history_value)
expanded == 2Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test
rl_dispatching == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*history_valueDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-3
569# else -
570 if (expanded == 2 && *history_value)-
571# endif /* !READLINE */-
572 maybe_add_history (history_value);
executed 3 times by 1 test: maybe_add_history (history_value);
Executed by:
  • Self test
3
573-
574 free (history_value);-
575-
576# if defined (READLINE)-
577 /* New hack. We can allow the user to edit the-
578 failed history expansion. */-
579 if (history_reediting && expanded < 0 && rl_done)
history_reeditingDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
expanded < 0Description
TRUEnever evaluated
FALSEnever evaluated
rl_doneDescription
TRUEnever evaluated
FALSEnever evaluated
0-4
580 re_edit (line);
never executed: re_edit (line);
0
581# endif /* READLINE */-
582 return ((char *)NULL);
executed 4 times by 1 test: return ((char *) ((void *)0) );
Executed by:
  • Self test
4
583 }-
584-
585# if defined (READLINE)-
586 if (hist_verify && expanded == 1)
hist_verifyDescription
TRUEnever evaluated
FALSEevaluated 93 times by 1 test
Evaluated by:
  • Self test
expanded == 1Description
TRUEnever evaluated
FALSEnever evaluated
0-93
587 {-
588 re_edit (history_value);-
589 free (history_value);-
590 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
591 }-
592# endif-
593 }
executed 93 times by 1 test: end of block
Executed by:
  • Self test
93
594-
595 /* Let other expansions know that return_value can be free'ed,-
596 and that a line has been added to the history list. Note-
597 that we only add lines that have something in them. */-
598 expanded = 1;-
599 return_value = history_value;-
600 }
executed 202 times by 1 test: end of block
Executed by:
  • Self test
202
601# endif /* BANG_HISTORY */-
602-
603 if (addit && remember_on_history && *return_value)
additDescription
TRUEevaluated 487 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
remember_on_historyDescription
TRUEevaluated 487 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*return_valueDescription
TRUEevaluated 487 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-487
604 maybe_add_history (return_value);
executed 487 times by 1 test: maybe_add_history (return_value);
Executed by:
  • Self test
487
605-
606#if 0-
607 if (expanded == 0)-
608 return_value = savestring (line);-
609#endif-
610-
611 return (return_value);
executed 487 times by 1 test: return (return_value);
Executed by:
  • Self test
487
612}-
613-
614/* Return 1 if the first non-whitespace character in LINE is a `#', indicating-
615 that the line is a shell comment. Return 2 if there is a comment after the-
616 first non-whitespace character. Return 0 if the line does not contain a-
617 comment. */-
618static int-
619shell_comment (line)-
620 char *line;-
621{-
622 char *p;-
623 int n;-
624-
625 if (line == 0)
line == 0Description
TRUEnever evaluated
FALSEevaluated 506 times by 1 test
Evaluated by:
  • Self test
0-506
626 return 0;
never executed: return 0;
0
627 for (p = line; p && *p && whitespace (*p); p++)
pDescription
TRUEevaluated 508 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*pDescription
TRUEevaluated 508 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
((*p) == ' ')Description
TRUEnever evaluated
FALSEevaluated 508 times by 1 test
Evaluated by:
  • Self test
((*p) == '\t')Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 506 times by 1 test
Evaluated by:
  • Self test
0-508
628 ;
executed 2 times by 1 test: ;
Executed by:
  • Self test
2
629 if (p && *p == '#')
pDescription
TRUEevaluated 506 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*p == '#'Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 481 times by 1 test
Evaluated by:
  • Self test
0-506
630 return 1;
executed 25 times by 1 test: return 1;
Executed by:
  • Self test
25
631 n = skip_to_delim (line, p - line, "#", SD_NOJMP|SD_GLOB|SD_EXTGLOB|SD_COMPLETE);-
632 return (line[n] == '#') ? 2 : 0;
executed 481 times by 1 test: return (line[n] == '#') ? 2 : 0;
Executed by:
  • Self test
481
633}-
634-
635#ifdef INCLUDE_UNUSED-
636/* Remove shell comments from LINE. A `#' and anything after it is a comment.-
637 This isn't really useful yet, since it doesn't handle quoting. */-
638static char *-
639filter_comments (line)-
640 char *line;-
641{-
642 char *p;-
643-
644 for (p = line; p && *p && *p != '#'; p++)-
645 ;-
646 if (p && *p == '#')-
647 *p = '\0';-
648 return (line);-
649}-
650#endif-
651-
652/* Check LINE against what HISTCONTROL says to do. Returns 1 if the line-
653 should be saved; 0 if it should be discarded. */-
654static int-
655check_history_control (line)-
656 char *line;-
657{-
658 HIST_ENTRY *temp;-
659 int r;-
660-
661 if (history_control == 0)
history_control == 0Description
TRUEevaluated 342 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 149 times by 1 test
Evaluated by:
  • Self test
149-342
662 return 1;
executed 342 times by 1 test: return 1;
Executed by:
  • Self test
342
663-
664 /* ignorespace or ignoreboth */-
665 if ((history_control & HC_IGNSPACE) && *line == ' ')
(history_control & 0x01)Description
TRUEevaluated 149 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*line == ' 'Description
TRUEnever evaluated
FALSEevaluated 149 times by 1 test
Evaluated by:
  • Self test
0-149
666 return 0;
never executed: return 0;
0
667-
668 /* ignoredups or ignoreboth */-
669 if (history_control & HC_IGNDUPS)
history_control & 0x02Description
TRUEevaluated 149 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-149
670 {-
671 using_history ();-
672 temp = previous_history ();-
673-
674 r = (temp == 0 || STREQ (temp->line, line) == 0);
never executed: __result = (((const unsigned char *) (const char *) ( temp->line ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( line ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
temp == 0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 148 times by 1 test
Evaluated by:
  • Self test
((temp->line)[... }) == 0) == 0Description
TRUEevaluated 137 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
(temp->line)[0] == (line)[0]Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 85 times by 1 test
Evaluated by:
  • Self test
__extension__ ... )))); }) == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 52 times by 1 test
Evaluated by:
  • Self test
__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-148
675-
676 using_history ();-
677-
678 if (r == 0)
r == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 138 times by 1 test
Evaluated by:
  • Self test
11-138
679 return r;
executed 11 times by 1 test: return r;
Executed by:
  • Self test
11
680 }
executed 138 times by 1 test: end of block
Executed by:
  • Self test
138
681-
682 return 1;
executed 138 times by 1 test: return 1;
Executed by:
  • Self test
138
683}-
684-
685/* Remove all entries matching LINE from the history list. Triggered when-
686 HISTCONTROL includes `erasedups'. */-
687static void-
688hc_erasedups (line)-
689 char *line;-
690{-
691 HIST_ENTRY *temp;-
692 int r;-
693-
694 using_history ();-
695 while (temp = previous_history ())
temp = previous_history ()Description
TRUEnever evaluated
FALSEnever evaluated
0
696 {-
697 if (STREQ (temp->line, line))
never executed: __result = (((const unsigned char *) (const char *) ( temp->line ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
never executed: __result = (((const unsigned char *) (const char *) ( line ))[3] - __s2[3]);
never executed: end of block
never executed: end of block
(temp->line)[0] == (line)[0]Description
TRUEnever evaluated
FALSEnever evaluated
__extension__ ... )))); }) == 0Description
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
698 {-
699 r = where_history ();-
700 temp = remove_history (r);-
701 if (temp)
tempDescription
TRUEnever evaluated
FALSEnever evaluated
0
702 free_history_entry (temp);
never executed: free_history_entry (temp);
0
703 }
never executed: end of block
0
704 }
never executed: end of block
0
705 using_history ();-
706}
never executed: end of block
0
707-
708/* Add LINE to the history list, handling possibly multi-line compound-
709 commands. We note whether or not we save the first line of each command-
710 (which is usually the entire command and history entry), and don't add-
711 the second and subsequent lines of a multi-line compound command if we-
712 didn't save the first line. We don't usually save shell comment lines in-
713 compound commands in the history, because they could have the effect of-
714 commenting out the rest of the command when the entire command is saved as-
715 a single history entry (when COMMAND_ORIENTED_HISTORY is enabled). If-
716 LITERAL_HISTORY is set, we're saving lines in the history with embedded-
717 newlines, so it's OK to save comment lines. If we're collecting the body-
718 of a here-document, we should act as if literal_history is enabled, because-
719 we want to save the entire contents of the here-document as it was-
720 entered. We also make sure to save multiple-line quoted strings or other-
721 constructs. */-
722void-
723maybe_add_history (line)-
724 char *line;-
725{-
726 int is_comment;-
727-
728 hist_last_line_added = 0;-
729 is_comment = shell_comment (line);-
730-
731 /* Don't use the value of history_control to affect the second-
732 and subsequent lines of a multi-line command (old code did-
733 this only when command_oriented_history is enabled). */-
734 if (current_command_line_count > 1)
current_command_line_count > 1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 488 times by 1 test
Evaluated by:
  • Self test
9-488
735 {-
736 if (current_command_first_line_saved &&
current_comman...rst_line_savedDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
737 ((parser_state & PST_HEREDOC) || literal_history || dstack.delimiter_depth != 0 || is_comment != 1))
(parser_state & 0x020000)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
literal_historyDescription
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
dstack.delimiter_depth != 0Description
TRUEnever evaluated
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
is_comment != 1Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-5
738 bash_add_history (line);
executed 9 times by 1 test: bash_add_history (line);
Executed by:
  • Self test
9
739 current_command_line_comment = is_comment ? current_command_line_count : -2;
is_commentDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
740 return;
executed 9 times by 1 test: return;
Executed by:
  • Self test
9
741 }-
742-
743 /* This is the first line of a (possible multi-line) command. Note whether-
744 or not we should save the first line and remember it. */-
745 current_command_line_comment = is_comment ? current_command_line_count : -2;
is_commentDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 462 times by 1 test
Evaluated by:
  • Self test
26-462
746 current_command_first_line_saved = check_add_history (line, 0);-
747}
executed 488 times by 1 test: end of block
Executed by:
  • Self test
488
748-
749/* Just check LINE against HISTCONTROL and HISTIGNORE and add it to the-
750 history if it's OK. Used by `history -s' as well as maybe_add_history().-
751 Returns 1 if the line was saved in the history, 0 otherwise. */-
752int-
753check_add_history (line, force)-
754 char *line;-
755 int force;-
756{-
757 if (check_history_control (line) && history_should_ignore (line) == 0)
check_history_control (line)Description
TRUEevaluated 480 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 11 times by 1 test
Evaluated by:
  • Self test
history_should...re (line) == 0Description
TRUEevaluated 430 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 50 times by 1 test
Evaluated by:
  • Self test
11-480
758 {-
759 /* We're committed to saving the line. If the user has requested it,-
760 remove other matching lines from the history. */-
761 if (history_control & HC_ERASEDUPS)
history_control & 0x04Description
TRUEnever evaluated
FALSEevaluated 430 times by 1 test
Evaluated by:
  • Self test
0-430
762 hc_erasedups (line);
never executed: hc_erasedups (line);
0
763 -
764 if (force)
forceDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 427 times by 1 test
Evaluated by:
  • Self test
3-427
765 {-
766 really_add_history (line);-
767 using_history ();-
768 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test
3
769 else-
770 bash_add_history (line);
executed 427 times by 1 test: bash_add_history (line);
Executed by:
  • Self test
427
771 return 1;
executed 430 times by 1 test: return 1;
Executed by:
  • Self test
430
772 }-
773 return 0;
executed 61 times by 1 test: return 0;
Executed by:
  • Self test
61
774}-
775-
776#if defined (SYSLOG_HISTORY)-
777#define SYSLOG_MAXLEN 600-
778-
779#ifndef OPENLOG_OPTS-
780#define OPENLOG_OPTS 0-
781#endif-
782-
783void-
784bash_syslog_history (line)-
785 const char *line;-
786{-
787 char trunc[SYSLOG_MAXLEN];-
788 static int first = 1;-
789-
790 if (first)-
791 {-
792 openlog (shell_name, OPENLOG_OPTS, SYSLOG_FACILITY);-
793 first = 0;-
794 }-
795-
796 if (strlen(line) < SYSLOG_MAXLEN)-
797 syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY: PID=%d UID=%d %s", getpid(), current_user.uid, line);-
798 else-
799 {-
800 strncpy (trunc, line, SYSLOG_MAXLEN);-
801 trunc[SYSLOG_MAXLEN - 1] = '\0';-
802 syslog (SYSLOG_FACILITY|SYSLOG_LEVEL, "HISTORY (TRUNCATED): PID=%d UID=%d %s", getpid(), current_user.uid, trunc);-
803 }-
804}-
805#endif-
806 -
807/* Add a line to the history list.-
808 The variable COMMAND_ORIENTED_HISTORY controls the style of history-
809 remembering; when non-zero, and LINE is not the first line of a-
810 complete parser construct, append LINE to the last history line instead-
811 of adding it as a new line. */-
812void-
813bash_add_history (line)-
814 char *line;-
815{-
816 int add_it, offset, curlen;-
817 HIST_ENTRY *current, *old;-
818 char *chars_to_add, *new_line;-
819-
820 add_it = 1;-
821 if (command_oriented_history && current_command_line_count > 1)
command_oriented_historyDescription
TRUEevaluated 436 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
current_command_line_count > 1Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 427 times by 1 test
Evaluated by:
  • Self test
0-436
822 {-
823 /* The second and subsequent lines of a here document have the trailing-
824 newline preserved. We don't want to add extra newlines here, but we-
825 do want to add one after the first line (which is the command that-
826 contains the here-doc specifier). parse.y:history_delimiting_chars()-
827 does the right thing to take care of this for us. We don't want to-
828 add extra newlines if the user chooses to enable literal_history,-
829 so we have to duplicate some of what that function does here. */-
830 if ((parser_state & PST_HEREDOC) && literal_history && current_command_line_count > 2 && line[strlen (line) - 1] == '\n')
(parser_state & 0x020000)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
literal_historyDescription
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test
current_command_line_count > 2Description
TRUEnever evaluated
FALSEnever evaluated
line[strlen (l...) - 1] == '\n'Description
TRUEnever evaluated
FALSEnever evaluated
0-5
831 chars_to_add = "";
never executed: chars_to_add = "";
0
832 else if (current_command_line_count == current_command_line_comment+1)
current_comman...line_comment+1Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
833 chars_to_add = "\n";
never executed: chars_to_add = "\n";
0
834 else if (literal_history)
literal_historyDescription
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
835 chars_to_add = "\n";
never executed: chars_to_add = "\n";
0
836 else-
837 chars_to_add = history_delimiting_chars (line);
executed 9 times by 1 test: chars_to_add = history_delimiting_chars (line);
Executed by:
  • Self test
9
838-
839 using_history ();-
840 current = previous_history ();-
841-
842 current_command_line_comment = shell_comment (line) ? current_command_line_count : -2;
shell_comment (line)Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
843-
844 if (current)
currentDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
845 {-
846 /* If the previous line ended with an escaped newline (escaped-
847 with backslash, but otherwise unquoted), then remove the quoted-
848 newline, since that is what happens when the line is parsed. */-
849 curlen = strlen (current->line);-
850-
851 if (dstack.delimiter_depth == 0 && current->line[curlen - 1] == '\\' &&
dstack.delimiter_depth == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
current->line[...n - 1] == '\\'Description
TRUEnever evaluated
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
0-9
852 current->line[curlen - 2] != '\\')
current->line[...n - 2] != '\\'Description
TRUEnever evaluated
FALSEnever evaluated
0
853 {-
854 current->line[curlen - 1] = '\0';-
855 curlen--;-
856 chars_to_add = "";-
857 }
never executed: end of block
0
858-
859 /* If we're not in some kind of quoted construct, the current history-
860 entry ends with a newline, and we're going to add a semicolon,-
861 don't. In some cases, it results in a syntax error (e.g., before-
862 a close brace), and it should not be needed. */-
863 if (dstack.delimiter_depth == 0 && current->line[curlen - 1] == '\n' && *chars_to_add == ';')
dstack.delimiter_depth == 0Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
current->line[...n - 1] == '\n'Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test
*chars_to_add == ';'Description
TRUEnever evaluated
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test
0-9
864 chars_to_add++;
never executed: chars_to_add++;
0
865-
866 new_line = (char *)xmalloc (1-
867 + curlen-
868 + strlen (line)-
869 + strlen (chars_to_add));-
870 sprintf (new_line, "%s%s%s", current->line, chars_to_add, line);-
871 offset = where_history ();-
872 old = replace_history_entry (offset, new_line, current->data);-
873 free (new_line);-
874-
875 if (old)
oldDescription
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
0-9
876 free_history_entry (old);
executed 9 times by 1 test: free_history_entry (old);
Executed by:
  • Self test
9
877-
878 add_it = 0;-
879 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
880 }
executed 9 times by 1 test: end of block
Executed by:
  • Self test
9
881-
882 if (add_it)
add_itDescription
TRUEevaluated 427 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 9 times by 1 test
Evaluated by:
  • Self test
9-427
883 really_add_history (line);
executed 427 times by 1 test: really_add_history (line);
Executed by:
  • Self test
427
884-
885#if defined (SYSLOG_HISTORY)-
886 bash_syslog_history (line);-
887#endif-
888-
889 using_history ();-
890}
executed 436 times by 1 test: end of block
Executed by:
  • Self test
436
891-
892static void-
893really_add_history (line)-
894 char *line;-
895{-
896 hist_last_line_added = 1;-
897 hist_last_line_pushed = 0;-
898 add_history (line);-
899 history_lines_this_session++;-
900}
executed 430 times by 1 test: end of block
Executed by:
  • Self test
430
901-
902int-
903history_number ()-
904{-
905 using_history ();-
906 return (remember_on_history ? history_base + where_history () : 1);
never executed: return (remember_on_history ? history_base + where_history () : 1);
0
907}-
908-
909static int-
910should_expand (s)-
911 char *s;-
912{-
913 char *p;-
914-
915 for (p = s; p && *p; p++)
pDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test
FALSEnever evaluated
*pDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
0-31
916 {-
917 if (*p == '\\')
*p == '\\'Description
TRUEnever evaluated
FALSEevaluated 26 times by 1 test
Evaluated by:
  • Self test
0-26
918 p++;
never executed: p++;
0
919 else if (*p == '&')
*p == '&'Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test
2-24
920 return 1;
executed 2 times by 1 test: return 1;
Executed by:
  • Self test
2
921 }
executed 24 times by 1 test: end of block
Executed by:
  • Self test
24
922 return 0;
executed 5 times by 1 test: return 0;
Executed by:
  • Self test
5
923}-
924-
925static int-
926histignore_item_func (ign)-
927 struct ign *ign;-
928{-
929 if (should_expand (ign->val))
should_expand (ign->val)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test
2-5
930 ign->flags |= HIGN_EXPAND;
executed 2 times by 1 test: ign->flags |= 0x01;
Executed by:
  • Self test
2
931 return (0);
executed 7 times by 1 test: return (0);
Executed by:
  • Self test
7
932}-
933-
934void-
935setup_history_ignore (varname)-
936 char *varname;-
937{-
938 setup_ignore_patterns (&histignore);-
939}
executed 38 times by 1 test: end of block
Executed by:
  • Self test
38
940-
941static HIST_ENTRY *-
942last_history_entry ()-
943{-
944 HIST_ENTRY *he;-
945-
946 using_history ();-
947 he = previous_history ();-
948 using_history ();-
949 return he;
executed 137 times by 1 test: return he;
Executed by:
  • Self test
137
950}-
951-
952char *-
953last_history_line ()-
954{-
955 HIST_ENTRY *he;-
956-
957 he = last_history_entry ();-
958 if (he == 0)
he == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
959 return ((char *)NULL);
never executed: return ((char *) ((void *)0) );
0
960 return he->line;
never executed: return he->line;
0
961}-
962-
963static char *-
964expand_histignore_pattern (pat)-
965 char *pat;-
966{-
967 HIST_ENTRY *phe;-
968 char *ret;-
969-
970 phe = last_history_entry ();-
971-
972 if (phe == (HIST_ENTRY *)0)
phe == (HIST_ENTRY *)0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test
FALSEevaluated 136 times by 1 test
Evaluated by:
  • Self test
1-136
973 return (savestring (pat));
executed 1 time by 1 test: return ((char *)strcpy (sh_xmalloc((1 + strlen (pat)), "bashhist.c", 973), (pat)));
Executed by:
  • Self test
1
974-
975 ret = strcreplace (pat, '&', phe->line, 1);-
976-
977 return ret;
executed 136 times by 1 test: return ret;
Executed by:
  • Self test
136
978}-
979-
980/* Return 1 if we should not put LINE into the history according to the-
981 patterns in HISTIGNORE. */-
982static int-
983history_should_ignore (line)-
984 char *line;-
985{-
986 register int i, match;-
987 char *npat;-
988-
989 if (histignore.num_ignores == 0)
histignore.num_ignores == 0Description
TRUEevaluated 343 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 137 times by 1 test
Evaluated by:
  • Self test
137-343
990 return 0;
executed 343 times by 1 test: return 0;
Executed by:
  • Self test
343
991-
992 for (i = match = 0; i < histignore.num_ignores; i++)
i < histignore.num_ignoresDescription
TRUEevaluated 437 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 87 times by 1 test
Evaluated by:
  • Self test
87-437
993 {-
994 if (histignore.ignores[i].flags & HIGN_EXPAND)
histignore.ign...].flags & 0x01Description
TRUEevaluated 137 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 300 times by 1 test
Evaluated by:
  • Self test
137-300
995 npat = expand_histignore_pattern (histignore.ignores[i].val);
executed 137 times by 1 test: npat = expand_histignore_pattern (histignore.ignores[i].val);
Executed by:
  • Self test
137
996 else-
997 npat = histignore.ignores[i].val;
executed 300 times by 1 test: npat = histignore.ignores[i].val;
Executed by:
  • Self test
300
998-
999 match = strmatch (npat, line, FNMATCH_EXTFLAG) != FNM_NOMATCH;-
1000-
1001 if (histignore.ignores[i].flags & HIGN_EXPAND)
histignore.ign...].flags & 0x01Description
TRUEevaluated 137 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 300 times by 1 test
Evaluated by:
  • Self test
137-300
1002 free (npat);
executed 137 times by 1 test: sh_xfree((npat), "bashhist.c", 1002);
Executed by:
  • Self test
137
1003-
1004 if (match)
matchDescription
TRUEevaluated 50 times by 1 test
Evaluated by:
  • Self test
FALSEevaluated 387 times by 1 test
Evaluated by:
  • Self test
50-387
1005 break;
executed 50 times by 1 test: break;
Executed by:
  • Self test
50
1006 }
executed 387 times by 1 test: end of block
Executed by:
  • Self test
387
1007-
1008 return match;
executed 137 times by 1 test: return match;
Executed by:
  • Self test
137
1009}-
1010#endif /* HISTORY */-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.1.2