1 /* bushhist.c -- bush interface to the GNU history library. */
3 /* Copyright (C) 1993-2019 Free Software Foundation, Inc.
5 This file is part of GNU Bush, the Bourne Again SHell.
7 Bush 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.
12 Bush 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.
17 You should have received a copy of the GNU General Public License
18 along with Bush. If not, see <http://www.gnu.org/licenses/>.
25 #if defined (HAVE_UNISTD_H)
27 # include <sys/types.h>
32 #include "bushtypes.h"
36 #include "posixstat.h"
41 #if defined (SYSLOG_HISTORY)
47 #include "lxrgmr/parser.h"
48 #include "input/input.h"
49 #include "lxrgmr/parser.h" /* for the struct dstack stuff. */
50 #include "impl/pathexp.h" /* for the struct ignorevar stuff */
51 #include "bushhist.h" /* matching prototypes and declarations */
52 #include "builtins/common.h"
54 #include <readline/history.h>
55 #include <glob/glob.h>
56 #include <glob/strmatch.h>
58 #if defined (READLINE)
59 # include "input/bushline.h"
60 extern int rl_done
, rl_dispatching
; /* should really include readline.h */
63 #ifndef HISTSIZE_DEFAULT
64 # define HISTSIZE_DEFAULT "500"
71 static int histignore_item_func
PARAMS((struct ign
*));
72 static int check_history_control
PARAMS((char *));
73 static void hc_erasedups
PARAMS((char *));
74 static void really_add_history
PARAMS((char *));
76 static struct ignorevar histignore
=
82 (sh_iv_item_func_t
*)histignore_item_func
,
85 #define HIGN_EXPAND 0x01
87 /* Declarations of bush history variables. */
88 /* Non-zero means to remember lines typed to the shell on the history
89 list. This is different than the user-controlled behaviour; this
90 becomes zero when we read lines from a file, for example. */
91 int remember_on_history
= 0;
92 int enable_history_list
= -1; /* value for `set -o history' */
94 /* The number of lines that Bush has added to this history session. The
95 difference between the number of the top element in the history list
96 (offset from history_base) and the number of lines in the history file.
97 Appending this session's history to the history file resets this to 0. */
98 int history_lines_this_session
;
100 /* The number of lines that Bush has read from the history file. */
101 int history_lines_in_file
;
103 #if defined (BANG_HISTORY)
104 /* Non-zero means do no history expansion on this line, regardless
105 of what history_expansion says. */
106 int history_expansion_inhibited
;
107 /* If non-zero, double quotes can quote the history expansion character. */
108 int double_quotes_inhibit_history_expansion
= 0;
111 /* With the old default, every line was saved in the history individually.
112 I.e., if the user enters:
117 Each line will be individually saved in the history.
124 If the variable command_oriented_history is set, multiple lines
125 which form one command will be saved as one history entry.
136 The user can then recall the whole command all at once instead
137 of just being able to recall one line at a time.
139 This is now enabled by default.
141 int command_oriented_history
= 1;
143 /* Set to 1 if the first line of a possibly-multi-line command was saved
144 in the history list. Managed by maybe_add_history(), but global so
145 the history-manipluating builtins can see it. */
146 int current_command_first_line_saved
= 0;
148 /* Set to the number of the most recent line of a possibly-multi-line command
149 that contains a shell comment. Used by bush_add_history() to determine
150 whether to add a newline or a semicolon. */
151 int current_command_line_comment
= 0;
153 /* Non-zero means to store newlines in the history list when using
154 command_oriented_history rather than trying to use semicolons. */
157 /* Non-zero means to append the history to the history file at shell
158 exit, even if the history has been stifled. */
159 int force_append_history
;
161 /* A nit for picking at history saving. Flags have the following values:
163 Value == 0 means save all lines parsed by the shell on the history.
164 Value & HC_IGNSPACE means save all lines that do not start with a space.
165 Value & HC_IGNDUPS means save all lines that do not match the last
167 Value & HC_ERASEDUPS means to remove all other matching lines from the
168 history list before saving the latest line. */
171 /* Set to 1 if the last command was added to the history list successfully
172 as a separate history entry; set to 0 if the line was ignored or added
173 to a previous entry as part of command-oriented-history processing. */
174 int hist_last_line_added
;
176 /* Set to 1 if builtins/history.def:push_history added the last history
178 int hist_last_line_pushed
;
180 #if defined (READLINE)
181 /* If non-zero, and readline is being used, the user is offered the
182 chance to re-edit a failed history expansion. */
183 int history_reediting
;
185 /* If non-zero, and readline is being used, don't directly execute a
186 line with history substitution. Reload it into the editing buffer
187 instead and let the user further edit and confirm with a newline. */
190 #endif /* READLINE */
192 /* Non-zero means to not save function definitions in the history list. */
193 int dont_save_function_defs
;
195 #if defined (BANG_HISTORY)
196 static int bush_history_inhibit_expansion
PARAMS((char *, int));
198 #if defined (READLINE)
199 static void re_edit
PARAMS((char *));
201 static int history_expansion_p
PARAMS((char *));
202 static int shell_comment
PARAMS((char *));
203 static int should_expand
PARAMS((char *));
204 static HIST_ENTRY
*last_history_entry
PARAMS((void));
205 static char *expand_histignore_pattern
PARAMS((char *));
206 static int history_should_ignore
PARAMS((char *));
208 #if defined (BANG_HISTORY)
209 /* Is the history expansion starting at string[i] one that should not
212 bush_history_inhibit_expansion (string
, i
)
219 hx
[0] = history_expansion_char
;
222 /* The shell uses ! as a pattern negation character in globbing [...]
223 expressions, so let those pass without expansion. */
224 if (i
> 0 && (string
[i
- 1] == '[') && member (']', string
+ i
+ 1))
226 /* The shell uses ! as the indirect expansion character, so let those
227 expansions pass as well. */
228 else if (i
> 1 && string
[i
- 1] == '{' && string
[i
- 2] == '$' &&
229 member ('}', string
+ i
+ 1))
231 /* The shell uses $! as a defined parameter expansion. */
232 else if (i
> 1 && string
[i
- 1] == '$' && string
[i
] == '!')
234 #if defined (EXTENDED_GLOB)
235 else if (extended_glob
&& i
> 1 && string
[i
+1] == '(' && member (')', string
+ i
+ 2))
240 /* If we're supposed to be in single-quoted string, skip over the
241 single-quoted part and then look at what's left. */
242 if (history_quoting_state
== '\'')
244 si
= skip_to_delim (string
, 0, "'", SD_NOJMP
|SD_HISTEXP
);
245 if (string
[si
] == 0 || si
>= i
)
250 /* Make sure the history expansion should not be skipped by quoting or
251 command/process substitution. */
252 if ((t
= skip_to_histexp (string
, si
, hx
, SD_NOJMP
|SD_HISTEXP
)) > 0)
254 /* Skip instances of history expansion appearing on the line before
258 t
= skip_to_histexp (string
, t
+1, hx
, SD_NOJMP
|SD_HISTEXP
);
270 bush_initialize_history ()
272 history_quotes_inhibit_expansion
= 1;
273 history_search_delimiter_chars
= ";&()|<>";
274 #if defined (BANG_HISTORY)
275 history_inhibit_expansion_function
= bush_history_inhibit_expansion
;
276 sv_histchars ("histchars");
281 bush_history_reinit (interact
)
284 #if defined (BANG_HISTORY)
285 history_expansion
= (interact
== 0) ? histexp_flag
: HISTEXPAND_DEFAULT
;
286 history_expansion_inhibited
= (interact
== 0) ? 1 - histexp_flag
: 0; /* changed in bush_history_enable() */
287 history_inhibit_expansion_function
= bush_history_inhibit_expansion
;
289 remember_on_history
= enable_history_list
;
293 bush_history_disable ()
295 remember_on_history
= 0;
296 #if defined (BANG_HISTORY)
297 history_expansion_inhibited
= 1;
302 bush_history_enable ()
304 remember_on_history
= enable_history_list
= 1;
305 #if defined (BANG_HISTORY)
306 history_expansion_inhibited
= 0;
307 history_inhibit_expansion_function
= bush_history_inhibit_expansion
;
309 sv_history_control ("HISTCONTROL");
310 sv_histignore ("HISTIGNORE");
313 /* Load the history list from the history file. */
319 /* Truncate history file for interactive shells which desire it.
320 Note that the history file is automatically truncated to the
321 size of HISTSIZE if the user does not explicitly set the size
323 set_if_not ("HISTSIZE", HISTSIZE_DEFAULT
);
324 sv_histsize ("HISTSIZE");
326 set_if_not ("HISTFILESIZE", get_string_value ("HISTSIZE"));
327 sv_histsize ("HISTFILESIZE");
329 /* Read the history in HISTFILE into the history list. */
330 hf
= get_string_value ("HISTFILE");
332 if (hf
&& *hf
&& file_exists (hf
))
335 /* We have read all of the lines from the history file, even if we
336 read more lines than $HISTSIZE. Remember the total number of lines
337 we read so we don't count the last N lines as new over and over
339 history_lines_in_file
= history_lines_read_from_file
;
341 /* history_lines_in_file = where_history () + history_base - 1; */
346 bush_clear_history ()
349 history_lines_this_session
= 0;
350 /* XXX - reset history_lines_read_from_file? */
353 /* Delete and free the history list entry at offset I. */
355 bush_delete_histent (i
)
360 discard
= remove_history (i
);
363 free_history_entry (discard
);
364 history_lines_this_session
--;
370 bush_delete_history_range (first
, last
)
374 HIST_ENTRY
**discard_list
;
376 discard_list
= remove_history_range (first
, last
);
377 for (i
= 0; discard_list
&& discard_list
[i
]; i
++)
378 free_history_entry (discard_list
[i
]);
379 history_lines_this_session
-= i
;
385 bush_delete_last_history ()
388 HIST_ENTRY
**hlist
, *histent
;
391 hlist
= history_list ();
395 for (i
= 0; hlist
[i
]; i
++)
399 /* History_get () takes a parameter that must be offset by history_base. */
400 histent
= history_get (history_base
+ i
); /* Don't free this */
404 r
= bush_delete_histent (i
);
406 if (where_history () > history_length
)
407 history_set_pos (history_length
);
412 #ifdef INCLUDE_UNUSED
413 /* Write the existing history out to the history file. */
420 hf
= get_string_value ("HISTFILE");
421 if (hf
&& *hf
&& file_exists (hf
))
423 /* Append only the lines that occurred this session to
427 if (history_lines_this_session
<= where_history () || force_append_history
)
428 r
= append_history (history_lines_this_session
, hf
);
430 r
= write_history (hf
);
431 sv_histsize ("HISTFILESIZE");
437 maybe_append_history (filename
)
440 int fd
, result
, histlen
;
443 result
= EXECUTION_SUCCESS
;
444 if (history_lines_this_session
> 0)
446 /* If the filename was supplied, then create it if necessary. */
447 if (stat (filename
, &buf
) == -1 && errno
== ENOENT
)
449 fd
= open (filename
, O_WRONLY
|O_CREAT
, 0600);
452 builtin_error (_("%s: cannot create: %s"), filename
, strerror (errno
));
453 return (EXECUTION_FAILURE
);
457 /* cap the number of lines we write at the length of the history list */
458 histlen
= where_history ();
459 if (histlen
> 0 && history_lines_this_session
> histlen
)
460 history_lines_this_session
= histlen
; /* reset below anyway */
461 result
= append_history (history_lines_this_session
, filename
);
462 /* Pretend we already read these lines from the file because we just
464 history_lines_in_file
+= history_lines_this_session
;
465 history_lines_this_session
= 0;
468 history_lines_this_session
= 0; /* reset if > where_history() */
473 /* If this is an interactive shell, then append the lines executed
474 this session to the history file. */
476 maybe_save_shell_history ()
482 if (history_lines_this_session
> 0)
484 hf
= get_string_value ("HISTFILE");
488 /* If the file doesn't exist, then create it. */
489 if (file_exists (hf
) == 0)
492 file
= open (hf
, O_CREAT
| O_TRUNC
| O_WRONLY
, 0600);
497 /* Now actually append the lines if the history hasn't been
498 stifled. If the history has been stifled, rewrite the
501 if (history_lines_this_session
<= where_history () || force_append_history
)
503 result
= append_history (history_lines_this_session
, hf
);
504 history_lines_in_file
+= history_lines_this_session
;
508 result
= write_history (hf
);
509 history_lines_in_file
= history_lines_written_to_file
;
510 /* history_lines_in_file = where_history () + history_base - 1; */
512 history_lines_this_session
= 0;
514 sv_histsize ("HISTFILESIZE");
520 #if defined (READLINE)
521 /* Tell readline () that we have some text for it to edit. */
526 if (bush_input
.type
== st_stdin
)
529 #endif /* READLINE */
531 /* Return 1 if this line needs history expansion. */
533 history_expansion_p (line
)
538 for (s
= line
; *s
; s
++)
539 if (*s
== history_expansion_char
|| *s
== history_subst_char
)
544 /* Do pre-processing on LINE. If PRINT_CHANGES is non-zero, then
545 print the results of expanding the line if there were any changes.
546 If there is an error, return NULL, otherwise the expanded line is
547 returned. If ADDIT is non-zero the line is added to the history
548 list after history expansion. ADDIT is just a suggestion;
549 REMEMBER_ON_HISTORY can veto, and does.
550 Right now this does history expansion. */
552 pre_process_line (line
, print_changes
, addit
)
554 int print_changes
, addit
;
563 # if defined (BANG_HISTORY)
564 /* History expand the line. If this results in no errors, then
565 add that line to the history if ADDIT is non-zero. */
566 if (!history_expansion_inhibited
&& history_expansion
&& history_expansion_p (line
))
570 /* If we are expanding the second or later line of a multi-line
571 command, decrease history_length so references to history expansions
572 in these lines refer to the previous history entry and not the
574 old_len
= history_length
;
575 if (history_length
> 0 && command_oriented_history
&& current_command_first_line_saved
&& current_command_line_count
> 1)
577 expanded
= history_expand (line
, &history_value
);
578 if (history_length
>= 0 && command_oriented_history
&& current_command_first_line_saved
&& current_command_line_count
> 1)
579 history_length
= old_len
;
586 internal_error ("%s", history_value
);
587 #if defined (READLINE)
588 else if (hist_verify
== 0 || expanded
== 2)
592 fprintf (stderr
, "%s\n", history_value
);
595 /* If there was an error, return NULL. */
596 if (expanded
< 0 || expanded
== 2) /* 2 == print only */
598 # if defined (READLINE)
599 if (expanded
== 2 && rl_dispatching
== 0 && *history_value
)
601 if (expanded
== 2 && *history_value
)
602 # endif /* !READLINE */
603 maybe_add_history (history_value
);
605 free (history_value
);
607 # if defined (READLINE)
608 /* New hack. We can allow the user to edit the
609 failed history expansion. */
610 if (history_reediting
&& expanded
< 0 && rl_done
)
612 # endif /* READLINE */
613 return ((char *)NULL
);
616 # if defined (READLINE)
617 if (hist_verify
&& expanded
== 1)
619 re_edit (history_value
);
620 free (history_value
);
621 return ((char *)NULL
);
626 /* Let other expansions know that return_value can be free'ed,
627 and that a line has been added to the history list. Note
628 that we only add lines that have something in them. */
630 return_value
= history_value
;
632 # endif /* BANG_HISTORY */
634 if (addit
&& remember_on_history
&& *return_value
)
635 maybe_add_history (return_value
);
639 return_value
= savestring (line
);
642 return (return_value
);
645 /* Return 1 if the first non-whitespace character in LINE is a `#', indicating
646 that the line is a shell comment. Return 2 if there is a comment after the
647 first non-whitespace character. Return 0 if the line does not contain a
658 for (p
= line
; p
&& *p
&& whitespace (*p
); p
++)
662 n
= skip_to_delim (line
, p
- line
, "#", SD_NOJMP
|SD_GLOB
|SD_EXTGLOB
|SD_COMPLETE
);
663 return (line
[n
] == '#') ? 2 : 0;
666 #ifdef INCLUDE_UNUSED
667 /* Remove shell comments from LINE. A `#' and anything after it is a comment.
668 This isn't really useful yet, since it doesn't handle quoting. */
670 filter_comments (line
)
675 for (p
= line
; p
&& *p
&& *p
!= '#'; p
++)
683 /* Check LINE against what HISTCONTROL says to do. Returns 1 if the line
684 should be saved; 0 if it should be discarded. */
686 check_history_control (line
)
692 if (history_control
== 0)
695 /* ignorespace or ignoreboth */
696 if ((history_control
& HC_IGNSPACE
) && *line
== ' ')
699 /* ignoredups or ignoreboth */
700 if (history_control
& HC_IGNDUPS
)
703 temp
= previous_history ();
705 r
= (temp
== 0 || STREQ (temp
->line
, line
) == 0);
716 /* Remove all entries matching LINE from the history list. Triggered when
717 HISTCONTROL includes `erasedups'. */
726 while (temp
= previous_history ())
728 if (STREQ (temp
->line
, line
))
730 r
= where_history ();
731 temp
= remove_history (r
);
733 free_history_entry (temp
);
739 /* Add LINE to the history list, handling possibly multi-line compound
740 commands. We note whether or not we save the first line of each command
741 (which is usually the entire command and history entry), and don't add
742 the second and subsequent lines of a multi-line compound command if we
743 didn't save the first line. We don't usually save shell comment lines in
744 compound commands in the history, because they could have the effect of
745 commenting out the rest of the command when the entire command is saved as
746 a single history entry (when COMMAND_ORIENTED_HISTORY is enabled). If
747 LITERAL_HISTORY is set, we're saving lines in the history with embedded
748 newlines, so it's OK to save comment lines. If we're collecting the body
749 of a here-document, we should act as if literal_history is enabled, because
750 we want to save the entire contents of the here-document as it was
751 entered. We also make sure to save multiple-line quoted strings or other
754 maybe_add_history (line
)
759 hist_last_line_added
= 0;
760 is_comment
= (parser_state
& PST_HEREDOC
) ? 0 : shell_comment (line
);
762 /* Don't use the value of history_control to affect the second
763 and subsequent lines of a multi-line command (old code did
764 this only when command_oriented_history is enabled). */
765 if (current_command_line_count
> 1)
767 if (current_command_first_line_saved
&&
768 ((parser_state
& PST_HEREDOC
) || literal_history
|| dstack
.delimiter_depth
!= 0 || is_comment
!= 1))
769 bush_add_history (line
);
770 current_command_line_comment
= is_comment
? current_command_line_count
: -2;
774 /* This is the first line of a (possible multi-line) command. Note whether
775 or not we should save the first line and remember it. */
776 current_command_line_comment
= is_comment
? current_command_line_count
: -2;
777 current_command_first_line_saved
= check_add_history (line
, 0);
780 /* Just check LINE against HISTCONTROL and HISTIGNORE and add it to the
781 history if it's OK. Used by `history -s' as well as maybe_add_history().
782 Returns 1 if the line was saved in the history, 0 otherwise. */
784 check_add_history (line
, force
)
788 if (check_history_control (line
) && history_should_ignore (line
) == 0)
790 /* We're committed to saving the line. If the user has requested it,
791 remove other matching lines from the history. */
792 if (history_control
& HC_ERASEDUPS
)
797 really_add_history (line
);
801 bush_add_history (line
);
807 #if defined (SYSLOG_HISTORY)
808 #define SYSLOG_MAXMSG 1024
809 #define SYSLOG_MAXLEN SYSLOG_MAXMSG
810 #define SYSLOG_MAXHDR 256
813 #define OPENLOG_OPTS 0
816 #if defined (SYSLOG_SHOPT)
817 int syslog_history
= SYSLOG_SHOPT
;
819 int syslog_history
= 1;
823 bush_syslog_history (line
)
826 char trunc
[SYSLOG_MAXLEN
], *msg
;
827 char loghdr
[SYSLOG_MAXHDR
];
828 char seqbuf
[32], *seqnum
;
829 int hdrlen
, msglen
, seqlen
, chunks
, i
;
830 static int first
= 1;
834 openlog (shell_name
, OPENLOG_OPTS
, SYSLOG_FACILITY
);
838 hdrlen
= snprintf (loghdr
, sizeof(loghdr
), "HISTORY: PID=%d UID=%d", getpid(), current_user
.uid
);
839 msglen
= strlen (line
);
841 if ((msglen
+ hdrlen
+ 1) < SYSLOG_MAXLEN
)
842 syslog (SYSLOG_FACILITY
|SYSLOG_LEVEL
, "%s %s", loghdr
, line
);
845 chunks
= ((msglen
+ hdrlen
) / SYSLOG_MAXLEN
) + 1;
846 for (msg
= line
, i
= 0; i
< chunks
; i
++)
848 seqnum
= inttostr (i
+ 1, seqbuf
, sizeof (seqbuf
));
849 seqlen
= STRLEN (seqnum
);
852 strncpy (trunc
, msg
, SYSLOG_MAXLEN
- hdrlen
- seqlen
- 7 - 1);
853 trunc
[SYSLOG_MAXLEN
- 1] = '\0';
854 syslog (SYSLOG_FACILITY
|SYSLOG_LEVEL
, "%s (seq=%s) %s", loghdr
, seqnum
, trunc
);
855 msg
+= SYSLOG_MAXLEN
- hdrlen
- seqlen
- 8;
861 /* Add a line to the history list.
862 The variable COMMAND_ORIENTED_HISTORY controls the style of history
863 remembering; when non-zero, and LINE is not the first line of a
864 complete parser construct, append LINE to the last history line instead
865 of adding it as a new line. */
867 bush_add_history (line
)
870 int add_it
, offset
, curlen
, is_comment
;
871 HIST_ENTRY
*current
, *old
;
872 char *chars_to_add
, *new_line
;
875 if (command_oriented_history
&& current_command_line_count
> 1)
877 is_comment
= (parser_state
& PST_HEREDOC
) ? 0 : shell_comment (line
);
879 /* The second and subsequent lines of a here document have the trailing
880 newline preserved. We don't want to add extra newlines here, but we
881 do want to add one after the first line (which is the command that
882 contains the here-doc specifier). parse.y:history_delimiting_chars()
883 does the right thing to take care of this for us. We don't want to
884 add extra newlines if the user chooses to enable literal_history,
885 so we have to duplicate some of what that function does here. */
886 /* If we're in a here document and past the first line,
887 (current_command_line_count > 2)
888 don't add a newline here. This will also take care of the literal_history
889 case if the other conditions are met. */
890 if ((parser_state
& PST_HEREDOC
) && current_command_line_count
> 2 && line
[strlen (line
) - 1] == '\n')
892 else if (current_command_line_count
== current_command_line_comment
+1)
894 else if (literal_history
)
897 chars_to_add
= history_delimiting_chars (line
);
900 current
= previous_history ();
902 current_command_line_comment
= is_comment
? current_command_line_count
: -2;
906 /* If the previous line ended with an escaped newline (escaped
907 with backslash, but otherwise unquoted), then remove the quoted
908 newline, since that is what happens when the line is parsed. */
909 curlen
= strlen (current
->line
);
911 if (dstack
.delimiter_depth
== 0 && current
->line
[curlen
- 1] == '\\' &&
912 current
->line
[curlen
- 2] != '\\')
914 current
->line
[curlen
- 1] = '\0';
919 /* If we're not in some kind of quoted construct, the current history
920 entry ends with a newline, and we're going to add a semicolon,
921 don't. In some cases, it results in a syntax error (e.g., before
922 a close brace), and it should not be needed. */
923 if (dstack
.delimiter_depth
== 0 && current
->line
[curlen
- 1] == '\n' && *chars_to_add
== ';')
926 new_line
= (char *)xmalloc (1
929 + strlen (chars_to_add
));
930 sprintf (new_line
, "%s%s%s", current
->line
, chars_to_add
, line
);
931 offset
= where_history ();
932 old
= replace_history_entry (offset
, new_line
, current
->data
);
936 free_history_entry (old
);
942 if (add_it
&& history_is_stifled() && history_length
== 0 && history_length
== history_max_entries
)
946 really_add_history (line
);
948 #if defined (SYSLOG_HISTORY)
950 bush_syslog_history (line
);
957 really_add_history (line
)
960 hist_last_line_added
= 1;
961 hist_last_line_pushed
= 0;
963 history_lines_this_session
++;
970 return ((remember_on_history
|| enable_history_list
) ? history_base
+ where_history () : 1);
979 for (p
= s
; p
&& *p
; p
++)
990 histignore_item_func (ign
)
993 if (should_expand (ign
->val
))
994 ign
->flags
|= HIGN_EXPAND
;
999 setup_history_ignore (varname
)
1002 setup_ignore_patterns (&histignore
);
1006 last_history_entry ()
1011 he
= previous_history ();
1017 last_history_line ()
1021 he
= last_history_entry ();
1023 return ((char *)NULL
);
1028 expand_histignore_pattern (pat
)
1034 phe
= last_history_entry ();
1036 if (phe
== (HIST_ENTRY
*)0)
1037 return (savestring (pat
));
1039 ret
= strcreplace (pat
, '&', phe
->line
, 1);
1044 /* Return 1 if we should not put LINE into the history according to the
1045 patterns in HISTIGNORE. */
1047 history_should_ignore (line
)
1050 register int i
, match
;
1053 if (histignore
.num_ignores
== 0)
1056 for (i
= match
= 0; i
< histignore
.num_ignores
; i
++)
1058 if (histignore
.ignores
[i
].flags
& HIGN_EXPAND
)
1059 npat
= expand_histignore_pattern (histignore
.ignores
[i
].val
);
1061 npat
= histignore
.ignores
[i
].val
;
1063 match
= strmatch (npat
, line
, FNMATCH_EXTFLAG
) != FNM_NOMATCH
;
1065 if (histignore
.ignores
[i
].flags
& HIGN_EXPAND
)
1074 #endif /* HISTORY */