]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/Shell.c
ShellPkg: Apply uncrustify changes
[mirror_edk2.git] / ShellPkg / Application / Shell / Shell.c
index 0f1fb9c287b83c253b40e76e979e43782055c95a..df00adfdfa5b38f00867256720389df9b3b4d249 100644 (file)
@@ -1,15 +1,10 @@
 /** @file\r
   This is THE shell (application)\r
 \r
 /** @file\r
   This is THE shell (application)\r
 \r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2019, Intel Corporation. All rights reserved.<BR>\r
   (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.<BR>\r
   (C) Copyright 2013-2014 Hewlett-Packard Development Company, L.P.<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
-  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 2015-2018 Dell Technologies.<BR>\r
+  SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 **/\r
 \r
 //\r
 // Initialize the global structure\r
 //\r
 //\r
 // Initialize the global structure\r
 //\r
-SHELL_INFO ShellInfoObject = {\r
+SHELL_INFO  ShellInfoObject = {\r
   NULL,\r
   NULL,\r
   FALSE,\r
   FALSE,\r
   {\r
   NULL,\r
   NULL,\r
   FALSE,\r
   FALSE,\r
   {\r
-    {{\r
-      0,\r
-      0,\r
-      0,\r
-      0,\r
-      0,\r
-      0,\r
-      0,\r
-      0,\r
-      0,\r
-      0\r
-    }},\r
+    {\r
+      {\r
+        0,\r
+        0,\r
+        0,\r
+        0,\r
+        0,\r
+        0,\r
+        0,\r
+        0,\r
+        0,\r
+        0\r
+      }\r
+    },\r
     0,\r
     NULL,\r
     NULL\r
   },\r
     0,\r
     NULL,\r
     NULL\r
   },\r
-  {{NULL, NULL}, NULL},\r
   {\r
   {\r
-    {{NULL, NULL}, NULL},\r
+    { NULL,NULL   }, NULL\r
+  },\r
+  {\r
+    {\r
+      { NULL,NULL   }, NULL\r
+    },\r
     0,\r
     0,\r
     TRUE\r
     0,\r
     0,\r
     TRUE\r
@@ -54,8 +55,12 @@ SHELL_INFO ShellInfoObject = {
   NULL,\r
   NULL,\r
   NULL,\r
   NULL,\r
   NULL,\r
   NULL,\r
-  {{NULL, NULL}, NULL, NULL},\r
-  {{NULL, NULL}, NULL, NULL},\r
+  {\r
+    { NULL,NULL   }, NULL, NULL\r
+  },\r
+  {\r
+    { NULL,NULL   }, NULL, NULL\r
+  },\r
   NULL,\r
   NULL,\r
   NULL,\r
   NULL,\r
   NULL,\r
   NULL,\r
@@ -67,12 +72,12 @@ SHELL_INFO ShellInfoObject = {
   FALSE\r
 };\r
 \r
   FALSE\r
 };\r
 \r
-STATIC CONST CHAR16 mScriptExtension[]      = L".NSH";\r
-STATIC CONST CHAR16 mExecutableExtensions[] = L".NSH;.EFI";\r
-STATIC CONST CHAR16 mStartupScript[]        = L"startup.nsh";\r
-CONST CHAR16 mNoNestingEnvVarName[]         = L"nonesting";\r
-CONST CHAR16 mNoNestingTrue[]               = L"True";\r
-CONST CHAR16 mNoNestingFalse[]              = L"False";\r
+STATIC CONST CHAR16  mScriptExtension[]      = L".NSH";\r
+STATIC CONST CHAR16  mExecutableExtensions[] = L".NSH;.EFI";\r
+STATIC CONST CHAR16  mStartupScript[]        = L"startup.nsh";\r
+CONST CHAR16         mNoNestingEnvVarName[]  = L"nonesting";\r
+CONST CHAR16         mNoNestingTrue[]        = L"True";\r
+CONST CHAR16         mNoNestingFalse[]       = L"False";\r
 \r
 /**\r
   Cleans off leading and trailing spaces and tabs.\r
 \r
 /**\r
   Cleans off leading and trailing spaces and tabs.\r
@@ -80,64 +85,64 @@ CONST CHAR16 mNoNestingFalse[]              = L"False";
   @param[in] String pointer to the string to trim them off.\r
 **/\r
 EFI_STATUS\r
   @param[in] String pointer to the string to trim them off.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-TrimSpaces(\r
-  IN CHAR16 **String\r
+TrimSpaces (\r
+  IN CHAR16  **String\r
   )\r
 {\r
   )\r
 {\r
-  ASSERT(String != NULL);\r
-  ASSERT(*String!= NULL);\r
+  ASSERT (String != NULL);\r
+  ASSERT (*String != NULL);\r
   //\r
   // Remove any spaces and tabs at the beginning of the (*String).\r
   //\r
   while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) {\r
   //\r
   // Remove any spaces and tabs at the beginning of the (*String).\r
   //\r
   while (((*String)[0] == L' ') || ((*String)[0] == L'\t')) {\r
-    CopyMem((*String), (*String)+1, StrSize((*String)) - sizeof((*String)[0]));\r
+    CopyMem ((*String), (*String)+1, StrSize ((*String)) - sizeof ((*String)[0]));\r
   }\r
 \r
   //\r
   // Remove any spaces and tabs at the end of the (*String).\r
   //\r
   }\r
 \r
   //\r
   // Remove any spaces and tabs at the end of the (*String).\r
   //\r
-  while ((StrLen (*String) > 0) && (((*String)[StrLen((*String))-1] == L' ') || ((*String)[StrLen((*String))-1] == L'\t'))) {\r
-    (*String)[StrLen((*String))-1] = CHAR_NULL;\r
+  while ((StrLen (*String) > 0) && (((*String)[StrLen ((*String))-1] == L' ') || ((*String)[StrLen ((*String))-1] == L'\t'))) {\r
+    (*String)[StrLen ((*String))-1] = CHAR_NULL;\r
   }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
   }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
-  Parse for the next instance of one string within another string. Can optionally make sure that \r
+  Parse for the next instance of one string within another string. Can optionally make sure that\r
   the string was not escaped (^ character) per the shell specification.\r
 \r
   @param[in] SourceString             The string to search within\r
   @param[in] FindString               The string to look for\r
   @param[in] CheckForEscapeCharacter  TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances\r
 **/\r
   the string was not escaped (^ character) per the shell specification.\r
 \r
   @param[in] SourceString             The string to search within\r
   @param[in] FindString               The string to look for\r
   @param[in] CheckForEscapeCharacter  TRUE to skip escaped instances of FinfString, otherwise will return even escaped instances\r
 **/\r
-CHAR16*\r
-EFIAPI\r
-FindNextInstance(\r
+CHAR16 *\r
+FindNextInstance (\r
   IN CONST CHAR16   *SourceString,\r
   IN CONST CHAR16   *FindString,\r
   IN CONST BOOLEAN  CheckForEscapeCharacter\r
   )\r
 {\r
   IN CONST CHAR16   *SourceString,\r
   IN CONST CHAR16   *FindString,\r
   IN CONST BOOLEAN  CheckForEscapeCharacter\r
   )\r
 {\r
-  CHAR16 *Temp;\r
+  CHAR16  *Temp;\r
+\r
   if (SourceString == NULL) {\r
     return (NULL);\r
   }\r
   if (SourceString == NULL) {\r
     return (NULL);\r
   }\r
-  Temp = StrStr(SourceString, FindString);\r
+\r
+  Temp = StrStr (SourceString, FindString);\r
 \r
   //\r
   // If nothing found, or we don't care about escape characters\r
   //\r
 \r
   //\r
   // If nothing found, or we don't care about escape characters\r
   //\r
-  if (Temp == NULL || !CheckForEscapeCharacter) {\r
+  if ((Temp == NULL) || !CheckForEscapeCharacter) {\r
     return (Temp);\r
   }\r
 \r
   //\r
   // If we found an escaped character, try again on the remainder of the string\r
   //\r
     return (Temp);\r
   }\r
 \r
   //\r
   // If we found an escaped character, try again on the remainder of the string\r
   //\r
-  if ((Temp > (SourceString)) && *(Temp-1) == L'^') {\r
-    return FindNextInstance(Temp+1, FindString, CheckForEscapeCharacter);\r
+  if ((Temp > (SourceString)) && (*(Temp-1) == L'^')) {\r
+    return FindNextInstance (Temp+1, FindString, CheckForEscapeCharacter);\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -156,31 +161,32 @@ FindNextInstance(
   @retval FALSE                         is NOT a valid environment variable name.\r
 **/\r
 BOOLEAN\r
   @retval FALSE                         is NOT a valid environment variable name.\r
 **/\r
 BOOLEAN\r
-IsValidEnvironmentVariableName(\r
-  IN CONST CHAR16     *BeginPercent,\r
-  IN CONST CHAR16     *EndPercent\r
+IsValidEnvironmentVariableName (\r
+  IN CONST CHAR16  *BeginPercent,\r
+  IN CONST CHAR16  *EndPercent\r
   )\r
 {\r
   )\r
 {\r
-  CONST CHAR16    *Walker;\r
-  \r
+  CONST CHAR16  *Walker;\r
+\r
   Walker = NULL;\r
 \r
   ASSERT (BeginPercent != NULL);\r
   ASSERT (EndPercent != NULL);\r
   ASSERT (BeginPercent < EndPercent);\r
   Walker = NULL;\r
 \r
   ASSERT (BeginPercent != NULL);\r
   ASSERT (EndPercent != NULL);\r
   ASSERT (BeginPercent < EndPercent);\r
-  \r
+\r
   if ((BeginPercent + 1) == EndPercent) {\r
     return FALSE;\r
   }\r
 \r
   for (Walker = BeginPercent + 1; Walker < EndPercent; Walker++) {\r
     if (\r
   if ((BeginPercent + 1) == EndPercent) {\r
     return FALSE;\r
   }\r
 \r
   for (Walker = BeginPercent + 1; Walker < EndPercent; Walker++) {\r
     if (\r
-        (*Walker >= L'0' && *Walker <= L'9') ||\r
-        (*Walker >= L'A' && *Walker <= L'Z') ||\r
-        (*Walker >= L'a' && *Walker <= L'z') ||\r
+        ((*Walker >= L'0') && (*Walker <= L'9')) ||\r
+        ((*Walker >= L'A') && (*Walker <= L'Z')) ||\r
+        ((*Walker >= L'a') && (*Walker <= L'z')) ||\r
         (*Walker == L'_')\r
         (*Walker == L'_')\r
-      ) {\r
-      if (Walker == BeginPercent + 1 && (*Walker >= L'0' && *Walker <= L'9')) {\r
+        )\r
+    {\r
+      if ((Walker == BeginPercent + 1) && ((*Walker >= L'0') && (*Walker <= L'9'))) {\r
         return FALSE;\r
       } else {\r
         continue;\r
         return FALSE;\r
       } else {\r
         continue;\r
@@ -202,79 +208,82 @@ IsValidEnvironmentVariableName(
   @retval FALSE           CmdLine does not have a valid split.\r
 **/\r
 BOOLEAN\r
   @retval FALSE           CmdLine does not have a valid split.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
-ContainsSplit(\r
-  IN CONST CHAR16 *CmdLine\r
+ContainsSplit (\r
+  IN CONST CHAR16  *CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  CONST CHAR16 *TempSpot;\r
-  CONST CHAR16 *FirstQuote;\r
-  CONST CHAR16 *SecondQuote;\r
-\r
-  FirstQuote    = FindNextInstance (CmdLine, L"\"", TRUE);\r
-  SecondQuote   = NULL;\r
-  TempSpot      = ShellFindFirstCharacter(CmdLine, L"|", TRUE);\r
-\r
-  if (FirstQuote == NULL    || \r
-      TempSpot == NULL      || \r
-      TempSpot == CHAR_NULL || \r
-      FirstQuote > TempSpot\r
-      ) {\r
-    return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
+  CONST CHAR16  *TempSpot;\r
+  CONST CHAR16  *FirstQuote;\r
+  CONST CHAR16  *SecondQuote;\r
+\r
+  FirstQuote  = FindNextInstance (CmdLine, L"\"", TRUE);\r
+  SecondQuote = NULL;\r
+  TempSpot    = FindFirstCharacter (CmdLine, L"|", L'^');\r
+\r
+  if ((FirstQuote == NULL) ||\r
+      (TempSpot == NULL) ||\r
+      (TempSpot == CHAR_NULL) ||\r
+      (FirstQuote > TempSpot)\r
+      )\r
+  {\r
+    return (BOOLEAN)((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
   }\r
 \r
   while ((TempSpot != NULL) && (*TempSpot != CHAR_NULL)) {\r
   }\r
 \r
   while ((TempSpot != NULL) && (*TempSpot != CHAR_NULL)) {\r
-    if (FirstQuote == NULL || FirstQuote > TempSpot) {\r
+    if ((FirstQuote == NULL) || (FirstQuote > TempSpot)) {\r
       break;\r
       break;\r
-    }    \r
+    }\r
+\r
     SecondQuote = FindNextInstance (FirstQuote + 1, L"\"", TRUE);\r
     if (SecondQuote == NULL) {\r
       break;\r
     }\r
     SecondQuote = FindNextInstance (FirstQuote + 1, L"\"", TRUE);\r
     if (SecondQuote == NULL) {\r
       break;\r
     }\r
+\r
     if (SecondQuote < TempSpot) {\r
       FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
       continue;\r
     } else {\r
       FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
     if (SecondQuote < TempSpot) {\r
       FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
       continue;\r
     } else {\r
       FirstQuote = FindNextInstance (SecondQuote + 1, L"\"", TRUE);\r
-      TempSpot = ShellFindFirstCharacter(TempSpot + 1, L"|", TRUE);\r
+      TempSpot   = FindFirstCharacter (TempSpot + 1, L"|", L'^');\r
       continue;\r
       continue;\r
-    } \r
+    }\r
   }\r
   }\r
-  \r
-  return (BOOLEAN) ((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
+\r
+  return (BOOLEAN)((TempSpot != NULL) && (*TempSpot != CHAR_NULL));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
-  Function to start monitoring for CTRL-S using SimpleTextInputEx.  This \r
+  Function to start monitoring for CTRL-S using SimpleTextInputEx.  This\r
   feature's enabled state was not known when the shell initially launched.\r
 \r
   @retval EFI_SUCCESS           The feature is enabled.\r
   @retval EFI_OUT_OF_RESOURCES  There is not enough memory available.\r
 **/\r
 EFI_STATUS\r
   feature's enabled state was not known when the shell initially launched.\r
 \r
   @retval EFI_SUCCESS           The feature is enabled.\r
   @retval EFI_OUT_OF_RESOURCES  There is not enough memory available.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-InternalEfiShellStartCtrlSMonitor(\r
+InternalEfiShellStartCtrlSMonitor (\r
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
-  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL *SimpleEx;\r
-  EFI_KEY_DATA                      KeyData;\r
-  EFI_STATUS                        Status;\r
-\r
-  Status = gBS->OpenProtocol(\r
-    gST->ConsoleInHandle,\r
-    &gEfiSimpleTextInputExProtocolGuid,\r
-    (VOID**)&SimpleEx,\r
-    gImageHandle,\r
-    NULL,\r
-    EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
-  if (EFI_ERROR(Status)) {\r
-    ShellPrintHiiEx(\r
-      -1, \r
-      -1, \r
+  EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *SimpleEx;\r
+  EFI_KEY_DATA                       KeyData;\r
+  EFI_STATUS                         Status;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  gST->ConsoleInHandle,\r
+                  &gEfiSimpleTextInputExProtocolGuid,\r
+                  (VOID **)&SimpleEx,\r
+                  gImageHandle,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    ShellPrintHiiEx (\r
+      -1,\r
+      -1,\r
       NULL,\r
       STRING_TOKEN (STR_SHELL_NO_IN_EX),\r
       NULL,\r
       STRING_TOKEN (STR_SHELL_NO_IN_EX),\r
-      ShellInfoObject.HiiHandle);\r
+      ShellInfoObject.HiiHandle\r
+      );\r
     return (EFI_SUCCESS);\r
   }\r
 \r
     return (EFI_SUCCESS);\r
   }\r
 \r
@@ -283,42 +292,47 @@ InternalEfiShellStartCtrlSMonitor(
   KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
   KeyData.Key.UnicodeChar         = L's';\r
 \r
   KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
   KeyData.Key.UnicodeChar         = L's';\r
 \r
-  Status = SimpleEx->RegisterKeyNotify(\r
-    SimpleEx,\r
-    &KeyData,\r
-    NotificationFunction,\r
-    &ShellInfoObject.CtrlSNotifyHandle1);\r
-  \r
-  KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
-  if (!EFI_ERROR(Status)) {\r
-    Status = SimpleEx->RegisterKeyNotify(\r
-      SimpleEx,\r
-      &KeyData,\r
-      NotificationFunction,\r
-      &ShellInfoObject.CtrlSNotifyHandle2);\r
+  Status = SimpleEx->RegisterKeyNotify (\r
+                       SimpleEx,\r
+                       &KeyData,\r
+                       NotificationFunction,\r
+                       &ShellInfoObject.CtrlSNotifyHandle1\r
+                       );\r
+\r
+  KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = SimpleEx->RegisterKeyNotify (\r
+                         SimpleEx,\r
+                         &KeyData,\r
+                         NotificationFunction,\r
+                         &ShellInfoObject.CtrlSNotifyHandle2\r
+                         );\r
   }\r
   }\r
-  KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
-  KeyData.Key.UnicodeChar         = 19;\r
-\r
-  if (!EFI_ERROR(Status)) {\r
-    Status = SimpleEx->RegisterKeyNotify(\r
-      SimpleEx,\r
-      &KeyData,\r
-      NotificationFunction,\r
-      &ShellInfoObject.CtrlSNotifyHandle3);\r
-  }  \r
-  KeyData.KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
-  if (!EFI_ERROR(Status)) {\r
-    Status = SimpleEx->RegisterKeyNotify(\r
-      SimpleEx,\r
-      &KeyData,\r
-      NotificationFunction,\r
-      &ShellInfoObject.CtrlSNotifyHandle4);\r
+\r
+  KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_LEFT_CONTROL_PRESSED;\r
+  KeyData.Key.UnicodeChar        = 19;\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = SimpleEx->RegisterKeyNotify (\r
+                         SimpleEx,\r
+                         &KeyData,\r
+                         NotificationFunction,\r
+                         &ShellInfoObject.CtrlSNotifyHandle3\r
+                         );\r
   }\r
   }\r
-  return (Status);\r
-}\r
 \r
 \r
+  KeyData.KeyState.KeyShiftState = EFI_SHIFT_STATE_VALID|EFI_RIGHT_CONTROL_PRESSED;\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = SimpleEx->RegisterKeyNotify (\r
+                         SimpleEx,\r
+                         &KeyData,\r
+                         NotificationFunction,\r
+                         &ShellInfoObject.CtrlSNotifyHandle4\r
+                         );\r
+  }\r
 \r
 \r
+  return (Status);\r
+}\r
 \r
 /**\r
   The entry point for the application.\r
 \r
 /**\r
   The entry point for the application.\r
@@ -344,46 +358,47 @@ UefiMain (
   EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *OldConIn;\r
   SPLIT_LIST                      *Split;\r
 \r
   EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *OldConIn;\r
   SPLIT_LIST                      *Split;\r
 \r
-  if (PcdGet8(PcdShellSupportLevel) > 3) {\r
+  if (PcdGet8 (PcdShellSupportLevel) > 3) {\r
     return (EFI_UNSUPPORTED);\r
   }\r
 \r
   //\r
   // Clear the screen\r
   //\r
     return (EFI_UNSUPPORTED);\r
   }\r
 \r
   //\r
   // Clear the screen\r
   //\r
-  Status = gST->ConOut->ClearScreen(gST->ConOut);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = gST->ConOut->ClearScreen (gST->ConOut);\r
+  if (EFI_ERROR (Status)) {\r
     return (Status);\r
   }\r
 \r
   //\r
   // Populate the global structure from PCDs\r
   //\r
     return (Status);\r
   }\r
 \r
   //\r
   // Populate the global structure from PCDs\r
   //\r
-  ShellInfoObject.ImageDevPath                = NULL;\r
-  ShellInfoObject.FileDevPath                 = NULL;\r
-  ShellInfoObject.PageBreakEnabled            = PcdGetBool(PcdShellPageBreakDefault);\r
-  ShellInfoObject.ViewingSettings.InsertMode  = PcdGetBool(PcdShellInsertModeDefault);\r
-  ShellInfoObject.LogScreenCount              = PcdGet8   (PcdShellScreenLogCount  );\r
+  ShellInfoObject.ImageDevPath               = NULL;\r
+  ShellInfoObject.FileDevPath                = NULL;\r
+  ShellInfoObject.PageBreakEnabled           = PcdGetBool (PcdShellPageBreakDefault);\r
+  ShellInfoObject.ViewingSettings.InsertMode = PcdGetBool (PcdShellInsertModeDefault);\r
+  ShellInfoObject.LogScreenCount             = PcdGet8 (PcdShellScreenLogCount);\r
 \r
   //\r
   // verify we dont allow for spec violation\r
   //\r
 \r
   //\r
   // verify we dont allow for spec violation\r
   //\r
-  ASSERT(ShellInfoObject.LogScreenCount >= 3);\r
+  ASSERT (ShellInfoObject.LogScreenCount >= 3);\r
 \r
   //\r
   // Initialize the LIST ENTRY objects...\r
   //\r
 \r
   //\r
   // Initialize the LIST ENTRY objects...\r
   //\r
-  InitializeListHead(&ShellInfoObject.BufferToFreeList.Link);\r
-  InitializeListHead(&ShellInfoObject.ViewingSettings.CommandHistory.Link);\r
-  InitializeListHead(&ShellInfoObject.SplitList.Link);\r
+  InitializeListHead (&ShellInfoObject.BufferToFreeList.Link);\r
+  InitializeListHead (&ShellInfoObject.ViewingSettings.CommandHistory.Link);\r
+  InitializeListHead (&ShellInfoObject.SplitList.Link);\r
 \r
   //\r
   // Check PCDs for optional features that are not implemented yet.\r
   //\r
 \r
   //\r
   // Check PCDs for optional features that are not implemented yet.\r
   //\r
-  if (   PcdGetBool(PcdShellSupportOldProtocols)\r
-      || !FeaturePcdGet(PcdShellRequireHiiPlatform)\r
-      || FeaturePcdGet(PcdShellSupportFrameworkHii)\r
-   ) {\r
+  if (  PcdGetBool (PcdShellSupportOldProtocols)\r
+     || !FeaturePcdGet (PcdShellRequireHiiPlatform)\r
+     || FeaturePcdGet (PcdShellSupportFrameworkHii)\r
+        )\r
+  {\r
     return (EFI_UNSUPPORTED);\r
   }\r
 \r
     return (EFI_UNSUPPORTED);\r
   }\r
 \r
@@ -395,8 +410,8 @@ UefiMain (
   //\r
   // install our console logger.  This will keep a log of the output for back-browsing\r
   //\r
   //\r
   // install our console logger.  This will keep a log of the output for back-browsing\r
   //\r
-  Status = ConsoleLoggerInstall(ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);\r
-  if (!EFI_ERROR(Status)) {\r
+  Status = ConsoleLoggerInstall (ShellInfoObject.LogScreenCount, &ShellInfoObject.ConsoleInfo);\r
+  if (!EFI_ERROR (Status)) {\r
     //\r
     // Enable the cursor to be visible\r
     //\r
     //\r
     // Enable the cursor to be visible\r
     //\r
@@ -407,16 +422,17 @@ UefiMain (
     // only do this if PcdShellRequireHiiPlatform == FALSE\r
     //\r
     // remove EFI_UNSUPPORTED check above when complete.\r
     // only do this if PcdShellRequireHiiPlatform == FALSE\r
     //\r
     // remove EFI_UNSUPPORTED check above when complete.\r
-    ///@todo add support for Framework HII\r
+    /// @todo add support for Framework HII\r
 \r
     //\r
     // install our (solitary) HII package\r
     //\r
     ShellInfoObject.HiiHandle = HiiAddPackages (&gEfiCallerIdGuid, gImageHandle, ShellStrings, NULL);\r
     if (ShellInfoObject.HiiHandle == NULL) {\r
 \r
     //\r
     // install our (solitary) HII package\r
     //\r
     ShellInfoObject.HiiHandle = HiiAddPackages (&gEfiCallerIdGuid, gImageHandle, ShellStrings, NULL);\r
     if (ShellInfoObject.HiiHandle == NULL) {\r
-      if (PcdGetBool(PcdShellSupportFrameworkHii)) {\r
-        ///@todo Add our package into Framework HII\r
+      if (PcdGetBool (PcdShellSupportFrameworkHii)) {\r
+        /// @todo Add our package into Framework HII\r
       }\r
       }\r
+\r
       if (ShellInfoObject.HiiHandle == NULL) {\r
         Status = EFI_NOT_STARTED;\r
         goto FreeResources;\r
       if (ShellInfoObject.HiiHandle == NULL) {\r
         Status = EFI_NOT_STARTED;\r
         goto FreeResources;\r
@@ -426,25 +442,25 @@ UefiMain (
     //\r
     // create and install the EfiShellParametersProtocol\r
     //\r
     //\r
     // create and install the EfiShellParametersProtocol\r
     //\r
-    Status = CreatePopulateInstallShellParametersProtocol(&ShellInfoObject.NewShellParametersProtocol, &ShellInfoObject.RootShellInstance);\r
-    ASSERT_EFI_ERROR(Status);\r
-    ASSERT(ShellInfoObject.NewShellParametersProtocol != NULL);\r
+    Status = CreatePopulateInstallShellParametersProtocol (&ShellInfoObject.NewShellParametersProtocol, &ShellInfoObject.RootShellInstance);\r
+    ASSERT_EFI_ERROR (Status);\r
+    ASSERT (ShellInfoObject.NewShellParametersProtocol != NULL);\r
 \r
     //\r
     // create and install the EfiShellProtocol\r
     //\r
 \r
     //\r
     // create and install the EfiShellProtocol\r
     //\r
-    Status = CreatePopulateInstallShellProtocol(&ShellInfoObject.NewEfiShellProtocol);\r
-    ASSERT_EFI_ERROR(Status);\r
-    ASSERT(ShellInfoObject.NewEfiShellProtocol != NULL);\r
+    Status = CreatePopulateInstallShellProtocol (&ShellInfoObject.NewEfiShellProtocol);\r
+    ASSERT_EFI_ERROR (Status);\r
+    ASSERT (ShellInfoObject.NewEfiShellProtocol != NULL);\r
 \r
     //\r
     // Now initialize the shell library (it requires Shell Parameters protocol)\r
     //\r
 \r
     //\r
     // Now initialize the shell library (it requires Shell Parameters protocol)\r
     //\r
-    Status = ShellInitialize();\r
-    ASSERT_EFI_ERROR(Status);\r
+    Status = ShellInitialize ();\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
 \r
-    Status = CommandInit();\r
-    ASSERT_EFI_ERROR(Status);\r
+    Status = CommandInit ();\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
     Status = ShellInitEnvVarList ();\r
 \r
 \r
     Status = ShellInitEnvVarList ();\r
 \r
@@ -459,39 +475,44 @@ UefiMain (
     //\r
     // If shell support level is >= 1 create the mappings and paths\r
     //\r
     //\r
     // If shell support level is >= 1 create the mappings and paths\r
     //\r
-    if (PcdGet8(PcdShellSupportLevel) >= 1) {\r
-      Status = ShellCommandCreateInitialMappingsAndPaths();\r
+    if (PcdGet8 (PcdShellSupportLevel) >= 1) {\r
+      Status = ShellCommandCreateInitialMappingsAndPaths ();\r
     }\r
 \r
     //\r
     // Set the environment variable for nesting support\r
     //\r
     }\r
 \r
     //\r
     // Set the environment variable for nesting support\r
     //\r
-    Size = 0;\r
+    Size       = 0;\r
     TempString = NULL;\r
     if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest) {\r
       //\r
       // No change.  require nesting in Shell Protocol Execute()\r
       //\r
     TempString = NULL;\r
     if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest) {\r
       //\r
       // No change.  require nesting in Shell Protocol Execute()\r
       //\r
-      StrnCatGrow(&TempString,\r
-                  &Size,\r
-                  L"False",\r
-                  0);\r
+      StrnCatGrow (\r
+        &TempString,\r
+        &Size,\r
+        L"False",\r
+        0\r
+        );\r
     } else {\r
     } else {\r
-      StrnCatGrow(&TempString,\r
-                  &Size,\r
-                  mNoNestingTrue,\r
-                  0);\r
+      StrnCatGrow (\r
+        &TempString,\r
+        &Size,\r
+        mNoNestingTrue,\r
+        0\r
+        );\r
     }\r
     }\r
-    Status = InternalEfiShellSetEnv(mNoNestingEnvVarName, TempString, TRUE);\r
-    SHELL_FREE_NON_NULL(TempString);\r
+\r
+    Status = InternalEfiShellSetEnv (mNoNestingEnvVarName, TempString, TRUE);\r
+    SHELL_FREE_NON_NULL (TempString);\r
     Size = 0;\r
 \r
     //\r
     // save the device path for the loaded image and the device path for the filepath (under loaded image)\r
     // These are where to look for the startup.nsh file\r
     //\r
     Size = 0;\r
 \r
     //\r
     // save the device path for the loaded image and the device path for the filepath (under loaded image)\r
     // These are where to look for the startup.nsh file\r
     //\r
-    Status = GetDevicePathsForImageAndFile(&ShellInfoObject.ImageDevPath, &ShellInfoObject.FileDevPath);\r
-    ASSERT_EFI_ERROR(Status);\r
+    Status = GetDevicePathsForImageAndFile (&ShellInfoObject.ImageDevPath, &ShellInfoObject.FileDevPath);\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
     // Display the version\r
 \r
     //\r
     // Display the version\r
@@ -503,10 +524,10 @@ UefiMain (
         NULL,\r
         STRING_TOKEN (STR_VER_OUTPUT_MAIN_SHELL),\r
         ShellInfoObject.HiiHandle,\r
         NULL,\r
         STRING_TOKEN (STR_VER_OUTPUT_MAIN_SHELL),\r
         ShellInfoObject.HiiHandle,\r
-        SupportLevel[PcdGet8(PcdShellSupportLevel)],\r
+        SupportLevel[PcdGet8 (PcdShellSupportLevel)],\r
         gEfiShellProtocol->MajorVersion,\r
         gEfiShellProtocol->MinorVersion\r
         gEfiShellProtocol->MajorVersion,\r
         gEfiShellProtocol->MinorVersion\r
-       );\r
+        );\r
 \r
       ShellPrintHiiEx (\r
         -1,\r
 \r
       ShellPrintHiiEx (\r
         -1,\r
@@ -514,8 +535,8 @@ UefiMain (
         NULL,\r
         STRING_TOKEN (STR_VER_OUTPUT_MAIN_SUPPLIER),\r
         ShellInfoObject.HiiHandle,\r
         NULL,\r
         STRING_TOKEN (STR_VER_OUTPUT_MAIN_SUPPLIER),\r
         ShellInfoObject.HiiHandle,\r
-        (CHAR16 *) PcdGetPtr (PcdShellSupplier)\r
-       );\r
+        (CHAR16 *)PcdGetPtr (PcdShellSupplier)\r
+        );\r
 \r
       ShellPrintHiiEx (\r
         -1,\r
 \r
       ShellPrintHiiEx (\r
         -1,\r
@@ -527,83 +548,83 @@ UefiMain (
         (gST->Hdr.Revision&0x0000ffff),\r
         gST->FirmwareVendor,\r
         gST->FirmwareRevision\r
         (gST->Hdr.Revision&0x0000ffff),\r
         gST->FirmwareVendor,\r
         gST->FirmwareRevision\r
-       );\r
+        );\r
     }\r
 \r
     //\r
     // Display the mapping\r
     //\r
     }\r
 \r
     //\r
     // Display the mapping\r
     //\r
-    if (PcdGet8(PcdShellSupportLevel) >= 2 && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {\r
-      Status = RunCommand(L"map");\r
-      ASSERT_EFI_ERROR(Status);\r
+    if ((PcdGet8 (PcdShellSupportLevel) >= 2) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap) {\r
+      Status = RunCommand (L"map");\r
+      ASSERT_EFI_ERROR (Status);\r
     }\r
 \r
     //\r
     // init all the built in alias'\r
     //\r
     }\r
 \r
     //\r
     // init all the built in alias'\r
     //\r
-    Status = SetBuiltInAlias();\r
-    ASSERT_EFI_ERROR(Status);\r
+    Status = SetBuiltInAlias ();\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
     //\r
     // Initialize environment variables\r
     //\r
 \r
     //\r
     // Initialize environment variables\r
     //\r
-    if (ShellCommandGetProfileList() != NULL) {\r
-      Status = InternalEfiShellSetEnv(L"profiles", ShellCommandGetProfileList(), TRUE);\r
-      ASSERT_EFI_ERROR(Status);\r
+    if (ShellCommandGetProfileList () != NULL) {\r
+      Status = InternalEfiShellSetEnv (L"profiles", ShellCommandGetProfileList (), TRUE);\r
+      ASSERT_EFI_ERROR (Status);\r
     }\r
 \r
     }\r
 \r
-    Size        = 100;\r
-    TempString  = AllocateZeroPool(Size);\r
+    Size       = 100;\r
+    TempString = AllocateZeroPool (Size);\r
 \r
 \r
-    UnicodeSPrint(TempString, Size, L"%d", PcdGet8(PcdShellSupportLevel));\r
-    Status = InternalEfiShellSetEnv(L"uefishellsupport", TempString, TRUE);\r
-    ASSERT_EFI_ERROR(Status);\r
+    UnicodeSPrint (TempString, Size, L"%d", PcdGet8 (PcdShellSupportLevel));\r
+    Status = InternalEfiShellSetEnv (L"uefishellsupport", TempString, TRUE);\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
 \r
-    UnicodeSPrint(TempString, Size, L"%d.%d", ShellInfoObject.NewEfiShellProtocol->MajorVersion, ShellInfoObject.NewEfiShellProtocol->MinorVersion);\r
-    Status = InternalEfiShellSetEnv(L"uefishellversion", TempString, TRUE);\r
-    ASSERT_EFI_ERROR(Status);\r
+    UnicodeSPrint (TempString, Size, L"%d.%d", ShellInfoObject.NewEfiShellProtocol->MajorVersion, ShellInfoObject.NewEfiShellProtocol->MinorVersion);\r
+    Status = InternalEfiShellSetEnv (L"uefishellversion", TempString, TRUE);\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
 \r
-    UnicodeSPrint(TempString, Size, L"%d.%d", (gST->Hdr.Revision & 0xFFFF0000) >> 16, gST->Hdr.Revision & 0x0000FFFF);\r
-    Status = InternalEfiShellSetEnv(L"uefiversion", TempString, TRUE);\r
-    ASSERT_EFI_ERROR(Status);\r
+    UnicodeSPrint (TempString, Size, L"%d.%d", (gST->Hdr.Revision & 0xFFFF0000) >> 16, gST->Hdr.Revision & 0x0000FFFF);\r
+    Status = InternalEfiShellSetEnv (L"uefiversion", TempString, TRUE);\r
+    ASSERT_EFI_ERROR (Status);\r
 \r
 \r
-    FreePool(TempString);\r
+    FreePool (TempString);\r
 \r
 \r
-    if (!EFI_ERROR(Status)) {\r
+    if (!EFI_ERROR (Status)) {\r
       if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {\r
         //\r
         // Set up the event for CTRL-C monitoring...\r
         //\r
       if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt) {\r
         //\r
         // Set up the event for CTRL-C monitoring...\r
         //\r
-        Status = InernalEfiShellStartMonitor();\r
+        Status = InernalEfiShellStartMonitor ();\r
       }\r
 \r
       }\r
 \r
-      if (!EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
+      if (!EFI_ERROR (Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
         //\r
         // Set up the event for CTRL-S monitoring...\r
         //\r
         //\r
         // Set up the event for CTRL-S monitoring...\r
         //\r
-        Status = InternalEfiShellStartCtrlSMonitor();\r
+        Status = InternalEfiShellStartCtrlSMonitor ();\r
       }\r
 \r
       }\r
 \r
-      if (!EFI_ERROR(Status) && ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
+      if (!EFI_ERROR (Status) && ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
         //\r
         // close off the gST->ConIn\r
         //\r
         //\r
         // close off the gST->ConIn\r
         //\r
-        OldConIn      = gST->ConIn;\r
-        ConInHandle   = gST->ConsoleInHandle;\r
-        gST->ConIn = CreateSimpleTextInOnFile((SHELL_FILE_HANDLE)&FileInterfaceNulFile, &gST->ConsoleInHandle);\r
+        OldConIn    = gST->ConIn;\r
+        ConInHandle = gST->ConsoleInHandle;\r
+        gST->ConIn  = CreateSimpleTextInOnFile ((SHELL_FILE_HANDLE)&FileInterfaceNulFile, &gST->ConsoleInHandle);\r
       } else {\r
       } else {\r
-        OldConIn      = NULL;\r
-        ConInHandle   = NULL;\r
+        OldConIn    = NULL;\r
+        ConInHandle = NULL;\r
       }\r
 \r
       }\r
 \r
-      if (!EFI_ERROR(Status) && PcdGet8(PcdShellSupportLevel) >= 1) {\r
+      if (!EFI_ERROR (Status) && (PcdGet8 (PcdShellSupportLevel) >= 1)) {\r
         //\r
         // process the startup script or launch the called app.\r
         //\r
         //\r
         // process the startup script or launch the called app.\r
         //\r
-        Status = DoStartupScript(ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);\r
+        Status = DoStartupScript (ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);\r
       }\r
 \r
       }\r
 \r
-      if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit() && (PcdGet8(PcdShellSupportLevel) >= 3 || PcdGetBool(PcdShellForceConsole)) && !EFI_ERROR(Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
+      if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit && !ShellCommandGetExit () && ((PcdGet8 (PcdShellSupportLevel) >= 3) || PcdGetBool (PcdShellForceConsole)) && !EFI_ERROR (Status) && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
         //\r
         // begin the UI waiting loop\r
         //\r
         //\r
         // begin the UI waiting loop\r
         //\r
@@ -612,33 +633,29 @@ UefiMain (
           // clean out all the memory allocated for CONST <something> * return values\r
           // between each shell prompt presentation\r
           //\r
           // clean out all the memory allocated for CONST <something> * return values\r
           // between each shell prompt presentation\r
           //\r
-          if (!IsListEmpty(&ShellInfoObject.BufferToFreeList.Link)){\r
-            FreeBufferList(&ShellInfoObject.BufferToFreeList);\r
+          if (!IsListEmpty (&ShellInfoObject.BufferToFreeList.Link)) {\r
+            FreeBufferList (&ShellInfoObject.BufferToFreeList);\r
           }\r
 \r
           //\r
           // Reset page break back to default.\r
           //\r
           }\r
 \r
           //\r
           // Reset page break back to default.\r
           //\r
-          ShellInfoObject.PageBreakEnabled        = PcdGetBool(PcdShellPageBreakDefault);\r
+          ShellInfoObject.PageBreakEnabled = PcdGetBool (PcdShellPageBreakDefault);\r
           ASSERT (ShellInfoObject.ConsoleInfo != NULL);\r
           ShellInfoObject.ConsoleInfo->Enabled    = TRUE;\r
           ShellInfoObject.ConsoleInfo->RowCounter = 0;\r
 \r
           ASSERT (ShellInfoObject.ConsoleInfo != NULL);\r
           ShellInfoObject.ConsoleInfo->Enabled    = TRUE;\r
           ShellInfoObject.ConsoleInfo->RowCounter = 0;\r
 \r
-          //\r
-          // Reset the CTRL-C event (yes we ignore the return values)\r
-          //\r
-          Status = gBS->CheckEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);\r
-\r
           //\r
           // Display Prompt\r
           //\r
           //\r
           // Display Prompt\r
           //\r
-          Status = DoShellPrompt();\r
-        } while (!ShellCommandGetExit());\r
+          Status = DoShellPrompt ();\r
+        } while (!ShellCommandGetExit ());\r
       }\r
       }\r
-      if (OldConIn != NULL && ConInHandle != NULL) {\r
+\r
+      if ((OldConIn != NULL) && (ConInHandle != NULL)) {\r
         CloseSimpleTextInOnFile (gST->ConIn);\r
         CloseSimpleTextInOnFile (gST->ConIn);\r
-        gST->ConIn            = OldConIn;\r
-        gST->ConsoleInHandle  = ConInHandle;\r
+        gST->ConIn           = OldConIn;\r
+        gST->ConsoleInHandle = ConInHandle;\r
       }\r
     }\r
   }\r
       }\r
     }\r
   }\r
@@ -648,79 +665,105 @@ FreeResources:
   // uninstall protocols / free memory / etc...\r
   //\r
   if (ShellInfoObject.UserBreakTimer != NULL) {\r
   // uninstall protocols / free memory / etc...\r
   //\r
   if (ShellInfoObject.UserBreakTimer != NULL) {\r
-    gBS->CloseEvent(ShellInfoObject.UserBreakTimer);\r
-    DEBUG_CODE(ShellInfoObject.UserBreakTimer = NULL;);\r
+    gBS->CloseEvent (ShellInfoObject.UserBreakTimer);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.UserBreakTimer = NULL;\r
+      );\r
   }\r
   }\r
+\r
   if (ShellInfoObject.ImageDevPath != NULL) {\r
   if (ShellInfoObject.ImageDevPath != NULL) {\r
-    FreePool(ShellInfoObject.ImageDevPath);\r
-    DEBUG_CODE(ShellInfoObject.ImageDevPath = NULL;);\r
+    FreePool (ShellInfoObject.ImageDevPath);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.ImageDevPath = NULL;\r
+      );\r
   }\r
   }\r
+\r
   if (ShellInfoObject.FileDevPath != NULL) {\r
   if (ShellInfoObject.FileDevPath != NULL) {\r
-    FreePool(ShellInfoObject.FileDevPath);\r
-    DEBUG_CODE(ShellInfoObject.FileDevPath = NULL;);\r
+    FreePool (ShellInfoObject.FileDevPath);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.FileDevPath = NULL;\r
+      );\r
   }\r
   }\r
+\r
   if (ShellInfoObject.NewShellParametersProtocol != NULL) {\r
   if (ShellInfoObject.NewShellParametersProtocol != NULL) {\r
-    CleanUpShellParametersProtocol(ShellInfoObject.NewShellParametersProtocol);\r
-    DEBUG_CODE(ShellInfoObject.NewShellParametersProtocol = NULL;);\r
+    CleanUpShellParametersProtocol (ShellInfoObject.NewShellParametersProtocol);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.NewShellParametersProtocol = NULL;\r
+      );\r
   }\r
   }\r
-  if (ShellInfoObject.NewEfiShellProtocol != NULL){\r
-    if (ShellInfoObject.NewEfiShellProtocol->IsRootShell()){\r
-      InternalEfiShellSetEnv(L"cwd", NULL, TRUE);\r
+\r
+  if (ShellInfoObject.NewEfiShellProtocol != NULL) {\r
+    if (ShellInfoObject.NewEfiShellProtocol->IsRootShell ()) {\r
+      InternalEfiShellSetEnv (L"cwd", NULL, TRUE);\r
     }\r
     }\r
-    CleanUpShellProtocol(ShellInfoObject.NewEfiShellProtocol);\r
-    DEBUG_CODE(ShellInfoObject.NewEfiShellProtocol = NULL;);\r
+\r
+    CleanUpShellEnvironment (ShellInfoObject.NewEfiShellProtocol);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.NewEfiShellProtocol = NULL;\r
+      );\r
   }\r
 \r
   }\r
 \r
-  if (!IsListEmpty(&ShellInfoObject.BufferToFreeList.Link)){\r
-    FreeBufferList(&ShellInfoObject.BufferToFreeList);\r
+  if (!IsListEmpty (&ShellInfoObject.BufferToFreeList.Link)) {\r
+    FreeBufferList (&ShellInfoObject.BufferToFreeList);\r
   }\r
 \r
   }\r
 \r
-  if (!IsListEmpty(&ShellInfoObject.SplitList.Link)){\r
-    ASSERT(FALSE); ///@todo finish this de-allocation (free SplitStdIn/Out when needed).\r
+  if (!IsListEmpty (&ShellInfoObject.SplitList.Link)) {\r
+    ASSERT (FALSE); /// @todo finish this de-allocation (free SplitStdIn/Out when needed).\r
 \r
 \r
-    for ( Split = (SPLIT_LIST*)GetFirstNode (&ShellInfoObject.SplitList.Link)\r
-        ; !IsNull (&ShellInfoObject.SplitList.Link, &Split->Link)\r
-        ; Split = (SPLIT_LIST *)GetNextNode (&ShellInfoObject.SplitList.Link, &Split->Link)\r
-     ) {\r
+    for ( Split = (SPLIT_LIST *)GetFirstNode (&ShellInfoObject.SplitList.Link)\r
+          ; !IsNull (&ShellInfoObject.SplitList.Link, &Split->Link)\r
+          ; Split = (SPLIT_LIST *)GetNextNode (&ShellInfoObject.SplitList.Link, &Split->Link)\r
+          )\r
+    {\r
       RemoveEntryList (&Split->Link);\r
       FreePool (Split);\r
     }\r
 \r
       RemoveEntryList (&Split->Link);\r
       FreePool (Split);\r
     }\r
 \r
-    DEBUG_CODE (InitializeListHead (&ShellInfoObject.SplitList.Link););\r
+    DEBUG_CODE (\r
+      InitializeListHead (&ShellInfoObject.SplitList.Link);\r
+      );\r
   }\r
 \r
   if (ShellInfoObject.ShellInitSettings.FileName != NULL) {\r
   }\r
 \r
   if (ShellInfoObject.ShellInitSettings.FileName != NULL) {\r
-    FreePool(ShellInfoObject.ShellInitSettings.FileName);\r
-    DEBUG_CODE(ShellInfoObject.ShellInitSettings.FileName = NULL;);\r
+    FreePool (ShellInfoObject.ShellInitSettings.FileName);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.ShellInitSettings.FileName = NULL;\r
+      );\r
   }\r
 \r
   if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
   }\r
 \r
   if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
-    FreePool(ShellInfoObject.ShellInitSettings.FileOptions);\r
-    DEBUG_CODE(ShellInfoObject.ShellInitSettings.FileOptions = NULL;);\r
+    FreePool (ShellInfoObject.ShellInitSettings.FileOptions);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.ShellInitSettings.FileOptions = NULL;\r
+      );\r
   }\r
 \r
   if (ShellInfoObject.HiiHandle != NULL) {\r
   }\r
 \r
   if (ShellInfoObject.HiiHandle != NULL) {\r
-    HiiRemovePackages(ShellInfoObject.HiiHandle);\r
-    DEBUG_CODE(ShellInfoObject.HiiHandle = NULL;);\r
+    HiiRemovePackages (ShellInfoObject.HiiHandle);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.HiiHandle = NULL;\r
+      );\r
   }\r
 \r
   }\r
 \r
-  if (!IsListEmpty(&ShellInfoObject.ViewingSettings.CommandHistory.Link)){\r
-    FreeBufferList(&ShellInfoObject.ViewingSettings.CommandHistory);\r
+  if (!IsListEmpty (&ShellInfoObject.ViewingSettings.CommandHistory.Link)) {\r
+    FreeBufferList (&ShellInfoObject.ViewingSettings.CommandHistory);\r
   }\r
 \r
   }\r
 \r
-  ASSERT(ShellInfoObject.ConsoleInfo != NULL);\r
+  ASSERT (ShellInfoObject.ConsoleInfo != NULL);\r
   if (ShellInfoObject.ConsoleInfo != NULL) {\r
   if (ShellInfoObject.ConsoleInfo != NULL) {\r
-    ConsoleLoggerUninstall(ShellInfoObject.ConsoleInfo);\r
-    FreePool(ShellInfoObject.ConsoleInfo);\r
-    DEBUG_CODE(ShellInfoObject.ConsoleInfo = NULL;);\r
+    ConsoleLoggerUninstall (ShellInfoObject.ConsoleInfo);\r
+    FreePool (ShellInfoObject.ConsoleInfo);\r
+    DEBUG_CODE (\r
+      ShellInfoObject.ConsoleInfo = NULL;\r
+      );\r
   }\r
 \r
   ShellFreeEnvVarList ();\r
   }\r
 \r
   ShellFreeEnvVarList ();\r
-  ShellSetRawCmdLine (NULL);\r
 \r
 \r
-  if (ShellCommandGetExit()) {\r
-    return ((EFI_STATUS)ShellCommandGetExitCode());\r
+  if (ShellCommandGetExit ()) {\r
+    return ((EFI_STATUS)ShellCommandGetExitCode ());\r
   }\r
   }\r
+\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
@@ -730,32 +773,34 @@ FreeResources:
   @retval EFI_SUCCESS           all init commands were run successfully.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_SUCCESS           all init commands were run successfully.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-SetBuiltInAlias(\r
+SetBuiltInAlias (\r
+  VOID\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
-  CONST ALIAS_LIST    *List;\r
-  ALIAS_LIST          *Node;\r
+  EFI_STATUS        Status;\r
+  CONST ALIAS_LIST  *List;\r
+  ALIAS_LIST        *Node;\r
 \r
   //\r
   // Get all the commands we want to run\r
   //\r
 \r
   //\r
   // Get all the commands we want to run\r
   //\r
-  List = ShellCommandGetInitAliasList();\r
+  List = ShellCommandGetInitAliasList ();\r
 \r
   //\r
   // for each command in the List\r
   //\r
 \r
   //\r
   // for each command in the List\r
   //\r
-  for ( Node = (ALIAS_LIST*)GetFirstNode(&List->Link)\r
-      ; !IsNull (&List->Link, &Node->Link)\r
-      ; Node = (ALIAS_LIST *)GetNextNode(&List->Link, &Node->Link)\r
-   ){\r
+  for ( Node = (ALIAS_LIST *)GetFirstNode (&List->Link)\r
+        ; !IsNull (&List->Link, &Node->Link)\r
+        ; Node = (ALIAS_LIST *)GetNextNode (&List->Link, &Node->Link)\r
+        )\r
+  {\r
     //\r
     // install the alias'\r
     //\r
     //\r
     // install the alias'\r
     //\r
-    Status = InternalSetAlias(Node->CommandString, Node->Alias, TRUE);\r
-    ASSERT_EFI_ERROR(Status);\r
+    Status = InternalSetAlias (Node->CommandString, Node->Alias, TRUE);\r
+    ASSERT_EFI_ERROR (Status);\r
   }\r
   }\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -769,15 +814,15 @@ SetBuiltInAlias(
   @retval FALSE             The 2 command names are not the same.\r
 **/\r
 BOOLEAN\r
   @retval FALSE             The 2 command names are not the same.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
-IsCommand(\r
-  IN CONST CHAR16 *Command1,\r
-  IN CONST CHAR16 *Command2\r
+IsCommand (\r
+  IN CONST CHAR16  *Command1,\r
+  IN CONST CHAR16  *Command2\r
   )\r
 {\r
   )\r
 {\r
-  if (StringNoCaseCompare(&Command1, &Command2) == 0) {\r
+  if (StringNoCaseCompare (&Command1, &Command2) == 0) {\r
     return (TRUE);\r
   }\r
     return (TRUE);\r
   }\r
+\r
   return (FALSE);\r
 }\r
 \r
   return (FALSE);\r
 }\r
 \r
@@ -790,19 +835,20 @@ IsCommand(
   @retval FALSE             The command is not a script only command.\r
 **/\r
 BOOLEAN\r
   @retval FALSE             The command is not a script only command.\r
 **/\r
 BOOLEAN\r
-EFIAPI\r
-IsScriptOnlyCommand(\r
-  IN CONST CHAR16 *CommandName\r
+IsScriptOnlyCommand (\r
+  IN CONST CHAR16  *CommandName\r
   )\r
 {\r
   )\r
 {\r
-  if (IsCommand(CommandName, L"for")\r
-    ||IsCommand(CommandName, L"endfor")\r
-    ||IsCommand(CommandName, L"if")\r
-    ||IsCommand(CommandName, L"else")\r
-    ||IsCommand(CommandName, L"endif")\r
-    ||IsCommand(CommandName, L"goto")) {\r
+  if (  IsCommand (CommandName, L"for")\r
+     || IsCommand (CommandName, L"endfor")\r
+     || IsCommand (CommandName, L"if")\r
+     || IsCommand (CommandName, L"else")\r
+     || IsCommand (CommandName, L"endif")\r
+     || IsCommand (CommandName, L"goto"))\r
+  {\r
     return (TRUE);\r
   }\r
     return (TRUE);\r
   }\r
+\r
   return (FALSE);\r
 }\r
 \r
   return (FALSE);\r
 }\r
 \r
@@ -821,51 +867,54 @@ IsScriptOnlyCommand(
   @sa HandleProtocol\r
 **/\r
 EFI_STATUS\r
   @sa HandleProtocol\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 GetDevicePathsForImageAndFile (\r
 GetDevicePathsForImageAndFile (\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL **DevPath,\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL  **DevPath,\r
+  IN OUT EFI_DEVICE_PATH_PROTOCOL  **FilePath\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
-  EFI_DEVICE_PATH_PROTOCOL  *ImageDevicePath;\r
+  EFI_STATUS                 Status;\r
+  EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;\r
+  EFI_DEVICE_PATH_PROTOCOL   *ImageDevicePath;\r
 \r
 \r
-  ASSERT(DevPath  != NULL);\r
-  ASSERT(FilePath != NULL);\r
+  ASSERT (DevPath  != NULL);\r
+  ASSERT (FilePath != NULL);\r
 \r
   Status = gBS->OpenProtocol (\r
 \r
   Status = gBS->OpenProtocol (\r
-                gImageHandle,\r
-                &gEfiLoadedImageProtocolGuid,\r
-                (VOID**)&LoadedImage,\r
-                gImageHandle,\r
-                NULL,\r
-                EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-               );\r
-  if (!EFI_ERROR (Status)) {\r
-    Status = gBS->OpenProtocol (\r
-                  LoadedImage->DeviceHandle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  (VOID**)&ImageDevicePath,\r
+                  gImageHandle,\r
+                  &gEfiLoadedImageProtocolGuid,\r
+                  (VOID **)&LoadedImage,\r
                   gImageHandle,\r
                   NULL,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   gImageHandle,\r
                   NULL,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                 );\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->OpenProtocol (\r
+                    LoadedImage->DeviceHandle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    (VOID **)&ImageDevicePath,\r
+                    gImageHandle,\r
+                    NULL,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
     if (!EFI_ERROR (Status)) {\r
       *DevPath  = DuplicateDevicePath (ImageDevicePath);\r
       *FilePath = DuplicateDevicePath (LoadedImage->FilePath);\r
     if (!EFI_ERROR (Status)) {\r
       *DevPath  = DuplicateDevicePath (ImageDevicePath);\r
       *FilePath = DuplicateDevicePath (LoadedImage->FilePath);\r
-      gBS->CloseProtocol(\r
-                  LoadedImage->DeviceHandle,\r
-                  &gEfiDevicePathProtocolGuid,\r
-                  gImageHandle,\r
-                  NULL);\r
+      gBS->CloseProtocol (\r
+             LoadedImage->DeviceHandle,\r
+             &gEfiDevicePathProtocolGuid,\r
+             gImageHandle,\r
+             NULL\r
+             );\r
     }\r
     }\r
-    gBS->CloseProtocol(\r
-                gImageHandle,\r
-                &gEfiLoadedImageProtocolGuid,\r
-                gImageHandle,\r
-                NULL);\r
+\r
+    gBS->CloseProtocol (\r
+           gImageHandle,\r
+           &gEfiLoadedImageProtocolGuid,\r
+           gImageHandle,\r
+           NULL\r
+           );\r
   }\r
   }\r
+\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
@@ -897,8 +946,7 @@ GetDevicePathsForImageAndFile (
   @retval EFI_SUCCESS           The variable is initialized.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_SUCCESS           The variable is initialized.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-ProcessCommandLine(\r
+ProcessCommandLine (\r
   VOID\r
   )\r
 {\r
   VOID\r
   )\r
 {\r
@@ -918,13 +966,13 @@ ProcessCommandLine(
   Status = gBS->LocateProtocol (\r
                   &gEfiUnicodeCollation2ProtocolGuid,\r
                   NULL,\r
   Status = gBS->LocateProtocol (\r
                   &gEfiUnicodeCollation2ProtocolGuid,\r
                   NULL,\r
-                  (VOID **) &UnicodeCollation\r
+                  (VOID **)&UnicodeCollation\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     Status = gBS->LocateProtocol (\r
                     &gEfiUnicodeCollationProtocolGuid,\r
                     NULL,\r
                   );\r
   if (EFI_ERROR (Status)) {\r
     Status = gBS->LocateProtocol (\r
                     &gEfiUnicodeCollationProtocolGuid,\r
                     NULL,\r
-                    (VOID **) &UnicodeCollation\r
+                    (VOID **)&UnicodeCollation\r
                     );\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
                     );\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
@@ -942,7 +990,7 @@ ProcessCommandLine(
   ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay        = FALSE;\r
   ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit         = FALSE;\r
   ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest       = FALSE;\r
   ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay        = FALSE;\r
   ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit         = FALSE;\r
   ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest       = FALSE;\r
-  ShellInfoObject.ShellInitSettings.Delay = 5;\r
+  ShellInfoObject.ShellInitSettings.Delay                      = 5;\r
 \r
   //\r
   // Start LoopVar at 0 to parse only optional arguments at Argv[0]\r
 \r
   //\r
   // Start LoopVar at 0 to parse only optional arguments at Argv[0]\r
@@ -950,95 +998,109 @@ ProcessCommandLine(
   // UEFI Shell boot option is created, and OptionalData is provided\r
   // that starts with shell command-line options.\r
   //\r
   // UEFI Shell boot option is created, and OptionalData is provided\r
   // that starts with shell command-line options.\r
   //\r
-  for (LoopVar = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r
+  for (LoopVar = 0; LoopVar < gEfiShellParametersProtocol->Argc; LoopVar++) {\r
     CurrentArg = gEfiShellParametersProtocol->Argv[LoopVar];\r
     if (UnicodeCollation->StriColl (\r
                             UnicodeCollation,\r
                             L"-startup",\r
                             CurrentArg\r
     CurrentArg = gEfiShellParametersProtocol->Argv[LoopVar];\r
     if (UnicodeCollation->StriColl (\r
                             UnicodeCollation,\r
                             L"-startup",\r
                             CurrentArg\r
-                            ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup      = TRUE;\r
-    }\r
-    else if (UnicodeCollation->StriColl (\r
-                                 UnicodeCollation,\r
-                                 L"-nostartup",\r
-                                 CurrentArg\r
-                                 ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup    = TRUE;\r
-    }\r
-    else if (UnicodeCollation->StriColl (\r
-                                 UnicodeCollation,\r
-                                 L"-noconsoleout",\r
-                                 CurrentArg\r
-                                 ) == 0) {\r
+                            ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup = TRUE;\r
+    } else if (UnicodeCollation->StriColl (\r
+                                   UnicodeCollation,\r
+                                   L"-nostartup",\r
+                                   CurrentArg\r
+                                   ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup = TRUE;\r
+    } else if (UnicodeCollation->StriColl (\r
+                                   UnicodeCollation,\r
+                                   L"-noconsoleout",\r
+                                   CurrentArg\r
+                                   ) == 0)\r
+    {\r
       ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut = TRUE;\r
       ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleOut = TRUE;\r
-    }\r
-    else if (UnicodeCollation->StriColl (\r
-                                 UnicodeCollation,\r
-                                 L"-noconsolein",\r
-                                 CurrentArg\r
-                                 ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn  = TRUE;\r
-    }\r
-    else if (UnicodeCollation->StriColl (\r
-                                 UnicodeCollation,\r
-                                 L"-nointerrupt",\r
-                                 CurrentArg\r
-                                 ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt  = TRUE;\r
-    }\r
-    else if (UnicodeCollation->StriColl (\r
-                                 UnicodeCollation,\r
-                                 L"-nomap",\r
-                                 CurrentArg\r
-                                 ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap        = TRUE;\r
-    }\r
-    else if (UnicodeCollation->StriColl (\r
-                                 UnicodeCollation,\r
-                                 L"-noversion",\r
-                                 CurrentArg\r
-                                 ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion    = TRUE;\r
-    }\r
-    else if (UnicodeCollation->StriColl (\r
-                                 UnicodeCollation,\r
-                                 L"-nonest",\r
-                                 CurrentArg\r
-                                 ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest       = TRUE;\r
-    }\r
-    else if (UnicodeCollation->StriColl (\r
-                                 UnicodeCollation,\r
-                                 L"-delay",\r
-                                 CurrentArg\r
-                                 ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay        = TRUE;\r
+    } else if (UnicodeCollation->StriColl (\r
+                                   UnicodeCollation,\r
+                                   L"-noconsolein",\r
+                                   CurrentArg\r
+                                   ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn = TRUE;\r
+    } else if (UnicodeCollation->StriColl (\r
+                                   UnicodeCollation,\r
+                                   L"-nointerrupt",\r
+                                   CurrentArg\r
+                                   ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoInterrupt = TRUE;\r
+    } else if (UnicodeCollation->StriColl (\r
+                                   UnicodeCollation,\r
+                                   L"-nomap",\r
+                                   CurrentArg\r
+                                   ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoMap = TRUE;\r
+    } else if (UnicodeCollation->StriColl (\r
+                                   UnicodeCollation,\r
+                                   L"-noversion",\r
+                                   CurrentArg\r
+                                   ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoVersion = TRUE;\r
+    } else if (UnicodeCollation->StriColl (\r
+                                   UnicodeCollation,\r
+                                   L"-nonest",\r
+                                   CurrentArg\r
+                                   ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoNest = TRUE;\r
+    } else if (UnicodeCollation->StriColl (\r
+                                   UnicodeCollation,\r
+                                   L"-delay",\r
+                                   CurrentArg\r
+                                   ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Delay = TRUE;\r
       // Check for optional delay value following "-delay"\r
       // Check for optional delay value following "-delay"\r
-      DelayValueStr = gEfiShellParametersProtocol->Argv[LoopVar + 1];\r
-      if (DelayValueStr != NULL){\r
+      if ((LoopVar + 1) >= gEfiShellParametersProtocol->Argc) {\r
+        DelayValueStr = NULL;\r
+      } else {\r
+        DelayValueStr = gEfiShellParametersProtocol->Argv[LoopVar + 1];\r
+      }\r
+\r
+      if (DelayValueStr != NULL) {\r
         if (*DelayValueStr == L':') {\r
           DelayValueStr++;\r
         }\r
         if (*DelayValueStr == L':') {\r
           DelayValueStr++;\r
         }\r
-        if (!EFI_ERROR(ShellConvertStringToUint64 (\r
-                        DelayValueStr,\r
-                        &DelayValue,\r
-                        FALSE,\r
-                        FALSE\r
-                        ))) {\r
+\r
+        if (!EFI_ERROR (\r
+               ShellConvertStringToUint64 (\r
+                 DelayValueStr,\r
+                 &DelayValue,\r
+                 FALSE,\r
+                 FALSE\r
+                 )\r
+               ))\r
+        {\r
           ShellInfoObject.ShellInitSettings.Delay = (UINTN)DelayValue;\r
           LoopVar++;\r
         }\r
       }\r
     } else if (UnicodeCollation->StriColl (\r
                                    UnicodeCollation,\r
           ShellInfoObject.ShellInitSettings.Delay = (UINTN)DelayValue;\r
           LoopVar++;\r
         }\r
       }\r
     } else if (UnicodeCollation->StriColl (\r
                                    UnicodeCollation,\r
-                                   L"-_exit",\r
+                                   L"-exit",\r
                                    CurrentArg\r
                                    CurrentArg\r
-                                   ) == 0) {\r
-      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit         = TRUE;\r
+                                   ) == 0)\r
+    {\r
+      ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit = TRUE;\r
     } else if (StrnCmp (L"-", CurrentArg, 1) == 0) {\r
       // Unrecognized option\r
     } else if (StrnCmp (L"-", CurrentArg, 1) == 0) {\r
       // Unrecognized option\r
-      ShellPrintHiiEx(-1, -1, NULL,\r
+      ShellPrintHiiEx (\r
+        -1,\r
+        -1,\r
+        NULL,\r
         STRING_TOKEN (STR_GEN_PROBLEM),\r
         ShellInfoObject.HiiHandle,\r
         CurrentArg\r
         STRING_TOKEN (STR_GEN_PROBLEM),\r
         ShellInfoObject.HiiHandle,\r
         CurrentArg\r
@@ -1052,10 +1114,33 @@ ProcessCommandLine(
         continue;\r
       }\r
 \r
         continue;\r
       }\r
 \r
-      ShellInfoObject.ShellInitSettings.FileName = AllocateCopyPool(StrSize(CurrentArg), CurrentArg);\r
+      ShellInfoObject.ShellInitSettings.FileName = NULL;\r
+      Size                                       = 0;\r
+      //\r
+      // If first argument contains a space, then add double quotes before the argument\r
+      //\r
+      if (StrStr (CurrentArg, L" ") != NULL) {\r
+        StrnCatGrow (&ShellInfoObject.ShellInitSettings.FileName, &Size, L"\"", 0);\r
+        if (ShellInfoObject.ShellInitSettings.FileName == NULL) {\r
+          return (EFI_OUT_OF_RESOURCES);\r
+        }\r
+      }\r
+\r
+      StrnCatGrow (&ShellInfoObject.ShellInitSettings.FileName, &Size, CurrentArg, 0);\r
       if (ShellInfoObject.ShellInitSettings.FileName == NULL) {\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
       if (ShellInfoObject.ShellInitSettings.FileName == NULL) {\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
+\r
+      //\r
+      // If first argument contains a space, then add double quotes after the argument\r
+      //\r
+      if (StrStr (CurrentArg, L" ") != NULL) {\r
+        StrnCatGrow (&ShellInfoObject.ShellInitSettings.FileName, &Size, L"\"", 0);\r
+        if (ShellInfoObject.ShellInitSettings.FileName == NULL) {\r
+          return (EFI_OUT_OF_RESOURCES);\r
+        }\r
+      }\r
+\r
       //\r
       // We found `file-name`.\r
       //\r
       //\r
       // We found `file-name`.\r
       //\r
@@ -1063,24 +1148,61 @@ ProcessCommandLine(
       LoopVar++;\r
 \r
       // Add `file-name-options`\r
       LoopVar++;\r
 \r
       // Add `file-name-options`\r
-      for (Size = 0 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {\r
-        ASSERT((ShellInfoObject.ShellInitSettings.FileOptions == NULL && Size == 0) || (ShellInfoObject.ShellInitSettings.FileOptions != NULL));\r
-        StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,\r
-                    &Size,\r
-                    L" ",\r
-                    0);\r
-        if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r
-          SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);\r
-          return (EFI_OUT_OF_RESOURCES);\r
+      for (Size = 0; LoopVar < gEfiShellParametersProtocol->Argc; LoopVar++) {\r
+        ASSERT ((ShellInfoObject.ShellInitSettings.FileOptions == NULL && Size == 0) || (ShellInfoObject.ShellInitSettings.FileOptions != NULL));\r
+        //\r
+        // Add a space between arguments\r
+        //\r
+        if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
+          StrnCatGrow (&ShellInfoObject.ShellInitSettings.FileOptions, &Size, L" ", 0);\r
+          if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r
+            SHELL_FREE_NON_NULL (ShellInfoObject.ShellInitSettings.FileName);\r
+            return (EFI_OUT_OF_RESOURCES);\r
+          }\r
         }\r
         }\r
-        StrnCatGrow(&ShellInfoObject.ShellInitSettings.FileOptions,\r
-                    &Size,\r
-                    gEfiShellParametersProtocol->Argv[LoopVar],\r
-                    0);\r
+\r
+        //\r
+        // If an argument contains a space, then add double quotes before the argument\r
+        //\r
+        if (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L" ") != NULL) {\r
+          StrnCatGrow (\r
+            &ShellInfoObject.ShellInitSettings.FileOptions,\r
+            &Size,\r
+            L"\"",\r
+            0\r
+            );\r
+          if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r
+            SHELL_FREE_NON_NULL (ShellInfoObject.ShellInitSettings.FileName);\r
+            return (EFI_OUT_OF_RESOURCES);\r
+          }\r
+        }\r
+\r
+        StrnCatGrow (\r
+          &ShellInfoObject.ShellInitSettings.FileOptions,\r
+          &Size,\r
+          gEfiShellParametersProtocol->Argv[LoopVar],\r
+          0\r
+          );\r
         if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r
         if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r
-          SHELL_FREE_NON_NULL(ShellInfoObject.ShellInitSettings.FileName);\r
+          SHELL_FREE_NON_NULL (ShellInfoObject.ShellInitSettings.FileName);\r
           return (EFI_OUT_OF_RESOURCES);\r
         }\r
           return (EFI_OUT_OF_RESOURCES);\r
         }\r
+\r
+        //\r
+        // If an argument contains a space, then add double quotes after the argument\r
+        //\r
+        if (StrStr (gEfiShellParametersProtocol->Argv[LoopVar], L" ") != NULL) {\r
+          StrnCatGrow (\r
+            &ShellInfoObject.ShellInitSettings.FileOptions,\r
+            &Size,\r
+            L"\"",\r
+            0\r
+            );\r
+          if (ShellInfoObject.ShellInitSettings.FileOptions == NULL) {\r
+            SHELL_FREE_NON_NULL (ShellInfoObject.ShellInitSettings.FileName);\r
+            return (EFI_OUT_OF_RESOURCES);\r
+          }\r
+        }\r
       }\r
     }\r
   }\r
       }\r
     }\r
   }\r
@@ -1093,6 +1215,67 @@ ProcessCommandLine(
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Function try to find location of the Startup.nsh file.\r
+\r
+  The buffer is callee allocated and should be freed by the caller.\r
+\r
+  @param    ImageDevicePath       The path to the image for shell.  first place to look for the startup script\r
+  @param    FileDevicePath        The path to the file for shell.  second place to look for the startup script.\r
+\r
+  @retval   NULL                  No Startup.nsh file was found.\r
+  @return   !=NULL                Pointer to NULL-terminated path.\r
+**/\r
+CHAR16 *\r
+LocateStartupScript (\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *ImageDevicePath,\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *FileDevicePath\r
+  )\r
+{\r
+  CHAR16        *StartupScriptPath;\r
+  CHAR16        *TempSpot;\r
+  CONST CHAR16  *MapName;\r
+  UINTN         Size;\r
+\r
+  StartupScriptPath = NULL;\r
+  Size              = 0;\r
+\r
+  //\r
+  // Try to find 'Startup.nsh' in the directory where the shell itself was launched.\r
+  //\r
+  MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath (&ImageDevicePath);\r
+  if (MapName != NULL) {\r
+    StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, MapName, 0);\r
+    if (StartupScriptPath == NULL) {\r
+      //\r
+      // Do not locate the startup script in sys path when out of resource.\r
+      //\r
+      return NULL;\r
+    }\r
+\r
+    TempSpot = StrStr (StartupScriptPath, L";");\r
+    if (TempSpot != NULL) {\r
+      *TempSpot = CHAR_NULL;\r
+    }\r
+\r
+    InternalEfiShellSetEnv (L"homefilesystem", StartupScriptPath, TRUE);\r
+\r
+    StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, ((FILEPATH_DEVICE_PATH *)FileDevicePath)->PathName, 0);\r
+    PathRemoveLastItem (StartupScriptPath);\r
+    StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, mStartupScript, 0);\r
+  }\r
+\r
+  //\r
+  // Try to find 'Startup.nsh' in the execution path defined by the environment variable PATH.\r
+  //\r
+  if ((StartupScriptPath == NULL) || EFI_ERROR (ShellIsFile (StartupScriptPath))) {\r
+    SHELL_FREE_NON_NULL (StartupScriptPath);\r
+    StartupScriptPath = ShellFindFilePath (mStartupScript);\r
+  }\r
+\r
+  return StartupScriptPath;\r
+}\r
+\r
 /**\r
   Handles all interaction with the default startup script.\r
 \r
 /**\r
   Handles all interaction with the default startup script.\r
 \r
@@ -1104,142 +1287,106 @@ ProcessCommandLine(
   @retval EFI_SUCCESS           the variable is initialized.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_SUCCESS           the variable is initialized.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-DoStartupScript(\r
-  IN EFI_DEVICE_PATH_PROTOCOL *ImagePath,\r
-  IN EFI_DEVICE_PATH_PROTOCOL *FilePath\r
+DoStartupScript (\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *ImagePath,\r
+  IN EFI_DEVICE_PATH_PROTOCOL  *FilePath\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                    Status;\r
-  EFI_STATUS                    CalleeStatus;\r
-  UINTN                         Delay;\r
-  EFI_INPUT_KEY                 Key;\r
-  SHELL_FILE_HANDLE             FileHandle;\r
-  EFI_DEVICE_PATH_PROTOCOL      *NewPath;\r
-  EFI_DEVICE_PATH_PROTOCOL      *NamePath;\r
-  CHAR16                        *FileStringPath;\r
-  CHAR16                        *TempSpot;\r
-  UINTN                         NewSize;\r
-  CONST CHAR16                  *MapName;\r
+  EFI_STATUS     Status;\r
+  EFI_STATUS     CalleeStatus;\r
+  UINTN          Delay;\r
+  EFI_INPUT_KEY  Key;\r
+  CHAR16         *FileStringPath;\r
+  CHAR16         *FullFileStringPath;\r
+  UINTN          NewSize;\r
 \r
   Key.UnicodeChar = CHAR_NULL;\r
   Key.ScanCode    = 0;\r
 \r
   Key.UnicodeChar = CHAR_NULL;\r
   Key.ScanCode    = 0;\r
-  FileHandle      = NULL;\r
 \r
 \r
-  if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup && ShellInfoObject.ShellInitSettings.FileName != NULL) {\r
+  if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup && (ShellInfoObject.ShellInitSettings.FileName != NULL)) {\r
     //\r
     // launch something else instead\r
     //\r
     //\r
     // launch something else instead\r
     //\r
-    NewSize = StrSize(ShellInfoObject.ShellInitSettings.FileName);\r
+    NewSize = StrSize (ShellInfoObject.ShellInitSettings.FileName);\r
     if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
     if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
-      NewSize += StrSize(ShellInfoObject.ShellInitSettings.FileOptions) + sizeof(CHAR16);\r
+      NewSize += StrSize (ShellInfoObject.ShellInitSettings.FileOptions) + sizeof (CHAR16);\r
     }\r
     }\r
-    FileStringPath = AllocateZeroPool(NewSize);\r
+\r
+    FileStringPath = AllocateZeroPool (NewSize);\r
     if (FileStringPath == NULL) {\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
     if (FileStringPath == NULL) {\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
-    StrCpyS(FileStringPath, NewSize/sizeof(CHAR16), ShellInfoObject.ShellInitSettings.FileName);\r
+\r
+    StrCpyS (FileStringPath, NewSize/sizeof (CHAR16), ShellInfoObject.ShellInitSettings.FileName);\r
     if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
     if (ShellInfoObject.ShellInitSettings.FileOptions != NULL) {\r
-      StrnCatS(FileStringPath, NewSize/sizeof(CHAR16), L" ", NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
-      StrnCatS(FileStringPath, NewSize/sizeof(CHAR16), ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof(CHAR16) - StrLen(FileStringPath) -1);\r
+      StrnCatS (FileStringPath, NewSize/sizeof (CHAR16), L" ", NewSize/sizeof (CHAR16) - StrLen (FileStringPath) -1);\r
+      StrnCatS (FileStringPath, NewSize/sizeof (CHAR16), ShellInfoObject.ShellInitSettings.FileOptions, NewSize/sizeof (CHAR16) - StrLen (FileStringPath) -1);\r
     }\r
     }\r
-    Status = RunShellCommand(FileStringPath, &CalleeStatus);\r
+\r
+    Status = RunShellCommand (FileStringPath, &CalleeStatus);\r
     if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit == TRUE) {\r
     if (ShellInfoObject.ShellInitSettings.BitUnion.Bits.Exit == TRUE) {\r
-      ShellCommandRegisterExit(gEfiShellProtocol->BatchIsActive(), (UINT64)CalleeStatus);\r
+      ShellCommandRegisterExit (gEfiShellProtocol->BatchIsActive (), (UINT64)CalleeStatus);\r
     }\r
     }\r
-    FreePool(FileStringPath);\r
-    return (Status);\r
 \r
 \r
+    FreePool (FileStringPath);\r
+    return (Status);\r
   }\r
 \r
   //\r
   // for shell level 0 we do no scripts\r
   // Without the Startup bit overriding we allow for nostartup to prevent scripts\r
   //\r
   }\r
 \r
   //\r
   // for shell level 0 we do no scripts\r
   // Without the Startup bit overriding we allow for nostartup to prevent scripts\r
   //\r
-  if ( (PcdGet8(PcdShellSupportLevel) < 1)\r
-    || (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup)\r
-   ){\r
+  if (  (PcdGet8 (PcdShellSupportLevel) < 1)\r
+     || (ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoStartup && !ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup)\r
+        )\r
+  {\r
     return (EFI_SUCCESS);\r
   }\r
 \r
     return (EFI_SUCCESS);\r
   }\r
 \r
-  gST->ConOut->EnableCursor(gST->ConOut, FALSE);\r
+  gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
   //\r
   // print out our warning and see if they press a key\r
   //\r
   for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay\r
   //\r
   // print out our warning and see if they press a key\r
   //\r
   for ( Status = EFI_UNSUPPORTED, Delay = ShellInfoObject.ShellInitSettings.Delay\r
-      ; Delay != 0 && EFI_ERROR(Status)\r
-      ; Delay--\r
-     ){\r
-    ShellPrintHiiEx(0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay);\r
+        ; Delay != 0 && EFI_ERROR (Status)\r
+        ; Delay--\r
+        )\r
+  {\r
+    ShellPrintHiiEx (0, gST->ConOut->Mode->CursorRow, NULL, STRING_TOKEN (STR_SHELL_STARTUP_QUESTION), ShellInfoObject.HiiHandle, Delay);\r
     gBS->Stall (1000000);\r
     if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
       Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
     }\r
   }\r
     gBS->Stall (1000000);\r
     if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.NoConsoleIn) {\r
       Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
     }\r
   }\r
-  ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle);\r
-  gST->ConOut->EnableCursor(gST->ConOut, TRUE);\r
+\r
+  ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_CRLF), ShellInfoObject.HiiHandle);\r
+  gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
 \r
   //\r
   // ESC was pressed\r
   //\r
 \r
   //\r
   // ESC was pressed\r
   //\r
-  if (Status == EFI_SUCCESS && Key.UnicodeChar == 0 && Key.ScanCode == SCAN_ESC) {\r
+  if ((Status == EFI_SUCCESS) && (Key.UnicodeChar == 0) && (Key.ScanCode == SCAN_ESC)) {\r
     return (EFI_SUCCESS);\r
   }\r
 \r
     return (EFI_SUCCESS);\r
   }\r
 \r
-  //\r
-  // Try the first location (must be file system)\r
-  //\r
-  MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath(&ImagePath);\r
-  if (MapName != NULL) {\r
-    FileStringPath = NULL;\r
-    NewSize = 0;\r
-    FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0);\r
-    if (FileStringPath == NULL) {\r
-      Status = EFI_OUT_OF_RESOURCES;\r
+  FileStringPath = LocateStartupScript (ImagePath, FilePath);\r
+  if (FileStringPath != NULL) {\r
+    FullFileStringPath = FullyQualifyPath (FileStringPath);\r
+    if (FullFileStringPath == NULL) {\r
+      Status = RunScriptFile (FileStringPath, NULL, FileStringPath, ShellInfoObject.NewShellParametersProtocol);\r
     } else {\r
     } else {\r
-      TempSpot = StrStr(FileStringPath, L";");\r
-      if (TempSpot != NULL) {\r
-        *TempSpot = CHAR_NULL;\r
-      }\r
-      FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);\r
-      PathRemoveLastItem(FileStringPath);\r
-      FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);\r
-      Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);\r
-      FreePool(FileStringPath);\r
+      Status = RunScriptFile (FullFileStringPath, NULL, FullFileStringPath, ShellInfoObject.NewShellParametersProtocol);\r
+      FreePool (FullFileStringPath);\r
     }\r
     }\r
-  }\r
-  if (EFI_ERROR(Status)) {\r
-    NamePath = FileDevicePath (NULL, mStartupScript);\r
-    NewPath = AppendDevicePathNode (ImagePath, NamePath);\r
-    FreePool(NamePath);\r
 \r
 \r
+    FreePool (FileStringPath);\r
+  } else {\r
     //\r
     //\r
-    // Try the location\r
+    // we return success since startup script is not mandatory.\r
     //\r
     //\r
-    Status = InternalOpenFileDevicePath(NewPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r
-    FreePool(NewPath);\r
-  }\r
-  //\r
-  // If we got a file, run it\r
-  //\r
-  if (!EFI_ERROR(Status) && FileHandle != NULL) {\r
-    Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);\r
-    ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);\r
-  } else {\r
-    FileStringPath = ShellFindFilePath(mStartupScript);\r
-    if (FileStringPath == NULL) {\r
-      //\r
-      // we return success since we don't need to have a startup script\r
-      //\r
-      Status = EFI_SUCCESS;\r
-      ASSERT(FileHandle == NULL);\r
-    } else {\r
-      Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);\r
-      FreePool(FileStringPath);\r
-    }\r
+    Status = EFI_SUCCESS;\r
   }\r
 \r
   }\r
 \r
-\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
@@ -1252,7 +1399,6 @@ DoStartupScript(
   @retval RETURN_ABORTED\r
 **/\r
 EFI_STATUS\r
   @retval RETURN_ABORTED\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 DoShellPrompt (\r
   VOID\r
   )\r
 DoShellPrompt (\r
   VOID\r
   )\r
@@ -1265,49 +1411,54 @@ DoShellPrompt (
   EFI_STATUS    Status;\r
   LIST_ENTRY    OldBufferList;\r
 \r
   EFI_STATUS    Status;\r
   LIST_ENTRY    OldBufferList;\r
 \r
-  CurDir  = NULL;\r
+  CurDir = NULL;\r
 \r
   //\r
   // Get screen setting to decide size of the command line buffer\r
   //\r
   gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Column, &Row);\r
 \r
   //\r
   // Get screen setting to decide size of the command line buffer\r
   //\r
   gST->ConOut->QueryMode (gST->ConOut, gST->ConOut->Mode->Mode, &Column, &Row);\r
-  BufferSize  = Column * Row * sizeof (CHAR16);\r
-  CmdLine     = AllocateZeroPool (BufferSize);\r
+  BufferSize = Column * Row * sizeof (CHAR16);\r
+  CmdLine    = AllocateZeroPool (BufferSize);\r
   if (CmdLine == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
   if (CmdLine == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  SaveBufferList(&OldBufferList);\r
-  CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd");\r
+  SaveBufferList (&OldBufferList);\r
+  CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv (L"cwd");\r
 \r
   //\r
   // Prompt for input\r
   //\r
   gST->ConOut->SetCursorPosition (gST->ConOut, 0, gST->ConOut->Mode->CursorRow);\r
 \r
 \r
   //\r
   // Prompt for input\r
   //\r
   gST->ConOut->SetCursorPosition (gST->ConOut, 0, gST->ConOut->Mode->CursorRow);\r
 \r
-  if (CurDir != NULL && StrLen(CurDir) > 1) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);\r
+  if ((CurDir != NULL) && (StrLen (CurDir) > 1)) {\r
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);\r
   } else {\r
   } else {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);\r
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);\r
   }\r
 \r
   //\r
   // Read a line from the console\r
   //\r
   }\r
 \r
   //\r
   // Read a line from the console\r
   //\r
-  Status = ShellInfoObject.NewEfiShellProtocol->ReadFile(ShellInfoObject.NewShellParametersProtocol->StdIn, &BufferSize, CmdLine);\r
+  Status = ShellInfoObject.NewEfiShellProtocol->ReadFile (ShellInfoObject.NewShellParametersProtocol->StdIn, &BufferSize, CmdLine);\r
 \r
   //\r
   // Null terminate the string and parse it\r
   //\r
   if (!EFI_ERROR (Status)) {\r
 \r
   //\r
   // Null terminate the string and parse it\r
   //\r
   if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Reset the CTRL-C event just before running the command (yes we ignore the return values)\r
+    //\r
+    Status = gBS->CheckEvent (ShellInfoObject.NewEfiShellProtocol->ExecutionBreak);\r
+\r
     CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;\r
     CmdLine[BufferSize / sizeof (CHAR16)] = CHAR_NULL;\r
-    Status = RunCommand(CmdLine);\r
-    }\r
+    Status                                = RunCommand (CmdLine);\r
+  }\r
 \r
   //\r
   // Done with this command\r
   //\r
 \r
   //\r
   // Done with this command\r
   //\r
-  RestoreBufferList(&OldBufferList);\r
+  RestoreBufferList (&OldBufferList);\r
   FreePool (CmdLine);\r
   return Status;\r
 }\r
   FreePool (CmdLine);\r
   return Status;\r
 }\r
@@ -1318,13 +1469,12 @@ DoShellPrompt (
 \r
   @param Buffer   Something to pass to FreePool when the shell is exiting.\r
 **/\r
 \r
   @param Buffer   Something to pass to FreePool when the shell is exiting.\r
 **/\r
-VOID*\r
-EFIAPI\r
+VOID *\r
 AddBufferToFreeList (\r
 AddBufferToFreeList (\r
-  VOID *Buffer\r
+  VOID  *Buffer\r
   )\r
 {\r
   )\r
 {\r
-  BUFFER_LIST   *BufferListEntry;\r
+  BUFFER_LIST  *BufferListEntry;\r
 \r
   if (Buffer == NULL) {\r
     return (NULL);\r
 \r
   if (Buffer == NULL) {\r
     return (NULL);\r
@@ -1340,15 +1490,14 @@ AddBufferToFreeList (
   return (Buffer);\r
 }\r
 \r
   return (Buffer);\r
 }\r
 \r
-\r
 /**\r
 /**\r
-  Create a new buffer list and stores the old one to OldBufferList \r
+  Create a new buffer list and stores the old one to OldBufferList\r
 \r
   @param OldBufferList   The temporary list head used to store the nodes in BufferToFreeList.\r
 **/\r
 VOID\r
 SaveBufferList (\r
 \r
   @param OldBufferList   The temporary list head used to store the nodes in BufferToFreeList.\r
 **/\r
 VOID\r
 SaveBufferList (\r
-  OUT LIST_ENTRY     *OldBufferList\r
+  OUT LIST_ENTRY  *OldBufferList\r
   )\r
 {\r
   CopyMem (OldBufferList, &ShellInfoObject.BufferToFreeList.Link, sizeof (LIST_ENTRY));\r
   )\r
 {\r
   CopyMem (OldBufferList, &ShellInfoObject.BufferToFreeList.Link, sizeof (LIST_ENTRY));\r
@@ -1362,39 +1511,36 @@ SaveBufferList (
 **/\r
 VOID\r
 RestoreBufferList (\r
 **/\r
 VOID\r
 RestoreBufferList (\r
-  IN OUT LIST_ENTRY     *OldBufferList\r
+  IN OUT LIST_ENTRY  *OldBufferList\r
   )\r
 {\r
   FreeBufferList (&ShellInfoObject.BufferToFreeList);\r
   CopyMem (&ShellInfoObject.BufferToFreeList.Link, OldBufferList, sizeof (LIST_ENTRY));\r
 }\r
 \r
   )\r
 {\r
   FreeBufferList (&ShellInfoObject.BufferToFreeList);\r
   CopyMem (&ShellInfoObject.BufferToFreeList.Link, OldBufferList, sizeof (LIST_ENTRY));\r
 }\r
 \r
-\r
 /**\r
   Add a buffer to the Line History List\r
 \r
   @param Buffer     The line buffer to add.\r
 **/\r
 VOID\r
 /**\r
   Add a buffer to the Line History List\r
 \r
   @param Buffer     The line buffer to add.\r
 **/\r
 VOID\r
-EFIAPI\r
-AddLineToCommandHistory(\r
-  IN CONST CHAR16 *Buffer\r
+AddLineToCommandHistory (\r
+  IN CONST CHAR16  *Buffer\r
   )\r
 {\r
   )\r
 {\r
-  BUFFER_LIST *Node;\r
-  BUFFER_LIST *Walker;\r
+  BUFFER_LIST  *Node;\r
+  BUFFER_LIST  *Walker;\r
   UINT16       MaxHistoryCmdCount;\r
   UINT16       Count;\r
 \r
   UINT16       MaxHistoryCmdCount;\r
   UINT16       Count;\r
 \r
-  Count = 0;\r
-  MaxHistoryCmdCount = PcdGet16(PcdShellMaxHistoryCommandCount);\r
-  \r
+  Count              = 0;\r
+  MaxHistoryCmdCount = PcdGet16 (PcdShellMaxHistoryCommandCount);\r
+\r
   if (MaxHistoryCmdCount == 0) {\r
   if (MaxHistoryCmdCount == 0) {\r
-    return ;\r
+    return;\r
   }\r
 \r
   }\r
 \r
-\r
-  Node = AllocateZeroPool(sizeof(BUFFER_LIST));\r
+  Node = AllocateZeroPool (sizeof (BUFFER_LIST));\r
   if (Node == NULL) {\r
     return;\r
   }\r
   if (Node == NULL) {\r
     return;\r
   }\r
@@ -1405,22 +1551,25 @@ AddLineToCommandHistory(
     return;\r
   }\r
 \r
     return;\r
   }\r
 \r
-  for ( Walker = (BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link)\r
-      ; !IsNull(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Walker->Link)\r
-      ; Walker = (BUFFER_LIST*)GetNextNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Walker->Link)\r
-   ){\r
+  for ( Walker = (BUFFER_LIST *)GetFirstNode (&ShellInfoObject.ViewingSettings.CommandHistory.Link)\r
+        ; !IsNull (&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Walker->Link)\r
+        ; Walker = (BUFFER_LIST *)GetNextNode (&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Walker->Link)\r
+        )\r
+  {\r
     Count++;\r
   }\r
     Count++;\r
   }\r
-  if (Count < MaxHistoryCmdCount){\r
-    InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r
+\r
+  if (Count < MaxHistoryCmdCount) {\r
+    InsertTailList (&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r
   } else {\r
   } else {\r
-    Walker = (BUFFER_LIST*)GetFirstNode(&ShellInfoObject.ViewingSettings.CommandHistory.Link);\r
-    RemoveEntryList(&Walker->Link);\r
+    Walker = (BUFFER_LIST *)GetFirstNode (&ShellInfoObject.ViewingSettings.CommandHistory.Link);\r
+    RemoveEntryList (&Walker->Link);\r
     if (Walker->Buffer != NULL) {\r
     if (Walker->Buffer != NULL) {\r
-      FreePool(Walker->Buffer);\r
+      FreePool (Walker->Buffer);\r
     }\r
     }\r
-    FreePool(Walker);\r
-    InsertTailList(&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r
+\r
+    FreePool (Walker);\r
+    InsertTailList (&ShellInfoObject.ViewingSettings.CommandHistory.Link, &Node->Link);\r
   }\r
 }\r
 \r
   }\r
 }\r
 \r
@@ -1438,22 +1587,23 @@ AddLineToCommandHistory(
   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_OUT_OF_RESOURCES    A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-ShellConvertAlias(\r
-  IN OUT CHAR16 **CommandString\r
+ShellConvertAlias (\r
+  IN OUT CHAR16  **CommandString\r
   )\r
 {\r
   CONST CHAR16  *NewString;\r
 \r
   )\r
 {\r
   CONST CHAR16  *NewString;\r
 \r
-  NewString = ShellInfoObject.NewEfiShellProtocol->GetAlias(*CommandString, NULL);\r
+  NewString = ShellInfoObject.NewEfiShellProtocol->GetAlias (*CommandString, NULL);\r
   if (NewString == NULL) {\r
     return (EFI_SUCCESS);\r
   }\r
   if (NewString == NULL) {\r
     return (EFI_SUCCESS);\r
   }\r
-  FreePool(*CommandString);\r
-  *CommandString = AllocateCopyPool(StrSize(NewString), NewString);\r
+\r
+  FreePool (*CommandString);\r
+  *CommandString = AllocateCopyPool (StrSize (NewString), NewString);\r
   if (*CommandString == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
   if (*CommandString == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -1463,30 +1613,29 @@ ShellConvertAlias(
   @param[in,out] CmdLine   The command line to update.\r
 **/\r
 EFI_STATUS\r
   @param[in,out] CmdLine   The command line to update.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-StripUnreplacedEnvironmentVariables(\r
-  IN OUT CHAR16 *CmdLine\r
+StripUnreplacedEnvironmentVariables (\r
+  IN OUT CHAR16  *CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  CHAR16 *FirstPercent;\r
-  CHAR16 *FirstQuote;\r
-  CHAR16 *SecondPercent;\r
-  CHAR16 *SecondQuote;\r
-  CHAR16 *CurrentLocator;\r
-\r
-  for (CurrentLocator = CmdLine ; CurrentLocator != NULL ; ) {\r
-    FirstQuote = FindNextInstance(CurrentLocator, L"\"", TRUE);\r
-    FirstPercent = FindNextInstance(CurrentLocator, L"%", TRUE);\r
-    SecondPercent = FirstPercent!=NULL?FindNextInstance(FirstPercent+1, L"%", TRUE):NULL;\r
-    if (FirstPercent == NULL || SecondPercent == NULL) {\r
+  CHAR16  *FirstPercent;\r
+  CHAR16  *FirstQuote;\r
+  CHAR16  *SecondPercent;\r
+  CHAR16  *SecondQuote;\r
+  CHAR16  *CurrentLocator;\r
+\r
+  for (CurrentLocator = CmdLine; CurrentLocator != NULL; ) {\r
+    FirstQuote    = FindNextInstance (CurrentLocator, L"\"", TRUE);\r
+    FirstPercent  = FindNextInstance (CurrentLocator, L"%", TRUE);\r
+    SecondPercent = FirstPercent != NULL ? FindNextInstance (FirstPercent+1, L"%", TRUE) : NULL;\r
+    if ((FirstPercent == NULL) || (SecondPercent == NULL)) {\r
       //\r
       // If we ever don't have 2 % we are done.\r
       //\r
       break;\r
     }\r
 \r
       //\r
       // If we ever don't have 2 % we are done.\r
       //\r
       break;\r
     }\r
 \r
-    if (FirstQuote!= NULL && FirstQuote < FirstPercent) {\r
-      SecondQuote = FindNextInstance(FirstQuote+1, L"\"", TRUE);\r
+    if ((FirstQuote != NULL) && (FirstQuote < FirstPercent)) {\r
+      SecondQuote = FindNextInstance (FirstQuote+1, L"\"", TRUE);\r
       //\r
       // Quote is first found\r
       //\r
       //\r
       // Quote is first found\r
       //\r
@@ -1496,31 +1645,36 @@ StripUnreplacedEnvironmentVariables(
         // restart after the pair of "\r
         //\r
         CurrentLocator = SecondQuote + 1;\r
         // restart after the pair of "\r
         //\r
         CurrentLocator = SecondQuote + 1;\r
-      } else /* FirstPercent < SecondQuote */{\r
+      } else {\r
+        /* FirstPercent < SecondQuote */\r
         //\r
         // Restart on the first percent\r
         //\r
         CurrentLocator = FirstPercent;\r
       }\r
         //\r
         // Restart on the first percent\r
         //\r
         CurrentLocator = FirstPercent;\r
       }\r
+\r
       continue;\r
     }\r
       continue;\r
     }\r
-    \r
-    if (FirstQuote == NULL || SecondPercent < FirstQuote) {\r
-      if (IsValidEnvironmentVariableName(FirstPercent, SecondPercent)) {\r
+\r
+    if ((FirstQuote == NULL) || (SecondPercent < FirstQuote)) {\r
+      if (IsValidEnvironmentVariableName (FirstPercent, SecondPercent)) {\r
         //\r
         // We need to remove from FirstPercent to SecondPercent\r
         //\r
         //\r
         // We need to remove from FirstPercent to SecondPercent\r
         //\r
-        CopyMem(FirstPercent, SecondPercent + 1, StrSize(SecondPercent + 1));\r
+        CopyMem (FirstPercent, SecondPercent + 1, StrSize (SecondPercent + 1));\r
         //\r
         // don't need to update the locator.  both % characters are gone.\r
         //\r
       } else {\r
         CurrentLocator = SecondPercent + 1;\r
       }\r
         //\r
         // don't need to update the locator.  both % characters are gone.\r
         //\r
       } else {\r
         CurrentLocator = SecondPercent + 1;\r
       }\r
+\r
       continue;\r
     }\r
       continue;\r
     }\r
+\r
     CurrentLocator = FirstQuote;\r
   }\r
     CurrentLocator = FirstQuote;\r
   }\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -1535,70 +1689,75 @@ StripUnreplacedEnvironmentVariables(
   @retval NULL                      An error occurred.\r
   @return                           The new command line with no environment variables present.\r
 **/\r
   @retval NULL                      An error occurred.\r
   @return                           The new command line with no environment variables present.\r
 **/\r
-CHAR16*\r
-EFIAPI\r
+CHAR16 *\r
 ShellConvertVariables (\r
 ShellConvertVariables (\r
-  IN CONST CHAR16 *OriginalCommandLine\r
+  IN CONST CHAR16  *OriginalCommandLine\r
   )\r
 {\r
   )\r
 {\r
-  CONST CHAR16        *MasterEnvList;\r
-  UINTN               NewSize;\r
-  CHAR16              *NewCommandLine1;\r
-  CHAR16              *NewCommandLine2;\r
-  CHAR16              *Temp;\r
-  UINTN               ItemSize;\r
-  CHAR16              *ItemTemp;\r
-  SCRIPT_FILE         *CurrentScriptFile;\r
-  ALIAS_LIST          *AliasListNode;\r
-\r
-  ASSERT(OriginalCommandLine != NULL);\r
+  CONST CHAR16  *MasterEnvList;\r
+  UINTN         NewSize;\r
+  CHAR16        *NewCommandLine1;\r
+  CHAR16        *NewCommandLine2;\r
+  CHAR16        *Temp;\r
+  UINTN         ItemSize;\r
+  CHAR16        *ItemTemp;\r
+  SCRIPT_FILE   *CurrentScriptFile;\r
+  ALIAS_LIST    *AliasListNode;\r
+\r
+  ASSERT (OriginalCommandLine != NULL);\r
 \r
   ItemSize          = 0;\r
 \r
   ItemSize          = 0;\r
-  NewSize           = StrSize(OriginalCommandLine);\r
-  CurrentScriptFile = ShellCommandGetCurrentScriptFile();\r
+  NewSize           = StrSize (OriginalCommandLine);\r
+  CurrentScriptFile = ShellCommandGetCurrentScriptFile ();\r
   Temp              = NULL;\r
 \r
   Temp              = NULL;\r
 \r
-  ///@todo update this to handle the %0 - %9 for scripting only (borrow from line 1256 area) ? ? ?\r
+  /// @todo update this to handle the %0 - %9 for scripting only (borrow from line 1256 area) ? ? ?\r
 \r
   //\r
   // calculate the size required for the post-conversion string...\r
   //\r
   if (CurrentScriptFile != NULL) {\r
 \r
   //\r
   // calculate the size required for the post-conversion string...\r
   //\r
   if (CurrentScriptFile != NULL) {\r
-    for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)\r
-      ;  !IsNull(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
-      ;  AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
-   ){\r
-      for (Temp = StrStr(OriginalCommandLine, AliasListNode->Alias)\r
-        ;  Temp != NULL\r
-        ;  Temp = StrStr(Temp+1, AliasListNode->Alias)\r
-       ){\r
+    for (AliasListNode = (ALIAS_LIST *)GetFirstNode (&CurrentScriptFile->SubstList)\r
+         ; !IsNull (&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
+         ; AliasListNode = (ALIAS_LIST *)GetNextNode (&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
+         )\r
+    {\r
+      for (Temp = StrStr (OriginalCommandLine, AliasListNode->Alias)\r
+           ; Temp != NULL\r
+           ; Temp = StrStr (Temp+1, AliasListNode->Alias)\r
+           )\r
+      {\r
         //\r
         // we need a preceding and if there is space no ^ preceding (if no space ignore)\r
         //\r
         //\r
         // we need a preceding and if there is space no ^ preceding (if no space ignore)\r
         //\r
-        if ((((Temp-OriginalCommandLine)>2) && *(Temp-2) != L'^') || ((Temp-OriginalCommandLine)<=2)) {\r
-          NewSize += StrSize(AliasListNode->CommandString);\r
+        if ((((Temp-OriginalCommandLine) > 2) && (*(Temp-2) != L'^')) || ((Temp-OriginalCommandLine) <= 2)) {\r
+          NewSize += StrSize (AliasListNode->CommandString);\r
         }\r
       }\r
     }\r
   }\r
 \r
         }\r
       }\r
     }\r
   }\r
 \r
-  for (MasterEnvList = EfiShellGetEnv(NULL)\r
-    ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL //&& *(MasterEnvList+1) != CHAR_NULL\r
-    ;  MasterEnvList += StrLen(MasterEnvList) + 1\r
-   ){\r
-    if (StrSize(MasterEnvList) > ItemSize) {\r
-      ItemSize = StrSize(MasterEnvList);\r
+  for (MasterEnvList = EfiShellGetEnv (NULL)\r
+       ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL // && *(MasterEnvList+1) != CHAR_NULL\r
+       ; MasterEnvList += StrLen (MasterEnvList) + 1\r
+       )\r
+  {\r
+    if (StrSize (MasterEnvList) > ItemSize) {\r
+      ItemSize = StrSize (MasterEnvList);\r
     }\r
     }\r
-    for (Temp = StrStr(OriginalCommandLine, MasterEnvList)\r
-      ;  Temp != NULL\r
-      ;  Temp = StrStr(Temp+1, MasterEnvList)\r
-     ){\r
+\r
+    for (Temp = StrStr (OriginalCommandLine, MasterEnvList)\r
+         ; Temp != NULL\r
+         ; Temp = StrStr (Temp+1, MasterEnvList)\r
+         )\r
+    {\r
       //\r
       // we need a preceding and following % and if there is space no ^ preceding (if no space ignore)\r
       //\r
       //\r
       // we need a preceding and following % and if there is space no ^ preceding (if no space ignore)\r
       //\r
-      if (*(Temp-1) == L'%' && *(Temp+StrLen(MasterEnvList)) == L'%' &&\r
-        ((((Temp-OriginalCommandLine)>2) && *(Temp-2) != L'^') || ((Temp-OriginalCommandLine)<=2))) {\r
-        NewSize+=StrSize(EfiShellGetEnv(MasterEnvList));\r
+      if ((*(Temp-1) == L'%') && (*(Temp+StrLen (MasterEnvList)) == L'%') &&\r
+          ((((Temp-OriginalCommandLine) > 2) && (*(Temp-2) != L'^')) || ((Temp-OriginalCommandLine) <= 2)))\r
+      {\r
+        NewSize += StrSize (EfiShellGetEnv (MasterEnvList));\r
       }\r
     }\r
   }\r
       }\r
     }\r
   }\r
@@ -1606,57 +1765,66 @@ ShellConvertVariables (
   //\r
   // now do the replacements...\r
   //\r
   //\r
   // now do the replacements...\r
   //\r
-  NewCommandLine1 = AllocateCopyPool(NewSize, OriginalCommandLine);\r
-  NewCommandLine2 = AllocateZeroPool(NewSize);\r
-  ItemTemp        = AllocateZeroPool(ItemSize+(2*sizeof(CHAR16)));\r
-  if (NewCommandLine1 == NULL || NewCommandLine2 == NULL || ItemTemp == NULL) {\r
-    SHELL_FREE_NON_NULL(NewCommandLine1);\r
-    SHELL_FREE_NON_NULL(NewCommandLine2);\r
-    SHELL_FREE_NON_NULL(ItemTemp);\r
+  NewCommandLine1 = AllocateZeroPool (NewSize);\r
+  NewCommandLine2 = AllocateZeroPool (NewSize);\r
+  ItemTemp        = AllocateZeroPool (ItemSize+(2*sizeof (CHAR16)));\r
+  if ((NewCommandLine1 == NULL) || (NewCommandLine2 == NULL) || (ItemTemp == NULL)) {\r
+    SHELL_FREE_NON_NULL (NewCommandLine1);\r
+    SHELL_FREE_NON_NULL (NewCommandLine2);\r
+    SHELL_FREE_NON_NULL (ItemTemp);\r
     return (NULL);\r
   }\r
     return (NULL);\r
   }\r
-  for (MasterEnvList = EfiShellGetEnv(NULL)\r
-    ;  MasterEnvList != NULL && *MasterEnvList != CHAR_NULL\r
-    ;  MasterEnvList += StrLen(MasterEnvList) + 1\r
-   ){\r
-    StrCpyS( ItemTemp, \r
-              ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r
-              L"%"\r
-              );\r
-    StrCatS( ItemTemp, \r
-              ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r
-              MasterEnvList\r
-              );\r
-    StrCatS( ItemTemp, \r
-              ((ItemSize+(2*sizeof(CHAR16)))/sizeof(CHAR16)), \r
-              L"%"\r
-              );\r
-    ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv(MasterEnvList), TRUE, FALSE);\r
-    StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r
+\r
+  CopyMem (NewCommandLine1, OriginalCommandLine, StrSize (OriginalCommandLine));\r
+\r
+  for (MasterEnvList = EfiShellGetEnv (NULL)\r
+       ; MasterEnvList != NULL && *MasterEnvList != CHAR_NULL\r
+       ; MasterEnvList += StrLen (MasterEnvList) + 1\r
+       )\r
+  {\r
+    StrCpyS (\r
+      ItemTemp,\r
+      ((ItemSize+(2*sizeof (CHAR16)))/sizeof (CHAR16)),\r
+      L"%"\r
+      );\r
+    StrCatS (\r
+      ItemTemp,\r
+      ((ItemSize+(2*sizeof (CHAR16)))/sizeof (CHAR16)),\r
+      MasterEnvList\r
+      );\r
+    StrCatS (\r
+      ItemTemp,\r
+      ((ItemSize+(2*sizeof (CHAR16)))/sizeof (CHAR16)),\r
+      L"%"\r
+      );\r
+    ShellCopySearchAndReplace (NewCommandLine1, NewCommandLine2, NewSize, ItemTemp, EfiShellGetEnv (MasterEnvList), TRUE, FALSE);\r
+    StrCpyS (NewCommandLine1, NewSize/sizeof (CHAR16), NewCommandLine2);\r
   }\r
   }\r
+\r
   if (CurrentScriptFile != NULL) {\r
   if (CurrentScriptFile != NULL) {\r
-    for (AliasListNode = (ALIAS_LIST*)GetFirstNode(&CurrentScriptFile->SubstList)\r
-      ;  !IsNull(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
-      ;  AliasListNode = (ALIAS_LIST*)GetNextNode(&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
-   ){\r
-    ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);\r
-    StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r
+    for (AliasListNode = (ALIAS_LIST *)GetFirstNode (&CurrentScriptFile->SubstList)\r
+         ; !IsNull (&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
+         ; AliasListNode = (ALIAS_LIST *)GetNextNode (&CurrentScriptFile->SubstList, &AliasListNode->Link)\r
+         )\r
+    {\r
+      ShellCopySearchAndReplace (NewCommandLine1, NewCommandLine2, NewSize, AliasListNode->Alias, AliasListNode->CommandString, TRUE, FALSE);\r
+      StrCpyS (NewCommandLine1, NewSize/sizeof (CHAR16), NewCommandLine2);\r
     }\r
   }\r
 \r
   //\r
   // Remove non-existent environment variables\r
   //\r
     }\r
   }\r
 \r
   //\r
   // Remove non-existent environment variables\r
   //\r
-  StripUnreplacedEnvironmentVariables(NewCommandLine1);\r
+  StripUnreplacedEnvironmentVariables (NewCommandLine1);\r
 \r
   //\r
   // Now cleanup any straggler intentionally ignored "%" characters\r
   //\r
 \r
   //\r
   // Now cleanup any straggler intentionally ignored "%" characters\r
   //\r
-  ShellCopySearchAndReplace(NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);\r
-  StrCpyS(NewCommandLine1, NewSize/sizeof(CHAR16), NewCommandLine2);\r
-  \r
-  FreePool(NewCommandLine2);\r
-  FreePool(ItemTemp);\r
+  ShellCopySearchAndReplace (NewCommandLine1, NewCommandLine2, NewSize, L"^%", L"%", TRUE, FALSE);\r
+  StrCpyS (NewCommandLine1, NewSize/sizeof (CHAR16), NewCommandLine2);\r
+\r
+  FreePool (NewCommandLine2);\r
+  FreePool (ItemTemp);\r
 \r
   return (NewCommandLine1);\r
 }\r
 \r
   return (NewCommandLine1);\r
 }\r
@@ -1672,25 +1840,24 @@ ShellConvertVariables (
   @retval other             Some error occurs when executing the split command.\r
 **/\r
 EFI_STATUS\r
   @retval other             Some error occurs when executing the split command.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-RunSplitCommand(\r
+RunSplitCommand (\r
   IN CONST CHAR16             *CmdLine,\r
   IN CONST CHAR16             *CmdLine,\r
-  IN       SHELL_FILE_HANDLE  *StdIn,\r
-  IN       SHELL_FILE_HANDLE  *StdOut\r
+  IN       SHELL_FILE_HANDLE  StdIn,\r
+  IN       SHELL_FILE_HANDLE  StdOut\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS        Status;\r
-  CHAR16            *NextCommandLine;\r
-  CHAR16            *OurCommandLine;\r
-  UINTN             Size1;\r
-  UINTN             Size2;\r
-  SPLIT_LIST        *Split;\r
-  SHELL_FILE_HANDLE *TempFileHandle;\r
-  BOOLEAN           Unicode;\r
+  EFI_STATUS         Status;\r
+  CHAR16             *NextCommandLine;\r
+  CHAR16             *OurCommandLine;\r
+  UINTN              Size1;\r
+  UINTN              Size2;\r
+  SPLIT_LIST         *Split;\r
+  SHELL_FILE_HANDLE  TempFileHandle;\r
+  BOOLEAN            Unicode;\r
 \r
 \r
-  ASSERT(StdOut == NULL);\r
+  ASSERT (StdOut == NULL);\r
 \r
 \r
-  ASSERT(StrStr(CmdLine, L"|") != NULL);\r
+  ASSERT (StrStr (CmdLine, L"|") != NULL);\r
 \r
   Status          = EFI_SUCCESS;\r
   NextCommandLine = NULL;\r
 \r
   Status          = EFI_SUCCESS;\r
   NextCommandLine = NULL;\r
@@ -1698,91 +1865,95 @@ RunSplitCommand(
   Size1           = 0;\r
   Size2           = 0;\r
 \r
   Size1           = 0;\r
   Size2           = 0;\r
 \r
-  NextCommandLine = StrnCatGrow(&NextCommandLine, &Size1, StrStr(CmdLine, L"|")+1, 0);\r
-  OurCommandLine  = StrnCatGrow(&OurCommandLine , &Size2, CmdLine                , StrStr(CmdLine, L"|") - CmdLine);\r
+  NextCommandLine = StrnCatGrow (&NextCommandLine, &Size1, StrStr (CmdLine, L"|")+1, 0);\r
+  OurCommandLine  = StrnCatGrow (&OurCommandLine, &Size2, CmdLine, StrStr (CmdLine, L"|") - CmdLine);\r
 \r
 \r
-  if (NextCommandLine == NULL || OurCommandLine == NULL) {\r
-    SHELL_FREE_NON_NULL(OurCommandLine);\r
-    SHELL_FREE_NON_NULL(NextCommandLine);\r
+  if ((NextCommandLine == NULL) || (OurCommandLine == NULL)) {\r
+    SHELL_FREE_NON_NULL (OurCommandLine);\r
+    SHELL_FREE_NON_NULL (NextCommandLine);\r
     return (EFI_OUT_OF_RESOURCES);\r
     return (EFI_OUT_OF_RESOURCES);\r
-  } else if (StrStr(OurCommandLine, L"|") != NULL || Size1 == 0 || Size2 == 0) {\r
-    SHELL_FREE_NON_NULL(OurCommandLine);\r
-    SHELL_FREE_NON_NULL(NextCommandLine);\r
+  } else if ((StrStr (OurCommandLine, L"|") != NULL) || (Size1 == 0) || (Size2 == 0)) {\r
+    SHELL_FREE_NON_NULL (OurCommandLine);\r
+    SHELL_FREE_NON_NULL (NextCommandLine);\r
     return (EFI_INVALID_PARAMETER);\r
     return (EFI_INVALID_PARAMETER);\r
-  } else if (NextCommandLine[0] == L'a' &&\r
-             (NextCommandLine[1] == L' ' || NextCommandLine[1] == CHAR_NULL)\r
-            ){\r
-    CopyMem(NextCommandLine, NextCommandLine+1, StrSize(NextCommandLine) - sizeof(NextCommandLine[0]));\r
+  } else if ((NextCommandLine[0] == L'a') &&\r
+             ((NextCommandLine[1] == L' ') || (NextCommandLine[1] == CHAR_NULL))\r
+             )\r
+  {\r
+    CopyMem (NextCommandLine, NextCommandLine+1, StrSize (NextCommandLine) - sizeof (NextCommandLine[0]));\r
     while (NextCommandLine[0] == L' ') {\r
     while (NextCommandLine[0] == L' ') {\r
-      CopyMem(NextCommandLine, NextCommandLine+1, StrSize(NextCommandLine) - sizeof(NextCommandLine[0]));\r
+      CopyMem (NextCommandLine, NextCommandLine+1, StrSize (NextCommandLine) - sizeof (NextCommandLine[0]));\r
     }\r
     }\r
+\r
     if (NextCommandLine[0] == CHAR_NULL) {\r
     if (NextCommandLine[0] == CHAR_NULL) {\r
-      SHELL_FREE_NON_NULL(OurCommandLine);\r
-      SHELL_FREE_NON_NULL(NextCommandLine);\r
+      SHELL_FREE_NON_NULL (OurCommandLine);\r
+      SHELL_FREE_NON_NULL (NextCommandLine);\r
       return (EFI_INVALID_PARAMETER);\r
     }\r
       return (EFI_INVALID_PARAMETER);\r
     }\r
+\r
     Unicode = FALSE;\r
   } else {\r
     Unicode = TRUE;\r
   }\r
 \r
     Unicode = FALSE;\r
   } else {\r
     Unicode = TRUE;\r
   }\r
 \r
-\r
   //\r
   // make a SPLIT_LIST item and add to list\r
   //\r
   //\r
   // make a SPLIT_LIST item and add to list\r
   //\r
-  Split = AllocateZeroPool(sizeof(SPLIT_LIST));\r
+  Split = AllocateZeroPool (sizeof (SPLIT_LIST));\r
   if (Split == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   if (Split == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  Split->SplitStdIn   = StdIn;\r
-  Split->SplitStdOut  = ConvertEfiFileProtocolToShellHandle(CreateFileInterfaceMem(Unicode), NULL);\r
-  ASSERT(Split->SplitStdOut != NULL);\r
-  InsertHeadList(&ShellInfoObject.SplitList.Link, &Split->Link);\r
 \r
 \r
-  Status = RunCommand(OurCommandLine);\r
+  Split->SplitStdIn  = StdIn;\r
+  Split->SplitStdOut = ConvertEfiFileProtocolToShellHandle (CreateFileInterfaceMem (Unicode), NULL);\r
+  ASSERT (Split->SplitStdOut != NULL);\r
+  InsertHeadList (&ShellInfoObject.SplitList.Link, &Split->Link);\r
+\r
+  Status = RunCommand (OurCommandLine);\r
 \r
   //\r
   // move the output from the first to the in to the second.\r
   //\r
 \r
   //\r
   // move the output from the first to the in to the second.\r
   //\r
-  TempFileHandle      = Split->SplitStdOut;\r
+  TempFileHandle = Split->SplitStdOut;\r
   if (Split->SplitStdIn == StdIn) {\r
     Split->SplitStdOut = NULL;\r
   } else {\r
   if (Split->SplitStdIn == StdIn) {\r
     Split->SplitStdOut = NULL;\r
   } else {\r
-    Split->SplitStdOut  = Split->SplitStdIn;\r
+    Split->SplitStdOut = Split->SplitStdIn;\r
   }\r
   }\r
-  Split->SplitStdIn   = TempFileHandle;\r
-  ShellInfoObject.NewEfiShellProtocol->SetFilePosition(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn), 0);\r
 \r
 \r
-  if (!EFI_ERROR(Status)) {\r
-    Status = RunCommand(NextCommandLine);\r
+  Split->SplitStdIn = TempFileHandle;\r
+  ShellInfoObject.NewEfiShellProtocol->SetFilePosition (Split->SplitStdIn, 0);\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = RunCommand (NextCommandLine);\r
   }\r
 \r
   //\r
   // remove the top level from the ScriptList\r
   //\r
   }\r
 \r
   //\r
   // remove the top level from the ScriptList\r
   //\r
-  ASSERT((SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link) == Split);\r
-  RemoveEntryList(&Split->Link);\r
+  ASSERT ((SPLIT_LIST *)GetFirstNode (&ShellInfoObject.SplitList.Link) == Split);\r
+  RemoveEntryList (&Split->Link);\r
 \r
   //\r
   // Note that the original StdIn is now the StdOut...\r
   //\r
   if (Split->SplitStdOut != NULL) {\r
 \r
   //\r
   // Note that the original StdIn is now the StdOut...\r
   //\r
   if (Split->SplitStdOut != NULL) {\r
-    ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdOut));\r
+    ShellInfoObject.NewEfiShellProtocol->CloseFile (Split->SplitStdOut);\r
   }\r
   }\r
+\r
   if (Split->SplitStdIn != NULL) {\r
   if (Split->SplitStdIn != NULL) {\r
-    ShellInfoObject.NewEfiShellProtocol->CloseFile(ConvertShellHandleToEfiFileProtocol(Split->SplitStdIn));\r
-    FreePool (Split->SplitStdIn);\r
+    ShellInfoObject.NewEfiShellProtocol->CloseFile (Split->SplitStdIn);\r
   }\r
 \r
   }\r
 \r
-  FreePool(Split);\r
-  FreePool(NextCommandLine);\r
-  FreePool(OurCommandLine);\r
+  FreePool (Split);\r
+  FreePool (NextCommandLine);\r
+  FreePool (OurCommandLine);\r
 \r
   return (Status);\r
 }\r
 \r
 /**\r
 \r
   return (Status);\r
 }\r
 \r
 /**\r
-  Take the original command line, substitute any variables, free \r
+  Take the original command line, substitute any variables, free\r
   the original string, return the modified copy.\r
 \r
   @param[in] CmdLine  pointer to the command line to update.\r
   the original string, return the modified copy.\r
 \r
   @param[in] CmdLine  pointer to the command line to update.\r
@@ -1791,23 +1962,24 @@ RunSplitCommand(
   @retval EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-ShellSubstituteVariables(\r
-  IN CHAR16 **CmdLine\r
+ShellSubstituteVariables (\r
+  IN CHAR16  **CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  CHAR16      *NewCmdLine;\r
-  NewCmdLine = ShellConvertVariables(*CmdLine);\r
-  SHELL_FREE_NON_NULL(*CmdLine);\r
+  CHAR16  *NewCmdLine;\r
+\r
+  NewCmdLine = ShellConvertVariables (*CmdLine);\r
+  SHELL_FREE_NON_NULL (*CmdLine);\r
   if (NewCmdLine == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
   if (NewCmdLine == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
+\r
   *CmdLine = NewCmdLine;\r
   return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
   *CmdLine = NewCmdLine;\r
   return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
-  Take the original command line, substitute any alias in the first group of space delimited characters, free \r
+  Take the original command line, substitute any alias in the first group of space delimited characters, free\r
   the original string, return the modified copy.\r
 \r
   @param[in] CmdLine  pointer to the command line to update.\r
   the original string, return the modified copy.\r
 \r
   @param[in] CmdLine  pointer to the command line to update.\r
@@ -1816,58 +1988,59 @@ ShellSubstituteVariables(
   @retval EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_OUT_OF_RESOURCES  a memory allocation failed.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-ShellSubstituteAliases(\r
-  IN CHAR16 **CmdLine\r
+ShellSubstituteAliases (\r
+  IN CHAR16  **CmdLine\r
   )\r
 {\r
   CHAR16      *NewCmdLine;\r
   CHAR16      *CommandName;\r
   EFI_STATUS  Status;\r
   UINTN       PostAliasSize;\r
   )\r
 {\r
   CHAR16      *NewCmdLine;\r
   CHAR16      *CommandName;\r
   EFI_STATUS  Status;\r
   UINTN       PostAliasSize;\r
-  ASSERT(CmdLine != NULL);\r
-  ASSERT(*CmdLine!= NULL);\r
 \r
 \r
+  ASSERT (CmdLine != NULL);\r
+  ASSERT (*CmdLine != NULL);\r
 \r
   CommandName = NULL;\r
 \r
   CommandName = NULL;\r
-  if (StrStr((*CmdLine), L" ") == NULL){\r
-    StrnCatGrow(&CommandName, NULL, (*CmdLine), 0);\r
+  if (StrStr ((*CmdLine), L" ") == NULL) {\r
+    StrnCatGrow (&CommandName, NULL, (*CmdLine), 0);\r
   } else {\r
   } else {\r
-    StrnCatGrow(&CommandName, NULL, (*CmdLine), StrStr((*CmdLine), L" ") - (*CmdLine));\r
+    StrnCatGrow (&CommandName, NULL, (*CmdLine), StrStr ((*CmdLine), L" ") - (*CmdLine));\r
   }\r
 \r
   //\r
   // This cannot happen 'inline' since the CmdLine can need extra space.\r
   //\r
   NewCmdLine = NULL;\r
   }\r
 \r
   //\r
   // This cannot happen 'inline' since the CmdLine can need extra space.\r
   //\r
   NewCmdLine = NULL;\r
-  if (!ShellCommandIsCommandOnList(CommandName)) {\r
+  if (!ShellCommandIsCommandOnList (CommandName)) {\r
     //\r
     // Convert via alias\r
     //\r
     //\r
     // Convert via alias\r
     //\r
-    Status = ShellConvertAlias(&CommandName);\r
-    if (EFI_ERROR(Status)){\r
+    Status = ShellConvertAlias (&CommandName);\r
+    if (EFI_ERROR (Status)) {\r
       return (Status);\r
     }\r
       return (Status);\r
     }\r
+\r
     PostAliasSize = 0;\r
     PostAliasSize = 0;\r
-    NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, CommandName, 0);\r
+    NewCmdLine    = StrnCatGrow (&NewCmdLine, &PostAliasSize, CommandName, 0);\r
     if (NewCmdLine == NULL) {\r
     if (NewCmdLine == NULL) {\r
-      SHELL_FREE_NON_NULL(CommandName);\r
-      SHELL_FREE_NON_NULL(*CmdLine);\r
+      SHELL_FREE_NON_NULL (CommandName);\r
+      SHELL_FREE_NON_NULL (*CmdLine);\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
-    NewCmdLine = StrnCatGrow(&NewCmdLine, &PostAliasSize, StrStr((*CmdLine), L" "), 0);\r
+\r
+    NewCmdLine = StrnCatGrow (&NewCmdLine, &PostAliasSize, StrStr ((*CmdLine), L" "), 0);\r
     if (NewCmdLine == NULL) {\r
     if (NewCmdLine == NULL) {\r
-      SHELL_FREE_NON_NULL(CommandName);\r
-      SHELL_FREE_NON_NULL(*CmdLine);\r
+      SHELL_FREE_NON_NULL (CommandName);\r
+      SHELL_FREE_NON_NULL (*CmdLine);\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
   } else {\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
   } else {\r
-    NewCmdLine = StrnCatGrow(&NewCmdLine, NULL, (*CmdLine), 0);\r
+    NewCmdLine = StrnCatGrow (&NewCmdLine, NULL, (*CmdLine), 0);\r
   }\r
 \r
   }\r
 \r
-  SHELL_FREE_NON_NULL(*CmdLine);\r
-  SHELL_FREE_NON_NULL(CommandName);\r
\r
+  SHELL_FREE_NON_NULL (*CmdLine);\r
+  SHELL_FREE_NON_NULL (CommandName);\r
+\r
   //\r
   // re-assign the passed in double pointer to point to our newly allocated buffer\r
   //\r
   //\r
   // re-assign the passed in double pointer to point to our newly allocated buffer\r
   //\r
@@ -1880,7 +2053,7 @@ ShellSubstituteAliases(
   Takes the Argv[0] part of the command line and determine the meaning of it.\r
 \r
   @param[in] CmdName  pointer to the command line to update.\r
   Takes the Argv[0] part of the command line and determine the meaning of it.\r
 \r
   @param[in] CmdName  pointer to the command line to update.\r
-  \r
+\r
   @retval Internal_Command    The name is an internal command.\r
   @retval File_Sys_Change     the name is a file system change.\r
   @retval Script_File_Name    the name is a NSH script file.\r
   @retval Internal_Command    The name is an internal command.\r
   @retval File_Sys_Change     the name is a file system change.\r
   @retval Script_File_Name    the name is a NSH script file.\r
@@ -1888,47 +2061,48 @@ ShellSubstituteAliases(
   @retval Efi_Application     the name is an application (.EFI).\r
 **/\r
 SHELL_OPERATION_TYPES\r
   @retval Efi_Application     the name is an application (.EFI).\r
 **/\r
 SHELL_OPERATION_TYPES\r
-EFIAPI\r
-GetOperationType(\r
-  IN CONST CHAR16 *CmdName\r
+GetOperationType (\r
+  IN CONST CHAR16  *CmdName\r
   )\r
 {\r
   )\r
 {\r
-        CHAR16* FileWithPath;\r
-  CONST CHAR16TempLocation;\r
-  CONST CHAR16TempLocation2;\r
+  CHAR16        *FileWithPath;\r
+  CONST CHAR16  *TempLocation;\r
+  CONST CHAR16  *TempLocation2;\r
 \r
   FileWithPath = NULL;\r
   //\r
   // test for an internal command.\r
   //\r
 \r
   FileWithPath = NULL;\r
   //\r
   // test for an internal command.\r
   //\r
-  if (ShellCommandIsCommandOnList(CmdName)) {\r
+  if (ShellCommandIsCommandOnList (CmdName)) {\r
     return (Internal_Command);\r
   }\r
 \r
   //\r
   // Test for file system change request.  anything ending with first : and cant have spaces.\r
   //\r
     return (Internal_Command);\r
   }\r
 \r
   //\r
   // Test for file system change request.  anything ending with first : and cant have spaces.\r
   //\r
-  if (CmdName[(StrLen(CmdName)-1)] == L':') {\r
-    if ( StrStr(CmdName, L" ") != NULL \r
-      || StrLen(StrStr(CmdName, L":")) > 1\r
-      ) {\r
+  if (CmdName[(StrLen (CmdName)-1)] == L':') {\r
+    if (  (StrStr (CmdName, L" ") != NULL)\r
+       || (StrLen (StrStr (CmdName, L":")) > 1)\r
+          )\r
+    {\r
       return (Unknown_Invalid);\r
     }\r
       return (Unknown_Invalid);\r
     }\r
+\r
     return (File_Sys_Change);\r
   }\r
 \r
   //\r
   // Test for a file\r
   //\r
     return (File_Sys_Change);\r
   }\r
 \r
   //\r
   // Test for a file\r
   //\r
-  if ((FileWithPath = ShellFindFilePathEx(CmdName, mExecutableExtensions)) != NULL) {\r
+  if ((FileWithPath = ShellFindFilePathEx (CmdName, mExecutableExtensions)) != NULL) {\r
     //\r
     // See if that file has a script file extension\r
     //\r
     //\r
     // See if that file has a script file extension\r
     //\r
-    if (StrLen(FileWithPath) > 4) {\r
-      TempLocation = FileWithPath+StrLen(FileWithPath)-4;\r
+    if (StrLen (FileWithPath) > 4) {\r
+      TempLocation  = FileWithPath+StrLen (FileWithPath)-4;\r
       TempLocation2 = mScriptExtension;\r
       TempLocation2 = mScriptExtension;\r
-      if (StringNoCaseCompare((VOID*)(&TempLocation), (VOID*)(&TempLocation2)) == 0) {\r
-        SHELL_FREE_NON_NULL(FileWithPath);\r
+      if (StringNoCaseCompare ((VOID *)(&TempLocation), (VOID *)(&TempLocation2)) == 0) {\r
+        SHELL_FREE_NON_NULL (FileWithPath);\r
         return (Script_File_Name);\r
       }\r
     }\r
         return (Script_File_Name);\r
       }\r
     }\r
@@ -1936,11 +2110,11 @@ GetOperationType(
     //\r
     // Was a file, but not a script.  we treat this as an application.\r
     //\r
     //\r
     // Was a file, but not a script.  we treat this as an application.\r
     //\r
-    SHELL_FREE_NON_NULL(FileWithPath);\r
+    SHELL_FREE_NON_NULL (FileWithPath);\r
     return (Efi_Application);\r
   }\r
     return (Efi_Application);\r
   }\r
-  \r
-  SHELL_FREE_NON_NULL(FileWithPath);\r
+\r
+  SHELL_FREE_NON_NULL (FileWithPath);\r
   //\r
   // No clue what this is... return invalid flag...\r
   //\r
   //\r
   // No clue what this is... return invalid flag...\r
   //\r
@@ -1956,25 +2130,24 @@ GetOperationType(
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
   @retval EFI_NOT_FOUND         The operation type is unknown or invalid.\r
 **/\r
   @retval EFI_OUT_OF_RESOURCES  A memory allocation failed.\r
   @retval EFI_NOT_FOUND         The operation type is unknown or invalid.\r
 **/\r
-EFI_STATUS \r
-EFIAPI\r
-IsValidSplit(\r
-  IN CONST CHAR16 *CmdLine\r
+EFI_STATUS\r
+IsValidSplit (\r
+  IN CONST CHAR16  *CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  CHAR16        *Temp;\r
-  CHAR16        *FirstParameter;\r
-  CHAR16        *TempWalker;\r
-  EFI_STATUS    Status;\r
+  CHAR16      *Temp;\r
+  CHAR16      *FirstParameter;\r
+  CHAR16      *TempWalker;\r
+  EFI_STATUS  Status;\r
 \r
 \r
-  Temp           = NULL;\r
+  Temp = NULL;\r
 \r
 \r
-  Temp = StrnCatGrow(&Temp, NULL, CmdLine, 0);\r
+  Temp = StrnCatGrow (&Temp, NULL, CmdLine, 0);\r
   if (Temp == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
   if (Temp == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
-  FirstParameter = StrStr(Temp, L"|");\r
+  FirstParameter = StrStr (Temp, L"|");\r
   if (FirstParameter != NULL) {\r
     *FirstParameter = CHAR_NULL;\r
   }\r
   if (FirstParameter != NULL) {\r
     *FirstParameter = CHAR_NULL;\r
   }\r
@@ -1984,26 +2157,27 @@ IsValidSplit(
   //\r
   // Process the command line\r
   //\r
   //\r
   // Process the command line\r
   //\r
-  Status = ProcessCommandLineToFinal(&Temp);\r
+  Status = ProcessCommandLineToFinal (&Temp);\r
 \r
 \r
-  if (!EFI_ERROR(Status)) {\r
-    FirstParameter = AllocateZeroPool(StrSize(CmdLine));\r
+  if (!EFI_ERROR (Status)) {\r
+    FirstParameter = AllocateZeroPool (StrSize (CmdLine));\r
     if (FirstParameter == NULL) {\r
     if (FirstParameter == NULL) {\r
-      SHELL_FREE_NON_NULL(Temp);\r
+      SHELL_FREE_NON_NULL (Temp);\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
-    TempWalker = (CHAR16*)Temp;\r
-    if (!EFI_ERROR (ShellGetNextParameter (&TempWalker, FirstParameter, StrSize(CmdLine), TRUE))) {\r
-      if (GetOperationType(FirstParameter) == Unknown_Invalid) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
-        SetLastError(SHELL_NOT_FOUND);\r
+\r
+    TempWalker = (CHAR16 *)Temp;\r
+    if (!EFI_ERROR (GetNextParameter (&TempWalker, &FirstParameter, StrSize (CmdLine), TRUE))) {\r
+      if (GetOperationType (FirstParameter) == Unknown_Invalid) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+        SetLastError (SHELL_NOT_FOUND);\r
         Status = EFI_NOT_FOUND;\r
       }\r
     }\r
   }\r
 \r
         Status = EFI_NOT_FOUND;\r
       }\r
     }\r
   }\r
 \r
-  SHELL_FREE_NON_NULL(Temp);\r
-  SHELL_FREE_NON_NULL(FirstParameter);\r
+  SHELL_FREE_NON_NULL (Temp);\r
+  SHELL_FREE_NON_NULL (FirstParameter);\r
   return Status;\r
 }\r
 \r
   return Status;\r
 }\r
 \r
@@ -2016,9 +2190,8 @@ IsValidSplit(
   @retval EFI_ABORTED     CmdLine has at least one invalid command or application.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_ABORTED     CmdLine has at least one invalid command or application.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-VerifySplit(\r
-  IN CONST CHAR16 *CmdLine\r
+VerifySplit (\r
+  IN CONST CHAR16  *CmdLine\r
   )\r
 {\r
   CONST CHAR16  *TempSpot;\r
   )\r
 {\r
   CONST CHAR16  *TempSpot;\r
@@ -2027,30 +2200,31 @@ VerifySplit(
   //\r
   // If this was the only item, then get out\r
   //\r
   //\r
   // If this was the only item, then get out\r
   //\r
-  if (!ContainsSplit(CmdLine)) {\r
+  if (!ContainsSplit (CmdLine)) {\r
     return (EFI_SUCCESS);\r
   }\r
 \r
   //\r
   // Verify up to the pipe or end character\r
   //\r
     return (EFI_SUCCESS);\r
   }\r
 \r
   //\r
   // Verify up to the pipe or end character\r
   //\r
-  Status = IsValidSplit(CmdLine);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = IsValidSplit (CmdLine);\r
+  if (EFI_ERROR (Status)) {\r
     return (Status);\r
   }\r
 \r
   //\r
   // recurse to verify the next item\r
   //\r
     return (Status);\r
   }\r
 \r
   //\r
   // recurse to verify the next item\r
   //\r
-  TempSpot = ShellFindFirstCharacter(CmdLine, L"|", TRUE) + 1;\r
-  if (*TempSpot == L'a' && \r
-      (*(TempSpot + 1) == L' ' || *(TempSpot + 1) == CHAR_NULL)\r
-     ) {\r
+  TempSpot = FindFirstCharacter (CmdLine, L"|", L'^') + 1;\r
+  if ((*TempSpot == L'a') &&\r
+      ((*(TempSpot + 1) == L' ') || (*(TempSpot + 1) == CHAR_NULL))\r
+      )\r
+  {\r
     // If it's an ASCII pipe '|a'\r
     TempSpot += 1;\r
   }\r
     // If it's an ASCII pipe '|a'\r
     TempSpot += 1;\r
   }\r
-  \r
-  return (VerifySplit(TempSpot));\r
+\r
+  return (VerifySplit (TempSpot));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -2062,16 +2236,15 @@ VerifySplit(
   @return               an error occurred.\r
 **/\r
 EFI_STATUS\r
   @return               an error occurred.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-ProcessNewSplitCommandLine(\r
-  IN CONST CHAR16 *CmdLine\r
+ProcessNewSplitCommandLine (\r
+  IN CONST CHAR16  *CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  SPLIT_LIST                *Split;\r
-  EFI_STATUS                Status;\r
+  SPLIT_LIST  *Split;\r
+  EFI_STATUS  Status;\r
 \r
 \r
-  Status = VerifySplit(CmdLine);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = VerifySplit (CmdLine);\r
+  if (EFI_ERROR (Status)) {\r
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
@@ -2080,18 +2253,20 @@ ProcessNewSplitCommandLine(
   //\r
   // are we in an existing split???\r
   //\r
   //\r
   // are we in an existing split???\r
   //\r
-  if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {\r
-    Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);\r
+  if (!IsListEmpty (&ShellInfoObject.SplitList.Link)) {\r
+    Split = (SPLIT_LIST *)GetFirstNode (&ShellInfoObject.SplitList.Link);\r
   }\r
 \r
   if (Split == NULL) {\r
   }\r
 \r
   if (Split == NULL) {\r
-    Status = RunSplitCommand(CmdLine, NULL, NULL);\r
+    Status = RunSplitCommand (CmdLine, NULL, NULL);\r
   } else {\r
   } else {\r
-    Status = RunSplitCommand(CmdLine, Split->SplitStdIn, Split->SplitStdOut);\r
+    Status = RunSplitCommand (CmdLine, Split->SplitStdIn, Split->SplitStdOut);\r
   }\r
   }\r
-  if (EFI_ERROR(Status)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_SPLIT), ShellInfoObject.HiiHandle, CmdLine);\r
   }\r
   }\r
+\r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
 \r
@@ -2103,29 +2278,29 @@ ProcessNewSplitCommandLine(
   @retval EFI_SUCCESS The operation was successful.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_SUCCESS The operation was successful.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-ChangeMappedDrive(\r
-  IN CONST CHAR16 *CmdLine\r
+ChangeMappedDrive (\r
+  IN CONST CHAR16  *CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS Status;\r
+  EFI_STATUS  Status;\r
+\r
   Status = EFI_SUCCESS;\r
 \r
   //\r
   // make sure we are the right operation\r
   //\r
   Status = EFI_SUCCESS;\r
 \r
   //\r
   // make sure we are the right operation\r
   //\r
-  ASSERT(CmdLine[(StrLen(CmdLine)-1)] == L':' && StrStr(CmdLine, L" ") == NULL);\r
-  \r
+  ASSERT (CmdLine[(StrLen (CmdLine)-1)] == L':' && StrStr (CmdLine, L" ") == NULL);\r
+\r
   //\r
   // Call the protocol API to do the work\r
   //\r
   //\r
   // Call the protocol API to do the work\r
   //\r
-  Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir(NULL, CmdLine);\r
+  Status = ShellInfoObject.NewEfiShellProtocol->SetCurDir (NULL, CmdLine);\r
 \r
   //\r
   // Report any errors\r
   //\r
 \r
   //\r
   // Report any errors\r
   //\r
-  if (EFI_ERROR(Status)) {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, CmdLine);\r
+  if (EFI_ERROR (Status)) {\r
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_MAPPING), ShellInfoObject.HiiHandle, CmdLine);\r
   }\r
 \r
   return (Status);\r
   }\r
 \r
   return (Status);\r
@@ -2139,32 +2314,31 @@ ChangeMappedDrive(
   @param[in,out] CmdLine        pointer to the command line to update\r
 **/\r
 EFI_STATUS\r
   @param[in,out] CmdLine        pointer to the command line to update\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-DoHelpUpdate(\r
-  IN OUT CHAR16 **CmdLine\r
+DoHelpUpdate (\r
+  IN OUT CHAR16  **CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  CHAR16 *CurrentParameter;\r
-  CHAR16 *Walker;\r
-  CHAR16 *NewCommandLine;\r
-  EFI_STATUS Status;\r
-  UINTN  NewCmdLineSize;\r
+  CHAR16      *CurrentParameter;\r
+  CHAR16      *Walker;\r
+  CHAR16      *NewCommandLine;\r
+  EFI_STATUS  Status;\r
+  UINTN       NewCmdLineSize;\r
 \r
   Status = EFI_SUCCESS;\r
 \r
 \r
   Status = EFI_SUCCESS;\r
 \r
-  CurrentParameter = AllocateZeroPool(StrSize(*CmdLine));\r
+  CurrentParameter = AllocateZeroPool (StrSize (*CmdLine));\r
   if (CurrentParameter == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
   Walker = *CmdLine;\r
   if (CurrentParameter == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
   Walker = *CmdLine;\r
-  while(Walker != NULL && *Walker != CHAR_NULL) {\r
-    if (!EFI_ERROR (ShellGetNextParameter (&Walker, CurrentParameter, StrSize(*CmdLine), TRUE))) {\r
-      if (StrStr(CurrentParameter, L"-?") == CurrentParameter) {\r
+  while (Walker != NULL && *Walker != CHAR_NULL) {\r
+    if (!EFI_ERROR (GetNextParameter (&Walker, &CurrentParameter, StrSize (*CmdLine), TRUE))) {\r
+      if (StrStr (CurrentParameter, L"-?") == CurrentParameter) {\r
         CurrentParameter[0] = L' ';\r
         CurrentParameter[1] = L' ';\r
         CurrentParameter[0] = L' ';\r
         CurrentParameter[1] = L' ';\r
-        NewCmdLineSize = StrSize(L"help ") + StrSize(*CmdLine);\r
-        NewCommandLine = AllocateZeroPool(NewCmdLineSize);\r
+        NewCmdLineSize      = StrSize (L"help ") + StrSize (*CmdLine);\r
+        NewCommandLine      = AllocateZeroPool (NewCmdLineSize);\r
         if (NewCommandLine == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
           break;\r
         if (NewCommandLine == NULL) {\r
           Status = EFI_OUT_OF_RESOURCES;\r
           break;\r
@@ -2173,16 +2347,16 @@ DoHelpUpdate(
         //\r
         // We know the space is sufficient since we just calculated it.\r
         //\r
         //\r
         // We know the space is sufficient since we just calculated it.\r
         //\r
-        StrnCpyS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), L"help ", 5);\r
-        StrnCatS(NewCommandLine, NewCmdLineSize/sizeof(CHAR16), *CmdLine, StrLen(*CmdLine));\r
-        SHELL_FREE_NON_NULL(*CmdLine);\r
+        StrnCpyS (NewCommandLine, NewCmdLineSize/sizeof (CHAR16), L"help ", 5);\r
+        StrnCatS (NewCommandLine, NewCmdLineSize/sizeof (CHAR16), *CmdLine, StrLen (*CmdLine));\r
+        SHELL_FREE_NON_NULL (*CmdLine);\r
         *CmdLine = NewCommandLine;\r
         break;\r
       }\r
     }\r
   }\r
 \r
         *CmdLine = NewCommandLine;\r
         break;\r
       }\r
     }\r
   }\r
 \r
-  SHELL_FREE_NON_NULL(CurrentParameter);\r
+  SHELL_FREE_NON_NULL (CurrentParameter);\r
 \r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
@@ -2193,25 +2367,28 @@ DoHelpUpdate(
   @param[in] ErrorCode      the error code to put into lasterror.\r
 **/\r
 EFI_STATUS\r
   @param[in] ErrorCode      the error code to put into lasterror.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-SetLastError(\r
-  IN CONST SHELL_STATUS   ErrorCode\r
+SetLastError (\r
+  IN CONST SHELL_STATUS  ErrorCode\r
   )\r
 {\r
   )\r
 {\r
-  CHAR16 LeString[19];\r
-  if (sizeof(EFI_STATUS) == sizeof(UINT64)) {\r
-    UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ErrorCode);\r
+  CHAR16  LeString[19];\r
+\r
+  if (sizeof (EFI_STATUS) == sizeof (UINT64)) {\r
+    UnicodeSPrint (LeString, sizeof (LeString), L"0x%Lx", ErrorCode);\r
   } else {\r
   } else {\r
-    UnicodeSPrint(LeString, sizeof(LeString), L"0x%x", ErrorCode);\r
+    UnicodeSPrint (LeString, sizeof (LeString), L"0x%x", ErrorCode);\r
   }\r
   }\r
-  DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
-  InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
+\r
+  DEBUG_CODE (\r
+    InternalEfiShellSetEnv (L"debuglasterror", LeString, TRUE);\r
+    );\r
+  InternalEfiShellSetEnv (L"lasterror", LeString, TRUE);\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
 /**\r
-  Converts the command line to it's post-processed form.  this replaces variables and alias' per UEFI Shell spec.\r
+  Converts the command line to its post-processed form.  this replaces variables and alias' per UEFI Shell spec.\r
 \r
   @param[in,out] CmdLine        pointer to the command line to update\r
 \r
 \r
   @param[in,out] CmdLine        pointer to the command line to update\r
 \r
@@ -2220,41 +2397,42 @@ SetLastError(
   @return                       some other error occurred\r
 **/\r
 EFI_STATUS\r
   @return                       some other error occurred\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-ProcessCommandLineToFinal(\r
-  IN OUT CHAR16 **CmdLine\r
+ProcessCommandLineToFinal (\r
+  IN OUT CHAR16  **CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  TrimSpaces(CmdLine);\r
+  EFI_STATUS  Status;\r
+\r
+  TrimSpaces (CmdLine);\r
 \r
 \r
-  Status = ShellSubstituteAliases(CmdLine);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = ShellSubstituteAliases (CmdLine);\r
+  if (EFI_ERROR (Status)) {\r
     return (Status);\r
   }\r
 \r
     return (Status);\r
   }\r
 \r
-  TrimSpaces(CmdLine);\r
+  TrimSpaces (CmdLine);\r
 \r
 \r
-  Status = ShellSubstituteVariables(CmdLine);\r
-  if (EFI_ERROR(Status)) {\r
+  Status = ShellSubstituteVariables (CmdLine);\r
+  if (EFI_ERROR (Status)) {\r
     return (Status);\r
   }\r
     return (Status);\r
   }\r
+\r
   ASSERT (*CmdLine != NULL);\r
 \r
   ASSERT (*CmdLine != NULL);\r
 \r
-  TrimSpaces(CmdLine);\r
+  TrimSpaces (CmdLine);\r
 \r
   //\r
   // update for help parsing\r
   //\r
 \r
   //\r
   // update for help parsing\r
   //\r
-  if (StrStr(*CmdLine, L"?") != NULL) {\r
+  if (StrStr (*CmdLine, L"?") != NULL) {\r
     //\r
     // This may do nothing if the ? does not indicate help.\r
     // Save all the details for in the API below.\r
     //\r
     //\r
     // This may do nothing if the ? does not indicate help.\r
     // Save all the details for in the API below.\r
     //\r
-    Status = DoHelpUpdate(CmdLine);\r
+    Status = DoHelpUpdate (CmdLine);\r
   }\r
 \r
   }\r
 \r
-  TrimSpaces(CmdLine);\r
+  TrimSpaces (CmdLine);\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
@@ -2263,7 +2441,7 @@ ProcessCommandLineToFinal(
   Run an internal shell command.\r
 \r
   This API will update the shell's environment since these commands are libraries.\r
   Run an internal shell command.\r
 \r
   This API will update the shell's environment since these commands are libraries.\r
-  \r
+\r
   @param[in] CmdLine          the command line to run.\r
   @param[in] FirstParameter   the first parameter on the command line\r
   @param[in] ParamProtocol    the shell parameters protocol pointer\r
   @param[in] CmdLine          the command line to run.\r
   @param[in] FirstParameter   the first parameter on the command line\r
   @param[in] ParamProtocol    the shell parameters protocol pointer\r
@@ -2273,44 +2451,43 @@ ProcessCommandLineToFinal(
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-RunInternalCommand(\r
+RunInternalCommand (\r
   IN CONST CHAR16                   *CmdLine,\r
   IN       CHAR16                   *FirstParameter,\r
   IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
   OUT EFI_STATUS                    *CommandStatus\r
   IN CONST CHAR16                   *CmdLine,\r
   IN       CHAR16                   *FirstParameter,\r
   IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
   OUT EFI_STATUS                    *CommandStatus\r
-)\r
+  )\r
 {\r
 {\r
-  EFI_STATUS                Status;\r
-  UINTN                     Argc;\r
-  CHAR16                    **Argv;\r
-  SHELL_STATUS              CommandReturnedStatus;\r
-  BOOLEAN                   LastError;\r
-  CHAR16                    *Walker;\r
-  CHAR16                    *NewCmdLine;  \r
+  EFI_STATUS    Status;\r
+  UINTN         Argc;\r
+  CHAR16        **Argv;\r
+  SHELL_STATUS  CommandReturnedStatus;\r
+  BOOLEAN       LastError;\r
+  CHAR16        *Walker;\r
+  CHAR16        *NewCmdLine;\r
 \r
   NewCmdLine = AllocateCopyPool (StrSize (CmdLine), CmdLine);\r
   if (NewCmdLine == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
 \r
   NewCmdLine = AllocateCopyPool (StrSize (CmdLine), CmdLine);\r
   if (NewCmdLine == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {\r
-    if (*Walker == L'^' && *(Walker+1) == L'#') {\r
-      CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));\r
+  for (Walker = NewCmdLine; Walker != NULL && *Walker != CHAR_NULL; Walker++) {\r
+    if ((*Walker == L'^') && (*(Walker+1) == L'#')) {\r
+      CopyMem (Walker, Walker+1, StrSize (Walker) - sizeof (Walker[0]));\r
     }\r
   }\r
 \r
   //\r
   // get the argc and argv updated for internal commands\r
   //\r
     }\r
   }\r
 \r
   //\r
   // get the argc and argv updated for internal commands\r
   //\r
-  Status = UpdateArgcArgv(ParamProtocol, NewCmdLine, Internal_Command, &Argv, &Argc);\r
-  if (!EFI_ERROR(Status)) {\r
+  Status = UpdateArgcArgv (ParamProtocol, NewCmdLine, Internal_Command, &Argv, &Argc);\r
+  if (!EFI_ERROR (Status)) {\r
     //\r
     // Run the internal command.\r
     //\r
     //\r
     // Run the internal command.\r
     //\r
-    Status = ShellCommandRunCommandHandler(FirstParameter, &CommandReturnedStatus, &LastError);\r
+    Status = ShellCommandRunCommandHandler (FirstParameter, &CommandReturnedStatus, &LastError);\r
 \r
 \r
-    if (!EFI_ERROR(Status)) {\r
+    if (!EFI_ERROR (Status)) {\r
       if (CommandStatus != NULL) {\r
         if (CommandReturnedStatus != SHELL_SUCCESS) {\r
           *CommandStatus = (EFI_STATUS)(CommandReturnedStatus | MAX_BIT);\r
       if (CommandStatus != NULL) {\r
         if (CommandReturnedStatus != SHELL_SUCCESS) {\r
           *CommandStatus = (EFI_STATUS)(CommandReturnedStatus | MAX_BIT);\r
@@ -2324,23 +2501,23 @@ RunInternalCommand(
       // some commands do not update last error.\r
       //\r
       if (LastError) {\r
       // some commands do not update last error.\r
       //\r
       if (LastError) {\r
-        SetLastError(CommandReturnedStatus);\r
+        SetLastError (CommandReturnedStatus);\r
       }\r
 \r
       //\r
       // Pass thru the exitcode from the app.\r
       //\r
       }\r
 \r
       //\r
       // Pass thru the exitcode from the app.\r
       //\r
-      if (ShellCommandGetExit()) {\r
+      if (ShellCommandGetExit ()) {\r
         //\r
         // An Exit was requested ("exit" command), pass its value up.\r
         //\r
         Status = CommandReturnedStatus;\r
         //\r
         // An Exit was requested ("exit" command), pass its value up.\r
         //\r
         Status = CommandReturnedStatus;\r
-      } else if (CommandReturnedStatus != SHELL_SUCCESS && IsScriptOnlyCommand(FirstParameter)) {\r
+      } else if ((CommandReturnedStatus != SHELL_SUCCESS) && IsScriptOnlyCommand (FirstParameter)) {\r
         //\r
         // Always abort when a script only command fails for any reason\r
         //\r
         Status = EFI_ABORTED;\r
         //\r
         // Always abort when a script only command fails for any reason\r
         //\r
         Status = EFI_ABORTED;\r
-      } else if (ShellCommandGetCurrentScriptFile() != NULL && CommandReturnedStatus == SHELL_ABORTED) {\r
+      } else if ((ShellCommandGetCurrentScriptFile () != NULL) && (CommandReturnedStatus == SHELL_ABORTED)) {\r
         //\r
         // Abort when in a script and a command aborted\r
         //\r
         //\r
         // Abort when in a script and a command aborted\r
         //\r
@@ -2353,7 +2530,7 @@ RunInternalCommand(
   // This is guaranteed to be called after UpdateArgcArgv no matter what else happened.\r
   // This is safe even if the update API failed.  In this case, it may be a no-op.\r
   //\r
   // This is guaranteed to be called after UpdateArgcArgv no matter what else happened.\r
   // This is safe even if the update API failed.  In this case, it may be a no-op.\r
   //\r
-  RestoreArgcArgv(ParamProtocol, &Argv, &Argc);\r
+  RestoreArgcArgv (ParamProtocol, &Argv, &Argc);\r
 \r
   //\r
   // If a script is running and the command is not a script only command, then\r
 \r
   //\r
   // If a script is running and the command is not a script only command, then\r
@@ -2362,10 +2539,11 @@ RunInternalCommand(
   // Script only commands have to be able halt the script since the script will\r
   // not operate if they are failing.\r
   //\r
   // Script only commands have to be able halt the script since the script will\r
   // not operate if they are failing.\r
   //\r
-  if ( ShellCommandGetCurrentScriptFile() != NULL\r
-    && !IsScriptOnlyCommand(FirstParameter)\r
-    && Status != EFI_ABORTED\r
-    ) {\r
+  if (  (ShellCommandGetCurrentScriptFile () != NULL)\r
+     && !IsScriptOnlyCommand (FirstParameter)\r
+     && (Status != EFI_ABORTED)\r
+        )\r
+  {\r
     Status = EFI_SUCCESS;\r
   }\r
 \r
     Status = EFI_SUCCESS;\r
   }\r
 \r
@@ -2386,39 +2564,39 @@ RunInternalCommand(
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-RunCommandOrFile(\r
+RunCommandOrFile (\r
   IN       SHELL_OPERATION_TYPES    Type,\r
   IN CONST CHAR16                   *CmdLine,\r
   IN       CHAR16                   *FirstParameter,\r
   IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
   OUT EFI_STATUS                    *CommandStatus\r
   IN       SHELL_OPERATION_TYPES    Type,\r
   IN CONST CHAR16                   *CmdLine,\r
   IN       CHAR16                   *FirstParameter,\r
   IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
   OUT EFI_STATUS                    *CommandStatus\r
-)\r
+  )\r
 {\r
   EFI_STATUS                Status;\r
   EFI_STATUS                StartStatus;\r
   CHAR16                    *CommandWithPath;\r
 {\r
   EFI_STATUS                Status;\r
   EFI_STATUS                StartStatus;\r
   CHAR16                    *CommandWithPath;\r
+  CHAR16                    *FullCommandWithPath;\r
   EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   SHELL_STATUS              CalleeExitStatus;\r
 \r
   EFI_DEVICE_PATH_PROTOCOL  *DevPath;\r
   SHELL_STATUS              CalleeExitStatus;\r
 \r
-  Status            = EFI_SUCCESS;\r
-  CommandWithPath   = NULL;\r
-  DevPath           = NULL;\r
-  CalleeExitStatus  = SHELL_INVALID_PARAMETER;\r
+  Status           = EFI_SUCCESS;\r
+  CommandWithPath  = NULL;\r
+  DevPath          = NULL;\r
+  CalleeExitStatus = SHELL_INVALID_PARAMETER;\r
 \r
   switch (Type) {\r
 \r
   switch (Type) {\r
-    case   Internal_Command:\r
-      Status = RunInternalCommand(CmdLine, FirstParameter, ParamProtocol, CommandStatus);\r
+    case Internal_Command:\r
+      Status = RunInternalCommand (CmdLine, FirstParameter, ParamProtocol, CommandStatus);\r
       break;\r
       break;\r
-    case   Script_File_Name:\r
-    case   Efi_Application:\r
+    case Script_File_Name:\r
+    case Efi_Application:\r
       //\r
       // Process a fully qualified path\r
       //\r
       //\r
       // Process a fully qualified path\r
       //\r
-      if (StrStr(FirstParameter, L":") != NULL) {\r
+      if (StrStr (FirstParameter, L":") != NULL) {\r
         ASSERT (CommandWithPath == NULL);\r
         ASSERT (CommandWithPath == NULL);\r
-        if (ShellIsFile(FirstParameter) == EFI_SUCCESS) {\r
-          CommandWithPath = StrnCatGrow(&CommandWithPath, NULL, FirstParameter, 0);\r
+        if (ShellIsFile (FirstParameter) == EFI_SUCCESS) {\r
+          CommandWithPath = StrnCatGrow (&CommandWithPath, NULL, FirstParameter, 0);\r
         }\r
       }\r
 \r
         }\r
       }\r
 \r
@@ -2426,31 +2604,39 @@ RunCommandOrFile(
       // Process a relative path and also check in the path environment variable\r
       //\r
       if (CommandWithPath == NULL) {\r
       // Process a relative path and also check in the path environment variable\r
       //\r
       if (CommandWithPath == NULL) {\r
-        CommandWithPath = ShellFindFilePathEx(FirstParameter, mExecutableExtensions);\r
+        CommandWithPath = ShellFindFilePathEx (FirstParameter, mExecutableExtensions);\r
       }\r
 \r
       //\r
       // This should be impossible now.\r
       //\r
       }\r
 \r
       //\r
       // This should be impossible now.\r
       //\r
-      ASSERT(CommandWithPath != NULL);\r
+      ASSERT (CommandWithPath != NULL);\r
 \r
       //\r
       // Make sure that path is not just a directory (or not found)\r
       //\r
 \r
       //\r
       // Make sure that path is not just a directory (or not found)\r
       //\r
-      if (!EFI_ERROR(ShellIsDirectory(CommandWithPath))) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
-        SetLastError(SHELL_NOT_FOUND);\r
+      if (!EFI_ERROR (ShellIsDirectory (CommandWithPath))) {\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+        SetLastError (SHELL_NOT_FOUND);\r
       }\r
       }\r
+\r
       switch (Type) {\r
       switch (Type) {\r
-        case   Script_File_Name:\r
-          Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);\r
+        case Script_File_Name:\r
+          FullCommandWithPath = FullyQualifyPath (CommandWithPath);\r
+          if (FullCommandWithPath == NULL) {\r
+            Status = RunScriptFile (CommandWithPath, NULL, CmdLine, ParamProtocol);\r
+          } else {\r
+            Status = RunScriptFile (FullCommandWithPath, NULL, CmdLine, ParamProtocol);\r
+            FreePool (FullCommandWithPath);\r
+          }\r
+\r
           break;\r
           break;\r
-        case   Efi_Application:\r
+        case Efi_Application:\r
           //\r
           // Get the device path of the application image\r
           //\r
           //\r
           // Get the device path of the application image\r
           //\r
-          DevPath = ShellInfoObject.NewEfiShellProtocol->GetDevicePathFromFilePath(CommandWithPath);\r
-          if (DevPath == NULL){\r
+          DevPath = ShellInfoObject.NewEfiShellProtocol->GetDevicePathFromFilePath (CommandWithPath);\r
+          if (DevPath == NULL) {\r
             Status = EFI_OUT_OF_RESOURCES;\r
             break;\r
           }\r
             Status = EFI_OUT_OF_RESOURCES;\r
             break;\r
           }\r
@@ -2458,20 +2644,20 @@ RunCommandOrFile(
           //\r
           // Execute the device path\r
           //\r
           //\r
           // Execute the device path\r
           //\r
-          Status = InternalShellExecuteDevicePath(\r
-            &gImageHandle,\r
-            DevPath,\r
-            CmdLine,\r
-            NULL,\r
-            &StartStatus\r
-           );\r
-\r
-          SHELL_FREE_NON_NULL(DevPath);\r
-\r
-          if(EFI_ERROR (Status)) {\r
-            CalleeExitStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
+          Status = InternalShellExecuteDevicePath (\r
+                     &gImageHandle,\r
+                     DevPath,\r
+                     CmdLine,\r
+                     NULL,\r
+                     &StartStatus\r
+                     );\r
+\r
+          SHELL_FREE_NON_NULL (DevPath);\r
+\r
+          if (EFI_ERROR (Status)) {\r
+            CalleeExitStatus = (SHELL_STATUS)(Status & (~MAX_BIT));\r
           } else {\r
           } else {\r
-            CalleeExitStatus = (SHELL_STATUS) StartStatus;\r
+            CalleeExitStatus = (SHELL_STATUS)StartStatus;\r
           }\r
 \r
           if (CommandStatus != NULL) {\r
           }\r
 \r
           if (CommandStatus != NULL) {\r
@@ -2482,7 +2668,7 @@ RunCommandOrFile(
           // Update last error status.\r
           //\r
           // Status is an EFI_STATUS. Clear top bit to convert to SHELL_STATUS\r
           // Update last error status.\r
           //\r
           // Status is an EFI_STATUS. Clear top bit to convert to SHELL_STATUS\r
-          SetLastError(CalleeExitStatus);\r
+          SetLastError (CalleeExitStatus);\r
           break;\r
         default:\r
           //\r
           break;\r
         default:\r
           //\r
@@ -2490,6 +2676,7 @@ RunCommandOrFile(
           //\r
           break;\r
       }\r
           //\r
           break;\r
       }\r
+\r
       break;\r
     default:\r
       //\r
       break;\r
     default:\r
       //\r
@@ -2498,7 +2685,7 @@ RunCommandOrFile(
       break;\r
   }\r
 \r
       break;\r
   }\r
 \r
-  SHELL_FREE_NON_NULL(CommandWithPath);\r
+  SHELL_FREE_NON_NULL (CommandWithPath);\r
 \r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
@@ -2516,52 +2703,51 @@ RunCommandOrFile(
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-SetupAndRunCommandOrFile(\r
+SetupAndRunCommandOrFile (\r
   IN   SHELL_OPERATION_TYPES          Type,\r
   IN   CHAR16                         *CmdLine,\r
   IN   CHAR16                         *FirstParameter,\r
   IN   EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
   OUT EFI_STATUS                      *CommandStatus\r
   IN   SHELL_OPERATION_TYPES          Type,\r
   IN   CHAR16                         *CmdLine,\r
   IN   CHAR16                         *FirstParameter,\r
   IN   EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol,\r
   OUT EFI_STATUS                      *CommandStatus\r
-)\r
+  )\r
 {\r
 {\r
-  EFI_STATUS                Status;\r
-  SHELL_FILE_HANDLE         OriginalStdIn;\r
-  SHELL_FILE_HANDLE         OriginalStdOut;\r
-  SHELL_FILE_HANDLE         OriginalStdErr;\r
-  SYSTEM_TABLE_INFO         OriginalSystemTableInfo;\r
-  CONST SCRIPT_FILE         *ConstScriptFile;\r
+  EFI_STATUS         Status;\r
+  SHELL_FILE_HANDLE  OriginalStdIn;\r
+  SHELL_FILE_HANDLE  OriginalStdOut;\r
+  SHELL_FILE_HANDLE  OriginalStdErr;\r
+  SYSTEM_TABLE_INFO  OriginalSystemTableInfo;\r
+  CONST SCRIPT_FILE  *ConstScriptFile;\r
 \r
   //\r
   // Update the StdIn, StdOut, and StdErr for redirection to environment variables, files, etc... unicode and ASCII\r
   //\r
 \r
   //\r
   // Update the StdIn, StdOut, and StdErr for redirection to environment variables, files, etc... unicode and ASCII\r
   //\r
-  Status = UpdateStdInStdOutStdErr(ParamProtocol, CmdLine, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r
+  Status = UpdateStdInStdOutStdErr (ParamProtocol, CmdLine, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r
 \r
   //\r
   // The StdIn, StdOut, and StdErr are set up.\r
   // Now run the command, script, or application\r
   //\r
 \r
   //\r
   // The StdIn, StdOut, and StdErr are set up.\r
   // Now run the command, script, or application\r
   //\r
-  if (!EFI_ERROR(Status)) {\r
-    TrimSpaces(&CmdLine);\r
-    Status = RunCommandOrFile(Type, CmdLine, FirstParameter, ParamProtocol, CommandStatus);\r
+  if (!EFI_ERROR (Status)) {\r
+    TrimSpaces (&CmdLine);\r
+    Status = RunCommandOrFile (Type, CmdLine, FirstParameter, ParamProtocol, CommandStatus);\r
   }\r
 \r
   //\r
   // Now print errors\r
   //\r
   }\r
 \r
   //\r
   // Now print errors\r
   //\r
-  if (EFI_ERROR(Status)) {\r
-    ConstScriptFile = ShellCommandGetCurrentScriptFile();\r
-    if (ConstScriptFile == NULL || ConstScriptFile->CurrentCommand == NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR), ShellInfoObject.HiiHandle, (VOID*)(Status));\r
+  if (EFI_ERROR (Status)) {\r
+    ConstScriptFile = ShellCommandGetCurrentScriptFile ();\r
+    if ((ConstScriptFile == NULL) || (ConstScriptFile->CurrentCommand == NULL)) {\r
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR), ShellInfoObject.HiiHandle, (VOID *)(Status));\r
     } else {\r
     } else {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR_SCRIPT), ShellInfoObject.HiiHandle, (VOID*)(Status), ConstScriptFile->CurrentCommand->Line);\r
+      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_ERROR_SCRIPT), ShellInfoObject.HiiHandle, (VOID *)(Status), ConstScriptFile->CurrentCommand->Line);\r
     }\r
   }\r
 \r
   //\r
   // put back the original StdIn, StdOut, and StdErr\r
   //\r
     }\r
   }\r
 \r
   //\r
   // put back the original StdIn, StdOut, and StdErr\r
   //\r
-  RestoreStdInStdOutStdErr(ParamProtocol, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r
+  RestoreStdInStdOutStdErr (ParamProtocol, &OriginalStdIn, &OriginalStdOut, &OriginalStdErr, &OriginalSystemTableInfo);\r
 \r
   return (Status);\r
 }\r
 \r
   return (Status);\r
 }\r
@@ -2569,7 +2755,7 @@ SetupAndRunCommandOrFile(
 /**\r
   Function will process and run a command line.\r
 \r
 /**\r
   Function will process and run a command line.\r
 \r
-  This will determine if the command line represents an internal shell \r
+  This will determine if the command line represents an internal shell\r
   command or dispatch an external application.\r
 \r
   @param[in] CmdLine      The command line to parse.\r
   command or dispatch an external application.\r
 \r
   @param[in] CmdLine      The command line to parse.\r
@@ -2579,36 +2765,32 @@ SetupAndRunCommandOrFile(
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-RunShellCommand(\r
-  IN CONST CHAR16   *CmdLine,\r
-  OUT EFI_STATUS    *CommandStatus\r
+RunShellCommand (\r
+  IN CONST CHAR16  *CmdLine,\r
+  OUT EFI_STATUS   *CommandStatus\r
   )\r
 {\r
   )\r
 {\r
-  EFI_STATUS                Status;\r
-  CHAR16                    *CleanOriginal;\r
-  CHAR16                    *FirstParameter;\r
-  CHAR16                    *TempWalker;\r
-  SHELL_OPERATION_TYPES     Type;\r
-  CHAR16                    *OldCmdLine;\r
-\r
-  ASSERT(CmdLine != NULL);\r
-  if (StrLen(CmdLine) == 0) {\r
+  EFI_STATUS             Status;\r
+  CHAR16                 *CleanOriginal;\r
+  CHAR16                 *FirstParameter;\r
+  CHAR16                 *TempWalker;\r
+  SHELL_OPERATION_TYPES  Type;\r
+  CONST CHAR16           *CurDir;\r
+\r
+  ASSERT (CmdLine != NULL);\r
+  if (StrLen (CmdLine) == 0) {\r
     return (EFI_SUCCESS);\r
   }\r
 \r
     return (EFI_SUCCESS);\r
   }\r
 \r
-  Status              = EFI_SUCCESS;\r
-  FirstParameter      = NULL;\r
-  CleanOriginal       = NULL;\r
-  OldCmdLine          = NULL;\r
+  Status        = EFI_SUCCESS;\r
+  CleanOriginal = NULL;\r
 \r
 \r
-  CleanOriginal = StrnCatGrow(&CleanOriginal, NULL, CmdLine, 0);\r
+  CleanOriginal = StrnCatGrow (&CleanOriginal, NULL, CmdLine, 0);\r
   if (CleanOriginal == NULL) {\r
   if (CleanOriginal == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto Done;\r
+    return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
   }\r
 \r
-  TrimSpaces(&CleanOriginal);\r
+  TrimSpaces (&CleanOriginal);\r
 \r
   //\r
   // NULL out comments (leveraged from RunScriptFileHandle() ).\r
 \r
   //\r
   // NULL out comments (leveraged from RunScriptFileHandle() ).\r
@@ -2626,70 +2808,83 @@ RunShellCommand(
     }\r
   }\r
 \r
     }\r
   }\r
 \r
-  TrimSpaces(&CleanOriginal);\r
+  TrimSpaces (&CleanOriginal);\r
 \r
   //\r
   // Handle case that passed in command line is just 1 or more " " characters.\r
   //\r
   if (StrLen (CleanOriginal) == 0) {\r
 \r
   //\r
   // Handle case that passed in command line is just 1 or more " " characters.\r
   //\r
   if (StrLen (CleanOriginal) == 0) {\r
-    Status = EFI_SUCCESS;\r
-    goto Done;\r
+    SHELL_FREE_NON_NULL (CleanOriginal);\r
+    return (EFI_SUCCESS);\r
   }\r
 \r
   }\r
 \r
-  Status = ProcessCommandLineToFinal(&CleanOriginal);\r
-  if (EFI_ERROR(Status)) {\r
-    goto Done;\r
+  Status = ProcessCommandLineToFinal (&CleanOriginal);\r
+  if (EFI_ERROR (Status)) {\r
+    SHELL_FREE_NON_NULL (CleanOriginal);\r
+    return (Status);\r
   }\r
 \r
   }\r
 \r
-  OldCmdLine = ShellGetRawCmdLine ();\r
-  ShellSetRawCmdLine (CleanOriginal);\r
-\r
   //\r
   // We don't do normal processing with a split command line (output from one command input to another)\r
   //\r
   //\r
   // We don't do normal processing with a split command line (output from one command input to another)\r
   //\r
-  if (ContainsSplit(CleanOriginal)) {\r
-    Status = ProcessNewSplitCommandLine(CleanOriginal);\r
-    goto Done;\r
+  if (ContainsSplit (CleanOriginal)) {\r
+    Status = ProcessNewSplitCommandLine (CleanOriginal);\r
+    SHELL_FREE_NON_NULL (CleanOriginal);\r
+    return (Status);\r
   }\r
 \r
   //\r
   // We need the first parameter information so we can determine the operation type\r
   //\r
   }\r
 \r
   //\r
   // We need the first parameter information so we can determine the operation type\r
   //\r
-  FirstParameter = AllocateZeroPool(StrSize(CleanOriginal));\r
+  FirstParameter = AllocateZeroPool (StrSize (CleanOriginal));\r
   if (FirstParameter == NULL) {\r
   if (FirstParameter == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto Done;\r
+    SHELL_FREE_NON_NULL (CleanOriginal);\r
+    return (EFI_OUT_OF_RESOURCES);\r
   }\r
   }\r
+\r
   TempWalker = CleanOriginal;\r
   TempWalker = CleanOriginal;\r
-  if (!EFI_ERROR (ShellGetNextParameter (&TempWalker, FirstParameter, StrSize(CleanOriginal), TRUE))) {\r
+  if (!EFI_ERROR (GetNextParameter (&TempWalker, &FirstParameter, StrSize (CleanOriginal), TRUE))) {\r
     //\r
     // Depending on the first parameter we change the behavior\r
     //\r
     //\r
     // Depending on the first parameter we change the behavior\r
     //\r
-    switch (Type = GetOperationType(FirstParameter)) {\r
-      case   File_Sys_Change:\r
+    switch (Type = GetOperationType (FirstParameter)) {\r
+      case File_Sys_Change:\r
         Status = ChangeMappedDrive (FirstParameter);\r
         break;\r
         Status = ChangeMappedDrive (FirstParameter);\r
         break;\r
-      case   Internal_Command:\r
-      case   Script_File_Name:\r
-      case   Efi_Application:\r
-        Status = SetupAndRunCommandOrFile(Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol, CommandStatus);\r
+      case Internal_Command:\r
+      case Script_File_Name:\r
+      case Efi_Application:\r
+        Status = SetupAndRunCommandOrFile (Type, CleanOriginal, FirstParameter, ShellInfoObject.NewShellParametersProtocol, CommandStatus);\r
         break;\r
       default:\r
         //\r
         // Whatever was typed, it was invalid.\r
         //\r
         break;\r
       default:\r
         //\r
         // Whatever was typed, it was invalid.\r
         //\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
-        SetLastError(SHELL_NOT_FOUND);\r
+        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+        SetLastError (SHELL_NOT_FOUND);\r
         break;\r
     }\r
   } else {\r
         break;\r
     }\r
   } else {\r
-    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
-    SetLastError(SHELL_NOT_FOUND);\r
+    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_NOT_FOUND), ShellInfoObject.HiiHandle, FirstParameter);\r
+    SetLastError (SHELL_NOT_FOUND);\r
+  }\r
+\r
+  //\r
+  // Check whether the current file system still exists. If not exist, we need update "cwd" and gShellCurMapping.\r
+  //\r
+  CurDir = EfiShellGetCurDir (NULL);\r
+  if (CurDir != NULL) {\r
+    if (EFI_ERROR (ShellFileExists (CurDir))) {\r
+      //\r
+      // EfiShellSetCurDir() cannot set current directory to NULL.\r
+      // EfiShellSetEnv() is not allowed to set the "cwd" variable.\r
+      // Only InternalEfiShellSetEnv () is allowed setting the "cwd" variable.\r
+      //\r
+      InternalEfiShellSetEnv (L"cwd", NULL, TRUE);\r
+      gShellCurMapping = NULL;\r
+    }\r
   }\r
 \r
   }\r
 \r
-Done:\r
-  ShellSetRawCmdLine (OldCmdLine);\r
-  SHELL_FREE_NON_NULL (OldCmdLine);\r
   SHELL_FREE_NON_NULL (CleanOriginal);\r
   SHELL_FREE_NON_NULL (FirstParameter);\r
 \r
   SHELL_FREE_NON_NULL (CleanOriginal);\r
   SHELL_FREE_NON_NULL (FirstParameter);\r
 \r
@@ -2699,7 +2894,7 @@ Done:
 /**\r
   Function will process and run a command line.\r
 \r
 /**\r
   Function will process and run a command line.\r
 \r
-  This will determine if the command line represents an internal shell \r
+  This will determine if the command line represents an internal shell\r
   command or dispatch an external application.\r
 \r
   @param[in] CmdLine      The command line to parse.\r
   command or dispatch an external application.\r
 \r
   @param[in] CmdLine      The command line to parse.\r
@@ -2708,45 +2903,11 @@ Done:
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
   @retval EFI_ABORTED     The command's operation was aborted.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-RunCommand(\r
-  IN CONST CHAR16   *CmdLine\r
+RunCommand (\r
+  IN CONST CHAR16  *CmdLine\r
   )\r
 {\r
   )\r
 {\r
-  return (RunShellCommand(CmdLine, NULL));\r
-}\r
-\r
-\r
-STATIC CONST UINT16 InvalidChars[] = {L'*', L'?', L'<', L'>', L'\\', L'/', L'\"', 0x0001, 0x0002};\r
-/**\r
-  Function determines if the CommandName COULD be a valid command.  It does not determine whether\r
-  this is a valid command.  It only checks for invalid characters.\r
-\r
-  @param[in] CommandName    The name to check\r
-\r
-  @retval TRUE              CommandName could be a command name\r
-  @retval FALSE             CommandName could not be a valid command name\r
-**/\r
-BOOLEAN\r
-EFIAPI\r
-IsValidCommandName(\r
-  IN CONST CHAR16     *CommandName\r
-  )\r
-{\r
-  UINTN Count;\r
-  if (CommandName == NULL) {\r
-    ASSERT(FALSE);\r
-    return (FALSE);\r
-  }\r
-  for ( Count = 0\r
-      ; Count < sizeof(InvalidChars) / sizeof(InvalidChars[0])\r
-      ; Count++\r
-     ){\r
-    if (ScanMem16(CommandName, StrSize(CommandName), InvalidChars[Count]) != NULL) {\r
-      return (FALSE);\r
-    }\r
-  }\r
-  return (TRUE);\r
+  return (RunShellCommand (CmdLine, NULL));\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -2758,34 +2919,33 @@ IsValidCommandName(
   @retval EFI_SUCCESS           the script completed successfully\r
 **/\r
 EFI_STATUS\r
   @retval EFI_SUCCESS           the script completed successfully\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 RunScriptFileHandle (\r
   IN SHELL_FILE_HANDLE  Handle,\r
   IN CONST CHAR16       *Name\r
   )\r
 {\r
 RunScriptFileHandle (\r
   IN SHELL_FILE_HANDLE  Handle,\r
   IN CONST CHAR16       *Name\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
-  SCRIPT_FILE         *NewScriptFile;\r
-  UINTN               LoopVar;\r
-  UINTN               PrintBuffSize;\r
-  CHAR16              *CommandLine;\r
-  CHAR16              *CommandLine2;\r
-  CHAR16              *CommandLine3;\r
-  SCRIPT_COMMAND_LIST *LastCommand;\r
-  BOOLEAN             Ascii;\r
-  BOOLEAN             PreScriptEchoState;\r
-  BOOLEAN             PreCommandEchoState;\r
-  CONST CHAR16        *CurDir;\r
-  UINTN               LineCount;\r
-  CHAR16              LeString[50];\r
-  LIST_ENTRY          OldBufferList;\r
-\r
-  ASSERT(!ShellCommandGetScriptExit());\r
-\r
-  PreScriptEchoState = ShellCommandGetEchoState();\r
-  PrintBuffSize = PcdGet16(PcdShellPrintBufferSize);\r
-\r
-  NewScriptFile = (SCRIPT_FILE*)AllocateZeroPool(sizeof(SCRIPT_FILE));\r
+  EFI_STATUS           Status;\r
+  SCRIPT_FILE          *NewScriptFile;\r
+  UINTN                LoopVar;\r
+  UINTN                PrintBuffSize;\r
+  CHAR16               *CommandLine;\r
+  CHAR16               *CommandLine2;\r
+  CHAR16               *CommandLine3;\r
+  SCRIPT_COMMAND_LIST  *LastCommand;\r
+  BOOLEAN              Ascii;\r
+  BOOLEAN              PreScriptEchoState;\r
+  BOOLEAN              PreCommandEchoState;\r
+  CONST CHAR16         *CurDir;\r
+  UINTN                LineCount;\r
+  CHAR16               LeString[50];\r
+  LIST_ENTRY           OldBufferList;\r
+\r
+  ASSERT (!ShellCommandGetScriptExit ());\r
+\r
+  PreScriptEchoState = ShellCommandGetEchoState ();\r
+  PrintBuffSize      = PcdGet16 (PcdShellPrintBufferSize);\r
+\r
+  NewScriptFile = (SCRIPT_FILE *)AllocateZeroPool (sizeof (SCRIPT_FILE));\r
   if (NewScriptFile == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
   if (NewScriptFile == NULL) {\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
@@ -2793,10 +2953,10 @@ RunScriptFileHandle (
   //\r
   // Set up the name\r
   //\r
   //\r
   // Set up the name\r
   //\r
-  ASSERT(NewScriptFile->ScriptName == NULL);\r
-  NewScriptFile->ScriptName = StrnCatGrow(&NewScriptFile->ScriptName, NULL, Name, 0);\r
+  ASSERT (NewScriptFile->ScriptName == NULL);\r
+  NewScriptFile->ScriptName = StrnCatGrow (&NewScriptFile->ScriptName, NULL, Name, 0);\r
   if (NewScriptFile->ScriptName == NULL) {\r
   if (NewScriptFile->ScriptName == NULL) {\r
-    DeleteScriptFileStruct(NewScriptFile);\r
+    DeleteScriptFileStruct (NewScriptFile);\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
@@ -2805,16 +2965,22 @@ RunScriptFileHandle (
   //\r
   NewScriptFile->Argc = ShellInfoObject.NewShellParametersProtocol->Argc;\r
   if (NewScriptFile->Argc != 0) {\r
   //\r
   NewScriptFile->Argc = ShellInfoObject.NewShellParametersProtocol->Argc;\r
   if (NewScriptFile->Argc != 0) {\r
-    NewScriptFile->Argv = (CHAR16**)AllocateZeroPool(NewScriptFile->Argc * sizeof(CHAR16*));\r
+    NewScriptFile->Argv = (CHAR16 **)AllocateZeroPool (NewScriptFile->Argc * sizeof (CHAR16 *));\r
     if (NewScriptFile->Argv == NULL) {\r
     if (NewScriptFile->Argv == NULL) {\r
-      DeleteScriptFileStruct(NewScriptFile);\r
+      DeleteScriptFileStruct (NewScriptFile);\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
-    for (LoopVar = 0 ; LoopVar < 10 && LoopVar < NewScriptFile->Argc; LoopVar++) {\r
-      ASSERT(NewScriptFile->Argv[LoopVar] == NULL);\r
-      NewScriptFile->Argv[LoopVar] = StrnCatGrow(&NewScriptFile->Argv[LoopVar], NULL, ShellInfoObject.NewShellParametersProtocol->Argv[LoopVar], 0);\r
+\r
+    //\r
+    // Put the full path of the script file into Argv[0] as required by section\r
+    // 3.6.2 of version 2.2 of the shell specification.\r
+    //\r
+    NewScriptFile->Argv[0] = StrnCatGrow (&NewScriptFile->Argv[0], NULL, NewScriptFile->ScriptName, 0);\r
+    for (LoopVar = 1; LoopVar < 10 && LoopVar < NewScriptFile->Argc; LoopVar++) {\r
+      ASSERT (NewScriptFile->Argv[LoopVar] == NULL);\r
+      NewScriptFile->Argv[LoopVar] = StrnCatGrow (&NewScriptFile->Argv[LoopVar], NULL, ShellInfoObject.NewShellParametersProtocol->Argv[LoopVar], 0);\r
       if (NewScriptFile->Argv[LoopVar] == NULL) {\r
       if (NewScriptFile->Argv[LoopVar] == NULL) {\r
-        DeleteScriptFileStruct(NewScriptFile);\r
+        DeleteScriptFileStruct (NewScriptFile);\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
     }\r
         return (EFI_OUT_OF_RESOURCES);\r
       }\r
     }\r
@@ -2822,24 +2988,25 @@ RunScriptFileHandle (
     NewScriptFile->Argv = NULL;\r
   }\r
 \r
     NewScriptFile->Argv = NULL;\r
   }\r
 \r
-  InitializeListHead(&NewScriptFile->CommandList);\r
-  InitializeListHead(&NewScriptFile->SubstList);\r
+  InitializeListHead (&NewScriptFile->CommandList);\r
+  InitializeListHead (&NewScriptFile->SubstList);\r
 \r
   //\r
   // Now build the list of all script commands.\r
   //\r
   LineCount = 0;\r
 \r
   //\r
   // Now build the list of all script commands.\r
   //\r
   LineCount = 0;\r
-  while(!ShellFileHandleEof(Handle)) {\r
-    CommandLine = ShellFileHandleReturnLine(Handle, &Ascii);\r
+  while (!ShellFileHandleEof (Handle)) {\r
+    CommandLine = ShellFileHandleReturnLine (Handle, &Ascii);\r
     LineCount++;\r
     LineCount++;\r
-    if (CommandLine == NULL || StrLen(CommandLine) == 0 || CommandLine[0] == '#') {\r
-      SHELL_FREE_NON_NULL(CommandLine);\r
+    if ((CommandLine == NULL) || (StrLen (CommandLine) == 0) || (CommandLine[0] == '#')) {\r
+      SHELL_FREE_NON_NULL (CommandLine);\r
       continue;\r
     }\r
       continue;\r
     }\r
-    NewScriptFile->CurrentCommand = AllocateZeroPool(sizeof(SCRIPT_COMMAND_LIST));\r
+\r
+    NewScriptFile->CurrentCommand = AllocateZeroPool (sizeof (SCRIPT_COMMAND_LIST));\r
     if (NewScriptFile->CurrentCommand == NULL) {\r
     if (NewScriptFile->CurrentCommand == NULL) {\r
-      SHELL_FREE_NON_NULL(CommandLine);\r
-      DeleteScriptFileStruct(NewScriptFile);\r
+      SHELL_FREE_NON_NULL (CommandLine);\r
+      DeleteScriptFileStruct (NewScriptFile);\r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
 \r
       return (EFI_OUT_OF_RESOURCES);\r
     }\r
 \r
@@ -2847,7 +3014,7 @@ RunScriptFileHandle (
     NewScriptFile->CurrentCommand->Data = NULL;\r
     NewScriptFile->CurrentCommand->Line = LineCount;\r
 \r
     NewScriptFile->CurrentCommand->Data = NULL;\r
     NewScriptFile->CurrentCommand->Line = LineCount;\r
 \r
-    InsertTailList(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r
+    InsertTailList (&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -2858,38 +3025,41 @@ RunScriptFileHandle (
   //\r
   // Now enumerate through the commands and run each one.\r
   //\r
   //\r
   // Now enumerate through the commands and run each one.\r
   //\r
-  CommandLine = AllocateZeroPool(PrintBuffSize);\r
+  CommandLine = AllocateZeroPool (PrintBuffSize);\r
   if (CommandLine == NULL) {\r
   if (CommandLine == NULL) {\r
-    DeleteScriptFileStruct(NewScriptFile);\r
+    DeleteScriptFileStruct (NewScriptFile);\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
-  CommandLine2 = AllocateZeroPool(PrintBuffSize);\r
+\r
+  CommandLine2 = AllocateZeroPool (PrintBuffSize);\r
   if (CommandLine2 == NULL) {\r
   if (CommandLine2 == NULL) {\r
-    FreePool(CommandLine);\r
-    DeleteScriptFileStruct(NewScriptFile);\r
+    FreePool (CommandLine);\r
+    DeleteScriptFileStruct (NewScriptFile);\r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
     return (EFI_OUT_OF_RESOURCES);\r
   }\r
 \r
-  for ( NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetFirstNode(&NewScriptFile->CommandList)\r
-      ; !IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)\r
-      ; // conditional increment in the body of the loop\r
-  ){\r
-    ASSERT(CommandLine2 != NULL);\r
-    StrnCpyS( CommandLine2, \r
-              PrintBuffSize/sizeof(CHAR16), \r
-              NewScriptFile->CurrentCommand->Cl,\r
-              PrintBuffSize/sizeof(CHAR16) - 1\r
-              );\r
+  for ( NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetFirstNode (&NewScriptFile->CommandList)\r
+        ; !IsNull (&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)\r
+        ; // conditional increment in the body of the loop\r
+        )\r
+  {\r
+    ASSERT (CommandLine2 != NULL);\r
+    StrnCpyS (\r
+      CommandLine2,\r
+      PrintBuffSize/sizeof (CHAR16),\r
+      NewScriptFile->CurrentCommand->Cl,\r
+      PrintBuffSize/sizeof (CHAR16) - 1\r
+      );\r
 \r
 \r
-    SaveBufferList(&OldBufferList);\r
+    SaveBufferList (&OldBufferList);\r
 \r
     //\r
     // NULL out comments\r
     //\r
 \r
     //\r
     // NULL out comments\r
     //\r
-    for (CommandLine3 = CommandLine2 ; CommandLine3 != NULL && *CommandLine3 != CHAR_NULL ; CommandLine3++) {\r
+    for (CommandLine3 = CommandLine2; CommandLine3 != NULL && *CommandLine3 != CHAR_NULL; CommandLine3++) {\r
       if (*CommandLine3 == L'^') {\r
         if ( *(CommandLine3+1) == L':') {\r
       if (*CommandLine3 == L'^') {\r
         if ( *(CommandLine3+1) == L':') {\r
-          CopyMem(CommandLine3, CommandLine3+1, StrSize(CommandLine3) - sizeof(CommandLine3[0]));\r
+          CopyMem (CommandLine3, CommandLine3+1, StrSize (CommandLine3) - sizeof (CommandLine3[0]));\r
         } else if (*(CommandLine3+1) == L'#') {\r
           CommandLine3++;\r
         }\r
         } else if (*(CommandLine3+1) == L'#') {\r
           CommandLine3++;\r
         }\r
@@ -2898,15 +3068,16 @@ RunScriptFileHandle (
       }\r
     }\r
 \r
       }\r
     }\r
 \r
-    if (CommandLine2 != NULL && StrLen(CommandLine2) >= 1) {\r
+    if ((CommandLine2 != NULL) && (StrLen (CommandLine2) >= 1)) {\r
       //\r
       // Due to variability in starting the find and replace action we need to have both buffers the same.\r
       //\r
       //\r
       // Due to variability in starting the find and replace action we need to have both buffers the same.\r
       //\r
-      StrnCpyS( CommandLine, \r
-                PrintBuffSize/sizeof(CHAR16), \r
-                CommandLine2,\r
-                PrintBuffSize/sizeof(CHAR16) - 1\r
-                );\r
+      StrnCpyS (\r
+        CommandLine,\r
+        PrintBuffSize/sizeof (CHAR16),\r
+        CommandLine2,\r
+        PrintBuffSize/sizeof (CHAR16) - 1\r
+        );\r
 \r
       //\r
       // Remove the %0 to %9 from the command line (if we have some arguments)\r
 \r
       //\r
       // Remove the %0 to %9 from the command line (if we have some arguments)\r
@@ -2914,154 +3085,167 @@ RunScriptFileHandle (
       if (NewScriptFile->Argv != NULL) {\r
         switch (NewScriptFile->Argc) {\r
           default:\r
       if (NewScriptFile->Argv != NULL) {\r
         switch (NewScriptFile->Argc) {\r
           default:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%9", NewScriptFile->Argv[9], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%9", NewScriptFile->Argv[9], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 9:\r
           case 9:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%8", NewScriptFile->Argv[8], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%8", NewScriptFile->Argv[8], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 8:\r
           case 8:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%7", NewScriptFile->Argv[7], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%7", NewScriptFile->Argv[7], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 7:\r
           case 7:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%6", NewScriptFile->Argv[6], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%6", NewScriptFile->Argv[6], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 6:\r
           case 6:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%5", NewScriptFile->Argv[5], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%5", NewScriptFile->Argv[5], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 5:\r
           case 5:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%4", NewScriptFile->Argv[4], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%4", NewScriptFile->Argv[4], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 4:\r
           case 4:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%3", NewScriptFile->Argv[3], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%3", NewScriptFile->Argv[3], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 3:\r
           case 3:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%2", NewScriptFile->Argv[2], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%2", NewScriptFile->Argv[2], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 2:\r
           case 2:\r
-            Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%1", NewScriptFile->Argv[1], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%1", NewScriptFile->Argv[1], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
           case 1:\r
           case 1:\r
-            Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%0", NewScriptFile->Argv[0], FALSE, FALSE);\r
-            ASSERT_EFI_ERROR(Status);\r
+            Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%0", NewScriptFile->Argv[0], FALSE, FALSE);\r
+            ASSERT_EFI_ERROR (Status);\r
             break;\r
           case 0:\r
             break;\r
         }\r
       }\r
             break;\r
           case 0:\r
             break;\r
         }\r
       }\r
-      Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%1", L"\"\"", FALSE, FALSE);\r
-      Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%2", L"\"\"", FALSE, FALSE);\r
-      Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%3", L"\"\"", FALSE, FALSE);\r
-      Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%4", L"\"\"", FALSE, FALSE);\r
-      Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%5", L"\"\"", FALSE, FALSE);\r
-      Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%6", L"\"\"", FALSE, FALSE);\r
-      Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%7", L"\"\"", FALSE, FALSE);\r
-      Status = ShellCopySearchAndReplace(CommandLine,  CommandLine2, PrintBuffSize, L"%8", L"\"\"", FALSE, FALSE);\r
-      Status = ShellCopySearchAndReplace(CommandLine2,  CommandLine, PrintBuffSize, L"%9", L"\"\"", FALSE, FALSE);\r
-\r
-      StrnCpyS( CommandLine2, \r
-                PrintBuffSize/sizeof(CHAR16), \r
-                CommandLine,\r
-                PrintBuffSize/sizeof(CHAR16) - 1\r
-                );\r
+\r
+      Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%1", L"\"\"", FALSE, FALSE);\r
+      Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%2", L"\"\"", FALSE, FALSE);\r
+      Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%3", L"\"\"", FALSE, FALSE);\r
+      Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%4", L"\"\"", FALSE, FALSE);\r
+      Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%5", L"\"\"", FALSE, FALSE);\r
+      Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%6", L"\"\"", FALSE, FALSE);\r
+      Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%7", L"\"\"", FALSE, FALSE);\r
+      Status = ShellCopySearchAndReplace (CommandLine, CommandLine2, PrintBuffSize, L"%8", L"\"\"", FALSE, FALSE);\r
+      Status = ShellCopySearchAndReplace (CommandLine2, CommandLine, PrintBuffSize, L"%9", L"\"\"", FALSE, FALSE);\r
+\r
+      StrnCpyS (\r
+        CommandLine2,\r
+        PrintBuffSize/sizeof (CHAR16),\r
+        CommandLine,\r
+        PrintBuffSize/sizeof (CHAR16) - 1\r
+        );\r
 \r
       LastCommand = NewScriptFile->CurrentCommand;\r
 \r
 \r
       LastCommand = NewScriptFile->CurrentCommand;\r
 \r
-      for (CommandLine3 = CommandLine2 ; CommandLine3[0] == L' ' ; CommandLine3++);\r
+      for (CommandLine3 = CommandLine2; CommandLine3[0] == L' '; CommandLine3++) {\r
+      }\r
 \r
 \r
-      if (CommandLine3 != NULL && CommandLine3[0] == L':' ) {\r
+      if ((CommandLine3 != NULL) && (CommandLine3[0] == L':')) {\r
         //\r
         // This line is a goto target / label\r
         //\r
       } else {\r
         //\r
         // This line is a goto target / label\r
         //\r
       } else {\r
-        if (CommandLine3 != NULL && StrLen(CommandLine3) > 0) {\r
+        if ((CommandLine3 != NULL) && (StrLen (CommandLine3) > 0)) {\r
           if (CommandLine3[0] == L'@') {\r
             //\r
             // We need to save the current echo state\r
             // and disable echo for just this command.\r
             //\r
           if (CommandLine3[0] == L'@') {\r
             //\r
             // We need to save the current echo state\r
             // and disable echo for just this command.\r
             //\r
-            PreCommandEchoState = ShellCommandGetEchoState();\r
-            ShellCommandSetEchoState(FALSE);\r
-            Status = RunCommand(CommandLine3+1);\r
+            PreCommandEchoState = ShellCommandGetEchoState ();\r
+            ShellCommandSetEchoState (FALSE);\r
+            Status = RunCommand (CommandLine3+1);\r
 \r
             //\r
             // If command was "@echo -off" or "@echo -on" then don't restore echo state\r
             //\r
 \r
             //\r
             // If command was "@echo -off" or "@echo -on" then don't restore echo state\r
             //\r
-            if (StrCmp (L"@echo -off", CommandLine3) != 0 &&\r
-                StrCmp (L"@echo -on", CommandLine3) != 0) {\r
+            if ((StrCmp (L"@echo -off", CommandLine3) != 0) &&\r
+                (StrCmp (L"@echo -on", CommandLine3) != 0))\r
+            {\r
               //\r
               // Now restore the pre-'@' echo state.\r
               //\r
               //\r
               // Now restore the pre-'@' echo state.\r
               //\r
-              ShellCommandSetEchoState(PreCommandEchoState);\r
+              ShellCommandSetEchoState (PreCommandEchoState);\r
             }\r
           } else {\r
             }\r
           } else {\r
-            if (ShellCommandGetEchoState()) {\r
-              CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv(L"cwd");\r
-              if (CurDir != NULL && StrLen(CurDir) > 1) {\r
-                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);\r
+            if (ShellCommandGetEchoState ()) {\r
+              CurDir = ShellInfoObject.NewEfiShellProtocol->GetEnv (L"cwd");\r
+              if ((CurDir != NULL) && (StrLen (CurDir) > 1)) {\r
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_CURDIR), ShellInfoObject.HiiHandle, CurDir);\r
               } else {\r
               } else {\r
-                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);\r
+                ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_SHELL), ShellInfoObject.HiiHandle);\r
               }\r
               }\r
-              ShellPrintEx(-1, -1, L"%s\r\n", CommandLine2);\r
+\r
+              ShellPrintEx (-1, -1, L"%s\r\n", CommandLine2);\r
             }\r
             }\r
-            Status = RunCommand(CommandLine3);\r
+\r
+            Status = RunCommand (CommandLine3);\r
           }\r
         }\r
 \r
           }\r
         }\r
 \r
-        if (ShellCommandGetScriptExit()) {\r
+        if (ShellCommandGetScriptExit ()) {\r
           //\r
           // ShellCommandGetExitCode() always returns a UINT64\r
           //\r
           //\r
           // ShellCommandGetExitCode() always returns a UINT64\r
           //\r
-          UnicodeSPrint(LeString, sizeof(LeString), L"0x%Lx", ShellCommandGetExitCode());\r
-          DEBUG_CODE(InternalEfiShellSetEnv(L"debuglasterror", LeString, TRUE););\r
-          InternalEfiShellSetEnv(L"lasterror", LeString, TRUE);\r
+          UnicodeSPrint (LeString, sizeof (LeString), L"0x%Lx", ShellCommandGetExitCode ());\r
+          DEBUG_CODE (\r
+            InternalEfiShellSetEnv (L"debuglasterror", LeString, TRUE);\r
+            );\r
+          InternalEfiShellSetEnv (L"lasterror", LeString, TRUE);\r
 \r
 \r
-          ShellCommandRegisterExit(FALSE, 0);\r
+          ShellCommandRegisterExit (FALSE, 0);\r
           Status = EFI_SUCCESS;\r
           Status = EFI_SUCCESS;\r
-          RestoreBufferList(&OldBufferList);\r
+          RestoreBufferList (&OldBufferList);\r
           break;\r
         }\r
           break;\r
         }\r
-        if (ShellGetExecutionBreakFlag()) {\r
-          RestoreBufferList(&OldBufferList);\r
+\r
+        if (ShellGetExecutionBreakFlag ()) {\r
+          RestoreBufferList (&OldBufferList);\r
           break;\r
         }\r
           break;\r
         }\r
-        if (EFI_ERROR(Status)) {\r
-          RestoreBufferList(&OldBufferList);\r
+\r
+        if (EFI_ERROR (Status)) {\r
+          RestoreBufferList (&OldBufferList);\r
           break;\r
         }\r
           break;\r
         }\r
-        if (ShellCommandGetExit()) {\r
-          RestoreBufferList(&OldBufferList);\r
+\r
+        if (ShellCommandGetExit ()) {\r
+          RestoreBufferList (&OldBufferList);\r
           break;\r
         }\r
       }\r
           break;\r
         }\r
       }\r
+\r
       //\r
       // If that commend did not update the CurrentCommand then we need to advance it...\r
       //\r
       if (LastCommand == NewScriptFile->CurrentCommand) {\r
       //\r
       // If that commend did not update the CurrentCommand then we need to advance it...\r
       //\r
       if (LastCommand == NewScriptFile->CurrentCommand) {\r
-        NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r
-        if (!IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)) {\r
+        NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode (&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r
+        if (!IsNull (&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)) {\r
           NewScriptFile->CurrentCommand->Reset = TRUE;\r
         }\r
       }\r
     } else {\r
           NewScriptFile->CurrentCommand->Reset = TRUE;\r
         }\r
       }\r
     } else {\r
-      NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r
-      if (!IsNull(&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)) {\r
+      NewScriptFile->CurrentCommand = (SCRIPT_COMMAND_LIST *)GetNextNode (&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link);\r
+      if (!IsNull (&NewScriptFile->CommandList, &NewScriptFile->CurrentCommand->Link)) {\r
         NewScriptFile->CurrentCommand->Reset = TRUE;\r
       }\r
     }\r
         NewScriptFile->CurrentCommand->Reset = TRUE;\r
       }\r
     }\r
-    RestoreBufferList(&OldBufferList);\r
-  }\r
 \r
 \r
+    RestoreBufferList (&OldBufferList);\r
+  }\r
 \r
 \r
-  FreePool(CommandLine);\r
-  FreePool(CommandLine2);\r
+  FreePool (CommandLine);\r
+  FreePool (CommandLine2);\r
   ShellCommandSetNewScript (NULL);\r
 \r
   //\r
   // Only if this was the last script reset the state.\r
   //\r
   ShellCommandSetNewScript (NULL);\r
 \r
   //\r
   // Only if this was the last script reset the state.\r
   //\r
-  if (ShellCommandGetCurrentScriptFile()==NULL) {\r
-    ShellCommandSetEchoState(PreScriptEchoState);\r
+  if (ShellCommandGetCurrentScriptFile () == NULL) {\r
+    ShellCommandSetEchoState (PreScriptEchoState);\r
   }\r
   }\r
+\r
   return (EFI_SUCCESS);\r
 }\r
 \r
   return (EFI_SUCCESS);\r
 }\r
 \r
@@ -3076,7 +3260,6 @@ RunScriptFileHandle (
   @retval EFI_SUCCESS           the script completed successfully\r
 **/\r
 EFI_STATUS\r
   @retval EFI_SUCCESS           the script completed successfully\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 RunScriptFile (\r
   IN CONST CHAR16                   *ScriptPath,\r
   IN SHELL_FILE_HANDLE              Handle OPTIONAL,\r
 RunScriptFile (\r
   IN CONST CHAR16                   *ScriptPath,\r
   IN SHELL_FILE_HANDLE              Handle OPTIONAL,\r
@@ -3084,39 +3267,38 @@ RunScriptFile (
   IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol\r
   )\r
 {\r
   IN EFI_SHELL_PARAMETERS_PROTOCOL  *ParamProtocol\r
   )\r
 {\r
-  EFI_STATUS          Status;\r
-  SHELL_FILE_HANDLE   FileHandle;\r
-  UINTN                     Argc;\r
-  CHAR16                    **Argv;\r
+  EFI_STATUS         Status;\r
+  SHELL_FILE_HANDLE  FileHandle;\r
+  UINTN              Argc;\r
+  CHAR16             **Argv;\r
 \r
 \r
-  if (ShellIsFile(ScriptPath) != EFI_SUCCESS) {\r
+  if (ShellIsFile (ScriptPath) != EFI_SUCCESS) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
   //\r
   // get the argc and argv updated for scripts\r
   //\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r
   //\r
   // get the argc and argv updated for scripts\r
   //\r
-  Status = UpdateArgcArgv(ParamProtocol, CmdLine, Script_File_Name, &Argv, &Argc);\r
-  if (!EFI_ERROR(Status)) {\r
-\r
+  Status = UpdateArgcArgv (ParamProtocol, CmdLine, Script_File_Name, &Argv, &Argc);\r
+  if (!EFI_ERROR (Status)) {\r
     if (Handle == NULL) {\r
       //\r
       // open the file\r
       //\r
     if (Handle == NULL) {\r
       //\r
       // open the file\r
       //\r
-      Status = ShellOpenFileByName(ScriptPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r
-      if (!EFI_ERROR(Status)) {\r
+      Status = ShellOpenFileByName (ScriptPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r
+      if (!EFI_ERROR (Status)) {\r
         //\r
         // run it\r
         //\r
         //\r
         // run it\r
         //\r
-        Status = RunScriptFileHandle(FileHandle, ScriptPath);\r
+        Status = RunScriptFileHandle (FileHandle, ScriptPath);\r
 \r
         //\r
         // now close the file\r
         //\r
 \r
         //\r
         // now close the file\r
         //\r
-        ShellCloseFile(&FileHandle);\r
+        ShellCloseFile (&FileHandle);\r
       }\r
     } else {\r
       }\r
     } else {\r
-      Status = RunScriptFileHandle(Handle, ScriptPath);\r
+      Status = RunScriptFileHandle (Handle, ScriptPath);\r
     }\r
   }\r
 \r
     }\r
   }\r
 \r
@@ -3124,8 +3306,43 @@ RunScriptFile (
   // This is guaranteed to be called after UpdateArgcArgv no matter what else happened.\r
   // This is safe even if the update API failed.  In this case, it may be a no-op.\r
   //\r
   // This is guaranteed to be called after UpdateArgcArgv no matter what else happened.\r
   // This is safe even if the update API failed.  In this case, it may be a no-op.\r
   //\r
-  RestoreArgcArgv(ParamProtocol, &Argv, &Argc);\r
+  RestoreArgcArgv (ParamProtocol, &Argv, &Argc);\r
 \r
   return (Status);\r
 }\r
 \r
 \r
   return (Status);\r
 }\r
 \r
+/**\r
+  Return the pointer to the first occurrence of any character from a list of characters.\r
+\r
+  @param[in] String           the string to parse\r
+  @param[in] CharacterList    the list of character to look for\r
+  @param[in] EscapeCharacter  An escape character to skip\r
+\r
+  @return the location of the first character in the string\r
+  @retval CHAR_NULL no instance of any character in CharacterList was found in String\r
+**/\r
+CONST CHAR16 *\r
+FindFirstCharacter (\r
+  IN CONST CHAR16  *String,\r
+  IN CONST CHAR16  *CharacterList,\r
+  IN CONST CHAR16  EscapeCharacter\r
+  )\r
+{\r
+  UINT32  WalkChar;\r
+  UINT32  WalkStr;\r
+\r
+  for (WalkStr = 0; WalkStr < StrLen (String); WalkStr++) {\r
+    if (String[WalkStr] == EscapeCharacter) {\r
+      WalkStr++;\r
+      continue;\r
+    }\r
+\r
+    for (WalkChar = 0; WalkChar < StrLen (CharacterList); WalkChar++) {\r
+      if (String[WalkStr] == CharacterList[WalkChar]) {\r
+        return (&String[WalkStr]);\r
+      }\r
+    }\r
+  }\r
+\r
+  return (String + StrLen (String));\r
+}\r