tcp_cmd
use tcp_cmd_remove_leading_space
This commit is contained in:
@@ -340,6 +340,7 @@ static bool tcp_cmd_parser(struct tcp_pcb* pcb, int argc, char** argv) {
|
||||
err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||
int argc = 0;
|
||||
char cmd[MAX_CMD_LEN];
|
||||
char* cmd_ptr;
|
||||
char* argv[MAX_TOKENS];
|
||||
bool close_conn = false;
|
||||
char* next;
|
||||
@@ -372,9 +373,16 @@ err_t tcp_cmd_recv(void* arg, struct tcp_pcb* pcb, struct pbuf* p, err_t err) {
|
||||
tcp_cmd_remove_newline(cmd, strlen(cmd));
|
||||
LOG_INFO(TAG, "cmd: %s", cmd);
|
||||
// Split string into tokens by delimiter (space)
|
||||
argv[0] = tcp_cmd_get_next_token(cmd, " ", &next);
|
||||
cmd_ptr = tcp_cmd_remove_leading_space(cmd, strlen(cmd));
|
||||
argv[0] = tcp_cmd_get_next_token(cmd_ptr, " ", &next);
|
||||
argc = 1;
|
||||
while (argv[argc - 1] != NULL && argc < MAX_TOKENS) {
|
||||
// Check if the next token is 0 (end of string) strlen doesn't work here
|
||||
if (*next == 0) {
|
||||
argv[argc] = NULL;
|
||||
break;
|
||||
}
|
||||
next = tcp_cmd_remove_leading_space(next, strlen(next));
|
||||
argv[argc] = tcp_cmd_get_next_token(NULL, " ", &next);
|
||||
if (argv[argc] == NULL) {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user