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