]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDebug1CommandsLib/Comp.c
comp - add comments and add input verification
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / Comp.c
index c6933e6095b8ab73932ccbcb643a45e98c4d1e0b..b59ef31682c5917bd072eda03c4bda874c7231af 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for Comp shell Debug1 function.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 \r
 #include "UefiShellDebug1CommandsLib.h"\r
 \r
+/**\r
+  Function for 'comp' command.\r
+\r
+  @param[in] ImageHandle  Handle to the Image (NULL if Internal).\r
+  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ShellCommandRunComp (\r
@@ -83,24 +89,26 @@ ShellCommandRunComp (
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
       FileName1 = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 1));\r
-      FileName2 = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 2));\r
-      Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);\r
-      if (EFI_ERROR(Status)) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);\r
+      if (FileName1 == NULL) {\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1));\r
         ShellStatus = SHELL_NOT_FOUND;\r
+      } else {\r
+        Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0);\r
+        if (EFI_ERROR(Status)) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status);\r
+          ShellStatus = SHELL_NOT_FOUND;\r
+        }\r
       }\r
-      Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);\r
-      if (EFI_ERROR(Status)) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);\r
+      FileName2 = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 2));\r
+      if (FileName2 == NULL) {\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2));\r
         ShellStatus = SHELL_NOT_FOUND;\r
-      }\r
-      if (FileHandleIsDirectory(FileHandle1) == EFI_SUCCESS){\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, FileName1);\r
-        ShellStatus = SHELL_INVALID_PARAMETER;\r
-      }\r
-      if (FileHandleIsDirectory(FileHandle2) == EFI_SUCCESS){\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, FileName2);\r
-        ShellStatus = SHELL_INVALID_PARAMETER;\r
+      } else {\r
+        Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0);\r
+        if (EFI_ERROR(Status)) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status);\r
+          ShellStatus = SHELL_NOT_FOUND;\r
+        }\r
       }\r
       if (ShellStatus == SHELL_SUCCESS) {\r
         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_HEADER), gShellDebug1HiiHandle, FileName1, FileName2);\r
@@ -228,22 +236,19 @@ ShellCommandRunComp (
             ShellStatus = SHELL_NOT_EQUAL;\r
           }\r
         }\r
-      }\r
-      if (ErrorCount == 0) {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle);\r
-      } else {\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle);\r
+        if (ErrorCount == 0) {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle);\r
+        } else {\r
+          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle);\r
+        }\r
       }\r
     }\r
 \r
     ShellCommandLineFreeVarList (Package);\r
   }\r
-  if (FileName1 != NULL) {\r
-    FreePool(FileName1);\r
-  }\r
-  if (FileName2 != NULL) {\r
-    FreePool(FileName2);\r
-  }\r
+  SHELL_FREE_NON_NULL(FileName1);\r
+  SHELL_FREE_NON_NULL(FileName2);\r
+\r
   if (FileHandle1 != NULL) {\r
     gEfiShellProtocol->CloseFile(FileHandle1);\r
   }\r