summaryrefslogtreecommitdiffstats
path: root/sis.c
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2019-07-02 09:57:28 +1000
committerJiri Gaisler <jiri@gaisler.se>2019-07-02 22:03:52 +0200
commitd509fe6c57f18e2534c586e7dde844811c76a146 (patch)
tree6e667f33725e141a9af9ae166f9ecbfa1c90deb2 /sis.c
parentelf_load() failed in interactive shell. (diff)
downloadsis-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.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/sis.c b/sis.c
index 87f75bc..fb89742 100644
--- a/sis.c
+++ b/sis.c
@@ -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