From accab6ee102110213b1dc046fc3eba1945c20010 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 9 Mar 2020 19:39:15 -0400 Subject: Add HISTFILE history saving --- bin/1sh/histedit.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'bin/1sh/histedit.c') diff --git a/bin/1sh/histedit.c b/bin/1sh/histedit.c index 520b4554..9784b1f1 100644 --- a/bin/1sh/histedit.c +++ b/bin/1sh/histedit.c @@ -69,6 +69,9 @@ EditLine *el; /* editline cookie */ int displayhist; static FILE *el_in, *el_out, *el_err; +static void history_load(const char *hf); +static void history_save(const char *hf); + static char *fc_replace(const char *, char *, char *); static int not_fcnumber(const char *); static int str_to_event(const char *, int); @@ -92,9 +95,10 @@ histedit(void) hist = history_init(); INTON; - if (hist != NULL) + if (hist != NULL) { sethistsize(histsizeval()); - else + sethistfile(histfileval()); + } else out2fmt_flush("sh: can't initialize history\n"); } if (editing && !el && isatty(0)) { /* && isatty(2) ??? */ @@ -152,6 +156,8 @@ bad: el = NULL; } if (hist) { + if (*histfileval() != '\0') + history_save(histfileval()); history_end(hist); hist = NULL; } @@ -160,6 +166,34 @@ bad: } +void +sethistfile(const char *hf) +{ + if (hist != NULL && hf != NULL && *hf != '\0') + history_load(hf); +} + + +static void +history_load(const char *hf) +{ + HistEvent he; + + if (history(hist, &he, H_LOAD, hf) == -1) + warning("%s: %s", he.str, hf); +} + + +static void +history_save(const char *hf) +{ + HistEvent he; + + if (history(hist, &he, H_SAVE, hf) == -1) + warning("%s: %s", he.str, hf); +} + + void sethistsize(const char *hs) { -- cgit 1.4.1