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