]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/Edit.c
ShellPkg: Update Level1 profile commands response output
[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
ecae5117 39 CONST CHAR16 *TempParam;\r
632820d1 40// SHELL_FILE_HANDLE TempHandle;\r
41\r
42 Buffer = NULL;\r
43 ShellStatus = SHELL_SUCCESS;\r
44 Nfs = NULL;\r
45\r
46 //\r
47 // initialize the shell lib (we must be in non-auto-init...)\r
48 //\r
49 Status = ShellInitialize();\r
50 ASSERT_EFI_ERROR(Status);\r
51\r
52 Status = CommandInit();\r
53 ASSERT_EFI_ERROR(Status);\r
54\r
55 //\r
56 // parse the command line\r
57 //\r
58 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);\r
59 if (EFI_ERROR(Status)) {\r
60 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
61 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);\r
62 FreePool(ProblemParam);\r
63 ShellStatus = SHELL_INVALID_PARAMETER;\r
64 } else {\r
65 ASSERT(FALSE);\r
66 }\r
67 } else {\r
68 if (ShellCommandLineGetCount(Package) > 2) {\r
69 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);\r
70 ShellStatus = SHELL_INVALID_PARAMETER;\r
71 } else {\r
72 Cwd = gEfiShellProtocol->GetCurDir(NULL);\r
73 if (Cwd == NULL) {\r
74 Cwd = ShellGetEnvironmentVariable(L"path");\r
75 if (Cwd != NULL) {\r
76 Nfs = StrnCatGrow(&Nfs, NULL, Cwd+3, 0);\r
77 if (Nfs != NULL) {\r
78 Spot = StrStr(Nfs, L";");\r
79 if (Spot != NULL) {\r
80 *Spot = CHAR_NULL;\r
81 }\r
82 Spot = StrStr(Nfs, L"\\");\r
83 if (Spot != NULL) {\r
84 Spot[1] = CHAR_NULL;\r
85 }\r
86 gEfiShellProtocol->SetCurDir(NULL, Nfs);\r
87 FreePool(Nfs);\r
88 } \r
89 }\r
90 }\r
91\r
92 Status = MainEditorInit ();\r
93\r
94 if (EFI_ERROR (Status)) {\r
95 gST->ConOut->ClearScreen (gST->ConOut);\r
96 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
97 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle);\r
98 } else {\r
99 MainEditorBackup ();\r
100\r
101 //\r
102 // if editor launched with file named\r
103 //\r
104 if (ShellCommandLineGetCount(Package) == 2) {\r
ecae5117 105 TempParam = ShellCommandLineGetRawValue(Package, 1);\r
106 ASSERT(TempParam != NULL);\r
107 FileBufferSetFileName (TempParam);\r
632820d1 108// if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {\r
109// Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);\r
110// if (!EFI_ERROR(Status)) {\r
111// ShellCloseFile(&TempHandle);\r
112// }\r
113// }\r
114 }\r
115\r
116 Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE);\r
117 if (!EFI_ERROR (Status)) {\r
118 MainEditorRefresh ();\r
119\r
120 Status = MainEditorKeyInput ();\r
121 }\r
122\r
123 if (Status != EFI_OUT_OF_RESOURCES) {\r
124 //\r
125 // back up the status string\r
126 //\r
127 Buffer = CatSPrint (NULL, L"%s", StatusBarGetString());\r
128 }\r
129\r
130 MainEditorCleanup ();\r
131\r
132 //\r
133 // print editor exit code on screen\r
134 //\r
135 if (Status == EFI_SUCCESS) {\r
136 } else if (Status == EFI_OUT_OF_RESOURCES) {\r
137 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_OUT_MEM), gShellDebug1HiiHandle);\r
138 } else {\r
139 if (Buffer != NULL) {\r
140 if (StrCmp (Buffer, L"") != 0) {\r
141 //\r
142 // print out the status string\r
143 //\r
144 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer);\r
145 } else {\r
146 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);\r
147 }\r
148 } else {\r
149 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);\r
150 }\r
151 }\r
152\r
153 if (Status != EFI_OUT_OF_RESOURCES) {\r
154 SHELL_FREE_NON_NULL (Buffer);\r
155 }\r
156 }\r
157 }\r
158 ShellCommandLineFreeVarList (Package);\r
159 }\r
160 return ShellStatus;\r
161}\r