From f812686107f5e463d23668f815d24a00cf46f38e Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 7 Nov 2021 22:10:02 -0500 Subject: [PATCH 1/2] prospective fix for issue 14, need to test and remove debug code --- Shell.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Shell.c b/Shell.c index 5286bd4..603fee0 100644 --- a/Shell.c +++ b/Shell.c @@ -457,9 +457,26 @@ static int shell_parse(char * buf, char ** argv, unsigned short maxargs) // Handle special char: Space is token separator case ' ': + //TODO is there other whitespace to handle? if (toggle == 0) { + shell_printf("Got space, i=%d\r\n",i); buf[i] = '\0'; + + // Try a loop? + while((i < length) && (buf[i + 1] == ' ')){ + shell_printf("Got another space. i = %d\r\n",i); + i++; + buf[i] = '\0'; + } + shell_printf("End of whitespace, i=%d length = %d\r\n",i,length); + + if(i == length - 2){ // if we're at the end of the input (length - 2 because we're on the last char, and length points to char after terminating NULL + shell_printf("End of input, i=%d\r\n"); + break; + } + argc++; + shell_printf("Adding arg %d\r\n",argc); argv[argc] = &buf[i + 1]; } break; From ed1852dc931b8e6dd3e66b50897207c6d2e902c0 Mon Sep 17 00:00:00 2001 From: Joe Date: Tue, 9 Nov 2021 18:35:05 -0500 Subject: [PATCH 2/2] Issue 14 testing complete and debug code removed --- Shell.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Shell.c b/Shell.c index 603fee0..2dc8374 100644 --- a/Shell.c +++ b/Shell.c @@ -457,26 +457,23 @@ static int shell_parse(char * buf, char ** argv, unsigned short maxargs) // Handle special char: Space is token separator case ' ': - //TODO is there other whitespace to handle? if (toggle == 0) { - shell_printf("Got space, i=%d\r\n",i); buf[i] = '\0'; - // Try a loop? + // Loop past any consecutive spaces while((i < length) && (buf[i + 1] == ' ')){ - shell_printf("Got another space. i = %d\r\n",i); i++; buf[i] = '\0'; } - shell_printf("End of whitespace, i=%d length = %d\r\n",i,length); - if(i == length - 2){ // if we're at the end of the input (length - 2 because we're on the last char, and length points to char after terminating NULL - shell_printf("End of input, i=%d\r\n"); - break; + // If we're at the end of the input (length - 2 because we're on the last char, + // and length points to char after terminating NULL + if(i == length - 2){ + break; // Break out of loop to avoid adding an empty argument at the end } + // Increment argument counter and add argument to argv array argc++; - shell_printf("Adding arg %d\r\n",argc); argv[argc] = &buf[i + 1]; } break;