summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c
diff options
context:
space:
mode:
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c')
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c273
1 files changed, 147 insertions, 126 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c
index 0df0b31..e94236d 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c
@@ -9,11 +9,11 @@
#include "UefiShellDebug1CommandsLib.h"
-STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
- {L"-n", TypeValue},
- {L"-s", TypeValue},
- {NULL, TypeMax}
- };
+STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
+ { L"-n", TypeValue },
+ { L"-s", TypeValue },
+ { NULL, TypeMax }
+};
typedef enum {
OutOfDiffPoint,
@@ -25,10 +25,10 @@ typedef enum {
// Buffer type, for reading both file operands in chunks.
//
typedef struct {
- UINT8 *Data; // dynamically allocated buffer
- UINTN Allocated; // the allocated size of Data
- UINTN Next; // next position in Data to fetch a byte at
- UINTN Left; // number of bytes left in Data for fetching at Next
+ UINT8 *Data; // dynamically allocated buffer
+ UINTN Allocated; // the allocated size of Data
+ UINTN Next; // next position in Data to fetch a byte at
+ UINTN Left; // number of bytes left in Data for fetching at Next
} FILE_BUFFER;
/**
@@ -43,7 +43,7 @@ typedef struct {
**/
VOID
-PrintDifferentPoint(
+PrintDifferentPoint (
CONST CHAR16 *FileName,
CHAR16 *FileTag,
UINT8 *Buffer,
@@ -52,7 +52,7 @@ PrintDifferentPoint(
UINT64 DifferentBytes
)
{
- UINTN Index;
+ UINTN Index;
ShellPrintEx (-1, -1, L"%s: %s\r\n %08x:", FileTag, FileName, Address);
@@ -73,7 +73,7 @@ PrintDifferentPoint(
// Print data in char-format.
//
for (Index = 0; Index < BufferSize; Index++) {
- if (Buffer[Index] >= 0x20 && Buffer[Index] <= 0x7E) {
+ if ((Buffer[Index] >= 0x20) && (Buffer[Index] <= 0x7E)) {
ShellPrintEx (-1, -1, L"%c", Buffer[Index]);
} else {
//
@@ -97,7 +97,7 @@ PrintDifferentPoint(
STATIC
VOID
FileBufferInit (
- OUT FILE_BUFFER *FileBuffer
+ OUT FILE_BUFFER *FileBuffer
)
{
FileBuffer->Allocated = PcdGet32 (PcdShellFileOperationSize);
@@ -116,7 +116,7 @@ FileBufferInit (
STATIC
VOID
FileBufferUninit (
- IN OUT FILE_BUFFER *FileBuffer
+ IN OUT FILE_BUFFER *FileBuffer
)
{
SHELL_FREE_NON_NULL (FileBuffer->Data);
@@ -154,26 +154,31 @@ FileBufferUninit (
STATIC
EFI_STATUS
FileBufferReadByte (
- IN SHELL_FILE_HANDLE FileHandle,
- IN OUT FILE_BUFFER *FileBuffer,
- OUT UINTN *BytesRead,
- OUT UINT8 *Byte
+ IN SHELL_FILE_HANDLE FileHandle,
+ IN OUT FILE_BUFFER *FileBuffer,
+ OUT UINTN *BytesRead,
+ OUT UINT8 *Byte
)
{
- UINTN ReadSize;
- EFI_STATUS Status;
+ UINTN ReadSize;
+ EFI_STATUS Status;
if (FileBuffer->Left == 0) {
ReadSize = FileBuffer->Allocated;
- Status = gEfiShellProtocol->ReadFile (FileHandle, &ReadSize,
- FileBuffer->Data);
+ Status = gEfiShellProtocol->ReadFile (
+ FileHandle,
+ &ReadSize,
+ FileBuffer->Data
+ );
if (EFI_ERROR (Status)) {
return Status;
}
+
if (ReadSize == 0) {
*BytesRead = 0;
return EFI_SUCCESS;
}
+
FileBuffer->Next = 0;
FileBuffer->Left = ReadSize;
}
@@ -199,112 +204,114 @@ ShellCommandRunComp (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
- EFI_STATUS Status;
- LIST_ENTRY *Package;
- CHAR16 *ProblemParam;
- CHAR16 *FileName1;
- CHAR16 *FileName2;
- CONST CHAR16 *TempParam;
- SHELL_STATUS ShellStatus;
- SHELL_FILE_HANDLE FileHandle1;
- SHELL_FILE_HANDLE FileHandle2;
- UINT64 Size1;
- UINT64 Size2;
- UINT64 DifferentBytes;
- UINT64 DifferentCount;
- UINT8 DiffPointNumber;
- UINT8 OneByteFromFile1;
- UINT8 OneByteFromFile2;
- UINT8 *DataFromFile1;
- UINT8 *DataFromFile2;
- FILE_BUFFER FileBuffer1;
- FILE_BUFFER FileBuffer2;
- UINTN InsertPosition1;
- UINTN InsertPosition2;
- UINTN DataSizeFromFile1;
- UINTN DataSizeFromFile2;
- UINTN TempAddress;
- UINTN Index;
- UINTN DiffPointAddress;
- READ_STATUS ReadStatus;
-
- ShellStatus = SHELL_SUCCESS;
- Status = EFI_SUCCESS;
- FileName1 = NULL;
- FileName2 = NULL;
- FileHandle1 = NULL;
- FileHandle2 = NULL;
- DataFromFile1 = NULL;
- DataFromFile2 = NULL;
- ReadStatus = OutOfDiffPoint;
- DifferentCount = 10;
- DifferentBytes = 4;
- DiffPointNumber = 0;
- InsertPosition1 = 0;
- InsertPosition2 = 0;
- TempAddress = 0;
- DiffPointAddress = 0;
+ EFI_STATUS Status;
+ LIST_ENTRY *Package;
+ CHAR16 *ProblemParam;
+ CHAR16 *FileName1;
+ CHAR16 *FileName2;
+ CONST CHAR16 *TempParam;
+ SHELL_STATUS ShellStatus;
+ SHELL_FILE_HANDLE FileHandle1;
+ SHELL_FILE_HANDLE FileHandle2;
+ UINT64 Size1;
+ UINT64 Size2;
+ UINT64 DifferentBytes;
+ UINT64 DifferentCount;
+ UINT8 DiffPointNumber;
+ UINT8 OneByteFromFile1;
+ UINT8 OneByteFromFile2;
+ UINT8 *DataFromFile1;
+ UINT8 *DataFromFile2;
+ FILE_BUFFER FileBuffer1;
+ FILE_BUFFER FileBuffer2;
+ UINTN InsertPosition1;
+ UINTN InsertPosition2;
+ UINTN DataSizeFromFile1;
+ UINTN DataSizeFromFile2;
+ UINTN TempAddress;
+ UINTN Index;
+ UINTN DiffPointAddress;
+ READ_STATUS ReadStatus;
+
+ ShellStatus = SHELL_SUCCESS;
+ Status = EFI_SUCCESS;
+ FileName1 = NULL;
+ FileName2 = NULL;
+ FileHandle1 = NULL;
+ FileHandle2 = NULL;
+ DataFromFile1 = NULL;
+ DataFromFile2 = NULL;
+ ReadStatus = OutOfDiffPoint;
+ DifferentCount = 10;
+ DifferentBytes = 4;
+ DiffPointNumber = 0;
+ InsertPosition1 = 0;
+ InsertPosition2 = 0;
+ TempAddress = 0;
+ DiffPointAddress = 0;
//
// initialize the shell lib (we must be in non-auto-init...)
//
- Status = ShellInitialize();
- ASSERT_EFI_ERROR(Status);
+ Status = ShellInitialize ();
+ ASSERT_EFI_ERROR (Status);
- Status = CommandInit();
- ASSERT_EFI_ERROR(Status);
+ Status = CommandInit ();
+ ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
- if (EFI_ERROR(Status)) {
- if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam);
- FreePool(ProblemParam);
+ if (EFI_ERROR (Status)) {
+ if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam);
+ FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- ASSERT(FALSE);
+ ASSERT (FALSE);
}
} else {
- if (ShellCommandLineGetCount(Package) > 3) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp");
+ if (ShellCommandLineGetCount (Package) > 3) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp");
ShellStatus = SHELL_INVALID_PARAMETER;
- } else if (ShellCommandLineGetCount(Package) < 3) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp");
+ } else if (ShellCommandLineGetCount (Package) < 3) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
- TempParam = ShellCommandLineGetRawValue(Package, 1);
- ASSERT(TempParam != NULL);
- FileName1 = ShellFindFilePath(TempParam);
+ TempParam = ShellCommandLineGetRawValue (Package, 1);
+ ASSERT (TempParam != NULL);
+ FileName1 = ShellFindFilePath (TempParam);
if (FileName1 == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
ShellStatus = SHELL_NOT_FOUND;
} else {
- Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
+ Status = ShellOpenFileByName (FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
ShellStatus = SHELL_NOT_FOUND;
}
}
- TempParam = ShellCommandLineGetRawValue(Package, 2);
- ASSERT(TempParam != NULL);
- FileName2 = ShellFindFilePath(TempParam);
+
+ TempParam = ShellCommandLineGetRawValue (Package, 2);
+ ASSERT (TempParam != NULL);
+ FileName2 = ShellFindFilePath (TempParam);
if (FileName2 == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
ShellStatus = SHELL_NOT_FOUND;
} else {
- Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
+ Status = ShellOpenFileByName (FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);
+ if (EFI_ERROR (Status)) {
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam);
ShellStatus = SHELL_NOT_FOUND;
}
}
+
if (ShellStatus == SHELL_SUCCESS) {
- Status = gEfiShellProtocol->GetFileSize(FileHandle1, &Size1);
- ASSERT_EFI_ERROR(Status);
- Status = gEfiShellProtocol->GetFileSize(FileHandle2, &Size2);
- ASSERT_EFI_ERROR(Status);
+ Status = gEfiShellProtocol->GetFileSize (FileHandle1, &Size1);
+ ASSERT_EFI_ERROR (Status);
+ Status = gEfiShellProtocol->GetFileSize (FileHandle2, &Size2);
+ ASSERT_EFI_ERROR (Status);
if (ShellCommandLineGetFlag (Package, L"-n")) {
TempParam = ShellCommandLineGetValue (Package, L"-n");
@@ -316,7 +323,7 @@ ShellCommandRunComp (
DifferentCount = MAX_UINTN;
} else {
Status = ShellConvertStringToUint64 (TempParam, &DifferentCount, FALSE, TRUE);
- if (EFI_ERROR(Status) || DifferentCount == 0) {
+ if (EFI_ERROR (Status) || (DifferentCount == 0)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-n");
ShellStatus = SHELL_INVALID_PARAMETER;
}
@@ -331,7 +338,7 @@ ShellCommandRunComp (
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = ShellConvertStringToUint64 (TempParam, &DifferentBytes, FALSE, TRUE);
- if (EFI_ERROR(Status) || DifferentBytes == 0) {
+ if (EFI_ERROR (Status) || (DifferentBytes == 0)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-s");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
@@ -348,8 +355,9 @@ ShellCommandRunComp (
DataFromFile2 = AllocateZeroPool ((UINTN)DifferentBytes);
FileBufferInit (&FileBuffer1);
FileBufferInit (&FileBuffer2);
- if (DataFromFile1 == NULL || DataFromFile2 == NULL ||
- FileBuffer1.Data == NULL || FileBuffer2.Data == NULL) {
+ if ((DataFromFile1 == NULL) || (DataFromFile2 == NULL) ||
+ (FileBuffer1.Data == NULL) || (FileBuffer2.Data == NULL))
+ {
ShellStatus = SHELL_OUT_OF_RESOURCES;
SHELL_FREE_NON_NULL (DataFromFile1);
SHELL_FREE_NON_NULL (DataFromFile2);
@@ -362,13 +370,21 @@ ShellCommandRunComp (
while (DiffPointNumber < DifferentCount) {
DataSizeFromFile1 = 1;
DataSizeFromFile2 = 1;
- OneByteFromFile1 = 0;
- OneByteFromFile2 = 0;
- Status = FileBufferReadByte (FileHandle1, &FileBuffer1,
- &DataSizeFromFile1, &OneByteFromFile1);
+ OneByteFromFile1 = 0;
+ OneByteFromFile2 = 0;
+ Status = FileBufferReadByte (
+ FileHandle1,
+ &FileBuffer1,
+ &DataSizeFromFile1,
+ &OneByteFromFile1
+ );
ASSERT_EFI_ERROR (Status);
- Status = FileBufferReadByte (FileHandle2, &FileBuffer2,
- &DataSizeFromFile2, &OneByteFromFile2);
+ Status = FileBufferReadByte (
+ FileHandle2,
+ &FileBuffer2,
+ &DataSizeFromFile2,
+ &OneByteFromFile2
+ );
ASSERT_EFI_ERROR (Status);
TempAddress++;
@@ -378,19 +394,21 @@ ShellCommandRunComp (
// 2.If no more char in File1 or File2, The ReadStatus is InPrevDiffPoint forever.
// So the previous different point is the last one, then break the while block.
//
- if ( (DataSizeFromFile1 == 0 && InsertPosition1 == 0 && DataSizeFromFile2 == 0 && InsertPosition2 == 0) ||
- (ReadStatus == InPrevDiffPoint && (DataSizeFromFile1 == 0 || DataSizeFromFile2 == 0))
- ) {
+ if (((DataSizeFromFile1 == 0) && (InsertPosition1 == 0) && (DataSizeFromFile2 == 0) && (InsertPosition2 == 0)) ||
+ ((ReadStatus == InPrevDiffPoint) && ((DataSizeFromFile1 == 0) || (DataSizeFromFile2 == 0)))
+ )
+ {
break;
}
if (ReadStatus == OutOfDiffPoint) {
if (OneByteFromFile1 != OneByteFromFile2) {
- ReadStatus = InDiffPoint;
+ ReadStatus = InDiffPoint;
DiffPointAddress = TempAddress;
if (DataSizeFromFile1 == 1) {
DataFromFile1[InsertPosition1++] = OneByteFromFile1;
}
+
if (DataSizeFromFile2 == 1) {
DataFromFile2[InsertPosition2++] = OneByteFromFile2;
}
@@ -399,6 +417,7 @@ ShellCommandRunComp (
if (DataSizeFromFile1 == 1) {
DataFromFile1[InsertPosition1++] = OneByteFromFile1;
}
+
if (DataSizeFromFile2 == 1) {
DataFromFile2[InsertPosition2++] = OneByteFromFile2;
}
@@ -411,11 +430,11 @@ ShellCommandRunComp (
//
// ReadStatus should be always equal InDiffPoint.
//
- if ( InsertPosition1 == DifferentBytes ||
- InsertPosition2 == DifferentBytes ||
- (DataSizeFromFile1 == 0 && DataSizeFromFile2 == 0)
- ) {
-
+ if ((InsertPosition1 == DifferentBytes) ||
+ (InsertPosition2 == DifferentBytes) ||
+ ((DataSizeFromFile1 == 0) && (DataSizeFromFile2 == 0))
+ )
+ {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++DiffPointNumber);
PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes);
PrintDifferentPoint (FileName2, L"File2", DataFromFile2, InsertPosition2, DiffPointAddress, DifferentBytes);
@@ -423,7 +442,7 @@ ShellCommandRunComp (
//
// One of two buffuers is empty, it means this is the last different point.
//
- if (InsertPosition1 == 0 || InsertPosition2 == 0) {
+ if ((InsertPosition1 == 0) || (InsertPosition2 == 0)) {
break;
}
@@ -438,9 +457,9 @@ ShellCommandRunComp (
//
// Try to find a new different point in the rest of DataFromFile.
//
- for (; Index < MAX (InsertPosition1,InsertPosition2); Index++) {
+ for ( ; Index < MAX (InsertPosition1, InsertPosition2); Index++) {
if (DataFromFile1[Index] != DataFromFile2[Index]) {
- ReadStatus = InDiffPoint;
+ ReadStatus = InDiffPoint;
DiffPointAddress += Index;
break;
}
@@ -469,24 +488,26 @@ ShellCommandRunComp (
FileBufferUninit (&FileBuffer2);
if (DiffPointNumber == 0) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle);
} else {
ShellStatus = SHELL_NOT_EQUAL;
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle);
}
}
}
ShellCommandLineFreeVarList (Package);
}
- SHELL_FREE_NON_NULL(FileName1);
- SHELL_FREE_NON_NULL(FileName2);
+
+ SHELL_FREE_NON_NULL (FileName1);
+ SHELL_FREE_NON_NULL (FileName2);
if (FileHandle1 != NULL) {
- gEfiShellProtocol->CloseFile(FileHandle1);
+ gEfiShellProtocol->CloseFile (FileHandle1);
}
+
if (FileHandle2 != NULL) {
- gEfiShellProtocol->CloseFile(FileHandle2);
+ gEfiShellProtocol->CloseFile (FileHandle2);
}
return (ShellStatus);