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 CONST CHAR16
*TempParam
;
40 // SHELL_FILE_HANDLE TempHandle;
43 ShellStatus
= SHELL_SUCCESS
;
47 // initialize the shell lib (we must be in non-auto-init...)
49 Status
= ShellInitialize();
50 ASSERT_EFI_ERROR(Status
);
52 Status
= CommandInit();
53 ASSERT_EFI_ERROR(Status
);
56 // parse the command line
58 Status
= ShellCommandLineParse (EmptyParamList
, &Package
, &ProblemParam
, TRUE
);
59 if (EFI_ERROR(Status
)) {
60 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
61 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_PROBLEM
), gShellDebug1HiiHandle
, ProblemParam
);
62 FreePool(ProblemParam
);
63 ShellStatus
= SHELL_INVALID_PARAMETER
;
68 if (ShellCommandLineGetCount(Package
) > 2) {
69 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
);
70 ShellStatus
= SHELL_INVALID_PARAMETER
;
72 Cwd
= gEfiShellProtocol
->GetCurDir(NULL
);
74 Cwd
= ShellGetEnvironmentVariable(L
"path");
76 Nfs
= StrnCatGrow(&Nfs
, NULL
, Cwd
+3, 0);
78 Spot
= StrStr(Nfs
, L
";");
82 Spot
= StrStr(Nfs
, L
"\\");
86 gEfiShellProtocol
->SetCurDir(NULL
, Nfs
);
92 Status
= MainEditorInit ();
94 if (EFI_ERROR (Status
)) {
95 gST
->ConOut
->ClearScreen (gST
->ConOut
);
96 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
97 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_INIT_FAILED
), gShellDebug1HiiHandle
);
102 // if editor launched with file named
104 if (ShellCommandLineGetCount(Package
) == 2) {
105 TempParam
= ShellCommandLineGetRawValue(Package
, 1);
106 ASSERT(TempParam
!= NULL
);
107 FileBufferSetFileName (TempParam
);
108 // if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
109 // Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
110 // if (!EFI_ERROR(Status)) {
111 // ShellCloseFile(&TempHandle);
116 Status
= FileBufferRead (MainEditor
.FileBuffer
->FileName
, FALSE
);
117 if (!EFI_ERROR (Status
)) {
118 MainEditorRefresh ();
120 Status
= MainEditorKeyInput ();
123 if (Status
!= EFI_OUT_OF_RESOURCES
) {
125 // back up the status string
127 Buffer
= CatSPrint (NULL
, L
"%s", StatusBarGetString());
130 MainEditorCleanup ();
133 // print editor exit code on screen
135 if (Status
== EFI_SUCCESS
) {
136 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
137 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
);
139 if (Buffer
!= NULL
) {
140 if (StrCmp (Buffer
, L
"") != 0) {
142 // print out the status string
144 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_BUFFER
), gShellDebug1HiiHandle
, Buffer
);
146 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR
), gShellDebug1HiiHandle
);
149 ShellPrintHiiEx(-1, -1, NULL
, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR
), gShellDebug1HiiHandle
);
153 if (Status
!= EFI_OUT_OF_RESOURCES
) {
154 SHELL_FREE_NON_NULL (Buffer
);
158 ShellCommandLineFreeVarList (Package
);