diff --git a/bin/sh/histedit.c b/bin/sh/histedit.c index 42858dccdf5c..55cf73bc4304 100644 --- a/bin/sh/histedit.c +++ b/bin/sh/histedit.c @@ -70,7 +70,7 @@ static const char rcsid[] = History *hist; /* history cookie */ EditLine *el; /* editline cookie */ int displayhist; -static FILE *el_in, *el_out; +static FILE *el_in, *el_out, *el_err; STATIC char *fc_replace __P((const char *, char *, char *)); @@ -105,11 +105,13 @@ histedit() INTOFF; if (el_in == NULL) el_in = fdopen(0, "r"); + if (el_err == NULL) + el_err = fdopen(1, "w"); if (el_out == NULL) el_out = fdopen(2, "w"); - if (el_in == NULL || el_out == NULL) + if (el_in == NULL || el_err == NULL || el_out == NULL) goto bad; - el = el_init(arg0, el_in, el_out); + el = el_init(arg0, el_in, el_out, el_err); if (el != NULL) { if (hist) el_set(el, EL_HIST, history, hist); @@ -151,12 +153,13 @@ sethistsize(hs) const char *hs; { int histsize; + HistEvent he; if (hist != NULL) { if (hs == NULL || *hs == '\0' || (histsize = atoi(hs)) < 0) histsize = 100; - history(hist, H_EVENT, histsize); + history(hist, &he, H_EVENT, histsize); } } @@ -171,9 +174,9 @@ histcmd(argc, argv) { int ch; char *editor = NULL; - const HistEvent *he; + HistEvent he; int lflg = 0, nflg = 0, rflg = 0, sflg = 0; - int i; + int i, retval; char *firststr, *laststr; int first, last, direction; char *pat = NULL, *repl; /* ksh "fc old=new" crap */ @@ -339,16 +342,16 @@ histcmd(argc, argv) * The history interface needs rethinking, as the following * convolutions will demonstrate. */ - history(hist, H_FIRST); - he = history(hist, H_NEXT_EVENT, first); - for (;he != NULL; he = history(hist, direction)) { + history(hist, &he, H_FIRST); + retval = history(hist, &he, H_NEXT_EVENT, first); + for (;retval != -1; retval = history(hist, &he, direction)) { if (lflg) { if (!nflg) - out1fmt("%5d ", he->num); - out1str(he->str); + out1fmt("%5d ", he.num); + out1str(he.str); } else { char *s = pat ? - fc_replace(he->str, pat, repl) : (char *)he->str; + fc_replace(he.str, pat, repl) : (char *)he.str; if (sflg) { if (displayhist) { @@ -360,7 +363,7 @@ histcmd(argc, argv) * XXX what about recursive and * relative histnums. */ - history(hist, H_ENTER, s); + history(hist, &he, H_ENTER, s); } } else fputs(s, efp); @@ -369,7 +372,7 @@ histcmd(argc, argv) * At end? (if we were to loose last, we'd sure be * messed up). */ - if (he->num == last) + if (he.num == last) break; } if (editor) { @@ -431,12 +434,12 @@ str_to_event(str, last) char *str; int last; { - const HistEvent *he; + HistEvent he; char *s = str; int relative = 0; - int i; + int i, retval; - he = history(hist, H_FIRST); + retval = history(hist, &he, H_FIRST); switch (*s) { case '-': relative = 1; @@ -447,33 +450,33 @@ str_to_event(str, last) if (is_number(s)) { i = atoi(s); if (relative) { - while (he != NULL && i--) { - he = history(hist, H_NEXT); + while (retval != -1 && i--) { + retval = history(hist, &he, H_NEXT); } - if (he == NULL) - he = history(hist, H_LAST); + if (retval == -1) + retval = history(hist, &he, H_LAST); } else { - he = history(hist, H_NEXT_EVENT, i); - if (he == NULL) { + retval = history(hist, &he, H_NEXT_EVENT, i); + if (retval == -1) { /* * the notion of first and last is * backwards to that of the history package */ - he = history(hist, last ? H_FIRST : H_LAST); + retval = history(hist, &he, last ? H_FIRST : H_LAST); } } - if (he == NULL) + if (retval == -1) error("history number %s not found (internal error)", str); } else { /* * pattern */ - he = history(hist, H_PREV_STR, str); - if (he == NULL) + retval = history(hist, &he, H_PREV_STR, str); + if (retval == -1) error("history pattern not found: %s", str); } - return (he->num); + return (he.num); } #else #include "error.h" diff --git a/bin/sh/input.c b/bin/sh/input.c index d75dfa4d7cc3..4532b26ad2ae 100644 --- a/bin/sh/input.c +++ b/bin/sh/input.c @@ -292,8 +292,10 @@ preadbuffer() #ifndef NO_HISTORY if (parsefile->fd == 0 && hist && something) { + HistEvent he; INTOFF; - history(hist, whichprompt == 1 ? H_ENTER : H_ADD, parsenextc); + history(hist, &he, whichprompt == 1 ? H_ENTER : H_ADD, + parsenextc); INTON; } #endif diff --git a/contrib/bind/bin/nslookup/commands.l b/contrib/bind/bin/nslookup/commands.l index 242f2e7ba80b..d1328630a7fe 100644 --- a/contrib/bind/bin/nslookup/commands.l +++ b/contrib/bind/bin/nslookup/commands.l @@ -125,14 +125,15 @@ nslookup_yy_input(buf, result, max_size, intr) { static EditLine *el = NULL; static History *hist = NULL; + HistEvent he; int num = 0; const char *bp = NULL; if (intr) { if (!el) { - el = el_init("nslookup", yyin, yyout); + el = el_init("nslookup", yyin, yyout, stderr); hist = history_init(); - history(hist, H_EVENT, 100); + history(hist, &he, H_EVENT, 100); el_set(el, EL_HIST, history, hist); el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_PROMPT, nslookup_prompt); @@ -147,7 +148,7 @@ nslookup_yy_input(buf, result, max_size, intr) *result = (num > max_size) ? max_size : num; strncpy(buf, bp, *result); - history(hist, H_ENTER, bp); + history(hist, &he, H_ENTER, bp); } else { if ( ((*result = fread( buf, 1, max_size, yyin )) == 0) && ferror( yyin ) ) diff --git a/include/Makefile b/include/Makefile index 1c4c8670df8f..a278a1fcffa1 100644 --- a/include/Makefile +++ b/include/Makefile @@ -107,6 +107,7 @@ copies: rm -f ${DESTDIR}/usr/include/$i; \ fi .endfor + install -d -o ${BINOWN} -g ${BINGRP} -m 755 ${DESTDIR}/usr/include mtree -deU ${MTREE_FOLLOWS_SYMLINKS} -f ${.CURDIR}/../etc/mtree/BSD.include.dist \ -p ${DESTDIR}/usr/include .for i in ${LDIRS} ${LSUBDIRS} diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index 43e0d263c026..fb72fb1cd713 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -220,15 +220,16 @@ cmdloop() struct cmdtable *cmdp; History *hist; EditLine *elptr; + HistEvent he; curinode = ginode(ROOTINO); curinum = ROOTINO; printactive(); hist = history_init(); - history(hist, H_EVENT, 100); /* 100 elt history buffer */ + history(hist, &he, H_EVENT, 100); /* 100 elt history buffer */ - elptr = el_init("fsdb", stdin, stdout); + elptr = el_init("fsdb", stdin, stdout, stderr); el_set(elptr, EL_EDITOR, "emacs"); el_set(elptr, EL_PROMPT, prompt); el_set(elptr, EL_HIST, history, hist); @@ -238,7 +239,7 @@ cmdloop() if (debug) printf("command `%s'\n", elline); - history(hist, H_ENTER, elline); + history(hist, &he, H_ENTER, elline); line = strdup(elline); cmd_argv = crack(line, &cmd_argc); diff --git a/usr.sbin/cdcontrol/cdcontrol.c b/usr.sbin/cdcontrol/cdcontrol.c index e8ab6c7a8493..3e272d3f66f7 100644 --- a/usr.sbin/cdcontrol/cdcontrol.c +++ b/usr.sbin/cdcontrol/cdcontrol.c @@ -1098,6 +1098,7 @@ input (int *cmd) #define MAXLINE 80 static EditLine *el = NULL; static History *hist = NULL; + HistEvent he; static char buf[MAXLINE]; int num = 0; int len; @@ -1107,9 +1108,10 @@ input (int *cmd) do { if (verbose) { if (!el) { - el = el_init("cdcontrol", stdin, stdout); + el = el_init("cdcontrol", stdin, stdout, + stderr); hist = history_init(); - history(hist, H_EVENT, 100); + history(hist, &he, H_EVENT, 100); el_set(el, EL_HIST, history, hist); el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_PROMPT, cdcontrol_prompt); @@ -1125,7 +1127,7 @@ input (int *cmd) len = (num > MAXLINE) ? MAXLINE : num; memcpy(buf, bp, len); buf[len] = 0; - history(hist, H_ENTER, bp); + history(hist, &he, H_ENTER, bp); #undef MAXLINE } else { diff --git a/usr.sbin/lpr/lpc/lpc.c b/usr.sbin/lpr/lpc/lpc.c index 5c890f42f096..457ad70600f4 100644 --- a/usr.sbin/lpr/lpc/lpc.c +++ b/usr.sbin/lpr/lpc/lpc.c @@ -150,6 +150,7 @@ cmdscanner(void) register struct cmd *c; static EditLine *el; static History *hist; + HistEvent he; size_t len; int num; const char *bp; @@ -161,9 +162,9 @@ cmdscanner(void) for (;;) { if (fromatty) { if (!el) { - el = el_init("lpc", stdin, stdout); + el = el_init("lpc", stdin, stdout, stderr); hist = history_init(); - history(hist, H_EVENT, 100); + history(hist, &he, H_EVENT, 100); el_set(el, EL_HIST, history, hist); el_set(el, EL_EDITOR, "emacs"); el_set(el, EL_PROMPT, lpc_prompt); @@ -185,7 +186,7 @@ cmdscanner(void) len = (num > MAX_CMDLINE) ? MAX_CMDLINE : num; memcpy(cmdline, bp, len); cmdline[len] = 0; - history(hist, H_ENTER, bp); + history(hist, &he, H_ENTER, bp); } else { if (fgets(cmdline, MAX_CMDLINE, stdin) == 0) diff --git a/usr.sbin/pppctl/pppctl.c b/usr.sbin/pppctl/pppctl.c index be9b73cff0b9..a83354db07eb 100644 --- a/usr.sbin/pppctl/pppctl.c +++ b/usr.sbin/pppctl/pppctl.c @@ -273,7 +273,7 @@ Terminal(void *v) struct thread_data *td; const char *l; int len; -#ifdef __NetBSD__ +#ifndef __OpenBSD__ HistEvent hev = { 0, "" }; #endif @@ -287,10 +287,10 @@ Terminal(void *v) while ((l = SmartGets(td->edit, &len, td->ppp))) { if (len > 1) -#ifdef __NetBSD__ - history(td->hist, &hev, H_ENTER, l); -#else +#ifdef __OpenBSD__ history(td->hist, H_ENTER, l); +#else + history(td->hist, &hev, H_ENTER, l); #endif write(td->ppp, l, len); if (Receive(td->ppp, REC_SHOW) != 0) @@ -543,7 +543,7 @@ main(int argc, char **argv) struct thread_data td; const char *env; int size; -#ifdef __NetBSD__ +#ifndef __OpenBSD__ HistEvent hev = { 0, "" }; #endif @@ -554,12 +554,12 @@ main(int argc, char **argv) size = 20; } else size = 20; -#ifdef __NetBSD__ - history(td.hist, &hev, H_SETSIZE, size); - td.edit = el_init("pppctl", stdin, stdout, stderr); -#else +#ifdef __OpenBSD__ history(td.hist, H_EVENT, size); td.edit = el_init("pppctl", stdin, stdout); +#else + history(td.hist, &hev, H_SETSIZE, size); + td.edit = el_init("pppctl", stdin, stdout, stderr); #endif el_source(td.edit, NULL); el_set(td.edit, EL_PROMPT, GetPrompt);