summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh_script.c
diff options
context:
space:
mode:
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)
{