public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] User UnicodeCollation in StrinCmp
@ 2018-01-26  9:07 Ruiyu Ni
  0 siblings, 0 replies; 5+ messages in thread
From: Ruiyu Ni @ 2018-01-26  9:07 UTC (permalink / raw)
  To: edk2-devel

Ruiyu Ni (2):
  ShellPkg/CommandLib: Locate proper UnicodeCollation instance
  ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp

 .../UefiShellCommandLib/UefiShellCommandLib.c      | 76 ++++++++++++++++++----
 .../UefiShellCommandLib/UefiShellCommandLib.h      |  3 +-
 ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c   |  4 +-
 ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c   |  4 +-
 .../Library/UefiShellLevel2CommandsLib/TimeDate.c  |  6 +-
 .../UefiShellLevel2CommandsLib.c                   | 65 +++++++++---------
 .../UefiShellLevel2CommandsLib.h                   | 15 +++--
 7 files changed, 116 insertions(+), 57 deletions(-)

-- 
2.15.1.windows.2



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

* [PATCH 0/2] User UnicodeCollation in StrinCmp
@ 2018-01-26  9:51 Ruiyu Ni
  2018-01-26  9:51 ` [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance Ruiyu Ni
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ruiyu Ni @ 2018-01-26  9:51 UTC (permalink / raw)
  To: edk2-devel

Ruiyu Ni (2):
  ShellPkg/CommandLib: Locate proper UnicodeCollation instance
  ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp

 .../UefiShellCommandLib/UefiShellCommandLib.c      | 76 ++++++++++++++++++----
 .../UefiShellCommandLib/UefiShellCommandLib.h      |  3 +-
 ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c   |  4 +-
 ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c   |  4 +-
 .../Library/UefiShellLevel2CommandsLib/TimeDate.c  |  6 +-
 .../UefiShellLevel2CommandsLib.c                   | 65 +++++++++---------
 .../UefiShellLevel2CommandsLib.h                   | 15 +++--
 7 files changed, 116 insertions(+), 57 deletions(-)

-- 
2.15.1.windows.2



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

* [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance
  2018-01-26  9:51 [PATCH 0/2] User UnicodeCollation in StrinCmp Ruiyu Ni
@ 2018-01-26  9:51 ` Ruiyu Ni
  2018-01-26  9:51 ` [PATCH 2/2] ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp Ruiyu Ni
  2018-01-26 15:51 ` [PATCH 0/2] User " Carsey, Jaben
  2 siblings, 0 replies; 5+ messages in thread
From: Ruiyu Ni @ 2018-01-26  9:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jaben Carsey

Original code locates the first UnicodeCollation instance in
DXE Core protocol database.
It's not correct considering multiple UnicodeCollation instances
exist in system.
The patch changes logic to find the one that matches the current
system language.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
---
 .../UefiShellCommandLib/UefiShellCommandLib.c      | 76 ++++++++++++++++++----
 .../UefiShellCommandLib/UefiShellCommandLib.h      |  3 +-
 2 files changed, 67 insertions(+), 12 deletions(-)

diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
index c7984f11b2..0df252b420 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c
@@ -1,7 +1,7 @@
 /** @file
   Provides interface to shell internal functions for shell commands.
 
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.<BR>
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
 
@@ -72,14 +72,70 @@ CommandInit(
   VOID
   )
 {
-  EFI_STATUS Status;
+  UINTN                           NumHandles;
+  EFI_HANDLE                      *Handles;
+  EFI_UNICODE_COLLATION_PROTOCOL  *Uc;
+  CHAR8                           *BestLanguage;
+  UINTN                           Index;
+  EFI_STATUS                      Status;
+  CHAR8                           *PlatformLang;
+  
+  GetEfiGlobalVariable2 (EFI_PLATFORM_LANG_VARIABLE_NAME, (VOID**)&PlatformLang, NULL);
+  if (PlatformLang == NULL) {
+    return EFI_UNSUPPORTED;
+  }
+
   if (gUnicodeCollation == NULL) {
-    Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);
-    if (EFI_ERROR(Status)) {
-      return (EFI_DEVICE_ERROR);
+    Status = gBS->LocateHandleBuffer (
+                    ByProtocol,
+                    &gEfiUnicodeCollation2ProtocolGuid,
+                    NULL,
+                    &NumHandles,
+                    &Handles
+                    );
+    if (EFI_ERROR (Status)) {
+      NumHandles = 0;
+      Handles    = NULL;
     }
+    for (Index = 0; Index < NumHandles; Index++) {
+      //
+      // Open Unicode Collation Protocol
+      //
+      Status = gBS->OpenProtocol (
+                      Handles[Index],
+                      &gEfiUnicodeCollation2ProtocolGuid,
+                      (VOID **) &Uc,
+                      gImageHandle,
+                      NULL,
+                      EFI_OPEN_PROTOCOL_GET_PROTOCOL
+                      );
+      if (EFI_ERROR (Status)) {
+        continue;
+      }
+
+      //
+      // Find the best matching matching language from the supported languages
+      // of Unicode Collation2 protocol. 
+      //
+      BestLanguage = GetBestLanguage (
+                       Uc->SupportedLanguages,
+                       FALSE,
+                       PlatformLang,
+                       NULL
+                       );
+      if (BestLanguage != NULL) {
+        FreePool (BestLanguage);
+        gUnicodeCollation = Uc;
+        break;
+      }
+    }
+    if (Handles != NULL) {
+      FreePool (Handles);
+    }
+    FreePool (PlatformLang);
   }
-  return (EFI_SUCCESS);
+
+  return (gUnicodeCollation == NULL) ? EFI_UNSUPPORTED : EFI_SUCCESS;
 }
 
 /**
@@ -112,11 +168,9 @@ ShellCommandLibConstructor (
   mProfileListSize  = 0;
   mProfileList      = NULL;
 
-  if (gUnicodeCollation == NULL) {
-    Status = gBS->LocateProtocol(&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID**)&gUnicodeCollation);
-    if (EFI_ERROR(Status)) {
-      return (EFI_DEVICE_ERROR);
-    }
+  Status = CommandInit ();
+  if (EFI_ERROR (Status)) {
+    return EFI_DEVICE_ERROR;
   }
 
   return (RETURN_SUCCESS);
diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h
index b998656b4e..bcfde60c26 100644
--- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h
+++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.h
@@ -1,7 +1,7 @@
 /** @file
   Provides interface to shell internal functions for shell commands.
 
-  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>
+  Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
@@ -19,6 +19,7 @@
 #include <Uefi.h>
 
 #include <Guid/FileInfo.h>
+#include <Guid/GlobalVariable.h>
 
 #include <Protocol/SimpleFileSystem.h>
 #include <Protocol/LoadedImage.h>
-- 
2.15.1.windows.2



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

* [PATCH 2/2] ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp
  2018-01-26  9:51 [PATCH 0/2] User UnicodeCollation in StrinCmp Ruiyu Ni
  2018-01-26  9:51 ` [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance Ruiyu Ni
@ 2018-01-26  9:51 ` Ruiyu Ni
  2018-01-26 15:51 ` [PATCH 0/2] User " Carsey, Jaben
  2 siblings, 0 replies; 5+ messages in thread
From: Ruiyu Ni @ 2018-01-26  9:51 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jaben Carsey

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
---
 ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c   |  4 +-
 ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c   |  4 +-
 .../Library/UefiShellLevel2CommandsLib/TimeDate.c  |  6 +-
 .../UefiShellLevel2CommandsLib.c                   | 65 +++++++++++-----------
 .../UefiShellLevel2CommandsLib.h                   | 15 ++---
 5 files changed, 49 insertions(+), 45 deletions(-)

diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
index 9ae81763f7..d5dc9804d4 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c
@@ -3,7 +3,7 @@
 
   (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
-  Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -102,7 +102,7 @@ IsCurrentFileSystem (
   if (((UINTN) Splitter1 - (UINTN) FullPath) != ((UINTN) Splitter2 - (UINTN) Cwd)) {
     return FALSE;
   } else {
-    if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN) FullPath) / sizeof (CHAR16)) == NULL) {
+    if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN) FullPath) / sizeof (CHAR16)) == 0) {
       return TRUE;
     } else {
       return FALSE;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
index b8f6d310f6..ae7528ddcf 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c
@@ -2,7 +2,7 @@
   Main file for cp shell level 2 function.
 
   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -510,7 +510,7 @@ ValidateAndCopyFiles(
 
     if ( !EFI_ERROR(ShellIsDirectory(Node->FullName))
       && !EFI_ERROR(ShellIsDirectory(DestPath))
-      && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == NULL
+      && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == 0
       ){
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle, L"cp");  
       ShellStatus = SHELL_INVALID_PARAMETER;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
index 5383cffe87..0b7551a239 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/TimeDate.c
@@ -2,7 +2,7 @@
   Main file for time, timezone, and date shell level 2 and shell level 3 functions.
 
   (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>
-  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -550,7 +550,7 @@ ShellCommandRunTime (
           // perform level 3 operation here.
           //
           if ((TempLocation = ShellCommandLineGetValue(Package, L"-tz")) != NULL) {
-            if (StrniCmp (TempLocation, L"_local", StrLen (TempLocation)) == NULL) {
+            if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16 *)TempLocation, L"_local") == 0) {
               Tz = EFI_UNSPECIFIED_TIMEZONE;
             } else if (TempLocation[0] == L'-') {
 
@@ -713,7 +713,7 @@ CheckAndSetTimeZone (
     return (SHELL_INVALID_PARAMETER);
   }
 
-  if (StrniCmp (TimeZoneString, L"_local", StrLen (TimeZoneString)) == NULL) {
+  if (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16 *)TimeZoneString, L"_local") == 0) {
     Status = gRT->GetTime (&TheTime, NULL);
     if (EFI_ERROR (Status)) {
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
index e9ce631892..36bc3552b5 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c
@@ -22,7 +22,7 @@
   * functions are non-interactive only
 
   Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
-  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -260,19 +260,6 @@ VerifyIntermediateDirectories (
   return (Status);
 }
 
-/**
-  Be lazy and borrow from baselib.
-
-  @param[in] Char   The character to convert to upper case.
-
-  @return Char as an upper case character.
-**/
-CHAR16
-EFIAPI
-InternalCharToUpper (
-  IN      CHAR16                    Char
-  );
-
 /**
   String comparison without regard to case for a limited number of characters.
 
@@ -280,31 +267,47 @@ InternalCharToUpper (
   @param[in] Target   The second item to compare.
   @param[in] Count    How many characters to compare.
 
-  @retval NULL Source and Target are identical strings without regard to case.
-  @return The location in Source where there is a difference.
+  @retval 0    Source and Target are identical strings without regard to case.
+  @retval !=0  Source is not identical to Target.
+  
 **/
