summaryrefslogtreecommitdiff
path: root/nuttx/examples/nsh/nsh.h
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-19 23:16:45 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-19 23:16:45 +0000
commit105215cc7a1ee50bdced4a0e64ec5efd84ae6377 (patch)
treef66a373f7d62b27f1322ecd26b675c5a8e54a178 /nuttx/examples/nsh/nsh.h
parent2cde9d488e766651e1641d9ab4c41237c3647fa3 (diff)
downloadpx4-nuttx-105215cc7a1ee50bdced4a0e64ec5efd84ae6377.tar.gz
px4-nuttx-105215cc7a1ee50bdced4a0e64ec5efd84ae6377.tar.bz2
px4-nuttx-105215cc7a1ee50bdced4a0e64ec5efd84ae6377.zip
Support nested if-then[-else]-fi
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@832 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/examples/nsh/nsh.h')
-rw-r--r--nuttx/examples/nsh/nsh.h27
1 files changed, 25 insertions, 2 deletions
diff --git a/nuttx/examples/nsh/nsh.h b/nuttx/examples/nsh/nsh.h
index 574e03221..57c75e1bc 100644
--- a/nuttx/examples/nsh/nsh.h
+++ b/nuttx/examples/nsh/nsh.h
@@ -87,6 +87,14 @@
# define CONFIG_EXAMPLES_NSH_STACKSIZE 4096
#endif
+/* The maximum number of nested if-then[-else]-fi sequences that
+ * are permissable.
+ */
+
+#ifndef CONFIG_EXAMPLES_NSH_NESTDEPTH
+# define CONFIG_EXAMPLES_NSH_NESTDEPTH 3
+#endif
+
/* Define to enable dumping of all input/output buffers */
#undef CONFIG_EXAMPLES_NSH_TELNETD_DUMPBUFFER
@@ -120,14 +128,27 @@ enum nsh_parser_e
NSH_PARSER_ELSE
};
+struct nsh_state_s
+{
+ ubyte ns_ifcond : 1; /* Value of command in 'if' statement */
+ ubyte ns_disabled : 1; /* TRUE: Unconditionally disabled */
+ ubyte ns_unused : 4;
+ ubyte ns_state : 2; /* Parser state (see enum nsh_parser_e) */
+};
+
struct nsh_parser_s
{
boolean np_bg; /* TRUE: The last command executed in background */
boolean np_redirect; /* TRUE: Output from the last command was re-directed */
boolean np_fail; /* TRUE: The last command failed */
- boolean np_ifcond; /* Value of command in 'if' statement */
- ubyte np_state; /* Parser state (see enum nsh_parser_e) */
+ ubyte np_ndx; /* Current index into np_st[] */
int np_nice; /* "nice" value applied to last background cmd */
+
+ /* This is a stack of parser state information. It supports nested
+ * execution of commands that span multiple lines (like if-then-else-fi)
+ */
+
+ struct nsh_state_s np_st[CONFIG_EXAMPLES_NSH_NESTDEPTH];
};
struct nsh_vtbl_s
@@ -165,9 +186,11 @@ extern const char g_fmtcmdnotfound[];
extern const char g_fmtcmdnotimpl[];
extern const char g_fmtnosuch[];
extern const char g_fmttoomanyargs[];
+extern const char g_fmtdeepnesting[];
extern const char g_fmtcontext[];
extern const char g_fmtcmdfailed[];
extern const char g_fmtcmdoutofmemory[];
+extern const char g_fmtinternalerror[];
/****************************************************************************
* Public Function Prototypes