2 Main file for Edit shell Debug1 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2005 - 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
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.
16 #include "UefiShellDebug1CommandsLib.h"
17 #include "TextEditor.h"
20 Function for 'edit' command.
22 @param[in] ImageHandle Handle to the Image (NULL if Internal).
23 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
28 IN EFI_HANDLE ImageHandle
,
29 IN EFI_SYSTEM_TABLE
*SystemTable
35 SHELL_STATUS ShellStatus
;
40 CONST CHAR16
*TempParam
;
41 // SHELL_FILE_HANDLE TempHandle;
44 ShellStatus
= SHELL_SUCCESS
;
48 // initialize the shell lib (we must be in non-auto-init...)
50 Status
= ShellInitialize();
51 ASSERT_EFI_ERROR(Status
);
53 Status
= CommandInit();
54 ASSERT_EFI_ERROR(Status
);
57 // parse the command line
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
), gShellDebug1HiiHandle
, L
"edit", ProblemParam
);
63 FreePool(ProblemParam
);
64 ShellStatus
= SHELL_INVALID_PARAMETER
;
69 if (ShellCommandLineGetCount(Package
) > 2) {
70 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"edit");
71 ShellStatus
= SHELL_INVALID_PARAMETER
;
73 Cwd
= gEfiShellProtocol
->GetCurDir(NULL
);
75 Cwd
= ShellGetEnvironmentVariable(L
"path");
77 Nfs
= StrnCatGrow(&Nfs
, NULL
, Cwd
+3, 0);
79 Spot
= StrStr(Nfs
, L
";");
83 Spot
= StrStr(Nfs
, L
"\\");
87 gEfiShellProtocol
->SetCurDir(NULL
, Nfs
);
93 Status
= MainEditorInit ();
95 if (EFI_ERROR (Status
)) {
96 gST
->ConOut
->ClearScreen (gST
->ConOut
);
97 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
98 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_INIT_FAILED
), gShellDebug1HiiHandle
);
103 // if editor launched with file named
105 if (ShellCommandLineGetCount(Package
) == 2) {
106 TempParam
= ShellCommandLineGetRawValue(Package
, 1);
107 ASSERT(TempParam
!= NULL
);
108 FileBufferSetFileName (TempParam
);
109 // if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
110 // Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
111 // if (!EFI_ERROR(Status)) {
112 // ShellCloseFile(&TempHandle);
117 Status
= FileBufferRead (MainEditor
.FileBuffer
->FileName
, FALSE
);
118 if (!EFI_ERROR (Status
)) {
119 MainEditorRefresh ();
121 Status
= MainEditorKeyInput ();
124 if (Status
!= EFI_OUT_OF_RESOURCES
) {
126 // back up the status string
128 Buffer
= CatSPrint (NULL
, L
"%s", StatusBarGetString());
131 MainEditorCleanup ();
134 // print editor exit code on screen
136 if (Status
== EFI_SUCCESS
) {
137 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
138 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
, L
"edit");
140 if (Buffer
!= NULL
) {
141 if (StrCmp (Buffer
, L
"") != 0) {
143 // print out the status string
145 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_BUFFER
), gShellDebug1HiiHandle
, Buffer
);
147 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR
), gShellDebug1HiiHandle
);
150 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR
), gShellDebug1HiiHandle
);
154 if (Status
!= EFI_OUT_OF_RESOURCES
) {
155 SHELL_FREE_NON_NULL (Buffer
);
159 ShellCommandLineFreeVarList (Package
);