]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/ShellManParser.c
MdePkg: Add missing SMBIOS definitions for SATA and SAS Ports
[mirror_edk2.git] / ShellPkg / Application / Shell / ShellManParser.c
index 8196a6ac9dcaf385d3d7abf744a368a959150475..78b8decd832412584732dea1459dffacb010e46a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell MAN file parser.\r
 \r
-  Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
   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
@@ -39,15 +39,20 @@ GetManFileName(
   // Fix the file name\r
   //\r
   if (StrnCmp(ManFileName+StrLen(ManFileName)-4, L".man", 4)==0) {\r
-    Buffer = AllocateZeroPool(StrSize(ManFileName));\r
-    if (Buffer != NULL) {\r
-      StrCpy(Buffer, ManFileName);\r
-    }\r
+    Buffer = AllocateCopyPool(StrSize(ManFileName), ManFileName);\r
   } else {\r
     Buffer = AllocateZeroPool(StrSize(ManFileName) + 4*sizeof(CHAR16));\r
     if (Buffer != NULL) {\r
-      StrCpy(Buffer, ManFileName);\r
-      StrCat(Buffer, L".man");\r
+      StrnCpyS( Buffer, \r
+                (StrSize(ManFileName) + 4*sizeof(CHAR16))/sizeof(CHAR16), \r
+                ManFileName, \r
+                StrLen(ManFileName)\r
+                );\r
+      StrnCatS( Buffer, \r
+                (StrSize(ManFileName) + 4*sizeof(CHAR16))/sizeof(CHAR16),\r
+                L".man", \r
+                4\r
+                );\r
     }\r
   }\r
   return (Buffer);\r
@@ -374,6 +379,9 @@ ManBufferFindTitleSection(
   CHAR16        *TitleString;\r
   CHAR16        *TitleEnd;\r
   CHAR16        *CurrentLocation;\r
+  UINTN         TitleLength;\r
+  CONST CHAR16  StartString[] = L".TH ";\r
+  CONST CHAR16  EndString[]   = L" 0 ";\r
 \r
   if ( Buffer     == NULL\r
     || Command    == NULL\r
@@ -384,13 +392,17 @@ ManBufferFindTitleSection(
 \r
   Status    = EFI_SUCCESS;\r
 \r
-  TitleString = AllocateZeroPool((7*sizeof(CHAR16)) + StrSize(Command));\r
+  //\r
+  // more characters for StartString and EndString\r
+  //\r
+  TitleLength = StrSize(Command) + (StrLen(StartString) + StrLen(EndString)) * sizeof(CHAR16);\r
+  TitleString = AllocateZeroPool(TitleLength);\r
   if (TitleString == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  StrCpy(TitleString, L".TH ");\r
-  StrCat(TitleString, Command);\r
-  StrCat(TitleString, L" 0 ");\r
+  StrCpyS(TitleString, TitleLength/sizeof(CHAR16), StartString);\r
+  StrCatS(TitleString, TitleLength/sizeof(CHAR16), Command);\r
+  StrCatS(TitleString, TitleLength/sizeof(CHAR16), EndString);\r
 \r
   CurrentLocation = StrStr(*Buffer, TitleString);\r
   if (CurrentLocation == NULL){\r
@@ -414,7 +426,7 @@ ManBufferFindTitleSection(
         if (*BriefDesc == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
         } else {\r
-          StrnCpy(*BriefDesc, CurrentLocation, TitleEnd-CurrentLocation);\r
+          StrnCpyS(*BriefDesc, (*BriefSize)/sizeof(CHAR16), CurrentLocation, TitleEnd-CurrentLocation);\r
         }\r
       }\r
 \r
@@ -467,6 +479,7 @@ ManFileFindTitleSection(
   CHAR16      *TitleEnd;\r
   UINTN       TitleLen;\r
   BOOLEAN     Found;\r
+  UINTN       TitleSize;\r
 \r
   if ( Handle     == NULL\r
     || Command    == NULL\r
@@ -484,26 +497,14 @@ ManFileFindTitleSection(
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
-  TitleString = AllocateZeroPool((4*sizeof(CHAR16)) + StrSize(Command));\r
+  TitleSize = (4*sizeof(CHAR16)) + StrSize(Command);\r
+  TitleString = AllocateZeroPool(TitleSize);\r
   if (TitleString == NULL) {\r
     FreePool(ReadLine);\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  StrCpy(TitleString, L".TH ");\r
-  StrCat(TitleString, Command);\r
-\r
-  //\r
-  // If the "name" ends with .efi we can safely chop that off since "help foo.efi" and "help foo" \r
-  // should produce the same results.\r
-  //\r
-  if ((StrLen(Command)> 4)\r
-    && (TitleString[StrLen(TitleString)-1] == L'i' || TitleString[StrLen(TitleString)-1] == L'I')\r
-    && (TitleString[StrLen(TitleString)-2] == L'f' || TitleString[StrLen(TitleString)-2] == L'F')\r
-    && (TitleString[StrLen(TitleString)-3] == L'e' || TitleString[StrLen(TitleString)-2] == L'E')\r
-    && (TitleString[StrLen(TitleString)-4] == L'.')\r
-    ) {\r
-    TitleString[StrLen(TitleString)-4] = CHAR_NULL;\r
-  }\r
+  StrCpyS(TitleString, TitleSize/sizeof(CHAR16), L".TH ");\r
+  StrCatS(TitleString, TitleSize/sizeof(CHAR16), Command);\r
 \r
   TitleLen = StrLen(TitleString);\r
   for (;!ShellFileHandleEof(Handle);Size = 1024) {\r
@@ -539,7 +540,7 @@ ManFileFindTitleSection(
           Status = EFI_OUT_OF_RESOURCES;\r
           break;\r
         }\r
-        StrCpy(*BriefDesc, TitleEnd);\r
+        StrCpyS(*BriefDesc, (*BriefSize)/sizeof(CHAR16), TitleEnd);\r
       }\r
       break;\r
     }\r
@@ -612,6 +613,7 @@ ProcessManFile(
   HelpSize    = 0;\r
   BriefSize   = 0;\r
   TempString  = NULL;\r
+  Ascii       = FALSE;\r
   //\r
   // See if it's in HII first\r
   //\r