add Edit and HexEdit commands.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11436 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jcarsey
2011-03-25 21:15:07 +00:00
parent 5a0fe66eda
commit 632820d1cf
28 changed files with 14014 additions and 0 deletions

View File

@@ -0,0 +1,158 @@
/** @file
Main file for Edit shell Debug1 function.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "UefiShellDebug1CommandsLib.h"
#include "TextEditor.h"
/**
Function for 'edit' command.
@param[in] ImageHandle Handle to the Image (NULL if Internal).
@param[in] SystemTable Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEdit (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
CHAR16 *Buffer;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
LIST_ENTRY *Package;
CONST CHAR16 *Cwd;
CHAR16 *Nfs;
CHAR16 *Spot;
// SHELL_FILE_HANDLE TempHandle;
Buffer = NULL;
ShellStatus = SHELL_SUCCESS;
Nfs = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
FreePool(ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
}
} else {
if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Cwd = gEfiShellProtocol->GetCurDir(NULL);
if (Cwd == NULL) {
Cwd = ShellGetEnvironmentVariable(L"path");
if (Cwd != NULL) {
Nfs = StrnCatGrow(&Nfs, NULL, Cwd+3, 0);
if (Nfs != NULL) {
Spot = StrStr(Nfs, L";");
if (Spot != NULL) {
*Spot = CHAR_NULL;
}
Spot = StrStr(Nfs, L"\\");
if (Spot != NULL) {
Spot[1] = CHAR_NULL;
}
gEfiShellProtocol->SetCurDir(NULL, Nfs);
FreePool(Nfs);
}
}
}
Status = MainEditorInit ();
if (EFI_ERROR (Status)) {
gST->ConOut->ClearScreen (gST->ConOut);
gST->ConOut->EnableCursor (gST->ConOut, TRUE);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle);
} else {
MainEditorBackup ();
//
// if editor launched with file named
//
if (ShellCommandLineGetCount(Package) == 2) {
FileBufferSetFileName (ShellCommandLineGetRawValue(Package, 1));
// if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
// Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
// if (!EFI_ERROR(Status)) {
// ShellCloseFile(&TempHandle);
// }
// }
}
Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE);
if (!EFI_ERROR (Status)) {
MainEditorRefresh ();
Status = MainEditorKeyInput ();
}
if (Status != EFI_OUT_OF_RESOURCES) {
//
// back up the status string
//
Buffer = CatSPrint (NULL, L"%s", StatusBarGetString());
}
MainEditorCleanup ();
//
// print editor exit code on screen
//
if (Status == EFI_SUCCESS) {
} else if (Status == EFI_OUT_OF_RESOURCES) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_OUT_MEM), gShellDebug1HiiHandle);
} else {
if (Buffer != NULL) {
if (StrCmp (Buffer, L"") != 0) {
//
// print out the status string
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);
}
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);
}
}
if (Status != EFI_OUT_OF_RESOURCES) {
SHELL_FREE_NON_NULL (Buffer);
}
}
}
ShellCommandLineFreeVarList (Package);
}
return ShellStatus;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,263 @@
/** @file
Declares filebuffer interface functions.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_FILE_BUFFER_H_
#define _LIB_FILE_BUFFER_H_
#include "TextEditorTypes.h"
/**
Initialization function for FileBuffer.
@param EFI_SUCCESS The initialization was successful.
@param EFI_LOAD_ERROR A default name could not be created.
@param EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferInit (
VOID
);
/**
Cleanup function for FileBuffer.
@retval EFI_SUCCESS The cleanup was successful.
**/
EFI_STATUS
EFIAPI
FileBufferCleanup (
VOID
);
/**
Refresh the screen with whats in the buffer.
@retval EFI_SUCCESS The refresh was successful.
@retval EFI_LOAD_ERROR There was an error finding what to write.
**/
EFI_STATUS
EFIAPI
FileBufferRefresh (
VOID
);
/**
Dispatch input to different handler
@param[in] Key The input key. One of:
ASCII KEY
Backspace/Delete
Return
Direction key: up/down/left/right/pgup/pgdn
Home/End
INS
@retval EFI_SUCCESS The dispatch was done successfully.
@retval EFI_LOAD_ERROR The dispatch was not successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferHandleInput (
IN CONST EFI_INPUT_KEY * Key
);
/**
Backup function for FileBuffer. Only backup the following items:
Mouse/Cursor position
File Name, Type, ReadOnly, Modified
Insert Mode
This is for making the file buffer refresh as few as possible.
@retval EFI_SUCCESS The backup operation was successful.
**/
EFI_STATUS
EFIAPI
FileBufferBackup (
VOID
);
/**
Set the cursor position according to FileBuffer.DisplayPosition.
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
FileBufferRestorePosition (
VOID
);
/**
Set FileName field in FileBuffer.
@param Str The file name to set.
@retval EFI_SUCCESS The filename was successfully set.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@retval EFI_INVALID_PARAMETER Str is not a valid filename.
**/
EFI_STATUS
EFIAPI
FileBufferSetFileName (
IN CONST CHAR16 *Str
);
/**
Read a file from disk into the FileBuffer.
@param[in] FileName The filename to read.
@param[in] Recover TRUE if is for recover mode, no information printouts.
@retval EFI_SUCCESS The load was successful.
@retval EFI_LOAD_ERROR The load failed.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
@retval EFI_INVALID_PARAMETER FileName is a directory.
**/
EFI_STATUS
EFIAPI
FileBufferRead (
IN CONST CHAR16 *FileName,
IN CONST BOOLEAN Recover
);
/**
Save lines in FileBuffer to disk
@param[in] FileName The file name for writing.
@retval EFI_SUCCESS Data was written.
@retval EFI_LOAD_ERROR
@retval EFI_OUT_OF_RESOURCES There were not enough resources to write the file.
**/
EFI_STATUS
EFIAPI
FileBufferSave (
CONST CHAR16 *FileName
);
/**
According to cursor's file position, adjust screen display
@param[in] NewFilePosRow The row of file position ( start from 1 ).
@param[in] NewFilePosCol The column of file position ( start from 1 ).
**/
VOID
EFIAPI
FileBufferMovePosition (
IN CONST UINTN NewFilePosRow,
IN CONST UINTN NewFilePosCol
);
/**
Cut current line out and return a pointer to it.
@param[out] CutLine Upon a successful return pointer to the pointer to
the allocated cut line.
@retval EFI_SUCCESS The cut was successful.
@retval EFI_NOT_FOUND There was no selection to cut.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferCutLine (
OUT EFI_EDITOR_LINE **CutLine
);
/**
Paste a line into line list.
@retval EFI_SUCCESS The paste was successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferPasteLine (
VOID
);
/**
Search string from current position on in file
@param[in] Str The search string.
@param[in] Offset The offset from current position.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_NOT_FOUND The string Str was not found.
**/
EFI_STATUS
EFIAPI
FileBufferSearch (
IN CONST CHAR16 *Str,
IN CONST UINTN Offset
);
/**
Replace SearchLen characters from current position on with Replace.
This will modify the current buffer at the current position.
@param[in] Replace The string to replace.
@param[in] SearchLen Search string's length.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
EFIAPI
FileBufferReplace (
IN CONST CHAR16 *Replace,
IN CONST UINTN SearchLen
);
/**
Search and replace operation.
@param[in] SearchStr The string to search for.
@param[in] ReplaceStr The string to replace with.
@param[in] Offset The column to start at.
**/
EFI_STATUS
EFIAPI
FileBufferReplaceAll (
IN CHAR16 *SearchStr,
IN CHAR16 *ReplaceStr,
IN UINTN Offset
);
/**
Move the mouse cursor position.
@param[in] TextX The new x-coordinate.
@param[in] TextY The new y-coordinate.
**/
VOID
EFIAPI
FileBufferAdjustMousePosition (
IN CONST INT32 TextX,
IN CONST INT32 TextY
);
/**
Set the modified state to TRUE.
**/
VOID
EFIAPI
FileBufferSetModified (
VOID
);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,77 @@
/** @file
Declares editor interface functions.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_EDITOR_H_
#define _LIB_EDITOR_H_
#include "TextEditorTypes.h"
/**
The initialization function for MainEditor.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occured.
**/
EFI_STATUS
EFIAPI
MainEditorInit (
VOID
);
/**
The cleanup function for MainEditor.
@retval EFI_SUCCESS The operation was successful.
@retval EFI_LOAD_ERROR A load error occured.
**/
EFI_STATUS
EFIAPI
MainEditorCleanup (
VOID
);
/**
Refresh the main editor component.
**/
VOID
EFIAPI
MainEditorRefresh (
VOID
);
/**
Handle user key input. This routes to other functions for the actions.
@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
MainEditorKeyInput (
VOID
);
/**
Backup function for MainEditor
@retval EFI_SUCCESS The operation was successful.
**/
EFI_STATUS
EFIAPI
MainEditorBackup (
VOID
);
#endif

