char *s51_prompt = "> ";
struct ccdbg *s51_dbg;
int s51_interrupted = 0;
+int s51_monitor = 0;
static FILE *s51_input;
static FILE *s51_output;
char *endptr;
struct sigvec vec, ovec;
- while ((opt = getopt(argc, argv, "PVvHht:X:c:r:Z:s:S:p:")) != -1) {
+ while ((opt = getopt(argc, argv, "PVvHhmt:X:c:r:Z:s:S:p:")) != -1) {
switch (opt) {
case 't':
cpu = optarg;
case 'h':
usage ();
break;
+ case 'm':
+ s51_monitor = 1;
+ break;
}
}
if (s51_port) {
perror("fdopen");
exit(1);
}
- vec.sv_handler = s51_sigint;
+ vec.sv_handler = SIG_IGN;
vec.sv_mask = 0;
vec.sv_flags = 0;
sigvec(SIGINT, &vec, &ovec);
va_start(ap, format);
vfprintf(s51_output, format, ap);
-#if 1
- if (s51_port)
+ if (s51_monitor)
vfprintf(stdout, format, ap);
-#endif
va_end(ap);
}
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 1
- if (s51_port)
- printf("> %s", line);
-#endif
- 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;
}