VirtualBox

Ignore:
Timestamp:
Apr 14, 2023 3:17:44 PM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156854
Message:

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Application/Shell/ShellParametersProtocol.c

    r85718 r99404  
    1313#include "Shell.h"
    1414
    15 BOOLEAN AsciiRedirection = FALSE;
     15BOOLEAN  AsciiRedirection = FALSE;
    1616
    1717/**
     
    2020  @param[in] String        the string to parse
    2121**/
    22 CONST CHAR16*
    23 FindEndOfParameter(
    24   IN CONST CHAR16 *String
     22CONST CHAR16 *
     23FindEndOfParameter (
     24  IN CONST CHAR16  *String
    2525  )
    2626{
    27   CONST CHAR16 *First;
    28   CONST CHAR16 *CloseQuote;
    29 
    30   First = FindFirstCharacter(String, L" \"", L'^');
     27  CONST CHAR16  *First;
     28  CONST CHAR16  *CloseQuote;
     29
     30  First = FindFirstCharacter (String, L" \"", L'^');
    3131
    3232  //
     
    8080**/
    8181EFI_STATUS
    82 GetNextParameter(
     82GetNextParameter (
    8383  IN OUT CHAR16   **Walker,
    8484  IN OUT CHAR16   **TempParameter,
     
    8787  )
    8888{
    89   CONST CHAR16 *NextDelim;
    90 
    91   if (Walker           == NULL
    92     ||*Walker          == NULL
    93     ||TempParameter    == NULL
    94     ||*TempParameter   == NULL
    95     ){
     89  CONST CHAR16  *NextDelim;
     90
     91  if (  (Walker           == NULL)
     92     || (*Walker          == NULL)
     93     || (TempParameter    == NULL)
     94     || (*TempParameter   == NULL)
     95        )
     96  {
    9697    return (EFI_INVALID_PARAMETER);
    9798  }
    9899
    99 
    100100  //
    101101  // make sure we dont have any leading spaces
    102102  //
    103103  while ((*Walker)[0] == L' ') {
    104       (*Walker)++;
     104    (*Walker)++;
    105105  }
    106106
     
    108108  // make sure we still have some params now...
    109109  //
    110   if (StrLen(*Walker) == 0) {
    111 DEBUG_CODE_BEGIN();
    112     *Walker        = NULL;
    113 DEBUG_CODE_END();
     110  if (StrLen (*Walker) == 0) {
     111    DEBUG_CODE_BEGIN ();
     112    *Walker = NULL;
     113    DEBUG_CODE_END ();
    114114    return (EFI_INVALID_PARAMETER);
    115115  }
    116116
    117   NextDelim = FindEndOfParameter(*Walker);
    118 
    119   if (NextDelim == NULL){
    120 DEBUG_CODE_BEGIN();
    121     *Walker        = NULL;
    122 DEBUG_CODE_END();
     117  NextDelim = FindEndOfParameter (*Walker);
     118
     119  if (NextDelim == NULL) {
     120    DEBUG_CODE_BEGIN ();
     121    *Walker = NULL;
     122    DEBUG_CODE_END ();
    123123    return (EFI_NOT_FOUND);
    124124  }
    125125
    126   StrnCpyS(*TempParameter, Length / sizeof(CHAR16), (*Walker), NextDelim - *Walker);
     126  StrnCpyS (*TempParameter, Length / sizeof (CHAR16), (*Walker), NextDelim - *Walker);
    127127
    128128  //
     
    136136  // Update Walker for the next iteration through the function
    137137  //
    138   *Walker = (CHAR16*)NextDelim;
     138  *Walker = (CHAR16 *)NextDelim;
    139139
    140140  //
     
    142142  // Remove any remaining escape characters in the string
    143143  //
    144   for (NextDelim = FindFirstCharacter(*TempParameter, L"\"^", CHAR_NULL)
    145     ; *NextDelim != CHAR_NULL
    146     ; NextDelim = FindFirstCharacter(NextDelim, L"\"^", CHAR_NULL)
    147     ) {
     144  for (NextDelim = FindFirstCharacter (*TempParameter, L"\"^", CHAR_NULL)
     145       ; *NextDelim != CHAR_NULL
     146       ; NextDelim = FindFirstCharacter (NextDelim, L"\"^", CHAR_NULL)
     147       )
     148  {
    148149    if (*NextDelim == L'^') {
    149 
    150150      //
    151151      // eliminate the escape ^
    152152      //
    153       CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
     153      CopyMem ((CHAR16 *)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
    154154      NextDelim++;
    155155    } else if (*NextDelim == L'\"') {
    156 
    157156      //
    158157      // eliminate the unescaped quote
    159158      //
    160159      if (StripQuotation) {
    161         CopyMem ((CHAR16*)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
    162     } else{
     160        CopyMem ((CHAR16 *)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));
     161      } else {
    163162        NextDelim++;
    164     }
     163      }
    165164    }
    166165  }
     
    190189**/
    191190EFI_STATUS
    192 ParseCommandLineToArgs(
    193   IN CONST CHAR16 *CommandLine,
    194   IN BOOLEAN      StripQuotation,
    195   IN OUT CHAR16   ***Argv,
    196   IN OUT UINTN    *Argc
     191ParseCommandLineToArgs (
     192  IN CONST CHAR16  *CommandLine,
     193  IN BOOLEAN       StripQuotation,
     194  IN OUT CHAR16    ***Argv,
     195  IN OUT UINTN     *Argc
    197196  )
    198197{
     
    205204  EFI_STATUS  Status;
    206205
    207   ASSERT(Argc != NULL);
    208   ASSERT(Argv != NULL);
    209 
    210   if (CommandLine == NULL || StrLen(CommandLine)==0) {
     206  ASSERT (Argc != NULL);
     207  ASSERT (Argv != NULL);
     208
     209  if ((CommandLine == NULL) || (StrLen (CommandLine) == 0)) {
    211210    (*Argc) = 0;
    212211    (*Argv) = NULL;
     
    214213  }
    215214
    216   NewCommandLine = AllocateCopyPool(StrSize(CommandLine), CommandLine);
    217   if (NewCommandLine == NULL){
     215  NewCommandLine = AllocateCopyPool (StrSize (CommandLine), CommandLine);
     216  if (NewCommandLine == NULL) {
    218217    return (EFI_OUT_OF_RESOURCES);
    219218  }
    220219
    221   TrimSpaces(&NewCommandLine);
    222   Size = StrSize(NewCommandLine);
    223   TempParameter = AllocateZeroPool(Size);
     220  TrimSpaces (&NewCommandLine);
     221  Size          = StrSize (NewCommandLine);
     222  TempParameter = AllocateZeroPool (Size);
    224223  if (TempParameter == NULL) {
    225     SHELL_FREE_NON_NULL(NewCommandLine);
     224    SHELL_FREE_NON_NULL (NewCommandLine);
    226225    return (EFI_OUT_OF_RESOURCES);
    227226  }
    228227
    229   for ( Count = 0
    230       , Walker = (CHAR16*)NewCommandLine
    231       ; Walker != NULL && *Walker != CHAR_NULL
    232       ; Count++
    233       ) {
    234     if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, TRUE))) {
     228  for ( Count = 0,
     229        Walker = (CHAR16 *)NewCommandLine
     230        ; Walker != NULL && *Walker != CHAR_NULL
     231        ; Count++
     232        )
     233  {
     234    if (EFI_ERROR (GetNextParameter (&Walker, &TempParameter, Size, TRUE))) {
    235235      break;
    236236    }
     
    240240  // lets allocate the pointer array
    241241  //
    242   (*Argv) = AllocateZeroPool((Count)*sizeof(CHAR16*));
     242  (*Argv) = AllocateZeroPool ((Count)*sizeof (CHAR16 *));
    243243  if (*Argv == NULL) {
    244244    Status = EFI_OUT_OF_RESOURCES;
     
    246246  }
    247247
    248   *Argc = 0;
    249   Walker = (CHAR16*)NewCommandLine;
    250   while(Walker != NULL && *Walker != CHAR_NULL) {
    251     SetMem16(TempParameter, Size, CHAR_NULL);
    252     if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, StripQuotation))) {
     248  *Argc  = 0;
     249  Walker = (CHAR16 *)NewCommandLine;
     250  while (Walker != NULL && *Walker != CHAR_NULL) {
     251    SetMem16 (TempParameter, Size, CHAR_NULL);
     252    if (EFI_ERROR (GetNextParameter (&Walker, &TempParameter, Size, StripQuotation))) {
    253253      Status = EFI_INVALID_PARAMETER;
    254254      goto Done;
    255255    }
    256256
    257     NewParam = AllocateCopyPool(StrSize(TempParameter), TempParameter);
    258     if (NewParam == NULL){
     257    NewParam = AllocateCopyPool (StrSize (TempParameter), TempParameter);
     258    if (NewParam == NULL) {
    259259      Status = EFI_OUT_OF_RESOURCES;
    260260      goto Done;
    261261    }
    262     ((CHAR16**)(*Argv))[(*Argc)] = NewParam;
     262
     263    ((CHAR16 **)(*Argv))[(*Argc)] = NewParam;
    263264    (*Argc)++;
    264265  }
    265   ASSERT(Count >= (*Argc));
     266
     267  ASSERT (Count >= (*Argc));
    266268  Status = EFI_SUCCESS;
    267269
    268270Done:
    269   SHELL_FREE_NON_NULL(TempParameter);
    270   SHELL_FREE_NON_NULL(NewCommandLine);
     271  SHELL_FREE_NON_NULL (TempParameter);
     272  SHELL_FREE_NON_NULL (NewCommandLine);
    271273  return (Status);
    272274}
     
    294296  )
    295297{
    296   EFI_STATUS Status;
    297   EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
    298   CHAR16                    *FullCommandLine;
    299   UINTN                     Size;
    300 
    301   Size = 0;
     298  EFI_STATUS                 Status;
     299  EFI_LOADED_IMAGE_PROTOCOL  *LoadedImage;
     300  CHAR16                     *FullCommandLine;
     301  UINTN                      Size;
     302
     303  Size            = 0;
    302304  FullCommandLine = NULL;
    303   LoadedImage = NULL;
     305  LoadedImage     = NULL;
    304306
    305307  //
    306308  // Assert for valid parameters
    307309  //
    308   ASSERT(NewShellParameters != NULL);
    309   ASSERT(RootShellInstance  != NULL);
     310  ASSERT (NewShellParameters != NULL);
     311  ASSERT (RootShellInstance  != NULL);
    310312
    311313  //
     
    313315  //
    314316  Status = gBS->OpenProtocol (
    315                 gImageHandle,
    316                 &gEfiShellParametersProtocolGuid,
    317                 (VOID **) &ShellInfoObject.OldShellParameters,
    318                 gImageHandle,
    319                 NULL,
    320                 EFI_OPEN_PROTOCOL_GET_PROTOCOL
    321                );
     317                  gImageHandle,
     318                  &gEfiShellParametersProtocolGuid,
     319                  (VOID **)&ShellInfoObject.OldShellParameters,
     320                  gImageHandle,
     321                  NULL,
     322                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
     323                  );
    322324  //
    323325  // if we don't then we must be the root shell (error is expected)
     
    330332  // Allocate the new structure
    331333  //
    332   *NewShellParameters = AllocateZeroPool(sizeof(EFI_SHELL_PARAMETERS_PROTOCOL));
     334  *NewShellParameters = AllocateZeroPool (sizeof (EFI_SHELL_PARAMETERS_PROTOCOL));
    333335  if ((*NewShellParameters) == NULL) {
    334336    return (EFI_OUT_OF_RESOURCES);
     
    339341  //
    340342  Status = gBS->OpenProtocol (
    341                 gImageHandle,
    342                 &gEfiLoadedImageProtocolGuid,
    343                 (VOID **) &LoadedImage,
    344                 gImageHandle,
    345                 NULL,
    346                 EFI_OPEN_PROTOCOL_GET_PROTOCOL
    347                );
    348   ASSERT_EFI_ERROR(Status);
     343                  gImageHandle,
     344                  &gEfiLoadedImageProtocolGuid,
     345                  (VOID **)&LoadedImage,
     346                  gImageHandle,
     347                  NULL,
     348                  EFI_OPEN_PROTOCOL_GET_PROTOCOL
     349                  );
     350  ASSERT_EFI_ERROR (Status);
    349351  //
    350352  // Build the full command line
    351353  //
    352   Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine);
     354  Status = SHELL_GET_ENVIRONMENT_VARIABLE (L"ShellOpt", &Size, FullCommandLine);
    353355  if (Status == EFI_BUFFER_TOO_SMALL) {
    354     FullCommandLine = AllocateZeroPool(Size + LoadedImage->LoadOptionsSize);
    355     Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine);
    356   }
     356    FullCommandLine = AllocateZeroPool (Size + LoadedImage->LoadOptionsSize);
     357    Status          = SHELL_GET_ENVIRONMENT_VARIABLE (L"ShellOpt", &Size, FullCommandLine);
     358  }
     359
    357360  if (Status == EFI_NOT_FOUND) {
    358361    //
     
    360363    //
    361364  } else {
    362     if (EFI_ERROR(Status)) {
     365    if (EFI_ERROR (Status)) {
    363366      return (Status);
    364367    }
    365368  }
    366   if (Size == 0 && LoadedImage->LoadOptionsSize != 0) {
    367     ASSERT(FullCommandLine == NULL);
     369
     370  if ((Size == 0) && (LoadedImage->LoadOptionsSize != 0)) {
     371    ASSERT (FullCommandLine == NULL);
    368372    //
    369373    // Now we need to include a NULL terminator in the size.
    370374    //
    371     Size = LoadedImage->LoadOptionsSize + sizeof(FullCommandLine[0]);
    372     FullCommandLine = AllocateZeroPool(Size);
    373   }
     375    Size            = LoadedImage->LoadOptionsSize + sizeof (FullCommandLine[0]);
     376    FullCommandLine = AllocateZeroPool (Size);
     377  }
     378
    374379  if (FullCommandLine != NULL) {
    375380    CopyMem (FullCommandLine, LoadedImage->LoadOptions, LoadedImage->LoadOptionsSize);
     
    377382    // Populate Argc and Argv
    378383    //
    379     Status = ParseCommandLineToArgs(FullCommandLine,
    380                                     TRUE,
    381                                     &(*NewShellParameters)->Argv,
    382                                     &(*NewShellParameters)->Argc);
    383 
    384     FreePool(FullCommandLine);
    385 
    386     ASSERT_EFI_ERROR(Status);
     384    Status = ParseCommandLineToArgs (
     385               FullCommandLine,
     386               TRUE,
     387               &(*NewShellParameters)->Argv,
     388               &(*NewShellParameters)->Argc
     389               );
     390
     391    FreePool (FullCommandLine);
     392
     393    ASSERT_EFI_ERROR (Status);
    387394  } else {
    388395    (*NewShellParameters)->Argv = NULL;
     
    397404    (*NewShellParameters)->StdOut = &FileInterfaceStdOut;
    398405    (*NewShellParameters)->StdErr = &FileInterfaceStdErr;
    399     Status = gBS->InstallProtocolInterface(&gImageHandle,
     406    Status                        = gBS->InstallProtocolInterface (
     407                                           &gImageHandle,
    400408                                           &gEfiShellParametersProtocolGuid,
    401409                                           EFI_NATIVE_INTERFACE,
    402                                            (VOID*)(*NewShellParameters));
     410                                           (VOID *)(*NewShellParameters)
     411                                           );
    403412  } else {
    404413    //
     
    408417    (*NewShellParameters)->StdOut = ShellInfoObject.OldShellParameters->StdOut;
    409418    (*NewShellParameters)->StdErr = ShellInfoObject.OldShellParameters->StdErr;
    410     Status = gBS->ReinstallProtocolInterface(gImageHandle,
    411                                              &gEfiShellParametersProtocolGuid,
    412                                              (VOID*)ShellInfoObject.OldShellParameters,
    413                                              (VOID*)(*NewShellParameters));
     419    Status                        = gBS->ReinstallProtocolInterface (
     420                                           gImageHandle,
     421                                           &gEfiShellParametersProtocolGuid,
     422                                           (VOID *)ShellInfoObject.OldShellParameters,
     423                                           (VOID *)(*NewShellParameters)
     424                                           );
    414425  }
    415426
     
    434445  )
    435446{
    436   EFI_STATUS Status;
    437   UINTN LoopCounter;
     447  EFI_STATUS  Status;
     448  UINTN       LoopCounter;
    438449
    439450  //
     
    441452  //
    442453  if (ShellInfoObject.OldShellParameters != NULL) {
    443     Status = gBS->ReinstallProtocolInterface(gImageHandle,
    444                                              &gEfiShellParametersProtocolGuid,
    445                                              (VOID*)NewShellParameters,
    446                                              (VOID*)ShellInfoObject.OldShellParameters);
    447     DEBUG_CODE(ShellInfoObject.OldShellParameters = NULL;);
     454    Status = gBS->ReinstallProtocolInterface (
     455                    gImageHandle,
     456                    &gEfiShellParametersProtocolGuid,
     457                    (VOID *)NewShellParameters,
     458                    (VOID *)ShellInfoObject.OldShellParameters
     459                    );
     460    DEBUG_CODE (
     461      ShellInfoObject.OldShellParameters = NULL;
     462      );
    448463  } else {
    449464    //
    450465    // No old one, just uninstall us...
    451466    //
    452     Status = gBS->UninstallProtocolInterface(gImageHandle,
    453                                              &gEfiShellParametersProtocolGuid,
    454                                              (VOID*)NewShellParameters);
    455   }
     467    Status = gBS->UninstallProtocolInterface (
     468                    gImageHandle,
     469                    &gEfiShellParametersProtocolGuid,
     470                    (VOID *)NewShellParameters
     471                    );
     472  }
     473
    456474  if (NewShellParameters->Argv != NULL) {
    457475    for ( LoopCounter = 0
    458         ; LoopCounter < NewShellParameters->Argc
    459         ; LoopCounter++
    460        ){
    461       FreePool(NewShellParameters->Argv[LoopCounter]);
    462     }
    463     FreePool(NewShellParameters->Argv);
    464   }
    465   FreePool(NewShellParameters);
     476          ; LoopCounter < NewShellParameters->Argc
     477          ; LoopCounter++
     478          )
     479    {
     480      FreePool (NewShellParameters->Argv[LoopCounter]);
     481    }
     482
     483    FreePool (NewShellParameters->Argv);
     484  }
     485
     486  FreePool (NewShellParameters);
    466487  return (Status);
    467488}
     
    476497**/
    477498EFI_STATUS
    478 IsUnicodeFile(
    479   IN CONST CHAR16 *FileName
     499IsUnicodeFile (
     500  IN CONST CHAR16  *FileName
    480501  )
    481502{
    482   SHELL_FILE_HANDLE Handle;
    483   EFI_STATUS        Status;
    484   UINT64            OriginalFilePosition;
    485   UINTN             CharSize;
    486   CHAR16            CharBuffer;
    487 
    488   Status = gEfiShellProtocol->OpenFileByName(FileName, &Handle, EFI_FILE_MODE_READ);
    489   if (EFI_ERROR(Status)) {
     503  SHELL_FILE_HANDLE  Handle;
     504  EFI_STATUS         Status;
     505  UINT64             OriginalFilePosition;
     506  UINTN              CharSize;
     507  CHAR16             CharBuffer;
     508
     509  Status = gEfiShellProtocol->OpenFileByName (FileName, &Handle, EFI_FILE_MODE_READ);
     510  if (EFI_ERROR (Status)) {
    490511    return (Status);
    491512  }
    492   gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition);
    493   gEfiShellProtocol->SetFilePosition(Handle, 0);
    494   CharSize = sizeof(CHAR16);
    495   Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);
    496   if (EFI_ERROR(Status) || CharBuffer != gUnicodeFileTag) {
     513
     514  gEfiShellProtocol->GetFilePosition (Handle, &OriginalFilePosition);
     515  gEfiShellProtocol->SetFilePosition (Handle, 0);
     516  CharSize = sizeof (CHAR16);
     517  Status   = gEfiShellProtocol->ReadFile (Handle, &CharSize, &CharBuffer);
     518  if (EFI_ERROR (Status) || (CharBuffer != gUnicodeFileTag)) {
    497519    Status = EFI_BUFFER_TOO_SMALL;
    498520  }
    499   gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);
    500   gEfiShellProtocol->CloseFile(Handle);
     521
     522  gEfiShellProtocol->SetFilePosition (Handle, OriginalFilePosition);
     523  gEfiShellProtocol->CloseFile (Handle);
    501524  return (Status);
    502525}
     
    511534VOID
    512535StripQuotes (
    513   IN OUT CHAR16 *TheString
     536  IN OUT CHAR16  *TheString
    514537  )
    515538{
    516   BOOLEAN RemoveNow;
    517 
    518   for (RemoveNow = FALSE ; TheString != NULL && *TheString != CHAR_NULL ; TheString++) {
    519     if (*TheString == L'^' && *(TheString + 1) == L'\"') {
     539  BOOLEAN  RemoveNow;
     540
     541  for (RemoveNow = FALSE; TheString != NULL && *TheString != CHAR_NULL; TheString++) {
     542    if ((*TheString == L'^') && (*(TheString + 1) == L'\"')) {
    520543      TheString++;
    521544    } else if (*TheString == L'\"') {
    522       RemoveNow = (BOOLEAN)!RemoveNow;
     545      RemoveNow = (BOOLEAN) !RemoveNow;
    523546    } else if (RemoveNow) {
    524547      *TheString = L' ';
     
    536559VOID
    537560CalculateEfiHdrCrc (
    538   IN  OUT EFI_TABLE_HEADER    *Hdr
     561  IN  OUT EFI_TABLE_HEADER  *Hdr
    539562  )
    540563{
    541   UINT32 Crc;
     564  UINT32  Crc;
    542565
    543566  Hdr->CRC32 = 0;
     
    560583  @return       The modified FileName.
    561584**/
    562 CHAR16*
     585CHAR16 *
    563586FixFileName (
    564   IN CHAR16 *FileName
     587  IN CHAR16  *FileName
    565588  )
    566589{
     
    574597  if (FileName[0] == L'\"') {
    575598    Copy = FileName+1;
    576     if ((TempLocation = StrStr(Copy , L"\"")) != NULL) {
     599    if ((TempLocation = StrStr (Copy, L"\"")) != NULL) {
    577600      TempLocation[0] = CHAR_NULL;
    578601    }
    579602  } else {
    580603    Copy = FileName;
    581     while(Copy[0] == L' ') {
     604    while (Copy[0] == L' ') {
    582605      Copy++;
    583606    }
    584     if ((TempLocation = StrStr(Copy , L" ")) != NULL) {
     607
     608    if ((TempLocation = StrStr (Copy, L" ")) != NULL) {
    585609      TempLocation[0] = CHAR_NULL;
    586610    }
     
    602626  @return       The modified FileName.
    603627**/
    604 CHAR16*
     628CHAR16 *
    605629FixVarName (
    606   IN CHAR16 *FileName
     630  IN CHAR16  *FileName
    607631  )
    608632{
     
    614638  if (FileName[0] == L'%') {
    615639    Copy = FileName+1;
    616     if ((TempLocation = StrStr(Copy , L"%")) != NULL) {
     640    if ((TempLocation = StrStr (Copy, L"%")) != NULL) {
    617641      TempLocation[0] = CHAR_NULL;
    618642    }
    619643  }
    620644
    621   return (FixFileName(Copy));
     645  return (FixFileName (Copy));
    622646}
    623 
    624647
    625648/**
     
    636659EFI_STATUS
    637660WriteFileTag (
    638   IN SHELL_FILE_HANDLE FileHandle
     661  IN SHELL_FILE_HANDLE  FileHandle
    639662  )
    640663{
    641   CHAR16     FileTag;
    642   UINTN      Size;
    643   EFI_STATUS Status;
     664  CHAR16      FileTag;
     665  UINTN       Size;
     666  EFI_STATUS  Status;
    644667
    645668  FileTag = gUnicodeFileTag;
    646   Size = sizeof FileTag;
    647   Status = ShellInfoObject.NewEfiShellProtocol->WriteFile (FileHandle, &Size,
    648                                                   &FileTag);
     669  Size    = sizeof FileTag;
     670  Status  = ShellInfoObject.NewEfiShellProtocol->WriteFile (
     671                                                   FileHandle,
     672                                                   &Size,
     673                                                   &FileTag
     674                                                   );
    649675  ASSERT (EFI_ERROR (Status) || Size == sizeof FileTag);
    650676  return Status;
    651677}
    652 
    653678
    654679/**
     
    670695**/
    671696EFI_STATUS
    672 UpdateStdInStdOutStdErr(
     697UpdateStdInStdOutStdErr (
    673698  IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,
    674699  IN CHAR16                             *NewCommandLine,
     
    679704  )
    680705{
    681   CHAR16            *CommandLineCopy;
    682   CHAR16            *CommandLineWalker;
    683   CHAR16            *StdErrFileName;
    684   CHAR16            *StdOutFileName;
    685   CHAR16            *StdInFileName;
    686   CHAR16            *StdInVarName;
    687   CHAR16            *StdOutVarName;
    688   CHAR16            *StdErrVarName;
    689   EFI_STATUS        Status;
    690   SHELL_FILE_HANDLE TempHandle;
    691   UINT64            FileSize;
    692   BOOLEAN           OutUnicode;
    693   BOOLEAN           InUnicode;
    694   BOOLEAN           ErrUnicode;
    695   BOOLEAN           OutAppend;
    696   BOOLEAN           ErrAppend;
    697   UINTN             Size;
    698   SPLIT_LIST        *Split;
    699   CHAR16            *FirstLocation;
    700   BOOLEAN           Volatile;
    701 
    702   OutUnicode      = TRUE;
    703   InUnicode       = TRUE;
     706  CHAR16             *CommandLineCopy;
     707  CHAR16             *CommandLineWalker;
     708  CHAR16             *StdErrFileName;
     709  CHAR16             *StdOutFileName;
     710  CHAR16             *StdInFileName;
     711  CHAR16             *StdInVarName;
     712  CHAR16             *StdOutVarName;
     713  CHAR16             *StdErrVarName;
     714  EFI_STATUS         Status;
     715  SHELL_FILE_HANDLE  TempHandle;
     716  UINT64             FileSize;
     717  BOOLEAN            OutUnicode;
     718  BOOLEAN            InUnicode;
     719  BOOLEAN            ErrUnicode;
     720  BOOLEAN            OutAppend;
     721  BOOLEAN            ErrAppend;
     722  UINTN              Size;
     723  SPLIT_LIST         *Split;
     724  CHAR16             *FirstLocation;
     725  BOOLEAN            Volatile;
     726
     727  OutUnicode       = TRUE;
     728  InUnicode        = TRUE;
    704729  AsciiRedirection = FALSE;
    705   ErrUnicode      = TRUE;
    706   StdInVarName    = NULL;
    707   StdOutVarName   = NULL;
    708   StdErrVarName   = NULL;
    709   StdErrFileName  = NULL;
    710   StdInFileName   = NULL;
    711   StdOutFileName  = NULL;
    712   ErrAppend       = FALSE;
    713   OutAppend       = FALSE;
    714   CommandLineCopy = NULL;
    715   FirstLocation   = NULL;
    716 
    717   if (ShellParameters == NULL || SystemTableInfo == NULL || OldStdIn == NULL || OldStdOut == NULL || OldStdErr == NULL) {
     730  ErrUnicode       = TRUE;
     731  StdInVarName     = NULL;
     732  StdOutVarName    = NULL;
     733  StdErrVarName    = NULL;
     734  StdErrFileName   = NULL;
     735  StdInFileName    = NULL;
     736  StdOutFileName   = NULL;
     737  ErrAppend        = FALSE;
     738  OutAppend        = FALSE;
     739  CommandLineCopy  = NULL;
     740  FirstLocation    = NULL;
     741
     742  if ((ShellParameters == NULL) || (SystemTableInfo == NULL) || (OldStdIn == NULL) || (OldStdOut == NULL) || (OldStdErr == NULL)) {
    718743    return (EFI_INVALID_PARAMETER);
    719744  }
    720745
    721   SystemTableInfo->ConIn          = gST->ConIn;
    722   SystemTableInfo->ConInHandle    = gST->ConsoleInHandle;
    723   SystemTableInfo->ConOut         = gST->ConOut;
    724   SystemTableInfo->ConOutHandle   = gST->ConsoleOutHandle;
    725   SystemTableInfo->ErrOut         = gST->StdErr;
    726   SystemTableInfo->ErrOutHandle   = gST->StandardErrorHandle;
    727   *OldStdIn                       = ShellParameters->StdIn;
    728   *OldStdOut                      = ShellParameters->StdOut;
    729   *OldStdErr                      = ShellParameters->StdErr;
     746  SystemTableInfo->ConIn        = gST->ConIn;
     747  SystemTableInfo->ConInHandle  = gST->ConsoleInHandle;
     748  SystemTableInfo->ConOut       = gST->ConOut;
     749  SystemTableInfo->ConOutHandle = gST->ConsoleOutHandle;
     750  SystemTableInfo->ErrOut       = gST->StdErr;
     751  SystemTableInfo->ErrOutHandle = gST->StandardErrorHandle;
     752  *OldStdIn                     = ShellParameters->StdIn;
     753  *OldStdOut                    = ShellParameters->StdOut;
     754  *OldStdErr                    = ShellParameters->StdErr;
    730755
    731756  if (NewCommandLine == NULL) {
     
    733758  }
    734759
    735   CommandLineCopy = StrnCatGrow(&CommandLineCopy, NULL, NewCommandLine, 0);
     760  CommandLineCopy = StrnCatGrow (&CommandLineCopy, NULL, NewCommandLine, 0);
    736761  if (CommandLineCopy == NULL) {
    737762    return (EFI_OUT_OF_RESOURCES);
    738763  }
    739   Status          = EFI_SUCCESS;
    740   Split           = NULL;
    741   FirstLocation   = CommandLineCopy + StrLen(CommandLineCopy);
    742 
    743   StripQuotes(CommandLineCopy);
    744 
    745   if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
    746     Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
    747     if (Split != NULL && Split->SplitStdIn != NULL) {
    748       ShellParameters->StdIn  = Split->SplitStdIn;
    749     }
    750     if (Split != NULL && Split->SplitStdOut != NULL) {
     764
     765  Status        = EFI_SUCCESS;
     766  Split         = NULL;
     767  FirstLocation = CommandLineCopy + StrLen (CommandLineCopy);
     768
     769  StripQuotes (CommandLineCopy);
     770
     771  if (!IsListEmpty (&ShellInfoObject.SplitList.Link)) {
     772    Split = (SPLIT_LIST *)GetFirstNode (&ShellInfoObject.SplitList.Link);
     773    if ((Split != NULL) && (Split->SplitStdIn != NULL)) {
     774      ShellParameters->StdIn = Split->SplitStdIn;
     775    }
     776
     777    if ((Split != NULL) && (Split->SplitStdOut != NULL)) {
    751778      ShellParameters->StdOut = Split->SplitStdOut;
    752779    }
    753780  }
    754781
    755   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>>v ")) != NULL) {
    756     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    757     SetMem16(CommandLineWalker, 12, L' ');
    758     StdErrVarName   = CommandLineWalker += 6;
    759     ErrAppend       = TRUE;
    760     if (StrStr(CommandLineWalker, L" 2>>v ") != NULL) {
    761       Status = EFI_NOT_FOUND;
    762     }
    763   }
    764   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>v ")) != NULL) {
    765     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    766     SetMem16(CommandLineWalker, 12, L' ');
    767     StdOutVarName   = CommandLineWalker += 6;
    768     OutAppend       = TRUE;
    769     if (StrStr(CommandLineWalker, L" 1>>v ") != NULL) {
    770       Status = EFI_NOT_FOUND;
    771     }
    772   } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>v ")) != NULL) {
    773     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    774     SetMem16(CommandLineWalker, 10, L' ');
    775     StdOutVarName   = CommandLineWalker += 5;
    776     OutAppend       = TRUE;
    777     if (StrStr(CommandLineWalker, L" >>v ") != NULL) {
    778       Status = EFI_NOT_FOUND;
    779     }
    780   } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >v ")) != NULL) {
    781     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    782     SetMem16(CommandLineWalker, 8, L' ');
    783     StdOutVarName   = CommandLineWalker += 4;
    784     OutAppend       = FALSE;
    785     if (StrStr(CommandLineWalker, L" >v ") != NULL) {
    786       Status = EFI_NOT_FOUND;
    787     }
    788   }
    789   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>a ")) != NULL) {
    790     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    791     SetMem16(CommandLineWalker, 12, L' ');
    792     StdOutFileName  = CommandLineWalker += 6;
    793     OutAppend       = TRUE;
    794     OutUnicode      = FALSE;
    795     if (StrStr(CommandLineWalker, L" 1>>a ") != NULL) {
    796       Status = EFI_NOT_FOUND;
    797     }
    798   }
    799   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>> ")) != NULL) {
    800     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    801     SetMem16(CommandLineWalker, 10, L' ');
     782  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2>>v ")) != NULL)) {
     783    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     784    SetMem16 (CommandLineWalker, 12, L' ');
     785    StdErrVarName = CommandLineWalker += 6;
     786    ErrAppend     = TRUE;
     787    if (StrStr (CommandLineWalker, L" 2>>v ") != NULL) {
     788      Status = EFI_NOT_FOUND;
     789    }
     790  }
     791
     792  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>>v ")) != NULL)) {
     793    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     794    SetMem16 (CommandLineWalker, 12, L' ');
     795    StdOutVarName = CommandLineWalker += 6;
     796    OutAppend     = TRUE;
     797    if (StrStr (CommandLineWalker, L" 1>>v ") != NULL) {
     798      Status = EFI_NOT_FOUND;
     799    }
     800  } else if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >>v ")) != NULL)) {
     801    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     802    SetMem16 (CommandLineWalker, 10, L' ');
     803    StdOutVarName = CommandLineWalker += 5;
     804    OutAppend     = TRUE;
     805    if (StrStr (CommandLineWalker, L" >>v ") != NULL) {
     806      Status = EFI_NOT_FOUND;
     807    }
     808  } else if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >v ")) != NULL)) {
     809    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     810    SetMem16 (CommandLineWalker, 8, L' ');
     811    StdOutVarName = CommandLineWalker += 4;
     812    OutAppend     = FALSE;
     813    if (StrStr (CommandLineWalker, L" >v ") != NULL) {
     814      Status = EFI_NOT_FOUND;
     815    }
     816  }
     817
     818  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>>a ")) != NULL)) {
     819    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     820    SetMem16 (CommandLineWalker, 12, L' ');
     821    StdOutFileName = CommandLineWalker += 6;
     822    OutAppend      = TRUE;
     823    OutUnicode     = FALSE;
     824    if (StrStr (CommandLineWalker, L" 1>>a ") != NULL) {
     825      Status = EFI_NOT_FOUND;
     826    }
     827  }
     828
     829  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>> ")) != NULL)) {
     830    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     831    SetMem16 (CommandLineWalker, 10, L' ');
    802832    if (StdOutFileName != NULL) {
    803833      Status = EFI_INVALID_PARAMETER;
    804834    } else {
    805       StdOutFileName  = CommandLineWalker += 5;
    806       OutAppend       = TRUE;
    807     }
    808     if (StrStr(CommandLineWalker, L" 1>> ") != NULL) {
    809       Status = EFI_NOT_FOUND;
    810     }
    811   }
    812   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >> ")) != NULL) {
    813     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    814     SetMem16(CommandLineWalker, 8, L' ');
     835      StdOutFileName = CommandLineWalker += 5;
     836      OutAppend      = TRUE;
     837    }
     838
     839    if (StrStr (CommandLineWalker, L" 1>> ") != NULL) {
     840      Status = EFI_NOT_FOUND;
     841    }
     842  }
     843
     844  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >> ")) != NULL)) {
     845    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     846    SetMem16 (CommandLineWalker, 8, L' ');
    815847    if (StdOutFileName != NULL) {
    816848      Status = EFI_INVALID_PARAMETER;
    817849    } else {
    818       StdOutFileName  = CommandLineWalker += 4;
    819       OutAppend       = TRUE;
    820     }
    821     if (StrStr(CommandLineWalker, L" >> ") != NULL) {
    822       Status = EFI_NOT_FOUND;
    823     }
    824   }
    825   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>a ")) != NULL) {
    826     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    827     SetMem16(CommandLineWalker, 10, L' ');
     850      StdOutFileName = CommandLineWalker += 4;
     851      OutAppend      = TRUE;
     852    }
     853
     854    if (StrStr (CommandLineWalker, L" >> ") != NULL) {
     855      Status = EFI_NOT_FOUND;
     856    }
     857  }
     858
     859  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >>a ")) != NULL)) {
     860    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     861    SetMem16 (CommandLineWalker, 10, L' ');
    828862    if (StdOutFileName != NULL) {
    829863      Status = EFI_INVALID_PARAMETER;
    830864    } else {
    831       StdOutFileName  = CommandLineWalker += 5;
    832       OutAppend       = TRUE;
    833       OutUnicode      = FALSE;
    834     }
    835     if (StrStr(CommandLineWalker, L" >>a ") != NULL) {
    836       Status = EFI_NOT_FOUND;
    837     }
    838   }
    839   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>a ")) != NULL) {
    840     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    841     SetMem16(CommandLineWalker, 10, L' ');
     865      StdOutFileName = CommandLineWalker += 5;
     866      OutAppend      = TRUE;
     867      OutUnicode     = FALSE;
     868    }
     869
     870    if (StrStr (CommandLineWalker, L" >>a ") != NULL) {
     871      Status = EFI_NOT_FOUND;
     872    }
     873  }
     874
     875  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>a ")) != NULL)) {
     876    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     877    SetMem16 (CommandLineWalker, 10, L' ');
    842878    if (StdOutFileName != NULL) {
    843879      Status = EFI_INVALID_PARAMETER;
    844880    } else {
    845       StdOutFileName  = CommandLineWalker += 5;
    846       OutAppend       = FALSE;
    847       OutUnicode      = FALSE;
    848     }
    849     if (StrStr(CommandLineWalker, L" 1>a ") != NULL) {
    850       Status = EFI_NOT_FOUND;
    851     }
    852   }
    853   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >a ")) != NULL) {
    854     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    855     SetMem16(CommandLineWalker, 8, L' ');
     881      StdOutFileName = CommandLineWalker += 5;
     882      OutAppend      = FALSE;
     883      OutUnicode     = FALSE;
     884    }
     885
     886    if (StrStr (CommandLineWalker, L" 1>a ") != NULL) {
     887      Status = EFI_NOT_FOUND;
     888    }
     889  }
     890
     891  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >a ")) != NULL)) {
     892    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     893    SetMem16 (CommandLineWalker, 8, L' ');
    856894    if (StdOutFileName != NULL) {
    857895      Status = EFI_INVALID_PARAMETER;
    858896    } else {
    859       StdOutFileName  = CommandLineWalker += 4;
    860       OutAppend       = FALSE;
    861       OutUnicode      = FALSE;
    862     }
    863     if (StrStr(CommandLineWalker, L" >a ") != NULL) {
    864       Status = EFI_NOT_FOUND;
    865     }
    866   }
    867   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>> ")) != NULL) {
    868     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    869     SetMem16(CommandLineWalker, 10, L' ');
     897      StdOutFileName = CommandLineWalker += 4;
     898      OutAppend      = FALSE;
     899      OutUnicode     = FALSE;
     900    }
     901
     902    if (StrStr (CommandLineWalker, L" >a ") != NULL) {
     903      Status = EFI_NOT_FOUND;
     904    }
     905  }
     906
     907  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2>> ")) != NULL)) {
     908    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     909    SetMem16 (CommandLineWalker, 10, L' ');
    870910    if (StdErrFileName != NULL) {
    871911      Status = EFI_INVALID_PARAMETER;
    872912    } else {
    873       StdErrFileName  = CommandLineWalker += 5;
    874       ErrAppend       = TRUE;
    875     }
    876     if (StrStr(CommandLineWalker, L" 2>> ") != NULL) {
    877       Status = EFI_NOT_FOUND;
    878     }
    879   }
    880 
    881   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>v ")) != NULL) {
    882     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    883     SetMem16(CommandLineWalker, 10, L' ');
     913      StdErrFileName = CommandLineWalker += 5;
     914      ErrAppend      = TRUE;
     915    }
     916
     917    if (StrStr (CommandLineWalker, L" 2>> ") != NULL) {
     918      Status = EFI_NOT_FOUND;
     919    }
     920  }
     921
     922  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2>v ")) != NULL)) {
     923    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     924    SetMem16 (CommandLineWalker, 10, L' ');
    884925    if (StdErrVarName != NULL) {
    885926      Status = EFI_INVALID_PARAMETER;
    886927    } else {
    887       StdErrVarName   = CommandLineWalker += 5;
    888       ErrAppend       = FALSE;
    889     }
    890     if (StrStr(CommandLineWalker, L" 2>v ") != NULL) {
    891       Status = EFI_NOT_FOUND;
    892     }
    893   }
    894   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>v ")) != NULL) {
    895     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    896     SetMem16(CommandLineWalker, 10, L' ');
     928      StdErrVarName = CommandLineWalker += 5;
     929      ErrAppend     = FALSE;
     930    }
     931
     932    if (StrStr (CommandLineWalker, L" 2>v ") != NULL) {
     933      Status = EFI_NOT_FOUND;
     934    }
     935  }
     936
     937  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>v ")) != NULL)) {
     938    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     939    SetMem16 (CommandLineWalker, 10, L' ');
    897940    if (StdOutVarName != NULL) {
    898941      Status = EFI_INVALID_PARAMETER;
    899942    } else {
    900       StdOutVarName   = CommandLineWalker += 5;
    901       OutAppend       = FALSE;
    902     }
    903     if (StrStr(CommandLineWalker, L" 1>v ") != NULL) {
    904       Status = EFI_NOT_FOUND;
    905     }
    906   }
    907   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>a ")) != NULL) {
    908     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    909     SetMem16(CommandLineWalker, 10, L' ');
     943      StdOutVarName = CommandLineWalker += 5;
     944      OutAppend     = FALSE;
     945    }
     946
     947    if (StrStr (CommandLineWalker, L" 1>v ") != NULL) {
     948      Status = EFI_NOT_FOUND;
     949    }
     950  }
     951
     952  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2>a ")) != NULL)) {
     953    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     954    SetMem16 (CommandLineWalker, 10, L' ');
    910955    if (StdErrFileName != NULL) {
    911956      Status = EFI_INVALID_PARAMETER;
    912957    } else {
    913       StdErrFileName  = CommandLineWalker += 5;
    914       ErrAppend       = FALSE;
    915       ErrUnicode      = FALSE;
    916     }
    917     if (StrStr(CommandLineWalker, L" 2>a ") != NULL) {
    918       Status = EFI_NOT_FOUND;
    919     }
    920   }
    921   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2> ")) != NULL) {
    922     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    923     SetMem16(CommandLineWalker, 8, L' ');
     958      StdErrFileName = CommandLineWalker += 5;
     959      ErrAppend      = FALSE;
     960      ErrUnicode     = FALSE;
     961    }
     962
     963    if (StrStr (CommandLineWalker, L" 2>a ") != NULL) {
     964      Status = EFI_NOT_FOUND;
     965    }
     966  }
     967
     968  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2> ")) != NULL)) {
     969    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     970    SetMem16 (CommandLineWalker, 8, L' ');
    924971    if (StdErrFileName != NULL) {
    925972      Status = EFI_INVALID_PARAMETER;
    926973    } else {
    927       StdErrFileName  = CommandLineWalker += 4;
    928       ErrAppend       = FALSE;
    929     }
    930     if (StrStr(CommandLineWalker, L" 2> ") != NULL) {
    931       Status = EFI_NOT_FOUND;
    932     }
    933   }
    934 
    935   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1> ")) != NULL) {
    936     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    937     SetMem16(CommandLineWalker, 8, L' ');
     974      StdErrFileName = CommandLineWalker += 4;
     975      ErrAppend      = FALSE;
     976    }
     977
     978    if (StrStr (CommandLineWalker, L" 2> ") != NULL) {
     979      Status = EFI_NOT_FOUND;
     980    }
     981  }
     982
     983  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1> ")) != NULL)) {
     984    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     985    SetMem16 (CommandLineWalker, 8, L' ');
    938986    if (StdOutFileName != NULL) {
    939987      Status = EFI_INVALID_PARAMETER;
    940988    } else {
    941       StdOutFileName  = CommandLineWalker += 4;
    942       OutAppend       = FALSE;
    943     }
    944     if (StrStr(CommandLineWalker, L" 1> ") != NULL) {
    945       Status = EFI_NOT_FOUND;
    946     }
    947   }
    948 
    949   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" > ")) != NULL) {
    950     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    951     SetMem16(CommandLineWalker, 6, L' ');
     989      StdOutFileName = CommandLineWalker += 4;
     990      OutAppend      = FALSE;
     991    }
     992
     993    if (StrStr (CommandLineWalker, L" 1> ") != NULL) {
     994      Status = EFI_NOT_FOUND;
     995    }
     996  }
     997
     998  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" > ")) != NULL)) {
     999    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     1000    SetMem16 (CommandLineWalker, 6, L' ');
    9521001    if (StdOutFileName != NULL) {
    9531002      Status = EFI_INVALID_PARAMETER;
    9541003    } else {
    955       StdOutFileName  = CommandLineWalker += 3;
    956       OutAppend       = FALSE;
    957     }
    958     if (StrStr(CommandLineWalker, L" > ") != NULL) {
    959       Status = EFI_NOT_FOUND;
    960     }
    961   }
    962 
    963   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" < ")) != NULL) {
    964     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    965     SetMem16(CommandLineWalker, 6, L' ');
     1004      StdOutFileName = CommandLineWalker += 3;
     1005      OutAppend      = FALSE;
     1006    }
     1007
     1008    if (StrStr (CommandLineWalker, L" > ") != NULL) {
     1009      Status = EFI_NOT_FOUND;
     1010    }
     1011  }
     1012
     1013  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" < ")) != NULL)) {
     1014    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     1015    SetMem16 (CommandLineWalker, 6, L' ');
    9661016    if (StdInFileName != NULL) {
    9671017      Status = EFI_INVALID_PARAMETER;
    9681018    } else {
    969       StdInFileName  = CommandLineWalker += 3;
    970     }
    971     if (StrStr(CommandLineWalker, L" < ") != NULL) {
    972       Status = EFI_NOT_FOUND;
    973     }
    974   }
    975   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <a ")) != NULL) {
    976     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    977     SetMem16(CommandLineWalker, 8, L' ');
     1019      StdInFileName = CommandLineWalker += 3;
     1020    }
     1021
     1022    if (StrStr (CommandLineWalker, L" < ") != NULL) {
     1023      Status = EFI_NOT_FOUND;
     1024    }
     1025  }
     1026
     1027  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" <a ")) != NULL)) {
     1028    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     1029    SetMem16 (CommandLineWalker, 8, L' ');
    9781030    if (StdInFileName != NULL) {
    9791031      Status = EFI_INVALID_PARAMETER;
    9801032    } else {
    981       StdInFileName   = CommandLineWalker += 4;
    982       InUnicode       = FALSE;
     1033      StdInFileName    = CommandLineWalker += 4;
     1034      InUnicode        = FALSE;
    9831035      AsciiRedirection = TRUE;
    9841036    }
    985     if (StrStr(CommandLineWalker, L" <a ") != NULL) {
    986       Status = EFI_NOT_FOUND;
    987     }
    988   }
    989   if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <v ")) != NULL) {
    990     FirstLocation = MIN(CommandLineWalker, FirstLocation);
    991     SetMem16(CommandLineWalker, 8, L' ');
     1037
     1038    if (StrStr (CommandLineWalker, L" <a ") != NULL) {
     1039      Status = EFI_NOT_FOUND;
     1040    }
     1041  }
     1042
     1043  if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" <v ")) != NULL)) {
     1044    FirstLocation = MIN (CommandLineWalker, FirstLocation);
     1045    SetMem16 (CommandLineWalker, 8, L' ');
    9921046    if (StdInVarName != NULL) {
    9931047      Status = EFI_INVALID_PARAMETER;
    9941048    } else {
    995       StdInVarName  = CommandLineWalker += 4;
    996     }
    997     if (StrStr(CommandLineWalker, L" <v ") != NULL) {
     1049      StdInVarName = CommandLineWalker += 4;
     1050    }
     1051
     1052    if (StrStr (CommandLineWalker, L" <v ") != NULL) {
    9981053      Status = EFI_NOT_FOUND;
    9991054    }
     
    10031058  // re-populate the string to support any filenames that were in quotes.
    10041059  //
    1005   StrnCpyS(CommandLineCopy, StrSize(CommandLineCopy)/sizeof(CHAR16), NewCommandLine, StrLen(NewCommandLine));
    1006 
    1007   if (FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)
    1008     && (((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof(CHAR16) < StrLen(NewCommandLine))
    1009     ){
    1010     *(NewCommandLine + ((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof(CHAR16)) = CHAR_NULL;
    1011   }
    1012 
    1013   if (!EFI_ERROR(Status)) {
    1014 
     1060  StrnCpyS (CommandLineCopy, StrSize (CommandLineCopy)/sizeof (CHAR16), NewCommandLine, StrLen (NewCommandLine));
     1061
     1062  if (  (FirstLocation != CommandLineCopy + StrLen (CommandLineCopy))
     1063     && (((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof (CHAR16) < StrLen (NewCommandLine))
     1064        )
     1065  {
     1066    *(NewCommandLine + ((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof (CHAR16)) = CHAR_NULL;
     1067  }
     1068
     1069  if (!EFI_ERROR (Status)) {
    10151070    if (StdErrFileName != NULL) {
    1016       if ((StdErrFileName    = FixFileName(StdErrFileName)) == NULL) {
     1071      if ((StdErrFileName    = FixFileName (StdErrFileName)) == NULL) {
    10171072        Status = EFI_INVALID_PARAMETER;
    10181073      }
    10191074    }
     1075
    10201076    if (StdOutFileName != NULL) {
    1021       if ((StdOutFileName    = FixFileName(StdOutFileName)) == NULL) {
     1077      if ((StdOutFileName    = FixFileName (StdOutFileName)) == NULL) {
    10221078        Status = EFI_INVALID_PARAMETER;
    10231079      }
    10241080    }
     1081
    10251082    if (StdInFileName  != NULL) {
    1026       if ((StdInFileName     = FixFileName(StdInFileName)) == NULL) {
     1083      if ((StdInFileName     = FixFileName (StdInFileName)) == NULL) {
    10271084        Status = EFI_INVALID_PARAMETER;
    10281085      }
    10291086    }
     1087
    10301088    if (StdErrVarName  != NULL) {
    1031       if ((StdErrVarName     = FixVarName(StdErrVarName)) == NULL) {
     1089      if ((StdErrVarName     = FixVarName (StdErrVarName)) == NULL) {
    10321090        Status = EFI_INVALID_PARAMETER;
    10331091      }
    10341092    }
     1093
    10351094    if (StdOutVarName  != NULL) {
    1036       if ((StdOutVarName     = FixVarName(StdOutVarName)) == NULL) {
     1095      if ((StdOutVarName     = FixVarName (StdOutVarName)) == NULL) {
    10371096        Status = EFI_INVALID_PARAMETER;
    10381097      }
    10391098    }
     1099
    10401100    if (StdInVarName   != NULL) {
    1041       if ((StdInVarName      = FixVarName(StdInVarName)) == NULL) {
     1101      if ((StdInVarName      = FixVarName (StdInVarName)) == NULL) {
    10421102        Status = EFI_INVALID_PARAMETER;
    10431103      }
     
    10481108    //
    10491109    if (
    1050       //
    1051       // Check that no 2 filenames are the same
    1052       //
    1053       (StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0)
    1054       ||(StdErrFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdErrFileName, &StdInFileName ) == 0)
    1055       ||(StdOutFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdOutFileName, &StdInFileName ) == 0)
    1056       //
    1057       // Check that no 2 variable names are the same
    1058       //
    1059       ||(StdErrVarName  != NULL && StdInVarName  != NULL && StringNoCaseCompare(&StdErrVarName , &StdInVarName  ) == 0)
    1060       ||(StdOutVarName  != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdOutVarName , &StdInVarName  ) == 0)
    1061       ||(StdErrVarName  != NULL && StdOutVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdOutVarName ) == 0)
    1062       //
    1063       // When a split (using | operator) is in place some are not allowed
    1064       //
    1065       ||(Split != NULL && Split->SplitStdIn  != NULL && (StdInVarName  != NULL || StdInFileName  != NULL))
    1066       ||(Split != NULL && Split->SplitStdOut != NULL && (StdOutVarName != NULL || StdOutFileName != NULL))
    1067       //
    1068       // Check that nothing is trying to be output to 2 locations.
    1069       //
    1070       ||(StdErrFileName != NULL && StdErrVarName != NULL)
    1071       ||(StdOutFileName != NULL && StdOutVarName != NULL)
    1072       ||(StdInFileName  != NULL && StdInVarName  != NULL)
    1073       //
    1074       // Check for no volatile environment variables
    1075       //
    1076       ||(StdErrVarName  != NULL && !EFI_ERROR (IsVolatileEnv (StdErrVarName, &Volatile)) && !Volatile)
    1077       ||(StdOutVarName  != NULL && !EFI_ERROR (IsVolatileEnv (StdOutVarName, &Volatile)) && !Volatile)
    1078       //
    1079       // Cant redirect during a reconnect operation.
    1080       //
    1081       ||(StrStr(NewCommandLine, L"connect -r") != NULL
    1082          && (StdOutVarName != NULL || StdOutFileName != NULL || StdErrFileName != NULL || StdErrVarName != NULL))
    1083       //
    1084       // Check that filetypes (Unicode/Ascii) do not change during an append
    1085       //
    1086       ||(StdOutFileName != NULL && OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && EFI_ERROR(IsUnicodeFile(StdOutFileName))))
    1087       ||(StdErrFileName != NULL && ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && EFI_ERROR(IsUnicodeFile(StdErrFileName))))
    1088       ||(StdOutFileName != NULL && !OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName))))
    1089       ||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName))))
    1090       ){
    1091       Status = EFI_INVALID_PARAMETER;
     1110          //
     1111          // Check that no 2 filenames are the same
     1112          //
     1113          ((StdErrFileName != NULL) && (StdOutFileName != NULL) && (StringNoCaseCompare (&StdErrFileName, &StdOutFileName) == 0))
     1114       || ((StdErrFileName != NULL) && (StdInFileName != NULL) && (StringNoCaseCompare (&StdErrFileName, &StdInFileName) == 0))
     1115       || ((StdOutFileName != NULL) && (StdInFileName != NULL) && (StringNoCaseCompare (&StdOutFileName, &StdInFileName) == 0))
     1116          //
     1117          // Check that no 2 variable names are the same
     1118          //
     1119       || ((StdErrVarName  != NULL) && (StdInVarName  != NULL) && (StringNoCaseCompare (&StdErrVarName, &StdInVarName) == 0))
     1120       || ((StdOutVarName  != NULL) && (StdInVarName != NULL) && (StringNoCaseCompare (&StdOutVarName, &StdInVarName) == 0))
     1121       || ((StdErrVarName  != NULL) && (StdOutVarName != NULL) && (StringNoCaseCompare (&StdErrVarName, &StdOutVarName) == 0))
     1122          //
     1123          // When a split (using | operator) is in place some are not allowed
     1124          //
     1125       || ((Split != NULL) && (Split->SplitStdIn  != NULL) && ((StdInVarName  != NULL) || (StdInFileName  != NULL)))
     1126       || ((Split != NULL) && (Split->SplitStdOut != NULL) && ((StdOutVarName != NULL) || (StdOutFileName != NULL)))
     1127          //
     1128          // Check that nothing is trying to be output to 2 locations.
     1129          //
     1130       || ((StdErrFileName != NULL) && (StdErrVarName != NULL))
     1131       || ((StdOutFileName != NULL) && (StdOutVarName != NULL))
     1132       || ((StdInFileName  != NULL) && (StdInVarName  != NULL))
     1133          //
     1134          // Check for no volatile environment variables
     1135          //
     1136       || ((StdErrVarName  != NULL) && !EFI_ERROR (IsVolatileEnv (StdErrVarName, &Volatile)) && !Volatile)
     1137       || ((StdOutVarName  != NULL) && !EFI_ERROR (IsVolatileEnv (StdOutVarName, &Volatile)) && !Volatile)
     1138          //
     1139          // Cant redirect during a reconnect operation.
     1140          //
     1141       || (  (StrStr (NewCommandLine, L"connect -r") != NULL)
     1142          && ((StdOutVarName != NULL) || (StdOutFileName != NULL) || (StdErrFileName != NULL) || (StdErrVarName != NULL)))
     1143          //
     1144          // Check that filetypes (Unicode/Ascii) do not change during an append
     1145          //
     1146       || ((StdOutFileName != NULL) && OutUnicode && OutAppend && (!EFI_ERROR (ShellFileExists (StdOutFileName)) && EFI_ERROR (IsUnicodeFile (StdOutFileName))))
     1147       || ((StdErrFileName != NULL) && ErrUnicode && ErrAppend && (!EFI_ERROR (ShellFileExists (StdErrFileName)) && EFI_ERROR (IsUnicodeFile (StdErrFileName))))
     1148       || ((StdOutFileName != NULL) && !OutUnicode && OutAppend && (!EFI_ERROR (ShellFileExists (StdOutFileName)) && !EFI_ERROR (IsUnicodeFile (StdOutFileName))))
     1149       || ((StdErrFileName != NULL) && !ErrUnicode && ErrAppend && (!EFI_ERROR (ShellFileExists (StdErrFileName)) && !EFI_ERROR (IsUnicodeFile (StdErrFileName))))
     1150          )
     1151    {
     1152      Status                  = EFI_INVALID_PARAMETER;
    10921153      ShellParameters->StdIn  = *OldStdIn;
    10931154      ShellParameters->StdOut = *OldStdOut;
    10941155      ShellParameters->StdErr = *OldStdErr;
    1095     } else if (!EFI_ERROR(Status)){
     1156    } else if (!EFI_ERROR (Status)) {
    10961157      //
    10971158      // Open the Std<Whatever> and we should not have conflicts here...
     
    11061167          // delete existing file.
    11071168          //
    1108           ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdErrFileName);
     1169          ShellInfoObject.NewEfiShellProtocol->DeleteFileByName (StdErrFileName);
    11091170        }
    1110         Status = ShellOpenFileByName(StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
    1111         if (!ErrAppend && ErrUnicode && !EFI_ERROR(Status)) {
     1171
     1172        Status = ShellOpenFileByName (StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, 0);
     1173        if (!ErrAppend && ErrUnicode && !EFI_ERROR (Status)) {
    11121174          Status = WriteFileTag (TempHandle);
    11131175        }
    1114         if (!ErrUnicode && !EFI_ERROR(Status)) {
    1115           TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
    1116           ASSERT(TempHandle != NULL);
     1176
     1177        if (!ErrUnicode && !EFI_ERROR (Status)) {
     1178          TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);
     1179          ASSERT (TempHandle != NULL);
    11171180        }
    1118         if (!EFI_ERROR(Status)) {
     1181
     1182        if (!EFI_ERROR (Status)) {
    11191183          ShellParameters->StdErr = TempHandle;
    1120           gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);
     1184          gST->StdErr             = CreateSimpleTextOutOnFile (TempHandle, &gST->StandardErrorHandle, gST->StdErr);
    11211185        }
    11221186      }
     
    11251189      // StdOut to a file
    11261190      //
    1127       if (!EFI_ERROR(Status) && StdOutFileName != NULL) {
     1191      if (!EFI_ERROR (Status) && (StdOutFileName != NULL)) {
    11281192        if (!OutAppend) {
    11291193          //
    11301194          // delete existing file.
    11311195          //
    1132           ShellInfoObject.NewEfiShellProtocol->DeleteFileByName(StdOutFileName);
     1196          ShellInfoObject.NewEfiShellProtocol->DeleteFileByName (StdOutFileName);
    11331197        }
    1134         Status = ShellOpenFileByName(StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0);
     1198
     1199        Status = ShellOpenFileByName (StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, 0);
    11351200        if (TempHandle == NULL) {
    11361201          Status = EFI_INVALID_PARAMETER;
    11371202        } else {
    11381203          if (gUnicodeCollation->MetaiMatch (gUnicodeCollation, StdOutFileName, L"NUL")) {
    1139             //no-op
    1140           } else if (!OutAppend && OutUnicode && !EFI_ERROR(Status)) {
     1204            // no-op
     1205          } else if (!OutAppend && OutUnicode && !EFI_ERROR (Status)) {
    11411206            Status = WriteFileTag (TempHandle);
    11421207          } else if (OutAppend) {
    1143             Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize(TempHandle, &FileSize);
    1144             if (!EFI_ERROR(Status)) {
     1208            Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize (TempHandle, &FileSize);
     1209            if (!EFI_ERROR (Status)) {
    11451210              //
    11461211              // When appending to a new unicode file, write the file tag.
     
    11491214              //
    11501215              Status = (FileSize == 0 && OutUnicode) ?
    1151                          WriteFileTag (TempHandle) :
    1152                          ShellInfoObject.NewEfiShellProtocol->SetFilePosition (
    1153                                                                 TempHandle,
    1154                                                                 FileSize);
     1216                       WriteFileTag (TempHandle) :
     1217                       ShellInfoObject.NewEfiShellProtocol->SetFilePosition (
     1218                                                              TempHandle,
     1219                                                              FileSize
     1220                                                              );
    11551221            }
    11561222          }
    1157           if (!OutUnicode && !EFI_ERROR(Status)) {
    1158             TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
    1159             ASSERT(TempHandle != NULL);
     1223
     1224          if (!OutUnicode && !EFI_ERROR (Status)) {
     1225            TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);
     1226            ASSERT (TempHandle != NULL);
    11601227          }
    1161           if (!EFI_ERROR(Status)) {
     1228
     1229          if (!EFI_ERROR (Status)) {
    11621230            ShellParameters->StdOut = TempHandle;
    1163             gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
     1231            gST->ConOut             = CreateSimpleTextOutOnFile (TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
    11641232          }
    11651233        }
     
    11691237      // StdOut to a var
    11701238      //
    1171       if (!EFI_ERROR(Status) && StdOutVarName != NULL) {
     1239      if (!EFI_ERROR (Status) && (StdOutVarName != NULL)) {
    11721240        if (!OutAppend) {
    11731241          //
    11741242          // delete existing variable.
    11751243          //
    1176           SHELL_SET_ENVIRONMENT_VARIABLE_V(StdOutVarName, 0, L"");
     1244          SHELL_SET_ENVIRONMENT_VARIABLE_V (StdOutVarName, 0, L"");
    11771245        }
    1178         TempHandle = CreateFileInterfaceEnv(StdOutVarName);
    1179         ASSERT(TempHandle != NULL);
     1246
     1247        TempHandle = CreateFileInterfaceEnv (StdOutVarName);
     1248        ASSERT (TempHandle != NULL);
    11801249        ShellParameters->StdOut = TempHandle;
    1181         gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
     1250        gST->ConOut             = CreateSimpleTextOutOnFile (TempHandle, &gST->ConsoleOutHandle, gST->ConOut);
    11821251      }
    11831252
     
    11851254      // StdErr to a var
    11861255      //
    1187       if (!EFI_ERROR(Status) && StdErrVarName != NULL) {
     1256      if (!EFI_ERROR (Status) && (StdErrVarName != NULL)) {
    11881257        if (!ErrAppend) {
    11891258          //
    11901259          // delete existing variable.
    11911260          //
    1192           SHELL_SET_ENVIRONMENT_VARIABLE_V(StdErrVarName, 0, L"");
     1261          SHELL_SET_ENVIRONMENT_VARIABLE_V (StdErrVarName, 0, L"");
    11931262        }
    1194         TempHandle = CreateFileInterfaceEnv(StdErrVarName);
    1195         ASSERT(TempHandle != NULL);
     1263
     1264        TempHandle = CreateFileInterfaceEnv (StdErrVarName);
     1265        ASSERT (TempHandle != NULL);
    11961266        ShellParameters->StdErr = TempHandle;
    1197         gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);
     1267        gST->StdErr             = CreateSimpleTextOutOnFile (TempHandle, &gST->StandardErrorHandle, gST->StdErr);
    11981268      }
    11991269
     
    12011271      // StdIn from a var
    12021272      //
    1203       if (!EFI_ERROR(Status) && StdInVarName != NULL) {
    1204         TempHandle = CreateFileInterfaceEnv(StdInVarName);
     1273      if (!EFI_ERROR (Status) && (StdInVarName != NULL)) {
     1274        TempHandle = CreateFileInterfaceEnv (StdInVarName);
    12051275        if (TempHandle == NULL) {
    12061276          Status = EFI_OUT_OF_RESOURCES;
    12071277        } else {
    12081278          if (!InUnicode) {
    1209             TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
     1279            TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);
    12101280          }
     1281
    12111282          Size = 0;
    1212           if (TempHandle == NULL || ((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {
     1283          if ((TempHandle == NULL) || (((EFI_FILE_PROTOCOL *)TempHandle)->Read (TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL)) {
    12131284            Status = EFI_INVALID_PARAMETER;
    12141285          } else {
    12151286            ShellParameters->StdIn = TempHandle;
    1216             gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);
     1287            gST->ConIn             = CreateSimpleTextInOnFile (TempHandle, &gST->ConsoleInHandle);
    12171288          }
    12181289        }
     
    12221293      // StdIn from a file
    12231294      //
    1224       if (!EFI_ERROR(Status) && StdInFileName != NULL) {
    1225         Status = ShellOpenFileByName(
    1226           StdInFileName,
    1227           &TempHandle,
    1228           EFI_FILE_MODE_READ,
    1229           0);
    1230         if (!EFI_ERROR(Status)) {
     1295      if (!EFI_ERROR (Status) && (StdInFileName != NULL)) {
     1296        Status = ShellOpenFileByName (
     1297                   StdInFileName,
     1298                   &TempHandle,
     1299                   EFI_FILE_MODE_READ,
     1300                   0
     1301                   );
     1302        if (!EFI_ERROR (Status)) {
    12311303          if (!InUnicode) {
    12321304            //
    12331305            // Create the ASCII->Unicode conversion layer
    12341306            //
    1235             TempHandle = CreateFileInterfaceFile(TempHandle, FALSE);
     1307            TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);
    12361308          }
     1309
    12371310          ShellParameters->StdIn = TempHandle;
    1238           gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);
     1311          gST->ConIn             = CreateSimpleTextInOnFile (TempHandle, &gST->ConsoleInHandle);
    12391312        }
    12401313      }
    12411314    }
    12421315  }
    1243   FreePool(CommandLineCopy);
    1244 
    1245   CalculateEfiHdrCrc(&gST->Hdr);
    1246 
    1247   if (gST->ConIn == NULL ||gST->ConOut == NULL) {
     1316
     1317  FreePool (CommandLineCopy);
     1318
     1319  CalculateEfiHdrCrc (&gST->Hdr);
     1320
     1321  if ((gST->ConIn == NULL) || (gST->ConOut == NULL)) {
    12481322    Status = EFI_OUT_OF_RESOURCES;
    12491323  }
    12501324
    12511325  if (Status == EFI_NOT_FOUND) {
    1252     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);
    1253   } else if (EFI_ERROR(Status)) {
    1254     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
     1326    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);
     1327  } else if (EFI_ERROR (Status)) {
     1328    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);
    12551329  }
    12561330
     
    12771351  )
    12781352{
    1279   SPLIT_LIST        *Split;
    1280 
    1281   if (ShellParameters == NULL
    1282     ||OldStdIn        == NULL
    1283     ||OldStdOut       == NULL
    1284     ||OldStdErr       == NULL
    1285     ||SystemTableInfo == NULL) {
     1353  SPLIT_LIST  *Split;
     1354
     1355  if (  (ShellParameters == NULL)
     1356     || (OldStdIn        == NULL)
     1357     || (OldStdOut       == NULL)
     1358     || (OldStdErr       == NULL)
     1359     || (SystemTableInfo == NULL))
     1360  {
    12861361    return (EFI_INVALID_PARAMETER);
    12871362  }
    1288   if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) {
    1289     Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link);
     1363
     1364  if (!IsListEmpty (&ShellInfoObject.SplitList.Link)) {
     1365    Split = (SPLIT_LIST *)GetFirstNode (&ShellInfoObject.SplitList.Link);
    12901366  } else {
    12911367    Split = NULL;
    12921368  }
     1369
    12931370  if (ShellParameters->StdIn  != *OldStdIn) {
    1294     if ((Split != NULL && Split->SplitStdIn != ShellParameters->StdIn) || Split == NULL) {
    1295       gEfiShellProtocol->CloseFile(ShellParameters->StdIn);
    1296     }
     1371    if (((Split != NULL) && (Split->SplitStdIn != ShellParameters->StdIn)) || (Split == NULL)) {
     1372      gEfiShellProtocol->CloseFile (ShellParameters->StdIn);
     1373    }
     1374
    12971375    ShellParameters->StdIn = *OldStdIn;
    12981376  }
     1377
    12991378  if (ShellParameters->StdOut != *OldStdOut) {
    1300     if ((Split != NULL && Split->SplitStdOut != ShellParameters->StdOut) || Split == NULL) {
    1301       gEfiShellProtocol->CloseFile(ShellParameters->StdOut);
    1302     }
     1379    if (((Split != NULL) && (Split->SplitStdOut != ShellParameters->StdOut)) || (Split == NULL)) {
     1380      gEfiShellProtocol->CloseFile (ShellParameters->StdOut);
     1381    }
     1382
    13031383    ShellParameters->StdOut = *OldStdOut;
    13041384  }
     1385
    13051386  if (ShellParameters->StdErr != *OldStdErr) {
    1306     gEfiShellProtocol->CloseFile(ShellParameters->StdErr);
     1387    gEfiShellProtocol->CloseFile (ShellParameters->StdErr);
    13071388    ShellParameters->StdErr = *OldStdErr;
    13081389  }
    13091390
    13101391  if (gST->ConIn != SystemTableInfo->ConIn) {
    1311     CloseSimpleTextInOnFile(gST->ConIn);
    1312     gST->ConIn                = SystemTableInfo->ConIn;
    1313     gST->ConsoleInHandle      = SystemTableInfo->ConInHandle;
    1314   }
     1392    CloseSimpleTextInOnFile (gST->ConIn);
     1393    gST->ConIn           = SystemTableInfo->ConIn;
     1394    gST->ConsoleInHandle = SystemTableInfo->ConInHandle;
     1395  }
     1396
    13151397  if (gST->ConOut != SystemTableInfo->ConOut) {
    1316     CloseSimpleTextOutOnFile(gST->ConOut);
    1317     gST->ConOut               = SystemTableInfo->ConOut;
    1318     gST->ConsoleOutHandle     = SystemTableInfo->ConOutHandle;
    1319   }
     1398    CloseSimpleTextOutOnFile (gST->ConOut);
     1399    gST->ConOut           = SystemTableInfo->ConOut;
     1400    gST->ConsoleOutHandle = SystemTableInfo->ConOutHandle;
     1401  }
     1402
    13201403  if (gST->StdErr != SystemTableInfo->ErrOut) {
    1321     CloseSimpleTextOutOnFile(gST->StdErr);
    1322     gST->StdErr               = SystemTableInfo->ErrOut;
    1323     gST->StandardErrorHandle  = SystemTableInfo->ErrOutHandle;
    1324   }
    1325 
    1326   CalculateEfiHdrCrc(&gST->Hdr);
     1404    CloseSimpleTextOutOnFile (gST->StdErr);
     1405    gST->StdErr              = SystemTableInfo->ErrOut;
     1406    gST->StandardErrorHandle = SystemTableInfo->ErrOutHandle;
     1407  }
     1408
     1409  CalculateEfiHdrCrc (&gST->Hdr);
    13271410
    13281411  return (EFI_SUCCESS);
    13291412}
     1413
    13301414/**
    13311415  Function will replace the current Argc and Argv in the ShellParameters protocol
     
    13471431**/
    13481432EFI_STATUS
    1349 UpdateArgcArgv(
     1433UpdateArgcArgv (
    13501434  IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,
    13511435  IN CONST CHAR16                       *NewCommandLine,
     
    13551439  )
    13561440{
    1357   BOOLEAN                 StripParamQuotation;
    1358 
    1359   ASSERT(ShellParameters != NULL);
     1441  BOOLEAN  StripParamQuotation;
     1442
     1443  ASSERT (ShellParameters != NULL);
    13601444  StripParamQuotation = TRUE;
    13611445
     
    13631447    *OldArgc = ShellParameters->Argc;
    13641448  }
     1449
    13651450  if (OldArgc != NULL) {
    13661451    *OldArgv = ShellParameters->Argv;
     
    13711456  }
    13721457
    1373   return ParseCommandLineToArgs( NewCommandLine,
    1374                                  StripParamQuotation,
    1375                                  &(ShellParameters->Argv),
    1376                                  &(ShellParameters->Argc)
    1377                                 );
     1458  return ParseCommandLineToArgs (
     1459           NewCommandLine,
     1460           StripParamQuotation,
     1461           &(ShellParameters->Argv),
     1462           &(ShellParameters->Argc)
     1463           );
    13781464}
    13791465
     
    13881474**/
    13891475VOID
    1390 RestoreArgcArgv(
     1476RestoreArgcArgv (
    13911477  IN OUT EFI_SHELL_PARAMETERS_PROTOCOL  *ShellParameters,
    13921478  IN CHAR16                             ***OldArgv,
     
    13941480  )
    13951481{
    1396   UINTN LoopCounter;
    1397   ASSERT(ShellParameters != NULL);
    1398   ASSERT(OldArgv         != NULL);
    1399   ASSERT(OldArgc         != NULL);
     1482  UINTN  LoopCounter;
     1483
     1484  ASSERT (ShellParameters != NULL);
     1485  ASSERT (OldArgv         != NULL);
     1486  ASSERT (OldArgc         != NULL);
    14001487
    14011488  if (ShellParameters->Argv != NULL) {
    14021489    for ( LoopCounter = 0
    1403         ; LoopCounter < ShellParameters->Argc
    1404         ; LoopCounter++
    1405        ){
    1406       FreePool(ShellParameters->Argv[LoopCounter]);
    1407     }
    1408     FreePool(ShellParameters->Argv);
    1409   }
     1490          ; LoopCounter < ShellParameters->Argc
     1491          ; LoopCounter++
     1492          )
     1493    {
     1494      FreePool (ShellParameters->Argv[LoopCounter]);
     1495    }
     1496
     1497    FreePool (ShellParameters->Argv);
     1498  }
     1499
    14101500  ShellParameters->Argv = *OldArgv;
    1411   *OldArgv = NULL;
     1501  *OldArgv              = NULL;
    14121502  ShellParameters->Argc = *OldArgc;
    1413   *OldArgc = 0;
     1503  *OldArgc              = 0;
    14141504}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette