diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-08-17 16:17:44 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-08-17 16:17:44 +0000 |
commit | 002549e43c326202f941483a7249a8f088c842ea (patch) | |
tree | fd0c93c57201b23cb0db54a04551a1a8eadcbcf3 /nuttx | |
parent | 55e4f1ebc7d9236a746a456733e5b5606f7e0a57 (diff) | |
download | px4-nuttx-002549e43c326202f941483a7249a8f088c842ea.tar.gz px4-nuttx-002549e43c326202f941483a7249a8f088c842ea.tar.bz2 px4-nuttx-002549e43c326202f941483a7249a8f088c842ea.zip |
Allow in all loctions
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@826 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/examples/nsh/nsh_envcmds.c | 17 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_fscmds.c | 2 | ||||
-rw-r--r-- | nuttx/examples/nsh/nsh_main.c | 84 |
3 files changed, 58 insertions, 45 deletions
diff --git a/nuttx/examples/nsh/nsh_envcmds.c b/nuttx/examples/nsh/nsh_envcmds.c index ce05fab82..86b7651e8 100644 --- a/nuttx/examples/nsh/nsh_envcmds.c +++ b/nuttx/examples/nsh/nsh_envcmds.c @@ -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"); } diff --git a/nuttx/examples/nsh/nsh_fscmds.c b/nuttx/examples/nsh/nsh_fscmds.c index 06ced9a04..721a30cfe 100644 --- a/nuttx/examples/nsh/nsh_fscmds.c +++ b/nuttx/examples/nsh/nsh_fscmds.c @@ -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) { diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c index d318802e1..32c4a94a6 100644 --- a/nuttx/examples/nsh/nsh_main.c +++ b/nuttx/examples/nsh/nsh_main.c @@ -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; } } + else + { + /* Does the token begin with '"'? */ - /* Does the token begin with '"'? */ + if (*pbegin == '"') + { + /* Yes.. then only another '"' can terminate the string */ - else 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 */ - pbegin++; - term = "\""; - } - else - { - /* No, then any of the usual terminators will terminate the argument */ + term = g_delim; + } - term = g_delim; - } + /* Find the end of the string */ - /* Find the end of the string */ + for (pend = pbegin + 1; + *pend && strchr(term, *pend) == NULL; + pend++); - 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. + */ - /* 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; + } + + /* Check for references to environment variables */ - 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; } |