[PATCH v2 2/3] cmd: lcdputs: Escape special characters

qianfanguijin at 163.com qianfanguijin at 163.com
Thu Mar 31 12:03:01 CEST 2022


From: qianfan Zhao <qianfanguijin at 163.com>

Add support \\, \r, \n, \t and \b.

eg:
=> lcdputs "hello\nworld"

Signed-off-by: qianfan Zhao <qianfanguijin at 163.com>
---
 drivers/video/vidconsole-uclass.c | 34 +++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index f42db40d4c..d2554fd3f7 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -709,15 +709,45 @@ static int do_video_puts(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	struct udevice *dev;
 	const char *s;
+	char c;
 
 	if (argc != 2)
 		return CMD_RET_USAGE;
 
 	if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
 		return CMD_RET_FAILURE;
-	for (s = argv[1]; *s; s++)
-		vidconsole_put_char(dev, *s);
 
+	for (s = argv[1]; (c = *s); s++) {
+		if (c == '\\') {
+			s++;
+
+			switch (*s) {
+			case '\0':
+				goto sync;
+			case '\\':
+				c = '\\';
+				break;
+			case 'r':
+				c = '\r';
+				break;
+			case 'n':
+				c = '\n';
+				break;
+			case 't':
+				c = '\t';
+				break;
+			case 'b':
+				c = '\b';
+				break;
+			default:
+				continue;
+			}
+		}
+
+		vidconsole_put_char(dev, c);
+	}
+
+sync:
 	return video_sync(dev->parent, false);
 }
 
-- 
2.17.1



More information about the U-Boot mailing list