1
0
mirror of https://github.com/simh/simh.git synced 2026-01-13 23:35:57 +00:00

SCP: Remove libreadline GPL conflict and add tab file expansion on Windows

- Leverage libedit which is minimal libreadline with BSD license
- Wineditline on Windows which is also a libreadline equivalent with
  a BSD license

Both are dynamically loaded on startup if they're available on
the host.
This commit is contained in:
Mark Pizzolato 2022-09-25 14:04:05 -10:00
parent dcdd75d746
commit 75745b7b52

36
scp.c
View File

@ -10450,33 +10450,45 @@ 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(_WIN32)
#define dlopen(X,Y) LoadLibraryA((X))
#define dlsym(X,Y) GetProcAddress((HINSTANCE)(X),(Y))
#define dlclose(X) FreeLibrary((X))
#ifndef RTLD_NOW
#define RTLD_NOW 0
#endif
#ifndef RTLD_LOCAL
#define RTLD_LOCAL 0
#endif
#define EDIT_DEFAULT_LIB "edit."
#define SIM_HAVE_DLOPEN DLL
#else
#define EDIT_DEFAULT_LIB "libedit."
#endif /* _WIN32 */
#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;
typedef void (*free_line_func)(void *);
static free_line_func p_free_line = NULL;
if (prompt && (!initialized)) {
initialized = 1;
void *handle;
initialized = 1;
#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);
handle = dlopen(EDIT_DEFAULT_LIB 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);
handle = dlopen(EDIT_DEFAULT_LIB S__STR(SIM_HAVE_DLOPEN) ".2", 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"));
p_free_line = (free_line_func)((size_t)dlsym(handle, "rl_free"));
if (p_free_line == NULL)
p_free_line = (free_line_func)&free;
}
}
if (prompt) { /* interactive? */
@ -10486,7 +10498,7 @@ if (prompt) { /* interactive? */
cptr = NULL;
else {
strlcpy (cptr, tmpc, size); /* copy result */
free (tmpc) ; /* free temp */
p_free_line (tmpc) ; /* free temp */
}
}
else {