View File

@@ -0,0 +1,92 @@
/** @file
Implementation of various string and line routines.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "TextEditor.h"
#include "Misc.h"
/**
Duplicate a EFI_EDITOR_LINE structure.
@param Src The line structure to copy from.
@retval NULL A memory allocation failed.
@return a pointer to the newly allcoated line.
**/
EFI_EDITOR_LINE *
EFIAPI
LineDup (
IN EFI_EDITOR_LINE *Src
)
{
EFI_EDITOR_LINE *Dest;
//
// allocate for the line structure
//
Dest = AllocateZeroPool (sizeof (EFI_EDITOR_LINE));
if (Dest == NULL) {
return NULL;
}
//
// allocate and set the line buffer
//
Dest->Buffer = CatSPrint (NULL, L"%s", Src->Buffer);
if (Dest->Buffer == NULL) {
FreePool (Dest);
return NULL;
}
//
// set the other structure members
//
Dest->Signature = LINE_LIST_SIGNATURE;
Dest->Size = Src->Size;
Dest->TotalSize = Dest->Size;
Dest->Type = Src->Type;
Dest->Link = Src->Link;
return Dest;
}
/**
Free a EFI_EDITOR_LINE structure.
@param Src The line structure to free.
**/
VOID
EFIAPI
LineFree (
IN EFI_EDITOR_LINE *Src
)
{
if (Src == NULL) {
return ;
}
//
// free the line buffer and then the line structure itself
//
SHELL_FREE_NON_NULL (Src->Buffer);
SHELL_FREE_NON_NULL (Src);
}

