50BOOLEAN FileBufferNeedRefresh;
55BOOLEAN FileBufferOnlyLineNeedRefresh;
57BOOLEAN FileBufferMouseNeedRefresh;
59extern BOOLEAN EditorMouseAction;
83 if (FileBuffer.FileName ==
NULL) {
84 return EFI_LOAD_ERROR;
88 if (FileBuffer.ListHead ==
NULL) {
89 return EFI_OUT_OF_RESOURCES;
94 FileBuffer.DisplayPosition.Row = 2;
95 FileBuffer.DisplayPosition.Column = 1;
96 FileBuffer.LowVisibleRange.Row = 2;
97 FileBuffer.LowVisibleRange.Column = 1;
99 FileBufferNeedRefresh =
FALSE;
100 FileBufferMouseNeedRefresh =
FALSE;
101 FileBufferOnlyLineNeedRefresh =
FALSE;
121 FileBufferBackupVar.MousePosition = FileBuffer.MousePosition;
123 SHELL_FREE_NON_NULL (FileBufferBackupVar.FileName);
124 FileBufferBackupVar.FileName =
NULL;
125 FileBufferBackupVar.FileName =
StrnCatGrow (&FileBufferBackupVar.FileName,
NULL, FileBuffer.FileName, 0);
127 FileBufferBackupVar.ModeInsert = FileBuffer.ModeInsert;
128 FileBufferBackupVar.FileType = FileBuffer.FileType;
130 FileBufferBackupVar.FilePosition = FileBuffer.FilePosition;
131 FileBufferBackupVar.LowVisibleRange = FileBuffer.LowVisibleRange;
133 FileBufferBackupVar.FileModified = FileBuffer.FileModified;
134 FileBufferBackupVar.ReadOnly = FileBuffer.ReadOnly;
160 if ((CurrentLine ==
NULL) || (LineList ==
NULL)) {
164 for (Line = CurrentLine, Index = 0; Index < Count; Index++) {
168 if (Line->Link.ForwardLink == LineList) {
199 if ((CurrentLine ==
NULL) || (LineList ==
NULL)) {
203 for (Line = CurrentLine, Index = 0; Index < Count; Index++) {
207 if (Line->Link.BackLink == LineList) {
263 BOOLEAN HasCharacter;
273 if (MainEditor.MouseSupported) {
274 if (FileBufferMouseNeedRefresh) {
275 FileBufferMouseNeedRefresh =
FALSE;
281 if ( ((FileBuffer.MousePosition.Row == FileBufferBackupVar.MousePosition.Row) &&
282 (FileBuffer.MousePosition.Column == FileBufferBackupVar.MousePosition.Column))
283 && EditorMouseAction)
291 Orig = MainEditor.ColorAttributes;
293 New.Colors.Foreground = Orig.Colors.Background & 0xF;
294 New.Colors.Background = Orig.Colors.Foreground & 0x7;
299 FRow = FileBuffer.LowVisibleRange.Row + FileBufferBackupVar.MousePosition.Row - 2;
301 FColumn = FileBuffer.LowVisibleRange.Column + FileBufferBackupVar.MousePosition.Column - 1;
304 if (FRow > FileBuffer.NumLines) {
305 HasCharacter =
FALSE;
307 CurrentLine = FileBuffer.CurrentLine;
308 Line =
MoveLine (FRow - FileBuffer.FilePosition.Row);
310 if ((Line ==
NULL) || (FColumn > Line->Size)) {
311 HasCharacter =
FALSE;
314 FileBuffer.CurrentLine = CurrentLine;
318 (INT32)FileBufferBackupVar.MousePosition.Column - 1,
319 (INT32)FileBufferBackupVar.MousePosition.Row - 1,
324 Value = (Line->Buffer[FColumn - 1]);
326 (INT32)FileBufferBackupVar.MousePosition.Column - 1,
327 (INT32)FileBufferBackupVar.MousePosition.Row - 1,
341 FRow = FileBuffer.LowVisibleRange.Row + FileBuffer.MousePosition.Row - 2;
342 FColumn = FileBuffer.LowVisibleRange.Column + FileBuffer.MousePosition.Column - 1;
345 if (FRow > FileBuffer.NumLines) {
346 HasCharacter =
FALSE;
348 CurrentLine = FileBuffer.CurrentLine;
349 Line =
MoveLine (FRow - FileBuffer.FilePosition.Row);
351 if ((Line ==
NULL) || (FColumn > Line->Size)) {
352 HasCharacter =
FALSE;
355 FileBuffer.CurrentLine = CurrentLine;
359 (INT32)FileBuffer.MousePosition.Column - 1,
360 (INT32)FileBuffer.MousePosition.Row - 1,
365 Value = Line->Buffer[FColumn - 1];
367 (INT32)FileBuffer.MousePosition.Column - 1,
368 (INT32)FileBuffer.MousePosition.Row - 1,
412 if (FileBuffer.Lines !=
NULL) {
413 Line = FileBuffer.Lines;
414 Link = &(Line->Link);
417 Link = Link->ForwardLink;
423 }
while (Link != FileBuffer.ListHead);
429 FileBuffer.Lines =
NULL;
430 FileBuffer.CurrentLine =
NULL;
431 FileBuffer.NumLines = 0;
433 FileBuffer.ListHead->ForwardLink = FileBuffer.ListHead;
434 FileBuffer.ListHead->BackLink = FileBuffer.ListHead;
451 SHELL_FREE_NON_NULL (FileBuffer.FileName);
458 SHELL_FREE_NON_NULL (FileBuffer.ListHead);
459 FileBuffer.ListHead =
NULL;
461 SHELL_FREE_NON_NULL (FileBufferBackupVar.FileName);
488 Buffer = Line->Buffer + FileBuffer.LowVisibleRange.Column - 1;
490 Limit = Line->Size - FileBuffer.LowVisibleRange.Column + 1;
491 if (Limit > Line->Size) {
495 BufLen = (MainEditor.ScreenSize.Column + 1) *
sizeof (CHAR16);
497 if (PrintLine !=
NULL) {
498 StrnCpyS (PrintLine, BufLen/
sizeof (CHAR16), Buffer,
MIN (Limit, MainEditor.ScreenSize.Column));
499 for (Limit =
StrLen (PrintLine); Limit < MainEditor.ScreenSize.Column; Limit++) {
500 PrintLine[Limit] = L
' ';
503 PrintLine[MainEditor.ScreenSize.Column] = CHAR_NULL;
506 if (PrintLine2 !=
NULL) {
539 FileBuffer.DisplayPosition.Column - 1,
540 FileBuffer.DisplayPosition.Row - 1
567 if (!FileBufferNeedRefresh &&
568 !FileBufferOnlyLineNeedRefresh &&
569 (FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row) &&
570 (FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column)
585 if (FileBufferOnlyLineNeedRefresh &&
586 (FileBufferBackupVar.LowVisibleRange.Row == FileBuffer.LowVisibleRange.Row) &&
587 (FileBufferBackupVar.LowVisibleRange.Column == FileBuffer.LowVisibleRange.Column)
590 EditorClearLine (FileBuffer.DisplayPosition.Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);
592 FileBuffer.CurrentLine,
593 FileBuffer.DisplayPosition.Row
603 if (FileBuffer.Lines ==
NULL) {
614 Line =
MoveLine (FileBuffer.LowVisibleRange.Row - FileBuffer.FilePosition.Row);
618 return EFI_LOAD_ERROR;
621 Link = &(Line->Link);
631 Link = Link->ForwardLink;
633 }
while (Link != FileBuffer.ListHead && Row <= (MainEditor.ScreenSize.Row - 1));
638 while (Row <= (MainEditor.ScreenSize.Row - 1)) {
639 EditorClearLine (Row, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row);
647 FileBufferNeedRefresh =
FALSE;
648 FileBufferOnlyLineNeedRefresh =
FALSE;
681 Line->Signature = LINE_LIST_SIGNATURE;
684 Line->Type = NewLineTypeDefault;
689 ASSERT (CHAR_NULL == CHAR_NULL);
691 if (Line->Buffer ==
NULL) {
695 FileBuffer.NumLines++;
702 if (FileBuffer.Lines ==
NULL) {
703 FileBuffer.Lines =
CR (FileBuffer.ListHead->ForwardLink,
EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);
727 return (EFI_INVALID_PARAMETER);
733 SHELL_FREE_NON_NULL (FileBuffer.FileName);
739 if (FileBuffer.FileName ==
NULL) {
740 return EFI_OUT_OF_RESOURCES;
760 FileBuffer.FileModified =
FALSE;
783 EE_NEWLINE_TYPE Type;
788 CHAR16 *UnicodeBuffer;
791 SHELL_FILE_HANDLE FileHandle;
794 UINTN LineSizeBackup;
800 UnicodeBuffer =
NULL;
801 Type = NewLineTypeDefault;
819 if (!EFI_ERROR (Status)) {
821 if (FileHandle ==
NULL) {
823 return EFI_LOAD_ERROR;
828 if (Info->
Attribute & EFI_FILE_DIRECTORY) {
831 return EFI_INVALID_PARAMETER;
834 if (Info->
Attribute & EFI_FILE_READ_ONLY) {
835 FileBuffer.ReadOnly =
TRUE;
837 FileBuffer.ReadOnly =
FALSE;
846 }
else if (Status == EFI_NOT_FOUND) {
850 Status =
ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
851 if (EFI_ERROR (Status)) {
852 if ((Status == EFI_WRITE_PROTECTED) ||
853 (Status == EFI_ACCESS_DENIED) ||
854 (Status == EFI_NO_MEDIA) ||
855 (Status == EFI_MEDIA_CHANGED)
859 }
else if ((Status == EFI_DEVICE_ERROR) || (Status == EFI_VOLUME_CORRUPTED) || (Status == EFI_VOLUME_FULL)) {
871 if (Status == EFI_WARN_DELETE_FAILURE) {
872 Status = EFI_ACCESS_DENIED;
876 if (EFI_ERROR (Status)) {
886 FileBuffer.ReadOnly =
FALSE;
892 if (
StrCmp (FileName, FileBuffer.FileName) != 0) {
910 if (Buffer ==
NULL) {
911 return EFI_OUT_OF_RESOURCES;
920 if (EFI_ERROR (Status)) {
922 SHELL_FREE_NON_NULL (Buffer);
923 return EFI_LOAD_ERROR;
930 SHELL_FREE_NON_NULL (Buffer);
934 FileBuffer.FileType = FileTypeAscii;
939 AsciiBuffer = Buffer;
945 FileBuffer.FileType = FileTypeAscii;
954 if ((FileSize % 2) != 0) {
956 SHELL_FREE_NON_NULL (Buffer);
957 return EFI_LOAD_ERROR;
962 FileBuffer.FileType = FileTypeUnicode;
963 UnicodeBuffer = Buffer;
971 FileBuffer.FileType = FileTypeAscii;
984 if (
StrCmp (FileName, FileBuffer.FileName) != 0) {
996 for (LoopVar1 = 0; LoopVar1 < FileSize; LoopVar1++) {
997 Type = NewLineTypeUnknown;
999 for (LineSize = LoopVar1; LineSize < FileSize; LineSize++) {
1000 if (FileBuffer.FileType == FileTypeAscii) {
1001 if (AsciiBuffer[LineSize] == CHAR_CARRIAGE_RETURN) {
1002 Type = NewLineTypeCarriageReturn;
1007 if (LineSize < FileSize - 1) {
1008 if (AsciiBuffer[LineSize + 1] == CHAR_LINEFEED) {
1009 Type = NewLineTypeCarriageReturnLineFeed;
1014 }
else if (AsciiBuffer[LineSize] == CHAR_LINEFEED) {
1015 Type = NewLineTypeLineFeed;
1020 if (LineSize < FileSize - 1) {
1021 if (AsciiBuffer[LineSize + 1] == CHAR_CARRIAGE_RETURN) {
1022 Type = NewLineTypeLineFeedCarriageReturn;
1029 if (UnicodeBuffer[LineSize] == CHAR_CARRIAGE_RETURN) {
1030 Type = NewLineTypeCarriageReturn;
1035 if (LineSize < FileSize - 1) {
1036 if (UnicodeBuffer[LineSize + 1] == CHAR_LINEFEED) {
1037 Type = NewLineTypeCarriageReturnLineFeed;
1042 }
else if (UnicodeBuffer[LineSize] == CHAR_LINEFEED) {
1043 Type = NewLineTypeLineFeed;
1048 if (LineSize < FileSize - 1) {
1049 if (UnicodeBuffer[LineSize + 1] == CHAR_CARRIAGE_RETURN) {
1050 Type = NewLineTypeLineFeedCarriageReturn;
1068 if (Type == NewLineTypeUnknown) {
1072 Type = NewLineTypeDefault;
1075 LineSizeBackup = LineSize;
1082 SHELL_FREE_NON_NULL (Buffer);
1083 return EFI_OUT_OF_RESOURCES;
1089 LineSize -= LoopVar1;
1094 SHELL_FREE_NON_NULL (Line->Buffer);
1097 if (Line->Buffer ==
NULL) {
1099 return EFI_OUT_OF_RESOURCES;
1105 for (LoopVar2 = 0; LoopVar2 < LineSize; LoopVar2++) {
1106 if (FileBuffer.FileType == FileTypeAscii) {
1107 Line->Buffer[LoopVar2] = (CHAR16)AsciiBuffer[LoopVar1];
1109 Line->Buffer[LoopVar2] = UnicodeBuffer[LoopVar1];
1118 Line->Buffer[LineSize] = 0;
1120 Line->Size = LineSize;
1121 Line->TotalSize = LineSize;
1124 if ((Type == NewLineTypeCarriageReturnLineFeed) || (Type == NewLineTypeLineFeedCarriageReturn)) {
1131 if ((((Type == NewLineTypeCarriageReturnLineFeed) || (Type == NewLineTypeLineFeedCarriageReturn)) && (LineSizeBackup == FileSize - 2)) ||
1132 (((Type == NewLineTypeLineFeed) || (Type == NewLineTypeCarriageReturn)) && (LineSizeBackup == FileSize - 1))
1137 SHELL_FREE_NON_NULL (Buffer);
1138 return EFI_OUT_OF_RESOURCES;
1150 SHELL_FREE_NON_NULL (Buffer);
1158 FileBuffer.DisplayPosition.Row = 2;
1159 FileBuffer.DisplayPosition.Column = 1;
1160 FileBuffer.LowVisibleRange.Row = 1;
1161 FileBuffer.LowVisibleRange.Column = 1;
1162 FileBuffer.FilePosition.Row = 1;
1163 FileBuffer.FilePosition.Column = 1;
1164 FileBuffer.MousePosition.Row = 2;
1165 FileBuffer.MousePosition.Column = 1;
1168 UnicodeBuffer =
CatSPrint (
NULL, L
"%d Lines Read", FileBuffer.NumLines);
1169 if (UnicodeBuffer ==
NULL) {
1170 return EFI_OUT_OF_RESOURCES;
1257 if (FileBuffer.Lines != 0) {
1258 FileBuffer.CurrentLine =
CR (FileBuffer.ListHead->ForwardLink,
EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);
1265 return EFI_OUT_OF_RESOURCES;
1268 FileBuffer.CurrentLine = Line;
1271 FileBuffer.FileModified =
FALSE;
1272 FileBufferNeedRefresh =
TRUE;
1273 FileBufferOnlyLineNeedRefresh =
FALSE;
1274 FileBufferMouseNeedRefresh =
TRUE;
1289 IN CONST EE_NEWLINE_TYPE Type,
1305 if ((Type != NewLineTypeLineFeed) && (Type != NewLineTypeCarriageReturn) && (Type != NewLineTypeCarriageReturnLineFeed) && (Type != NewLineTypeLineFeedCarriageReturn)) {
1313 if (Type == NewLineTypeCarriageReturn) {
1314 if (MainEditor.FileBuffer->FileType == FileTypeUnicode) {
1323 *Size = NewLineSize;
1330 if (Type == NewLineTypeLineFeed) {
1331 if (MainEditor.FileBuffer->FileType == FileTypeUnicode) {
1340 *Size = NewLineSize;
1347 if (Type == NewLineTypeCarriageReturnLineFeed) {
1348 if (MainEditor.FileBuffer->FileType == FileTypeUnicode) {
1361 *Size = NewLineSize;
1368 if (Type == NewLineTypeLineFeedCarriageReturn) {
1369 if (MainEditor.FileBuffer->FileType == FileTypeUnicode) {
1382 *Size = NewLineSize;
1408 for (Index = 0; Index < Length; Index++) {
1409 *AStr++ = (CHAR8)*UStr++;
1429 SHELL_FILE_HANDLE FileHandle;
1437 CHAR8 NewLineBuffer[4];
1444 EE_NEWLINE_TYPE Type;
1459 TotalSize = 0x200000;
1466 if ((FileBuffer.FileName !=
NULL) && (
StrCmp (FileName, FileBuffer.FileName) == 0)) {
1470 if (!FileBuffer.FileModified) {
1477 if (FileBuffer.ReadOnly) {
1483 Status =
ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
1485 if (!EFI_ERROR (Status)) {
1488 if ((Info !=
NULL) && Info->
Attribute & EFI_FILE_DIRECTORY) {
1492 return EFI_LOAD_ERROR;
1496 Attribute = Info->
Attribute & ~EFI_FILE_READ_ONLY;
1504 if (EFI_ERROR (Status) || (Status == EFI_WARN_DELETE_FAILURE)) {
1506 return EFI_LOAD_ERROR;
1510 Status =
ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, Attribute);
1512 if (EFI_ERROR (Status)) {
1514 return EFI_LOAD_ERROR;
1520 if (FileBuffer.FileType == FileTypeUnicode) {
1523 if (EFI_ERROR (Status)) {
1525 return EFI_LOAD_ERROR;
1530 if (Cache ==
NULL) {
1532 return EFI_OUT_OF_RESOURCES;
1539 Type = NewLineTypeCarriageReturnLineFeed;
1542 LeftSize = TotalSize;
1544 for (Link = FileBuffer.ListHead->ForwardLink; Link != FileBuffer.ListHead; Link = Link->ForwardLink) {
1547 if (Line->Type != NewLineTypeDefault) {
1555 if ((Line->Buffer !=
NULL) && (Line->Size != 0)) {
1556 if (FileBuffer.FileType == FileTypeAscii) {
1557 Length += Line->Size;
1559 Length += (Line->Size * 2);
1570 if (LeftSize < Length) {
1571 Size = TotalSize - LeftSize;
1573 if (EFI_ERROR (Status)) {
1576 return EFI_LOAD_ERROR;
1580 LeftSize = TotalSize;
1583 if ((Line->Buffer !=
NULL) && (Line->Size != 0)) {
1584 if (FileBuffer.FileType == FileTypeAscii) {
1586 Length = Line->Size;
1588 Length = (Line->Size * 2);
1589 CopyMem (Ptr, (CHAR8 *)Line->Buffer, Length);
1604 if (Link->ForwardLink != FileBuffer.ListHead) {
1605 GetNewLine (Type, NewLineBuffer, &NewLineSize);
1606 CopyMem (Ptr, (CHAR8 *)NewLineBuffer, NewLineSize);
1609 LeftSize -= NewLineSize;
1615 if (TotalSize != LeftSize) {
1616 Size = TotalSize - LeftSize;
1618 if (EFI_ERROR (Status)) {
1621 return EFI_LOAD_ERROR;
1629 FileBuffer.FileModified =
FALSE;
1636 return EFI_OUT_OF_RESOURCES;
1640 SHELL_FREE_NON_NULL (Str);
1645 if ((FileName !=
NULL) && (FileBuffer.FileName !=
NULL) && (
StrCmp (FileName, FileBuffer.FileName) != 0)) {
1650 if (FileBuffer.FileName ==
NULL) {
1652 return EFI_OUT_OF_RESOURCES;
1656 FileBuffer.ReadOnly =
FALSE;
1674 Line = FileBuffer.CurrentLine;
1676 FRow = FileBuffer.FilePosition.Row;
1677 FCol = FileBuffer.FilePosition.Column;
1686 if (Line->Link.BackLink != FileBuffer.ListHead) {
1689 FCol = Line->Size + 1;
1722 for (Index = Pos - 1; Index < Line->Size; Index++) {
1723 Line->Buffer[Index] = Line->Buffer[Index + 1];
1746 Dest->Buffer[Size] = 0;
1753 Dest->Buffer =
NULL;
1757 Dest->Size = Size + Src->Size;
1758 Dest->TotalSize = Dest->Size;
1785 FileColumn = FileBuffer.FilePosition.Column;
1787 Line = FileBuffer.CurrentLine;
1792 if (FileColumn == 1) {
1796 if (FileBuffer.FilePosition.Row == 1) {
1802 Line = FileBuffer.CurrentLine;
1803 Link = Line->Link.ForwardLink;
1810 if (Line->Buffer ==
NULL) {
1811 return EFI_OUT_OF_RESOURCES;
1820 FileBuffer.NumLines--;
1822 FileBufferNeedRefresh =
TRUE;
1823 FileBufferOnlyLineNeedRefresh =
FALSE;
1830 FileBufferOnlyLineNeedRefresh =
TRUE;
1833 if (!FileBuffer.FileModified) {
1834 FileBuffer.FileModified =
TRUE;
1859 FileBufferNeedRefresh =
TRUE;
1860 FileBufferOnlyLineNeedRefresh =
FALSE;
1862 Line = FileBuffer.CurrentLine;
1864 FileColumn = FileBuffer.FilePosition.Column;
1867 if (NewLine ==
NULL) {
1868 return EFI_OUT_OF_RESOURCES;
1871 NewLine->Signature = LINE_LIST_SIGNATURE;
1872 NewLine->Size = Line->Size - FileColumn + 1;
1873 NewLine->TotalSize = NewLine->Size;
1875 if (NewLine->Buffer ==
NULL) {
1876 return EFI_OUT_OF_RESOURCES;
1879 NewLine->Type = NewLineTypeDefault;
1881 if (NewLine->Size > 0) {
1886 if (Buffer ==
NULL) {
1889 return EFI_OUT_OF_RESOURCES;
1894 NewLine->Buffer = Buffer;
1896 for (Index = 0; Index < NewLine->Size; Index++) {
1897 NewLine->Buffer[Index] = Line->Buffer[Index + FileColumn - 1];
1900 NewLine->Buffer[NewLine->Size] = CHAR_NULL;
1902 Line->Buffer[FileColumn - 1] = CHAR_NULL;
1903 Line->Size = FileColumn - 1;
1909 FileBuffer.NumLines++;
1914 NewLine->Link.BackLink = &(Line->Link);
1915 NewLine->Link.ForwardLink = Line->Link.ForwardLink;
1916 Line->Link.ForwardLink->BackLink = &(NewLine->Link);
1917 Line->Link.ForwardLink = &(NewLine->Link);
1922 Row = FileBuffer.FilePosition.Row + 1;
1930 if (!FileBuffer.FileModified) {
1931 FileBuffer.FileModified =
TRUE;
1953 Line = FileBuffer.CurrentLine;
1954 FileColumn = FileBuffer.FilePosition.Column;
1959 if (FileColumn >= Line->Size + 1) {
1963 if (Line->Link.ForwardLink == FileBuffer.ListHead) {
1971 Link = Line->Link.ForwardLink;
1974 if (Line->Buffer ==
NULL) {
1975 return EFI_OUT_OF_RESOURCES;
1981 FileBuffer.NumLines--;
1983 FileBufferNeedRefresh =
TRUE;
1984 FileBufferOnlyLineNeedRefresh =
FALSE;
1990 FileBufferOnlyLineNeedRefresh =
TRUE;
1993 if (!FileBuffer.FileModified) {
1994 FileBuffer.FileModified =
TRUE;
2014 Line = FileBuffer.CurrentLine;
2015 if (Line->Buffer ==
NULL) {
2019 FRow = FileBuffer.FilePosition.Row;
2020 FCol = FileBuffer.FilePosition.Column;
2025 if (FCol > Line->Size) {
2029 if (Line->Link.ForwardLink != FileBuffer.ListHead) {
2067 CHAR16 *TempStringPtr;
2077 if (Line->TotalSize <= Line->Size) {
2083 Line->TotalSize += 8;
2089 TempStringPtr = Str;
2090 for (Index =
StrSize; Index > Pos; Index--) {
2091 TempStringPtr[Index] = TempStringPtr[Index - 1];
2097 TempStringPtr[Index] = Char;
2120 Line = FileBuffer.CurrentLine;
2125 FileBufferOnlyLineNeedRefresh =
TRUE;
2132 FilePos = FileBuffer.FilePosition.Column - 1;
2133 if (FileBuffer.ModeInsert || (FilePos + 1 > Line->Size)) {
2136 Line->Buffer[FilePos] = Char;
2144 if (!FileBuffer.FileModified) {
2145 FileBuffer.FileModified =
TRUE;
2173 case CHAR_BACKSPACE:
2184 case CHAR_CARRIAGE_RETURN:
2192 if ((Char > 127) || (Char < 32)) {
2218 Line = FileBuffer.CurrentLine;
2219 if (Line->Buffer ==
NULL) {
2223 FRow = FileBuffer.FilePosition.Row;
2224 FCol = FileBuffer.FilePosition.Column;
2229 if (Line->Link.ForwardLink != FileBuffer.ListHead) {
2236 if (FCol > Line->Size) {
2237 FCol = Line->Size + 1;
2262 Line = FileBuffer.CurrentLine;
2264 FRow = FileBuffer.FilePosition.Row;
2265 FCol = FileBuffer.FilePosition.Column;
2270 if (Line->Link.BackLink != FileBuffer.ListHead) {
2277 if (FCol > Line->Size) {
2278 FCol = Line->Size + 1;
2304 Line = FileBuffer.CurrentLine;
2306 FRow = FileBuffer.FilePosition.Row;
2307 FCol = FileBuffer.FilePosition.Column;
2312 if (FileBuffer.NumLines >= FRow + (MainEditor.ScreenSize.Row - 2)) {
2313 Gap = (MainEditor.ScreenSize.Row - 2);
2318 Gap = FileBuffer.NumLines - FRow;
2329 if ((Line !=
NULL) && (FCol > Line->Size)) {
2330 FCol = Line->Size + 1;
2356 Line = FileBuffer.CurrentLine;
2358 FRow = FileBuffer.FilePosition.Row;
2359 FCol = FileBuffer.FilePosition.Column;
2364 if (FRow > (MainEditor.ScreenSize.Row - 2)) {
2365 Gap = (MainEditor.ScreenSize.Row - 2);
2384 if ((Line !=
NULL) && (FCol > Line->Size)) {
2385 FCol = Line->Size + 1;
2409 Line = FileBuffer.CurrentLine;
2411 FRow = FileBuffer.FilePosition.Row;
2416 FCol = Line->Size + 1;
2446 switch (Key->ScanCode) {
2451 if (!FileBuffer.ReadOnly) {
2497 case SCAN_PAGE_DOWN:
2505 if (!FileBuffer.ReadOnly) {
2532 FileBuffer.ModeInsert = (BOOLEAN) !FileBuffer.ModeInsert;
2560 if (FileRow < FileBuffer.LowVisibleRange.Row) {
2583 if (FileRow > FileBuffer.LowVisibleRange.Row + (MainEditor.ScreenSize.Row - 2) - 1) {
2606 if (FileCol < FileBuffer.LowVisibleRange.Column) {
2629 if (FileCol > FileBuffer.LowVisibleRange.Column + MainEditor.ScreenSize.Column - 1) {
2665 MainEditor.FileBuffer->CurrentLine = Line;
2693 RowGap = NewFilePosRow - FileBuffer.FilePosition.Row;
2694 ColGap = NewFilePosCol - FileBuffer.FilePosition.Column;
2705 FileBuffer.FilePosition.Row = NewFilePosRow;
2713 if (NewFilePosRow < (FileBuffer.DisplayPosition.Row - 1)) {
2714 FileBuffer.DisplayPosition.Row = NewFilePosRow + 1;
2717 FileBuffer.FilePosition.Row = NewFilePosRow;
2722 FileBuffer.FilePosition.Row = NewFilePosRow;
2725 FileBuffer.DisplayPosition.Row -= Abs;
2727 FileBuffer.DisplayPosition.Row += RowGap;
2732 FileBuffer.LowVisibleRange.Row = FileBuffer.FilePosition.Row - (FileBuffer.DisplayPosition.Row - 2);
2744 FileBuffer.DisplayPosition.Column = MainEditor.ScreenSize.Column;
2745 FileBuffer.FilePosition.Column = NewFilePosCol;
2753 if (NewFilePosCol < (FileBuffer.DisplayPosition.Column)) {
2754 FileBuffer.DisplayPosition.Column = NewFilePosCol;
2757 FileBuffer.FilePosition.Column = NewFilePosCol;
2762 FileBuffer.FilePosition.Column = NewFilePosCol;
2764 Abs = (
UINTN)(-ColGap);
2765 FileBuffer.DisplayPosition.Column -= Abs;
2767 FileBuffer.DisplayPosition.Column += ColGap;
2772 FileBuffer.LowVisibleRange.Column = FileBuffer.FilePosition.Column - (FileBuffer.DisplayPosition.Column - 1);
2802 if (FileBuffer.ReadOnly) {
2807 Line = FileBuffer.CurrentLine;
2812 if ((
StrCmp (Line->Buffer, L
"\0") == 0) && (Line->Link.ForwardLink == FileBuffer.ListHead)
2822 return EFI_NOT_FOUND;
2828 if (Line->Link.ForwardLink == FileBuffer.ListHead) {
2834 if (NewLine ==
NULL) {
2835 return EFI_OUT_OF_RESOURCES;
2839 FileBuffer.NumLines--;
2840 Row = FileBuffer.FilePosition.Row;
2845 FileBuffer.CurrentLine =
CR (
2846 FileBuffer.CurrentLine->Link.ForwardLink,
2854 FileBuffer.Lines =
CR (FileBuffer.ListHead->ForwardLink,
EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);
2858 FileBuffer.FileModified =
TRUE;
2859 FileBufferNeedRefresh =
TRUE;
2860 FileBufferOnlyLineNeedRefresh =
FALSE;
2887 if (MainEditor.CutLine ==
NULL) {
2894 if (FileBuffer.ReadOnly) {
2899 NewLine =
LineDup (MainEditor.CutLine);
2900 if (NewLine ==
NULL) {
2901 return EFI_OUT_OF_RESOURCES;
2907 Line = FileBuffer.CurrentLine;
2908 NewLine->Link.BackLink = Line->Link.BackLink;
2909 NewLine->Link.ForwardLink = &Line->Link;
2911 Line->Link.BackLink->ForwardLink = &NewLine->Link;
2912 Line->Link.BackLink = &NewLine->Link;
2914 FileBuffer.NumLines++;
2915 FileBuffer.CurrentLine = NewLine;
2917 FileBuffer.Lines =
CR (FileBuffer.ListHead->ForwardLink,
EFI_EDITOR_LINE, Link, LINE_LIST_SIGNATURE);
2923 Row = FileBuffer.FilePosition.Row;
2930 FileBuffer.FileModified =
TRUE;
2931 FileBufferNeedRefresh =
TRUE;
2932 FileBufferOnlyLineNeedRefresh =
FALSE;
2967 Current = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column - 1 + Offset;
2969 if (Current >= (FileBuffer.CurrentLine->Buffer + FileBuffer.CurrentLine->Size)) {
2973 Current = FileBuffer.CurrentLine->Buffer + FileBuffer.CurrentLine->Size;
2978 CharPos =
StrStr (Current, Str);
2979 if (CharPos !=
NULL) {
2980 Position = CharPos - Current + 1;
2988 Column = (Position - 1) + FileBuffer.FilePosition.Column + Offset;
2989 Row = FileBuffer.FilePosition.Row;
2994 Link = FileBuffer.CurrentLine->Link.ForwardLink;
2996 Row = FileBuffer.FilePosition.Row + 1;
2997 while (Link != FileBuffer.ListHead) {
3000 CharPos =
StrStr (Line->Buffer, Str);
3001 if (CharPos !=
NULL) {
3002 Position = CharPos - Line->Buffer + 1;
3015 Link = Link->ForwardLink;
3018 if (Link == FileBuffer.ListHead) {
3026 return EFI_NOT_FOUND;
3064 ReplaceLen =
StrLen (Replace);
3066 OldSize = FileBuffer.CurrentLine->Size + 1;
3070 NewSize = OldSize + (ReplaceLen - SearchLen);
3072 if (ReplaceLen > SearchLen) {
3076 if (FileBuffer.CurrentLine->TotalSize + 1 <= NewSize) {
3080 FileBuffer.CurrentLine->Buffer
3082 FileBuffer.CurrentLine->TotalSize = NewSize - 1;
3085 if (FileBuffer.CurrentLine->Buffer ==
NULL) {
3086 return EFI_OUT_OF_RESOURCES;
3092 Buffer = FileBuffer.CurrentLine->Buffer + (NewSize - 1);
3093 Gap = ReplaceLen - SearchLen;
3098 for (Index = 0; Index < (FileBuffer.CurrentLine->Size - FileBuffer.FilePosition.Column - SearchLen + 2); Index++) {
3099 *Buffer = *(Buffer - Gap);
3106 Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column - 1;
3107 for (Index = 0; Index < ReplaceLen; Index++) {
3108 Buffer[Index] = Replace[Index];
3112 if (ReplaceLen < SearchLen) {
3113 Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column - 1;
3115 for (Index = 0; Index < ReplaceLen; Index++) {
3116 Buffer[Index] = Replace[Index];
3119 Buffer += ReplaceLen;
3120 Gap = SearchLen - ReplaceLen;
3125 for (Index = 0; Index < (FileBuffer.CurrentLine->Size - FileBuffer.FilePosition.Column - ReplaceLen + 2); Index++) {
3126 *Buffer = *(Buffer + Gap);
3131 if (ReplaceLen == SearchLen) {
3132 Buffer = FileBuffer.CurrentLine->Buffer + FileBuffer.FilePosition.Column - 1;
3133 for (Index = 0; Index < ReplaceLen; Index++) {
3134 Buffer[Index] = Replace[Index];
3138 FileBuffer.CurrentLine->Size += (ReplaceLen - SearchLen);
3140 FileBufferOnlyLineNeedRefresh =
TRUE;
3142 FileBuffer.FileModified =
TRUE;
3144 MainTitleBarRefresh (MainEditor.FileBuffer->FileName, MainEditor.FileBuffer->FileType, MainEditor.FileBuffer->ReadOnly, MainEditor.FileBuffer->FileModified, MainEditor.ScreenSize.Column, MainEditor.ScreenSize.Row, 0, 0);
3179 CoordinateX = FileBuffer.MousePosition.Column;
3180 CoordinateY = FileBuffer.MousePosition.Row;
3183 CoordinateX += TextX;
3185 if (CoordinateX >= AbsX) {
3186 CoordinateX -= AbsX;
3193 CoordinateY += TextY;
3195 if (CoordinateY >= AbsY) {
3196 CoordinateY -= AbsY;
3206 if ((CoordinateX >= 1) && (CoordinateX <= MainEditor.ScreenSize.Column)) {
3207 FileBuffer.MousePosition.Column = CoordinateX;
3208 }
else if (CoordinateX < 1) {
3209 FileBuffer.MousePosition.Column = 1;
3210 }
else if (CoordinateX > MainEditor.ScreenSize.Column) {
3211 FileBuffer.MousePosition.Column = MainEditor.ScreenSize.Column;
3218 if ((CoordinateY >= 2) && (CoordinateY <= (MainEditor.ScreenSize.Row - 1))) {
3219 FileBuffer.MousePosition.Row = CoordinateY;
3220 }
else if (CoordinateY < 2) {
3221 FileBuffer.MousePosition.Row = 2;
3222 }
else if (CoordinateY > (MainEditor.ScreenSize.Row - 1)) {
3223 FileBuffer.MousePosition.Row = (MainEditor.ScreenSize.Row - 1);
3236 IN CHAR16 *SearchStr,
3237 IN CHAR16 *ReplaceStr,
3254 SearchLen =
StrLen (SearchStr);
3255 ReplaceLen =
StrLen (ReplaceStr);
3257 Column = FileBuffer.FilePosition.Column + Offset - 1;
3259 if (Column > FileBuffer.CurrentLine->Size) {
3260 Column = FileBuffer.CurrentLine->Size;
3263 Link = &(FileBuffer.CurrentLine->Link);
3265 while (Link != FileBuffer.ListHead) {
3267 CharPos =
StrStr (Line->Buffer + Column, SearchStr);
3268 if (CharPos !=
NULL) {
3269 Position = CharPos - Line->Buffer;
3273 if (ReplaceLen > SearchLen) {
3274 OldSize = Line->Size + 1;
3278 NewSize = OldSize + (ReplaceLen - SearchLen);
3283 if (Line->TotalSize + 1 <= NewSize) {
3289 Line->TotalSize = NewSize - 1;
3292 if (Line->Buffer ==
NULL) {
3293 return EFI_OUT_OF_RESOURCES;
3299 Buffer = Line->Buffer + (NewSize - 1);
3300 Gap = ReplaceLen - SearchLen;
3305 for (Index = 0; Index < (Line->Size - Position - SearchLen + 1); Index++) {
3306 *Buffer = *(Buffer - Gap);
3309 }
else if (ReplaceLen < SearchLen) {
3310 Buffer = Line->Buffer + Position + ReplaceLen;
3311 Gap = SearchLen - ReplaceLen;
3313 for (Index = 0; Index < (Line->Size - Position - ReplaceLen + 1); Index++) {
3314 *Buffer = *(Buffer + Gap);
3318 ASSERT (ReplaceLen == SearchLen);
3324 Buffer = Line->Buffer + Position;
3325 for (Index = 0; Index < ReplaceLen; Index++) {
3326 Buffer[Index] = ReplaceStr[Index];
3329 Line->Size += (ReplaceLen - SearchLen);
3330 Column += ReplaceLen;
3336 Link = Link->ForwardLink;
3343 FileBuffer.FileModified =
TRUE;
3344 FileBufferNeedRefresh =
TRUE;
3358 FileBuffer.FileModified =
TRUE;
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
RETURN_STATUS EFIAPI StrnCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS StatusBarSetStatusString(IN CHAR16 *Str)
EFI_STATUS MainTitleBarRefresh(IN CONST CHAR16 *FileName OPTIONAL, IN CONST EDIT_FILE_TYPE FileType, IN CONST BOOLEAN ReadOnly, IN CONST BOOLEAN Modified, IN CONST UINTN LastCol, IN CONST UINTN LastRow, IN CONST UINTN Offset, IN CONST UINTN Size)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS FileBufferPrintLine(IN CONST EFI_EDITOR_LINE *Line, IN CONST UINTN Row)
EFI_STATUS FileBufferPageDown(VOID)
EFI_STATUS FileBufferScrollUp(VOID)
VOID FileBufferMovePosition(IN CONST UINTN NewFilePosRow, IN CONST UINTN NewFilePosCol)
VOID FileBufferSetModified(VOID)
EFI_STATUS FileBufferRefresh(VOID)
EFI_EDITOR_LINE * InternalEditorMiscLineRetreat(IN CONST UINTN Count, IN CONST EFI_EDITOR_LINE *CurrentLine, IN CONST LIST_ENTRY *LineList)
EFI_STATUS FileBufferEnd(VOID)
EFI_STATUS FileBufferCleanup(VOID)
EFI_STATUS FileBufferRead(IN CONST CHAR16 *FileName, IN CONST BOOLEAN Recover)
EFI_STATUS FileBufferScrollRight(VOID)
EFI_STATUS FileBufferRestorePosition(VOID)
EFI_STATUS FileBufferCutLine(OUT EFI_EDITOR_LINE **CutLine)
EFI_STATUS FileBufferDoBackspace(VOID)
EFI_STATUS FileBufferDoDelete(VOID)
EFI_STATUS FileBufferSave(IN CONST CHAR16 *FileName)
VOID LineCat(IN OUT EFI_EDITOR_LINE *Dest, IN EFI_EDITOR_LINE *Src)
EFI_EDITOR_LINE * MoveLine(IN CONST INTN Count)
EFI_STATUS FileBufferSearch(IN CONST CHAR16 *Str, IN CONST UINTN Offset)
EFI_STATUS FileBufferDoReturn(VOID)
EFI_STATUS FileBufferDoCharInput(IN CONST CHAR16 Char)
EFI_STATUS FileBufferHandleInput(IN CONST EFI_INPUT_KEY *Key)
EFI_STATUS FileBufferRestoreMousePosition(VOID)
BOOLEAN LeftCurrentScreen(IN UINTN FileCol)
BOOLEAN AboveCurrentScreen(IN UINTN FileRow)
EFI_STATUS FileBufferSetFileName(IN CONST CHAR16 *Str)
EFI_STATUS FileBufferReplace(IN CONST CHAR16 *Replace, IN CONST UINTN SearchLen)
EFI_STATUS FileBufferBackup(VOID)
EFI_STATUS FileBufferAddChar(IN CHAR16 Char)
BOOLEAN UnderCurrentScreen(IN UINTN FileRow)
EFI_STATUS FileBufferPageUp(VOID)
EFI_STATUS FileBufferScrollLeft(VOID)
VOID FileBufferAdjustMousePosition(IN CONST INT32 TextX, IN CONST INT32 TextY)
EFI_STATUS FileBufferReplaceAll(IN CHAR16 *SearchStr, IN CHAR16 *ReplaceStr, IN UINTN Offset)
EFI_STATUS FileBufferFree(VOID)
EFI_EDITOR_LINE * MoveCurrentLine(IN INTN Count)
EFI_STATUS FileBufferInit(VOID)
EFI_EDITOR_LINE * InternalEditorMiscLineAdvance(IN CONST UINTN Count, IN CONST EFI_EDITOR_LINE *CurrentLine, IN CONST LIST_ENTRY *LineList)
VOID GetNewLine(IN CONST EE_NEWLINE_TYPE Type, OUT CHAR8 *Buffer, OUT UINT8 *Size)
BOOLEAN RightCurrentScreen(IN UINTN FileCol)
UINTN UnicodeToAscii(IN CONST CHAR16 *UStr, IN CONST UINTN Length, OUT CHAR8 *AStr)
EFI_STATUS FileBufferFreeLines(VOID)
VOID LineDeleteAt(IN OUT EFI_EDITOR_LINE *Line, IN UINTN Pos)
EFI_STATUS FileBufferPasteLine(VOID)
EFI_EDITOR_LINE * FileBufferCreateLine(VOID)
UINTN LineStrInsert(IN EFI_EDITOR_LINE *Line, IN CHAR16 Char, IN UINTN Pos, IN UINTN StrSize)
EFI_STATUS FileBufferScrollDown(VOID)
CONST UINT16 gUnicodeFileTag
#define CR(Record, TYPE, Field, TestSignature)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_FILE_INFO *EFIAPI ShellGetFileInfo(IN SHELL_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI ShellDeleteFile(IN SHELL_FILE_HANDLE *FileHandle)
EFI_STATUS EFIAPI ShellCopySearchAndReplace(IN CHAR16 CONST *SourceString, IN OUT CHAR16 *NewString, IN UINTN NewSize, IN CONST CHAR16 *FindTarget, IN CONST CHAR16 *ReplaceWith, IN CONST BOOLEAN SkipPreCarrot, IN CONST BOOLEAN ParameterReplacing)
EFI_STATUS EFIAPI ShellOpenFileByName(IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
EFI_STATUS EFIAPI ShellWriteFile(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI ShellCloseFile(IN SHELL_FILE_HANDLE *FileHandle)
EFI_STATUS EFIAPI ShellReadFile(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
VOID LineFree(IN EFI_EDITOR_LINE *Src)
EFI_EDITOR_LINE * LineDup(IN EFI_EDITOR_LINE *Src)
CHAR16 *EFIAPI CatSPrint(IN CHAR16 *String OPTIONAL, IN CONST CHAR16 *FormatString,...)
BOOLEAN IsValidFileName(IN CONST CHAR16 *Name)
CHAR16 * EditGetDefaultFileName(IN CONST CHAR16 *Extension)
VOID EditorClearLine(IN UINTN Row, IN UINTN LastCol, IN UINTN LastRow)
#define EFI_UNICODE_BYTE_ORDER_MARK
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut