From patchwork Sun Jan 18 20:42:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1595 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768769016; bh=WRpPHrFCecNWMk4E7gpPBO55Fx7oe9kT01Ou8mzFTkM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=f4ULT2tIf8ZuBWgMzwKZC6LnKDBMH0oTqe14vAFiCFdqmLyqZYwI2+E5CVsOmUQn0 mJpTpu70J42gdP5g2dNN0xJaozhI40kJ7DUzPjkDEkH3WXvW9ZX5k5MyHqQ6GfXw6s Xhg9I+aqTxLT67U62awuGJwLNL2wUYnyA8SoWCWYAIPTTHJxBVPjJheVC+cTZEovgW DyicZunZ2XOWyQsLFgkpFSqB4aMEUUkRBhM2dLXQY90kPa00GUHzAqlla/ffatHvut ltCydaSwNeYUkcRZuJ1NP0qETsUh89CctmhyflYoYkCDXJZapNXsg832f0lCmPxOlb wUb7nko+y43Dw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 746C26948C for ; Sun, 18 Jan 2026 13:43:36 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id aF1EgA6wuWqg for ; Sun, 18 Jan 2026 13:43:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768769016; bh=WRpPHrFCecNWMk4E7gpPBO55Fx7oe9kT01Ou8mzFTkM=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=f4ULT2tIf8ZuBWgMzwKZC6LnKDBMH0oTqe14vAFiCFdqmLyqZYwI2+E5CVsOmUQn0 mJpTpu70J42gdP5g2dNN0xJaozhI40kJ7DUzPjkDEkH3WXvW9ZX5k5MyHqQ6GfXw6s Xhg9I+aqTxLT67U62awuGJwLNL2wUYnyA8SoWCWYAIPTTHJxBVPjJheVC+cTZEovgW DyicZunZ2XOWyQsLFgkpFSqB4aMEUUkRBhM2dLXQY90kPa00GUHzAqlla/ffatHvut ltCydaSwNeYUkcRZuJ1NP0qETsUh89CctmhyflYoYkCDXJZapNXsg832f0lCmPxOlb wUb7nko+y43Dw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 61F8A69491 for ; Sun, 18 Jan 2026 13:43:36 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768769014; bh=jCUmWIUkxz3l4VG+xGJL5pUZssxMFt0jTGquj8wuQ9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J0YdYLKreUwUJwQnaqQHNluVZECZ068Fo+1ftIQH72blgXlxj3L45tOvyZfo3FeJd 0gRJyHKKjosqRUNbU8zKXYDZa/kipawd3CJRJATROC6X4UOg7lvjRHpGNYhcEPxV1r D7mozLKwAaJ84Qimi27u5WsTQl1l76FRiynEsRnHZnag6xFughW8LDpnX+YoVzq90j dZp5CIcZwaUoZHkopaX/xge1LNgpGnOdhnIoiBgGrMuAtphI/ZCVHb+WtoOuyXZ9p/ yj1hE35xfxvbKsK4Qwa+Sd7XG1qs22UfOhHPpR8fXEtNM2MMfalTd3Kcnz7xjH9ARo T5eirI77XJNCg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9612A6948C; Sun, 18 Jan 2026 13:43:34 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id UjpZhpMSIYoC; Sun, 18 Jan 2026 13:43:34 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768769010; bh=1hv9iGktruAalLkRjR9/B6mJsG7nnhPEaQrBqwVSOsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mIe13DodhFVQ2LeD/4HrSEIsN2plpEdAGWtED1mjS0PUr5ayIyoR49CfvTZnfKTTV 4MAO5XzYnzGIz9JZilZ6dsNI75MvEAhb/eZndeFUac4qT2OgSsVDcpUlWXuvgGbi2n yljngmBsqij9l5XY0g/Zey9Z88sTq4bXrY1RaL09igCuSTd84d/Mn8g9M8i9htGo+u 8R/oY9Jn4+MIFkT12Ksb5aliq0YUSrn5KK3izulbDXWVhGqXM8lvrWIq3FJ2vYrh4o ZUHM+q+6Vr9q7TUym4/SFGsIMPjsU5stFwipR6xSwvd9hVZ6Wwq2QG52VACJMdobSd 74mOVAvRUU89g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4CBE16946A; Sun, 18 Jan 2026 13:43:30 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sun, 18 Jan 2026 13:42:43 -0700 Message-ID: <20260118204303.1982533-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260118204303.1982533-1-sjg@u-boot.org> References: <20260118204303.1982533-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GA52Q7UPHDMYVJUSOVAFKZB5OBWPKBWW X-Message-ID-Hash: GA52Q7UPHDMYVJUSOVAFKZB5OBWPKBWW X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 04/16] cli: Add cls_putnstr() for string output with callback List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Add cls_putnstr() to output a string of specified length using the putch callback. Update all putnstr() calls to use cls_putnstr() so that string output is also redirected when a callback is set. Remove the now-unused putnstr macro. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- common/cli_readline.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/common/cli_readline.c b/common/cli_readline.c index 2e41aa5afef..4eb34d7cf7c 100644 --- a/common/cli_readline.c +++ b/common/cli_readline.c @@ -64,8 +64,6 @@ static char *delete_char (char *buffer, char *p, int *colp, int *np, int plen) * Author: Janghoon Lyu */ -#define putnstr(str, n) printf("%.*s", (int)n, str) - #define CTL_BACKSPACE ('\b') #define DEL ((char)255) #define DEL7 ((char)127) @@ -87,6 +85,12 @@ static void cls_putch(struct cli_line_state *cls, int ch) putc(ch); } +static void cls_putnstr(struct cli_line_state *cls, const char *str, size_t n) +{ + while (n-- > 0) + cls_putch(cls, *str++); +} + #define getcmd_cbeep(cls) cls_putch(cls, '\a') #ifdef CONFIG_XPL_BUILD @@ -245,7 +249,7 @@ static void cread_erase_to_eol(struct cli_line_state *cls) #define REFRESH_TO_EOL() { \ if (cls->num < cls->eol_num) { \ uint wlen = cls->eol_num - cls->num; \ - putnstr(buf + cls->num, wlen); \ + cls_putnstr(cls, buf + cls->num, wlen); \ cls->num = cls->eol_num; \ } \ } @@ -270,7 +274,7 @@ static void cread_add_char(struct cli_line_state *cls, char ichar, int insert, memmove(&buf[*num+1], &buf[*num], wlen-1); buf[*num] = ichar; - putnstr(buf + *num, wlen); + cls_putnstr(cls, buf + *num, wlen); (*num)++; while (--wlen) cls_putch(cls, CTL_BACKSPACE); @@ -278,7 +282,7 @@ static void cread_add_char(struct cli_line_state *cls, char ichar, int insert, /* echo the character */ wlen = 1; buf[*num] = ichar; - putnstr(buf + *num, wlen); + cls_putnstr(cls, buf + *num, wlen); (*num)++; } } @@ -334,7 +338,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar) if (wlen) { memmove(&buf[cls->num], &buf[cls->num + 1], wlen); - putnstr(buf + cls->num, wlen); + cls_putnstr(cls, buf + cls->num, wlen); } cls_putch(cls, ' '); @@ -370,7 +374,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar) cls->eol_num - base + 1); cls->num = base; cls_putchars(cls, wlen, CTL_BACKSPACE); - puts(buf + base); + cls_putnstr(cls, buf + base, cls->eol_num - base); cls_putchars(cls, wlen, ' '); cls_putchars(cls, wlen + cls->eol_num - cls->num, CTL_BACKSPACE); @@ -391,7 +395,7 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar) cls->num--; memmove(&buf[cls->num], &buf[cls->num + 1], wlen); cls_putch(cls, CTL_BACKSPACE); - putnstr(buf + cls->num, wlen); + cls_putnstr(cls, buf + cls->num, wlen); cls_putch(cls, ' '); do { cls_putch(cls, CTL_BACKSPACE);