From ec9f8a5b55663cf5bc21c605787c7c83594f8719 Mon Sep 17 00:00:00 2001 From: Danny Holman Date: Wed, 15 Feb 2023 22:43:41 -0600 Subject: main: add a command line processor Add a function that processes incoming user commands. Signed-off-by: Danny Holman --- server/src/mini-rat.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/server/src/mini-rat.c b/server/src/mini-rat.c index e0fd5d1..521b269 100644 --- a/server/src/mini-rat.c +++ b/server/src/mini-rat.c @@ -2,12 +2,33 @@ #include #include +int running = 1; +int cur_session = 0; + +void parse_cmd(const char *line) { + if (strcmp(line, "exit\n") == 0) { + running = 0; + } else if (strncmp(line, "session ", 8) == 0) { + sprintf(line, "session %d", cur_session); + print("Swapped current session to %d\n", cur_session); + } + return; +} + int main(int argc, char* argv[]) { FILE *logfile = fopen("log.txt", "w"); - init_logging(stderr); - uint16_t port = 21115; + init_logging(logfile); + uint16_t port = 1122; pthread_t listen_thread; pthread_create(&listen_thread, NULL, listener, (void*)&port); - pthread_exit(NULL); + char line[4096]; + while (running) { + printf("mini-rat> "); + fgets(line, 4096, stdin); + parse_cmd(line); + } + + pthread_cancel(listen_thread); + return 0; } -- cgit v1.2.3