Generalized readline support to dynamically load the readline library and avoid the symbol conflicts which happen on some platforms and some simulators with a global PC variable.
This commit is contained in:
parent
2d4d248ae3
commit
8b01b90008
2 changed files with 49 additions and 31 deletions
33
makefile
33
makefile
|
@ -15,9 +15,6 @@
|
|||
# In general, the logic below will detect and build with the available
|
||||
# features which the host build environment provides.
|
||||
#
|
||||
# Readline support can be disabled if GNU make is invoked with
|
||||
# DONT_USE_READLINE=1 on the command line.
|
||||
#
|
||||
# Internal ROM support can be disabled if GNU make is invoked with
|
||||
# DONT_USE_ROMS=1 on the command line.
|
||||
#
|
||||
|
@ -67,7 +64,11 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin)
|
|||
LIBPATH += /usr/pkg/lib
|
||||
OS_LDFLAGS += -L/usr/pkg/lib -R/usr/pkg/lib
|
||||
endif
|
||||
LIBEXT = a
|
||||
ifneq (,$(findstring NetBSD,$(shell uname))$(findstring FreeBSD,$(shell uname)))
|
||||
LIBEXT = so
|
||||
else
|
||||
LIBEXT = a
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
@ -92,21 +93,15 @@ ifeq ($(WIN32),) #*nix Environments (&& cygwin)
|
|||
$(info using libpthread: $(call find_lib,pthread) $(call find_include,pthread))
|
||||
endif
|
||||
endif
|
||||
ifeq ($(DONT_USE_READLINE),)
|
||||
ifneq (,$(call find_include,readline/readline))
|
||||
ifneq (,$(call find_lib,readline))
|
||||
# Use Locally installed and available readline support
|
||||
ifneq (,$(call find_lib,ncurses))
|
||||
OS_CCDEFS += -DHAVE_READLINE
|
||||
OS_LDFLAGS += -lreadline -lncurses
|
||||
$(info using libreadline and libncurses: $(call find_lib,readline) $(call find_lib,ncurses) $(call find_include,readline/readline))
|
||||
else
|
||||
ifneq (,$(call find_lib,curses))
|
||||
OS_CCDEFS += -DHAVE_READLINE
|
||||
OS_LDFLAGS += -lreadline -lcurses
|
||||
$(info using libreadline and libcurses: $(call find_lib,readline) $(call find_lib,curses) $(call find_include,readline/readline))
|
||||
endif
|
||||
endif
|
||||
ifneq (,$(call find_include,dlfcn))
|
||||
ifneq (,$(call find_lib,dl))
|
||||
OS_CCDEFS += -DHAVE_DLOPEN=$(LIBEXT)
|
||||
OS_LDFLAGS += -ldl
|
||||
$(info using libdl: $(call find_lib,dl) $(call find_include,dlfcn))
|
||||
else
|
||||
ifeq (BSD,$(findstring BSD,$(shell uname)))
|
||||
OS_CCDEFS += -DHAVE_DLOPEN=so
|
||||
$(info using libdl: $(call find_include,dlfcn))
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
|
47
scp.c
47
scp.c
|
@ -213,9 +213,8 @@
|
|||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#if defined(HAVE_READLINE)
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#if defined(HAVE_DLOPEN) /* Dynamic Readline support */
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
#define EX_D 0 /* deposit */
|
||||
|
@ -3841,15 +3840,39 @@ return read_line_p (NULL, cptr, size, stream);
|
|||
char *read_line_p (char *prompt, char *cptr, int32 size, FILE *stream)
|
||||
{
|
||||
char *tptr;
|
||||
#if defined(HAVE_DLOPEN)
|
||||
static int initialized = 0;
|
||||
static char *(*p_readline)(const char *) = NULL;
|
||||
static void (*p_add_history)(const char *) = NULL;
|
||||
|
||||
#if defined(HAVE_READLINE)
|
||||
if (!initialized) {
|
||||
initialized = 1;
|
||||
void *handle;
|
||||
|
||||
#define __STR_QUOTE(tok) #tok
|
||||
#define __STR(tok) __STR_QUOTE(tok)
|
||||
handle = dlopen("libncurses." __STR(HAVE_DLOPEN), RTLD_NOW|RTLD_GLOBAL);
|
||||
handle = dlopen("libreadline." __STR(HAVE_DLOPEN), RTLD_NOW|RTLD_GLOBAL);
|
||||
if (handle) {
|
||||
p_readline = dlsym(handle, "readline");
|
||||
p_add_history = dlsym(handle, "add_history");
|
||||
}
|
||||
}
|
||||
if (prompt) { /* interactive? */
|
||||
char *tmpc = readline (prompt); /* get cmd line */
|
||||
if (tmpc == NULL) /* bad result? */
|
||||
cptr = NULL;
|
||||
char *tmpc;
|
||||
|
||||
if (p_readline) {
|
||||
char *tmpc = p_readline (prompt); /* get cmd line */
|
||||
if (tmpc == NULL) /* bad result? */
|
||||
cptr = NULL;
|
||||
else {
|
||||
strncpy (cptr, tmpc, size); /* copy result */
|
||||
free (tmpc) ; /* free temp */
|
||||
}
|
||||
}
|
||||
else {
|
||||
strncpy (cptr, tmpc, size); /* copy result */
|
||||
free (tmpc) ; /* free temp */
|
||||
printf ("%s", prompt); /* display prompt */
|
||||
cptr = fgets (cptr, size, stream); /* get cmd line */
|
||||
}
|
||||
}
|
||||
else cptr = fgets (cptr, size, stream); /* get cmd line */
|
||||
|
@ -3875,9 +3898,9 @@ while (isspace (*cptr)) /* trim leading spc */
|
|||
if (*cptr == ';') /* ignore comment */
|
||||
*cptr = 0;
|
||||
|
||||
#if defined (HAVE_READLINE)
|
||||
if (prompt)
|
||||
add_history (cptr);
|
||||
#if defined (HAVE_DLOPEN)
|
||||
if (prompt && p_add_history && *cptr) /* Save non blank lines in history */
|
||||
p_add_history (cptr);
|
||||
#endif
|
||||
|
||||
return cptr;
|
||||
|
|
Loading…
Add table
Reference in a new issue