From ffaed10379587684fb342c561bbb12fe0ed60071 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sun, 17 Aug 2008 19:57:40 +0000 Subject: [PATCH] NSH now supports comments git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@830 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog | 9 ++--- Documentation/NuttX.html | 9 ++--- examples/nsh/nsh_main.c | 72 +++++++++++++++++++++++----------------- 3 files changed, 52 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9ba531c3559..ea14d3f0ecb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -394,19 +394,19 @@ 0.3.13 2008-xx-xx Gregory Nutt - * Added mkfatfs, mkfifo, sleep, usleep and nice commands to NSH + * NSH: Added mkfatfs, mkfifo, sleep, usleep and nice commands * Fixed problem with console input in Cygwin-based simulator; NSH now works with simulator. * NSH will now execute commands in background * sched_get_priority_max/min returned error on SCHED_RR * Removed duplicate getenv() implementation in /lib * Correct detection of End-of-File in fgets - * Implement sh and crude script handler in NSH + * NSH: Implemented sh and crude script handler * Fix prototype of read() and write(). Need to use ssize_t and size_t, not int and unsigned int. - * Add support for redirection of command output in NSH + * NSH now supports redirection of command output * NSH can now use both telnet and serial front ends together - * $variable can be used for any command value in NSH. + * NSH: $variable can be used for any command value * Fixed an error in opendir() that could cause an assertion to fail inappropriately. * Correct an error in the FAT that caused files opened for writing with @@ -414,4 +414,5 @@ end of the file in that case. * NSH now supports last exit status $? * NSH now supports if-then[-else]-fi construct + * NSH now supports comments beginning with '#' diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index f84038533cf..fcf807ef795 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -1028,19 +1028,19 @@ buildroot-0.1.0 2007-03-09 <spudmonkey@racsa.co.cr>
    nuttx-0.3.13 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> - * Added mkfatfs, mkfifo, sleep, usleep and nice commands to NSH + * NSH: Added mkfatfs, mkfifo, sleep, usleep and nice commands * Fixed problem with console input in Cygwin-based simulator; NSH now works with simulator. * NSH will now execute commands in background * sched_get_priority_max/min returned error on SCHED_RR * Removed duplicate getenv() implementation in /lib * Correct detection of End-of-File in fgets - * Implement sh and crude script handler in NSH + * NSH: Implemented sh and crude script handler * Fix prototype of read() and write(). Need to use ssize_t and size_t, not int and unsigned int. - * Add support for redirection of command output in NSH + * NSH now supports redirection of command output * NSH can now use both telnet and serial front ends together - * $variable can be used for any command value in NSH. + * NSH: $variable can be used for any command value * Fixed an error in opendir() that could cause an assertion to fail inappropriately. * Correct an error in the FAT that caused files opened for writing with @@ -1048,6 +1048,7 @@ nuttx-0.3.13 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> end of the file in that case. * NSH now supports last exit status $? * NSH now supports if-then[-else]-fi construct + * NSH now supports comments beginning with '#' pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index bde02fc03d6..b2915a75aeb 100644 --- a/examples/nsh/nsh_main.c +++ b/examples/nsh/nsh_main.c @@ -321,7 +321,7 @@ char *nsh_argument(FAR struct nsh_vtbl_s *vtbl, char **saveptr) return NULL; } - /* Does the token begin with '>' */ + /* Does the token begin with '>' -- redirection of output? */ if (*pbegin == '>') { @@ -330,17 +330,29 @@ char *nsh_argument(FAR struct nsh_vtbl_s *vtbl, char **saveptr) if (*(pbegin + 1) == '>') { *saveptr = pbegin + 2; - pbegin = (char*)g_redirect2; + pbegin = (char*)g_redirect2; } else { *saveptr = pbegin + 1; - pbegin = (char*)g_redirect1; + pbegin = (char*)g_redirect1; } } + + /* Does the token begin with '#' -- comment */ + + else if (*pbegin == '#') + { + /* Return NULL meaning that we are at the end of the line */ + + *saveptr = pbegin; + pbegin = NULL; + } else { - /* Does the token begin with '"'? */ + /* Otherwise, we are going to have to parse to find the end of + * the token. Does the token begin with '"'? + */ if (*pbegin == '"') { @@ -379,41 +391,41 @@ char *nsh_argument(FAR struct nsh_vtbl_s *vtbl, char **saveptr) /* Save the pointer where we left off */ *saveptr = pend; - } - /* Check for references to environment variables */ + /* Check for references to environment variables */ - if (pbegin[0] == '$' && !quoted) - { - /* Check for built-in variables */ - - if (strcmp(pbegin, g_exitstatus) == 0) + if (pbegin[0] == '$' && !quoted) { - if (vtbl->np.np_fail) - { - return (char*)g_failure; - } - else - { - return (char*)g_success; - } - } + /* Check for built-in variables */ - /* Not a built-in? Return the value of the environment variable with this name */ + if (strcmp(pbegin, g_exitstatus) == 0) + { + if (vtbl->np.np_fail) + { + return (char*)g_failure; + } + else + { + return (char*)g_success; + } + } + + /* Not a built-in? Return the value of the environment variable with this name */ #ifndef CONFIG_DISABLE_ENVIRON - else - { - char *value = getenv(pbegin+1); - if (value) - { - return value; - } else { - return (char*)""; + char *value = getenv(pbegin+1); + if (value) + { + return value; + } + else + { + return (char*)""; + } } - } #endif + } } /* Return the beginning of the token. */