]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/UnicodeCollationEng.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Universal / Disk / UnicodeCollation / EnglishDxe / UnicodeCollationEng.c
index 07bb2f446d4bbb5b2dd2aee850e936af2acd0c99..b959cb1e9c9a48d0a24e19da94e90b2e9f43afc2 100644 (file)
@@ -1,23 +1,17 @@
 /** @file\r
   Driver to implement English version of Unicode Collation Protocol.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. <BR>\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 #include "UnicodeCollationEng.h"\r
 \r
-CHAR8 mEngUpperMap[0x100];\r
-CHAR8 mEngLowerMap[0x100];\r
-CHAR8 mEngInfoMap[0x100];\r
+CHAR8 mEngUpperMap[MAP_TABLE_SIZE];\r
+CHAR8 mEngLowerMap[MAP_TABLE_SIZE];\r
+CHAR8 mEngInfoMap[MAP_TABLE_SIZE];\r
 \r
 CHAR8 mOtherChars[] = {\r
   '0',\r
@@ -51,7 +45,7 @@ CHAR8 mOtherChars[] = {
   '\0'\r
 };\r
 \r
-STATIC EFI_HANDLE  mHandle = NULL;\r
+EFI_HANDLE  mHandle = NULL;\r
 \r
 //\r
 // EFI Unicode Collation Protocol supporting ISO 639-2 language code\r
@@ -67,7 +61,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL  UnicodeEng = {
 };\r
 \r
 //\r
-// EFI Unicode Collation2 Protocol supporting RFC 3066 language code\r
+// EFI Unicode Collation2 Protocol supporting RFC 4646 language code\r
 //\r
 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL  Unicode2Eng = {\r
   EngStriColl,\r
@@ -81,13 +75,13 @@ GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_COLLATION_PROTOCOL  Unicode2Eng = {
 \r
 /**\r
   The user Entry Point for English module.\r
\r
+\r
   This function initializes unicode character mapping and then installs Unicode\r
-  Collation & Unicode Collation 2 Protocols based on the feature flags.  \r
+  Collation & Unicode Collation 2 Protocols based on the feature flags.\r
 \r
-  @param  ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param  ImageHandle    The firmware allocated handle for the EFI image.\r
   @param  SystemTable    A pointer to the EFI System Table.\r
-  \r
+\r
   @retval EFI_SUCCESS    The entry point is executed successfully.\r
   @retval other          Some error occurs when executing this entry point.\r
 \r
@@ -106,7 +100,7 @@ InitializeUnicodeCollationEng (
   //\r
   // Initialize mapping tables for the supported languages\r
   //\r
-  for (Index = 0; Index < 0x100; Index++) {\r
+  for (Index = 0; Index < MAP_TABLE_SIZE; Index++) {\r
     mEngUpperMap[Index] = (CHAR8) Index;\r
     mEngLowerMap[Index] = (CHAR8) Index;\r
     mEngInfoMap[Index]  = 0;\r
@@ -122,7 +116,7 @@ InitializeUnicodeCollationEng (
     }\r
   }\r
 \r
-  for (Index = 0; mOtherChars[Index]; Index++) {\r
+  for (Index = 0; mOtherChars[Index] != 0; Index++) {\r
     Index2 = mOtherChars[Index];\r
     mEngInfoMap[Index2] |= CHAR_FAT_VALID;\r
   }\r
@@ -171,12 +165,11 @@ InitializeUnicodeCollationEng (
 \r
 \r
 /**\r
-  Performs a case-insensitive comparison of two Null-terminated Unicode \r
-  strings.\r
+  Performs a case-insensitive comparison of two Null-terminated strings.\r
 \r
   @param  This Protocol instance pointer.\r
-  @param  Str1 A pointer to a Null-terminated Unicode string.\r
-  @param  Str2 A pointer to a Null-terminated Unicode string.\r
+  @param  Str1 A pointer to a Null-terminated string.\r
+  @param  Str2 A pointer to a Null-terminated string.\r
 \r
   @retval 0   Str1 is equivalent to Str2\r
   @retval > 0 Str1 is lexically greater than Str2\r
@@ -191,8 +184,8 @@ EngStriColl (
   IN CHAR16                           *Str2\r
   )\r
 {\r
-  while (*Str1) {\r
-    if (ToUpper (*Str1) != ToUpper (*Str2)) {\r
+  while (*Str1 != 0) {\r
+    if (TO_UPPER (*Str1) != TO_UPPER (*Str2)) {\r
       break;\r
     }\r
 \r
@@ -200,16 +193,16 @@ EngStriColl (
     Str2 += 1;\r
   }\r
 \r
-  return ToUpper (*Str1) - ToUpper (*Str2);\r
+  return TO_UPPER (*Str1) - TO_UPPER (*Str2);\r
 }\r
 \r
 \r
 /**\r
-  Converts all the Unicode characters in a Null-terminated Unicode string to \r
-  lower case Unicode characters.\r
+  Converts all the characters in a Null-terminated string to\r
+  lower case characters.\r
 \r
   @param  This   Protocol instance pointer.\r
-  @param  Str    A pointer to a Null-terminated Unicode string.\r
+  @param  Str    A pointer to a Null-terminated string.\r
 \r
 **/\r
 VOID\r
