]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c
Revert last patch about "Modal form" opcode support.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Edit / Edit.c
CommitLineData
632820d1 1/** @file\r
2 Main file for Edit shell Debug1 function.\r
3\r
4 Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "UefiShellDebug1CommandsLib.h"\r
16#include "TextEditor.h"\r
17\r
18/**\r
19 Function for 'edit' command.\r
20\r
21 @param[in] ImageHandle Handle to the Image (NULL if Internal).\r
22 @param[in] SystemTable Pointer to the System Table (NULL if Internal).\r
23**/\r
24SHELL_STATUS\r
25EFIAPI\r
26ShellCommandRunEdit (\r
27 IN EFI_HANDLE ImageHandle,\r
28 IN EFI_SYSTEM_TABLE *SystemTable\r
29 )\r
30{\r
31 EFI_STATUS Status;\r
32 CHAR16 *Buffer;\r
33 CHAR16 *ProblemParam;\r
34 SHELL_STATUS ShellStatus;\r
35 LIST_ENTRY *Package;\r
36 CONST CHAR16 *Cwd;\r
37 CHAR16 *Nfs;\r
38 CHAR16 *Spot;\r
39// SHELL_FILE_HANDLE TempHandle;\r
40\r
41 Buffer = NULL;\r
42 ShellStatus = SHELL_SUCCESS;\r
43 Nfs = NULL;\r
44\r
45 //\r
46 // initialize the shell lib (we must be in non-auto-init...)\r
47 //\r
48 Status = ShellInitialize();\r
49 ASSERT_EFI_ERROR(Status);\r
50\r
51 Status = CommandInit();\r
52 ASSERT_EFI_ERROR(Status);\r
53\r
54 //\r
55 // parse the command line\r
56 //\r
57 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r
58 if (EFI_ERROR(Status)) {\r
59 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
60 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);\r
61 FreePool(ProblemParam);\r
62 ShellStatus = SHELL_INVALID_PARAMETER;\r
63 } else {\r
64 ASSERT(FALSE);\r
65 }\r
66 } else {\r
67 if (ShellCommandLineGetCount(Package) > 2) {\r
68 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
69 ShellStatus = SHELL_INVALID_PARAMETER;\r
70 } else {\r
71 Cwd = gEfiShellProtocol->GetCurDir(NULL);\r
72 if (Cwd == NULL) {\r
73 Cwd = ShellGetEnvironmentVariable(L"path");\r
74 if (Cwd != NULL) {\r
75 Nfs = StrnCatGrow(&Nfs, NULL, Cwd+3, 0);\r
76 if (Nfs != NULL) {\r
77 Spot = StrStr(Nfs, L";");\r
78 if (Spot != NULL) {\r
79 *Spot = CHAR_NULL;\r
80 }\r
81 Spot = StrStr(Nfs, L"\\");\r
82 if (Spot != NULL) {\r
83 Spot[1] = CHAR_NULL;\r
84 }\r
85 gEfiShellProtocol->SetCurDir(NULL, Nfs);\r
86 FreePool(Nfs);\r
87 } \r
88 }\r
89 }\r
90\r
91 Status = MainEditorInit ();\r
92\r
93 if (EFI_ERROR (Status)) {\r
94 gST->ConOut->ClearScreen (gST->ConOut);\r
95 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
96 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle);\r
97 } else {\r
98 MainEditorBackup ();\r
99\r
100 //\r
101 // if editor launched with file named\r
102 //\r
103 if (ShellCommandLineGetCount(Package) == 2) {\r
104 FileBufferSetFileName (ShellCommandLineGetRawValue(Package, 1));\r
105// if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {\r
106// Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);\r
107// if (!EFI_ERROR(Status)) {\r
108// ShellCloseFile(&TempHandle);\r
109// }\r
110// }\r
111 }\r
112\r
113 Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE);\r
114 if (!EFI_ERROR (Status)) {\r
115 MainEditorRefresh ();\r
116\r
117 Status = MainEditorKeyInput ();\r
118 }\r
119\r
120 if (Status != EFI_OUT_OF_RESOURCES) {\r
121 //\r
122 // back up the status string\r
123 //\r
124 Buffer = CatSPrint (NULL, L"%s", StatusBarGetString());\r
125 }\r
126\r
127 MainEditorCleanup ();\r
128\r
129 //\r
130 // print editor exit code on screen\r
131 //\r
132 if (Status == EFI_SUCCESS) {\r
133 } else if (Status == EFI_OUT_OF_RESOURCES) {\r
134 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_OUT_MEM), gShellDebug1HiiHandle);\r
135 } else {\r
136 if (Buffer != NULL) {\r
137 if (StrCmp (Buffer, L"") != 0) {\r
138 //\r
139 // print out the status string\r
140 //\r
141 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer);\r
142 } else {\r
143 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);\r
144 }\r
145 } else {\r
146 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);\r
147 }\r
148 }\r
149\r
150 if (Status != EFI_OUT_OF_RESOURCES) {\r
151 SHELL_FREE_NON_NULL (Buffer);\r
152 }\r
153 }\r
154 }\r
155 ShellCommandLineFreeVarList (Package);\r
156 }\r
157 return ShellStatus;\r
158}\r