4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/** @file
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Main file for goto shell level 1 function.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This program and the accompanying materials
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync are licensed and made available under the terms and conditions of the BSD License
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync which accompanies this distribution. The full text of the license may be found at
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync http://opensource.org/licenses/bsd-license.php
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync**/
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include "UefiShellLevel1CommandsLib.h"
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/**
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Function for 'goto' command.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] ImageHandle Handle to the Image (NULL if Internal).
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] SystemTable Pointer to the System Table (NULL if Internal).
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync**/
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncSHELL_STATUS
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncEFIAPI
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncShellCommandRunGoto (
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IN EFI_HANDLE ImageHandle,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync IN EFI_SYSTEM_TABLE *SystemTable
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync )
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync{
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync EFI_STATUS Status;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync LIST_ENTRY *Package;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CHAR16 *ProblemParam;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SHELL_STATUS ShellStatus;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CHAR16 *CompareString;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync UINTN Size;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync SCRIPT_FILE *CurrentScriptFile;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellStatus = SHELL_SUCCESS;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CompareString = NULL;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync //
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // initialize the shell lib (we must be in non-auto-init...)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync //
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = ShellInitialize();
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ASSERT_EFI_ERROR(Status);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = CommandInit();
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ASSERT_EFI_ERROR(Status);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (!gEfiShellProtocol->BatchIsActive()) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync return (SHELL_UNSUPPORTED);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync }
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync //
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // parse the command line
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync //
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (EFI_ERROR(Status)) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync FreePool(ProblemParam);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellStatus = SHELL_INVALID_PARAMETER;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync } else {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ASSERT(FALSE);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync }
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync } else {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellStatus = SHELL_INVALID_PARAMETER;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellStatus = SHELL_INVALID_PARAMETER;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync } else {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Size = 0;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CompareString = StrnCatGrow(&CompareString, &Size, L":", 0);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync //
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Check forwards and then backwards for a label...
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync //
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CurrentScriptFile = ShellCommandGetCurrentScriptFile();
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellPrintHiiEx(
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync -1,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync -1,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync NULL,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync gShellLevel1HiiHandle,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CompareString,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync L"Goto",
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync CurrentScriptFile!=NULL
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync && CurrentScriptFile->CurrentCommand!=NULL
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ? CurrentScriptFile->CurrentCommand->Line:0);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellStatus = SHELL_NOT_FOUND;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync }
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync FreePool(CompareString);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync }
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync ShellCommandLineFreeVarList (Package);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync }
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync return (ShellStatus);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync}
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync