From 1399d23cdf82d95692bcbec53d8dc97a02bc924b Mon Sep 17 00:00:00 2001 From: Stian Skjelstad Date: Fri, 23 Aug 2024 15:20:43 +0200 Subject: [PATCH] Add EditStringASCII(), that is relevant for editing URLs --- boot/console.c | 1 + stuff/poutput.h | 1 + stuff/utf-8.c | 18 +++++++++++++++++- stuff/utf-8.h | 4 ++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/boot/console.c b/boot/console.c index 8d405126..9074f650 100644 --- a/boot/console.c +++ b/boot/console.c @@ -781,6 +781,7 @@ struct console_t Console = try_open_png, EditStringUTF8z, EditStringUTF8, + EditStringASCII, 80, /* TextHeight */ 25, /* TextWidth */ 0, /* TextGUIOverlay */ diff --git a/stuff/poutput.h b/stuff/poutput.h index 281c4c11..a5202e21 100644 --- a/stuff/poutput.h +++ b/stuff/poutput.h @@ -112,6 +112,7 @@ struct console_t int (*EditStringUTF8z)(unsigned int y, unsigned int x, unsigned int w, int l, char *s); /* zero-terminated, forever long dynamic buffer */ int (*EditStringUTF8)(unsigned int y, unsigned int x, unsigned int w, char **s); + int (*EditStringASCII)(unsigned int y, unsigned int x, unsigned int w, char **s); /* console resolution */ unsigned int TextHeight; /* range 25..inifinity */ diff --git a/stuff/utf-8.c b/stuff/utf-8.c index ce600c65..48272bc8 100644 --- a/stuff/utf-8.c +++ b/stuff/utf-8.c @@ -463,7 +463,7 @@ int EditStringUTF8z (unsigned int y, unsigned int x, unsigned int w, int l, char } -int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s) +static int _EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s, int ASCIIonly) { /* problems: each UTF-8 noun might be 1-4 bytes per character <- use utf8_decode in a loop to cycle positions @@ -592,6 +592,13 @@ int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s) continue; } input_buffer_fill = 0; + if (ASCIIonly) + { + if (codepoint > 127) + { + continue; + } + } if ( insmode || ( curpos == workstring_length ) ) /* insert / append */ { @@ -702,6 +709,15 @@ int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s) return 1; } +int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s) +{ + return _EditStringUTF8 (y, x, w, s, 0); +} + +int EditStringASCII(unsigned int y, unsigned int x, unsigned int w, char **s) +{ + return _EditStringUTF8 (y, x, w, s, 1); +} #if 0 diff --git a/stuff/utf-8.h b/stuff/utf-8.h index d15960a8..b6d5764b 100644 --- a/stuff/utf-8.h +++ b/stuff/utf-8.h @@ -25,4 +25,8 @@ int EditStringUTF8z(unsigned int y, unsigned int x, unsigned int w, int l, char /* zero-terminated, forever long dynamic buffer */ int EditStringUTF8(unsigned int y, unsigned int x, unsigned int w, char **s); +/* zero-terminated, forever long dynamic buffer */ +int EditStringASCII(unsigned int y, unsigned int x, unsigned int w, char **s); + + #endif