diff --git a/config.h.in b/config.h.in index 5e4085b..834ba6f 100644 --- a/config.h.in +++ b/config.h.in @@ -18,7 +18,7 @@ /* Define to enable SIGSTOP (Ctrl-Z) key. */ #undef CONFIG_SIGSTOP -/* Don't save command if same as last one. */ +/* Define to skip duplicate lines in the scrollback history. */ #undef CONFIG_UNIQUE_HISTORY /* Define to use the termcap library for terminal size. */ @@ -115,9 +115,6 @@ /* Enable static keyword, hides internal methods. */ #undef HIDE -/* Number of lines in history. */ -#undef HIST_SIZE - /* Define to 1 if `lstat' dereferences a symlink specified with a trailing slash. */ #undef LSTAT_FOLLOWS_SLASHED_SYMLINK diff --git a/configure b/configure index 7448e97..5563ad8 100755 --- a/configure +++ b/configure @@ -869,13 +869,12 @@ with_pic enable_fast_install with_gnu_ld enable_libtool_lock +enable_unique_history enable_default_complete enable_arrow_keys enable_sigstop enable_terminal_bell enable_termcap -enable_history -enable_unique_history ' ac_precious_vars='build_alias host_alias @@ -1514,13 +1513,14 @@ Optional Features: --enable-fast-install[=PKGS] optimize for fast installation [default=yes] --disable-libtool-lock avoid locking (might break parallel builds) + --disable-unique-history + Disable uniqify of scrollback. Default: duplicate + entries are ignored. Use this to save dupes. --enable-default-complete Enable default completion handler. --enable-arrow-keys Enable ANSI arrow keys. --enable-sigstop Enable SIGSTOP key. --enable-terminal-bell Enable terminal bell on completion. --enable-termcap Use the termcap library for terminal size. - --enable-history=LINES Enable scrollback history, default off. - --enable-unique-history Uniqify scrollback history, i.e., don't save dupes. Optional Packages: --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] @@ -11130,6 +11130,16 @@ fi done +# Check whether --enable-unique-history was given. +if test "${enable_unique_history+set}" = set; then : + enableval=$enable_unique_history; +else + +$as_echo "#define CONFIG_UNIQUE_HISTORY 1" >>confdefs.h + +fi + + # Check whether --enable-default-complete was given. if test "${enable_default_complete+set}" = set; then : enableval=$enable_default_complete; complete=true; @@ -11178,30 +11188,6 @@ $as_echo "#define CONFIG_USE_TERMCAP /**/" >>confdefs.h fi -# Default history size 1, i.e. disabled. -let HIST_SIZE=1 -# Check whether --enable-history was given. -if test "${enable_history+set}" = set; then : - enableval=$enable_history; let HIST_SIZE=$enableval -fi - -if test $HIST_SIZE -lt 1; then - let HIST_SIZE=1 -fi - -cat >>confdefs.h <<_ACEOF -#define HIST_SIZE $HIST_SIZE -_ACEOF - - -# Check whether --enable-unique-history was given. -if test "${enable_unique_history+set}" = set; then : - enableval=$enable_unique_history; -$as_echo "#define CONFIG_UNIQUE_HISTORY /**/" >>confdefs.h - -fi - - # Restore gnu89 inline semantics on gcc 4.3 and newer saved_cflags="$CFLAGS" CFLAGS="$CFLAGS -fgnu89-inline" diff --git a/configure.ac b/configure.ac index 4b155cc..6905385 100644 --- a/configure.ac +++ b/configure.ac @@ -52,6 +52,11 @@ AC_PROG_GCC_TRADITIONAL AC_FUNC_STAT AC_CHECK_FUNCS([strchr strdup strrchr tcgetattr perror]) +AC_ARG_ENABLE(unique-history, + [AS_HELP_STRING([--disable-unique-history], + [Disable uniqify of scrollback. Default: duplicate entries are ignored. Use this to save dupes.])], + , AC_DEFINE(CONFIG_UNIQUE_HISTORY, 1, [Define to skip duplicate lines in the scrollback history.])) + AC_ARG_ENABLE(default-complete, [ --enable-default-complete Enable default completion handler.], complete=true; AC_DEFINE(CONFIG_DEFAULT_COMPLETE,, [Define to enable the default completion handler.])) @@ -73,20 +78,6 @@ AC_ARG_ENABLE(termcap, [ --enable-termcap Use the termcap library for terminal size.], AC_DEFINE([CONFIG_USE_TERMCAP],, [Define to use the termcap library for terminal size.])) -# Default history size 1, i.e. disabled. -let HIST_SIZE=1 -AC_ARG_ENABLE(history, - [ --enable-history=LINES Enable scrollback history, default off.], - let HIST_SIZE=$enableval) -if test $HIST_SIZE -lt 1; then - let HIST_SIZE=1 -fi -AC_DEFINE_UNQUOTED(HIST_SIZE, $HIST_SIZE, [Number of lines in history.]) - -AC_ARG_ENABLE(unique-history, - [ --enable-unique-history Uniqify scrollback history, i.e., don't save dupes.], - AC_DEFINE([CONFIG_UNIQUE_HISTORY],, [Don't save command if same as last one.])) - # Restore gnu89 inline semantics on gcc 4.3 and newer saved_cflags="$CFLAGS" CFLAGS="$CFLAGS -fgnu89-inline" diff --git a/include/editline.h b/include/editline.h index b0d7969..a27d7b5 100644 --- a/include/editline.h +++ b/include/editline.h @@ -47,9 +47,11 @@ extern int rl_mark; extern int rl_end; extern char *rl_line_buffer; extern const char *rl_readline_name; -extern int el_no_echo; /* e.g under emacs, don't echo except prompt */ -extern void rl_reset_terminal(char *p); +extern int el_no_echo; /* e.g under emacs, don't echo except prompt */ +extern int el_hist_size; /* size of history scrollback buffer, default: 15 */ + extern void rl_initialize(void); +extern void rl_reset_terminal(char *p); extern char *readline(const char *prompt); extern void add_history(const char *line); diff --git a/src/editline.c b/src/editline.c index 41054b4..9304c00 100644 --- a/src/editline.c +++ b/src/editline.c @@ -38,9 +38,6 @@ #define META(x) ((x) | 0x80) #define ISMETA(x) ((x) & 0x80) #define UNMETA(x) ((x) & 0x7F) -#ifndef HIST_SIZE /* Default to one line history, i.e. disabled. */ -#define HIST_SIZE 1 -#endif #define SEPS "\"#$&'()*:;<=>?[\\]^`{|}~\n\t " /* @@ -64,7 +61,7 @@ typedef struct { typedef struct { int Size; int Pos; - char *Lines[HIST_SIZE]; + char **Lines; } el_hist_t; /* @@ -79,12 +76,18 @@ int rl_quit; int rl_susp; #endif +int el_hist_size = 15; +static el_hist_t H = { + .Size = 0, + .Pos = 0, + .Lines = NULL, +}; + static char NILSTR[] = ""; static const char *el_input = NILSTR; static char *Yanked; static char *Screen; static char NEWLINE[]= CRLF; -static el_hist_t H; static int Repeat; static int old_point; static int el_push_back; @@ -1000,6 +1003,12 @@ static char *editinput(void) return NULL; } +static void hist_alloc(void) +{ + if (!H.Lines) + H.Lines = calloc(el_hist_size, sizeof(char *)); +} + static void hist_add(const char *p) { int i; @@ -1014,11 +1023,11 @@ static void hist_add(const char *p) if ((s = strdup(p)) == NULL) return; - if (H.Size < HIST_SIZE) { + if (H.Size < el_hist_size) { H.Lines[H.Size++] = s; } else { free(H.Lines[0]); - for (i = 0; i < HIST_SIZE - 1; i++) + for (i = 0; i < el_hist_size - 1; i++) H.Lines[i] = H.Lines[i + 1]; H.Lines[i] = s; } @@ -1072,6 +1081,8 @@ void rl_initialize(void) { if (!rl_prompt) rl_prompt = "? "; + + hist_alloc(); } char *readline(const char *prompt)