summaryrefslogtreecommitdiff
path: root/apps/nshlib/nsh.h
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-01-17 13:24:44 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-01-17 13:24:44 -0600
commit3895a010a5c8d971ec04802ae569f44a06bd572b (patch)
treed81fc78a1873dd6faa5b634845ddb940c6ce2cab /apps/nshlib/nsh.h
parent5d3165161596265372177859b50577ae1ee54be0 (diff)
downloadpx4-nuttx-3895a010a5c8d971ec04802ae569f44a06bd572b.tar.gz
px4-nuttx-3895a010a5c8d971ec04802ae569f44a06bd572b.tar.bz2
px4-nuttx-3895a010a5c8d971ec04802ae569f44a06bd572b.zip
Add true and false commands; repartition some logic to better support forthcoming looping
Diffstat (limited to 'apps/nshlib/nsh.h')
-rw-r--r--apps/nshlib/nsh.h39
1 files changed, 21 insertions, 18 deletions
diff --git a/apps/nshlib/nsh.h b/apps/nshlib/nsh.h
index a38d04c4a..a9db6e5d2 100644
--- a/apps/nshlib/nsh.h
+++ b/apps/nshlib/nsh.h
@@ -1,7 +1,7 @@
/****************************************************************************
* apps/nshlib/nsh.h
*
- * Copyright (C) 2007-2013 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007-2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -453,23 +453,28 @@
/****************************************************************************
* Public Types
****************************************************************************/
+/* State when parsing and if-then-else sequence */
enum nsh_parser_e
{
- NSH_PARSER_NORMAL = 0,
- NSH_PARSER_IF,
- NSH_PARSER_THEN,
- NSH_PARSER_ELSE
+ NSH_PARSER_NORMAL = 0, /* Not in any special sequence */
+ NSH_PARSER_IF, /* Just parsed 'if', expect condition */
+ NSH_PARSER_THEN, /* Just parsed 'then', looking for 'else' or 'fi' */
+ NSH_PARSER_ELSE /* Just parsed 'else', look for 'fi' */
};
-struct nsh_state_s
+/* All state data for parsing one if-then-else sequence */
+
+struct nsh_ifthenelse_s
{
- uint8_t ns_ifcond : 1; /* Value of command in 'if' statement */
- uint8_t ns_disabled : 1; /* TRUE: Unconditionally disabled */
- uint8_t ns_unused : 4;
- uint8_t ns_state : 2; /* Parser state (see enum nsh_parser_e) */
+ uint8_t ie_ifcond : 1; /* Value of command in 'if' statement */
+ uint8_t ie_disabled : 1; /* TRUE: Unconditionally disabled */
+ uint8_t ie_unused : 4;
+ uint8_t ie_state : 2; /* Parser state (see enum nsh_parser_e) */
};
+/* These structure provides the overall state of the parser */
+
struct nsh_parser_s
{
#ifndef CONFIG_NSH_DISABLEBG
@@ -479,19 +484,17 @@ struct nsh_parser_s
bool np_redirect; /* true: Output from the last command was re-directed */
#endif
bool np_fail; /* true: The last command failed */
-#ifndef CONFIG_NSH_DISABLESCRIPT
- uint8_t np_ndx; /* Current index into np_st[] */
-#endif
#ifndef CONFIG_NSH_DISABLEBG
int np_nice; /* "nice" value applied to last background cmd */
#endif
- /* This is a stack of parser state information. It supports nested
- * execution of commands that span multiple lines (like if-then-else-fi)
- */
-
#ifndef CONFIG_NSH_DISABLESCRIPT
- struct nsh_state_s np_st[CONFIG_NSH_NESTDEPTH];
+ FILE *np_stream; /* Stream of current script */
+ uint8_t np_iendx; /* Current index into np_iestate[] */
+
+ /* This is a stack of if-then-else state information. */
+
+ struct nsh_ifthenelse_s np_iestate[CONFIG_NSH_NESTDEPTH];
#endif
};