X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FHexEdit%2FBufferImage.c;h=469642245d0e704c258e1098f5c495264bf7f000;hp=60e0b75435adad5fa3125074fc9fd64458af5b37;hb=a1d4bfcc3f58a9ed0ce6118556016c7c058d01b1;hpb=980d554e3ab6457a4f7a455fabcc297d6e93547f diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c index 60e0b75435..469642245d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/BufferImage.c @@ -74,26 +74,16 @@ BOOLEAN HBufferImageOnlyLineNeedRefresh; BOOLEAN HBufferImageMouseNeedRefresh; +/** + Initialization function for HBufferImage + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_LOAD_ERROR A load error occured. +**/ EFI_STATUS HBufferImageInit ( VOID ) -/*++ - -Routine Description: - - Initialization function for HBufferImage - -Arguments: - - None - -Returns: - - EFI_SUCCESS - EFI_LOAD_ERROR - ---*/ { EFI_STATUS Status; @@ -147,28 +137,16 @@ Returns: return EFI_SUCCESS; } +/** + Backup function for HBufferImage. Only a few fields need to be backup. + This is for making the file buffer refresh as few as possible. + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageBackup ( VOID ) -/*++ - -Routine Description: - - Backup function for HBufferImage - Only a few fields need to be backup. - This is for making the file buffer refresh - as few as possible. - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HBufferImageBackupVar.MousePosition = HBufferImage.MousePosition; @@ -203,30 +181,20 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -HBufferImageFreeLines ( - VOID - ) -/*++ - -Routine Description: - - Free all the lines in HBufferImage +/** + Free all the lines in HBufferImage. Fields affected: Lines CurrentLine NumLines ListHead -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +HBufferImageFreeLines ( + VOID + ) { HFreeLines (HBufferImage.ListHead, HBufferImage.Lines); @@ -237,25 +205,15 @@ Returns: return EFI_SUCCESS; } +/** + Cleanup function for HBufferImage + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageCleanup ( VOID ) -/*++ - -Routine Description: - - Cleanup function for HBufferImage - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { EFI_STATUS Status; @@ -269,12 +227,22 @@ Returns: HFileImageCleanup (); HDiskImageCleanup (); - HMemImageCleanup (); return Status; } +/** + Print Line on Row + + @param[in] Line The lline to print. + @param[in] Row The row on screen ( begin from 1 ). + @param[in] FRow The FRow. + @param[in] Orig The original color. + @param[in] New The color to print with. + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImagePrintLine ( IN HEFI_EDITOR_LINE *Line, @@ -284,25 +252,6 @@ HBufferImagePrintLine ( IN HEFI_EDITOR_COLOR_UNION New ) -/*++ - -Routine Description: - - Print Line on Row - -Arguments: - - Line - Line to print - Row - Row on screen ( begin from 1 ) - FRow - FRow - Orig - Orig - New - Light display - -Returns: - - EFI_SUCCESS - ---*/ { UINTN Index; @@ -345,7 +294,7 @@ Returns: } - if (HEditorMouseAction == FALSE) { + if (!HEditorMouseAction) { ShellPrintEx ( 0, (INT32)Row - 1, @@ -432,7 +381,7 @@ Returns: // // PRINT the buffer content // - if (HEditorMouseAction == FALSE) { + if (!HEditorMouseAction) { for (Index = 0; Index < 0x10 && Index < Line->Size; Index++) { Pos = ASCII_POSITION + Index; @@ -471,6 +420,15 @@ Returns: return EFI_SUCCESS; } +/** + Function to decide if a column number is stored in the high bits. + + @param[in] Column The column to examine. + @param[out] FCol The actual column number. + + @retval TRUE The actual column was in high bits and is now in FCol. + @retval FALSE There was not a column number in the high bits. +**/ BOOLEAN HBufferImageIsAtHighBits ( IN UINTN Column, @@ -494,7 +452,7 @@ HBufferImageIsAtHighBits ( *FCol = (Column / 3) + 1; - if (!(Column % 3)) { + if (Column % 3 == 0) { return TRUE; } @@ -505,6 +463,15 @@ HBufferImageIsAtHighBits ( return FALSE; } +/** + Decide if a point is in the already selected area. + + @param[in] MouseRow The row of the point to test. + @param[in] MouseCol The col of the point to test. + + @retval TRUE The point is in the selected area. + @retval FALSE The point is not in the selected area. +**/ BOOLEAN HBufferImageIsInSelectedArea ( IN UINTN MouseRow, @@ -567,6 +534,11 @@ HBufferImageIsInSelectedArea ( return TRUE; } +/** + Set mouse position according to HBufferImage.MousePosition. + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageRestoreMousePosition ( VOID @@ -637,7 +609,7 @@ HBufferImageRestoreMousePosition ( CurrentLine = HBufferImage.CurrentLine; Line = HMoveLine (FRow - HBufferImage.BufferPosition.Row); - if (FColumn > Line->Size) { + if (Line == NULL || FColumn > Line->Size) { HasCharacter = FALSE; } @@ -691,7 +663,7 @@ HBufferImageRestoreMousePosition ( CurrentLine = HBufferImage.CurrentLine; Line = HMoveLine (FRow - HBufferImage.BufferPosition.Row); - if (FColumn > Line->Size) { + if (Line == NULL || FColumn > Line->Size) { HasCharacter = FALSE; } @@ -734,25 +706,15 @@ HBufferImageRestoreMousePosition ( return EFI_SUCCESS; } +/** + Set cursor position according to HBufferImage.DisplayPosition. + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageRestorePosition ( VOID ) -/*++ - -Routine Description: - - Set cursor position according to HBufferImage.DisplayPosition. - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { // // set cursor position @@ -766,26 +728,17 @@ Returns: return EFI_SUCCESS; } +/** + Refresh function for HBufferImage. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_LOAD_ERROR A Load error occured. + +**/ EFI_STATUS HBufferImageRefresh ( VOID ) -/*++ - -Routine Description: - - Refresh function for HBufferImage - -Arguments: - - None - -Returns: - - EFI_SUCCESS - EFI_LOAD_ERROR - ---*/ { LIST_ENTRY *Link; HEFI_EDITOR_LINE *Line; @@ -811,8 +764,8 @@ Returns: // no definite required refresh // and file position displayed on screen has not been changed // - if (HBufferImageNeedRefresh == FALSE && - HBufferImageOnlyLineNeedRefresh == FALSE && + if (!HBufferImageNeedRefresh && + !HBufferImageOnlyLineNeedRefresh && HBufferImageBackupVar.LowVisibleRow == HBufferImage.LowVisibleRow ) { HBufferImageRestoreMousePosition (); @@ -826,7 +779,7 @@ Returns: // // only need to refresh current line // - if (HBufferImageOnlyLineNeedRefresh == TRUE && HBufferImageBackupVar.LowVisibleRow == HBufferImage.LowVisibleRow) { + if (HBufferImageOnlyLineNeedRefresh && HBufferImageBackupVar.LowVisibleRow == HBufferImage.LowVisibleRow) { HBufferImagePrintLine ( HBufferImage.CurrentLine, @@ -917,7 +870,7 @@ Returns: } while (Link != HBufferImage.ListHead && Row <= EndRow); while (Row <= EndRow) { - HEditorClearLine (Row); + EditorClearLine (Row, HMainEditor.ScreenSize.Column, HMainEditor.ScreenSize.Row); Row++; } // @@ -935,7 +888,22 @@ Returns: return EFI_SUCCESS; } +/** + Read an image into a buffer friom a source. + + @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer. + @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer. + @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer. + @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer. + @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer. + @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer. + @param[in] BufferType The type of buffer to save. IGNORED. + @param[in] Recover TRUE for recovermode, FALSE otherwise. + + @return EFI_SUCCESS The operation was successful. +**/ EFI_STATUS +EFIAPI HBufferImageRead ( IN CONST CHAR16 *FileName, IN CONST CHAR16 *DiskName, @@ -985,6 +953,19 @@ HBufferImageRead ( return Status; } +/** + Save the current image. + + @param[in] FileName Pointer to the file name. OPTIONAL and ignored if not FileTypeFileBuffer. + @param[in] DiskName Pointer to the disk name. OPTIONAL and ignored if not FileTypeDiskBuffer. + @param[in] DiskOffset Offset into the disk. OPTIONAL and ignored if not FileTypeDiskBuffer. + @param[in] DiskSize Size of the disk buffer. OPTIONAL and ignored if not FileTypeDiskBuffer. + @param[in] MemOffset Offset into the Memory. OPTIONAL and ignored if not FileTypeMemBuffer. + @param[in] MemSize Size of the Memory buffer. OPTIONAL and ignored if not FileTypeMemBuffer. + @param[in] BufferType The type of buffer to save. IGNORED. + + @return EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageSave ( IN CHAR16 *FileName, @@ -1035,29 +1016,20 @@ HBufferImageSave ( return Status; } -HEFI_EDITOR_LINE * -HBufferImageCreateLine ( - VOID - ) -/*++ - -Routine Description: - - Create a new line and append it to the line list +/** + Create a new line and append it to the line list. Fields affected: NumLines Lines -Arguments: - - None + @retval NULL create line failed. + @return the line created. -Returns: - - NULL -- create line failed - Not NULL -- the line created - ---*/ +**/ +HEFI_EDITOR_LINE * +HBufferImageCreateLine ( + VOID + ) { HEFI_EDITOR_LINE *Line; @@ -1091,26 +1063,15 @@ Returns: return Line; } +/** + Free the current image. + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageFree ( VOID ) -/*++ - -Routine Description: - - Function called when load a new file in. It will free all the old lines - and set FileModified field to FALSE - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { // // free all lines @@ -1120,293 +1081,110 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -HBufferImageHandleInput ( - IN EFI_INPUT_KEY *Key - ) -/*++ - -Routine Description: - - Dispatch input to different handler - -Arguments: +/** + change char to int value based on Hex. - Key -- input key - the keys can be: - ASCII KEY - Backspace/Delete - Direction key: up/down/left/right/pgup/pgdn - Home/End - INS + @param[in] Char The input char. -Returns: + @return The character's index value. + @retval -1 The operation failed. +**/ +INTN +EFIAPI +HBufferImageCharToHex ( + IN CHAR16 Char + ) +{ + // + // change the character to hex + // + if (Char >= L'0' && Char <= L'9') { + return (INTN) (Char - L'0'); + } - EFI_SUCCESS - EFI_LOAD_ERROR - EFI_OUT_OF_RESOURCES + if (Char >= L'a' && Char <= L'f') { + return (INTN) (Char - L'a' + 10); + } ---*/ -{ - EFI_STATUS Status; + if (Char >= L'A' && Char <= L'F') { + return (INTN) (Char - L'A' + 10); + } - Status = EFI_SUCCESS; + return -1; +} - switch (Key->ScanCode) { - // - // ordinary key - // - case SCAN_NULL: - Status = HBufferImageDoCharInput (Key->UnicodeChar); - break; +/** + Add character. - // - // up arrow - // - case SCAN_UP: - Status = HBufferImageScrollUp (); - break; + @param[in] Char -- input char. - // - // down arrow - // - case SCAN_DOWN: - Status = HBufferImageScrollDown (); - break; + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +HBufferImageAddChar ( + IN CHAR16 Char + ) +{ + HEFI_EDITOR_LINE *Line; + HEFI_EDITOR_LINE *NewLine; + INTN Value; + UINT8 Old; + UINTN FRow; + UINTN FCol; + BOOLEAN High; - // - // right arrow - // - case SCAN_RIGHT: - Status = HBufferImageScrollRight (); - break; + Value = HBufferImageCharToHex (Char); // - // left arrow + // invalid input // - case SCAN_LEFT: - Status = HBufferImageScrollLeft (); - break; + if (Value == -1) { + return EFI_SUCCESS; + } - // - // page up - // - case SCAN_PAGE_UP: - Status = HBufferImagePageUp (); - break; + Line = HBufferImage.CurrentLine; + FRow = HBufferImage.BufferPosition.Row; + FCol = HBufferImage.BufferPosition.Column; + High = HBufferImage.HighBits; // - // page down + // only needs to refresh current line // - case SCAN_PAGE_DOWN: - Status = HBufferImagePageDown (); - break; + HBufferImageOnlyLineNeedRefresh = TRUE; // - // delete + // not a full line and beyond the last character // - case SCAN_DELETE: - Status = HBufferImageDoDelete (); - break; + if (FCol > Line->Size) { + // + // cursor always at high 4 bits + // and always put input to the low 4 bits + // + Line->Buffer[Line->Size] = (UINT8) Value; + Line->Size++; + High = FALSE; + } else { - // - // home - // - case SCAN_HOME: - Status = HBufferImageHome (); - break; + Old = Line->Buffer[FCol - 1]; - // - // end - // - case SCAN_END: - Status = HBufferImageEnd (); - break; + // + // always put the input to the low 4 bits + // + Old = (UINT8) (Old & 0x0f); + Old = (UINT8) (Old << 4); + Old = (UINT8) (Value + Old); + Line->Buffer[FCol - 1] = Old; - default: - Status = StatusBarSetStatusString (L"Unknown Command"); - break; - } + // + // at the low 4 bits of the last character of a full line + // so if no next line, need to create a new line + // + if (!High && FCol == 0x10) { - return Status; -} - -EFI_STATUS -HBufferImageDoCharInput ( - IN CHAR16 Char - ) -/*++ - -Routine Description: - - ASCII key + Backspace + return - -Arguments: - - Char -- input char - -Returns: - - EFI_SUCCESS - EFI_LOAD_ERROR - EFI_OUT_OF_RESOURCES - ---*/ -{ - EFI_STATUS Status; - - Status = EFI_SUCCESS; - - switch (Char) { - case 0: - break; - - case 0x08: - Status = HBufferImageDoBackspace (); - break; - - case 0x09: - case 0x0a: - case 0x0d: - // - // Tabs, Returns are thought as nothing - // - break; - - default: - // - // DEAL WITH ASCII CHAR, filter out thing like ctrl+f - // - if (Char > 127 || Char < 32) { - Status = StatusBarSetStatusString (L"Unknown Command"); - } else { - Status = HBufferImageAddChar (Char); - } - - break; - } - - return Status; -} - -INTN -HBufferImageCharToHex ( - IN CHAR16 Char - ) -/*++ - -Routine Description: - - change char to int value based on Hex - -Arguments: - - Char -- input char - -Returns: - - int value; - - ---*/ -{ - // - // change the character to hex - // - if (Char >= L'0' && Char <= L'9') { - return (INTN) (Char - L'0'); - } - - if (Char >= L'a' && Char <= L'f') { - return (INTN) (Char - L'a' + 10); - } - - if (Char >= L'A' && Char <= L'F') { - return (INTN) (Char - L'A' + 10); - } - - return -1; -} - -EFI_STATUS -HBufferImageAddChar ( - IN CHAR16 Char - ) -/*++ - -Routine Description: - - Add character - -Arguments: - - Char -- input char - -Returns: - - EFI_SUCCESS - EFI_OUT_OF_RESOURCES - ---*/ -{ - HEFI_EDITOR_LINE *Line; - HEFI_EDITOR_LINE *NewLine; - INTN Value; - UINT8 Old; - UINTN FRow; - UINTN FCol; - BOOLEAN High; - - Value = HBufferImageCharToHex (Char); - - // - // invalid input - // - if (Value == -1) { - return EFI_SUCCESS; - } - - Line = HBufferImage.CurrentLine; - FRow = HBufferImage.BufferPosition.Row; - FCol = HBufferImage.BufferPosition.Column; - High = HBufferImage.HighBits; - - // - // only needs to refresh current line - // - HBufferImageOnlyLineNeedRefresh = TRUE; - - // - // not a full line and beyond the last character - // - if (FCol > Line->Size) { - // - // cursor always at high 4 bits - // and always put input to the low 4 bits - // - Line->Buffer[Line->Size] = (UINT8) Value; - Line->Size++; - High = FALSE; - } else { - - Old = Line->Buffer[FCol - 1]; - - // - // always put the input to the low 4 bits - // - Old = (UINT8) (Old & 0x0f); - Old = (UINT8) (Old << 4); - Old = (UINT8) (Value + Old); - Line->Buffer[FCol - 1] = Old; - - // - // at the low 4 bits of the last character of a full line - // so if no next line, need to create a new line - // - if (High == FALSE && FCol == 0x10) { - - HBufferImageOnlyLineNeedRefresh = FALSE; - HBufferImageNeedRefresh = TRUE; + HBufferImageOnlyLineNeedRefresh = FALSE; + HBufferImageNeedRefresh = TRUE; if (Line->Link.ForwardLink == HBufferImage.ListHead) { // @@ -1431,7 +1209,7 @@ Returns: // // if already at end of this line, scroll it to the start of next line // - if (FCol == 0x10 && High == FALSE) { + if (FCol == 0x10 && !High) { // // definitely has next line // @@ -1469,83 +1247,151 @@ Returns: return EFI_SUCCESS; } -BOOLEAN -HInCurrentScreen ( - IN UINTN FileRow +/** + Delete the previous character. + + @retval EFI_SUCCESS The operationw as successful. +**/ +EFI_STATUS +EFIAPI +HBufferImageDoBackspace ( + VOID ) -/*++ +{ + HEFI_EDITOR_LINE *Line; -Routine Description: + UINTN FileColumn; + UINTN FPos; + BOOLEAN LastLine; - Check user specified FileRow and FileCol is in current screen + // + // variable initialization + // + LastLine = FALSE; -Arguments: + // + // already the first character + // + if (HBufferImage.BufferPosition.Row == 1 && HBufferImage.BufferPosition.Column == 1) { + return EFI_SUCCESS; + } - FileRow -- Row of file position ( start from 1 ) + FPos = (HBufferImage.BufferPosition.Row - 1) * 0x10 + HBufferImage.BufferPosition.Column - 1; + FileColumn = HBufferImage.BufferPosition.Column; -Returns: + Line = HBufferImage.CurrentLine; + LastLine = FALSE; + if (Line->Link.ForwardLink == HBufferImage.ListHead && FileColumn > 1) { + LastLine = TRUE; + } - TRUE - FALSE + HBufferImageDeleteCharacterFromBuffer (FPos - 1, 1, NULL); ---*/ -{ - if (FileRow >= HBufferImage.LowVisibleRow && FileRow <= HBufferImage.LowVisibleRow + (HMainEditor.ScreenSize.Row - 5) - 1) { - return TRUE; + // + // if is the last line + // then only this line need to be refreshed + // + if (LastLine) { + HBufferImageNeedRefresh = FALSE; + HBufferImageOnlyLineNeedRefresh = TRUE; + } else { + HBufferImageNeedRefresh = TRUE; + HBufferImageOnlyLineNeedRefresh = FALSE; } - return FALSE; + if (!HBufferImage.Modified) { + HBufferImage.Modified = TRUE; + } + + return EFI_SUCCESS; } -BOOLEAN -HAboveCurrentScreen ( - IN UINTN FileRow +/** + ASCII key + Backspace + return. + + @param[in] Char The input char. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_LOAD_ERROR A load error occured. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ +EFI_STATUS +EFIAPI +HBufferImageDoCharInput ( + IN CHAR16 Char ) -/*++ +{ + EFI_STATUS Status; -Routine Description: + Status = EFI_SUCCESS; - Check user specified FileRow is above current screen + switch (Char) { + case 0: + break; -Arguments: + case 0x08: + Status = HBufferImageDoBackspace (); + break; - FileRow -- Row of file position ( start from 1 ) - -Returns: + case 0x09: + case 0x0a: + case 0x0d: + // + // Tabs, Returns are thought as nothing + // + break; - TRUE - FALSE + default: + // + // DEAL WITH ASCII CHAR, filter out thing like ctrl+f + // + if (Char > 127 || Char < 32) { + Status = StatusBarSetStatusString (L"Unknown Command"); + } else { + Status = HBufferImageAddChar (Char); + } ---*/ -{ - if (FileRow < HBufferImage.LowVisibleRow) { - return TRUE; + break; } - return FALSE; + return Status; } +/** + Check user specified FileRow is above current screen. + + @param[in] FileRow Row of file position ( start from 1 ). + + @retval TRUE It is above the current screen. + @retval FALSE It is not above the current screen. + +**/ BOOLEAN -HUnderCurrentScreen ( +HAboveCurrentScreen ( IN UINTN FileRow ) -/*++ - -Routine Description: - - Check user specified FileRow is under current screen +{ + if (FileRow < HBufferImage.LowVisibleRow) { + return TRUE; + } -Arguments: + return FALSE; +} - FileRow -- Row of file position ( start from 1 ) +/** + Check user specified FileRow is under current screen. -Returns: + @param[in] FileRow Row of file position ( start from 1 ). - TRUE - FALSE + @retval TRUE It is under the current screen. + @retval FALSE It is not under the current screen. ---*/ +**/ +BOOLEAN +HUnderCurrentScreen ( + IN UINTN FileRow + ) { if (FileRow > HBufferImage.LowVisibleRow + (HMainEditor.ScreenSize.Row - 5) - 1) { return TRUE; @@ -1554,29 +1400,19 @@ Returns: return FALSE; } +/** + According to cursor's file position, adjust screen display. + + @param[in] NewFilePosRow Row of file position ( start from 1 ). + @param[in] NewFilePosCol Column of file position ( start from 1 ). + @param[in] HighBits Cursor will on high4 bits or low4 bits. +**/ VOID HBufferImageMovePosition ( IN UINTN NewFilePosRow, IN UINTN NewFilePosCol, IN BOOLEAN HighBits ) -/*++ - -Routine Description: - - According to cursor's file position, adjust screen display - -Arguments: - - NewFilePosRow -- Row of file position ( start from 1 ) - NewFilePosCol -- Column of file position ( start from 1 ) - HighBits -- cursor will on high4 bits or low4 bits - -Returns: - - None - ---*/ { INTN RowGap; UINTN Abs; @@ -1620,7 +1456,7 @@ Returns: // HBufferImage.BufferPosition.Row = NewFilePosRow; if (RowGap <= 0) { - Abs = -RowGap; + Abs = (UINTN)ABS(RowGap); HBufferImage.DisplayPosition.Row -= Abs; } else { HBufferImage.DisplayPosition.Row += RowGap; @@ -1641,7 +1477,7 @@ Returns: NewDisplayCol++; } - if (HighBits == FALSE) { + if (!HighBits) { NewDisplayCol++; } @@ -1654,25 +1490,15 @@ Returns: } +/** + Scroll cursor to right. + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageScrollRight ( VOID ) -/*++ - -Routine Description: - - Scroll cursor to right - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HEFI_EDITOR_LINE *Line; UINTN FRow; @@ -1722,25 +1548,15 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -HBufferImageScrollLeft ( - VOID - ) -/*++ +/** + Scroll cursor to left. -Routine Description: - - Scroll cursor to left - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +HBufferImageScrollLeft ( + VOID + ) { HEFI_EDITOR_LINE *Line; @@ -1781,25 +1597,15 @@ Returns: return EFI_SUCCESS; } +/** + Scroll cursor to the next line + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageScrollDown ( VOID ) -/*++ - -Routine Description: - - Scroll cursor to the next line - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HEFI_EDITOR_LINE *Line; UINTN FRow; @@ -1836,25 +1642,15 @@ Returns: return EFI_SUCCESS; } +/** + Scroll cursor to previous line + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageScrollUp ( VOID ) -/*++ - -Routine Description: - - Scroll cursor to previous line - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HEFI_EDITOR_LINE *Line; UINTN FRow; @@ -1880,25 +1676,15 @@ Returns: return EFI_SUCCESS; } +/** + Scroll cursor to next page + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImagePageDown ( VOID ) -/*++ - -Routine Description: - - Scroll cursor to next page - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HEFI_EDITOR_LINE *Line; UINTN FRow; @@ -1931,7 +1717,7 @@ Returns: // // if that line, is not that long, so move to the end of that line // - if (FCol > Line->Size) { + if (Line != NULL && FCol > Line->Size) { FCol = Line->Size + 1; HighBits = TRUE; } @@ -1943,25 +1729,15 @@ Returns: return EFI_SUCCESS; } +/** + Scroll cursor to previous page + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImagePageUp ( VOID ) -/*++ - -Routine Description: - - Scroll cursor to previous page - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HEFI_EDITOR_LINE *Line; UINTN FRow; @@ -2001,25 +1777,15 @@ Returns: return EFI_SUCCESS; } +/** + Scroll cursor to start of line + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HBufferImageHome ( VOID ) -/*++ - -Routine Description: - - Scroll cursor to start of line - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HEFI_EDITOR_LINE *Line; UINTN FRow; @@ -2043,25 +1809,15 @@ Returns: return EFI_SUCCESS; } +/** + Scroll cursor to end of line. + + @retval EFI_SUCCESS Teh operation was successful. +**/ EFI_STATUS HBufferImageEnd ( VOID ) -/*++ - -Routine Description: - - Scroll cursor to end of line - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HEFI_EDITOR_LINE *Line; UINTN FRow; @@ -2092,6 +1848,11 @@ Returns: return EFI_SUCCESS; } +/** + Get the size of the open buffer. + + @retval The size in bytes. +**/ UINTN HBufferImageGetTotalSize ( VOID @@ -2122,28 +1883,21 @@ HBufferImageGetTotalSize ( return Size; } +/** + Delete character from buffer. + + @param[in] Pos Position, Pos starting from 0. + @param[in] Count The Count of characters to delete. + @param[out] DeleteBuffer The DeleteBuffer. + + @retval EFI_SUCCESS Success +**/ EFI_STATUS HBufferImageDeleteCharacterFromBuffer ( IN UINTN Pos, IN UINTN Count, OUT UINT8 *DeleteBuffer ) -/*++ -Routine Description: - - Delete character from buffer - -Arguments: - - Pos - Position, Pos starting from 0 - Count - Count - DeleteBuffer - DeleteBuffer - -Returns: - - EFI_SUCCESS Success - ---*/ { UINTN Index; @@ -2264,28 +2018,21 @@ Returns: return EFI_SUCCESS; } +/** + Add character to buffer, add before pos. + + @param[in] Pos Position, Pos starting from 0. + @param[in] Count Count of characters to add. + @param[in] AddBuffer Add buffer. + + @retval EFI_SUCCESS Success. +**/ EFI_STATUS HBufferImageAddCharacterToBuffer ( IN UINTN Pos, IN UINTN Count, IN UINT8 *AddBuffer ) -/*++' -Routine Description: - - Add character to buffer, add before pos - -Arguments: - - Pos - Position, Pos starting from 0 - Count - Count - AddBuffer - Add buffer - -Returns: - - EFI_SUCCESS Success - ---*/ { INTN Index; @@ -2378,94 +2125,16 @@ Returns: return EFI_SUCCESS; } -EFI_STATUS -HBufferImageDoBackspace ( - VOID - ) -/*++ - -Routine Description: - - delete the previous character - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ -{ - HEFI_EDITOR_LINE *Line; - - UINTN FileColumn; - UINTN FPos; - BOOLEAN LastLine; - - // - // variable initialization - // - LastLine = FALSE; - - // - // already the first character - // - if (HBufferImage.BufferPosition.Row == 1 && HBufferImage.BufferPosition.Column == 1) { - return EFI_SUCCESS; - } - - FPos = (HBufferImage.BufferPosition.Row - 1) * 0x10 + HBufferImage.BufferPosition.Column - 1; - - FileColumn = HBufferImage.BufferPosition.Column; - - Line = HBufferImage.CurrentLine; - LastLine = FALSE; - if (Line->Link.ForwardLink == HBufferImage.ListHead && FileColumn > 1) { - LastLine = TRUE; - } - - HBufferImageDeleteCharacterFromBuffer (FPos - 1, 1, NULL); - - // - // if is the last line - // then only this line need to be refreshed - // - if (LastLine) { - HBufferImageNeedRefresh = FALSE; - HBufferImageOnlyLineNeedRefresh = TRUE; - } else { - HBufferImageNeedRefresh = TRUE; - HBufferImageOnlyLineNeedRefresh = FALSE; - } - - if (!HBufferImage.Modified) { - HBufferImage.Modified = TRUE; - } - - return EFI_SUCCESS; -} +/** + Delete current character from line. + @retval EFI_SUCCESS The operationw as successful. +**/ EFI_STATUS +EFIAPI HBufferImageDoDelete ( VOID ) -/*++ - -Routine Description: - - Delete current character from line - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { HEFI_EDITOR_LINE *Line; @@ -2513,30 +2182,40 @@ Returns: return EFI_SUCCESS; } +/** + Change the raw buffer to a list of lines for the UI. + + @param[in] Buffer The pointer to the buffer to fill. + @param[in] Bytes The size of the buffer in bytes. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ EFI_STATUS +EFIAPI HBufferImageBufferToList ( IN VOID *Buffer, IN UINTN Bytes ) { - UINTN i; - UINTN j; + UINTN TempI; + UINTN TempJ; UINTN Left; HEFI_EDITOR_LINE *Line; UINT8 *BufferPtr; - i = 0; + TempI = 0; Left = 0; BufferPtr = (UINT8 *) Buffer; // // parse file content line by line // - while (i < Bytes) { - if (Bytes - i >= 0x10) { + while (TempI < Bytes) { + if (Bytes - TempI >= 0x10) { Left = 0x10; } else { - Left = Bytes - i; + Left = Bytes - TempI; } // @@ -2549,9 +2228,9 @@ HBufferImageBufferToList ( Line->Size = Left; - for (j = 0; j < Left; j++) { - Line->Buffer[j] = BufferPtr[i]; - i++; + for (TempJ = 0; TempJ < Left; TempJ++) { + Line->Buffer[TempJ] = BufferPtr[TempI]; + TempI++; } } @@ -2569,7 +2248,16 @@ HBufferImageBufferToList ( return EFI_SUCCESS; } +/** + Change the list of lines from the UI to a raw buffer. + + @param[in] Buffer The pointer to the buffer to fill. + @param[in] Bytes The size of the buffer in bytes. + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS +EFIAPI HBufferImageListToBuffer ( IN VOID *Buffer, IN UINTN Bytes @@ -2599,6 +2287,7 @@ HBufferImageListToBuffer ( Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST); + //@todo shouldn't this be an error??? if (Count + Line->Size > Bytes) { return EFI_SUCCESS; } @@ -2616,14 +2305,21 @@ HBufferImageListToBuffer ( return EFI_SUCCESS; } +/** + Move the mouse in the image buffer. + + @param[in] TextX The x-coordinate. + @param[in] TextY The y-coordinate. +**/ VOID +EFIAPI HBufferImageAdjustMousePosition ( IN INT32 TextX, IN INT32 TextY ) { - UINTN X; - UINTN Y; + UINTN TempX; + UINTN TempY; UINTN AbsX; UINTN AbsY; @@ -2632,7 +2328,7 @@ HBufferImageAdjustMousePosition ( // This function will change it to MousePosition // // - // get absolute X value + // get absolute TempX value // if (TextX >= 0) { AbsX = TextX; @@ -2640,7 +2336,7 @@ HBufferImageAdjustMousePosition ( AbsX = -TextX; } // - // get absolute Y value + // get absolute TempY value // if (TextY >= 0) { AbsY = TextY; @@ -2648,49 +2344,153 @@ HBufferImageAdjustMousePosition ( AbsY = -TextY; } - X = HBufferImage.MousePosition.Column; - Y = HBufferImage.MousePosition.Row; + TempX = HBufferImage.MousePosition.Column; + TempY = HBufferImage.MousePosition.Row; if (TextX >= 0) { - X += TextX; + TempX += TextX; } else { - if (X >= AbsX) { - X -= AbsX; + if (TempX >= AbsX) { + TempX -= AbsX; } else { - X = 0; + TempX = 0; } } if (TextY >= 0) { - Y += TextY; + TempY += TextY; } else { - if (Y >= AbsY) { - Y -= AbsY; + if (TempY >= AbsY) { + TempY -= AbsY; } else { - Y = 0; + TempY = 0; } } // // check whether new mouse column position is beyond screen // if not, adjust it // - if (X >= 10 && X <= (10 + 0x10 * 3 - 1)) { - HBufferImage.MousePosition.Column = X; - } else if (X < 10) { + if (TempX >= 10 && TempX <= (10 + 0x10 * 3 - 1)) { + HBufferImage.MousePosition.Column = TempX; + } else if (TempX < 10) { HBufferImage.MousePosition.Column = 10; - } else if (X > (10 + 0x10 * 3 - 1)) { + } else if (TempX > (10 + 0x10 * 3 - 1)) { HBufferImage.MousePosition.Column = 10 + 0x10 * 3 - 1; } // // check whether new mouse row position is beyond screen // if not, adjust it // - if (Y >= 2 && Y <= (HMainEditor.ScreenSize.Row - 4)) { - HBufferImage.MousePosition.Row = Y; - } else if (Y < 2) { + if (TempY >= 2 && TempY <= (HMainEditor.ScreenSize.Row - 4)) { + HBufferImage.MousePosition.Row = TempY; + } else if (TempY < 2) { HBufferImage.MousePosition.Row = 2; - } else if (Y > (HMainEditor.ScreenSize.Row - 4)) { + } else if (TempY > (HMainEditor.ScreenSize.Row - 4)) { HBufferImage.MousePosition.Row = (HMainEditor.ScreenSize.Row - 4); } } + +/** + Dispatch input to different handler + + @param[in] Key The input key: + the keys can be: + ASCII KEY + Backspace/Delete + Direction key: up/down/left/right/pgup/pgdn + Home/End + INS + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_LOAD_ERROR A load error occured. + @retval EFI_OUT_OF_RESOURCES A Memory allocation failed. +**/ +EFI_STATUS +HBufferImageHandleInput ( + IN EFI_INPUT_KEY *Key + ) +{ + EFI_STATUS Status; + + Status = EFI_SUCCESS; + + switch (Key->ScanCode) { + // + // ordinary key + // + case SCAN_NULL: + Status = HBufferImageDoCharInput (Key->UnicodeChar); + break; + + // + // up arrow + // + case SCAN_UP: + Status = HBufferImageScrollUp (); + break; + + // + // down arrow + // + case SCAN_DOWN: + Status = HBufferImageScrollDown (); + break; + + // + // right arrow + // + case SCAN_RIGHT: + Status = HBufferImageScrollRight (); + break; + + // + // left arrow + // + case SCAN_LEFT: + Status = HBufferImageScrollLeft (); + break; + + // + // page up + // + case SCAN_PAGE_UP: + Status = HBufferImagePageUp (); + break; + + // + // page down + // + case SCAN_PAGE_DOWN: + Status = HBufferImagePageDown (); + break; + + // + // delete + // + case SCAN_DELETE: + Status = HBufferImageDoDelete (); + break; + + // + // home + // + case SCAN_HOME: + Status = HBufferImageHome (); + break; + + // + // end + // + case SCAN_END: + Status = HBufferImageEnd (); + break; + + default: + Status = StatusBarSetStatusString (L"Unknown Command"); + break; + } + + return Status; +} +