diff --git a/cmddb.c b/cmddb.c index d2630f0..4528766 100644 --- a/cmddb.c +++ b/cmddb.c @@ -234,6 +234,13 @@ const struct cmddb_record commands[] = { "locka [set|clear]\n" " Show or change the status of the LOCKA flash write-protect bit.\n" }, + { + .name = "exit", + .func = cmd_exit, + .help = +"exit\n" +" Exit from MSPDebug.\n" + } }; int cmddb_get(const char *name, struct cmddb_record *ret) diff --git a/mspdebug.man b/mspdebug.man index 5ca0862..16f19df 100644 --- a/mspdebug.man +++ b/mspdebug.man @@ -174,6 +174,8 @@ bit in the flash memory controller). Specify "segment" and a memory address to erase an individual flash segment. +.IP "\fBexit\fR" +Exit from MSPDebug. .IP "\fBgdb\fR [\fIport\fR]" Start a GDB remote stub, optionally specifying a TCP port to listen on. If no port is given, the default port is 2000. diff --git a/reader.c b/reader.c index 3ebdb28..e22758e 100644 --- a/reader.c +++ b/reader.c @@ -38,6 +38,7 @@ static int modify_flags; static int in_reader_loop; +static int want_exit; void mark_modified(int flags) { @@ -57,7 +58,7 @@ int prompt_abort(int flags) return 0; for (;;) { - printc("Symbols have not been saved since modification. " + printf("Symbols have not been saved since modification. " "Continue (y/n)? "); fflush(stdout); @@ -141,6 +142,11 @@ static int do_command(char *arg, int interactive) return 0; } +void reader_exit(void) +{ + want_exit = 1; +} + void reader_loop(void) { int old = in_reader_loop; @@ -154,19 +160,25 @@ void reader_loop(void) } do { + want_exit = 0; + for (;;) { char *buf = readline("(mspdebug) "); - if (!buf) + if (!buf) { + printc("\n"); break; + } add_history(buf); do_command(buf, 1); free(buf); + + if (want_exit) + break; } } while (prompt_abort(MODIFY_SYMS)); - printc("\n"); in_reader_loop = old; } diff --git a/reader.h b/reader.h index cc898d3..0db32d5 100644 --- a/reader.h +++ b/reader.h @@ -46,6 +46,9 @@ int prompt_abort(int flags); /* Run the reader loop */ void reader_loop(void); +/* Cause the reader loop to exit */ +void reader_exit(void); + /* Commands can be fed directly to the processor either one at a time, * or by specifying a file to read from. */ diff --git a/stdcmd.c b/stdcmd.c index c54b733..f51e308 100644 --- a/stdcmd.c +++ b/stdcmd.c @@ -242,3 +242,9 @@ int cmd_read(char **arg) return process_file(filename); } + +int cmd_exit(char **arg) +{ + reader_exit(); + return 0; +} diff --git a/stdcmd.h b/stdcmd.h index c267045..bf26384 100644 --- a/stdcmd.h +++ b/stdcmd.h @@ -23,5 +23,6 @@ int cmd_help(char **arg); int cmd_read(char **arg); int cmd_opt(char **arg); +int cmd_exit(char **arg); #endif