public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [v4 10/24] cli_simple: Rework this support slightly
Date: Thu, 19 Oct 2023 11:00:51 -0400	[thread overview]
Message-ID: <20231019150105.714407-10-trini@konsulko.com> (raw)
In-Reply-To: <20231019150105.714407-1-trini@konsulko.com>

The interactive portion of our non-HUSH 'simple' parser is guarded by
CONFIG_CMDLINE already.  Much of the code behind this simple parser is
also used as "input" parser, such as from menu interfaces and so forth
and not strictly command line input.  To support this, always build the
assorted cli object files, but guard the interactive portions of
cli_simple.c with a CMDLINE check.

Signed-off-by: Tom Rini <trini@konsulko.com>
---
 common/Makefile     |  2 +-
 common/cli_simple.c | 77 +++++++++++++++++++++++----------------------
 2 files changed, 40 insertions(+), 39 deletions(-)

diff --git a/common/Makefile b/common/Makefile
index b711dc29b65e..1495436d5d45 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -8,6 +8,7 @@ ifndef CONFIG_SPL_BUILD
 obj-y += init/
 obj-y += main.o
 obj-y += exports.o
+obj-y += cli_getch.o cli_simple.o cli_readline.o
 obj-$(CONFIG_HUSH_PARSER) += cli_hush.o
 obj-$(CONFIG_AUTOBOOT) += autoboot.o
 obj-y += version.o
@@ -38,7 +39,6 @@ obj-$(CONFIG_SPLASH_SOURCE) += splash_source.o
 obj-$(CONFIG_MENU) += menu.o
 obj-$(CONFIG_UPDATE_COMMON) += update.o
 obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o
-obj-$(CONFIG_CMDLINE) += cli_getch.o cli_readline.o cli_simple.o
 
 endif # !CONFIG_SPL_BUILD
 
