From 5d94e3bd9379abb04ca5ba1143d072c48d61a406 Mon Sep 17 00:00:00 2001 From: nishi Date: Sat, 27 Apr 2024 00:32:05 +0000 Subject: [PATCH] do not use readline git-svn-id: file:///raid/svn-main/nishi-serenade/trunk@60 0f02c867-ac3d-714e-8a88-971ba1f6efcf --- Serenade/main.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Serenade/main.c b/Serenade/main.c index 0321f7d..2b4ba96 100644 --- a/Serenade/main.c +++ b/Serenade/main.c @@ -48,6 +48,15 @@ extern bool is_repl; +int run_command(const char* cmd){ + if(strcmp(cmd, ":quit") == 0){ + return 1; + }else{ + fprintf(stderr, "Unknown command\n"); + return 0; + } +} + int main(int argc, char** argv) { int i; bool loaded = false; @@ -134,9 +143,11 @@ int main(int argc, char** argv) { br--; } } - if(strcmp(line, ":quit") == 0) { + if(line[0] == ':'){ + int st = run_command(line); free(line); - break; + if(st != 0) break; + continue; } char* tmp = str; str = sn_strcat(tmp, line); @@ -151,8 +162,13 @@ int main(int argc, char** argv) { free(line); #else if(cbuf[0] == '\n') { - if(strcmp(str, ":quit") == 0) { - break; + if(str[0] == ':'){ + int st = run_command(str); + free(str); + str = malloc(1); + str[0] = 0; + if(st != 0) break; + continue; } if(br == 0 && strlen(str) > 0) { sn_eval(sn, str, strlen(str)); @@ -182,7 +198,9 @@ int main(int argc, char** argv) { } #endif } +#ifdef HAS_READLINE_SUPPORT write_history(".serenade_history"); +#endif free(str); sn_interpreter_free(sn); } -- 2.43.0