diff options
author | Chris Johns <chrisj@rtems.org> | 2019-07-02 09:57:28 +1000 |
---|---|---|
committer | Jiri Gaisler <jiri@gaisler.se> | 2019-07-02 22:03:52 +0200 |
commit | d509fe6c57f18e2534c586e7dde844811c76a146 (patch) | |
tree | 6e667f33725e141a9af9ae166f9ecbfa1c90deb2 /sis.c | |
parent | elf_load() failed in interactive shell. (diff) | |
download | sis-d509fe6c57f18e2534c586e7dde844811c76a146.tar.bz2 |
Make readline conditional and add linenoise it not present.
- Readline is not present on all hosts is used on and it has
not been a requirement. Rather than break all hosts that
are working this patch conditionally adds linenoise a small
simple realline replacement.
Diffstat (limited to 'sis.c')
-rw-r--r-- | sis.c | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -28,10 +28,14 @@ #include <inttypes.h> #include <libgen.h> -/* Structures and functions from readline library */ - -#include "readline/readline.h" -#include "readline/history.h" +#if HAVE_READLINE + #include "readline/readline.h" + #include "readline/history.h" +#else + /* Linenoise as a readline library replacement + https://github.com/antirez/linenoise */ + #include "linenoise.h" +#endif /* Command history buffer length - MUST be binary */ #define HIST_LEN 256 @@ -251,7 +255,11 @@ main (argc, argv) #ifdef F_GETFL termsave = fcntl (0, F_GETFL, 0); #endif +#if HAVE_READLINE using_history (); +#else + linenoiseHistorySetMaxLen(HIST_LEN); +#endif init_signals (); ebase.simtime = 0; ebase.simstart = 0; @@ -287,12 +295,11 @@ main (argc, argv) if (cmdq[cmdi] != 0) { -#if 0 - remove_history (cmdq[cmdi]); +#if HAVE_READLINE + free (cmdq[cmdi]); #else - remove_history (cmdi); + linenoiseFree (cmdq[cmdi]); #endif - free (cmdq[cmdi]); cmdq[cmdi] = 0; } if (run) @@ -306,9 +313,17 @@ main (argc, argv) sprintf (prompt, "cpu%d> ", cpu); else sprintf (prompt, "sis> "); +#if HAVE_READLINE cmdq[cmdi] = readline (prompt); +#else + cmdq[cmdi] = linenoise (prompt); +#endif if (cmdq[cmdi] && *cmdq[cmdi]) +#if HAVE_READLINE add_history (cmdq[cmdi]); +#else + linenoiseHistoryAdd (cmdq[cmdi]); +#endif if (cmdq[cmdi]) stat = exec_cmd (cmdq[cmdi]); else |