mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
Add TELNET front end to NSH
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@421 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -266,3 +266,4 @@
|
|||||||
* Correct processing of input UDP broadcast packets.
|
* Correct processing of input UDP broadcast packets.
|
||||||
* Verfied basic DHCP client functionality (netutils/dhcpc)
|
* Verfied basic DHCP client functionality (netutils/dhcpc)
|
||||||
* Implemented send() timeout logic
|
* Implemented send() timeout logic
|
||||||
|
* Add TELNETD front end to NSH (examples/nsh)
|
||||||
|
|||||||
@@ -754,6 +754,7 @@ Other memory:
|
|||||||
* Correct processing of input UDP broadcast packets.
|
* Correct processing of input UDP broadcast packets.
|
||||||
* Verfied basic DHCP client functionality (netutils/dhcpc)
|
* Verfied basic DHCP client functionality (netutils/dhcpc)
|
||||||
* Implemented send() timeout logic
|
* Implemented send() timeout logic
|
||||||
|
* Add TELNETD front end to NSH (examples/nsh)
|
||||||
</pre></ul>
|
</pre></ul>
|
||||||
|
|
||||||
<table width ="100%">
|
<table width ="100%">
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ o Build system
|
|||||||
- Dependencies do not work correctly under configs/<board>/src (same as arch/<arch>/src/board).
|
- Dependencies do not work correctly under configs/<board>/src (same as arch/<arch>/src/board).
|
||||||
|
|
||||||
o Applications & Tests
|
o Applications & Tests
|
||||||
|
- Verify TELNET frontend to nsh
|
||||||
|
|
||||||
o ARM
|
o ARM
|
||||||
- Add option to use a separate stack for interrupt handling. At present,
|
- Add option to use a separate stack for interrupt handling. At present,
|
||||||
@@ -75,6 +76,7 @@ o ARM
|
|||||||
user stack allocation larger than needed.
|
user stack allocation larger than needed.
|
||||||
|
|
||||||
o ARM/C5471
|
o ARM/C5471
|
||||||
|
- Needs an Ethernet driver
|
||||||
|
|
||||||
o ARM/DM320
|
o ARM/DM320
|
||||||
- It seems that when a lot of debug statements are added, the system no
|
- It seems that when a lot of debug statements are added, the system no
|
||||||
|
|||||||
@@ -284,7 +284,7 @@ __start:
|
|||||||
#endif
|
#endif
|
||||||
/* Perform early serial initialization */
|
/* Perform early serial initialization */
|
||||||
|
|
||||||
#ifdef CONFIG_DEV_CONSOLE
|
#if defined(CONFIG_DEV_CONSOLE) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
bl up_earlyserialinit
|
bl up_earlyserialinit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -104,10 +104,13 @@ __start:
|
|||||||
blt 1b
|
blt 1b
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_DEV_CONSOLE) && CONFIG_NFILE_DESCRIPTORS >0
|
||||||
/* Perform early serial initialization */
|
/* Perform early serial initialization */
|
||||||
|
|
||||||
mov fp, #0
|
mov fp, #0
|
||||||
bl up_earlyserialinit
|
bl up_earlyserialinit
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG
|
#ifdef CONFIG_DEBUG
|
||||||
mov r0, #'C'
|
mov r0, #'C'
|
||||||
|
|||||||
@@ -299,6 +299,18 @@ CONFIG_NET_BROADCAST=n
|
|||||||
CONFIG_NET_DHCP_LIGHT=n
|
CONFIG_NET_DHCP_LIGHT=n
|
||||||
CONFIG_NET_RESOLV_ENTRIES=4
|
CONFIG_NET_RESOLV_ENTRIES=4
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Stack and heap information
|
# Stack and heap information
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -288,6 +288,18 @@ CONFIG_NET_BROADCAST=n
|
|||||||
CONFIG_NET_DHCP_LIGHT=n
|
CONFIG_NET_DHCP_LIGHT=n
|
||||||
CONFIG_NET_RESOLV_ENTRIES=4
|
CONFIG_NET_RESOLV_ENTRIES=4
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Stack and heap information
|
# Stack and heap information
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -312,6 +312,18 @@ CONFIG_NET_BROADCAST=n
|
|||||||
CONFIG_NET_DHCP_LIGHT=n
|
CONFIG_NET_DHCP_LIGHT=n
|
||||||
CONFIG_NET_RESOLV_ENTRIES=4
|
CONFIG_NET_RESOLV_ENTRIES=4
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Stack and heap information
|
# Stack and heap information
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -317,6 +317,18 @@ CONFIG_EXAMPLE_NETTEST_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
|||||||
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
|
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# DM90x0 Driver Settings
|
# DM90x0 Driver Settings
|
||||||
CONFIG_NET_DM90x0=n
|
CONFIG_NET_DM90x0=n
|
||||||
|
|||||||
@@ -317,6 +317,18 @@ CONFIG_EXAMPLE_NETTEST_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
|||||||
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
|
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# DM90x0 Driver Settings
|
# DM90x0 Driver Settings
|
||||||
CONFIG_NET_DM90x0=y
|
CONFIG_NET_DM90x0=y
|
||||||
|
|||||||
@@ -325,6 +325,18 @@ CONFIG_EXAMPLE_UDP_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
|||||||
CONFIG_EXAMPLE_UDP_NETMASK=(255<<24|255<<16|255<<8|0)
|
CONFIG_EXAMPLE_UDP_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
CONFIG_EXAMPLE_UDP_SERVERIP=(10<<24|0<<16|0<<8|1)
|
CONFIG_EXAMPLE_UDP_SERVERIP=(10<<24|0<<16|0<<8|1)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# DM90x0 Driver Settings
|
# DM90x0 Driver Settings
|
||||||
CONFIG_NET_DM90x0=y
|
CONFIG_NET_DM90x0=y
|
||||||
|
|||||||
@@ -317,6 +317,18 @@ CONFIG_EXAMPLE_NETTEST_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
|||||||
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
|
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(10<<24|0<<16|0<<8|1)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# DM90x0 Driver Settings
|
# DM90x0 Driver Settings
|
||||||
CONFIG_NET_DM90x0=y
|
CONFIG_NET_DM90x0=y
|
||||||
|
|||||||
@@ -285,6 +285,18 @@ CONFIG_NET_BROADCAST=n
|
|||||||
CONFIG_NET_DHCP_LIGHT=n
|
CONFIG_NET_DHCP_LIGHT=n
|
||||||
CONFIG_NET_RESOLV_ENTRIES=4
|
CONFIG_NET_RESOLV_ENTRIES=4
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Stack and heap information
|
# Stack and heap information
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -279,6 +279,18 @@ CONFIG_EXAMPLE_NETTEST_DRIPADDR=(192<<24|168<<16|0<<8|1)
|
|||||||
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(192<<24|168<<16|0<<8|106)
|
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(192<<24|168<<16|0<<8|106)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Stack and heap information
|
# Stack and heap information
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -280,6 +280,18 @@ CONFIG_EXAMPLE_NETTEST_DRIPADDR=(192<<24|168<<16|0<<8|1)
|
|||||||
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
CONFIG_EXAMPLE_NETTEST_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(192<<24|168<<16|0<<8|106)
|
CONFIG_EXAMPLE_NETTEST_CLIENTIP=(192<<24|168<<16|0<<8|106)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Settings for examples/nsh
|
||||||
|
CONFIG_EXAMPLES_NSH_TELNET=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IOBUFFER_SIZE=512
|
||||||
|
CONFIG_EXAMPLES_NSH_CMD_SIZE=40
|
||||||
|
CONFIG_EXAMPLES_NSH_STACKSIZE=4096
|
||||||
|
CONFIG_EXAMPLES_NSH_DHCPC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_NOMAC=n
|
||||||
|
CONFIG_EXAMPLES_NSH_IPADDR=(10<<24|0<<16|0<<8|2)
|
||||||
|
CONFIG_EXAMPLES_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1)
|
||||||
|
CONFIG_EXAMPLES_NSH_NETMASK=(255<<24|255<<16|255<<8|0)
|
||||||
|
|
||||||
# Stack and heap information
|
# Stack and heap information
|
||||||
#
|
#
|
||||||
# CONFIG_BOOT_FROM_FLASH - Some configurations support XIP
|
# CONFIG_BOOT_FROM_FLASH - Some configurations support XIP
|
||||||
|
|||||||
+11
-4
@@ -1,5 +1,5 @@
|
|||||||
############################################################
|
############################################################################
|
||||||
# Makefile
|
# examples/nsh/Makefile
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
# Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
#
|
||||||
############################################################
|
############################################################################
|
||||||
|
|
||||||
-include $(TOPDIR)/.config
|
-include $(TOPDIR)/.config
|
||||||
-include $(TOPDIR)/Make.defs
|
-include $(TOPDIR)/Make.defs
|
||||||
@@ -39,8 +39,15 @@
|
|||||||
MKDEP = $(TOPDIR)/tools/mkdeps.sh
|
MKDEP = $(TOPDIR)/tools/mkdeps.sh
|
||||||
|
|
||||||
ASRCS =
|
ASRCS =
|
||||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
|
||||||
CSRCS = nsh_main.c nsh_fscmds.c nsh_proccmds.c nsh_envcmds.c
|
CSRCS = nsh_main.c nsh_fscmds.c nsh_proccmds.c nsh_envcmds.c
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_EXAMPLES_NSH_TELNET),y)
|
||||||
|
CSRCS += nsh_telnetd.c
|
||||||
|
else
|
||||||
|
CSRCS += nsh_serial.c
|
||||||
|
endif
|
||||||
|
|
||||||
|
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||||
|
|
||||||
SRCS = $(ASRCS) $(CSRCS)
|
SRCS = $(ASRCS) $(CSRCS)
|
||||||
|
|||||||
+48
-15
@@ -41,23 +41,30 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
#ifdef CONFIG_EXAMPLES_NSH_TELNET
|
||||||
|
#else
|
||||||
|
# include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define NSH_MAX_ARGUMENTS 6
|
||||||
|
|
||||||
#define errno (*get_errno_ptr())
|
#define errno (*get_errno_ptr())
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
typedef void (*cmd_t)(int argc, char **argv);
|
typedef void (*cmd_t)(FAR void *handle, int argc, char **argv);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
extern const char g_nshprompt[];
|
||||||
extern const char g_fmtargrequired[];
|
extern const char g_fmtargrequired[];
|
||||||
extern const char g_fmtarginvalid[];
|
extern const char g_fmtarginvalid[];
|
||||||
extern const char g_fmtcmdnotfound[];
|
extern const char g_fmtcmdnotfound[];
|
||||||
@@ -71,30 +78,56 @@ extern const char g_fmtcmdoutofmemory[];
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
/* Message handler */
|
||||||
extern void cmd_cat(int argc, char **argv);
|
|
||||||
extern void cmd_cp(int argc, char **argv);
|
extern int nsh_parse(FAR void *handle, char *cmdline);
|
||||||
|
|
||||||
|
/* I/O interfaces */
|
||||||
|
|
||||||
|
#ifdef CONFIG_EXAMPLES_NSH_TELNET
|
||||||
|
|
||||||
|
extern int nsh_telnetmain(void);
|
||||||
|
extern int nsh_telnetout(FAR void *handle, const char *fmt, ...);
|
||||||
|
|
||||||
|
# define nsh_main() nsh_telnetmain()
|
||||||
|
# define nsh_output(handle, ...) nsh_telnetout(handle, __VA_ARGS__)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
extern int nsh_serialmain(void);
|
||||||
|
|
||||||
|
# define nsh_main() nsh_serialmain()
|
||||||
|
# define nsh_output(handle, ...) printf(__VA_ARGS__)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
extern void cmd_echo(int argc, char **argv);
|
|
||||||
extern void cmd_exec(int argc, char **argv);
|
/* Shell command handlers */
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
extern void cmd_ls(int argc, char **argv);
|
extern void cmd_cat(FAR void *handle, int argc, char **argv);
|
||||||
|
extern void cmd_cp(FAR void *handle, int argc, char **argv);
|
||||||
|
#endif
|
||||||
|
extern void cmd_echo(FAR void *handle, int argc, char **argv);
|
||||||
|
extern void cmd_exec(FAR void *handle, int argc, char **argv);
|
||||||
|
extern void cmd_exit(FAR void *handle, int argc, char **argv);
|
||||||
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
|
extern void cmd_ls(FAR void *handle, int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
extern void cmd_mkdir(int argc, char **argv);
|
extern void cmd_mkdir(FAR void *handle, int argc, char **argv);
|
||||||
extern void cmd_mount(int argc, char **argv);
|
extern void cmd_mount(FAR void *handle, int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
extern void cmd_ps(int argc, char **argv);
|
extern void cmd_ps(FAR void *handle, int argc, char **argv);
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
#ifndef CONFIG_DISABLE_ENVIRON
|
||||||
extern void cmd_set(int argc, char **argv);
|
extern void cmd_set(FAR void *handle, int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
extern void cmd_rm(int argc, char **argv);
|
extern void cmd_rm(FAR void *handle, int argc, char **argv);
|
||||||
extern void cmd_rmdir(int argc, char **argv);
|
extern void cmd_rmdir(FAR void *handle, int argc, char **argv);
|
||||||
extern void cmd_umount(int argc, char **argv);
|
extern void cmd_umount(FAR void *handle, int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
#ifndef CONFIG_DISABLE_ENVIRON
|
||||||
extern void cmd_unset(int argc, char **argv);
|
extern void cmd_unset(FAR void *handle, int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __NSH_H */
|
#endif /* __NSH_H */
|
||||||
|
|||||||
@@ -79,7 +79,7 @@
|
|||||||
* Name: cmd_echo
|
* Name: cmd_echo
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void cmd_echo(int argc, char **argv)
|
void cmd_echo(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@@ -97,16 +97,16 @@ void cmd_echo(int argc, char **argv)
|
|||||||
char *value = getenv(argv[i]+1);
|
char *value = getenv(argv[i]+1);
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
printf("%s ", value);
|
nsh_output(handle, "%s ", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
printf("%s ", argv[i]);
|
nsh_output(handle, "%s ", argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
putchar('\n');
|
nsh_output(handle, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -114,11 +114,11 @@ void cmd_echo(int argc, char **argv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
#ifndef CONFIG_DISABLE_ENVIRON
|
||||||
void cmd_set(int argc, char **argv)
|
void cmd_set(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (setenv(argv[1], argv[2], TRUE) < 0)
|
if (setenv(argv[1], argv[2], TRUE) < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "setenv", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "setenv", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -128,11 +128,11 @@ void cmd_set(int argc, char **argv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_ENVIRON
|
#ifndef CONFIG_DISABLE_ENVIRON
|
||||||
void cmd_unset(int argc, char **argv)
|
void cmd_unset(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (unsetenv(argv[1]) < 0)
|
if (unsetenv(argv[1]) < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "unsetenv", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "unsetenv", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+49
-47
@@ -90,7 +90,7 @@
|
|||||||
* Private Types
|
* Private Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
typedef int (*direntry_handler_t)(const char *, struct dirent *, void *);
|
typedef int (*direntry_handler_t)(FAR void *, const char *, struct dirent *, void *);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
@@ -151,7 +151,8 @@ static char *getdirpath(const char *path, const char *file)
|
|||||||
* Name: foreach_direntry
|
* Name: foreach_direntry
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int foreach_direntry(const char *cmd, const char *dirpath,
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
|
static int foreach_direntry(FAR void *handle, const char *cmd, const char *dirpath,
|
||||||
direntry_handler_t handler, void *pvarg)
|
direntry_handler_t handler, void *pvarg)
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
@@ -171,7 +172,7 @@ static int foreach_direntry(const char *cmd, const char *dirpath,
|
|||||||
{
|
{
|
||||||
/* Failed to open the directory */
|
/* Failed to open the directory */
|
||||||
|
|
||||||
printf(g_fmtnosuch, cmd, "directory", dirpath);
|
nsh_output(handle, g_fmtnosuch, cmd, "directory", dirpath);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +190,7 @@ static int foreach_direntry(const char *cmd, const char *dirpath,
|
|||||||
|
|
||||||
/* Call the handler with this directory entry */
|
/* Call the handler with this directory entry */
|
||||||
|
|
||||||
if (handler(dirpath, entryp, pvarg) < 0)
|
if (handler(handle, dirpath, entryp, pvarg) < 0)
|
||||||
{
|
{
|
||||||
/* The handler reported a problem */
|
/* The handler reported a problem */
|
||||||
|
|
||||||
@@ -201,13 +202,14 @@ static int foreach_direntry(const char *cmd, const char *dirpath,
|
|||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: ls_handler
|
* Name: ls_handler
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
static int ls_handler(const char *dirpath, struct dirent *entryp, void *pvarg)
|
static int ls_handler(FAR void *handle, const char *dirpath, struct dirent *entryp, void *pvarg)
|
||||||
{
|
{
|
||||||
unsigned int lsflags = (unsigned int)pvarg;
|
unsigned int lsflags = (unsigned int)pvarg;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -225,7 +227,7 @@ static int ls_handler(const char *dirpath, struct dirent *entryp, void *pvarg)
|
|||||||
free(fullpath);
|
free(fullpath);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, "ls", "stat", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, "ls", "stat", strerror(errno));
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,30 +292,30 @@ static int ls_handler(const char *dirpath, struct dirent *entryp, void *pvarg)
|
|||||||
details[9]='x';
|
details[9]='x';
|
||||||
}
|
}
|
||||||
|
|
||||||
printf(" %s", details);
|
nsh_output(handle, " %s", details);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((lsflags & LSFLAGS_SIZE) != 0)
|
if ((lsflags & LSFLAGS_SIZE) != 0)
|
||||||
{
|
{
|
||||||
printf("%8d", buf.st_size);
|
nsh_output(handle, "%8d", buf.st_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* then provide the filename that is common to normal and verbose output */
|
/* then provide the filename that is common to normal and verbose output */
|
||||||
|
|
||||||
#ifdef CONFIG_FULL_PATH
|
#ifdef CONFIG_FULL_PATH
|
||||||
printf(" %s/%s", arg, entryp->d_name);
|
nsh_output(handle, " %s/%s", arg, entryp->d_name);
|
||||||
#else
|
#else
|
||||||
printf(" %s", entryp->d_name);
|
nsh_output(handle, " %s", entryp->d_name);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (DIRENT_ISDIRECTORY(entryp->d_type))
|
if (DIRENT_ISDIRECTORY(entryp->d_type))
|
||||||
{
|
{
|
||||||
printf("/\n");
|
nsh_output(handle, "/\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
putchar('\n');
|
nsh_output(handle, "\n");
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
@@ -324,7 +326,7 @@ static int ls_handler(const char *dirpath, struct dirent *entryp, void *pvarg)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
static int ls_recursive(const char *dirpath, struct dirent *entryp, void *pvarg)
|
static int ls_recursive(FAR void *handle, const char *dirpath, struct dirent *entryp, void *pvarg)
|
||||||
{
|
{
|
||||||
/* Is this entry a directory? */
|
/* Is this entry a directory? */
|
||||||
|
|
||||||
@@ -337,12 +339,12 @@ static int ls_recursive(const char *dirpath, struct dirent *entryp, void *pvarg)
|
|||||||
|
|
||||||
/* List the directory contents */
|
/* List the directory contents */
|
||||||
|
|
||||||
printf("%s:\n", newpath);
|
nsh_output(handle, "%s:\n", newpath);
|
||||||
foreach_direntry("ls", newpath, ls_handler, pvarg);
|
foreach_direntry(handle, "ls", newpath, ls_handler, pvarg);
|
||||||
|
|
||||||
/* Then recurse to list each directory within the directory */
|
/* Then recurse to list each directory within the directory */
|
||||||
|
|
||||||
foreach_direntry("ls", newpath, ls_recursive, pvarg);
|
foreach_direntry(handle, "ls", newpath, ls_recursive, pvarg);
|
||||||
free(newpath);
|
free(newpath);
|
||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
@@ -358,7 +360,7 @@ static int ls_recursive(const char *dirpath, struct dirent *entryp, void *pvarg)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
void cmd_cat(int argc, char **argv)
|
void cmd_cat(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
|
||||||
@@ -367,7 +369,7 @@ void cmd_cat(int argc, char **argv)
|
|||||||
int fd = open(argv[1], O_RDONLY);
|
int fd = open(argv[1], O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "open", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,7 +387,7 @@ void cmd_cat(int argc, char **argv)
|
|||||||
|
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "read", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "read", strerror(errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,7 +407,7 @@ void cmd_cat(int argc, char **argv)
|
|||||||
|
|
||||||
if (errno != EINTR)
|
if (errno != EINTR)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "write", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "write", strerror(errno));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -433,7 +435,7 @@ void cmd_cat(int argc, char **argv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
void cmd_cp(int argc, char **argv)
|
void cmd_cp(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
char *fullpath = NULL;
|
char *fullpath = NULL;
|
||||||
@@ -448,7 +450,7 @@ void cmd_cp(int argc, char **argv)
|
|||||||
rdfd = open(argv[1], O_RDONLY);
|
rdfd = open(argv[1], O_RDONLY);
|
||||||
if (rdfd < 0)
|
if (rdfd < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "open", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", strerror(errno));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,7 +472,7 @@ void cmd_cp(int argc, char **argv)
|
|||||||
fullpath = getdirpath(argv[2], basename(argv[1]) );
|
fullpath = getdirpath(argv[2], basename(argv[1]) );
|
||||||
if (!fullpath)
|
if (!fullpath)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdoutofmemory, argv[0]);
|
nsh_output(handle, g_fmtcmdoutofmemory, argv[0]);
|
||||||
goto out_with_rdfd;
|
goto out_with_rdfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -490,7 +492,7 @@ void cmd_cp(int argc, char **argv)
|
|||||||
wrfd = open(wrpath, oflags, 0666);
|
wrfd = open(wrpath, oflags, 0666);
|
||||||
if (wrfd < 0)
|
if (wrfd < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "open", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", strerror(errno));
|
||||||
goto out_with_fullpath;
|
goto out_with_fullpath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,7 +516,7 @@ void cmd_cp(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
/* Read error */
|
/* Read error */
|
||||||
|
|
||||||
printf(g_fmtcmdfailed, argv[0], "read", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "read", strerror(errno));
|
||||||
goto out_with_wrfd;
|
goto out_with_wrfd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -531,7 +533,7 @@ void cmd_cp(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
/* Read error */
|
/* Read error */
|
||||||
|
|
||||||
printf(g_fmtcmdfailed, argv[0], "write", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "write", strerror(errno));
|
||||||
goto out_with_wrfd;
|
goto out_with_wrfd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -557,7 +559,7 @@ out_with_rdfd:
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
void cmd_ls(int argc, char **argv)
|
void cmd_ls(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
unsigned int lsflags = 0;
|
unsigned int lsflags = 0;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -583,7 +585,7 @@ void cmd_ls(int argc, char **argv)
|
|||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
printf(g_fmtarginvalid, argv[0]);
|
nsh_output(handle, g_fmtarginvalid, argv[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -592,24 +594,24 @@ void cmd_ls(int argc, char **argv)
|
|||||||
|
|
||||||
if (optind + 1 < argc)
|
if (optind + 1 < argc)
|
||||||
{
|
{
|
||||||
printf(g_fmttoomanyargs, argv[0]);
|
nsh_output(handle, g_fmttoomanyargs, argv[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (optind + 1 > argc)
|
else if (optind + 1 > argc)
|
||||||
{
|
{
|
||||||
printf(g_fmtargrequired, argv[0]);
|
nsh_output(handle, g_fmtargrequired, argv[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* List the directory contents */
|
/* List the directory contents */
|
||||||
|
|
||||||
printf("%s:\n", argv[optind]);
|
nsh_output(handle, "%s:\n", argv[optind]);
|
||||||
ret = foreach_direntry("ls", argv[optind], ls_handler, (void*)lsflags);
|
ret = foreach_direntry(handle, "ls", argv[optind], ls_handler, (void*)lsflags);
|
||||||
if (ret == OK && (lsflags & LSFLAGS_RECURSIVE) != 0)
|
if (ret == OK && (lsflags & LSFLAGS_RECURSIVE) != 0)
|
||||||
{
|
{
|
||||||
/* Then recurse to list each directory within the directory */
|
/* Then recurse to list each directory within the directory */
|
||||||
|
|
||||||
ret = foreach_direntry("ls", argv[optind], ls_recursive, (void*)lsflags);
|
ret = foreach_direntry(handle, "ls", argv[optind], ls_recursive, (void*)lsflags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -619,12 +621,12 @@ void cmd_ls(int argc, char **argv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
void cmd_mkdir(int argc, char **argv)
|
void cmd_mkdir(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
int result = mkdir(argv[1], 0777);
|
int result = mkdir(argv[1], 0777);
|
||||||
if ( result < 0)
|
if ( result < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "mkdir", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "mkdir", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -634,7 +636,7 @@ void cmd_mkdir(int argc, char **argv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
void cmd_mount(int argc, char **argv)
|
void cmd_mount(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *filesystem = 0;
|
char *filesystem = 0;
|
||||||
int result;
|
int result;
|
||||||
@@ -651,12 +653,12 @@ void cmd_mount(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ':':
|
case ':':
|
||||||
printf(g_fmtargrequired, argv[0]);
|
nsh_output(handle, g_fmtargrequired, argv[0]);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
printf(g_fmtarginvalid, argv[0]);
|
nsh_output(handle, g_fmtarginvalid, argv[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -665,12 +667,12 @@ void cmd_mount(int argc, char **argv)
|
|||||||
|
|
||||||
if (optind + 2 < argc)
|
if (optind + 2 < argc)
|
||||||
{
|
{
|
||||||
printf(g_fmttoomanyargs, argv[0]);
|
nsh_output(handle, g_fmttoomanyargs, argv[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (optind + 2 > argc)
|
else if (optind + 2 > argc)
|
||||||
{
|
{
|
||||||
printf(g_fmtargrequired, argv[0]);
|
nsh_output(handle, g_fmtargrequired, argv[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -678,7 +680,7 @@ void cmd_mount(int argc, char **argv)
|
|||||||
result = mount(argv[optind], argv[optind+1], filesystem, 0, NULL);
|
result = mount(argv[optind], argv[optind+1], filesystem, 0, NULL);
|
||||||
if ( result < 0)
|
if ( result < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "mount", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "mount", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -688,11 +690,11 @@ void cmd_mount(int argc, char **argv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
void cmd_rm(int argc, char **argv)
|
void cmd_rm(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (unlink(argv[1]) < 0)
|
if (unlink(argv[1]) < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "unlink", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "unlink", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -702,11 +704,11 @@ void cmd_rm(int argc, char **argv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
void cmd_rmdir(int argc, char **argv)
|
void cmd_rmdir(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (rmdir(argv[1]) < 0)
|
if (rmdir(argv[1]) < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "rmdir", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "rmdir", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -716,13 +718,13 @@ void cmd_rmdir(int argc, char **argv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
void cmd_umount(int argc, char **argv)
|
void cmd_umount(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
/* Perform the umount */
|
/* Perform the umount */
|
||||||
int result = umount(argv[1]);
|
int result = umount(argv[1]);
|
||||||
if ( result < 0)
|
if ( result < 0)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdfailed, argv[0], "umount", strerror(errno));
|
nsh_output(handle, g_fmtcmdfailed, argv[0], "umount", strerror(errno));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+71
-79
@@ -51,7 +51,6 @@
|
|||||||
|
|
||||||
#define CONFIG_NSH_LINE_SIZE 80
|
#define CONFIG_NSH_LINE_SIZE 80
|
||||||
#undef CONFIG_FULL_PATH
|
#undef CONFIG_FULL_PATH
|
||||||
#define NSH_MAX_ARGUMENTS 6
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Types
|
* Private Types
|
||||||
@@ -70,14 +69,13 @@ struct cmdmap_s
|
|||||||
* Private Function Prototypes
|
* Private Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void cmd_help(int argc, char **argv);
|
static void cmd_help(FAR void *handle, int argc, char **argv);
|
||||||
static void cmd_unrecognized(int argc, char **argv);
|
static void cmd_unrecognized(FAR void *handle, int argc, char **argv);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static char line[CONFIG_NSH_LINE_SIZE];
|
|
||||||
static const char delim[] = " \t\n";
|
static const char delim[] = " \t\n";
|
||||||
|
|
||||||
static const struct cmdmap_s g_cmdmap[] =
|
static const struct cmdmap_s g_cmdmap[] =
|
||||||
@@ -92,6 +90,7 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||||||
{ "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string> [<string>...]]" },
|
{ "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string> [<string>...]]" },
|
||||||
#endif
|
#endif
|
||||||
{ "exec", cmd_exec, 2, 3, "<hex-address>" },
|
{ "exec", cmd_exec, 2, 3, "<hex-address>" },
|
||||||
|
{ "exit", cmd_exit, 1, 1, NULL },
|
||||||
{ "help", cmd_help, 1, 1, NULL },
|
{ "help", cmd_help, 1, 1, NULL },
|
||||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||||
{ "ls", cmd_ls, 2, 5, "[-lRs] <dir-path>" },
|
{ "ls", cmd_ls, 2, 5, "[-lRs] <dir-path>" },
|
||||||
@@ -119,6 +118,7 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
const char g_nshprompt[] = "nsh> ";
|
||||||
const char g_fmtargrequired[] = "nsh: %s: missing required argument(s)\n";
|
const char g_fmtargrequired[] = "nsh: %s: missing required argument(s)\n";
|
||||||
const char g_fmtarginvalid[] = "nsh: %s: argument invalid\n";
|
const char g_fmtarginvalid[] = "nsh: %s: argument invalid\n";
|
||||||
const char g_fmtcmdnotfound[] = "nsh: %s: command not found\n";
|
const char g_fmtcmdnotfound[] = "nsh: %s: command not found\n";
|
||||||
@@ -136,20 +136,20 @@ const char g_fmtcmdoutofmemory[] = "nsh: %s: out of memory\n";
|
|||||||
* Name: cmd_help
|
* Name: cmd_help
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void cmd_help(int argc, char **argv)
|
static void cmd_help(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
const struct cmdmap_s *ptr;
|
const struct cmdmap_s *ptr;
|
||||||
|
|
||||||
printf("NSH commands:\n");
|
nsh_output(handle, "NSH commands:\n");
|
||||||
for (ptr = g_cmdmap; ptr->cmd; ptr++)
|
for (ptr = g_cmdmap; ptr->cmd; ptr++)
|
||||||
{
|
{
|
||||||
if (ptr->usage)
|
if (ptr->usage)
|
||||||
{
|
{
|
||||||
printf(" %s %s\n", ptr->cmd, ptr->usage);
|
nsh_output(handle, " %s %s\n", ptr->cmd, ptr->usage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf(" %s\n", ptr->cmd);
|
nsh_output(handle, " %s\n", ptr->cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -158,9 +158,9 @@ static void cmd_help(int argc, char **argv)
|
|||||||
* Name: cmd_unrecognized
|
* Name: cmd_unrecognized
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static void cmd_unrecognized(int argc, char **argv)
|
static void cmd_unrecognized(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
printf(g_fmtcmdnotfound, argv[0]);
|
nsh_output(handle, g_fmtcmdnotfound, argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -182,94 +182,86 @@ void user_initialize(void)
|
|||||||
|
|
||||||
int user_start(int argc, char *argv[])
|
int user_start(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
printf("NuttShell (NSH)\n");
|
return nsh_main();
|
||||||
fflush(stdout);
|
}
|
||||||
|
|
||||||
for (;;)
|
/****************************************************************************
|
||||||
|
* Name: nsh_parse
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int nsh_parse(FAR void *handle, char *cmdline)
|
||||||
|
{
|
||||||
|
const struct cmdmap_s *cmdmap;
|
||||||
|
char *argv[NSH_MAX_ARGUMENTS+1];
|
||||||
|
char *saveptr;
|
||||||
|
char *cmd;
|
||||||
|
int argc;
|
||||||
|
|
||||||
|
/* Parse out the command at the beginning of the line */
|
||||||
|
|
||||||
|
cmd = strtok_r(cmdline, " \t\n", &saveptr);
|
||||||
|
if (cmd)
|
||||||
{
|
{
|
||||||
const struct cmdmap_s *cmdmap;
|
cmd_t handler = cmd_unrecognized;
|
||||||
char *saveptr;
|
|
||||||
char *cmd;
|
|
||||||
|
|
||||||
/* Get the next line of input */
|
/* Parse all of the arguments following the command name */
|
||||||
|
|
||||||
fgets(line, CONFIG_NSH_LINE_SIZE, stdin);
|
|
||||||
|
|
||||||
/* Parse out the command at the beginning of the line */
|
argv[0] = cmd;
|
||||||
|
for (argc = 1; argc < NSH_MAX_ARGUMENTS+1; argc++)
|
||||||
cmd = strtok_r(line, " \t\n", &saveptr);
|
|
||||||
if (cmd)
|
|
||||||
{
|
{
|
||||||
cmd_t handler = cmd_unrecognized;
|
argv[argc] = strtok_r( NULL, " \t\n", &saveptr);
|
||||||
|
if (!argv[argc])
|
||||||
/* Parse all of the arguments following the command name */
|
|
||||||
|
|
||||||
char *cmd_argv[NSH_MAX_ARGUMENTS+1];
|
|
||||||
int cmd_argc;
|
|
||||||
|
|
||||||
cmd_argv[0] = cmd;
|
|
||||||
for (cmd_argc = 1; cmd_argc < NSH_MAX_ARGUMENTS+1; cmd_argc++)
|
|
||||||
{
|
{
|
||||||
cmd_argv[cmd_argc] = strtok_r( NULL, " \t\n", &saveptr);
|
break;
|
||||||
if ( !cmd_argv[cmd_argc] )
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cmd_argc > NSH_MAX_ARGUMENTS)
|
if (argc > NSH_MAX_ARGUMENTS)
|
||||||
|
{
|
||||||
|
nsh_output(handle, g_fmttoomanyargs, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* See if the command is one that we understand */
|
||||||
|
|
||||||
|
for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++)
|
||||||
|
{
|
||||||
|
if (strcmp(cmdmap->cmd, cmd) == 0)
|
||||||
{
|
{
|
||||||
printf(g_fmttoomanyargs, cmd);
|
/* Check if a valid number of arguments was provided. We
|
||||||
}
|
|
||||||
|
|
||||||
/* See if the command is one that we understand */
|
|
||||||
|
|
||||||
for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++)
|
|
||||||
{
|
|
||||||
if (strcmp(cmdmap->cmd, cmd) == 0)
|
|
||||||
{
|
|
||||||
/* Check if a valid number of arguments was provided. We
|
|
||||||
* do this simple, imperfect checking here so that it does
|
* do this simple, imperfect checking here so that it does
|
||||||
* not have to be performed in each command.
|
* not have to be performed in each command.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (cmd_argc < cmdmap->minargs)
|
if (argc < cmdmap->minargs)
|
||||||
{
|
{
|
||||||
/* Fewer than the minimum number were provided */
|
/* Fewer than the minimum number were provided */
|
||||||
|
|
||||||
printf(g_fmtargrequired, cmd);
|
nsh_output(handle, g_fmtargrequired, cmd);
|
||||||
handler = NULL;
|
return ERROR;
|
||||||
break;
|
}
|
||||||
}
|
else if (argc > cmdmap->maxargs)
|
||||||
else if (cmd_argc > cmdmap->maxargs)
|
{
|
||||||
{
|
/* More than the maximum number were provided */
|
||||||
/* More than the maximum number were provided */
|
|
||||||
|
|
||||||
printf(g_fmttoomanyargs, cmd);
|
nsh_output(handle, g_fmttoomanyargs, cmd);
|
||||||
handler = NULL;
|
return ERROR;
|
||||||
break;
|
}
|
||||||
}
|
else
|
||||||
else
|
{
|
||||||
{
|
/* A valid number of arguments were provided (this does
|
||||||
/* A valid number of arguments were provided (this does
|
* not mean they are right).
|
||||||
* not mean they are right.
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
handler = cmdmap->handler;
|
handler = cmdmap->handler;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If a error was detected above, handler will be nullified to
|
|
||||||
* prevent reporting multiple errors.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (handler)
|
|
||||||
{
|
|
||||||
handler(cmd_argc, cmd_argv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fflush(stdout);
|
|
||||||
|
handler(handle, argc, argv);
|
||||||
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -97,27 +97,27 @@ static void ps_task(FAR _TCB *tcb, FAR void *arg)
|
|||||||
{
|
{
|
||||||
boolean needcomma = FALSE;
|
boolean needcomma = FALSE;
|
||||||
int i;
|
int i;
|
||||||
printf("%5d %3d %4s %7s%c%c %8s ",
|
nsh_output(arg, "%5d %3d %4s %7s%c%c %8s ",
|
||||||
tcb->pid, tcb->sched_priority,
|
tcb->pid, tcb->sched_priority,
|
||||||
tcb->flags & TCB_FLAG_ROUND_ROBIN ? "RR " : "FIFO",
|
tcb->flags & TCB_FLAG_ROUND_ROBIN ? "RR " : "FIFO",
|
||||||
tcb->flags & TCB_FLAG_PTHREAD ? "PTHREAD" : "TASK ",
|
tcb->flags & TCB_FLAG_PTHREAD ? "PTHREAD" : "TASK ",
|
||||||
tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : ' ',
|
tcb->flags & TCB_FLAG_NONCANCELABLE ? 'N' : ' ',
|
||||||
tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : ' ',
|
tcb->flags & TCB_FLAG_CANCEL_PENDING ? 'P' : ' ',
|
||||||
g_statenames[tcb->task_state]);
|
g_statenames[tcb->task_state]);
|
||||||
|
|
||||||
printf("%s(", tcb->argv[0]);
|
nsh_output(arg, "%s(", tcb->argv[0]);
|
||||||
for (i = 1; i < CONFIG_MAX_TASK_ARGS+1 && tcb->argv[i]; i++)
|
for (i = 1; i < CONFIG_MAX_TASK_ARGS+1 && tcb->argv[i]; i++)
|
||||||
{
|
{
|
||||||
if (needcomma)
|
if (needcomma)
|
||||||
{
|
{
|
||||||
printf(", %p", tcb->argv[i]);
|
nsh_output(arg, ", %p", tcb->argv[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("%p", tcb->argv[i]);
|
nsh_output(arg, "%p", tcb->argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf(")\n");
|
nsh_output(arg, ")\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -128,7 +128,7 @@ static void ps_task(FAR _TCB *tcb, FAR void *arg)
|
|||||||
* Name: cmd_exec
|
* Name: cmd_exec
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void cmd_exec(int argc, char **argv)
|
void cmd_exec(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *endptr;
|
char *endptr;
|
||||||
long addr;
|
long addr;
|
||||||
@@ -136,11 +136,11 @@ void cmd_exec(int argc, char **argv)
|
|||||||
addr = strtol(argv[1], &endptr, 0);
|
addr = strtol(argv[1], &endptr, 0);
|
||||||
if (!addr || endptr == argv[1] || *endptr != '\0')
|
if (!addr || endptr == argv[1] || *endptr != '\0')
|
||||||
{
|
{
|
||||||
printf(g_fmtarginvalid, argv[0]);
|
nsh_output(handle, g_fmtarginvalid, argv[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Calling %p\n", (exec_t)addr);
|
nsh_output(handle, "Calling %p\n", (exec_t)addr);
|
||||||
((exec_t)addr)();
|
((exec_t)addr)();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,8 +148,8 @@ void cmd_exec(int argc, char **argv)
|
|||||||
* Name: cmd_ps
|
* Name: cmd_ps
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void cmd_ps(int argc, char **argv)
|
void cmd_ps(FAR void *handle, int argc, char **argv)
|
||||||
{
|
{
|
||||||
printf("PID PRI SCHD TYPE NP STATE NAME\n");
|
nsh_output(handle, "PID PRI SCHD TYPE NP STATE NAME\n");
|
||||||
sched_foreach(ps_task, NULL);
|
sched_foreach(ps_task, handle);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,129 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* examples/nsh/nsh_serial.h
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "nsh.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define CONFIG_NSH_LINE_SIZE 80
|
||||||
|
#undef CONFIG_FULL_PATH
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct cmdmap_s
|
||||||
|
{
|
||||||
|
const char *cmd; /* Name of the command */
|
||||||
|
cmd_t handler; /* Function that handles the command */
|
||||||
|
ubyte minargs; /* Minimum number of arguments (including command) */
|
||||||
|
ubyte maxargs; /* Maximum number of arguments (including command) */
|
||||||
|
const char *usage; /* Usage instructions for 'help' command */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static char line[CONFIG_NSH_LINE_SIZE];
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nsh_main
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int nsh_serialmain(void)
|
||||||
|
{
|
||||||
|
printf("NuttShell (NSH)\n");
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
/* Display the prompt string */
|
||||||
|
|
||||||
|
fputs(g_nshprompt, stdout);
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
/* Get the next line of input */
|
||||||
|
|
||||||
|
fgets(line, CONFIG_NSH_LINE_SIZE, stdin);
|
||||||
|
|
||||||
|
/* Parse process the command */
|
||||||
|
|
||||||
|
(void)nsh_parse(NULL, line);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: cmd_exit
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Exit the shell task
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void cmd_exit(void *handle, int argc, char **argv)
|
||||||
|
{
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -134,9 +134,11 @@ int closedir(FAR DIR *dirp)
|
|||||||
free(idir);
|
free(idir);
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||||
errout_with_inode:
|
errout_with_inode:
|
||||||
inode_release(inode);
|
inode_release(inode);
|
||||||
free(idir);
|
free(idir);
|
||||||
|
#endif
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
*get_errno_ptr() = ret;
|
*get_errno_ptr() = ret;
|
||||||
|
|||||||
@@ -219,10 +219,14 @@ FAR DIR *opendir(const char *path)
|
|||||||
|
|
||||||
/* Nasty goto's make error handling simpler */
|
/* Nasty goto's make error handling simpler */
|
||||||
|
|
||||||
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
||||||
errout_with_inode:
|
errout_with_inode:
|
||||||
inode_release(inode);
|
inode_release(inode);
|
||||||
|
#endif
|
||||||
|
|
||||||
errout_with_direntry:
|
errout_with_direntry:
|
||||||
free(dir);
|
free(dir);
|
||||||
|
|
||||||
errout_with_semaphore:
|
errout_with_semaphore:
|
||||||
inode_semgive();
|
inode_semgive();
|
||||||
*get_errno_ptr() = ret;
|
*get_errno_ptr() = ret;
|
||||||
|
|||||||
+7
-7
@@ -62,14 +62,14 @@
|
|||||||
|
|
||||||
struct accept_s
|
struct accept_s
|
||||||
{
|
{
|
||||||
sem_t acpt_sem; /* Wait for interrupt event */
|
sem_t acpt_sem; /* Wait for interrupt event */
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
FAR const struct sockaddr_in6 *acpt_addr; /* Return connection adress */
|
FAR struct sockaddr_in6 *acpt_addr; /* Return connection adress */
|
||||||
#else
|
#else
|
||||||
FAR const struct sockaddr_in *acpt_addr; /* Return connection adress */
|
FAR struct sockaddr_in *acpt_addr; /* Return connection adress */
|
||||||
#endif
|
#endif
|
||||||
FAR struct uip_conn *acpt_newconn; /* The accepted connection */
|
FAR struct uip_conn *acpt_newconn; /* The accepted connection */
|
||||||
int acpt_result; /* The result of the wait */
|
int acpt_result; /* The result of the wait */
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -242,9 +242,9 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
|
|||||||
FAR struct uip_conn *conn;
|
FAR struct uip_conn *conn;
|
||||||
struct accept_s state;
|
struct accept_s state;
|
||||||
#ifdef CONFIG_NET_IPv6
|
#ifdef CONFIG_NET_IPv6
|
||||||
FAR const struct sockaddr_in6 *inaddr = (const struct sockaddr_in6 *)addr;
|
FAR struct sockaddr_in6 *inaddr = (const struct sockaddr_in6 *)addr;
|
||||||
#else
|
#else
|
||||||
FAR const struct sockaddr_in *inaddr = (const struct sockaddr_in *)addr;
|
FAR struct sockaddr_in *inaddr = (const struct sockaddr_in *)addr;
|
||||||
#endif
|
#endif
|
||||||
irqstate_t save;
|
irqstate_t save;
|
||||||
int newfd;
|
int newfd;
|
||||||
|
|||||||
+1
-1
@@ -831,7 +831,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|||||||
struct uip_conn *conn;
|
struct uip_conn *conn;
|
||||||
struct recvfrom_s state;
|
struct recvfrom_s state;
|
||||||
irqstate_t save;
|
irqstate_t save;
|
||||||
int ret;
|
int ret = OK;
|
||||||
|
|
||||||
/* Verify that the SOCK_STREAM has been connected */
|
/* Verify that the SOCK_STREAM has been connected */
|
||||||
|
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ void shell_output(void *handle, const char *fmt, ...)
|
|||||||
telnetd_dumpbuffer("Shell output", pstate->tn_iobuffer, len+2);
|
telnetd_dumpbuffer("Shell output", pstate->tn_iobuffer, len+2);
|
||||||
if (send(pstate->tn_sockfd, pstate->tn_iobuffer, len+2, 0) < 0)
|
if (send(pstate->tn_sockfd, pstate->tn_iobuffer, len+2, 0) < 0)
|
||||||
{
|
{
|
||||||
dbg("[%d] Failed to send prompt\n", pstate->tn_sockfd);
|
dbg("[%d] Failed to send response\n", pstate->tn_sockfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user