make certain actions flush the history buffer
This commit is contained in:
parent
e0196f47d5
commit
2e4cd72899
16
histrap.c
16
histrap.c
@ -27,7 +27,7 @@
|
|||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.147 2015/07/05 19:37:15 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.148 2015/07/05 19:53:45 tg Exp $");
|
||||||
|
|
||||||
Trap sigtraps[ksh_NSIG + 1];
|
Trap sigtraps[ksh_NSIG + 1];
|
||||||
static struct sigaction Sigact_ign;
|
static struct sigaction Sigact_ign;
|
||||||
@ -84,6 +84,9 @@ static const char TFCEDIT_dollaru[] = "${FCEDIT:-/bin/ed} $_";
|
|||||||
/* maximum considered size of persistent history file */
|
/* maximum considered size of persistent history file */
|
||||||
#define MKSH_MAXHISTFSIZE ((off_t)1048576 * 96)
|
#define MKSH_MAXHISTFSIZE ((off_t)1048576 * 96)
|
||||||
|
|
||||||
|
/* hidden option */
|
||||||
|
#define HIST_DISCARD 5
|
||||||
|
|
||||||
int
|
int
|
||||||
c_fc(const char **wp)
|
c_fc(const char **wp)
|
||||||
{
|
{
|
||||||
@ -567,6 +570,7 @@ sethistfile(const char *name)
|
|||||||
afree(hname, APERM);
|
afree(hname, APERM);
|
||||||
hname = NULL;
|
hname = NULL;
|
||||||
/* let's reset the history */
|
/* let's reset the history */
|
||||||
|
histsave(NULL, NULL, HIST_DISCARD, true);
|
||||||
histptr = history - 1;
|
histptr = history - 1;
|
||||||
hist_source->line = 0;
|
hist_source->line = 0;
|
||||||
}
|
}
|
||||||
@ -601,6 +605,8 @@ histsync(void)
|
|||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
|
|
||||||
|
/* called by histsave(), may not HIST_DISCARD, caller should flush */
|
||||||
|
|
||||||
if (histfd != -1) {
|
if (histfd != -1) {
|
||||||
int lno = hist_source->line;
|
int lno = hist_source->line;
|
||||||
|
|
||||||
@ -626,6 +632,12 @@ histsave(int *lnp, const char *cmd, int svmode, bool ignoredups)
|
|||||||
char **hp, *c;
|
char **hp, *c;
|
||||||
const char *ccp;
|
const char *ccp;
|
||||||
|
|
||||||
|
if (svmode == HIST_DISCARD) {
|
||||||
|
afree(enqueued, APERM);
|
||||||
|
enqueued = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (svmode == HIST_APPEND) {
|
if (svmode == HIST_APPEND) {
|
||||||
if (!enqueued)
|
if (!enqueued)
|
||||||
svmode = HIST_STORE;
|
svmode = HIST_STORE;
|
||||||
@ -734,6 +746,8 @@ hist_init(Source *s)
|
|||||||
enum { hist_init_first, hist_init_retry, hist_init_restore } hs;
|
enum { hist_init_first, hist_init_retry, hist_init_restore } hs;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
histsave(NULL, NULL, HIST_DISCARD, true);
|
||||||
|
|
||||||
if (Flag(FTALKING) == 0)
|
if (Flag(FTALKING) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
6
lex.c
6
lex.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.203 2015/07/05 19:37:16 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.204 2015/07/05 19:53:46 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* states while lexing word
|
* states while lexing word
|
||||||
@ -1474,8 +1474,10 @@ getsc_line(Source *s)
|
|||||||
cp = Xstring(s->xs, xp);
|
cp = Xstring(s->xs, xp);
|
||||||
while (*cp && ctype(*cp, C_IFSWS))
|
while (*cp && ctype(*cp, C_IFSWS))
|
||||||
++cp;
|
++cp;
|
||||||
if (!*cp)
|
if (!*cp) {
|
||||||
|
histsave(&s->line, NULL, HIST_FLUSH, true);
|
||||||
histsync();
|
histsync();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (interactive)
|
if (interactive)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user