Allocate history scrollback buffer at runtime instead of at configure.

Also make sure "unique history" is enabled by default in configure.
This commit is contained in:
Joachim Nilsson 2010-08-04 02:12:19 +02:00
parent 55aaddbc54
commit 04a0cbd902
5 changed files with 42 additions and 55 deletions

View File

@ -18,7 +18,7 @@
/* Define to enable SIGSTOP (Ctrl-Z) key. */ /* Define to enable SIGSTOP (Ctrl-Z) key. */
#undef CONFIG_SIGSTOP #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 #undef CONFIG_UNIQUE_HISTORY
/* Define to use the termcap library for terminal size. */ /* Define to use the termcap library for terminal size. */
@ -115,9 +115,6 @@
/* Enable static keyword, hides internal methods. */ /* Enable static keyword, hides internal methods. */
#undef HIDE #undef HIDE
/* Number of lines in history. */
#undef HIST_SIZE
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing /* Define to 1 if `lstat' dereferences a symlink specified with a trailing
slash. */ slash. */
#undef LSTAT_FOLLOWS_SLASHED_SYMLINK #undef LSTAT_FOLLOWS_SLASHED_SYMLINK

42
configure vendored
View File

@ -869,13 +869,12 @@ with_pic
enable_fast_install enable_fast_install
with_gnu_ld with_gnu_ld
enable_libtool_lock enable_libtool_lock
enable_unique_history
enable_default_complete enable_default_complete
enable_arrow_keys enable_arrow_keys
enable_sigstop enable_sigstop
enable_terminal_bell enable_terminal_bell
enable_termcap enable_termcap
enable_history
enable_unique_history
' '
ac_precious_vars='build_alias ac_precious_vars='build_alias
host_alias host_alias
@ -1514,13 +1513,14 @@ Optional Features:
--enable-fast-install[=PKGS] --enable-fast-install[=PKGS]
optimize for fast installation [default=yes] optimize for fast installation [default=yes]
--disable-libtool-lock avoid locking (might break parallel builds) --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-default-complete Enable default completion handler.
--enable-arrow-keys Enable ANSI arrow keys. --enable-arrow-keys Enable ANSI arrow keys.
--enable-sigstop Enable SIGSTOP key. --enable-sigstop Enable SIGSTOP key.
--enable-terminal-bell Enable terminal bell on completion. --enable-terminal-bell Enable terminal bell on completion.
--enable-termcap Use the termcap library for terminal size. --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: Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
@ -11130,6 +11130,16 @@ fi
done 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. # Check whether --enable-default-complete was given.
if test "${enable_default_complete+set}" = set; then : if test "${enable_default_complete+set}" = set; then :
enableval=$enable_default_complete; complete=true; enableval=$enable_default_complete; complete=true;
@ -11178,30 +11188,6 @@ $as_echo "#define CONFIG_USE_TERMCAP /**/" >>confdefs.h
fi 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 # Restore gnu89 inline semantics on gcc 4.3 and newer
saved_cflags="$CFLAGS" saved_cflags="$CFLAGS"
CFLAGS="$CFLAGS -fgnu89-inline" CFLAGS="$CFLAGS -fgnu89-inline"

View File

@ -52,6 +52,11 @@ AC_PROG_GCC_TRADITIONAL
AC_FUNC_STAT AC_FUNC_STAT
AC_CHECK_FUNCS([strchr strdup strrchr tcgetattr perror]) 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, AC_ARG_ENABLE(default-complete,
[ --enable-default-complete Enable default completion handler.], [ --enable-default-complete Enable default completion handler.],
complete=true; AC_DEFINE(CONFIG_DEFAULT_COMPLETE,, [Define to enable the 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.], [ --enable-termcap Use the termcap library for terminal size.],
AC_DEFINE([CONFIG_USE_TERMCAP],, [Define to 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 # Restore gnu89 inline semantics on gcc 4.3 and newer
saved_cflags="$CFLAGS" saved_cflags="$CFLAGS"
CFLAGS="$CFLAGS -fgnu89-inline" CFLAGS="$CFLAGS -fgnu89-inline"

View File

@ -47,9 +47,11 @@ extern int rl_mark;
extern int rl_end; extern int rl_end;
extern char *rl_line_buffer; extern char *rl_line_buffer;
extern const char *rl_readline_name; extern const char *rl_readline_name;
extern int el_no_echo; /* e.g under emacs, don't echo except prompt */ extern int el_no_echo; /* e.g under emacs, don't echo except prompt */
extern void rl_reset_terminal(char *p); extern int el_hist_size; /* size of history scrollback buffer, default: 15 */
extern void rl_initialize(void); extern void rl_initialize(void);
extern void rl_reset_terminal(char *p);
extern char *readline(const char *prompt); extern char *readline(const char *prompt);
extern void add_history(const char *line); extern void add_history(const char *line);

View File

@ -38,9 +38,6 @@
#define META(x) ((x) | 0x80) #define META(x) ((x) | 0x80)
#define ISMETA(x) ((x) & 0x80) #define ISMETA(x) ((x) & 0x80)
#define UNMETA(x) ((x) & 0x7F) #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 " #define SEPS "\"#$&'()*:;<=>?[\\]^`{|}~\n\t "
/* /*
@ -64,7 +61,7 @@ typedef struct {
typedef struct { typedef struct {
int Size; int Size;
int Pos; int Pos;
char *Lines[HIST_SIZE]; char **Lines;
} el_hist_t; } el_hist_t;
/* /*
@ -79,12 +76,18 @@ int rl_quit;
int rl_susp; int rl_susp;
#endif #endif
int el_hist_size = 15;
static el_hist_t H = {
.Size = 0,
.Pos = 0,
.Lines = NULL,
};
static char NILSTR[] = ""; static char NILSTR[] = "";
static const char *el_input = NILSTR; static const char *el_input = NILSTR;
static char *Yanked; static char *Yanked;
static char *Screen; static char *Screen;
static char NEWLINE[]= CRLF; static char NEWLINE[]= CRLF;
static el_hist_t H;
static int Repeat; static int Repeat;
static int old_point; static int old_point;
static int el_push_back; static int el_push_back;
@ -1000,6 +1003,12 @@ static char *editinput(void)
return NULL; 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) static void hist_add(const char *p)
{ {
int i; int i;
@ -1014,11 +1023,11 @@ static void hist_add(const char *p)
if ((s = strdup(p)) == NULL) if ((s = strdup(p)) == NULL)
return; return;
if (H.Size < HIST_SIZE) { if (H.Size < el_hist_size) {
H.Lines[H.Size++] = s; H.Lines[H.Size++] = s;
} else { } else {
free(H.Lines[0]); 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] = H.Lines[i + 1];
H.Lines[i] = s; H.Lines[i] = s;
} }
@ -1072,6 +1081,8 @@ void rl_initialize(void)
{ {
if (!rl_prompt) if (!rl_prompt)
rl_prompt = "? "; rl_prompt = "? ";
hist_alloc();
} }
char *readline(const char *prompt) char *readline(const char *prompt)