From 110183e258519aa31f731db25a392d6a05c0f90c Mon Sep 17 00:00:00 2001 From: Paul Koning Date: Wed, 28 Sep 2022 09:59:00 -0400 Subject: [PATCH] simh ui: replace "readline" by "editline". This avoids infecting SIMH with the GPL license, since readline, very surprisingly, is GPL rather than LGPL. The replacement package is "editline", which has a useable license. --- .travis/deps.sh | 1 + makefile | 12 ++++++++++ scp.c | 59 ++++++++++--------------------------------------- 3 files changed, 25 insertions(+), 47 deletions(-) diff --git a/.travis/deps.sh b/.travis/deps.sh index 0e7205fc..d799adb6 100755 --- a/.travis/deps.sh +++ b/.travis/deps.sh @@ -12,6 +12,7 @@ install_linux() { sudo apt-get install -ym libegl1-mesa-dev libgles2-mesa-dev sudo apt-get install -ym libsdl2-dev libpcap-dev libvdeplug-dev sudo apt-get install -ym libsdl2-ttf-dev + sudo apt-get install -ym libedit-dev } install_"$1" diff --git a/makefile b/makefile index ae3b81f8..a055314e 100644 --- a/makefile +++ b/makefile @@ -607,6 +607,18 @@ ifeq (${WIN32},) #*nix Environments (&& cygwin) endif endif endif + ifneq (,$(call find_include,editline/readline)) + OS_CCDEFS += -DHAVE_EDITLINE + OS_LDFLAGS += -ledit + ifneq (Darwin,$(OSTYPE)) + # The doc says termcap is needed, though reality suggests + # otherwise. Put it in anyway, it can't hurt. + ifneq (,$(call find_lib,termcap)) + OS_LDFLAGS += -ltermcap + endif + endif + $(info using libedit: $(call find_include,editline/readline)) + endif ifneq (,$(call find_include,utime)) OS_CCDEFS += -DHAVE_UTIME endif diff --git a/scp.c b/scp.c index 9a586589..92c8f90e 100644 --- a/scp.c +++ b/scp.c @@ -242,8 +242,8 @@ #endif #include -#if defined(SIM_HAVE_DLOPEN) /* Dynamic Readline support */ -#include +#if defined(HAVE_EDITLINE) /* Editline command line editing */ +#include #endif #ifndef MAX @@ -10273,51 +10273,16 @@ return read_line_p (NULL, cptr, size, stream); char *read_line_p (const char *prompt, char *cptr, int32 size, FILE *stream) { char *tptr; -#if defined(SIM_HAVE_DLOPEN) -static int initialized = 0; -typedef char *(*readline_func)(const char *); -static readline_func p_readline = NULL; -typedef void (*add_history_func)(const char *); -static add_history_func p_add_history = NULL; - -if (prompt && (!initialized)) { - initialized = 1; - void *handle; - -#define S__STR_QUOTE(tok) #tok -#define S__STR(tok) S__STR_QUOTE(tok) - handle = dlopen("libncurses." S__STR(SIM_HAVE_DLOPEN), RTLD_NOW|RTLD_GLOBAL); - handle = dlopen("libcurses." S__STR(SIM_HAVE_DLOPEN), RTLD_NOW|RTLD_GLOBAL); - handle = dlopen("libreadline." S__STR(SIM_HAVE_DLOPEN), RTLD_NOW|RTLD_GLOBAL); - if (!handle) - handle = dlopen("libreadline." S__STR(SIM_HAVE_DLOPEN) ".8", RTLD_NOW|RTLD_GLOBAL); - if (!handle) - handle = dlopen("libreadline." S__STR(SIM_HAVE_DLOPEN) ".7", RTLD_NOW|RTLD_GLOBAL); - if (!handle) - handle = dlopen("libreadline." S__STR(SIM_HAVE_DLOPEN) ".6", RTLD_NOW|RTLD_GLOBAL); - if (!handle) - handle = dlopen("libreadline." S__STR(SIM_HAVE_DLOPEN) ".5", RTLD_NOW|RTLD_GLOBAL); - if (handle) { - p_readline = (readline_func)((size_t)dlsym(handle, "readline")); - p_add_history = (add_history_func)((size_t)dlsym(handle, "add_history")); - } - } +#if defined(HAVE_EDITLINE) if (prompt) { /* interactive? */ - if (p_readline) { - char *tmpc = p_readline (prompt); /* get cmd line */ - if (tmpc == NULL) /* bad result? */ - cptr = NULL; - else { - strlcpy (cptr, tmpc, size); /* copy result */ - free (tmpc) ; /* free temp */ - } - } + char *tmpc = readline (prompt); /* get cmd line */ + if (tmpc == NULL) /* bad result? */ + cptr = NULL; else { - printf ("%s", prompt); /* display prompt */ - fflush (stdout); - cptr = fgets (cptr, size, stream); /* get cmd line */ - } + strlcpy (cptr, tmpc, size); /* copy result */ + free (tmpc) ; /* free temp */ } +} else cptr = fgets (cptr, size, stream); /* get cmd line */ #else if (prompt) { /* interactive? */ @@ -10349,9 +10314,9 @@ if ((*cptr == ';') || (*cptr == '#')) { /* ignore comment */ *cptr = 0; } -#if defined (SIM_HAVE_DLOPEN) -if (prompt && p_add_history && *cptr) /* Save non blank lines in history */ - p_add_history (cptr); +#if defined (HAVE_EDITLINE) +if (prompt && *cptr) /* Save non blank lines in history */ + add_history (cptr); #endif return cptr;