From 6d888fff253d006383176c437376a0e65b8409f6 Mon Sep 17 00:00:00 2001 From: Daniel Beer Date: Tue, 12 Oct 2010 11:53:46 +1300 Subject: [PATCH] Print commands as they're read from a file. When using the "read" command, all commands executed are printed first, so you can see what goes wrong, if anything. --- main.c | 2 +- reader.c | 5 ++++- reader.h | 4 +++- stdcmd.c | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 96a72cf..c831c8d 100644 --- a/main.c +++ b/main.c @@ -327,7 +327,7 @@ static void process_rc_file(void) snprintf(text, sizeof(text), "%s/.mspdebug", home); if (!access(text, F_OK)) - process_file(text); + process_file(text, 0); } static int add_fet_device(void *user_data, const struct fet_db_record *r) diff --git a/reader.c b/reader.c index e22758e..7a77f0e 100644 --- a/reader.c +++ b/reader.c @@ -187,7 +187,7 @@ int process_command(char *cmd) return do_command(cmd, 0); } -int process_file(const char *filename) +int process_file(const char *filename, int show) { FILE *in; char buf[1024]; @@ -211,6 +211,9 @@ int process_file(const char *filename) if (*cmd == '#') continue; + if (show) + printc("\x1b[1m=>\x1b[0m %s", cmd); + if (do_command(cmd, 0) < 0) { printc_err("read: error processing %s (line %d)\n", filename, line_no); diff --git a/reader.h b/reader.h index 0db32d5..adb1a86 100644 --- a/reader.h +++ b/reader.h @@ -51,8 +51,10 @@ 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. + * + * If show is non-zero, commands will be printed as they are executed. */ int process_command(char *cmd); -int process_file(const char *filename); +int process_file(const char *filename, int show); #endif diff --git a/stdcmd.c b/stdcmd.c index f51e308..b00afd9 100644 --- a/stdcmd.c +++ b/stdcmd.c @@ -240,7 +240,7 @@ int cmd_read(char **arg) return -1; } - return process_file(filename); + return process_file(filename, 1); } int cmd_exit(char **arg)