2 Main file for Edit shell Debug1 function.
4 Copyright (c) 2005 - 2011, 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
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.
15 #include "UefiShellDebug1CommandsLib.h"
16 #include "TextEditor.h"
19 Function for 'edit' command.
21 @param[in] ImageHandle Handle to the Image (NULL if Internal).
22 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
27 IN EFI_HANDLE ImageHandle
,
28 IN EFI_SYSTEM_TABLE
*SystemTable
34 SHELL_STATUS ShellStatus
;
39 // SHELL_FILE_HANDLE TempHandle;
42 ShellStatus
= SHELL_SUCCESS
;
46 // initialize the shell lib (we must be in non-auto-init...)
48 Status
= ShellInitialize();
49 ASSERT_EFI_ERROR(Status
);
51 Status
= CommandInit();
52 ASSERT_EFI_ERROR(Status
);
55 // parse the command line
57 Status
= ShellCommandLineParse (EmptyParamList
, &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
), gShellDebug1HiiHandle
, ProblemParam
);
61 FreePool(ProblemParam
);
62 ShellStatus
= SHELL_INVALID_PARAMETER
;
67 if (ShellCommandLineGetCount(Package
) > 2) {
68 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
69 ShellStatus
= SHELL_INVALID_PARAMETER
;
71 Cwd
= gEfiShellProtocol
->GetCurDir(NULL
);
73 Cwd
= ShellGetEnvironmentVariable(L
"path");
75 Nfs
= StrnCatGrow(&Nfs
, NULL
, Cwd
+3, 0);
77 Spot
= StrStr(Nfs
, L
";");
81 Spot
= StrStr(Nfs
, L
"\\");
85 gEfiShellProtocol
->SetCurDir(NULL
, Nfs
);
91 Status
= MainEditorInit ();
93 if (EFI_ERROR (Status
)) {
94 gST
->ConOut
->ClearScreen (gST
->ConOut
);
95 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
96 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_INIT_FAILED
), gShellDebug1HiiHandle
);
101 // if editor launched with file named
103 if (ShellCommandLineGetCount(Package
) == 2) {
104 FileBufferSetFileName (ShellCommandLineGetRawValue(Package
, 1));
105 // if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
106 // Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
107 // if (!EFI_ERROR(Status)) {
108 // ShellCloseFile(&TempHandle);
113 Status
= FileBufferRead (MainEditor
.FileBuffer
->FileName
, FALSE
);
114 if (!EFI_ERROR (Status
)) {
115 MainEditorRefresh ();
117 Status
= MainEditorKeyInput ();
120 if (Status
!= EFI_OUT_OF_RESOURCES
) {
122 // back up the status string
124 Buffer
= CatSPrint (NULL
, L
"%s", StatusBarGetString());
127 MainEditorCleanup ();
130 // print editor exit code on screen
132 if (Status
== EFI_SUCCESS
) {
133 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
134 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
);
136 if (Buffer
!= NULL
) {
137 if (StrCmp (Buffer
, L
"") != 0) {
139 // print out the status string
141 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_BUFFER
), gShellDebug1HiiHandle
, Buffer
);
143 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR
), gShellDebug1HiiHandle
);
146 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR
), gShellDebug1HiiHandle
);
150 if (Status
!= EFI_OUT_OF_RESOURCES
) {
151 SHELL_FREE_NON_NULL (Buffer
);
155 ShellCommandLineFreeVarList (Package
);