public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk] [PATCH] ShellPkg/edit: allow non-ASCII characters in edit
@ 2019-11-24 10:37 Heinrich Schuchardt
  2020-11-02 21:10 ` [edk2-devel] " Laszlo Ersek
  0 siblings, 1 reply; 6+ messages in thread
From: Heinrich Schuchardt @ 2019-11-24 10:37 UTC (permalink / raw)
  To: EDK II Development, Liming Gao; +Cc: michael.d.kinney, Heinrich Schuchardt

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2339

Currently it is not possible to add letters outside the range
U+0020 - U+007F to a file using the edit command.

In Unicode the following are control characters:

* U+0000—U+001F (C0 controls)
* U+007F (DEL)
* U+0080—U+009F (C1 controls).

For reference see:

* https://unicode.org/charts/PDF/U0000.pdf
* https://unicode.org/charts/PDF/U0080.pdf

So the characters we should exclude from the file buffer are:
U+0000 - U+001f, U+007f - U009F

Allow all other characters as input to the file buffer in Unicode mode.
Allow only ASCII characters as input in ASCII mode.

When saving a file in ASCII mode replace non-ASCII characters by a question
mark ('?').

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
Resent due to a typo in Limings email-address.
---
 .../Edit/FileBuffer.c                         | 21 +++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
index fd324cc4a8..12235e4e4b 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
@@ -1360,6 +1360,8 @@ GetNewLine (
 /**
   Change a Unicode string to an ASCII string.
 
+  Non-ASCII characters are replaced by '?'.
+
   @param[in] UStr     The Unicode string.
   @param[in] Length   The maximum size of AStr.
   @param[out] AStr    ASCII string to pass out.
@@ -1378,8 +1380,12 @@ UnicodeToAscii (
   //
   // just buffer copy, not character copy
   //
-  for (Index = 0; Index < Length; Index++) {
-    *AStr++ = (CHAR8) *UStr++;
+  for (Index = 0; Index < Length; Index++, UStr++) {
+    if (*UStr < 0x80) {
+      *AStr++ = (CHAR8) *UStr;
+    } else {
+      *AStr++ = '?';
+    }
   }
 
   return Index;
@@ -2154,9 +2160,16 @@ FileBufferDoCharInput (
 
   default:
     //
-    // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
+    // Do not add Unicode control characters to the file buffer:
+    //
+    // * U+0000-U+001f (C0 controls)
+    // * U+007f (DEL)
+    // * U+0080-U+009f (C1 controls)
+    //
+    // Do not add non-ASCII characters in ASCII mode.
     //
-    if (Char > 127 || Char < 32) {
+    if (Char < 0x20 || (Char >= 0x7f &&
+        (Char <= 0x9f || FileBuffer.FileType == FileTypeAscii))) {
       Status = StatusBarSetStatusString (L"Unknown Command");
     } else {
       Status = FileBufferAddChar (Char);
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [edk] [PATCH] ShellPkg/edit: allow non-ASCII characters in edit
@ 2020-11-02 23:11 Heinrich Schuchardt
  2020-11-03 23:42 ` Leif Lindholm
  2020-11-04 17:23 ` Laszlo Ersek
  0 siblings, 2 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2020-11-02 23:11 UTC (permalink / raw)
  To: Ray Ni, Zhichao Gao, Leif Lindholm, Ard Biesheuvel
  Cc: devel, Laszlo Ersek, Liming Gao, Heinrich Schuchardt

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2339

Currently it is not possible to add letters outside the range
U+0020 - U+007F to a file using the edit command.

In Unicode the following are control characters:

* U+0000—U+001F (C0 controls)
* U+007F (DEL)
* U+0080—U+009F (C1 controls).

For reference see:

* https://unicode.org/charts/PDF/U0000.pdf
* https://unicode.org/charts/PDF/U0080.pdf

So the characters we should exclude from the file buffer are:
U+0000 - U+001f, U+007f - U009F

Allow all other characters as input to the file buffer in Unicode mode.
Allow only ASCII characters as input in ASCII mode.

When saving a file in ASCII mode replace non-ASCII characters by a question
mark ('?').

For editing texts with double width characters (e.g. Japanese) further
adjustments will be needed.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
Resent.
Original message https://edk2.groups.io/g/devel/message/51205
---
 .../Edit/FileBuffer.c                         | 21 +++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
index 5659ec981054..3923b83670fa 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
@@ -1360,6 +1360,8 @@ GetNewLine (
 /**
   Change a Unicode string to an ASCII string.

+  Non-ASCII characters are replaced by '?'.
+
   @param[in] UStr     The Unicode string.
   @param[in] Length   The maximum size of AStr.
   @param[out] AStr    ASCII string to pass out.
@@ -1378,8 +1380,12 @@ UnicodeToAscii (
   //
   // just buffer copy, not character copy
   //
-  for (Index = 0; Index < Length; Index++) {
-    *AStr++ = (CHAR8) *UStr++;
+  for (Index = 0; Index < Length; Index++, UStr++) {
+    if (*UStr < 0x80) {
+      *AStr++ = (CHAR8) *UStr;
+    } else {
+      *AStr++ = '?';
+    }
   }

   return Index;
@@ -2154,9 +2160,16 @@ FileBufferDoCharInput (

   default:
     //
-    // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
+    // Do not add Unicode control characters to the file buffer:
     //
-    if (Char > 127 || Char < 32) {
+    // * U+0000-U+001f (C0 controls)
+    // * U+007f (DEL)
+    // * U+0080-U+009f (C1 controls)
+    //
+    // Do not add non-ASCII characters in ASCII mode.
+    //
+    if (Char < 0x20 || (Char >= 0x7f &&
+        (Char <= 0x9f || FileBuffer.FileType == FileTypeAscii))) {
       Status = StatusBarSetStatusString (L"Unknown Command");
     } else {
       Status = FileBufferAddChar (Char);
--
2.28.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [edk] [PATCH] ShellPkg/edit: allow non-ASCII characters in edit
@ 2019-11-24 10:15 Heinrich Schuchardt
  0 siblings, 0 replies; 6+ messages in thread
From: Heinrich Schuchardt @ 2019-11-24 10:15 UTC (permalink / raw)
  To: EDK II Development, liminig.gao; +Cc: michael.d.kinney, Heinrich Schuchardt

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2339

Currently it is not possible to add letters outside the range
U+0020 - U+007F to a file using the edit command.

In Unicode the following are control characters:

* U+0000—U+001F (C0 controls)
* U+007F (DEL)
* U+0080—U+009F (C1 controls).

For reference see:

* https://unicode.org/charts/PDF/U0000.pdf
* https://unicode.org/charts/PDF/U0080.pdf

So the characters we should exclude from the file buffer are:
U+0000 - U+001f, U+007f - U009F

Allow all other characters as input to the file buffer in Unicode mode.
Allow only ASCII characters as input in ASCII mode.

When saving a file in ASCII mode replace non-ASCII characters by a question
mark ('?').

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 .../Edit/FileBuffer.c                         | 21 +++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
index fd324cc4a8..12235e4e4b 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
@@ -1360,6 +1360,8 @@ GetNewLine (
 /**
   Change a Unicode string to an ASCII string.
 
+  Non-ASCII characters are replaced by '?'.
+
   @param[in] UStr     The Unicode string.
   @param[in] Length   The maximum size of AStr.
   @param[out] AStr    ASCII string to pass out.
@@ -1378,8 +1380,12 @@ UnicodeToAscii (
   //
   // just buffer copy, not character copy
   //
-  for (Index = 0; Index < Length; Index++) {
-    *AStr++ = (CHAR8) *UStr++;
+  for (Index = 0; Index < Length; Index++, UStr++) {
+    if (*UStr < 0x80) {
+      *AStr++ = (CHAR8) *UStr;
+    } else {
+      *AStr++ = '?';
+    }
   }
 
   return Index;
@@ -2154,9 +2160,16 @@ FileBufferDoCharInput (
 
   default:
     //
-    // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
+    // Do not add Unicode control characters to the file buffer:
+    //
+    // * U+0000-U+001f (C0 controls)
+    // * U+007f (DEL)
+    // * U+0080-U+009f (C1 controls)
+    //
+    // Do not add non-ASCII characters in ASCII mode.
     //
-    if (Char > 127 || Char < 32) {
+    if (Char < 0x20 || (Char >= 0x7f &&
+        (Char <= 0x9f || FileBuffer.FileType == FileTypeAscii))) {
       Status = StatusBarSetStatusString (L"Unknown Command");
     } else {
       Status = FileBufferAddChar (Char);
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-04 17:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-24 10:37 [edk] [PATCH] ShellPkg/edit: allow non-ASCII characters in edit Heinrich Schuchardt
2020-11-02 21:10 ` [edk2-devel] " Laszlo Ersek
  -- strict thread matches above, loose matches on Subject: below --
2020-11-02 23:11 Heinrich Schuchardt
2020-11-03 23:42 ` Leif Lindholm
2020-11-04 17:23 ` Laszlo Ersek
2019-11-24 10:15 Heinrich Schuchardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox