]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellLevel1CommandsLib/Exit.c
2f2a5bf56580da6b17815affa1108588a941d603
[mirror_edk2.git] / ShellPkg / Library / UefiShellLevel1CommandsLib / Exit.c
1 /** @file
2 Main file for exit shell level 1 function.
3
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "UefiShellLevel1CommandsLib.h"
16
17 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
18 {L"/b", TypeFlag},
19 {NULL, TypeMax}
20 };
21
22 /**
23 Function for 'exit' command.
24
25 @param[in] ImageHandle Handle to the Image (NULL if Internal).
26 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
27 **/
28 SHELL_STATUS
29 EFIAPI
30 ShellCommandRunExit (
31 IN EFI_HANDLE ImageHandle,
32 IN EFI_SYSTEM_TABLE *SystemTable
33 )
34 {
35 EFI_STATUS Status;
36 LIST_ENTRY *Package;
37 CHAR16 *ProblemParam;
38 SHELL_STATUS ShellStatus;
39
40 ShellStatus = SHELL_SUCCESS;
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 //
52 // parse the command line
53 //
54 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
55 if (EFI_ERROR(Status)) {
56 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
57 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel1HiiHandle, ProblemParam);
58 FreePool(ProblemParam);
59 ShellStatus = SHELL_INVALID_PARAMETER;
60 } else {
61 ASSERT(FALSE);
62 }
63 } else {
64
65 //
66 // If we are in a batch file and /b then pass TRUE otherwise false...
67 //
68 ShellCommandRegisterExit((BOOLEAN)(gEfiShellProtocol->BatchIsActive() && ShellCommandLineGetFlag(Package, L"/b")));
69
70 //
71 // return the specified error code
72 //
73 if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
74 ShellStatus = (SHELL_STATUS)(ShellStrToUintn(ShellCommandLineGetRawValue(Package, 1)));
75 }
76
77 ShellCommandLineFreeVarList (Package);
78 }
79 return (ShellStatus);
80 }
81