View File

@@ -0,0 +1,52 @@
/** @file
Declares generic editor helper functions.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _LIB_MISC_H_
#define _LIB_MISC_H_
#include "TextEditorTypes.h"
/**
Free a EFI_EDITOR_LINE structure.
@param Src The line structure to free.
**/
VOID
EFIAPI
LineFree (
IN EFI_EDITOR_LINE *Src
);
/**
Duplicate a EFI_EDITOR_LINE structure.
@param Src The line structure to copy from.
@retval NULL A memory allocation failed.
@return a pointer to the newly allcoated line.
**/
EFI_EDITOR_LINE *
EFIAPI
LineDup (
IN EFI_EDITOR_LINE *Src
);
#endif

View File

@@ -0,0 +1,32 @@
/** @file
Main include file for Edit shell Debug1 function.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _EFI_EDIT_H_
#define _EFI_EDIT_H_
#include "TextEditorTypes.h"
#include "MainTextEditor.h"
#include "FileBuffer.h"
#include "EditTitleBar.h"
#include "EditStatusBar.h"
#include "EditInputBar.h"
#include "EditMenuBar.h"
#include "Misc.h"
extern EFI_EDITOR_GLOBAL_EDITOR MainEditor;
extern BOOLEAN EditorFirst;
extern BOOLEAN EditorExit;
#endif // _EFI_EDIT_H_

View File

@@ -0,0 +1,102 @@
/** @file
Declares editor types.
Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved. <BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _EDITOR_TYPE_H_
#define _EDITOR_TYPE_H_
#include "UefiShellDebug1CommandsLib.h"
#include "EditTitleBar.h"
#include "EditMenuBar.h"
#define MIN_POOL_SIZE 125
#define MAX_STRING_LENGTH 127
typedef struct {
UINTN Row;
UINTN Column;
} EFI_EDITOR_POSITION;
typedef
EFI_STATUS
(*EFI_MENU_ITEM_FUNCTION) (
VOID
);
typedef enum {
NewLineTypeDefault,
NewLineTypeLineFeed,
NewLineTypeCarriageReturn,
NewLineTypeCarriageReturnLineFeed,
NewLineTypeLineFeedCarriageReturn,
NewLineTypeUnknown
} EE_NEWLINE_TYPE;
#define LINE_LIST_SIGNATURE 'eell'
typedef struct _EFI_EDITOR_LINE {
UINTN Signature;
CHAR16 *Buffer;
UINTN Size; // unit is Unicode
UINTN TotalSize; // unit is Unicode, exclude CHAR_NULL
EE_NEWLINE_TYPE Type;
LIST_ENTRY Link;
} EFI_EDITOR_LINE;
typedef struct {
UINT32 Foreground : 4;
UINT32 Background : 4;
} EFI_EDITOR_COLOR_ATTRIBUTES;
typedef union {
EFI_EDITOR_COLOR_ATTRIBUTES Colors;
UINTN Data;
} EFI_EDITOR_COLOR_UNION;
typedef struct {
UINTN Columns;
UINTN Rows;
} EFI_EDITOR_TEXT_MODE;
typedef struct {
CHAR16 *FileName; // file name current edited in editor
EDIT_FILE_TYPE FileType; // Unicode file or ASCII file
LIST_ENTRY *ListHead; // list head of lines
EFI_EDITOR_LINE *Lines; // lines of current file
UINTN NumLines; // total line numbers
EFI_EDITOR_POSITION DisplayPosition; // cursor position in screen
EFI_EDITOR_POSITION FilePosition; // cursor position in file
EFI_EDITOR_POSITION MousePosition; // mouse position in screen
// file position of first byte displayed on screen
//
EFI_EDITOR_POSITION LowVisibleRange;
BOOLEAN FileModified; // file is modified or not
BOOLEAN ModeInsert; // input mode INS or OVR
BOOLEAN ReadOnly; // file is read-only or not
EFI_EDITOR_LINE *CurrentLine; // current line cursor is at
} EFI_EDITOR_FILE_BUFFER;
typedef struct {
EFI_EDITOR_FILE_BUFFER *FileBuffer;
EFI_EDITOR_COLOR_UNION ColorAttributes;
EFI_EDITOR_POSITION ScreenSize; // row number and column number
EFI_EDITOR_LINE *CutLine; // clip board
BOOLEAN MouseSupported;
EFI_SIMPLE_POINTER_PROTOCOL *MouseInterface;
INT32 MouseAccumulatorX;
INT32 MouseAccumulatorY;
} EFI_EDITOR_GLOBAL_EDITOR;
#endif