From 0aa44015f4501f618280f095b4a4c477e69b3541 Mon Sep 17 00:00:00 2001 From: Loïc Guégan Date: Mon, 24 Mar 2025 09:53:41 +0100 Subject: Clean code --- src/main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index b26543d..051449c 100644 --- a/src/main.c +++ b/src/main.c @@ -12,10 +12,13 @@ char cmd[64]; char *cmdptr=cmd; // Execute command from cmd buffer +// This is a test function which is buggy void exec(){ - if(!strncmp(cmd, "blink", strlen("exit"))) + if(cmd == cmdptr) + return; + else if(!strncmp(cmd, "blink", 5)) gpio_blink_led(1); - else if(!strncmp(cmd, "help", strlen("help"))) + else if(!strncmp(cmd, "help", 4)) tty_putstr(HELP); else if(cmdptr != cmd) tty_putstr("Unknown command (see help)\n\r"); @@ -30,6 +33,8 @@ void main(){ // REPL + // TODO: Handling arrows etc. + // Pressing arrow freezes the shell char c=tty_getchar(); tty_putstr(MOTD); tty_putstr(PROMPT); @@ -47,14 +52,12 @@ void main(){ cmdptr--; } } - else{ + else if(c>=32 && c <= 127){ // Printable char *cmdptr=c; cmdptr++; tty_putchar(c); } } - - return; } -- cgit v1.2.3