now removes *all* trailing newlines (by reusing histsave result, saves code),
plus plugs an ancient memory leak (hist_execute afree’s its arg now); also partial revert of commitid 78014291f06497b3 as COMPLEX_HISTORY handles multi-line commands correctly now (r1.4, 2005-05-23)
This commit is contained in:
6
check.t
6
check.t
@@ -1,4 +1,4 @@
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.696 2015/07/05 15:12:04 tg Exp $
|
||||
# $MirOS: src/bin/mksh/check.t,v 1.697 2015/07/05 17:04:24 tg Exp $
|
||||
# -*- mode: sh -*-
|
||||
#-
|
||||
# Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
@@ -3582,7 +3582,7 @@ expected-stdout:
|
||||
a new line
|
||||
1 echo abc def
|
||||
2 echo FOOBAR def
|
||||
3 echo a new line
|
||||
echo a new line
|
||||
expected-stderr-pattern:
|
||||
/^X*echo FOOBAR def\necho a new line\nX*$/
|
||||
---
|
||||
@@ -3664,7 +3664,7 @@ expected-stdout:
|
||||
a new line
|
||||
1 echo abc def
|
||||
2 echo FOOBAR def
|
||||
3 echo a new line
|
||||
echo a new line
|
||||
expected-stderr-pattern:
|
||||
/^X*13\n32\necho FOOBAR def\necho a new line\nX*$/
|
||||
---
|
||||
|
17
histrap.c
17
histrap.c
@@ -27,7 +27,7 @@
|
||||
#include <sys/file.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.145 2015/07/05 16:48:28 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.146 2015/07/05 17:04:26 tg Exp $");
|
||||
|
||||
Trap sigtraps[ksh_NSIG + 1];
|
||||
static struct sigaction Sigact_ign;
|
||||
@@ -38,7 +38,7 @@ static int writehistline(int, int, const char *);
|
||||
static void writehistfile(int, const char *);
|
||||
#endif
|
||||
|
||||
static int hist_execute(char *);
|
||||
static int hist_execute(char *, Area *);
|
||||
static char **hist_get(const char *, bool, bool);
|
||||
static char **hist_get_oldest(void);
|
||||
|
||||
@@ -223,7 +223,7 @@ c_fc(const char **wp)
|
||||
xp += len;
|
||||
line = Xclose(xs, xp);
|
||||
}
|
||||
return (hist_execute(line));
|
||||
return (hist_execute(line, ATEMP));
|
||||
}
|
||||
|
||||
if (editor && (lflag || nflag)) {
|
||||
@@ -360,13 +360,13 @@ c_fc(const char **wp)
|
||||
shf_close(shf);
|
||||
*xp = '\0';
|
||||
strip_nuls(Xstring(xs, xp), Xlength(xs, xp));
|
||||
return (hist_execute(Xstring(xs, xp)));
|
||||
return (hist_execute(Xstring(xs, xp), hist_source->areap));
|
||||
}
|
||||
}
|
||||
|
||||
/* Save cmd in history, execute cmd (cmd gets trashed) */
|
||||
/* save cmd in history, execute cmd (cmd gets afree’d) */
|
||||
static int
|
||||
hist_execute(char *cmd)
|
||||
hist_execute(char *cmd, Area *areap)
|
||||
{
|
||||
static int last_line = -1;
|
||||
Source *sold;
|
||||
@@ -381,6 +381,11 @@ hist_execute(char *cmd)
|
||||
}
|
||||
|
||||
histsave(&hist_source->line, cmd, true, true);
|
||||
/* now *histptr == cmd without all trailing newlines */
|
||||
afree(cmd, areap);
|
||||
cmd = *histptr;
|
||||
/* pdksh says POSIX doesn’t say this is done, testsuite needs it */
|
||||
shellf("%s\n", cmd);
|
||||
|
||||
/*-
|
||||
* Commands are executed here instead of pushing them onto the
|
||||
|
Reference in New Issue
Block a user