diff --git a/common/cli_simple.c b/common/cli_simple.c
index e80ba488a5eb..f89ba92d1b05 100644
--- a/common/cli_simple.c
+++ b/common/cli_simple.c
@@ -22,44 +22,6 @@
 #define debug_parser(fmt, args...)		\
 	debug_cond(DEBUG_PARSER, fmt, ##args)
 
-
-int cli_simple_parse_line(char *line, char *argv[])
-{
-	int nargs = 0;
-
-	debug_parser("%s: \"%s\"\n", __func__, line);
-	while (nargs < CONFIG_SYS_MAXARGS) {
-		/* skip any white space */
-		while (isblank(*line))
-			++line;
-
-		if (*line == '\0') {	/* end of line, no more args	*/
-			argv[nargs] = NULL;
-			debug_parser("%s: nargs=%d\n", __func__, nargs);
-			return nargs;
-		}
-
-		argv[nargs++] = line;	/* begin of argument string	*/
-
-		/* find end of string */
-		while (*line && !isblank(*line))
-			++line;
-
-		if (*line == '\0') {	/* end of line, no more args	*/
-			argv[nargs] = NULL;
-			debug_parser("parse_line: nargs=%d\n", nargs);
-			return nargs;
-		}
-
-		*line++ = '\0';		/* terminate current arg	 */
-	}
-
-	printf("** Too many args (max. %d) **\n", CONFIG_SYS_MAXARGS);
-
-	debug_parser("%s: nargs=%d\n", __func__, nargs);
-	return nargs;
-}
-
 int cli_simple_process_macros(const char *input, char *output, int max_size)
 {
 	char c, prev;
@@ -172,6 +134,44 @@ int cli_simple_process_macros(const char *input, char *output, int max_size)
 	return ret;
 }
 
+#ifdef CONFIG_CMDLINE
+int cli_simple_parse_line(char *line, char *argv[])
+{
+	int nargs = 0;
+
+	debug_parser("%s: \"%s\"\n", __func__, line);
+	while (nargs < CONFIG_SYS_MAXARGS) {
+		/* skip any white space */
+		while (isblank(*line))
+			++line;
+
+		if (*line == '\0') {	/* end of line, no more args	*/
+			argv[nargs] = NULL;
+			debug_parser("%s: nargs=%d\n", __func__, nargs);
+			return nargs;
+		}
+
+		argv[nargs++] = line;	/* begin of argument string	*/
+
+		/* find end of string */
+		while (*line && !isblank(*line))
+			++line;
+
+		if (*line == '\0') {	/* end of line, no more args	*/
+			argv[nargs] = NULL;
+			debug_parser("parse_line: nargs=%d\n", nargs);
+			return nargs;
+		}
+
+		*line++ = '\0';		/* terminate current arg	 */
+	}
+
+	printf("** Too many args (max. %d) **\n", CONFIG_SYS_MAXARGS);
+
+	debug_parser("%s: nargs=%d\n", __func__, nargs);
+	return nargs;
+}
+
  /*
  * WARNING:
  *
@@ -346,3 +346,4 @@ int cli_simple_run_command_list(char *cmd, int flag)
 
 	return rcode;
 }
+#endif
-- 
2.34.1


  parent reply	other threads:[~2023-10-19 15:02 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-19 15:00 [v4 01/24] buildman: Use oldconfig when adjusting the config Tom Rini
2023-10-19 15:00 ` [v4 02/24] virtio: Make VIRTIO_NET depend on NETDEVICES Tom Rini
2023-10-19 15:00 ` [v4 03/24] dfu: Make DFU_TFTP " Tom Rini
2023-10-19 15:00 ` [v4 04/24] version: Separate our version string from the version command Tom Rini
2023-10-19 15:00 ` [v4 05/24] qemu: Correct CMD_QFW dependencies in Kconfig Tom Rini
2023-10-19 15:00 ` [v4 06/24] Kconfig: Move CONFIG_SYS_[CP]BSIZE to common/Kconfig Tom Rini
2023-10-19 15:00 ` [v4 07/24] env: Move env_set() out of cmd/nvedit.c and in to env/common.c Tom Rini
2023-10-19 15:00 ` [v4 08/24] test: Make UNIT_TEST depend on CMDLINE Tom Rini
2023-10-19 15:00 ` [v4 09/24] video: Don't require the font command Tom Rini
2023-10-19 15:00 ` Tom Rini [this message]
2023-10-19 15:00 ` [v4 11/24] efi: Rearrange the Kconfig for CMD_BOOTEFI_BOOTMGR Tom Rini
2023-10-19 15:16   ` Heinrich Schuchardt
2023-10-19 15:19     ` Tom Rini
2023-10-19 15:24       ` Heinrich Schuchardt
2023-10-19 15:28         ` Tom Rini
2023-10-20 12:21       ` AKASHI Takahiro
2023-10-20 13:58         ` Tom Rini
2023-10-19 15:00 ` [v4 12/24] bootmeth: Make BOOTMETH_EFILOADER depend on CMD_BOOTEFI Tom Rini
2023-10-19 15:00 ` [v4 13/24] autoboot: Correct dependencies on CMDLINE Tom Rini
2023-10-19 15:00 ` [v4 14/24] boot: Make DISTRO_DEFAULTS select CMDLINE Tom Rini
2023-10-19 15:00 ` [v4 15/24] boot: Rework BOOT_DEFAULTS to allow for CMDLINE to be disabled Tom Rini
2023-10-19 15:00 ` [v4 16/24] boot: Move SYS_BOOTM_LEN to be by LEGACY_IMAGE_FORMAT Tom Rini
2023-10-19 15:00 ` [v4 17/24] bootmeth_cros: Require bootm.o and bootm_os.o Tom Rini
2023-10-19 15:00 ` [v4 18/24] bootmeth_script: Depend on CMDLINE Tom Rini
2023-10-19 15:01 ` [v4 19/24] boot: Make preboot and bootcmd require CMDLINE Tom Rini
2023-10-19 15:01 ` [v4 20/24] cmd: Make most commands depend on CMDLINE Tom Rini
2023-10-19 15:01 ` [v4 21/24] sandbox: Disable CONFIG_DISTRO_DEFAULTS Tom Rini
2023-10-19 15:01 ` [v4 22/24] sandbox: Avoid requiring CMDLINE Tom Rini
2023-10-19 15:01 ` [v4 23/24] sandbox: Add <asm/barrier.h> Tom Rini
2023-10-21  2:39   ` Sean Anderson
2023-10-19 15:01 ` [v4 24/24] clk_k210.c: Clean up how we handle nop Tom Rini
2023-10-20 21:53   ` [v4.1 1/2] sandbox: Add a test for disabling CONFIG_CMDLINE Tom Rini
2023-10-20 21:53     ` [v4.1 2/2] CI, pytest: Add a test for sandbox without LTO Tom Rini
2023-10-21 15:43       ` Simon Glass
2023-10-21 18:34         ` Tom Rini
2023-10-23  7:05           ` Simon Glass
2023-10-23 13:37             ` Tom Rini
2023-10-23 17:13               ` Simon Glass
2023-10-23 17:27                 ` Tom Rini
2023-10-24 18:02                   ` Simon Glass
2023-10-24 18:07                     ` Tom Rini
2023-10-24 21:39                       ` Simon Glass
2023-10-24 22:01                         ` Tom Rini
2023-10-21  2:39   ` [v4 24/24] clk_k210.c: Clean up how we handle nop Sean Anderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231019150105.714407-10-trini@konsulko.com \
    --to=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox