summaryrefslogtreecommitdiff
path: root/s51/s51-main.c
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 /s51/s51-main.c
parent66ee94ed10e3d79b24f45a5c63e58456d4d30343 (diff)
Add readline support to s51
Diffstat (limited to 's51/s51-main.c')
-rw-r--r--s51/s51-main.c33
1 files changed, 24 insertions, 9 deletions
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;
}