• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   Main file for Shift 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 'shift' 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
ShellCommandRunShift(IN EFI_HANDLE ImageHandle,IN EFI_SYSTEM_TABLE * SystemTable)26 ShellCommandRunShift (
27   IN EFI_HANDLE        ImageHandle,
28   IN EFI_SYSTEM_TABLE  *SystemTable
29   )
30 {
31   EFI_STATUS          Status;
32   SCRIPT_FILE         *CurrentScriptFile;
33   UINTN               LoopVar;
34 
35   Status = CommandInit();
36   ASSERT_EFI_ERROR(Status);
37 
38   if (!gEfiShellProtocol->BatchIsActive()) {
39     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"shift");
40     return (SHELL_UNSUPPORTED);
41   }
42 
43   CurrentScriptFile = ShellCommandGetCurrentScriptFile();
44   ASSERT(CurrentScriptFile != NULL);
45 
46   if (CurrentScriptFile->Argc < 2) {
47     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle, L"shift");
48     return (SHELL_UNSUPPORTED);
49   }
50 
51   for (LoopVar = 0 ; LoopVar < CurrentScriptFile->Argc ; LoopVar++) {
52     if (LoopVar == 0) {
53       SHELL_FREE_NON_NULL(CurrentScriptFile->Argv[LoopVar]);
54     }
55     if (LoopVar < CurrentScriptFile->Argc -1) {
56       CurrentScriptFile->Argv[LoopVar] = CurrentScriptFile->Argv[LoopVar+1];
57     } else {
58       CurrentScriptFile->Argv[LoopVar] = NULL;
59     }
60   }
61   CurrentScriptFile->Argc--;
62   return (SHELL_SUCCESS);
63 }
64 
65