From 9e926c41c05daae9dd8e6e4af20131d55cf2de03 Mon Sep 17 00:00:00 2001 From: tslil Date: Wed, 30 Dec 2020 17:56:22 -0500 Subject: Added linenoise library, uninitialised variable + renaming --- src/ctaklm.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/ctaklm.c') diff --git a/src/ctaklm.c b/src/ctaklm.c index b343d11..1342770 100644 --- a/src/ctaklm.c +++ b/src/ctaklm.c @@ -1,5 +1,8 @@ #include +#include +#include +#include <3rd-party/linenoise.h> #include int main(int argc, char **argv) { @@ -31,4 +34,26 @@ int main(int argc, char **argv) { generate_place(5,1+5*2, STONE_CAPSTONE, buf); printf("Generated place: %s\n",buf); + char *line; + while((line = linenoise("hello> ")) != NULL) { + /* Do something with the string. */ + if (line[0] != '\0' && line[0] != '/') { + printf("echo: '%s'\n", line); + linenoiseHistoryAdd(line); /* Add to the history. */ + /* linenoiseHistorySave("history.txt"); /\* Save the history on disk. *\/ */ + } else if (!strncmp(line,"/historylen",11)) { + /* The "/historylen" command will change the history len. */ + int len = atoi(line+11); + linenoiseHistorySetMaxLen(len); + } else if (!strncmp(line, "/mask", 5)) { + linenoiseMaskModeEnable(); + } else if (!strncmp(line, "/unmask", 7)) { + linenoiseMaskModeDisable(); + } else if (line[0] == '/') { + printf("Unreconized command: %s\n", line); + } + free(line); + } + return 0; + } -- cgit v1.3.1