Home | History | Annotate | Download | only in UefiShellLevel1CommandsLib
      1 /** @file
      2   Main file for goto shell level 1 function.
      3 
      4   (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
      5   Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
      6   This program and the accompanying materials
      7   are licensed and made available under the terms and conditions of the BSD License
      8   which accompanies this distribution.  The full text of the license may be found at
      9   http://opensource.org/licenses/bsd-license.php
     10 
     11   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #include "UefiShellLevel1CommandsLib.h"
     17 
     18 /**
     19   Function for 'goto' command.
     20 
     21   @param[in] ImageHandle  Handle to the Image (NULL if Internal).
     22   @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
     23 **/
     24 SHELL_STATUS
     25 EFIAPI
     26 ShellCommandRunGoto (
     27   IN EFI_HANDLE        ImageHandle,
     28   IN EFI_SYSTEM_TABLE  *SystemTable
     29   )
     30 {
     31   EFI_STATUS          Status;
     32   LIST_ENTRY          *Package;
     33   CHAR16              *ProblemParam;
     34   SHELL_STATUS        ShellStatus;
     35   CHAR16              *CompareString;
     36   UINTN               Size;
     37   SCRIPT_FILE         *CurrentScriptFile;
     38 
     39   ShellStatus         = SHELL_SUCCESS;
     40   CompareString       = NULL;
     41 
     42   //
     43   // initialize the shell lib (we must be in non-auto-init...)
     44   //
     45   Status = ShellInitialize();
     46   ASSERT_EFI_ERROR(Status);
     47 
     48   Status = CommandInit();
     49   ASSERT_EFI_ERROR(Status);
     50 
     51   if (!gEfiShellProtocol->BatchIsActive()) {
     52     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"Goto");
     53     return (SHELL_UNSUPPORTED);
     54   }
     55 
     56   //
     57   // parse the command line
     58   //
     59   Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
     60   if (EFI_ERROR(Status)) {
     61     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
     62       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, L"goto", ProblemParam);
     63       FreePool(ProblemParam);
     64       ShellStatus = SHELL_INVALID_PARAMETER;
     65     } else {
     66       ASSERT(FALSE);
     67     }
     68   } else {
     69     if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
     70       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel1HiiHandle, L"goto");
     71       ShellStatus = SHELL_INVALID_PARAMETER;
     72     } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
     73       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"goto");
     74       ShellStatus = SHELL_INVALID_PARAMETER;
     75     } else {
     76       Size = 0;
     77       ASSERT((CompareString == NULL && Size == 0) || (CompareString != NULL));
     78       CompareString = StrnCatGrow(&CompareString, &Size, L":", 0);
     79       CompareString = StrnCatGrow(&CompareString, &Size, ShellCommandLineGetRawValue(Package, 1), 0);
     80       //
     81       // Check forwards and then backwards for a label...
     82       //
     83       if (!MoveToTag(GetNextNode, L"endfor", L"for", CompareString, ShellCommandGetCurrentScriptFile(), FALSE, FALSE, TRUE)) {
     84         CurrentScriptFile = ShellCommandGetCurrentScriptFile();
     85         ShellPrintHiiEx(
     86           -1,
     87           -1,
     88           NULL,
     89           STRING_TOKEN (STR_SYNTAX_NO_MATCHING),
     90           gShellLevel1HiiHandle,
     91           CompareString,
     92           L"Goto",
     93           CurrentScriptFile!=NULL
     94             && CurrentScriptFile->CurrentCommand!=NULL
     95             ? CurrentScriptFile->CurrentCommand->Line:0);
     96         ShellStatus = SHELL_NOT_FOUND;
     97       }
     98     FreePool(CompareString);
     99     }
    100     ShellCommandLineFreeVarList (Package);
    101   }
    102 
    103   return (ShellStatus);
    104 }
    105 
    106