Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ HFILES = config.h es.h gc.h input.h prim.h print.h sigmsgs.h \
CFILES = access.c closure.c conv.c dict.c eval.c except.c fd.c gc.c glob.c \
glom.c input.c heredoc.c history.c list.c main.c match.c open.c opt.c \
prim-ctl.c prim-etc.c prim-io.c prim-sys.c prim.c print.c proc.c \
sigmsgs.c signal.c split.c status.c str.c syntax.c term.c token.c \
tree.c util.c var.c vec.c version.c y.tab.c dump.c
readline.c sigmsgs.c signal.c split.c status.c str.c syntax.c term.c \
token.c tree.c util.c var.c vec.c version.c y.tab.c dump.c
OFILES = access.o closure.o conv.o dict.o eval.o except.o fd.o gc.o glob.o \
glom.o input.o heredoc.o history.o list.o main.o match.o open.o opt.o \
prim-ctl.o prim-etc.o prim-io.o prim-sys.o prim.o print.o proc.o \
sigmsgs.o signal.o split.o status.o str.o syntax.o term.o token.o \
tree.o util.o var.o vec.o version.o y.tab.o
readline.o sigmsgs.o signal.o split.o status.o str.o syntax.o term.o \
token.o tree.o util.o var.o vec.o version.o y.tab.o
OTHER = Makefile parse.y mksignal
GEN = esdump y.tab.h y.output sigmsgs.c initial.c version.h

Expand Down Expand Up @@ -147,6 +147,7 @@ prim-io.o : prim-io.c es.h config.h stdenv.h gc.h prim.h
prim-sys.o : prim-sys.c es.h config.h stdenv.h prim.h
print.o : print.c es.h config.h stdenv.h print.h
proc.o : proc.c es.h config.h stdenv.h prim.h
readline.o : readline.c es.h config.h stdenv.h prim.h
signal.o : signal.c es.h config.h stdenv.h sigmsgs.h
split.o : split.c es.h config.h stdenv.h gc.h
status.o : status.c es.h config.h stdenv.h term.h
Expand Down
10 changes: 8 additions & 2 deletions doc/es.1
Original file line number Diff line number Diff line change
Expand Up @@ -2800,11 +2800,17 @@ library:
.ta 2i
.Ds
.ft \*(Cf
resetterminal sethistory
setmaxhistorylength writehistory
readline resetterminal
sethistory setmaxhistorylength
writehistory
.ft R
.De
.PP
.Cr readline
reads from standard input, using the
.I readline
library, taking a single optional prompt argument and returning a string
containing the line it read or the empty list on EOF.
.Cr sethistory
and
.Cr setmaxhistorylength
Expand Down
10 changes: 6 additions & 4 deletions es.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ extern List *runstring(const char *str, const char *name, int flags);
#define run_printcmds 32 /* -x */
#define run_lisptrees 64 /* -L and defined(LISPTREES) */


#if HAVE_READLINE
extern Boolean resetterminal;
#endif
/* readline.c */

extern Boolean resetterminal;
extern char *callreadline(char *prompt);

/* history.c */
#if HAVE_READLINE
extern void inithistory(void);

extern void sethistory(char *file);
Expand All @@ -319,6 +319,8 @@ extern void setmaxhistorylength(int length);
extern void checkhistory(void);
#endif


/* history.c */
extern void newhistbuffer(void);
extern void addhistbuffer(char c);
extern char *dumphistbuffer(void);
Expand Down
113 changes: 0 additions & 113 deletions history.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,6 @@

static Buffer *histbuffer = NULL;

#if HAVE_READLINE
#include <readline/history.h>

Boolean reloadhistory = FALSE;
static char *history;

#if 0
/* These split history file entries by timestamp, which allows readline to pick up
* multi-line commands correctly across process boundaries. Disabled by default,
* because it leaves the history file itself kind of ugly. */
static int history_write_timestamps = 1;
static char history_comment_char = '#';
#endif
#endif


/*
* histbuffer -- build the history line during input and dump it as a gc-string
Expand Down Expand Up @@ -63,101 +48,3 @@ extern char *dumphistbuffer(void) {
s[len - 1] = '\0';
return s;
}


/*
* history file
*/

#if HAVE_READLINE
static int sethistorylength = -1; /* unlimited */

extern void setmaxhistorylength(int len) {
sethistorylength = len;
}

extern void loghistory(char *cmd) {
int err;
if (cmd == NULL)
return;
add_history(cmd);
if (history == NULL)
return;

if ((err = append_history(1, history))) {
eprint("history(%s): %s\n", history, esstrerror(err));
vardef("history", NULL, NULL);
}
}

static int count_history(void) {
int i, n, count = 0, fd = eopen(history, oOpen);
char buf[4096];
if (fd < 0)
return -1;
while ((n = read(fd, &buf, 4096)) != 0) {
if (n < 0) {
if (errno == EINTR) {
SIGCHK();
continue;
} else {
close(fd);
return -1;
}
}
for (i = 0; i < n; i++)
if (buf[i] == '\n')
count++;
}
close(fd);
return count;
}

static void reload_history(void) {
/* Attempt to populate readline history with new history file. */
if (history != NULL) {
int n = count_history() - sethistorylength;
if (sethistorylength < 0 || n < 0) n = 0;
read_history_range(history, n, -1);
}
using_history();

reloadhistory = FALSE;
}

extern void sethistory(char *file) {
if (reloadhistory)
reload_history();
reloadhistory = TRUE;
history = file;
}

extern void checkhistory(void) {
static int effectivelength = -1;
if (reloadhistory)
reload_history();
if (sethistorylength != effectivelength) {
switch (sethistorylength) {
case -1:
unstifle_history();
break;
case 0:
clear_history();
FALLTHROUGH;
default:
stifle_history(sethistorylength);
}
effectivelength = sethistorylength;
}
}

/*
* initialization
*/

/* inithistory -- called at dawn of time from main() */
extern void inithistory(void) {
/* declare the global roots */
globalroot(&history); /* history file */
}
#endif
Loading