Skip to content

Commit

Permalink
apps/nshlib: Small parsing improvement plus some added comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregory-nutt committed Aug 6, 2018
1 parent cb556d6 commit 303629d
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions nshlib/nsh_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,9 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
FAR char **allocation)
{
FAR char *working = cmdline;
#ifdef CONFIG_NSH_QUOTE
FAR char *nextwork;
#endif
FAR char *argument = NULL;
FAR char *ptr;
size_t len;
Expand All @@ -1122,10 +1125,11 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
{
/* Look for interesting things within the command string. */

len = strcspn(working, g_arg_separator);
ptr = working + len;

len = strcspn(working, g_arg_separator);
ptr = working + len;
#ifdef CONFIG_NSH_QUOTE
nextwork = ptr + 1;

/* But ignore these interesting things if they are quoted */

while (len > 0 && *ptr != '\0')
Expand All @@ -1147,8 +1151,9 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
{
/* Yes.. skip over it */

len += strcspn(ptr + 1, g_arg_separator) + 1;
ptr = working + len;
len += strcspn(ptr + 1, g_arg_separator) + 1;
ptr = working + len;
nextwork = ptr + 1;
}
else
{
Expand Down Expand Up @@ -1297,7 +1302,12 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
}
else
{
/* Set working to the NUL terminator at the end of the string */
/* Set working to the NUL terminator at the end of the string.
*
* REVISIT: Needs logic to get the size of the variable name
* based on parsing the name string which must be of the form
* [a-zA-Z_]+[a-zA-Z0-9_]*
*/

working = ptr + strlen(ptr);
}
Expand Down Expand Up @@ -1330,7 +1340,11 @@ static FAR char *nsh_argexpand(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline,
* cmdline.
*/

#ifdef CONFIG_NSH_QUOTE
working = nextwork;
#else
working++;
#endif
}
}
}
Expand Down

0 comments on commit 303629d

Please sign in to comment.