2 Main file for Edit shell Debug1 function.
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved. <BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "UefiShellDebug1CommandsLib.h"
11 #include "TextEditor.h"
14 Function for 'edit' command.
16 @param[in] ImageHandle Handle to the Image (NULL if Internal).
17 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
22 IN EFI_HANDLE ImageHandle
,
23 IN EFI_SYSTEM_TABLE
*SystemTable
29 SHELL_STATUS ShellStatus
;
34 CONST CHAR16
*TempParam
;
36 // SHELL_FILE_HANDLE TempHandle;
39 ShellStatus
= SHELL_SUCCESS
;
43 // initialize the shell lib (we must be in non-auto-init...)
45 Status
= ShellInitialize ();
46 ASSERT_EFI_ERROR (Status
);
48 Status
= CommandInit ();
49 ASSERT_EFI_ERROR (Status
);
52 // parse the command line
54 Status
= ShellCommandLineParse (EmptyParamList
, &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
), gShellDebug1HiiHandle
, L
"edit", ProblemParam
);
58 FreePool (ProblemParam
);
59 ShellStatus
= SHELL_INVALID_PARAMETER
;
64 if (ShellCommandLineGetCount (Package
) > 2) {
65 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_TOO_MANY
), gShellDebug1HiiHandle
, L
"edit");
66 ShellStatus
= SHELL_INVALID_PARAMETER
;
68 Cwd
= gEfiShellProtocol
->GetCurDir (NULL
);
70 Cwd
= ShellGetEnvironmentVariable (L
"path");
72 Nfs
= StrnCatGrow (&Nfs
, NULL
, Cwd
+3, 0);
74 Spot
= StrStr (Nfs
, L
";");
79 Spot
= StrStr (Nfs
, L
"\\");
84 gEfiShellProtocol
->SetCurDir (NULL
, Nfs
);
90 Status
= MainEditorInit ();
92 if (EFI_ERROR (Status
)) {
93 gST
->ConOut
->ClearScreen (gST
->ConOut
);
94 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
95 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_EDIT_MAIN_INIT_FAILED
), gShellDebug1HiiHandle
);
100 // if editor launched with file named
102 if (ShellCommandLineGetCount (Package
) == 2) {
103 TempParam
= ShellCommandLineGetRawValue (Package
, 1);
104 ASSERT (TempParam
!= NULL
);
105 FileBufferSetFileName (TempParam
);
106 // if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
107 // Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
108 // if (!EFI_ERROR(Status)) {
109 // ShellCloseFile(&TempHandle);
114 Status
= FileBufferRead (MainEditor
.FileBuffer
->FileName
, FALSE
);
115 if (!EFI_ERROR (Status
)) {
116 MainEditorRefresh ();
118 Status
= MainEditorKeyInput ();
121 if (Status
!= EFI_OUT_OF_RESOURCES
) {
123 // back up the status string
125 Buffer
= CatSPrint (NULL
, L
"%s", StatusBarGetString ());
128 MainEditorCleanup ();
131 // print editor exit code on screen
133 if (Status
== EFI_SUCCESS
) {
134 } else if (Status
== EFI_OUT_OF_RESOURCES
) {
135 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_GEN_OUT_MEM
), gShellDebug1HiiHandle
, L
"edit");
137 if (Buffer
!= NULL
) {
138 if (StrCmp (Buffer
, L
"") != 0) {
140 // print out the status string
142 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_EDIT_MAIN_BUFFER
), gShellDebug1HiiHandle
, Buffer
);
144 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR
), gShellDebug1HiiHandle
);
147 ShellPrintHiiEx (-1, -1, NULL
, STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR
), gShellDebug1HiiHandle
);
151 if (Status
!= EFI_OUT_OF_RESOURCES
) {
152 SHELL_FREE_NON_NULL (Buffer
);
157 ShellCommandLineFreeVarList (Package
);