TianoCore EDK2 master
Loading...
Searching...
No Matches
Edit.c
Go to the documentation of this file.
1
11#include "TextEditor.h"
12
20EFIAPI
22 IN EFI_HANDLE ImageHandle,
23 IN EFI_SYSTEM_TABLE *SystemTable
24 )
25{
26 EFI_STATUS Status;
27 CHAR16 *Buffer;
28 CHAR16 *ProblemParam;
29 SHELL_STATUS ShellStatus;
30 LIST_ENTRY *Package;
31 CONST CHAR16 *Cwd;
32 CHAR16 *Nfs;
33 CHAR16 *Spot;
34 CONST CHAR16 *TempParam;
35
36 // SHELL_FILE_HANDLE TempHandle;
37
38 Buffer = NULL;
39 ShellStatus = SHELL_SUCCESS;
40 Nfs = NULL;
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 (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;
60 } else {
61 ASSERT (FALSE);
62 }
63 } else {
64 if (ShellCommandLineGetCount (Package) > 2) {
65 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"edit");
66 ShellStatus = SHELL_INVALID_PARAMETER;
67 } else {
68 Cwd = gEfiShellProtocol->GetCurDir (NULL);
69 if (Cwd == NULL) {
70 Cwd = ShellGetEnvironmentVariable (L"path");
71 if (Cwd != NULL) {
72 Nfs = StrnCatGrow (&Nfs, NULL, Cwd+3, 0);
73 if (Nfs != NULL) {
74 Spot = StrStr (Nfs, L";");
75 if (Spot != NULL) {
76 *Spot = CHAR_NULL;
77 }
78
79 Spot = StrStr (Nfs, L"\\");
80 if (Spot != NULL) {
81 Spot[1] = CHAR_NULL;
82 }
83
84 gEfiShellProtocol->SetCurDir (NULL, Nfs);
85 FreePool (Nfs);
86 }
87 }
88 }
89
90 Status = MainEditorInit ();
91
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);
96 } else {
98
99 //
100 // if editor launched with file named
101 //
102 if (ShellCommandLineGetCount (Package) == 2) {
103 TempParam = ShellCommandLineGetRawValue (Package, 1);
104 if (TempParam == NULL) {
105 ASSERT (TempParam != NULL);
106 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellDebug1HiiHandle, L"edit");
107 ShellStatus = SHELL_INVALID_PARAMETER;
108 } else {
109 FileBufferSetFileName (TempParam);
110 }
111
112 // if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
113 // Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
114 // if (!EFI_ERROR(Status)) {
115 // ShellCloseFile(&TempHandle);
116 // }
117 // }
118 }
119
120 Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE);
121 if (!EFI_ERROR (Status)) {
123
124 Status = MainEditorKeyInput ();
125 }
126
127 if (Status != EFI_OUT_OF_RESOURCES) {
128 //
129 // back up the status string
130 //
131 Buffer = CatSPrint (NULL, L"%s", StatusBarGetString ());
132 }
133
135
136 //
137 // print editor exit code on screen
138 //
139 if (Status == EFI_SUCCESS) {
140 } else if (Status == EFI_OUT_OF_RESOURCES) {
141 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"edit");
142 } else {
143 if (Buffer != NULL) {
144 if (StrCmp (Buffer, L"") != 0) {
145 //
146 // print out the status string
147 //
148 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer);
149 } else {
150 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);
151 }
152 } else {
153 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);
154 }
155 }
156
157 if (Status != EFI_OUT_OF_RESOURCES) {
158 SHELL_FREE_NON_NULL (Buffer);
159 }
160 }
161 }
162
164 }
165
166 return ShellStatus;
167}
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
SHELL_STATUS EFIAPI ShellCommandRunEdit(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: Edit.c:21
CONST CHAR16 * StatusBarGetString(VOID)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS FileBufferRead(IN CONST CHAR16 *FileName, IN CONST BOOLEAN Recover)
Definition: FileBuffer.c:777
EFI_STATUS FileBufferSetFileName(IN CONST CHAR16 *Str)
Definition: FileBuffer.c:719
EFI_STATUS MainEditorBackup(VOID)
EFI_STATUS MainEditorCleanup(VOID)
EFI_STATUS MainEditorInit(VOID)
EFI_STATUS MainEditorKeyInput(VOID)
VOID MainEditorRefresh(VOID)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
SHELL_STATUS
Definition: Shell.h:21
@ SHELL_SUCCESS
Definition: Shell.h:25
@ SHELL_INVALID_PARAMETER
Definition: Shell.h:35
EFI_STATUS EFIAPI CommandInit(VOID)
#define ShellCommandLineParse(CheckList, CheckPackage, ProblemParam, AutoPageBreak)
Make it easy to upgrade from older versions of the shell library.
Definition: ShellLib.h:755
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
CONST CHAR16 *EFIAPI ShellGetEnvironmentVariable(IN CONST CHAR16 *EnvKey)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
SHELL_PARAM_ITEM EmptyParamList[]
Helper structure for no parameters (besides -? and -b)
Definition: UefiShellLib.c:19
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
#define STRING_TOKEN(t)
CHAR16 *EFIAPI CatSPrint(IN CHAR16 *String OPTIONAL, IN CONST CHAR16 *FormatString,...)
Definition: UefiLibPrint.c:827
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064