Allow in all loctions

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@826 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2008-08-17 16:17:44 +00:00
parent 2878532acb
commit 0ef52f153e
3 changed files with 60 additions and 47 deletions

View File

@ -88,24 +88,9 @@ void cmd_echo(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
*/ */
for (i = 1; i < argc; i++) 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"); 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) if (optind + 1 < argc)
{ {

View File

@ -287,6 +287,9 @@ char *nsh_argument(char **saveptr)
char *pbegin = *saveptr; char *pbegin = *saveptr;
char *pend = NULL; char *pend = NULL;
const char *term; const char *term;
#ifndef CONFIG_DISABLE_ENVIRON
boolean quoted = FALSE;
#endif
/* Find the beginning of the next token */ /* Find the beginning of the next token */
@ -312,23 +315,27 @@ char *nsh_argument(char **saveptr)
if (*(pbegin + 1) == '>') if (*(pbegin + 1) == '>')
{ {
*saveptr = pbegin + 2; *saveptr = pbegin + 2;
return (char*)g_redirect2; pbegin = g_redirect2;
} }
else else
{ {
*saveptr = pbegin + 1; *saveptr = pbegin + 1;
return (char*)g_redirect1; pbegin = g_redirect1;
} }
} }
else
{
/* Does the token begin with '"'? */ /* Does the token begin with '"'? */
else if (*pbegin == '"') if (*pbegin == '"')
{ {
/* Yes.. then only another '"' can terminate the string */ /* Yes.. then only another '"' can terminate the string */
pbegin++; pbegin++;
term = "\""; term = "\"";
#ifndef CONFIG_DISABLE_ENVIRON
quoted = TRUE;
#endif
} }
else else
{ {
@ -354,11 +361,32 @@ char *nsh_argument(char **saveptr)
*pend++ = '\0'; *pend++ = '\0';
} }
/* Save the pointer where we left off and return the /* Save the pointer where we left off */
* beginning of the token.
*/
*saveptr = pend; *saveptr = pend;
}
/* Check for references to environment variables */
#ifndef CONFIG_DISABLE_ENVIRON
if (pbegin[0] == '$' && !quoted)
{
/* Yes.. return the value of the environment variable with this name */
char *value = getenv(pbegin+1);
if (value)
{
return value;
}
else
{
return "";
}
}
#endif
/* Return the beginning of the token. */
return pbegin; return pbegin;
} }