-CONST CHAR16*
+INTN
 StrniCmp(
   IN CONST CHAR16 *Source,
   IN CONST CHAR16 *Target,
   IN CONST UINTN  Count
   )
 {
-  UINTN   LoopCount;
-  CHAR16  Char1;
-  CHAR16  Char2;
-
-  ASSERT(Source != NULL);
-  ASSERT(Target != NULL);
-
-  for (LoopCount = 0 ; LoopCount < Count ; LoopCount++) {
-    Char1 = InternalCharToUpper(Source[LoopCount]);
-    Char2 = InternalCharToUpper(Target[LoopCount]);
-    if (Char1 != Char2) {
-      return (&Source[LoopCount]);
-    }
+  CHAR16                    *SourceCopy;
+  CHAR16                    *TargetCopy;
+  UINTN                     SourceLength;
+  UINTN                     TargetLength;
+  INTN                      Result;
+
+  if (Count == 0) {
+    return 0;
+  }
+
+  SourceLength = StrLen (Source);
+  TargetLength = StrLen (Target);
+  SourceLength = MIN (SourceLength, Count);
+  TargetLength = MIN (TargetLength, Count);
+  SourceCopy = AllocateCopyPool ((SourceLength + 1) * sizeof (CHAR16), Source);
+  if (SourceCopy == NULL) {
+    return -1;
+  }
+  TargetCopy = AllocateCopyPool ((TargetLength + 1) * sizeof (CHAR16), Target);
+  if (TargetCopy == NULL) {
+    FreePool (SourceCopy);
+    return -1;
   }
-  return (NULL);
+  
+  SourceCopy[SourceLength] = L'\0';
+  TargetCopy[TargetLength] = L'\0';
+  Result = gUnicodeCollation->StriColl (gUnicodeCollation, SourceCopy, TargetCopy);
+  FreePool (SourceCopy);
+  FreePool (TargetCopy);
+  return Result;
 }
 
 
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
index 857487fd80..fef6adc3e1 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
@@ -280,16 +280,17 @@ VerifyIntermediateDirectories (
   );
 
 /**
-  CaseInsensitive length limited string comparison.
+  String comparison without regard to case for a limited number of characters.
 
-  @param[in] Source   Pointer to first string.
-  @param[in] Target   Pointer to second string.
-  @param[in] Count    Number of characters to compare.
+  @param[in] Source   The first item to compare.
+  @param[in] Target   The second item to compare.
+  @param[in] Count    How many characters to compare.
 
-  @retval 0   The strings are the same.
-  @return     non-zero if the strings are different.
+  @retval 0    Source and Target are identical strings without regard to case.
+  @retval !=0  Source is not identical to Target.
+  
 **/
-CONST CHAR16*
+INTN
 StrniCmp(
   IN CONST CHAR16 *Source,
   IN CONST CHAR16 *Target,
-- 
2.15.1.windows.2



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

* Re: [PATCH 0/2] User UnicodeCollation in StrinCmp
  2018-01-26  9:51 [PATCH 0/2] User UnicodeCollation in StrinCmp Ruiyu Ni
  2018-01-26  9:51 ` [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance Ruiyu Ni
  2018-01-26  9:51 ` [PATCH 2/2] ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp Ruiyu Ni
@ 2018-01-26 15:51 ` Carsey, Jaben
  2 siblings, 0 replies; 5+ messages in thread
From: Carsey, Jaben @ 2018-01-26 15:51 UTC (permalink / raw)
  To: Ni, Ruiyu, edk2-devel@lists.01.org

for series.
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Ruiyu Ni
> Sent: Friday, January 26, 2018 1:51 AM
> To: edk2-devel@lists.01.org
> Subject: [edk2] [PATCH 0/2] User UnicodeCollation in StrinCmp
> Importance: High
> 
> Ruiyu Ni (2):
>   ShellPkg/CommandLib: Locate proper UnicodeCollation instance
>   ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp
> 
>  .../UefiShellCommandLib/UefiShellCommandLib.c      | 76
> ++++++++++++++++++----
>  .../UefiShellCommandLib/UefiShellCommandLib.h      |  3 +-
>  ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c   |  4 +-
>  ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c   |  4 +-
>  .../Library/UefiShellLevel2CommandsLib/TimeDate.c  |  6 +-
>  .../UefiShellLevel2CommandsLib.c                   | 65 +++++++++---------
>  .../UefiShellLevel2CommandsLib.h                   | 15 +++--
>  7 files changed, 116 insertions(+), 57 deletions(-)
> 
> --
> 2.15.1.windows.2
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


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

end of thread, other threads:[~2018-01-26 15:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-26  9:51 [PATCH 0/2] User UnicodeCollation in StrinCmp Ruiyu Ni
2018-01-26  9:51 ` [PATCH 1/2] ShellPkg/CommandLib: Locate proper UnicodeCollation instance Ruiyu Ni
2018-01-26  9:51 ` [PATCH 2/2] ShellPkg/Level2Command: Use UnicodeCollation in StrinCmp Ruiyu Ni
2018-01-26 15:51 ` [PATCH 0/2] User " Carsey, Jaben
  -- strict thread matches above, loose matches on Subject: below --
2018-01-26  9:07 Ruiyu Ni

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