diff mbox series

[03/36] cli: Drop some #ifdefs in cli_readline

Message ID 20230919180918.2904313-4-sjg@chromium.org
State Superseded
Delegated to: Tom Rini
Headers show
Series expo: Support editing lines of text | expand

Commit Message

Simon Glass Sept. 19, 2023, 6:08 p.m. UTC
Add a few static inlines to avoid the need for #ifdefs in
cli_readline_into_buffer()

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/cli_readline.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/common/cli_readline.c b/common/cli_readline.c
index f3ba76a62ec..61f9ba99068 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -423,6 +423,18 @@  static int cread_line(const char *const prompt, char *buf, unsigned int *len,
 	return 0;
 }
 
+#else /* !CONFIG_CMDLINE_EDITING */
+
+static inline void hist_init(void)
+{
+}
+
+static int cread_line(const char *const prompt, char *buf, unsigned int *len,
+		      int timeout)
+{
+	return 0;
+}
+
 #endif /* CONFIG_CMDLINE_EDITING */
 
 /****************************************************************************/
@@ -552,8 +564,7 @@  int cli_readline_into_buffer(const char *const prompt, char *buffer,
 			     int timeout)
 {
 	char *p = buffer;
-#ifdef CONFIG_CMDLINE_EDITING
-	unsigned int len = CONFIG_SYS_CBSIZE;
+	uint len = CONFIG_SYS_CBSIZE;
 	int rc;
 	static int initted;
 
@@ -563,7 +574,7 @@  int cli_readline_into_buffer(const char *const prompt, char *buffer,
 	 * Revert to non-history version if still
 	 * running from flash.
 	 */
-	if (gd->flags & GD_FLG_RELOC) {
+	if (IS_ENABLED(CONFIG_CMDLINE_EDITING) && (gd->flags & GD_FLG_RELOC)) {
 		if (!initted) {
 			hist_init();
 			initted = 1;
@@ -576,9 +587,6 @@  int cli_readline_into_buffer(const char *const prompt, char *buffer,
 		return rc < 0 ? rc : len;
 
 	} else {
-#endif	/* CONFIG_CMDLINE_EDITING */
 		return cread_line_simple(prompt, p);
-#ifdef CONFIG_CMDLINE_EDITING
 	}
-#endif
 }