diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-03-18 19:46:25 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-03-18 19:46:25 +0000 |
commit | 058e81edfdee203f2143b3f0910aa957a7f8da48 (patch) | |
tree | 4842491d56251e5499f2838ee303bd752d518e12 | |
parent | 529a1cf7339541eaee3d189a3b97d9c544ba7810 (diff) | |
download | nuttx-058e81edfdee203f2143b3f0910aa957a7f8da48.tar.gz nuttx-058e81edfdee203f2143b3f0910aa957a7f8da48.tar.bz2 nuttx-058e81edfdee203f2143b3f0910aa957a7f8da48.zip |
Move NSH to apps/ as library
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3393 42af7a65-404d-4744-a932-0658087f49c3
46 files changed, 2223 insertions, 1293 deletions
diff --git a/apps/nshlib/Makefile b/apps/nshlib/Makefile new file mode 100644 index 000000000..e4f5bf7b5 --- /dev/null +++ b/apps/nshlib/Makefile @@ -0,0 +1,121 @@ +############################################################################ +# apps/nshlib/Makefile +# +# Copyright (C) 2011 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 NuttX 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. +# +############################################################################ + +# TODO, this makefile should run make under the app dirs, instead of +# sourcing the Make.defs! + +-include $(TOPDIR)/Make.defs +include ../Make.defs + +ifeq ($(WINTOOL),y) +INCDIROPT = -w +endif + +# NSH Library + +ASRCS = +CSRCS = nsh_main.c nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_mmcmds.c \ + nsh_envcmds.c nsh_dbgcmds.c + +ifeq ($(CONFIG_EXAMPLES_NSH_BUILTIN_APPS),y) +CSRCS += nsh_apps.c +endif + +ifeq ($(CONFIG_EXAMPLES_NSH_ROMFSETC),y) +CSRCS += nsh_romfsetc.c +endif + +ifeq ($(CONFIG_NET),y) +CSRCS += nsh_netinit.c nsh_netcmds.c +endif + +ifeq ($(CONFIG_EXAMPLES_NSH_CONSOLE),y) +CSRCS += nsh_serial.c +endif + +ifeq ($(CONFIG_EXAMPLES_NSH_TELNET),y) +CSRCS += nsh_telnetd.c +endif + +ifneq ($(CONFIG_EXAMPLES_NSH_DISABLESCRIPT),y) +CSRCS += nsh_test.c +endif + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +BIN = ../libapps$(LIBEXT) + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +$(BIN): $(OBJS) + @( for obj in $(OBJS) ; do \ + $(call ARCHIVE, $@, $${obj}); \ + done ; ) + @touch .built + +.built: $(BIN) + +.depend: Makefile $(SRCS) + @$(MKDEP) $(ROOTDEPPATH) \ + $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep + @touch $@ + +# Register application +depend: .depend + +clean: + @rm -f $(BIN) *.o *~ .*.swp .built + $(call CLEAN) + +distclean: clean + @rm -f Make.dep .depend + +-include Make.dep diff --git a/nuttx/examples/nsh/README.txt b/apps/nshlib/README.txt index ab44cbaeb..10bb202df 100644 --- a/nuttx/examples/nsh/README.txt +++ b/apps/nshlib/README.txt @@ -1,8 +1,8 @@ -examples/nsh -^^^^^^^^^^^^ +apps/nshlib +^^^^^^^^^^^ - This directory contains the NuttShell (NSH). This is a simple - shell application for NuttX. + This directory contains the NuttShell (NSH) library. This library can be + linked with other logic to provide a simple shell application for NuttX. - Console/NSH Front End - Command Overview @@ -159,7 +159,7 @@ Modifying the ROMFS Image ------------------------- The contents of the /etc directory are retained in the file -examples/nsh/nsh_romfsimg.h (OR, if CONFIG_EXAMPLES_NSH_ARCHROMFS +apps/nshlib/nsh_romfsimg.h (OR, if CONFIG_EXAMPLES_NSH_ARCHROMFS is defined, include/arch/board/rcs.template). In order to modify the start-up behavior, there are three things to study: @@ -178,17 +178,17 @@ the start-up behavior, there are three things to study: - The configuration settings of the installed NuttX configuration. - The genromfs tool (available from http://romfs.sourceforge.net). - - The file examples/nsh/rcS.template (OR, if + - The file apps/nshlib/rcS.template (OR, if CONFIG_EXAMPLES_NSH_ARCHROMFS is defined, include/arch/board/rcs.template) 3. rcS.template. - The file examples/nsh/rcS.template contains the general form + The file apps/nshlib/rcS.template contains the general form of the rcS file; configured values are plugged into this template file to produce the final rcS file. NOTE: - examples/nsh/rcS.template generates the standard, default + apps/nshlib/rcS.template generates the standard, default nsh_romfsimg.h file. If CONFIG_EXAMPLES_NSH_ARCHROMFS is defined in the NuttX configuration file, then a custom, board-specific nsh_romfsimg.h file residing in configs/<board>/include will be diff --git a/nuttx/examples/nsh/nsh.h b/apps/nshlib/nsh.h index ea05da31b..c92bb6e80 100644 --- a/nuttx/examples/nsh/nsh.h +++ b/apps/nshlib/nsh.h @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh.h + * apps/nshlib/nsh.h * * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_apps.c b/apps/nshlib/nsh_apps.c index 58f44414a..0c786dc12 100644 --- a/nuttx/examples/nsh/nsh_apps.c +++ b/apps/nshlib/nsh_apps.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh_apps.c + * apps/nshlib/nsh_apps.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. * Copyright (C) 2011 Uros Platise. All rights reserved. diff --git a/nuttx/examples/nsh/nsh_dbgcmds.c b/apps/nshlib/nsh_dbgcmds.c index ef026c68a..001f5dd49 100644 --- a/nuttx/examples/nsh/nsh_dbgcmds.c +++ b/apps/nshlib/nsh_dbgcmds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/dbg_dbgcmds.c + * apps/nshlib/dbg_dbgcmds.c * * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_ddcmd.c b/apps/nshlib/nsh_ddcmd.c index d0457cbaa..c33a80ec0 100644 --- a/nuttx/examples/nsh/nsh_ddcmd.c +++ b/apps/nshlib/nsh_ddcmd.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh_ddcmd.c + * apps/nshlib/nsh_ddcmd.c * * Copyright (C) 2008-2009 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_envcmds.c b/apps/nshlib/nsh_envcmds.c index 1c701e46d..edb2693c4 100644 --- a/nuttx/examples/nsh/nsh_envcmds.c +++ b/apps/nshlib/nsh_envcmds.c @@ -1,7 +1,7 @@ /**************************************************************************** - * nsh_envcmds.c + * apps/nshlib/nsh_envcmds.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/examples/nsh/nsh_fscmds.c b/apps/nshlib/nsh_fscmds.c index 40f894ec8..4a471e65f 100644 --- a/nuttx/examples/nsh/nsh_fscmds.c +++ b/apps/nshlib/nsh_fscmds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh_fscmds.c + * apps/nshlib/nsh_fscmds.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/apps/nshlib/nsh_main.c b/apps/nshlib/nsh_main.c new file mode 100644 index 000000000..3437707a3 --- /dev/null +++ b/apps/nshlib/nsh_main.c @@ -0,0 +1,1299 @@ +/**************************************************************************** + * apps/nshlib/nsh_main.c + * + * Copyright (C) 2007-2011 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 NuttX 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/stat.h> + +#include <stdint.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <sched.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG +# include <pthread.h> +#endif + +#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS +# include <apps/apps.h> +#endif +#include <apps/nsh.h> + +#include "nsh.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* Argument list size + * + * argv[0]: The command name. + * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS) + * argv[argc-3]: Possibly '>' or '>>' + * argv[argc-2]: Possibly <file> + * argv[argc-1]: Possibly '&' (if pthreads are enabled) + * argv[argc]: NULL terminating pointer + * + * Maximum size is NSH_MAX_ARGUMENTS+5 + */ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG +# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+5) +#else +# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+4) +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct cmdmap_s +{ + const char *cmd; /* Name of the command */ + cmd_t handler; /* Function that handles the command */ + uint8_t minargs; /* Minimum number of arguments (including command) */ + uint8_t maxargs; /* Maximum number of arguments (including command) */ + const char *usage; /* Usage instructions for 'help' command */ +}; + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG +struct cmdarg_s +{ + FAR struct nsh_vtbl_s *vtbl; /* For front-end interaction */ + int fd; /* FD for output redirection */ + int argc; /* Number of arguments in argv */ + FAR char *argv[MAX_ARGV_ENTRIES]; /* Argument list */ +}; +#endif + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_HELP + static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_EXIT + static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); +#endif +static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const char g_delim[] = " \t\n"; +static const char g_redirect1[] = ">"; +static const char g_redirect2[] = ">>"; +static const char g_exitstatus[] = "$?"; +static const char g_success[] = "0"; +static const char g_failure[] = "1"; + +static const struct cmdmap_s g_cmdmap[] = +{ +#if !defined(CONFIG_EXAMPLES_NSH_DISABLESCRIPT) && !defined(CONFIG_EXAMPLES_NSH_DISABLE_TEST) + { "[", cmd_lbracket, 4, NSH_MAX_ARGUMENTS, "<expression> ]" }, +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_CAT + { "cat", cmd_cat, 2, NSH_MAX_ARGUMENTS, "<path> [<path> [<path> ...]]" }, +# endif +#ifndef CONFIG_DISABLE_ENVIRON +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_CD + { "cd", cmd_cd, 1, 2, "[<dir-path>|-|~|..]" }, +# endif +#endif +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_CP + { "cp", cmd_cp, 3, 3, "<source-path> <dest-path>" }, +# endif +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LS + { "dd", cmd_dd, 3, 6, "if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]" }, +# endif +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_ECHO +# ifndef CONFIG_DISABLE_ENVIRON + { "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string|$name> [<string|$name>...]]" }, +# else + { "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string> [<string>...]]" }, +# endif +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_EXEC + { "exec", cmd_exec, 2, 3, "<hex-address>" }, +#endif +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_EXIT + { "exit", cmd_exit, 1, 1, NULL }, +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_FREE + { "free", cmd_free, 1, 1, NULL }, +#endif + +#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_GET + { "get", cmd_get, 4, 7, "[-b|-n] [-f <local-path>] -h <ip-address> <remote-path>" }, +# endif +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_HELP + { "help", cmd_help, 1, 1, NULL }, +#endif + +#ifdef CONFIG_NET +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_IFCONFIG + { "ifconfig", cmd_ifconfig, 1, 1, NULL }, +# endif +#endif + +#ifndef CONFIG_DISABLE_SIGNALS +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SLEEP + { "kill", cmd_kill, 3, 3, "-<signal> <pid>" }, +# endif +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP + { "losetup", cmd_losetup, 3, 6, "[-d <dev-path>] | [[-o <offset>] [-r] <dev-path> <file-path>]" }, +# endif +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LS + { "ls", cmd_ls, 1, 5, "[-lRs] <dir-path>" }, +# endif +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MB + { "mb", cmd_mb, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKDIR + { "mkdir", cmd_mkdir, 2, 2, "<path>" }, +# endif +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKFATFS + { "mkfatfs", cmd_mkfatfs, 2, 2, "<path>" }, +# endif +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKFIFO + { "mkfifo", cmd_mkfifo, 2, 2, "<path>" }, +# endif +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKRD + { "mkrd", cmd_mkrd, 2, 6, "[-m <minor>] [-s <sector-size>] <nsectors>" }, +# endif +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MH + { "mh", cmd_mh, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MOUNT + { "mount", cmd_mount, 4, 5, "-t <fstype> <block-device> <dir-path>" }, +# endif +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MW + { "mw", cmd_mw, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, +#endif + +#if defined(CONFIG_NET) && defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ + !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_PING + { "ping", cmd_ping, 2, 6, "[-c <count>] [-i <interval>] <ip-address>" }, +# endif +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_PS + { "ps", cmd_ps, 1, 1, NULL }, +#endif + +#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_PUT + { "put", cmd_put, 4, 7, "[-b|-n] [-f <remote-path>] -h <ip-address> <local-path>" }, +# endif +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_PWD + { "pwd", cmd_pwd, 1, 1, NULL }, +# endif +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_RM + { "rm", cmd_rm, 2, 2, "<file-path>" }, +# endif +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_RMDIR + { "rmdir", cmd_rmdir, 2, 2, "<dir-path>" }, +# endif +#endif + +#ifndef CONFIG_DISABLE_ENVIRON +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SET + { "set", cmd_set, 3, 3, "<name> <value>" }, +# endif +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_EXAMPLES_NSH_DISABLESCRIPT) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SH + { "sh", cmd_sh, 2, 2, "<script-path>" }, +# endif +#endif + +#ifndef CONFIG_DISABLE_SIGNALS +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SLEEP + { "sleep", cmd_sleep, 2, 2, "<sec>" }, +# endif +#endif + +#if !defined(CONFIG_EXAMPLES_NSH_DISABLESCRIPT) && !defined(CONFIG_EXAMPLES_NSH_DISABLE_TEST) + { "test", cmd_test, 3, NSH_MAX_ARGUMENTS, "<expression>" }, +#endif + +#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_UMOUNT + { "umount", cmd_umount, 2, 2, "<dir-path>" }, +# endif +#endif + +#ifndef CONFIG_DISABLE_ENVIRON +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_UNSET + { "unset", cmd_unset, 2, 2, "<name>" }, +# endif +#endif + +#ifndef CONFIG_DISABLE_SIGNALS +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_USLEEP + { "usleep", cmd_usleep, 2, 2, "<usec>" }, +# endif +#endif + +#if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 +# ifndef CONFIG_EXAMPLES_NSH_DISABLE_GET + { "wget", cmd_wget, 2, 4, "[-o <local-path>] <url>" }, +# endif +#endif + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_XD + { "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" }, +#endif + { NULL, NULL, 1, 1, NULL } +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +const char g_nshgreeting[] = "\nNuttShell (NSH)\n"; +const char g_nshprompt[] = "nsh> "; +const char g_nshsyntax[] = "nsh: %s: syntax error\n"; +const char g_fmtargrequired[] = "nsh: %s: missing required argument(s)\n"; +const char g_fmtarginvalid[] = "nsh: %s: argument invalid\n"; +const char g_fmtargrange[] = "nsh: %s: value out of range\n"; +const char g_fmtcmdnotfound[] = "nsh: %s: command not found\n"; +const char g_fmtnosuch[] = "nsh: %s: no such %s: %s\n"; +const char g_fmttoomanyargs[] = "nsh: %s: too many arguments\n"; +const char g_fmtdeepnesting[] = "nsh: %s: nesting too deep\n"; +const char g_fmtcontext[] = "nsh: %s: not valid in this context\n"; +#ifdef CONFIG_EXAMPLES_NSH_STRERROR +const char g_fmtcmdfailed[] = "nsh: %s: %s failed: %s\n"; +#else +const char g_fmtcmdfailed[] = "nsh: %s: %s failed: %d\n"; +#endif +const char g_fmtcmdoutofmemory[] = "nsh: %s: out of memory\n"; +const char g_fmtinternalerror[] = "nsh: %s: Internal error\n"; +#ifndef CONFIG_DISABLE_SIGNALS +const char g_fmtsignalrecvd[] = "nsh: %s: Interrupted by signal\n"; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: cmd_help + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_HELP +static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + const struct cmdmap_s *ptr; + + nsh_output(vtbl, "NSH command forms:\n"); +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG + nsh_output(vtbl, " [nice [-d <niceness>>]] <cmd> [> <file>|>> <file>] [&]\n"); +#else + nsh_output(vtbl, " <cmd> [> <file>|>> <file>]\n"); +#endif +#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT + nsh_output(vtbl, "OR\n"); + nsh_output(vtbl, " if <cmd>\n"); + nsh_output(vtbl, " then\n"); + nsh_output(vtbl, " [sequence of <cmd>]\n"); + nsh_output(vtbl, " else\n"); + nsh_output(vtbl, " [sequence of <cmd>]\n"); + nsh_output(vtbl, " fi\n"); +#endif + nsh_output(vtbl, "Where <cmd> is one of:\n"); + for (ptr = g_cmdmap; ptr->cmd; ptr++) + { + if (ptr->usage) + { + nsh_output(vtbl, " %s %s\n", ptr->cmd, ptr->usage); + } + else + { + nsh_output(vtbl, " %s\n", ptr->cmd); + } + } + return OK; +} +#endif + +/**************************************************************************** + * Name: cmd_unrecognized + ****************************************************************************/ + +static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_output(vtbl, g_fmtcmdnotfound, argv[0]); + return ERROR; +} + +/**************************************************************************** + * Name: cmd_exit + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLE_EXIT +static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) +{ + nsh_exit(vtbl); + return OK; +} +#endif + +/**************************************************************************** + * Name: nsh_execute + ****************************************************************************/ + +static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]) +{ + const struct cmdmap_s *cmdmap; + const char *cmd; + cmd_t handler = cmd_unrecognized; + int ret; + + /* The form of argv is: + * + * argv[0]: The command name. This is argv[0] when the arguments + * are, finally, received by the command vtblr + * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS) + * argv[argc]: NULL terminating pointer + */ + + cmd = argv[0]; + + /* 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 + * not have to be performed in each command. + */ + + if (argc < cmdmap->minargs) + { + /* Fewer than the minimum number were provided */ + + nsh_output(vtbl, g_fmtargrequired, cmd); + return ERROR; + } + else if (argc > cmdmap->maxargs) + { + /* More than the maximum number were provided */ + + nsh_output(vtbl, g_fmttoomanyargs, cmd); + return ERROR; + } + else + { + /* A valid number of arguments were provided (this does + * not mean they are right). + */ + + handler = cmdmap->handler; + break; + } + } + } + + /* If the command was not found, then try to execute the command from + * a list of pre-built applications. + */ + +#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS + if (handler == cmd_unrecognized && nsh_execapp(vtbl, cmd, argv) == OK) + { + /* The pre-built application was successfully started -- return OK. + * If not, then fall through to execute the cmd_nrecognized handler. + */ + + return OK; + } +#endif + + ret = handler(vtbl, argc, argv); + return ret; +} + +/**************************************************************************** + * Name: nsh_releaseargs + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG +static void nsh_releaseargs(struct cmdarg_s *arg) +{ + FAR struct nsh_vtbl_s *vtbl = arg->vtbl; + int i; + + /* If the output was redirected, then file descriptor should + * be closed. The created task has its one, independent copy of + * the file descriptor + */ + + if (vtbl->np.np_redirect) + { + (void)close(arg->fd); + } + + /* Released the cloned vtbl instance */ + + nsh_release(vtbl); + + /* Release the cloned args */ + + for (i = 0; i < arg->argc; i++) + { + free(arg->argv[i]); + } + free(arg); +} +#endif + +/**************************************************************************** + * Name: nsh_child + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG +static pthread_addr_t nsh_child(pthread_addr_t arg) +{ + struct cmdarg_s *carg = (struct cmdarg_s *)arg; + int ret; + + dbg("BG %s\n", carg->argv[0]); + + /* Execute the specified command on the child thread */ + + ret = nsh_execute(carg->vtbl, carg->argc, carg->argv); + + /* Released the cloned arguments */ + + dbg("BG %s complete\n", carg->argv[0]); + nsh_releaseargs(carg); + return (void*)ret; +} +#endif + +/**************************************************************************** + * Name: nsh_cloneargs + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG +static inline struct cmdarg_s *nsh_cloneargs(FAR struct nsh_vtbl_s *vtbl, + int fd, int argc, char *argv[]) +{ + struct cmdarg_s *ret = (struct cmdarg_s *)zalloc(sizeof(struct cmdarg_s)); + int i; + + if (ret) + { + ret->vtbl = vtbl; + ret->fd = fd; + ret->argc = argc; + + for (i = 0; i < argc; i++) + { + ret->argv[i] = strdup(argv[i]); + } + } + return ret; +} +#endif + +/**************************************************************************** + * Name: nsh_argument + ****************************************************************************/ + +char *nsh_argument(FAR struct nsh_vtbl_s *vtbl, char **saveptr) +{ + char *pbegin = *saveptr; + char *pend = NULL; + const char *term; +#ifndef CONFIG_DISABLE_ENVIRON + bool quoted = false; +#endif + + /* Find the beginning of the next token */ + + for (; + *pbegin && strchr(g_delim, *pbegin) != NULL; + pbegin++); + + /* If we are at the end of the string with nothing + * but delimiters found, then return NULL. + */ + + if (!*pbegin) + { + return NULL; + } + + /* Does the token begin with '>' -- redirection of output? */ + + if (*pbegin == '>') + { + /* Yes.. does it begin with ">>"? */ + + if (*(pbegin + 1) == '>') + { + *saveptr = pbegin + 2; + pbegin = (char*)g_redirect2; + } + else + { + *saveptr = pbegin + 1; + pbegin = (char*)g_redirect1; + } + } + + /* Does the token begin with '#' -- comment */ + + else if (*pbegin == '#') + { + /* Return NULL meaning that we are at the end of the line */ + + *saveptr = pbegin; + pbegin = NULL; + } + else + { + /* Otherwise, we are going to have to parse to find the end of + * the token. Does the token begin with '"'? + */ + + if (*pbegin == '"') + { + /* Yes.. then only another '"' can terminate the string */ + + pbegin++; + term = "\""; +#ifndef CONFIG_DISABLE_ENVIRON + quoted = true; +#endif + } + else + { + /* No, then any of the usual terminators will terminate the argument */ + + term = g_delim; + } + + /* Find the end of the string */ + + for (pend = pbegin + 1; + *pend && strchr(term, *pend) == NULL; + pend++); + + /* pend either points to the end of the string or to + * the first delimiter after the string. + */ + + if (*pend) + { + /* Turn the delimiter into a null terminator */ + + *pend++ = '\0'; + } + + /* Save the pointer where we left off */ + + *saveptr = pend; + +#ifndef CONFIG_DISABLE_ENVIRON + /* Check for references to environment variables */ + + if (pbegin[0] == '$' && !quoted) + { + /* Check for built-in variables */ + + if (strcmp(pbegin, g_exitstatus) == 0) + { + if (vtbl->np.np_fail) + { + return (char*)g_failure; + } + else + { + return (char*)g_success; + } + } + + /* Not a built-in? Return the value of the environment variable with this name */ + + else + { + char *value = getenv(pbegin+1); + if (value) + { + return value; + } + else + { + return (char*)""; + } + } + } +#endif + } + + /* Return the beginning of the token. */ + + return pbegin; +} + +/**************************************************************************** + * Name: nsh_cmdenabled + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT +static inline bool nsh_cmdenabled(FAR struct nsh_vtbl_s *vtbl) +{ + struct nsh_parser_s *np = &vtbl->np; + bool ret = !np->np_st[np->np_ndx].ns_disabled; + if (ret) + { + switch (np->np_st[np->np_ndx].ns_state) + { + case NSH_PARSER_NORMAL : + case NSH_PARSER_IF: + default: + break; + + case NSH_PARSER_THEN: + ret = !np->np_st[np->np_ndx].ns_ifcond; + break; + + case NSH_PARSER_ELSE: + ret = np->np_st[np->np_ndx].ns_ifcond; + break; + } + } + return ret; +} +#endif + +/**************************************************************************** + * Name: nsh_ifthenelse + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT +static inline int nsh_ifthenelse(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR char **saveptr) +{ + struct nsh_parser_s *np = &vtbl->np; + FAR char *cmd = *ppcmd; + bool disabled; + + if (cmd) + { + /* Check if the command is preceeded by "if" */ + + if (strcmp(cmd, "if") == 0) + { + /* Get the cmd following the if */ + + *ppcmd = nsh_argument(vtbl, saveptr); + if (!*ppcmd) + { + nsh_output(vtbl, g_fmtarginvalid, "if"); + goto errout; + } + + /* Verify that "if" is valid in this context */ + + if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_NORMAL && + np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN && + np->np_st[np->np_ndx].ns_state != NSH_PARSER_ELSE) + { + nsh_output(vtbl, g_fmtcontext, "if"); + goto errout; + } + + /* Check if we have exceeded the maximum depth of nesting */ + + if (np->np_ndx >= CONFIG_EXAMPLES_NSH_NESTDEPTH-1) + { + nsh_output(vtbl, g_fmtdeepnesting, "if"); + goto errout; + } + + /* "Push" the old state and set the new state */ + + disabled = !nsh_cmdenabled(vtbl); + np->np_ndx++; + np->np_st[np->np_ndx].ns_state = NSH_PARSER_IF; + np->np_st[np->np_ndx].ns_disabled = disabled; + np->np_st[np->np_ndx].ns_ifcond = false; + } + else if (strcmp(cmd, "then") == 0) + { + /* Get the cmd following the then -- there shouldn't be one */ + + *ppcmd = nsh_argument(vtbl, saveptr); + if (*ppcmd) + { + nsh_output(vtbl, g_fmtarginvalid, "then"); + goto errout; + } + + /* Verify that "then" is valid in this context */ + + if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_IF) + { + nsh_output(vtbl, g_fmtcontext, "then"); + goto errout; + } + np->np_st[np->np_ndx].ns_state = NSH_PARSER_THEN; + } + else if (strcmp(cmd, "else") == 0) + { + /* Get the cmd following the else -- there shouldn't be one */ + + *ppcmd = nsh_argument(vtbl, saveptr); + if (*ppcmd) + { + nsh_output(vtbl, g_fmtarginvalid, "else"); + goto errout; + } + + /* Verify that "then" is valid in this context */ + + if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN) + { + nsh_output(vtbl, g_fmtcontext, "else"); + goto errout; + } + np->np_st[np->np_ndx].ns_state = NSH_PARSER_ELSE; + } + else if (strcmp(cmd, "fi") == 0) + { + /* Get the cmd following the fi -- there should be one */ + + *ppcmd = nsh_argument(vtbl, saveptr); + if (*ppcmd) + { + nsh_output(vtbl, g_fmtarginvalid, "fi"); + goto errout; + } + + /* Verify that "fi" is valid in this context */ + + if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN && + np->np_st[np->np_ndx].ns_state != NSH_PARSER_ELSE) + { + nsh_output(vtbl, g_fmtcontext, "fi"); + goto errout; + } + + if (np->np_ndx < 1) /* Shouldn't happen */ + { + nsh_output(vtbl, g_fmtinternalerror, "if"); + goto errout; + } + + /* "Pop" the previous state */ + + np->np_ndx--; + } + else if (np->np_st[np->np_ndx].ns_state == NSH_PARSER_IF) + { + nsh_output(vtbl, g_fmtcontext, cmd); + goto errout; + } + } + return OK; + +errout: + np->np_ndx = 0; + np->np_st[0].ns_state = NSH_PARSER_NORMAL; + np->np_st[0].ns_disabled = false; + np->np_st[0].ns_ifcond = false; + return ERROR; +} +#endif + +/**************************************************************************** + * Name: nsh_saveresult + ****************************************************************************/ + +static inline int nsh_saveresult(FAR struct nsh_vtbl_s *vtbl, bool result) +{ + struct nsh_parser_s *np = &vtbl->np; + +#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT + if (np->np_st[np->np_ndx].ns_state == NSH_PARSER_IF) + { + np->np_fail = false; + np->np_st[np->np_ndx].ns_ifcond = result; + return OK; + } + else +#endif + { + np->np_fail = result; + return result ? ERROR : OK; + } +} + +/**************************************************************************** + * Name: nsh_nice + ****************************************************************************/ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG +static inline int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR char **saveptr) +{ + FAR char *cmd = *ppcmd; + + vtbl->np.np_nice = 0; + if (cmd) + { + /* Check if the command is preceded by "nice" */ + + if (strcmp(cmd, "nice") == 0) + { + /* Nicenesses range from -20 (most favorable scheduling) to 19 + * (least favorable). Default is 10. + */ + + vtbl->np.np_nice = 10; + + /* Get the cmd (or -d option of nice command) */ + + cmd = nsh_argument(vtbl, saveptr); + if (cmd && strcmp(cmd, "-d") == 0) + { + FAR char *val = nsh_argument(vtbl, saveptr); + if (val) + { + char *endptr; + vtbl->np.np_nice = (int)strtol(val, &endptr, 0); + if (vtbl->np.np_nice > 19 || vtbl->np.np_nice < -20 || + endptr == val || *endptr != '\0') + { + nsh_output(vtbl, g_fmtarginvalid, "nice"); + return ERROR; + } + cmd = nsh_argument(vtbl, saveptr); + } + } + + /* Return the real command name */ + + *ppcmd = cmd; + } + } + return OK; +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nsh_initialize + ****************************************************************************/ + +void nsh_initialize(void) +{ + /* Mount the /etc filesystem */ + + (void)nsh_romfsetc(); + + /* Perform architecture-specific initialization (if available) */ + + (void)nsh_archinitialize(); + + /* Bring up the network */ + + (void)nsh_netinit(); +} + +/**************************************************************************** + * Name: nsh_parse + ****************************************************************************/ + +int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) +{ + FAR char *argv[MAX_ARGV_ENTRIES]; + FAR char *saveptr; + FAR char *cmd; + FAR char *redirfile = NULL; + int fd = -1; + int oflags = 0; + int argc; + int ret; + + /* Initialize parser state */ + + memset(argv, 0, MAX_ARGV_ENTRIES*sizeof(FAR char *)); +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG + vtbl->np.np_bg = false; +#endif + vtbl->np.np_redirect = false; + + /* Parse out the command at the beginning of the line */ + + saveptr = cmdline; + cmd = nsh_argument(vtbl, &saveptr); + + /* Handler if-then-else-fi */ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT + if (nsh_ifthenelse(vtbl, &cmd, &saveptr) != 0) + { + goto errout; + } +#endif + + /* Handle nice */ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG + if (nsh_nice(vtbl, &cmd, &saveptr) != 0) + { + goto errout; + } +#endif + + /* Check if any command was provided -OR- if command processing is + * currently disabled. + */ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT + if (!cmd || !nsh_cmdenabled(vtbl)) +#else + if (!cmd) +#endif + { + /* An empty line is not an error and an unprocessed command cannot + * generate an error, but neither should they change the last + * command status. + */ + + return OK; + } + + /* Parse all of the arguments following the command name. The form + * of argv is: + * + * argv[0]: The command name. + * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS) + * argv[argc-3]: Possibly '>' or '>>' + * argv[argc-2]: Possibly <file> + * argv[argc-1]: Possibly '&' + * argv[argc]: NULL terminating pointer + * + * Maximum size is NSH_MAX_ARGUMENTS+5 + */ + + argv[0] = cmd; + for (argc = 1; argc < MAX_ARGV_ENTRIES-1; argc++) + { + argv[argc] = nsh_argument(vtbl, &saveptr); + if (!argv[argc]) + { + break; + } + } + argv[argc] = NULL; + + /* Check if the command should run in background */ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG + if (argc > 1 && strcmp(argv[argc-1], "&") == 0) + { + vtbl->np.np_bg = true; + argv[argc-1] = NULL; + argc--; + } +#endif + + + /* Check if the output was re-directed using > or >> */ + + if (argc > 2) + { + /* Check for redirection to a new file */ + + if (strcmp(argv[argc-2], g_redirect1) == 0) + { + vtbl->np.np_redirect = true; + oflags = O_WRONLY|O_CREAT|O_TRUNC; + redirfile = nsh_getfullpath(vtbl, argv[argc-1]); + argc -= 2; + } + + /* Check for redirection by appending to an existing file */ + + else if (strcmp(argv[argc-2], g_redirect2) == 0) + { + vtbl->np.np_redirect = true; + oflags = O_WRONLY|O_CREAT|O_APPEND; + redirfile = nsh_getfullpath(vtbl, argv[argc-1]); + argc -= 2; + } + } + + /* Redirected output? */ + + if (vtbl->np.np_redirect) + { + /* Open the redirection file. This file will eventually + * be closed by a call to either nsh_release (if the command + * is executed in the background) or by nsh_undirect if the + * command is executed in the foreground. + */ + + fd = open(redirfile, oflags, 0666); + nsh_freefullpath(redirfile); + redirfile = NULL; + + if (fd < 0) + { + nsh_output(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO); + goto errout; + } + } + + /* Check if the maximum number of arguments was exceeded */ + + if (argc > NSH_MAX_ARGUMENTS) + { + nsh_output(vtbl, g_fmttoomanyargs, cmd); + } + + /* Handle the case where the command is executed in background. + * However is app is to be started as nuttapp new process will + * be created anyway, so skip this step. */ + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG + if (vtbl->np.np_bg +#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS + && nuttapp_isavail(argv[0]) < 0 +#endif + ) + { + struct sched_param param; + struct nsh_vtbl_s *bkgvtbl; + struct cmdarg_s *args; + pthread_attr_t attr; + pthread_t thread; + + /* Get a cloned copy of the vtbl with reference count=1. + * after the command has been processed, the nsh_release() call + * at the end of nsh_child() will destroy the clone. + */ + + bkgvtbl = nsh_clone(vtbl); + if (!bkgvtbl) + { + goto errout_with_redirect; + } + + /* Create a container for the command arguments */ + + args = nsh_cloneargs(bkgvtbl, fd, argc, argv); + if (!args) + { + nsh_release(bkgvtbl); + goto errout_with_redirect; + } + + /* Handle redirection of output via a file descriptor */ + + if (vtbl->np.np_redirect) + { + (void)nsh_redirect(bkgvtbl, fd, NULL); + } + + /* Get the execution priority of this task */ + + ret = sched_getparam(0, ¶m); + if (ret != 0) + { + nsh_output(vtbl, g_fmtcmdfailed, cmd, "sched_getparm", NSH_ERRNO); + nsh_releaseargs(args); + nsh_release(bkgvtbl); + goto errout; + } + + /* Determine the priority to execute the command */ + + if (vtbl->np.np_nice != 0) + { + int priority = param.sched_priority - vtbl->np.np_nice; + if (vtbl->np.np_nice < 0) + { + int max_priority = sched_get_priority_max(SCHED_NSH); + if (priority > max_priority) + { + priority = max_priority; + } + } + else + { + int min_priority = sched_get_priority_min(SCHED_NSH); + if (priority < min_priority) + { + priority = min_priority; + } + } + param.sched_priority = priority; + } + + /* Set up the thread attributes */ + + (void)pthread_attr_init(&attr); + (void)pthread_attr_setschedpolicy(&attr, SCHED_NSH); + (void)pthread_attr_setschedparam(&attr, ¶m); + + /* Execute the command as a separate thread at the appropriate priority */ + + ret = pthread_create(&thread, &attr, nsh_child, (pthread_addr_t)args); + if (ret != 0) + { + nsh_output(vtbl, g_fmtcmdfailed, cmd, "pthread_create", NSH_ERRNO_OF(ret)); + nsh_releaseargs(args); + nsh_release(bkgvtbl); + goto errout; + } + nsh_output(vtbl, "%s [%d:%d]\n", cmd, thread, param.sched_priority); + } + else +#endif + { + uint8_t save[SAVE_SIZE]; + + /* Handle redirection of output via a file descriptor */ + + if (vtbl->np.np_redirect) + { + nsh_redirect(vtbl, fd, save); + } + + /* Then execute the command in "foreground" -- i.e., while the user waits + * for the next prompt. + */ + + ret = nsh_execute(vtbl, argc, argv); + + /* Restore the original output. Undirect will close the redirection + * file descriptor. + */ + + if (vtbl->np.np_redirect) + { + nsh_undirect(vtbl, save); + } + + if (ret < 0) + { + goto errout; + } + } + + /* Return success if the command succeeded (or at least, starting of the + * command task succeeded). + */ + + return nsh_saveresult(vtbl, false); + +#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG +errout_with_redirect: + if (vtbl->np.np_redirect) + { + close(fd); + } +#endif +errout: + return nsh_saveresult(vtbl, true); +} diff --git a/nuttx/examples/nsh/nsh_mmcmds.c b/apps/nshlib/nsh_mmcmds.c index f2e572eb3..f2e218786 100644 --- a/nuttx/examples/nsh/nsh_mmcmds.c +++ b/apps/nshlib/nsh_mmcmds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/dbg_mmcmds.c + * apps/nshlib/dbg_mmcmds.c * * Copyright (C) 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_netcmds.c b/apps/nshlib/nsh_netcmds.c index 77caeea82..44fea2e2a 100644 --- a/nuttx/examples/nsh/nsh_netcmds.c +++ b/apps/nshlib/nsh_netcmds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh_netcmds.c + * apps/nshlib/nsh_netcmds.c * * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_netinit.c b/apps/nshlib/nsh_netinit.c index 356cc268e..eb0052cc7 100644 --- a/nuttx/examples/nsh/nsh_netinit.c +++ b/apps/nshlib/nsh_netinit.c @@ -1,7 +1,7 @@ /**************************************************************************** - * examples/nsh/nsh_netinit.c + * apps/nshlib/nsh_netinit.c * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * This is influenced by similar logic from uIP: diff --git a/nuttx/examples/nsh/nsh_proccmds.c b/apps/nshlib/nsh_proccmds.c index 5c3f6db60..b49e114ae 100644 --- a/nuttx/examples/nsh/nsh_proccmds.c +++ b/apps/nshlib/nsh_proccmds.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh_proccmds.c + * apps/nshlib/nsh_proccmds.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_romfsetc.c b/apps/nshlib/nsh_romfsetc.c index 482a3618c..ec8300de4 100644 --- a/nuttx/examples/nsh/nsh_romfsetc.c +++ b/apps/nshlib/nsh_romfsetc.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh_romfsetc.c + * apps/nshlib/nsh_romfsetc.c * * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_romfsimg.h b/apps/nshlib/nsh_romfsimg.h index 49b0ad166..49b0ad166 100644 --- a/nuttx/examples/nsh/nsh_romfsimg.h +++ b/apps/nshlib/nsh_romfsimg.h diff --git a/nuttx/examples/nsh/nsh_serial.c b/apps/nshlib/nsh_serial.c index 0704cf080..54e6fff4c 100644 --- a/nuttx/examples/nsh/nsh_serial.c +++ b/apps/nshlib/nsh_serial.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh_serial.c + * apps/nshlib/nsh_serial.c * * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_telnetd.c b/apps/nshlib/nsh_telnetd.c index 9776124f6..6cf9c188b 100644 --- a/nuttx/examples/nsh/nsh_telnetd.c +++ b/apps/nshlib/nsh_telnetd.c @@ -1,5 +1,5 @@ /**************************************************************************** - * examples/nsh/nsh_telnetd.c + * apps/nshlib/nsh_telnetd.c * * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> diff --git a/nuttx/examples/nsh/nsh_test.c b/apps/nshlib/nsh_test.c index fb76b473d..594887b18 100644 --- a/nuttx/examples/nsh/nsh_test.c +++ b/apps/nshlib/nsh_test.c @@ -1,7 +1,7 @@ /**************************************************************************** - * examples/nsh/nsh_test.c + * apps/nshlib/nsh_test.c * - * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without diff --git a/nuttx/examples/nsh/rcS.template b/apps/nshlib/rcS.template index 996f37fb1..996f37fb1 100644 --- a/nuttx/examples/nsh/rcS.template +++ b/apps/nshlib/rcS.template diff --git a/nuttx/configs/avr32dev1/nsh/appconfig b/nuttx/configs/avr32dev1/nsh/appconfig new file mode 100644 index 000000000..a34eda375 --- /dev/null +++ b/nuttx/configs/avr32dev1/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# avrdev1/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/detron/nsh/appconfig b/nuttx/configs/detron/nsh/appconfig new file mode 100644 index 000000000..57fd74915 --- /dev/null +++ b/nuttx/configs/detron/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# detron/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/ea3131/nsh/appconfig b/nuttx/configs/ea3131/nsh/appconfig new file mode 100644 index 000000000..878ce1853 --- /dev/null +++ b/nuttx/configs/ea3131/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# ea3131/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/eagle100/nsh/appconfig b/nuttx/configs/eagle100/nsh/appconfig new file mode 100644 index 000000000..97028d4c3 --- /dev/null +++ b/nuttx/configs/eagle100/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# eagle100/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/ez80f910200zco/nsh/appconfig b/nuttx/configs/ez80f910200zco/nsh/appconfig new file mode 100644 index 000000000..db733c0ba --- /dev/null +++ b/nuttx/configs/ez80f910200zco/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# ez80f910200zco/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/lm3s6965-ek/nsh/appconfig b/nuttx/configs/lm3s6965-ek/nsh/appconfig new file mode 100644 index 000000000..d4f8c3ad6 --- /dev/null +++ b/nuttx/configs/lm3s6965-ek/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# lm3s6965-ek/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/lm3s8962-ek/nsh/appconfig b/nuttx/configs/lm3s8962-ek/nsh/appconfig new file mode 100644 index 000000000..4c5c6d157 --- /dev/null +++ b/nuttx/configs/lm3s8962-ek/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# lm3s8962-ek/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/mbed/nsh/appconfig b/nuttx/configs/mbed/nsh/appconfig new file mode 100644 index 000000000..3563dcc63 --- /dev/null +++ b/nuttx/configs/mbed/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# mbed/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/mcu123-lpc214x/nsh/appconfig b/nuttx/configs/mcu123-lpc214x/nsh/appconfig new file mode 100644 index 000000000..439fa9c7f --- /dev/null +++ b/nuttx/configs/mcu123-lpc214x/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# mcu123-lpc214x/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/ntosd-dm320/nsh/appconfig b/nuttx/configs/ntosd-dm320/nsh/appconfig new file mode 100644 index 000000000..f43f12058 --- /dev/null +++ b/nuttx/configs/ntosd-dm320/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# ntosd-dm320/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/nucleus2g/nsh/appconfig b/nuttx/configs/nucleus2g/nsh/appconfig new file mode 100644 index 000000000..7c6dd08f8 --- /dev/null +++ b/nuttx/configs/nucleus2g/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# nucleus2g/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/olimex-lpc1766stk/nsh/appconfig b/nuttx/configs/olimex-lpc1766stk/nsh/appconfig new file mode 100644 index 000000000..58b0c3b53 --- /dev/null +++ b/nuttx/configs/olimex-lpc1766stk/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# olimex-lpc1766stk/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/olimex-lpc2378/nsh/appconfig b/nuttx/configs/olimex-lpc2378/nsh/appconfig new file mode 100644 index 000000000..21d8d346e --- /dev/null +++ b/nuttx/configs/olimex-lpc2378/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# olimex-lpc2378/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/olimex-strp711/nsh/appconfig b/nuttx/configs/olimex-strp711/nsh/appconfig new file mode 100644 index 000000000..b8fc1d238 --- /dev/null +++ b/nuttx/configs/olimex-strp711/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# olimex-strp711/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/qemu-i486/nsh/appconfig b/nuttx/configs/qemu-i486/nsh/appconfig new file mode 100644 index 000000000..6ad247659 --- /dev/null +++ b/nuttx/configs/qemu-i486/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# qemu-i486/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/sam3u-ek/nsh/appconfig b/nuttx/configs/sam3u-ek/nsh/appconfig new file mode 100644 index 000000000..2ce871372 --- /dev/null +++ b/nuttx/configs/sam3u-ek/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# sam3u-ek/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/sim/nsh/appconfig b/nuttx/configs/sim/nsh/appconfig new file mode 100644 index 000000000..6e5816518 --- /dev/null +++ b/nuttx/configs/sim/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# sim/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/stm3210e-eval/nsh/appconfig b/nuttx/configs/stm3210e-eval/nsh/appconfig new file mode 100644 index 000000000..2b6c43302 --- /dev/null +++ b/nuttx/configs/stm3210e-eval/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# stm3210e-eval/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/us7032evb1/nsh/appconfig b/nuttx/configs/us7032evb1/nsh/appconfig new file mode 100644 index 000000000..b3d0be81a --- /dev/null +++ b/nuttx/configs/us7032evb1/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# us7032evb1/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/vsn/nsh/appconfig b/nuttx/configs/vsn/nsh/appconfig index 71883c3fa..d946c07a3 100755 --- a/nuttx/configs/vsn/nsh/appconfig +++ b/nuttx/configs/vsn/nsh/appconfig @@ -37,4 +37,6 @@ # Add the list of built-in apps needed by this configuration -CONFIGURED_APPS += hello/.built_always poweroff/.built_always jvm/.built_always +CONFIGURED_APPS += hello/.built_always poweroff/.built_always \ + sdcard/.built_always ramtron/.built_always nshlib/.built_always + diff --git a/nuttx/configs/xtrs/nsh/appconfig b/nuttx/configs/xtrs/nsh/appconfig new file mode 100644 index 000000000..7325820e9 --- /dev/null +++ b/nuttx/configs/xtrs/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# xtrs/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/configs/z80sim/nsh/appconfig b/nuttx/configs/z80sim/nsh/appconfig new file mode 100644 index 000000000..acd2aa82d --- /dev/null +++ b/nuttx/configs/z80sim/nsh/appconfig @@ -0,0 +1,36 @@ +############################################################################
+# z80sim/nsh/appconfig
+#
+# Copyright (C) 2011 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 NuttX 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.
+#
+############################################################################
+
+CONFIGURED_APPS += nshlib/.built_always
\ No newline at end of file diff --git a/nuttx/examples/README.txt b/nuttx/examples/README.txt index 534530d52..83b0c5667 100644 --- a/nuttx/examples/README.txt +++ b/nuttx/examples/README.txt @@ -132,10 +132,10 @@ examples/netttest examples/nsh ^^^^^^^^^^^^ - This directory contains the NuttShell (NSH). This is a simple - shell application. With some additional development, NSH will - someday be a great NuttX application debugger. NSH is described - in its own README located at examples/nsh/README.txt + This directory provides an example of how to configure and use + the NuttShell (NSH) application. NSH is a simple shell + application. NSH is described in its own README located at + apps/nshlib/README.txt examples/nx ^^^^^^^^^^^ diff --git a/nuttx/examples/nsh/Makefile b/nuttx/examples/nsh/Makefile index 99e6f6b03..3ef915cb7 100644 --- a/nuttx/examples/nsh/Makefile +++ b/nuttx/examples/nsh/Makefile @@ -1,7 +1,7 @@ ############################################################################ # examples/nsh/Makefile # -# Copyright (C) 2007-2008, 2010 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2008, 2010-2011 Gregory Nutt. All rights reserved. # Author: Gregory Nutt <spudmonkey@racsa.co.cr> # # Redistribution and use in source and binary forms, with or without @@ -37,32 +37,7 @@ -include $(TOPDIR)/Make.defs ASRCS = -CSRCS = nsh_main.c nsh_fscmds.c nsh_ddcmd.c nsh_proccmds.c nsh_mmcmds.c \ - nsh_envcmds.c nsh_dbgcmds.c - -ifeq ($(CONFIG_EXAMPLES_NSH_BUILTIN_APPS),y) -CSRCS += nsh_apps.c -endif - -ifeq ($(CONFIG_EXAMPLES_NSH_ROMFSETC),y) -CSRCS += nsh_romfsetc.c -endif - -ifeq ($(CONFIG_NET),y) -CSRCS += nsh_netinit.c nsh_netcmds.c -endif - -ifeq ($(CONFIG_EXAMPLES_NSH_CONSOLE),y) -CSRCS += nsh_serial.c -endif - -ifeq ($(CONFIG_EXAMPLES_NSH_TELNET),y) -CSRCS += nsh_telnetd.c -endif - -ifneq ($(CONFIG_EXAMPLES_NSH_DISABLESCRIPT),y) -CSRCS += nsh_test.c -endif +CSRCS = nsh_main.c AOBJS = $(ASRCS:.S=$(OBJEXT)) COBJS = $(CSRCS:.c=$(OBJEXT)) diff --git a/nuttx/examples/nsh/nsh_main.c b/nuttx/examples/nsh/nsh_main.c index 2544baf5b..fc6c9b0f9 100644 --- a/nuttx/examples/nsh/nsh_main.c +++ b/nuttx/examples/nsh/nsh_main.c @@ -40,948 +40,41 @@ #include <nuttx/config.h> #include <sys/stat.h> - #include <stdint.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> #include <sched.h> -#include <fcntl.h> -#include <errno.h> -#include <debug.h> - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG -# include <pthread.h> -#endif -#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS -# include <apps/apps.h> -#endif #include <apps/nsh.h> -#include "nsh.h" - /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ -/* Argument list size - * - * argv[0]: The command name. - * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS) - * argv[argc-3]: Possibly '>' or '>>' - * argv[argc-2]: Possibly <file> - * argv[argc-1]: Possibly '&' (if pthreads are enabled) - * argv[argc]: NULL terminating pointer - * - * Maximum size is NSH_MAX_ARGUMENTS+5 - */ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG -# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+5) -#else -# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+4) -#endif - -#if CONFIG_RR_INTERVAL > 0 -# define SCHED_NSH SCHED_RR -#else -# define SCHED_NSH SCHED_FIFO +#ifndef CONFIG_BUILTIN_APPS +# warning "This example requires CONFIG_BUILTIN_APPS..." +# warning " You must have an appconfig file in your config directory to use this example" #endif /**************************************************************************** * Private Types ****************************************************************************/ -struct cmdmap_s -{ - const char *cmd; /* Name of the command */ - cmd_t handler; /* Function that handles the command */ - uint8_t minargs; /* Minimum number of arguments (including command) */ - uint8_t maxargs; /* Maximum number of arguments (including command) */ - const char *usage; /* Usage instructions for 'help' command */ -}; - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG -struct cmdarg_s -{ - FAR struct nsh_vtbl_s *vtbl; /* For front-end interaction */ - int fd; /* FD for output redirection */ - int argc; /* Number of arguments in argv */ - FAR char *argv[MAX_ARGV_ENTRIES]; /* Argument list */ -}; -#endif - /**************************************************************************** * Private Function Prototypes ****************************************************************************/ -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_HELP - static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_EXIT - static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); -#endif -static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv); - /**************************************************************************** * Private Data ****************************************************************************/ -static const char g_delim[] = " \t\n"; -static const char g_redirect1[] = ">"; -static const char g_redirect2[] = ">>"; -static const char g_exitstatus[] = "$?"; -static const char g_success[] = "0"; -static const char g_failure[] = "1"; - -static const struct cmdmap_s g_cmdmap[] = -{ -#if !defined(CONFIG_EXAMPLES_NSH_DISABLESCRIPT) && !defined(CONFIG_EXAMPLES_NSH_DISABLE_TEST) - { "[", cmd_lbracket, 4, NSH_MAX_ARGUMENTS, "<expression> ]" }, -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_CAT - { "cat", cmd_cat, 2, NSH_MAX_ARGUMENTS, "<path> [<path> [<path> ...]]" }, -# endif -#ifndef CONFIG_DISABLE_ENVIRON -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_CD - { "cd", cmd_cd, 1, 2, "[<dir-path>|-|~|..]" }, -# endif -#endif -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_CP - { "cp", cmd_cp, 3, 3, "<source-path> <dest-path>" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LS - { "dd", cmd_dd, 3, 6, "if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] [skip=<sectors>]" }, -# endif -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_ECHO -# ifndef CONFIG_DISABLE_ENVIRON - { "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string|$name> [<string|$name>...]]" }, -# else - { "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string> [<string>...]]" }, -# endif -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_EXEC - { "exec", cmd_exec, 2, 3, "<hex-address>" }, -#endif -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_EXIT - { "exit", cmd_exit, 1, 1, NULL }, -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_FREE - { "free", cmd_free, 1, 1, NULL }, -#endif - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_GET - { "get", cmd_get, 4, 7, "[-b|-n] [-f <local-path>] -h <ip-address> <remote-path>" }, -# endif -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_HELP - { "help", cmd_help, 1, 1, NULL }, -#endif - -#ifdef CONFIG_NET -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_IFCONFIG - { "ifconfig", cmd_ifconfig, 1, 1, NULL }, -# endif -#endif - -#ifndef CONFIG_DISABLE_SIGNALS -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SLEEP - { "kill", cmd_kill, 3, 3, "-<signal> <pid>" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_MOUNTPOINT) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LOSETUP - { "losetup", cmd_losetup, 3, 6, "[-d <dev-path>] | [[-o <offset>] [-r] <dev-path> <file-path>]" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_LS - { "ls", cmd_ls, 1, 5, "[-lRs] <dir-path>" }, -# endif -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MB - { "mb", cmd_mb, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKDIR - { "mkdir", cmd_mkdir, 2, 2, "<path>" }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_FAT) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKFATFS - { "mkfatfs", cmd_mkfatfs, 2, 2, "<path>" }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKFIFO - { "mkfifo", cmd_mkfifo, 2, 2, "<path>" }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MKRD - { "mkrd", cmd_mkrd, 2, 6, "[-m <minor>] [-s <sector-size>] <nsectors>" }, -# endif -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MH - { "mh", cmd_mh, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_MOUNT - { "mount", cmd_mount, 4, 5, "-t <fstype> <block-device> <dir-path>" }, -# endif -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_MW - { "mw", cmd_mw, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" }, -#endif - -#if defined(CONFIG_NET) && defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) && \ - !defined(CONFIG_DISABLE_CLOCK) && !defined(CONFIG_DISABLE_SIGNALS) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_PING - { "ping", cmd_ping, 2, 6, "[-c <count>] [-i <interval>] <ip-address>" }, -# endif -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_PS - { "ps", cmd_ps, 1, 1, NULL }, -#endif - -#if defined(CONFIG_NET_UDP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_PUT - { "put", cmd_put, 4, 7, "[-b|-n] [-f <remote-path>] -h <ip-address> <local-path>" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && !defined(CONFIG_DISABLE_ENVIRON) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_PWD - { "pwd", cmd_pwd, 1, 1, NULL }, -# endif -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_RM - { "rm", cmd_rm, 2, 2, "<file-path>" }, -# endif -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_RMDIR - { "rmdir", cmd_rmdir, 2, 2, "<dir-path>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_ENVIRON -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SET - { "set", cmd_set, 3, 3, "<name> <value>" }, -# endif -#endif - -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 && !defined(CONFIG_EXAMPLES_NSH_DISABLESCRIPT) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SH - { "sh", cmd_sh, 2, 2, "<script-path>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_SIGNALS -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_SLEEP - { "sleep", cmd_sleep, 2, 2, "<sec>" }, -# endif -#endif - -#if !defined(CONFIG_EXAMPLES_NSH_DISABLESCRIPT) && !defined(CONFIG_EXAMPLES_NSH_DISABLE_TEST) - { "test", cmd_test, 3, NSH_MAX_ARGUMENTS, "<expression>" }, -#endif - -#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_UMOUNT - { "umount", cmd_umount, 2, 2, "<dir-path>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_ENVIRON -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_UNSET - { "unset", cmd_unset, 2, 2, "<name>" }, -# endif -#endif - -#ifndef CONFIG_DISABLE_SIGNALS -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_USLEEP - { "usleep", cmd_usleep, 2, 2, "<usec>" }, -# endif -#endif - -#if defined(CONFIG_NET_TCP) && CONFIG_NFILE_DESCRIPTORS > 0 -# ifndef CONFIG_EXAMPLES_NSH_DISABLE_GET - { "wget", cmd_wget, 2, 4, "[-o <local-path>] <url>" }, -# endif -#endif - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_XD - { "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" }, -#endif - { NULL, NULL, 1, 1, NULL } -}; - /**************************************************************************** * Public Data ****************************************************************************/ -const char g_nshgreeting[] = "\nNuttShell (NSH)\n"; -const char g_nshprompt[] = "nsh> "; -const char g_nshsyntax[] = "nsh: %s: syntax error\n"; -const char g_fmtargrequired[] = "nsh: %s: missing required argument(s)\n"; -const char g_fmtarginvalid[] = "nsh: %s: argument invalid\n"; -const char g_fmtargrange[] = "nsh: %s: value out of range\n"; -const char g_fmtcmdnotfound[] = "nsh: %s: command not found\n"; -const char g_fmtnosuch[] = "nsh: %s: no such %s: %s\n"; -const char g_fmttoomanyargs[] = "nsh: %s: too many arguments\n"; -const char g_fmtdeepnesting[] = "nsh: %s: nesting too deep\n"; -const char g_fmtcontext[] = "nsh: %s: not valid in this context\n"; -#ifdef CONFIG_EXAMPLES_NSH_STRERROR -const char g_fmtcmdfailed[] = "nsh: %s: %s failed: %s\n"; -#else -const char g_fmtcmdfailed[] = "nsh: %s: %s failed: %d\n"; -#endif -const char g_fmtcmdoutofmemory[] = "nsh: %s: out of memory\n"; -const char g_fmtinternalerror[] = "nsh: %s: Internal error\n"; -#ifndef CONFIG_DISABLE_SIGNALS -const char g_fmtsignalrecvd[] = "nsh: %s: Interrupted by signal\n"; -#endif - /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: cmd_help - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_HELP -static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - const struct cmdmap_s *ptr; - - nsh_output(vtbl, "NSH command forms:\n"); -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG - nsh_output(vtbl, " [nice [-d <niceness>>]] <cmd> [> <file>|>> <file>] [&]\n"); -#else - nsh_output(vtbl, " <cmd> [> <file>|>> <file>]\n"); -#endif -#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT - nsh_output(vtbl, "OR\n"); - nsh_output(vtbl, " if <cmd>\n"); - nsh_output(vtbl, " then\n"); - nsh_output(vtbl, " [sequence of <cmd>]\n"); - nsh_output(vtbl, " else\n"); - nsh_output(vtbl, " [sequence of <cmd>]\n"); - nsh_output(vtbl, " fi\n"); -#endif - nsh_output(vtbl, "Where <cmd> is one of:\n"); - for (ptr = g_cmdmap; ptr->cmd; ptr++) - { - if (ptr->usage) - { - nsh_output(vtbl, " %s %s\n", ptr->cmd, ptr->usage); - } - else - { - nsh_output(vtbl, " %s\n", ptr->cmd); - } - } - return OK; -} -#endif - -/**************************************************************************** - * Name: cmd_unrecognized - ****************************************************************************/ - -static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - nsh_output(vtbl, g_fmtcmdnotfound, argv[0]); - return ERROR; -} - -/**************************************************************************** - * Name: cmd_exit - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLE_EXIT -static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) -{ - nsh_exit(vtbl); - return OK; -} -#endif - -/**************************************************************************** - * Name: nsh_execute - ****************************************************************************/ - -static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]) -{ - const struct cmdmap_s *cmdmap; - const char *cmd; - cmd_t handler = cmd_unrecognized; - int ret; - - /* The form of argv is: - * - * argv[0]: The command name. This is argv[0] when the arguments - * are, finally, received by the command vtblr - * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS) - * argv[argc]: NULL terminating pointer - */ - - cmd = argv[0]; - - /* 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 - * not have to be performed in each command. - */ - - if (argc < cmdmap->minargs) - { - /* Fewer than the minimum number were provided */ - - nsh_output(vtbl, g_fmtargrequired, cmd); - return ERROR; - } - else if (argc > cmdmap->maxargs) - { - /* More than the maximum number were provided */ - - nsh_output(vtbl, g_fmttoomanyargs, cmd); - return ERROR; - } - else - { - /* A valid number of arguments were provided (this does - * not mean they are right). - */ - - handler = cmdmap->handler; - break; - } - } - } - - /* If the command was not found, then try to execute the command from - * a list of pre-built applications. - */ - -#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS - if (handler == cmd_unrecognized && nsh_execapp(vtbl, cmd, argv) == OK) - { - /* The pre-built application was successfully started -- return OK. - * If not, then fall through to execute the cmd_nrecognized handler. - */ - - return OK; - } -#endif - - ret = handler(vtbl, argc, argv); - return ret; -} - -/**************************************************************************** - * Name: nsh_releaseargs - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG -static void nsh_releaseargs(struct cmdarg_s *arg) -{ - FAR struct nsh_vtbl_s *vtbl = arg->vtbl; - int i; - - /* If the output was redirected, then file descriptor should - * be closed. The created task has its one, independent copy of - * the file descriptor - */ - - if (vtbl->np.np_redirect) - { - (void)close(arg->fd); - } - - /* Released the cloned vtbl instance */ - - nsh_release(vtbl); - - /* Release the cloned args */ - - for (i = 0; i < arg->argc; i++) - { - free(arg->argv[i]); - } - free(arg); -} -#endif - -/**************************************************************************** - * Name: nsh_child - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG -static pthread_addr_t nsh_child(pthread_addr_t arg) -{ - struct cmdarg_s *carg = (struct cmdarg_s *)arg; - int ret; - - dbg("BG %s\n", carg->argv[0]); - - /* Execute the specified command on the child thread */ - - ret = nsh_execute(carg->vtbl, carg->argc, carg->argv); - - /* Released the cloned arguments */ - - dbg("BG %s complete\n", carg->argv[0]); - nsh_releaseargs(carg); - return (void*)ret; -} -#endif - -/**************************************************************************** - * Name: nsh_cloneargs - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG -static inline struct cmdarg_s *nsh_cloneargs(FAR struct nsh_vtbl_s *vtbl, - int fd, int argc, char *argv[]) -{ - struct cmdarg_s *ret = (struct cmdarg_s *)zalloc(sizeof(struct cmdarg_s)); - int i; - - if (ret) - { - ret->vtbl = vtbl; - ret->fd = fd; - ret->argc = argc; - - for (i = 0; i < argc; i++) - { - ret->argv[i] = strdup(argv[i]); - } - } - return ret; -} -#endif - -/**************************************************************************** - * Name: nsh_argument - ****************************************************************************/ - -char *nsh_argument(FAR struct nsh_vtbl_s *vtbl, char **saveptr) -{ - char *pbegin = *saveptr; - char *pend = NULL; - const char *term; -#ifndef CONFIG_DISABLE_ENVIRON - bool quoted = false; -#endif - - /* Find the beginning of the next token */ - - for (; - *pbegin && strchr(g_delim, *pbegin) != NULL; - pbegin++); - - /* If we are at the end of the string with nothing - * but delimiters found, then return NULL. - */ - - if (!*pbegin) - { - return NULL; - } - - /* Does the token begin with '>' -- redirection of output? */ - - if (*pbegin == '>') - { - /* Yes.. does it begin with ">>"? */ - - if (*(pbegin + 1) == '>') - { - *saveptr = pbegin + 2; - pbegin = (char*)g_redirect2; - } - else - { - *saveptr = pbegin + 1; - pbegin = (char*)g_redirect1; - } - } - - /* Does the token begin with '#' -- comment */ - - else if (*pbegin == '#') - { - /* Return NULL meaning that we are at the end of the line */ - - *saveptr = pbegin; - pbegin = NULL; - } - else - { - /* Otherwise, we are going to have to parse to find the end of - * the token. Does the token begin with '"'? - */ - - if (*pbegin == '"') - { - /* Yes.. then only another '"' can terminate the string */ - - pbegin++; - term = "\""; -#ifndef CONFIG_DISABLE_ENVIRON - quoted = true; -#endif - } - else - { - /* No, then any of the usual terminators will terminate the argument */ - - term = g_delim; - } - - /* Find the end of the string */ - - for (pend = pbegin + 1; - *pend && strchr(term, *pend) == NULL; - pend++); - - /* pend either points to the end of the string or to - * the first delimiter after the string. - */ - - if (*pend) - { - /* Turn the delimiter into a null terminator */ - - *pend++ = '\0'; - } - - /* Save the pointer where we left off */ - - *saveptr = pend; - -#ifndef CONFIG_DISABLE_ENVIRON - /* Check for references to environment variables */ - - if (pbegin[0] == '$' && !quoted) - { - /* Check for built-in variables */ - - if (strcmp(pbegin, g_exitstatus) == 0) - { - if (vtbl->np.np_fail) - { - return (char*)g_failure; - } - else - { - return (char*)g_success; - } - } - - /* Not a built-in? Return the value of the environment variable with this name */ - - else - { - char *value = getenv(pbegin+1); - if (value) - { - return value; - } - else - { - return (char*)""; - } - } - } -#endif - } - - /* Return the beginning of the token. */ - - return pbegin; -} - -/**************************************************************************** - * Name: nsh_cmdenabled - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT -static inline bool nsh_cmdenabled(FAR struct nsh_vtbl_s *vtbl) -{ - struct nsh_parser_s *np = &vtbl->np; - bool ret = !np->np_st[np->np_ndx].ns_disabled; - if (ret) - { - switch (np->np_st[np->np_ndx].ns_state) - { - case NSH_PARSER_NORMAL : - case NSH_PARSER_IF: - default: - break; - - case NSH_PARSER_THEN: - ret = !np->np_st[np->np_ndx].ns_ifcond; - break; - - case NSH_PARSER_ELSE: - ret = np->np_st[np->np_ndx].ns_ifcond; - break; - } - } - return ret; -} -#endif - -/**************************************************************************** - * Name: nsh_ifthenelse - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT -static inline int nsh_ifthenelse(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR char **saveptr) -{ - struct nsh_parser_s *np = &vtbl->np; - FAR char *cmd = *ppcmd; - bool disabled; - - if (cmd) - { - /* Check if the command is preceeded by "if" */ - - if (strcmp(cmd, "if") == 0) - { - /* Get the cmd following the if */ - - *ppcmd = nsh_argument(vtbl, saveptr); - if (!*ppcmd) - { - nsh_output(vtbl, g_fmtarginvalid, "if"); - goto errout; - } - - /* Verify that "if" is valid in this context */ - - if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_NORMAL && - np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN && - np->np_st[np->np_ndx].ns_state != NSH_PARSER_ELSE) - { - nsh_output(vtbl, g_fmtcontext, "if"); - goto errout; - } - - /* Check if we have exceeded the maximum depth of nesting */ - - if (np->np_ndx >= CONFIG_EXAMPLES_NSH_NESTDEPTH-1) - { - nsh_output(vtbl, g_fmtdeepnesting, "if"); - goto errout; - } - - /* "Push" the old state and set the new state */ - - disabled = !nsh_cmdenabled(vtbl); - np->np_ndx++; - np->np_st[np->np_ndx].ns_state = NSH_PARSER_IF; - np->np_st[np->np_ndx].ns_disabled = disabled; - np->np_st[np->np_ndx].ns_ifcond = false; - } - else if (strcmp(cmd, "then") == 0) - { - /* Get the cmd following the then -- there shouldn't be one */ - - *ppcmd = nsh_argument(vtbl, saveptr); - if (*ppcmd) - { - nsh_output(vtbl, g_fmtarginvalid, "then"); - goto errout; - } - - /* Verify that "then" is valid in this context */ - - if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_IF) - { - nsh_output(vtbl, g_fmtcontext, "then"); - goto errout; - } - np->np_st[np->np_ndx].ns_state = NSH_PARSER_THEN; - } - else if (strcmp(cmd, "else") == 0) - { - /* Get the cmd following the else -- there shouldn't be one */ - - *ppcmd = nsh_argument(vtbl, saveptr); - if (*ppcmd) - { - nsh_output(vtbl, g_fmtarginvalid, "else"); - goto errout; - } - - /* Verify that "then" is valid in this context */ - - if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN) - { - nsh_output(vtbl, g_fmtcontext, "else"); - goto errout; - } - np->np_st[np->np_ndx].ns_state = NSH_PARSER_ELSE; - } - else if (strcmp(cmd, "fi") == 0) - { - /* Get the cmd following the fi -- there should be one */ - - *ppcmd = nsh_argument(vtbl, saveptr); - if (*ppcmd) - { - nsh_output(vtbl, g_fmtarginvalid, "fi"); - goto errout; - } - - /* Verify that "fi" is valid in this context */ - - if (np->np_st[np->np_ndx].ns_state != NSH_PARSER_THEN && - np->np_st[np->np_ndx].ns_state != NSH_PARSER_ELSE) - { - nsh_output(vtbl, g_fmtcontext, "fi"); - goto errout; - } - - if (np->np_ndx < 1) /* Shouldn't happen */ - { - nsh_output(vtbl, g_fmtinternalerror, "if"); - goto errout; - } - - /* "Pop" the previous state */ - - np->np_ndx--; - } - else if (np->np_st[np->np_ndx].ns_state == NSH_PARSER_IF) - { - nsh_output(vtbl, g_fmtcontext, cmd); - goto errout; - } - } - return OK; - -errout: - np->np_ndx = 0; - np->np_st[0].ns_state = NSH_PARSER_NORMAL; - np->np_st[0].ns_disabled = false; - np->np_st[0].ns_ifcond = false; - return ERROR; -} -#endif - -/**************************************************************************** - * Name: nsh_saveresult - ****************************************************************************/ - -static inline int nsh_saveresult(FAR struct nsh_vtbl_s *vtbl, bool result) -{ - struct nsh_parser_s *np = &vtbl->np; - -#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT - if (np->np_st[np->np_ndx].ns_state == NSH_PARSER_IF) - { - np->np_fail = false; - np->np_st[np->np_ndx].ns_ifcond = result; - return OK; - } - else -#endif - { - np->np_fail = result; - return result ? ERROR : OK; - } -} - -/**************************************************************************** - * Name: nsh_nice - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG -static inline int nsh_nice(FAR struct nsh_vtbl_s *vtbl, FAR char **ppcmd, FAR char **saveptr) -{ - FAR char *cmd = *ppcmd; - - vtbl->np.np_nice = 0; - if (cmd) - { - /* Check if the command is preceded by "nice" */ - - if (strcmp(cmd, "nice") == 0) - { - /* Nicenesses range from -20 (most favorable scheduling) to 19 - * (least favorable). Default is 10. - */ - - vtbl->np.np_nice = 10; - - /* Get the cmd (or -d option of nice command) */ - - cmd = nsh_argument(vtbl, saveptr); - if (cmd && strcmp(cmd, "-d") == 0) - { - FAR char *val = nsh_argument(vtbl, saveptr); - if (val) - { - char *endptr; - vtbl->np.np_nice = (int)strtol(val, &endptr, 0); - if (vtbl->np.np_nice > 19 || vtbl->np.np_nice < -20 || - endptr == val || *endptr != '\0') - { - nsh_output(vtbl, g_fmtarginvalid, "nice"); - return ERROR; - } - cmd = nsh_argument(vtbl, saveptr); - } - } - - /* Return the real command name */ - - *ppcmd = cmd; - } - } - return OK; -} -#endif - -/**************************************************************************** * Public Functions ****************************************************************************/ @@ -1012,17 +105,9 @@ int user_start(int argc, char *argv[]) int ret; #endif - /* Mount the /etc filesystem */ - - (void)nsh_romfsetc(); - - /* Perform architecture-specific initialization (if available) */ - - (void)nsh_archinitialize(); + /* Initialize the NSH library */ - /* Bring up the network */ - - (void)nsh_netinit(); + nsh_initialize(); /* Set the priority of this task to something in the middle so that 'nice' * can both raise and lower the priority. @@ -1064,303 +149,3 @@ int user_start(int argc, char *argv[]) return nsh_consolemain(0, NULL); #endif } - -/**************************************************************************** - * Name: nsh_parse - ****************************************************************************/ - -int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline) -{ - FAR char *argv[MAX_ARGV_ENTRIES]; - FAR char *saveptr; - FAR char *cmd; - FAR char *redirfile = NULL; - int fd = -1; - int oflags = 0; - int argc; - int ret; - - /* Initialize parser state */ - - memset(argv, 0, MAX_ARGV_ENTRIES*sizeof(FAR char *)); -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG - vtbl->np.np_bg = false; -#endif - vtbl->np.np_redirect = false; - - /* Parse out the command at the beginning of the line */ - - saveptr = cmdline; - cmd = nsh_argument(vtbl, &saveptr); - - /* Handler if-then-else-fi */ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT - if (nsh_ifthenelse(vtbl, &cmd, &saveptr) != 0) - { - goto errout; - } -#endif - - /* Handle nice */ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG - if (nsh_nice(vtbl, &cmd, &saveptr) != 0) - { - goto errout; - } -#endif - - /* Check if any command was provided -OR- if command processing is - * currently disabled. - */ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLESCRIPT - if (!cmd || !nsh_cmdenabled(vtbl)) -#else - if (!cmd) -#endif - { - /* An empty line is not an error and an unprocessed command cannot - * generate an error, but neither should they change the last - * command status. - */ - - return OK; - } - - /* Parse all of the arguments following the command name. The form - * of argv is: - * - * argv[0]: The command name. - * argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS) - * argv[argc-3]: Possibly '>' or '>>' - * argv[argc-2]: Possibly <file> - * argv[argc-1]: Possibly '&' - * argv[argc]: NULL terminating pointer - * - * Maximum size is NSH_MAX_ARGUMENTS+5 - */ - - argv[0] = cmd; - for (argc = 1; argc < MAX_ARGV_ENTRIES-1; argc++) - { - argv[argc] = nsh_argument(vtbl, &saveptr); - if (!argv[argc]) - { - break; - } - } - argv[argc] = NULL; - - /* Check if the command should run in background */ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG - if (argc > 1 && strcmp(argv[argc-1], "&") == 0) - { - vtbl->np.np_bg = true; - argv[argc-1] = NULL; - argc--; - } -#endif - - - /* Check if the output was re-directed using > or >> */ - - if (argc > 2) - { - /* Check for redirection to a new file */ - - if (strcmp(argv[argc-2], g_redirect1) == 0) - { - vtbl->np.np_redirect = true; - oflags = O_WRONLY|O_CREAT|O_TRUNC; - redirfile = nsh_getfullpath(vtbl, argv[argc-1]); - argc -= 2; - } - - /* Check for redirection by appending to an existing file */ - - else if (strcmp(argv[argc-2], g_redirect2) == 0) - { - vtbl->np.np_redirect = true; - oflags = O_WRONLY|O_CREAT|O_APPEND; - redirfile = nsh_getfullpath(vtbl, argv[argc-1]); - argc -= 2; - } - } - - /* Redirected output? */ - - if (vtbl->np.np_redirect) - { - /* Open the redirection file. This file will eventually - * be closed by a call to either nsh_release (if the command - * is executed in the background) or by nsh_undirect if the - * command is executed in the foreground. - */ - - fd = open(redirfile, oflags, 0666); - nsh_freefullpath(redirfile); - redirfile = NULL; - - if (fd < 0) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO); - goto errout; - } - } - - /* Check if the maximum number of arguments was exceeded */ - - if (argc > NSH_MAX_ARGUMENTS) - { - nsh_output(vtbl, g_fmttoomanyargs, cmd); - } - - /* Handle the case where the command is executed in background. - * However is app is to be started as nuttapp new process will - * be created anyway, so skip this step. */ - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG - if (vtbl->np.np_bg -#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS - && nuttapp_isavail(argv[0]) < 0 -#endif - ) - { - struct sched_param param; - struct nsh_vtbl_s *bkgvtbl; - struct cmdarg_s *args; - pthread_attr_t attr; - pthread_t thread; - - /* Get a cloned copy of the vtbl with reference count=1. - * after the command has been processed, the nsh_release() call - * at the end of nsh_child() will destroy the clone. - */ - - bkgvtbl = nsh_clone(vtbl); - if (!bkgvtbl) - { - goto errout_with_redirect; - } - - /* Create a container for the command arguments */ - - args = nsh_cloneargs(bkgvtbl, fd, argc, argv); - if (!args) - { - nsh_release(bkgvtbl); - goto errout_with_redirect; - } - - /* Handle redirection of output via a file descriptor */ - - if (vtbl->np.np_redirect) - { - (void)nsh_redirect(bkgvtbl, fd, NULL); - } - - /* Get the execution priority of this task */ - - ret = sched_getparam(0, ¶m); - if (ret != 0) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "sched_getparm", NSH_ERRNO); - nsh_releaseargs(args); - nsh_release(bkgvtbl); - goto errout; - } - - /* Determine the priority to execute the command */ - - if (vtbl->np.np_nice != 0) - { - int priority = param.sched_priority - vtbl->np.np_nice; - if (vtbl->np.np_nice < 0) - { - int max_priority = sched_get_priority_max(SCHED_NSH); - if (priority > max_priority) - { - priority = max_priority; - } - } - else - { - int min_priority = sched_get_priority_min(SCHED_NSH); - if (priority < min_priority) - { - priority = min_priority; - } - } - param.sched_priority = priority; - } - - /* Set up the thread attributes */ - - (void)pthread_attr_init(&attr); - (void)pthread_attr_setschedpolicy(&attr, SCHED_NSH); - (void)pthread_attr_setschedparam(&attr, ¶m); - - /* Execute the command as a separate thread at the appropriate priority */ - - ret = pthread_create(&thread, &attr, nsh_child, (pthread_addr_t)args); - if (ret != 0) - { - nsh_output(vtbl, g_fmtcmdfailed, cmd, "pthread_create", NSH_ERRNO_OF(ret)); - nsh_releaseargs(args); - nsh_release(bkgvtbl); - goto errout; - } - nsh_output(vtbl, "%s [%d:%d]\n", cmd, thread, param.sched_priority); - } - else -#endif - { - uint8_t save[SAVE_SIZE]; - - /* Handle redirection of output via a file descriptor */ - - if (vtbl->np.np_redirect) - { - nsh_redirect(vtbl, fd, save); - } - - /* Then execute the command in "foreground" -- i.e., while the user waits - * for the next prompt. - */ - - ret = nsh_execute(vtbl, argc, argv); - - /* Restore the original output. Undirect will close the redirection - * file descriptor. - */ - - if (vtbl->np.np_redirect) - { - nsh_undirect(vtbl, save); - } - - if (ret < 0) - { - goto errout; - } - } - - /* Return success if the command succeeded (or at least, starting of the - * command task succeeded). - */ - - return nsh_saveresult(vtbl, false); - -#ifndef CONFIG_EXAMPLES_NSH_DISABLEBG -errout_with_redirect: - if (vtbl->np.np_redirect) - { - close(fd); - } -#endif -errout: - return nsh_saveresult(vtbl, true); -} diff --git a/nuttx/include/apps/nsh.h b/nuttx/include/apps/nsh.h index d8e857841..6977e44bd 100644 --- a/nuttx/include/apps/nsh.h +++ b/nuttx/include/apps/nsh.h @@ -46,6 +46,12 @@ * Pre-Processor Definitions ****************************************************************************/ +#if CONFIG_RR_INTERVAL > 0 +# define SCHED_NSH SCHED_RR +#else +# define SCHED_NSH SCHED_FIFO +#endif + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/nuttx/sched/os_bringup.c b/nuttx/sched/os_bringup.c index c9d84c223..64b4e9388 100644 --- a/nuttx/sched/os_bringup.c +++ b/nuttx/sched/os_bringup.c @@ -55,7 +55,7 @@ # include "work_internal.h" #endif #ifdef CONFIG_BUILTIN_APPS -# include "nuttx/nuttapp.h" +# include "apps/apps.h" #endif /**************************************************************************** @@ -172,17 +172,3 @@ int os_bringup(void) ASSERT(init_taskid != ERROR); return OK; } - - -Index: sched/os_bringup.c -=================================================================== ---- sched/os_bringup.c (revision 3388) -+++ sched/os_bringup.c (working copy) -@@ -154,7 +154,14 @@ - svdbg("Starting init thread\n"); - - #if defined(CONFIG_BUILTIN_APPS_NUTTX) && defined(CONFIG_BUILTIN_APP_START) -- init_taskid = exec_nuttapp(CONFIG_BUILTIN_APP_START, (const char **)NULL); - #else - init_taskid = START_TASK("init", SCHED_PRIORITY_DEFAULT, - CONFIG_USERMAIN_STACKSIZE, |