From a4dc6af85c1b64ec884c172f9ef238d046fbe2ed Mon Sep 17 00:00:00 2001 From: Joerg Hoppe Date: Fri, 14 Jun 2019 16:33:48 +0200 Subject: [PATCH] New ".input" command for "demo" scripts --- 90_common/src/inputline.c | 12 +++++++++--- 90_common/src/inputline.h | 2 +- 90_common/src/logger.cpp | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/90_common/src/inputline.c b/90_common/src/inputline.c index 002edd6..110076f 100644 --- a/90_common/src/inputline.c +++ b/90_common/src/inputline.c @@ -94,9 +94,13 @@ static int inputline_internal(char *line) { printf("<<<\n"); return 1; } else if (!strncasecmp(line, ".print", 6)) { - printf("<<<\n"); - printf("<<>>\n", line + 7); + printf("<<< %s\n", line + 7); return 1; + } else if (!strncasecmp(line, ".input", 6)) { + char buffer[100] ; + printf("<<< Press ENTER to continue.\n"); + fgets(buffer, sizeof(buffer), stdin) ; + return 1 ; } else if (!strncasecmp(line, ".end", 3)) { // close input file fclose(inputline_file); @@ -106,7 +110,7 @@ static int inputline_internal(char *line) { return 0; } -char *inputline(char *buffer, int buffer_size) { +char *inputline(char *buffer, int buffer_size, const char *prompt) { char *s; if (inputline_file != NULL) { // read from file @@ -149,6 +153,8 @@ char *inputline(char *buffer, int buffer_size) { } if (inputline_file == NULL) { /*** read interactive ***/ + if (prompt && *prompt) + printf("%s", prompt); fgets(buffer, buffer_size, stdin); // remove terminating "\n" for (s = buffer; *s; s++) diff --git a/90_common/src/inputline.h b/90_common/src/inputline.h index adf6093..26158bb 100644 --- a/90_common/src/inputline.h +++ b/90_common/src/inputline.h @@ -31,6 +31,6 @@ void inputline_init(void) ; bool inputline_fopen(char *filename) ; -char *inputline(char *buffer, int buffer_size) ; +char *inputline(char *buffer, int buffer_size, const char *prompt) ; #endif /* INPUTLINE_H_ */ diff --git a/90_common/src/logger.cpp b/90_common/src/logger.cpp index da2d521..45e6ea0 100644 --- a/90_common/src/logger.cpp +++ b/90_common/src/logger.cpp @@ -344,7 +344,8 @@ void logger_c::log(logsource_c *logsource, unsigned msglevel, const char *srcfil if (msglevel <= life_level) { char msgtext[LOGMESSAGE_TEXT_SIZE]; message_render(msgtext, sizeof(msgtext), &msg, RENDER_STYLE_CONSOLE); - cout << string(msgtext) << "\n"; + cout << msgtext << "\n"; + // cout << string(msgtext) << "\n"; // not thread safe??? } va_end(args);