summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_script.c
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-01-17 15:56:32 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-01-17 15:56:32 -0600
commite33bd6bd784ba0334beb0481d82416be38fbb54d (patch)
treeb87ce3e8c39930580c812fdee5cdfed7d700fd8a /apps/nshlib/nsh_script.c
parent3895a010a5c8d971ec04802ae569f44a06bd572b (diff)
downloadpx4-nuttx-e33bd6bd784ba0334beb0481d82416be38fbb54d.tar.gz
px4-nuttx-e33bd6bd784ba0334beb0481d82416be38fbb54d.tar.bz2
px4-nuttx-e33bd6bd784ba0334beb0481d82416be38fbb54d.zip
NSH: Add support for while-do-done and until-do-done loops
Diffstat (limited to 'apps/nshlib/nsh_script.c')
-rw-r--r--apps/nshlib/nsh_script.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/apps/nshlib/nsh_script.c b/apps/nshlib/nsh_script.c
index 088df6878..e5c1958a1 100644
--- a/apps/nshlib/nsh_script.c
+++ b/apps/nshlib/nsh_script.c
@@ -132,6 +132,23 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
/* Get the next line of input from the file */
fflush(stdout);
+
+ /* Get the current file position. This is used to control
+ * looping. If a loop begins in the next line, then this file
+ * offset will be needed to locate the top of the loop in the
+ * script file. Note that ftell will return -1 on failure.
+ */
+
+ vtbl->np.np_foffs = ftell(vtbl->np.np_stream);
+ vtbl->np.np_loffs = 0;
+
+ if (vtbl->np.np_foffs < 0)
+ {
+ nsh_output(vtbl, g_fmtcmdfailed, "loop", "ftell", NSH_ERRNO);
+ }
+
+ /* Now read the next line from the script file */
+
pret = fgets(buffer, CONFIG_NSH_LINELEN, vtbl->np.np_stream);
if (pret)
{