@@ -219,19 +212,19 @@ EngStrLwr (
   IN OUT CHAR16                       *Str\r
   )\r
 {\r
-  while (*Str) {\r
-    *Str = ToLower (*Str);\r
+  while (*Str != 0) {\r
+    *Str = TO_LOWER (*Str);\r
     Str += 1;\r
   }\r
 }\r
 \r
 \r
 /**\r
-  Converts all the Unicode characters in a Null-terminated Unicode string to upper\r
-  case Unicode characters.\r
+  Converts all the characters in a Null-terminated string to upper\r
+  case characters.\r
 \r
   @param  This   Protocol instance pointer.\r
-  @param  Str    A pointer to a Null-terminated Unicode string.\r
+  @param  Str    A pointer to a Null-terminated string.\r
 \r
 **/\r
 VOID\r
@@ -241,19 +234,19 @@ EngStrUpr (
   IN OUT CHAR16                       *Str\r
   )\r
 {\r
-  while (*Str) {\r
-    *Str = ToUpper (*Str);\r
+  while (*Str != 0) {\r
+    *Str = TO_UPPER (*Str);\r
     Str += 1;\r
   }\r
 }\r
 \r
 /**\r
-  Performs a case-insensitive comparison of a Null-terminated Unicode \r
-  pattern string and a Null-terminated Unicode string.\r
+  Performs a case-insensitive comparison of a Null-terminated\r
+  pattern string and a Null-terminated string.\r
 \r
   @param  This    Protocol instance pointer.\r
-  @param  String  A pointer to a Null-terminated Unicode string.\r
-  @param  Pattern A pointer to a Null-terminated Unicode pattern string.\r
+  @param  String  A pointer to a Null-terminated string.\r
+  @param  Pattern A pointer to a Null-terminated pattern string.\r
 \r
   @retval TRUE    Pattern was found in String.\r
   @retval FALSE   Pattern was not found in String.\r
@@ -280,7 +273,7 @@ EngMetaiMatch (
       //\r
       // End of pattern.  If end of string, TRUE match\r
       //\r
-      if (*String) {\r
+      if (*String != 0) {\r
         return FALSE;\r
       } else {\r
         return TRUE;\r
@@ -290,7 +283,7 @@ EngMetaiMatch (
       //\r
       // Match zero or more chars\r
       //\r
-      while (*String) {\r
+      while (*String != 0) {\r
         if (EngMetaiMatch (This, String, Pattern)) {\r
           return TRUE;\r
         }\r
@@ -304,7 +297,7 @@ EngMetaiMatch (
       //\r
       // Match any one char\r
       //\r
-      if (!*String) {\r
+      if (*String == 0) {\r
         return FALSE;\r
       }\r
 \r
@@ -316,7 +309,7 @@ EngMetaiMatch (
       // Match char set\r
       //\r
       CharC = *String;\r
-      if (!CharC) {\r
+      if (CharC == 0) {\r
         //\r
         // syntax problem\r
         //\r
@@ -325,7 +318,7 @@ EngMetaiMatch (
 \r
       Index3  = 0;\r
       CharP   = *Pattern++;\r
-      while (CharP) {\r
+      while (CharP != 0) {\r
         if (CharP == ']') {\r
           return FALSE;\r
         }\r
@@ -342,7 +335,7 @@ EngMetaiMatch (
             return FALSE;\r
           }\r
 \r
-          if (ToUpper (CharC) >= ToUpper (Index3) && ToUpper (CharC) <= ToUpper (CharP)) {\r
+          if (TO_UPPER (CharC) >= TO_UPPER (Index3) && TO_UPPER (CharC) <= TO_UPPER (CharP)) {\r
             //\r
             // if in range, it's a match\r
             //\r
@@ -351,7 +344,7 @@ EngMetaiMatch (
         }\r
 \r
         Index3 = CharP;\r
-        if (ToUpper (CharC) == ToUpper (CharP)) {\r
+        if (TO_UPPER (CharC) == TO_UPPER (CharP)) {\r
           //\r
           // if char matches\r
           //\r
@@ -363,7 +356,7 @@ EngMetaiMatch (
       //\r
       // skip to end of match char set\r
       //\r
-      while (CharP && CharP != ']') {\r
+      while ((CharP != 0) && (CharP != ']')) {\r
         CharP = *Pattern;\r
         Pattern += 1;\r
       }\r
@@ -373,7 +366,7 @@ EngMetaiMatch (
 \r
     default:\r
       CharC = *String;\r
-      if (ToUpper (CharC) != ToUpper (CharP)) {\r
+      if (TO_UPPER (CharC) != TO_UPPER (CharP)) {\r
         return FALSE;\r
       }\r
 \r
@@ -385,15 +378,14 @@ EngMetaiMatch (
 \r
 \r
 /**\r
-  Converts an 8.3 FAT file name in an OEM character set to a Null-terminated \r
-  Unicode string.\r
+  Converts an 8.3 FAT file name in an OEM character set to a Null-terminated string.\r
 \r
   @param  This    Protocol instance pointer.\r
   @param  FatSize The size of the string Fat in bytes.\r
   @param  Fat     A pointer to a Null-terminated string that contains an 8.3 file\r
-                  name using an OEM character set.\r
-  @param  String  A pointer to a Null-terminated Unicode string. The string must\r
-                  be preallocated to hold FatSize Unicode characters.\r
+                  name using an 8-bit OEM character set.\r
+  @param  String  A pointer to a Null-terminated string. The string must\r
+                  be preallocated to hold FatSize characters.\r
 \r
 **/\r
 VOID\r
@@ -408,7 +400,7 @@ EngFatToStr (
   //\r
   // No DBCS issues, just expand and add null terminate to end of string\r
   //\r
-  while (*Fat && FatSize) {\r
+  while ((*Fat != 0) && (FatSize != 0)) {\r
     *String = *Fat;\r
     String += 1;\r
     Fat += 1;\r
@@ -420,12 +412,12 @@ EngFatToStr (
 \r
 \r
 /**\r
-  Converts a Null-terminated Unicode string to legal characters in a FAT \r
-  filename using an OEM character set. \r
+  Converts a Null-terminated string to legal characters in a FAT\r
+  filename using an OEM character set.\r
 \r
   @param  This    Protocol instance pointer.\r
-  @param  String  A pointer to a Null-terminated Unicode string. The string must\r
-                  be preallocated to hold FatSize Unicode characters.\r
+  @param  String  A pointer to a Null-terminated string. The string must\r
+                  be preallocated to hold FatSize characters.\r
   @param  FatSize The size of the string Fat in bytes.\r
   @param  Fat     A pointer to a Null-terminated string that contains an 8.3 file\r
                   name using an OEM character set.\r
@@ -446,16 +438,16 @@ EngStrToFat (
   BOOLEAN SpecialCharExist;\r
 \r
   SpecialCharExist = FALSE;\r
-  while (*String && FatSize) {\r
+  while ((*String != 0) && (FatSize != 0)) {\r
     //\r
     // Skip '.' or ' ' when making a fat name\r
     //\r
     if (*String != '.' && *String != ' ') {\r
       //\r
       // If this is a valid fat char, move it.\r
-      // Otherwise, move a '_' and flag the fact that the name needs an Lfn\r
+      // Otherwise, move a '_' and flag the fact that the name needs a long file name.\r
       //\r
-      if (*String < 0x100 && (mEngInfoMap[*String] & CHAR_FAT_VALID)) {\r
+      if (*String < MAP_TABLE_SIZE && ((mEngInfoMap[*String] & CHAR_FAT_VALID) != 0)) {\r
         *Fat = mEngUpperMap[*String];\r
       } else {\r
         *Fat              = '_';\r