Vishal Bhoj | 82c8071 | 2015-12-15 21:13:33 +0530 | [diff] [blame^] | 1 | /** @file
|
| 2 | Main file for exit shell level 1 function.
|
| 3 |
|
| 4 | (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
|
| 5 | Copyright (c) 2009 - 2011, 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 | STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
|
| 19 | {L"/b", TypeFlag},
|
| 20 | {NULL, TypeMax}
|
| 21 | };
|
| 22 |
|
| 23 | /**
|
| 24 | Function for 'exit' command.
|
| 25 |
|
| 26 | @param[in] ImageHandle Handle to the Image (NULL if Internal).
|
| 27 | @param[in] SystemTable Pointer to the System Table (NULL if Internal).
|
| 28 | **/
|
| 29 | SHELL_STATUS
|
| 30 | EFIAPI
|
| 31 | ShellCommandRunExit (
|
| 32 | IN EFI_HANDLE ImageHandle,
|
| 33 | IN EFI_SYSTEM_TABLE *SystemTable
|
| 34 | )
|
| 35 | {
|
| 36 | EFI_STATUS Status;
|
| 37 | LIST_ENTRY *Package;
|
| 38 | CHAR16 *ProblemParam;
|
| 39 | SHELL_STATUS ShellStatus;
|
| 40 | UINT64 RetVal;
|
| 41 | CONST CHAR16 *Return;
|
| 42 |
|
| 43 | ShellStatus = SHELL_SUCCESS;
|
| 44 |
|
| 45 | //
|
| 46 | // initialize the shell lib (we must be in non-auto-init...)
|
| 47 | //
|
| 48 | Status = ShellInitialize();
|
| 49 | ASSERT_EFI_ERROR(Status);
|
| 50 |
|
| 51 | Status = CommandInit();
|
| 52 | ASSERT_EFI_ERROR(Status);
|
| 53 |
|
| 54 | //
|
| 55 | // parse the command line
|
| 56 | //
|
| 57 | Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
|
| 58 | if (EFI_ERROR(Status)) {
|
| 59 | if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
|
| 60 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, L"exit", ProblemParam);
|
| 61 | FreePool(ProblemParam);
|
| 62 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 63 | } else {
|
| 64 | ASSERT(FALSE);
|
| 65 | }
|
| 66 | } else {
|
| 67 |
|
| 68 | //
|
| 69 | // return the specified error code
|
| 70 | //
|
| 71 | Return = ShellCommandLineGetRawValue(Package, 1);
|
| 72 | if (Return != NULL) {
|
| 73 | Status = ShellConvertStringToUint64(Return, &RetVal, FALSE, FALSE);
|
| 74 | if (EFI_ERROR(Status)) {
|
| 75 | ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel1HiiHandle, L"exit", Return);
|
| 76 | ShellStatus = SHELL_INVALID_PARAMETER;
|
| 77 | } else {
|
| 78 | //
|
| 79 | // If we are in a batch file and /b then pass TRUE otherwise false...
|
| 80 | //
|
| 81 | ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), RetVal);
|
| 82 |
|
| 83 | ShellStatus = SHELL_SUCCESS;
|
| 84 | }
|
| 85 | } else {
|
| 86 | // If we are in a batch file and /b then pass TRUE otherwise false...
|
| 87 | //
|
| 88 | ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")), 0);
|
| 89 |
|
| 90 | ShellStatus = SHELL_SUCCESS;
|
| 91 | }
|
| 92 |
|
| 93 | ShellCommandLineFreeVarList (Package);
|
| 94 | }
|
| 95 | return (ShellStatus);
|
| 96 | }
|
| 97 |
|