Skip to content

Instantly share code, notes, and snippets.

@oraccha
Created September 22, 2011 08:34
Show Gist options
  • Save oraccha/1234344 to your computer and use it in GitHub Desktop.
Save oraccha/1234344 to your computer and use it in GitHub Desktop.
SIMH V3.8-1: add readline support
--- simhv38-1.orig/makefile 2008-11-19 21:53:48.000000000 +0900
+++ simhv38-1/makefile 2011-09-22 17:22:53.000000000 +0900
@@ -12,7 +12,8 @@
OS_CCDEFS = -lrt -lm -D_GNU_SOURCE
endif
endif
- CC = gcc -std=c99 -U__STRICT_ANSI__ -g $(OS_CCDEFS) -I .
+ CC = gcc -std=c99 -U__STRICT_ANSI__ -g $(OS_CCDEFS) -I . -DHAVE_READLINE
+ LDFLAGS = -lreadline
ifeq ($(USE_NETWORK),)
else
NETWORK_OPT = -DUSE_NETWORK -isystem /usr/local/include /usr/local/lib/libpcap.a
diff -u simhv38-1.orig/scp.c simhv38-1/scp.c
--- simhv38-1.orig/scp.c 2009-02-08 10:09:34.000000000 +0900
+++ simhv38-1/scp.c 2011-09-22 17:29:47.000000000 +0900
@@ -182,6 +182,12 @@
#include "sim_rev.h"
#include <signal.h>
#include <ctype.h>
+#if defined (HAVE_READLINE)
+#include <readline/readline.h>
+#include <readline/history.h>
+
+#define MAX_HISTORY 10
+#endif
#define EX_D 0 /* deposit */
#define EX_E 1 /* examine */
@@ -669,7 +675,9 @@
}
while (stat != SCPE_EXIT) { /* in case exit */
+#if !defined (HAVE_READLINE)
printf ("sim> "); /* prompt */
+#endif
if (cptr = sim_brk_getact (cbuf, CBUFSIZE)) /* pending action? */
printf ("%s\n", cptr); /* echo */
else if (sim_vm_read != NULL) /* sim routine? */
@@ -3357,6 +3365,18 @@
char *read_line (char *cptr, int32 size, FILE *stream)
{
char *tptr;
+#if defined (HAVE_READLINE)
+char *line = NULL;
+static int nhists = 0;
+HIST_ENTRY *hist = NULL;
+#endif
+
+#if defined (HAVE_READLINE)
+if (stream == stdin) {
+ cptr = readline("sim> ");
+ goto end_get_cmd_lien;
+}
+#endif
cptr = fgets (cptr, size, stream); /* get cmd line */
if (cptr == NULL) {
@@ -3370,6 +3390,7 @@
break;
}
}
+end_get_cmd_line:
while (isspace (*cptr)) /* trim leading spc */
cptr++;
if (*cptr == ';') *cptr = 0; /* ignore comment */
@@ -3377,6 +3398,10 @@
#if defined (HAVE_READLINE)
add_history (cptr);
+if (++nhists > MAX_HISTORY) {
+ hist = remove_history(0);
+ free(hist);
+}
#endif
return cptr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment