9
0
Fork 0

Allow in all loctions

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@826 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-08-17 16:17:44 +00:00
parent 8672344900
commit 7031259b45
3 changed files with 60 additions and 47 deletions

View File

@ -89,22 +89,7 @@ void cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
for (i = 1; i < argc; i++)
{
/* Check for references to environment variables */
#ifndef CONFIG_DISABLE_ENVIRON
if (argv[i][0] == '$')
{
char *value = getenv(argv[i]+1);
if (value)
{
nsh_output(vtbl, "%s ", value);
}
}
else
#endif
{
nsh_output(vtbl, "%s ", argv[i]);
}
nsh_output(vtbl, "%s ", argv[i]);
}
nsh_output(vtbl, "\n");
}

View File

@ -599,7 +599,7 @@ void cmd_ls(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
}
/* There are one required arguments after the options */
/* There is one required arguments after the options */
if (optind + 1 < argc)
{

View File

@ -287,6 +287,9 @@ char *nsh_argument(char **saveptr)
char *pbegin = *saveptr;
char *pend = NULL;
const char *term;
#ifndef CONFIG_DISABLE_ENVIRON
boolean quoted = FALSE;
#endif
/* Find the beginning of the next token */
@ -312,53 +315,78 @@ char *nsh_argument(char **saveptr)
if (*(pbegin + 1) == '>')
{
*saveptr = pbegin + 2;
return (char*)g_redirect2;
pbegin = g_redirect2;
}
else
{
*saveptr = pbegin + 1;
return (char*)g_redirect1;
pbegin = g_redirect1;
}
}
/* Does the token begin with '"'? */
else if (*pbegin == '"')
{
/* Yes.. then only another '"' can terminate the string */
pbegin++;
term = "\"";
}
else
{
/* No, then any of the usual terminators will terminate the argument */
/* Does the token begin with '"'? */
term = g_delim;
if (*pbegin == '"')
{
/* Yes.. then only another '"' can terminate the string */
pbegin++;
term = "\"";
#ifndef CONFIG_DISABLE_ENVIRON
quoted = TRUE;
#endif
}
else
{
/* No, then any of the usual terminators will terminate the argument */
term = g_delim;
}
/* Find the end of the string */
for (pend = pbegin + 1;
*pend && strchr(term, *pend) == NULL;
pend++);
/* pend either points to the end of the string or to
* the first delimiter after the string.
*/
if (*pend)
{
/* Turn the delimiter into a null terminator */
*pend++ = '\0';
}
/* Save the pointer where we left off */
*saveptr = pend;
}
/* Find the end of the string */
/* Check for references to environment variables */
for (pend = pbegin + 1;
*pend && strchr(term, *pend) == NULL;
pend++);
/* pend either points to the end of the string or to
* the first delimiter after the string.
*/
if (*pend)
#ifndef CONFIG_DISABLE_ENVIRON
if (pbegin[0] == '$' && !quoted)
{
/* Turn the delimiter into a null terminator */
/* Yes.. return the value of the environment variable with this name */
*pend++ = '\0';
char *value = getenv(pbegin+1);
if (value)
{
return value;
}
else
{
return "";
}
}
#endif
/* Save the pointer where we left off and return the
* beginning of the token.
*/
/* Return the beginning of the token. */
*saveptr = pend;
return pbegin;
}