summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2009-03-26 22:41:47 -0700
committerKeith Packard <keithp@keithp.com>2009-03-26 22:41:47 -0700
commit91607bebdd167ac632aca4b66e22cb0cabdf0d20 (patch)
tree48fa2727e6c895a63707b77bc48706d1d87c3a4b
parent66ee94ed10e3d79b24f45a5c63e58456d4d30343 (diff)
Add readline support to s51
-rw-r--r--s51/Makefile.am2
-rw-r--r--s51/s51-main.c33
2 files changed, 25 insertions, 10 deletions
diff --git a/s51/Makefile.am b/s51/Makefile.am
index 6213750c..4778d66b 100644
--- a/s51/Makefile.am
+++ b/s51/Makefile.am
@@ -1,7 +1,7 @@
bin_PROGRAMS=s51
AM_CFLAGS=-I$(top_srcdir)/lib $(LIBUSB_CFLAGS)
-S51_LIBS=../lib/libcc.a
+S51_LIBS=../lib/libcc.a -lreadline
man_MANS = s51.1
diff --git a/s51/s51-main.c b/s51/s51-main.c
index 96429988..46b97b0c 100644
--- a/s51/s51-main.c
+++ b/s51/s51-main.c
@@ -189,19 +189,34 @@ s51_putc(int c)
putc(c, s51_output);
}
+#include <readline/readline.h>
+#include <readline/history.h>
+
int
s51_read_line(char *line, int len)
{
int ret;
- if (s51_prompt)
- s51_printf("%s", s51_prompt);
- else
- s51_putc('\0');
- fflush(s51_output);
- ret = fgets(line, len, s51_input) != NULL;
- if (s51_monitor)
- printf("> %s", line);
- fflush(stdout);
+ if (s51_output == stdout && s51_input == stdin && s51_prompt) {
+ char *r;
+
+ r = readline(s51_prompt);
+ if (r == NULL)
+ return 0;
+ strncpy (line, r, len);
+ line[len-1] = '\0';
+ add_history(r);
+ return 1;
+ } else {
+ if (s51_prompt)
+ s51_printf("%s", s51_prompt);
+ else
+ s51_putc('\0');
+ fflush(s51_output);
+ ret = fgets(line, len, s51_input) != NULL;
+ if (s51_monitor)
+ printf("> %s", line);
+ fflush(stdout);
+ }
return ret;
}