diff --git a/edit.c b/edit.c index c391c43..1ea734e 100644 --- a/edit.c +++ b/edit.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.133 2008/09/30 17:49:24 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.134 2008/09/30 19:25:49 tg Exp $"); /* tty driver characters we are interested in */ typedef struct { @@ -3154,8 +3154,7 @@ x_edit_line(int c __unused) } if (modified) { *xep = '\0'; - source->line++; - histsave(source->line, xbuf, true); + histsave(&source->line, xbuf, true, true); x_arg = 0; } else x_arg = source->line - (histptr - x_histp); @@ -4365,8 +4364,8 @@ vi_cmd(int argcnt, const char *cmd) if (!argcnt) { if (modified) { es->cbuf[es->linelen] = '\0'; - source->line++; - histsave(source->line, es->cbuf, true); + histsave(&source->line, es->cbuf, true, + true); } else argcnt = source->line + 1 - (hlast - hnum); diff --git a/funcs.c b/funcs.c index bf22090..ffb070e 100644 --- a/funcs.c +++ b/funcs.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.88 2008/09/30 17:49:25 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.89 2008/09/30 19:25:50 tg Exp $"); /* A leading = means assignments before command are kept; * a leading * means a POSIX special builtin; @@ -502,8 +502,7 @@ c_print(const char **wp) if (flags & PO_HIST) { Xput(xs, xp, '\0'); - source->line++; - histsave(source->line, Xstring(xs, xp), true); + histsave(&source->line, Xstring(xs, xp), true, false); Xfree(xs, xp); } else { int n, len = Xlength(xs, xp); @@ -1894,8 +1893,7 @@ c_read(const char **wp) shf_flush(shf); if (historyr) { Xput(xs, xp, '\0'); - source->line++; - histsave(source->line, Xstring(xs, xp), true); + histsave(&source->line, Xstring(xs, xp), true, false); Xfree(xs, xp); } /* if this is the co-process fd, close the file descriptor diff --git a/histrap.c b/histrap.c index ab10332..4585c2a 100644 --- a/histrap.c +++ b/histrap.c @@ -3,7 +3,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.68 2008/09/30 17:49:26 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.69 2008/09/30 19:25:51 tg Exp $"); /*- * MirOS: This is the default mapping type, and need not be specified. @@ -280,7 +280,8 @@ hist_execute(char *cmd) if (!*q) /* ignore trailing newline */ q = NULL; } - histsave(++(hist_source->line), p, true); + /* setting ignoredups to true breaks history-e-minus-5 */ + histsave(&hist_source->line, p, true, false); shellf("%s\n", p); /* POSIX doesn't say this is done... */ if ((p = q)) /* restore \n (trailing \n not restored) */ @@ -574,7 +575,7 @@ init_histvec(void) * save command in history */ void -histsave(int lno __unused, const char *cmd, bool dowrite __unused) +histsave(int *lnp, const char *cmd, bool dowrite __unused, bool ignoredups) { char **hp; char *c, *cp; @@ -583,9 +584,15 @@ histsave(int lno __unused, const char *cmd, bool dowrite __unused) if ((cp = strchr(c, '\n')) != NULL) *cp = '\0'; + if (ignoredups && !strcmp(c, *histptr)) { + afree(c, APERM); + return; + } + ++*lnp; + #if HAVE_PERSISTENT_HISTORY if (histfd && dowrite) - writehistfile(lno, c); + writehistfile(*lnp, c); #endif hp = histptr; @@ -824,8 +831,8 @@ static void histload(Source *s, unsigned char *base, int bytes) { State state; - int lno = 0; - unsigned char *line = NULL; + int lno = 0; + unsigned char *line = NULL; for (state = shdr; bytes-- > 0; base++) { switch (state) { @@ -857,8 +864,8 @@ histload(Source *s, unsigned char *base, int bytes) /* a replacement ? */ histinsert(s, lno, (char *)line); } else { - s->line = lno; - histsave(lno, (char *)line, false); + s->line = lno--; + histsave(&lno, line, false, false); } state = shdr; } diff --git a/lex.c b/lex.c index 21790bc..f7dbb89 100644 --- a/lex.c +++ b/lex.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.69 2008/09/30 17:58:49 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.70 2008/09/30 19:25:51 tg Exp $"); /* * states while lexing word @@ -1242,15 +1242,7 @@ getsc_line(Source *s) } else if (interactive) { char *p = Xstring(s->xs, xp); if (*p && (cur_prompt != PS1 || !ctype(*p, C_IFS | C_IFSWS))) { - if ((p = strchr(p, '\n')) != NULL) - *p = '\0'; - /* ignore dups */ - if (strcmp(s->str, *histptr)) { - s->line++; - histsave(s->line, s->str, true); - } - if (p != NULL) - *p = '\n'; + histsave(&s->line, s->str, true, true); } } if (interactive) diff --git a/sh.h b/sh.h index d599b4c..8197d39 100644 --- a/sh.h +++ b/sh.h @@ -100,7 +100,7 @@ #define __SCCSID(x) __IDSTRING(sccsid,x) #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.235 2008/09/30 18:43:07 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.236 2008/09/30 19:25:51 tg Exp $"); #endif #define MKSH_VERSION "R35 2008/09/30" @@ -1306,7 +1306,7 @@ void hist_init(Source *); #if HAVE_PERSISTENT_HISTORY void hist_finish(void); #endif -void histsave(int, const char *, bool); +void histsave(int *, const char *, bool, bool); int c_fc(const char **); void sethistsize(int); #if HAVE_PERSISTENT_HISTORY