X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FApplication%2FShell%2FShellParametersProtocol.c;h=ab435a126313da06da9eaecfe3e8c478e3617430;hb=7798fb83de4b2505a8e17457256b113a05d8475c;hp=a01a5c6a71581bfecf88f834b13d16b63caf9d8a;hpb=0406a5717b3b3760a7bf6b5cc1a5efe7aa7a76b1;p=mirror_edk2.git diff --git a/ShellPkg/Application/Shell/ShellParametersProtocol.c b/ShellPkg/Application/Shell/ShellParametersProtocol.c index a01a5c6a71..ab435a1263 100644 --- a/ShellPkg/Application/Shell/ShellParametersProtocol.c +++ b/ShellPkg/Application/Shell/ShellParametersProtocol.c @@ -2,7 +2,8 @@ Member functions of EFI_SHELL_PARAMETERS_PROTOCOL and functions for creation, manipulation, and initialization of EFI_SHELL_PARAMETERS_PROTOCOL. - Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.
+ Copyright (c) 2013 Hewlett-Packard Development Company, L.P. + Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -290,10 +291,10 @@ CreatePopulateInstallShellParametersProtocol ( // // Build the full command line // - Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, &FullCommandLine); + Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine); if (Status == EFI_BUFFER_TOO_SMALL) { FullCommandLine = AllocateZeroPool(Size + LoadedImage->LoadOptionsSize); - Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, &FullCommandLine); + Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine); } if (Status == EFI_NOT_FOUND) { // @@ -313,9 +314,7 @@ CreatePopulateInstallShellParametersProtocol ( FullCommandLine = AllocateZeroPool(Size); } if (FullCommandLine != NULL) { - if (LoadedImage->LoadOptionsSize != 0){ - StrCpy(FullCommandLine, LoadedImage->LoadOptions); - } + CopyMem (FullCommandLine, LoadedImage->LoadOptions, LoadedImage->LoadOptionsSize); // // Populate Argc and Argv // @@ -539,6 +538,57 @@ FixFileName ( return (Copy); } +/** + Fix a string to only have the environment variable name, removing starting at the first space of whatever is quoted and removing the leading and trailing %. + + @param[in] FileName The filename to start with. + + @retval NULL FileName was invalid. + @return The modified FileName. +**/ +CHAR16* +EFIAPI +FixVarName ( + IN CHAR16 *FileName + ) +{ + CHAR16 *Copy; + CHAR16 *TempLocation; + + Copy = FileName; + + if (FileName[0] == L'%') { + Copy = FileName+1; + if ((TempLocation = StrStr(Copy , L"%")) != NULL) { + TempLocation[0] = CHAR_NULL; + } + } + + return (FixFileName(Copy)); +} + +/** + Remove the unicode file tag from the begining of the file buffer since that will not be + used by StdIn. +**/ +EFI_STATUS +EFIAPI +RemoveFileTag( + IN SHELL_FILE_HANDLE *Handle + ) +{ + UINTN CharSize; + CHAR16 CharBuffer; + + CharSize = sizeof(CHAR16); + CharBuffer = 0; + gEfiShellProtocol->ReadFile(*Handle, &CharSize, &CharBuffer); + if (CharBuffer != gUnicodeFileTag) { + gEfiShellProtocol->SetFilePosition(*Handle, 0); + } + return (EFI_SUCCESS); +} + /** Funcion will replace the current StdIn and StdOut in the ShellParameters protocol structure by parsing NewCommandLine. The current values are returned to the @@ -915,17 +965,17 @@ UpdateStdInStdOutStdErr( } } if (StdErrVarName != NULL) { - if ((StdErrVarName = FixFileName(StdErrVarName)) == NULL) { + if ((StdErrVarName = FixVarName(StdErrVarName)) == NULL) { Status = EFI_INVALID_PARAMETER; } } if (StdOutVarName != NULL) { - if ((StdOutVarName = FixFileName(StdOutVarName)) == NULL) { + if ((StdOutVarName = FixVarName(StdOutVarName)) == NULL) { Status = EFI_INVALID_PARAMETER; } } if (StdInVarName != NULL) { - if ((StdInVarName = FixFileName(StdInVarName)) == NULL) { + if ((StdInVarName = FixVarName(StdInVarName)) == NULL) { Status = EFI_INVALID_PARAMETER; } } @@ -1010,7 +1060,7 @@ UpdateStdInStdOutStdErr( } if (!EFI_ERROR(Status)) { ShellParameters->StdErr = TempHandle; - gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle); + gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr); } } @@ -1053,7 +1103,7 @@ UpdateStdInStdOutStdErr( } if (!EFI_ERROR(Status)) { ShellParameters->StdOut = TempHandle; - gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle); + gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut); } } } @@ -1071,7 +1121,7 @@ UpdateStdInStdOutStdErr( TempHandle = CreateFileInterfaceEnv(StdOutVarName); ASSERT(TempHandle != NULL); ShellParameters->StdOut = TempHandle; - gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle); + gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut); } // @@ -1087,7 +1137,7 @@ UpdateStdInStdOutStdErr( TempHandle = CreateFileInterfaceEnv(StdErrVarName); ASSERT(TempHandle != NULL); ShellParameters->StdErr = TempHandle; - gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle); + gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr); } // @@ -1120,7 +1170,15 @@ UpdateStdInStdOutStdErr( &TempHandle, EFI_FILE_MODE_READ, 0); - if (!InUnicode && !EFI_ERROR(Status)) { + if (InUnicode) { + // + // Chop off the 0xFEFF if it's there... + // + RemoveFileTag(&TempHandle); + } else if (!EFI_ERROR(Status)) { + // + // Create the ASCII->Unicode conversion layer + // TempHandle = CreateFileInterfaceFile(TempHandle, FALSE); } if (!EFI_ERROR(Status)) { @@ -1135,8 +1193,15 @@ UpdateStdInStdOutStdErr( CalculateEfiHdrCrc(&gST->Hdr); if (gST->ConIn == NULL ||gST->ConOut == NULL) { - return (EFI_OUT_OF_RESOURCES); + Status = EFI_OUT_OF_RESOURCES; } + + if (Status == EFI_NOT_FOUND) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle); + } else if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle); + } + return (Status); }