2014-01-10 20:50:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/nshlib/nsh_command.c
|
|
|
|
*
|
2020-03-21 18:25:56 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2014-01-10 20:50:36 +01:00
|
|
|
*
|
2020-03-21 18:25:56 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-01-10 20:50:36 +01:00
|
|
|
*
|
2020-03-21 18:25:56 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-01-10 20:50:36 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
2021-05-24 07:44:39 +02:00
|
|
|
#include <assert.h>
|
2014-01-10 20:50:36 +01:00
|
|
|
|
2014-01-10 22:23:26 +01:00
|
|
|
#ifdef CONFIG_NSH_BUILTIN_APPS
|
2019-08-23 17:12:20 +02:00
|
|
|
# include <nuttx/lib/builtin.h>
|
2014-01-10 22:23:26 +01:00
|
|
|
#endif
|
2014-01-10 20:50:36 +01:00
|
|
|
|
2015-07-30 20:11:58 +02:00
|
|
|
#if defined(CONFIG_SYSTEM_READLINE) && defined(CONFIG_READLINE_HAVE_EXTMATCH)
|
2016-07-11 18:11:18 +02:00
|
|
|
# include "system/readline.h"
|
2015-07-30 20:11:58 +02:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#include "nsh.h"
|
|
|
|
#include "nsh_console.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Help command summary layout */
|
|
|
|
|
2019-01-11 16:21:59 +01:00
|
|
|
#define HELP_LINELEN 80
|
2023-03-05 02:07:36 +01:00
|
|
|
#define HELP_TABSIZE 4
|
2014-01-10 20:50:36 +01:00
|
|
|
#define NUM_CMDS ((sizeof(g_cmdmap)/sizeof(struct cmdmap_s)) - 1)
|
|
|
|
|
2023-06-09 03:34:52 +02:00
|
|
|
/* Help marco for nsh command */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NSH_DISABLE_HELP
|
|
|
|
# define CMD_MAP(cmd, handler, min, max, usage) \
|
|
|
|
{ cmd, handler, min, max }
|
|
|
|
#else
|
|
|
|
# define CMD_MAP(cmd, handler, min, max, usage) \
|
|
|
|
{ cmd, handler, min, max, usage }
|
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct cmdmap_s
|
|
|
|
{
|
2015-11-28 15:29:27 +01:00
|
|
|
FAR const char *cmd; /* Name of the command */
|
|
|
|
nsh_cmd_t handler; /* Function that handles the command */
|
2014-01-10 20:50:36 +01:00
|
|
|
uint8_t minargs; /* Minimum number of arguments (including command) */
|
|
|
|
uint8_t maxargs; /* Maximum number of arguments (including command) */
|
2023-06-09 03:34:52 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
2015-11-28 15:29:27 +01:00
|
|
|
FAR const char *usage; /* Usage instructions for 'help' command */
|
2023-06-09 03:34:52 +02:00
|
|
|
#endif
|
2014-01-10 20:50:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
2022-09-22 05:38:12 +02:00
|
|
|
static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2014-01-17 20:24:44 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
2022-09-22 05:38:12 +02:00
|
|
|
static int cmd_true(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
|
|
|
|
static int cmd_false(FAR struct nsh_vtbl_s *vtbl, int argc,
|
|
|
|
FAR char **argv);
|
2014-01-17 20:24:44 +01:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_EXIT
|
2022-09-22 05:38:12 +02:00
|
|
|
static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
2014-01-17 20:24:44 +01:00
|
|
|
|
2019-01-11 14:39:23 +01:00
|
|
|
static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc,
|
2022-09-22 05:38:12 +02:00
|
|
|
FAR char **argv);
|
2014-01-10 20:50:36 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const struct cmdmap_s g_cmdmap[] =
|
|
|
|
{
|
2023-02-21 23:08:13 +01:00
|
|
|
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP(".", cmd_source, 2, 2, "<script-path>"),
|
2020-04-18 15:57:26 +02:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("[", cmd_lbracket,
|
|
|
|
4, CONFIG_NSH_MAXARGUMENTS, "<expression> ]"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("?", cmd_help, 1, 1, NULL),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) && !defined(CONFIG_NSH_DISABLE_ADDROUTE)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("addroute", cmd_addroute, 3, 4, "<target> [<netmask>] <router>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2023-02-22 17:19:59 +01:00
|
|
|
#ifdef CONFIG_NSH_ALIAS
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("alias", cmd_alias, 1, CONFIG_NSH_MAXARGUMENTS,
|
|
|
|
"[name[=value] ... ]"),
|
|
|
|
CMD_MAP("unalias", cmd_unalias, 1, CONFIG_NSH_MAXARGUMENTS,
|
|
|
|
"[-a] name [name ... ]"),
|
2023-02-22 17:19:59 +01:00
|
|
|
#endif
|
|
|
|
|
2016-02-08 21:49:05 +01:00
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_ARP) && !defined(CONFIG_NSH_DISABLE_ARP)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("arp", cmd_arp, 1, 6,
|
|
|
|
"[-i <ifname>] [-a <ipaddr>|-d <ipaddr>|-s <ipaddr> <hwaddr>]"),
|
2019-11-03 23:19:14 +01:00
|
|
|
#endif
|
2016-02-08 21:49:05 +01:00
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64)
|
|
|
|
# ifndef CONFIG_NSH_DISABLE_BASE64DEC
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("base64dec", cmd_base64decode,
|
|
|
|
2, 4, "[-w] [-f] <string or filepath>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
# endif
|
|
|
|
# ifndef CONFIG_NSH_DISABLE_BASE64ENC
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("base64enc", cmd_base64encode,
|
|
|
|
2, 4, "[-w] [-f] <string or filepath>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2015-11-23 17:21:15 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_BASENAME
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("basename", cmd_basename, 2, 3, "<path> [<suffix>]"),
|
2015-11-23 17:21:15 +01:00
|
|
|
#endif
|
|
|
|
|
2023-04-01 14:23:12 +02:00
|
|
|
#if defined(CONFIG_BOARDCTL_BOOT_IMAGE) && !defined(CONFIG_NSH_DISABLE_BOOT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("boot", cmd_boot, 1, 3, "[<image path> [<header size>]]"),
|
2023-04-01 14:23:12 +02:00
|
|
|
#endif
|
|
|
|
|
2014-01-18 16:39:16 +01:00
|
|
|
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_LOOPS)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("break", cmd_break, 1, 1, NULL),
|
2014-02-21 01:14:02 +01:00
|
|
|
#endif
|
2014-01-18 16:39:16 +01:00
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_CAT
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("cat", cmd_cat, 2, CONFIG_NSH_MAXARGUMENTS,
|
|
|
|
"<path> [<path> [<path> ...]]"),
|
2019-02-11 20:10:10 +01:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_CD
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("cd", cmd_cd, 1, 2, "[<dir-path>|-|~|..]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
2019-02-11 20:10:10 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_CP
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("cp", cmd_cp, 3, 3, "<source-path> <dest-path>"),
|
2019-02-11 20:10:10 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_CMP
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("cmp", cmd_cmp, 3, 3, "<path1> <path2>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2015-11-23 17:21:15 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_DIRNAME
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("dirname", cmd_dirname, 2, 2, "<path>"),
|
2015-11-23 17:21:15 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-11 20:13:18 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_DATE
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("date", cmd_date,
|
|
|
|
1, 4, "[-s \"MMM DD HH:MM:SS YYYY\"] [-u]"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_DD
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("dd", cmd_dd, 3, 7,
|
2020-03-17 06:13:46 +01:00
|
|
|
"if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] "
|
2023-06-09 03:34:52 +02:00
|
|
|
"[skip=<sectors>] [verify]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
#endif
|
2014-01-10 20:50:36 +01:00
|
|
|
|
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) && !defined(CONFIG_NSH_DISABLE_DELROUTE)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("delroute", cmd_delroute, 2, 3, "<target> [<netmask>]"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2020-03-21 18:25:56 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && !defined(CONFIG_NSH_DISABLE_DF)
|
2017-10-26 21:28:37 +02:00
|
|
|
#ifdef NSH_HAVE_CATFILE
|
2017-10-27 00:07:42 +02:00
|
|
|
#if defined(HAVE_DF_HUMANREADBLE) && defined(HAVE_DF_BLOCKOUTPUT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("df", cmd_df, 1, 2, "[-h]"),
|
2017-10-27 00:07:42 +02:00
|
|
|
#else
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("df", cmd_df, 1, 1, NULL),
|
2017-10-27 00:07:42 +02:00
|
|
|
#endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-06-27 10:24:05 +02:00
|
|
|
#if defined(CONFIG_SYSLOG_DEVPATH) && !defined(CONFIG_NSH_DISABLE_DMESG)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("dmesg", cmd_dmesg, 1, 1, NULL),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_ECHO
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_DISABLE_ENVIRON
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS,
|
|
|
|
"[-n] [<string|$name> [<string|$name>...]]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# else
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("echo", cmd_echo, 1, CONFIG_NSH_MAXARGUMENTS,
|
|
|
|
"[-n] [<string> [<string>...]]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2016-10-01 15:44:15 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-30 18:55:23 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_ENV
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("env", cmd_env, 1, 1, NULL),
|
2018-09-30 18:55:23 +02:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_EXEC
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("exec", cmd_exec, 2, 3, "<hex-address>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
2014-01-17 20:24:44 +01:00
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_EXIT
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("exit", cmd_exit, 1, 1, NULL),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2018-10-01 21:30:25 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_EXPORT
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("export", cmd_export, 2, 3, "[<name> [<value>]]"),
|
2018-10-01 21:30:25 +02:00
|
|
|
#endif
|
|
|
|
|
2014-01-17 20:24:44 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("false", cmd_false, 1, 1, NULL),
|
2014-01-17 20:24:44 +01:00
|
|
|
#endif
|
|
|
|
|
2023-06-14 10:14:59 +02:00
|
|
|
#ifdef CONFIG_FS_PROCFS
|
|
|
|
# ifndef CONFIG_NSH_DISABLE_FDINFO
|
|
|
|
CMD_MAP("fdinfo", cmd_fdinfo, 1, 2, "[pid]"),
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_FREE
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("free", cmd_free, 1, 1, NULL),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2022-01-20 14:12:14 +01:00
|
|
|
#ifdef CONFIG_DEBUG_MM
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_MEMDUMP
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("memdump", cmd_memdump,
|
|
|
|
1, 4, "[pid/used/free/on/off]" " <minseq> <maxseq>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2022-01-20 14:12:14 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifdef CONFIG_NET_UDP
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_GET
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("get", cmd_get, 4, 7,
|
|
|
|
"[-b|-n] [-f <local-path>] -h <ip-address> <remote-path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifdef CONFIG_NSH_HELP_TERSE
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("help", cmd_help, 1, 2, "[<cmd>]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# else
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("help", cmd_help, 1, 3, "[-v] [<cmd>]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HEXDUMP
|
|
|
|
#ifndef CONFIG_NSH_CMDOPT_HEXDUMP
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("hexdump", cmd_hexdump, 2, 2, "<file or device>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#else
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("hexdump", cmd_hexdump, 2, 4,
|
|
|
|
"<file or device> [skip=<bytes>] [count=<bytes>]"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_IFCONFIG
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("ifconfig", cmd_ifconfig, 1, 12,
|
2023-05-10 08:58:44 +02:00
|
|
|
"[interface [address_family] [mtu <len>] | [<ip-address>|dhcp]]"
|
2022-12-29 08:35:26 +01:00
|
|
|
"[dr|gw|gateway <dr-address>] [netmask <net-mask>|prefixlen <len>] "
|
2023-06-09 03:34:52 +02:00
|
|
|
"[dns <dns-address>] [hw <hw-mac>]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
|
|
|
# ifndef CONFIG_NSH_DISABLE_IFUPDOWN
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("ifdown", cmd_ifdown, 2, 2, "<interface>"),
|
|
|
|
CMD_MAP("ifup", cmd_ifup, 2, 2, "<interface>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2015-12-13 16:55:52 +01:00
|
|
|
#if defined(CONFIG_MODULE) && !defined(CONFIG_NSH_DISABLE_MODCMDS)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("insmod", cmd_insmod, 3, 3, "<file-path> <module-name>"),
|
2018-01-13 00:58:44 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_IRQINFO
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("irqinfo", cmd_irqinfo, 1, 1, NULL),
|
2015-12-13 16:55:52 +01:00
|
|
|
#endif
|
|
|
|
|
2019-04-29 22:53:38 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_KILL
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("kill", cmd_kill, 2, 3, "[-<signal>] <pid>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
2023-05-21 10:37:31 +02:00
|
|
|
# if defined(CONFIG_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOSETUP)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("losetup", cmd_losetup, 3, 6,
|
2022-04-11 06:58:04 +02:00
|
|
|
"[-d <dev-path>] | [[-o <offset>] [-r] [-s <sect-size>] "
|
2023-06-09 03:34:52 +02:00
|
|
|
"<dev-path> <file-path>]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
2023-05-21 10:37:31 +02:00
|
|
|
# if defined(CONFIG_SMART_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOSMART)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("losmart", cmd_losmart, 2, 11,
|
2020-03-17 06:13:46 +01:00
|
|
|
"[-d <dev-path>] | [[-m <minor>] [-o <offset>] [-e <erase-size>] "
|
2023-06-09 03:34:52 +02:00
|
|
|
"[-s <sect-size>] [-r] <file-path>]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2015-11-28 16:05:05 +01:00
|
|
|
#endif
|
|
|
|
|
2023-02-06 16:10:20 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
2023-05-21 10:37:31 +02:00
|
|
|
# if defined(CONFIG_MTD_LOOP) && !defined(CONFIG_NSH_DISABLE_LOMTD)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("lomtd", cmd_lomtd, 3, 9,
|
2023-02-06 16:10:20 +01:00
|
|
|
"[-d <dev-path>] | [[-o <offset>] [-e <erase-size>] "
|
2023-06-09 03:34:52 +02:00
|
|
|
"[-s <sect-size>] <dev-path> <file-path>]]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2023-02-06 16:10:20 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#if !defined(CONFIG_NSH_DISABLE_LN) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("ln", cmd_ln, 3, 4, "[-s] <target> <link>"),
|
2017-02-03 02:40:59 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_LS
|
2023-07-04 10:28:19 +02:00
|
|
|
CMD_MAP("ls", cmd_ls, 1, 5, "[-lRsh] <dir-path>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2015-12-13 16:55:52 +01:00
|
|
|
#if defined(CONFIG_MODULE) && !defined(CONFIG_NSH_DISABLE_MODCMDS)
|
2023-05-21 10:37:31 +02:00
|
|
|
# if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("lsmod", cmd_lsmod, 1, 1, NULL),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2015-12-13 16:55:52 +01:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_MB
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mb", cmd_mb, 2, 3,
|
|
|
|
"<hex-address>[=<hex-value>] [<hex-byte-count>]"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5)
|
|
|
|
# ifndef CONFIG_NSH_DISABLE_MD5
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("md5", cmd_md5, 2, 3, "[-f] <string or filepath>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2014-02-21 01:14:02 +01:00
|
|
|
#ifdef NSH_HAVE_DIROPTS
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_MKDIR
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mkdir", cmd_mkdir, 2, 3, "[-p] <path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FSUTILS_MKFATFS)
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_MKFATFS
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mkfatfs", cmd_mkfatfs, 2, 6,
|
|
|
|
"[-F <fatsize>] [-r <rootdirentries>] <block-driver>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
2023-05-21 10:37:31 +02:00
|
|
|
# if defined(CONFIG_PIPES) && CONFIG_DEV_FIFO_SIZE > 0 && \
|
2016-08-04 20:57:02 +02:00
|
|
|
!defined(CONFIG_NSH_DISABLE_MKFIFO)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mkfifo", cmd_mkfifo, 2, 2, "<path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2020-08-23 19:25:25 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_MKRD
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mkrd", cmd_mkrd, 2, 6,
|
|
|
|
"[-m <minor>] [-s <sector-size>] <nsectors>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_SMARTFS) && \
|
|
|
|
defined(CONFIG_FSUTILS_MKSMARTFS)
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_MKSMARTFS
|
|
|
|
# ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mksmartfs", cmd_mksmartfs, 2, 6,
|
|
|
|
"[-s <sector-size>] [-f] <path> [<num-root-directories>]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# else
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mksmartfs", cmd_mksmartfs,
|
|
|
|
2, 5, "[-s <sector-size>] [-f] <path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2015-11-23 13:59:56 +01:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_MH
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mh", cmd_mh, 2, 3,
|
|
|
|
"<hex-address>[=<hex-value>] [<hex-byte-count>]"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2020-03-21 18:25:56 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT)
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_MOUNT
|
|
|
|
# if defined(NSH_HAVE_CATFILE) && defined(HAVE_MOUNT_LIST)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mount", cmd_mount, 1, 7,
|
|
|
|
"[-t <fstype> [-o <options>] [<block-device>] <mount-point>]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# else
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mount", cmd_mount, 4, 7,
|
|
|
|
"-t <fstype> [-o <options>] [<block-device>] <mount-point>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2014-02-21 01:14:02 +01:00
|
|
|
#ifdef NSH_HAVE_DIROPTS
|
2014-01-10 20:50:36 +01:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_MV
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mv", cmd_mv, 3, 3, "<old-path> <new-path>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_MW
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("mw", cmd_mw, 2, 3,
|
|
|
|
"<hex-address>[=<hex-value>] [<hex-byte-count>]"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_NET) && \
|
|
|
|
defined(CONFIG_NFS)
|
2014-01-10 20:50:36 +01:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_NFSMOUNT
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("nfsmount", cmd_nfsmount, 4, 5,
|
|
|
|
"<server-address> <mount-point> <remote-path> [udp]"),
|
2014-01-10 20:50:36 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2020-03-30 12:06:47 +02:00
|
|
|
#if defined(CONFIG_LIBC_NETDB) && !defined(CONFIG_NSH_DISABLE_NSLOOKUP)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("nslookup", cmd_nslookup, 2, 2, "<host-name>"),
|
2015-07-13 19:19:02 +02:00
|
|
|
#endif
|
|
|
|
|
2020-03-21 18:25:56 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_NSH_LOGIN_PASSWD) && \
|
2016-01-20 20:05:25 +01:00
|
|
|
!defined(CONFIG_FSUTILS_PASSWD_READONLY)
|
2016-01-20 16:37:25 +01:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_PASSWD
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("passwd", cmd_passwd, 3, 3, "<username> <password>"),
|
2016-01-20 16:37:25 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2019-11-04 14:44:33 +01:00
|
|
|
#if defined(CONFIG_PM) && !defined(CONFIG_NSH_DISABLE_PMCONFIG)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("pmconfig", cmd_pmconfig, 1, 4,
|
|
|
|
"[stay|relax] [normal|idle|standby|sleep] [domain]"),
|
2019-11-04 14:44:33 +01:00
|
|
|
#endif
|
|
|
|
|
2015-07-04 20:44:24 +02:00
|
|
|
#if defined(CONFIG_BOARDCTL_POWEROFF) && !defined(CONFIG_NSH_DISABLE_POWEROFF)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("poweroff", cmd_poweroff, 1, 2, NULL),
|
2015-07-04 20:44:24 +02:00
|
|
|
#endif
|
|
|
|
|
2018-01-13 00:58:44 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_PRINTF
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_DISABLE_ENVIRON
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("printf", cmd_printf, 1, CONFIG_NSH_MAXARGUMENTS,
|
|
|
|
"[\\xNN] [\\n\\r\\t] [<string|$name> [<string|$name>...]]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# else
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("printf", cmd_printf, 1, CONFIG_NSH_MAXARGUMENTS,
|
|
|
|
"[\\xNN] [\\n\\r\\t] [<string> [<string>...]]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2018-01-13 00:58:44 +01:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_PS
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("ps", cmd_ps, 1, 1, NULL),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifdef CONFIG_NET_UDP
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_PUT
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("put", cmd_put, 4, 7,
|
|
|
|
"[-b|-n] [-f <remote-path>] -h <ip-address> <local-path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_DISABLE_ENVIRON
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_PWD
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("pwd", cmd_pwd, 1, 1, NULL),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#if !defined(CONFIG_NSH_DISABLE_READLINK) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("readlink", cmd_readlink, 2, 2, "<link>"),
|
2017-02-05 17:35:11 +01:00
|
|
|
#endif
|
|
|
|
|
2015-07-04 20:44:24 +02:00
|
|
|
#if defined(CONFIG_BOARDCTL_RESET) && !defined(CONFIG_NSH_DISABLE_REBOOT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("reboot", cmd_reboot, 1, 2, NULL),
|
2015-07-04 20:44:24 +02:00
|
|
|
#endif
|
|
|
|
|
2022-03-30 09:38:21 +02:00
|
|
|
#if defined(CONFIG_BOARDCTL_RESET_CAUSE) && !defined(CONFIG_NSH_DISABLE_RESET_CAUSE)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("resetcause", cmd_reset_cause, 1, 1, NULL),
|
2022-03-30 09:38:21 +02:00
|
|
|
#endif
|
|
|
|
|
2014-02-21 01:14:02 +01:00
|
|
|
#ifdef NSH_HAVE_DIROPTS
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_RM
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("rm", cmd_rm, 2, 3, "[-r] <file-path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-02-21 01:14:02 +01:00
|
|
|
#endif
|
2014-02-19 17:01:26 +01:00
|
|
|
|
2014-02-21 01:14:02 +01:00
|
|
|
#ifdef NSH_HAVE_DIROPTS
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_RMDIR
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("rmdir", cmd_rmdir, 2, 2, "<dir-path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2015-12-13 16:55:52 +01:00
|
|
|
#if defined(CONFIG_MODULE) && !defined(CONFIG_NSH_DISABLE_MODCMDS)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("rmmod", cmd_rmmod, 2, 2, "<module-name>"),
|
2015-12-13 16:55:52 +01:00
|
|
|
#endif
|
|
|
|
|
2017-08-11 23:56:53 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_ROUTE
|
2017-08-11 23:33:26 +02:00
|
|
|
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("route", cmd_route, 2, 2, "ipv4|ipv6"),
|
2017-08-11 23:33:26 +02:00
|
|
|
#elif defined(CONFIG_NET_IPv4)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("route", cmd_route, 1, 2, "[ipv4]"),
|
2017-08-11 23:33:26 +02:00
|
|
|
#elif defined(CONFIG_NET_IPv6)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("route", cmd_route, 1, 2, "[ipv6]"),
|
2017-08-11 23:33:26 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-11-03 16:36:49 +01:00
|
|
|
#if defined(CONFIG_RPTUN) && !defined(CONFIG_NSH_DISABLE_RPTUN)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("rptun", cmd_rptun, 3, 7,
|
2022-05-11 06:31:25 +02:00
|
|
|
"<start|stop|reset|panic|dump|ping> <path|all>"
|
2023-06-09 03:34:52 +02:00
|
|
|
" [value|times length ack sleep]"),
|
2019-11-03 16:36:49 +01:00
|
|
|
#endif
|
|
|
|
|
2017-04-06 02:25:59 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_SET
|
2018-10-02 19:54:18 +02:00
|
|
|
#ifdef CONFIG_NSH_VARS
|
|
|
|
# if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("set", cmd_set,
|
|
|
|
1, 4, "[{+|-}{e|x|xe|ex}] [<name> <value>]"),
|
2018-10-02 19:54:18 +02:00
|
|
|
# elif !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_NSH_DISABLESCRIPT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("set", cmd_set, 1, 3, "[<name> <value>]"),
|
2018-10-02 19:54:18 +02:00
|
|
|
# elif defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("set", cmd_set, 1, 2, "[{+|-}{e|x|xe|ex}]"),
|
2018-10-02 19:54:18 +02:00
|
|
|
# endif
|
|
|
|
#else
|
2017-04-06 02:25:59 +02:00
|
|
|
# if !defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("set", cmd_set,
|
|
|
|
2, 4, "[{+|-}{e|x|xe|ex}] [<name> <value>]"),
|
2017-04-06 02:25:59 +02:00
|
|
|
# elif !defined(CONFIG_DISABLE_ENVIRON) && defined(CONFIG_NSH_DISABLESCRIPT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("set", cmd_set, 3, 3, "<name> <value>"),
|
2017-04-06 02:25:59 +02:00
|
|
|
# elif defined(CONFIG_DISABLE_ENVIRON) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("set", cmd_set, 2, 2, "{+|-}{e|x|xe|ex}"),
|
2017-04-06 02:25:59 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
2018-10-02 19:54:18 +02:00
|
|
|
#endif /* CONFIG_NSH_DISABLE_SET */
|
2014-01-10 20:50:36 +01:00
|
|
|
|
2015-07-04 19:11:16 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_SHUTDOWN
|
|
|
|
#if defined(CONFIG_BOARDCTL_POWEROFF) && defined(CONFIG_BOARDCTL_RESET)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("shutdown", cmd_shutdown, 1, 2, "[--reboot]"),
|
2015-07-04 19:11:16 +02:00
|
|
|
#elif defined(CONFIG_BOARDCTL_POWEROFF)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("shutdown", cmd_shutdown, 1, 1, NULL),
|
2015-07-04 19:11:16 +02:00
|
|
|
#elif defined(CONFIG_BOARDCTL_RESET)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("shutdown", cmd_shutdown, 2, 2, "--reboot"),
|
2015-07-04 19:11:16 +02:00
|
|
|
#endif
|
2015-07-04 16:20:19 +02:00
|
|
|
#endif
|
2014-01-10 20:50:36 +01:00
|
|
|
|
2019-04-29 22:53:38 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_SLEEP
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("sleep", cmd_sleep, 2, 2, "<sec>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2023-02-21 23:08:13 +01:00
|
|
|
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("source", cmd_source, 2, 2, "<script-path>"),
|
2020-04-18 15:57:26 +02:00
|
|
|
#endif
|
|
|
|
|
2023-04-04 13:59:45 +02:00
|
|
|
#if defined(CONFIG_BOARDCTL_SWITCH_BOOT) && !defined(CONFIG_NSH_DISABLE_SWITCHBOOT)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("swtichboot", cmd_switchboot, 2, 2, "<image path>"),
|
2023-04-04 13:59:45 +02:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("test", cmd_test,
|
|
|
|
3, CONFIG_NSH_MAXARGUMENTS, "<expression>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2015-12-31 16:16:38 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_TIME
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("time", cmd_time, 2, 2, "\"<command>\""),
|
2015-12-31 16:16:38 +01:00
|
|
|
#endif
|
|
|
|
|
2022-09-13 14:05:50 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_TIMEDATECTL
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("timedatectl", cmd_timedatectl, 1, 3, "[set-timezone TZ]"),
|
2022-09-13 14:05:50 +02:00
|
|
|
#endif
|
|
|
|
|
2014-01-17 20:24:44 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("true", cmd_true, 1, 1, NULL),
|
2014-01-17 20:24:44 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_TRUNCATE
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("truncate", cmd_truncate, 4, 4, "-s <length> <file-path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2018-01-04 19:52:17 +01:00
|
|
|
#endif
|
|
|
|
|
2015-07-04 23:13:11 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_UNAME
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifdef CONFIG_NET
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("uname", cmd_uname, 1, 7, "[-a | -imnoprsv]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# else
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("uname", cmd_uname, 1, 7, "[-a | -imoprsv]"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2015-07-04 23:13:11 +02:00
|
|
|
#endif
|
|
|
|
|
2020-03-21 18:25:56 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT)
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_UMOUNT
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("umount", cmd_umount, 2, 2, "<dir-path>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2018-10-01 21:30:25 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_UNSET
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("unset", cmd_unset, 2, 2, "<name>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
apps/nshlib: add uptime command support
run uptime command on sim:
nsh>
nsh>
nsh> uptime
19:35:01 up 1:40, load average: 0.00, 0.00, 0.00
nsh>
nsh>
nsh> uptime -s
2022-09-16 17:54:26
nsh>
nsh>
nsh> uptime -p
up 1 hour, 40 minutes
nsh>
nsh>
nsh> uptime -h
Usage:
uptime [options]
Options:
-p, show uptime in pretty format
-h, display this help and exit
-s, system up since
nsh>
nsh>
nsh> uptime -abc
uptime: invalid option -- -abc
Usage:
uptime [options]
Options:
-p, show uptime in pretty format
-h, display this help and exit
-s, system up since
nsh>
nsh>
nsh> date
Fri, Sep 16 19:35:18 2022
nsh>
nsh>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2022-09-12 09:43:36 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_UPTIME
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("uptime", cmd_uptime, 1, 2, "[-sph]"),
|
apps/nshlib: add uptime command support
run uptime command on sim:
nsh>
nsh>
nsh> uptime
19:35:01 up 1:40, load average: 0.00, 0.00, 0.00
nsh>
nsh>
nsh> uptime -s
2022-09-16 17:54:26
nsh>
nsh>
nsh> uptime -p
up 1 hour, 40 minutes
nsh>
nsh>
nsh> uptime -h
Usage:
uptime [options]
Options:
-p, show uptime in pretty format
-h, display this help and exit
-s, system up since
nsh>
nsh>
nsh> uptime -abc
uptime: invalid option -- -abc
Usage:
uptime [options]
Options:
-p, show uptime in pretty format
-h, display this help and exit
-s, system up since
nsh>
nsh>
nsh> date
Fri, Sep 16 19:35:18 2022
nsh>
nsh>
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2022-09-12 09:43:36 +02:00
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE)
|
|
|
|
# ifndef CONFIG_NSH_DISABLE_URLDECODE
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("urldecode", cmd_urldecode, 2, 3, "[-f] <string or filepath>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
# endif
|
|
|
|
# ifndef CONFIG_NSH_DISABLE_URLENCODE
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("urlencode", cmd_urlencode, 2, 3, "[-f] <string or filepath>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2020-03-21 18:25:56 +01:00
|
|
|
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && \
|
|
|
|
defined(CONFIG_NSH_LOGIN_PASSWD) && \
|
2016-01-20 20:05:25 +01:00
|
|
|
!defined(CONFIG_FSUTILS_PASSWD_READONLY)
|
2016-01-20 16:37:25 +01:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_USERADD
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("useradd", cmd_useradd, 3, 3, "<username> <password>"),
|
2016-01-20 16:37:25 +01:00
|
|
|
# endif
|
|
|
|
# ifndef CONFIG_NSH_DISABLE_USERDEL
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("userdel", cmd_userdel, 2, 2, "<username>"),
|
2016-01-20 16:37:25 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2019-04-29 22:53:38 +02:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_USLEEP
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("usleep", cmd_usleep, 2, 2, "<usec>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
2019-02-11 20:10:10 +01:00
|
|
|
#ifdef CONFIG_NET_TCP
|
2023-05-21 10:37:31 +02:00
|
|
|
# ifndef CONFIG_NSH_DISABLE_WGET
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("wget", cmd_wget, 2, 4, "[-o <local-path>] <url>"),
|
2023-05-21 10:37:31 +02:00
|
|
|
# endif
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_XD
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP("xd", cmd_xd, 3, 3, "<hex-address> <byte-count>"),
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
2023-06-09 03:34:52 +02:00
|
|
|
CMD_MAP(NULL, NULL, 1, 1, NULL)
|
2014-01-10 20:50:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: help_cmdlist
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
|
|
|
static inline void help_cmdlist(FAR struct nsh_vtbl_s *vtbl)
|
|
|
|
{
|
2019-01-11 15:59:36 +01:00
|
|
|
unsigned int colwidth;
|
|
|
|
unsigned int cmdwidth;
|
2019-01-11 16:21:59 +01:00
|
|
|
unsigned int cmdsperline;
|
|
|
|
unsigned int ncmdrows;
|
2014-01-14 20:30:22 +01:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int j;
|
|
|
|
unsigned int k;
|
2023-03-02 10:38:46 +01:00
|
|
|
unsigned int offset;
|
2023-03-05 02:07:36 +01:00
|
|
|
|
|
|
|
/* Extra 5 bytes for tab before newline and '\0' */
|
|
|
|
|
|
|
|
char line[HELP_LINELEN + HELP_TABSIZE + 1];
|
2014-01-10 20:50:36 +01:00
|
|
|
|
2019-01-11 15:59:36 +01:00
|
|
|
/* Pick an optimal column width */
|
|
|
|
|
|
|
|
for (k = 0, colwidth = 0; k < NUM_CMDS; k++)
|
|
|
|
{
|
|
|
|
cmdwidth = strlen(g_cmdmap[k].cmd);
|
|
|
|
if (cmdwidth > colwidth)
|
|
|
|
{
|
|
|
|
colwidth = cmdwidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
colwidth += 2;
|
|
|
|
|
2019-01-11 16:21:59 +01:00
|
|
|
/* Determine the number of commands to put on one line */
|
|
|
|
|
|
|
|
if (colwidth > HELP_LINELEN)
|
|
|
|
{
|
|
|
|
cmdsperline = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cmdsperline = HELP_LINELEN / colwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the total number of lines to output */
|
|
|
|
|
|
|
|
ncmdrows = (NUM_CMDS + (cmdsperline - 1)) / cmdsperline;
|
|
|
|
|
|
|
|
/* Print the command name in 'ncmdrows' rows with 'cmdsperline' commands
|
2014-01-10 20:50:36 +01:00
|
|
|
* on each line.
|
|
|
|
*/
|
|
|
|
|
2019-01-11 16:21:59 +01:00
|
|
|
for (i = 0; i < ncmdrows; i++)
|
2014-01-10 20:50:36 +01:00
|
|
|
{
|
2023-03-02 10:38:46 +01:00
|
|
|
/* Tab before a new line */
|
|
|
|
|
2023-03-05 02:07:36 +01:00
|
|
|
offset = HELP_TABSIZE;
|
2023-03-02 10:38:46 +01:00
|
|
|
memset(line, ' ', offset);
|
|
|
|
|
2019-01-11 14:39:23 +01:00
|
|
|
for (j = 0, k = i;
|
2019-01-11 16:21:59 +01:00
|
|
|
j < cmdsperline && k < NUM_CMDS;
|
|
|
|
j++, k += ncmdrows)
|
2014-01-10 20:50:36 +01:00
|
|
|
{
|
2023-03-02 10:38:46 +01:00
|
|
|
/* Copy the cmd name to line buffer */
|
|
|
|
|
|
|
|
offset += strlcpy(line + offset, g_cmdmap[k].cmd,
|
|
|
|
sizeof(line) - offset);
|
|
|
|
|
|
|
|
/* Add space between commands */
|
2019-01-11 15:59:36 +01:00
|
|
|
|
|
|
|
for (cmdwidth = strlen(g_cmdmap[k].cmd);
|
|
|
|
cmdwidth < colwidth;
|
|
|
|
cmdwidth++)
|
|
|
|
{
|
2023-03-02 10:38:46 +01:00
|
|
|
line[offset++] = ' ';
|
2019-01-11 15:59:36 +01:00
|
|
|
}
|
2014-01-10 20:50:36 +01:00
|
|
|
}
|
|
|
|
|
2023-03-02 10:38:46 +01:00
|
|
|
line[offset++] = '\n';
|
|
|
|
nsh_write(vtbl, line, offset);
|
2014-01-10 20:50:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: help_usage
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if !defined(CONFIG_NSH_DISABLE_HELP) && !defined(CONFIG_NSH_HELP_TERSE)
|
|
|
|
static inline void help_usage(FAR struct nsh_vtbl_s *vtbl)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, "NSH command forms:\n");
|
|
|
|
#ifndef CONFIG_NSH_DISABLEBG
|
2020-03-17 06:13:46 +01:00
|
|
|
nsh_output(vtbl, " [nice [-d <niceness>>]] <cmd> "
|
|
|
|
"[> <file>|>> <file>] [&]\n\n");
|
2014-01-10 20:50:36 +01:00
|
|
|
#else
|
2014-01-17 22:56:32 +01:00
|
|
|
nsh_output(vtbl, " <cmd> [> <file>|>> <file>]\n\n");
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
2014-01-18 16:39:16 +01:00
|
|
|
#ifndef CONFIG_NSH_DISABLE_ITEF
|
2014-01-10 20:50:36 +01:00
|
|
|
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\n");
|
2014-01-18 16:39:16 +01:00
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_LOOPS
|
2014-01-17 22:56:32 +01:00
|
|
|
nsh_output(vtbl, "OR\n");
|
|
|
|
nsh_output(vtbl, " while <cmd>\n");
|
|
|
|
nsh_output(vtbl, " do\n");
|
|
|
|
nsh_output(vtbl, " [sequence of <cmd>]\n");
|
|
|
|
nsh_output(vtbl, " done\n\n");
|
|
|
|
nsh_output(vtbl, "OR\n");
|
|
|
|
nsh_output(vtbl, " until <cmd>\n");
|
|
|
|
nsh_output(vtbl, " do\n");
|
|
|
|
nsh_output(vtbl, " [sequence of <cmd>]\n");
|
|
|
|
nsh_output(vtbl, " done\n\n");
|
2014-01-10 20:50:36 +01:00
|
|
|
#endif
|
2014-01-18 16:39:16 +01:00
|
|
|
#endif
|
2014-01-10 20:50:36 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: help_showcmd
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
|
|
|
static void help_showcmd(FAR struct nsh_vtbl_s *vtbl,
|
|
|
|
FAR const struct cmdmap_s *cmdmap)
|
|
|
|
{
|
|
|
|
if (cmdmap->usage)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, " %s %s\n", cmdmap->cmd, cmdmap->usage);
|
|
|
|
}
|
2020-02-27 18:39:16 +01:00
|
|
|
else
|
2014-01-10 20:50:36 +01:00
|
|
|
{
|
|
|
|
nsh_output(vtbl, " %s\n", cmdmap->cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: help_cmd
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
|
|
|
static int help_cmd(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd)
|
|
|
|
{
|
|
|
|
FAR const struct cmdmap_s *cmdmap;
|
|
|
|
|
|
|
|
/* Find the command in the command table */
|
|
|
|
|
|
|
|
for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++)
|
|
|
|
{
|
|
|
|
/* Is this the one we are looking for? */
|
|
|
|
|
|
|
|
if (strcmp(cmdmap->cmd, cmd) == 0)
|
|
|
|
{
|
|
|
|
/* Yes... show it */
|
|
|
|
|
|
|
|
nsh_output(vtbl, "%s usage:", cmd);
|
|
|
|
help_showcmd(vtbl, cmdmap);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdnotfound, cmd);
|
2014-01-10 20:50:36 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: help_allcmds
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if !defined(CONFIG_NSH_DISABLE_HELP) && !defined(CONFIG_NSH_HELP_TERSE)
|
|
|
|
static inline void help_allcmds(FAR struct nsh_vtbl_s *vtbl)
|
|
|
|
{
|
|
|
|
FAR const struct cmdmap_s *cmdmap;
|
|
|
|
|
|
|
|
/* Show all of the commands in the command table */
|
|
|
|
|
|
|
|
for (cmdmap = g_cmdmap; cmdmap->cmd; cmdmap++)
|
|
|
|
{
|
|
|
|
help_showcmd(vtbl, cmdmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: help_builtins
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
|
|
|
static inline void help_builtins(FAR struct nsh_vtbl_s *vtbl)
|
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(vtbl);
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
#ifdef CONFIG_NSH_BUILTIN_APPS
|
2020-02-21 03:32:23 +01:00
|
|
|
FAR const struct builtin_s *builtin;
|
2019-01-11 16:21:59 +01:00
|
|
|
unsigned int builtins_per_line;
|
|
|
|
unsigned int num_builtin_rows;
|
2020-02-21 03:32:23 +01:00
|
|
|
unsigned int builtin_width;
|
|
|
|
unsigned int num_builtins;
|
|
|
|
unsigned int column_width;
|
2019-01-11 14:35:04 +01:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int j;
|
|
|
|
unsigned int k;
|
2023-03-02 10:38:46 +01:00
|
|
|
unsigned int offset;
|
2023-03-08 13:56:16 +01:00
|
|
|
|
|
|
|
/* Extra 5 bytes for tab before newline and '\0' */
|
|
|
|
|
|
|
|
char line[HELP_LINELEN + HELP_TABSIZE + 1];
|
|
|
|
|
2023-03-02 10:38:46 +01:00
|
|
|
static const char *g_builtin_prompt = "\nBuiltin Apps:\n";
|
2019-01-11 14:35:04 +01:00
|
|
|
|
2019-01-11 15:59:36 +01:00
|
|
|
/* Count the number of built-in commands and get the optimal column width */
|
2019-01-11 14:35:04 +01:00
|
|
|
|
|
|
|
num_builtins = 0;
|
2019-01-11 16:21:59 +01:00
|
|
|
column_width = 0;
|
2019-01-11 15:59:36 +01:00
|
|
|
|
2020-02-21 03:32:23 +01:00
|
|
|
for (i = 0; (builtin = builtin_for_index(i)) != NULL; i++)
|
2019-01-11 14:35:04 +01:00
|
|
|
{
|
2020-02-21 03:32:23 +01:00
|
|
|
if (builtin->main == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-01-11 14:35:04 +01:00
|
|
|
num_builtins++;
|
2019-01-11 15:59:36 +01:00
|
|
|
|
2020-02-21 03:32:23 +01:00
|
|
|
builtin_width = strlen(builtin->name);
|
2019-01-11 16:21:59 +01:00
|
|
|
if (builtin_width > column_width)
|
2019-01-11 15:59:36 +01:00
|
|
|
{
|
2019-01-11 16:21:59 +01:00
|
|
|
column_width = builtin_width;
|
2019-01-11 15:59:36 +01:00
|
|
|
}
|
2019-01-11 14:35:04 +01:00
|
|
|
}
|
|
|
|
|
2020-02-21 03:32:23 +01:00
|
|
|
/* Skip the printing if no available built-in commands */
|
|
|
|
|
|
|
|
if (num_builtins == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-11 16:21:59 +01:00
|
|
|
column_width += 2;
|
2019-01-11 15:59:36 +01:00
|
|
|
|
2019-01-11 16:21:59 +01:00
|
|
|
/* Determine the number of commands to put on one line */
|
2019-01-11 14:35:04 +01:00
|
|
|
|
2019-01-11 16:21:59 +01:00
|
|
|
if (column_width > HELP_LINELEN)
|
|
|
|
{
|
|
|
|
builtins_per_line = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
builtins_per_line = HELP_LINELEN / column_width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the total number of lines to output */
|
|
|
|
|
|
|
|
num_builtin_rows = ((num_builtins + (builtins_per_line - 1)) /
|
|
|
|
builtins_per_line);
|
2014-01-10 20:50:36 +01:00
|
|
|
|
|
|
|
/* List the set of available built-in commands */
|
|
|
|
|
2023-03-02 10:38:46 +01:00
|
|
|
nsh_write(vtbl, g_builtin_prompt, strlen(g_builtin_prompt));
|
2019-01-11 14:35:04 +01:00
|
|
|
for (i = 0; i < num_builtin_rows; i++)
|
2014-01-10 20:50:36 +01:00
|
|
|
{
|
2023-03-02 10:38:46 +01:00
|
|
|
offset = 4;
|
|
|
|
memset(line, ' ', offset);
|
|
|
|
|
2019-01-11 14:35:04 +01:00
|
|
|
for (j = 0, k = i;
|
2020-02-21 03:32:23 +01:00
|
|
|
j < builtins_per_line &&
|
|
|
|
(builtin = builtin_for_index(k));
|
2019-01-11 14:35:04 +01:00
|
|
|
j++, k += num_builtin_rows)
|
|
|
|
{
|
2020-02-21 03:32:23 +01:00
|
|
|
if (builtin->main == NULL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-03-02 10:38:46 +01:00
|
|
|
offset += strlcpy(line + offset, builtin->name,
|
|
|
|
sizeof(line) - offset);
|
2019-01-11 15:59:36 +01:00
|
|
|
|
2020-02-21 03:32:23 +01:00
|
|
|
for (builtin_width = strlen(builtin->name);
|
2019-01-11 16:21:59 +01:00
|
|
|
builtin_width < column_width;
|
|
|
|
builtin_width++)
|
2019-01-11 15:59:36 +01:00
|
|
|
{
|
2023-03-02 10:38:46 +01:00
|
|
|
line[offset++] = ' ';
|
2019-01-11 15:59:36 +01:00
|
|
|
}
|
2019-01-11 14:35:04 +01:00
|
|
|
}
|
|
|
|
|
2023-03-02 10:38:46 +01:00
|
|
|
line[offset++] = '\n';
|
|
|
|
nsh_write(vtbl, line, offset);
|
2014-01-10 20:50:36 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_help
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_HELP
|
2022-09-22 05:38:12 +02:00
|
|
|
static int cmd_help(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2014-01-10 20:50:36 +01:00
|
|
|
{
|
|
|
|
FAR const char *cmd = NULL;
|
|
|
|
#ifndef CONFIG_NSH_HELP_TERSE
|
|
|
|
bool verbose = false;
|
|
|
|
int i;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The command may be followed by a verbose option */
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_HELP_TERSE
|
|
|
|
i = 1;
|
|
|
|
if (argc > i)
|
|
|
|
{
|
|
|
|
if (strcmp(argv[i], "-v") == 0)
|
|
|
|
{
|
|
|
|
verbose = true;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The command line may end with a command name */
|
|
|
|
|
|
|
|
if (argc > i)
|
|
|
|
{
|
|
|
|
cmd = argv[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show the generic usage if verbose is requested */
|
|
|
|
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
help_usage(vtbl);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (argc > 1)
|
|
|
|
{
|
|
|
|
cmd = argv[1];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Are we showing help on a single command? */
|
|
|
|
|
|
|
|
if (cmd)
|
|
|
|
{
|
|
|
|
/* Yes.. show the single command */
|
|
|
|
|
|
|
|
help_cmd(vtbl, cmd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-27 18:39:16 +01:00
|
|
|
/* In verbose mode, show detailed help for all commands */
|
2014-01-10 20:50:36 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_HELP_TERSE
|
|
|
|
if (verbose)
|
|
|
|
{
|
|
|
|
nsh_output(vtbl, "Where <cmd> is one of:\n");
|
|
|
|
help_allcmds(vtbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Otherwise, just show the list of command names */
|
|
|
|
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
help_cmd(vtbl, "help");
|
|
|
|
nsh_output(vtbl, "\n");
|
|
|
|
help_cmdlist(vtbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* And show the list of built-in applications */
|
|
|
|
|
|
|
|
help_builtins(vtbl);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_unrecognized
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-01-11 14:39:23 +01:00
|
|
|
static int cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, int argc,
|
2022-09-22 05:38:12 +02:00
|
|
|
FAR char **argv)
|
2014-01-10 20:50:36 +01:00
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(argc);
|
|
|
|
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtcmdnotfound, argv[0]);
|
2014-01-10 20:50:36 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2014-01-17 20:24:44 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_true
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
2022-09-22 05:38:12 +02:00
|
|
|
static int cmd_true(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2014-01-17 20:24:44 +01:00
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(vtbl);
|
|
|
|
UNUSED(argc);
|
|
|
|
UNUSED(argv);
|
|
|
|
|
2014-01-17 20:24:44 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_false
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLESCRIPT
|
2022-09-22 05:38:12 +02:00
|
|
|
static int cmd_false(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2014-01-17 20:24:44 +01:00
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(vtbl);
|
|
|
|
UNUSED(argc);
|
|
|
|
UNUSED(argv);
|
|
|
|
|
2014-01-17 20:24:44 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: cmd_exit
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NSH_DISABLE_EXIT
|
2022-09-22 05:38:12 +02:00
|
|
|
static int cmd_exit(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
|
2014-01-10 20:50:36 +01:00
|
|
|
{
|
2022-08-22 15:17:00 +02:00
|
|
|
UNUSED(argc);
|
|
|
|
UNUSED(argv);
|
|
|
|
|
2014-01-10 20:50:36 +01:00
|
|
|
nsh_exit(vtbl, 0);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_command
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Execute the command in argv[0]
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-02-23 05:51:44 +01:00
|
|
|
* -1 (ERROR) if the command was unsuccessful
|
2014-01-10 20:50:36 +01:00
|
|
|
* 0 (OK) if the command was successful
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-09-22 05:38:12 +02:00
|
|
|
int nsh_command(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char *argv[])
|
2014-01-10 20:50:36 +01:00
|
|
|
{
|
|
|
|
const struct cmdmap_s *cmdmap;
|
|
|
|
const char *cmd;
|
2015-11-28 15:29:27 +01:00
|
|
|
nsh_cmd_t handler = cmd_unrecognized;
|
2014-01-10 20:50:36 +01:00
|
|
|
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 CONFIG_NSH_MAXARGUMENTS)
|
|
|
|
* 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 */
|
|
|
|
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmtargrequired, cmd);
|
2014-01-10 20:50:36 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
else if (argc > cmdmap->maxargs)
|
|
|
|
{
|
|
|
|
/* More than the maximum number were provided */
|
|
|
|
|
2018-12-09 01:53:54 +01:00
|
|
|
nsh_error(vtbl, g_fmttoomanyargs, cmd);
|
2014-01-10 20:50:36 +01:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* A valid number of arguments were provided (this does
|
|
|
|
* not mean they are right).
|
|
|
|
*/
|
|
|
|
|
|
|
|
handler = cmdmap->handler;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-27 18:39:16 +01:00
|
|
|
ret = handler(vtbl, argc, argv);
|
|
|
|
return ret;
|
2014-01-10 20:50:36 +01:00
|
|
|
}
|
2015-07-30 20:11:58 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_extmatch_count
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This support function is used to provide support for realine tab-
|
|
|
|
* completion logic nsh_extmatch_count() counts the number of matching
|
|
|
|
* nsh command names
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* name - A point to the name containing the name to be matched.
|
|
|
|
* matches - A table is size CONFIG_READLINE_MAX_EXTCMDS that can
|
|
|
|
* be used to remember matching name indices.
|
2020-02-22 19:52:12 +01:00
|
|
|
* namelen - The length of the name to match
|
2015-07-30 20:11:58 +02:00
|
|
|
*
|
|
|
|
* Returned Values:
|
|
|
|
* The number commands that match to the first namelen characters.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION) && \
|
|
|
|
defined(CONFIG_READLINE_HAVE_EXTMATCH)
|
|
|
|
int nsh_extmatch_count(FAR char *name, FAR int *matches, int namelen)
|
|
|
|
{
|
|
|
|
int nr_matches = 0;
|
|
|
|
int i;
|
|
|
|
|
2022-08-22 15:17:00 +02:00
|
|
|
for (i = 0; i < (int)NUM_CMDS; i++)
|
2015-07-30 20:11:58 +02:00
|
|
|
{
|
|
|
|
if (strncmp(name, g_cmdmap[i].cmd, namelen) == 0)
|
|
|
|
{
|
|
|
|
matches[nr_matches] = i;
|
|
|
|
nr_matches++;
|
|
|
|
|
|
|
|
if (nr_matches >= CONFIG_READLINE_MAX_EXTCMDS)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nr_matches;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_extmatch_getname
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This support function is used to provide support for realine tab-
|
|
|
|
* completion logic nsh_extmatch_getname() will return the full command
|
|
|
|
* string from an index that was previously saved by nsh_exmatch_count().
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* index - The index of the command name to be returned.
|
|
|
|
*
|
|
|
|
* Returned Values:
|
|
|
|
* The numb
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION) && \
|
|
|
|
defined(CONFIG_READLINE_HAVE_EXTMATCH)
|
|
|
|
FAR const char *nsh_extmatch_getname(int index)
|
|
|
|
{
|
2022-08-29 17:58:36 +02:00
|
|
|
DEBUGASSERT(index > 0 && index <= (int)NUM_CMDS);
|
2015-07-30 20:11:58 +02:00
|
|
|
return g_cmdmap[index].cmd;
|
|
|
|
}
|
|
|
|
#endif
|