]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/CodeTools/Source/EfiCompress/EfiCompressMain.c
More renames for Tool Packages
[mirror_edk2.git] / Tools / CodeTools / Source / EfiCompress / EfiCompressMain.c
diff --git a/Tools/CodeTools/Source/EfiCompress/EfiCompressMain.c b/Tools/CodeTools/Source/EfiCompress/EfiCompressMain.c
new file mode 100644 (file)
index 0000000..492210f
--- /dev/null
@@ -0,0 +1,165 @@
+/*++\r
+\r
+Copyright (c)  1999-2006 Intel Corporation. All rights reserved\r
+This program and the accompanying materials are licensed and made available \r
+under the terms and conditions of the BSD License which accompanies this \r
+distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+\r
+Module Name:\r
+  \r
+  EfiCompressMain.c\r
+\r
+Abstract:\r
+\r
+  The main function for the compression utility.\r
+  \r
+--*/\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <ctype.h>\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+#include <Common/UefiBaseTypes.h>\r
+\r
+#include "EfiCompress.h"\r
+\r
+int\r
+main (\r
+  INT32 argc,\r
+  CHAR8 *argv[]\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Compresses the input files\r
+\r
+Arguments:\r
+\r
+  argc   - number of arguments passed into the command line.\r
+  argv[] - files to compress and files to output compressed data to.\r
+\r
+Returns:\r
+\r
+  int: 0 for successful execution of the function.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  FILE        *infile;\r
+  FILE        *outfile;\r
+  UINT32      SrcSize;\r
+  UINT32      DstSize;\r
+  UINT8       *SrcBuffer;\r
+  UINT8       *DstBuffer;\r
+  UINT8       Buffer[8];\r
+\r
+  //\r
+  //  Added for makefile debug - KCE\r
+  //\r
+  INT32       arg_counter;\r
+  printf ("\n\n");\r
+  for (arg_counter = 0; arg_counter < argc; arg_counter++) {\r
+    printf ("%s ", argv[arg_counter]);\r
+  }\r
+\r
+  printf ("\n\n");\r
+\r
+  SrcBuffer             = DstBuffer = NULL;\r
+\r
+  infile                = outfile = NULL;\r
+\r
+  if (argc != 3) {\r
+    printf ("Usage: EFICOMPRESS <infile> <outfile>\n");\r
+    goto Done;\r
+  }\r
+\r
+  if ((outfile = fopen (argv[2], "wb")) == NULL) {\r
+    printf ("Can't open output file\n");\r
+    goto Done;\r
+  }\r
+\r
+  if ((infile = fopen (argv[1], "rb")) == NULL) {\r
+    printf ("Can't open input file\n");\r
+    goto Done;\r
+  }\r
+  //\r
+  // Get the size of source file\r
+  //\r
+  SrcSize = 0;\r
+  while (fread (Buffer, 1, 1, infile)) {\r
+    SrcSize++;\r
+\r
+  }\r
+  //\r
+  // Read in the source data\r
+  //\r
+  if ((SrcBuffer = malloc (SrcSize)) == NULL) {\r
+    printf ("Can't allocate memory\n");\r
+    goto Done;\r
+  }\r
+\r
+  rewind (infile);\r
+  if (fread (SrcBuffer, 1, SrcSize, infile) != SrcSize) {\r
+    printf ("Can't read from source\n");\r
+    goto Done;\r
+  }\r
+  //\r
+  // Get destination data size and do the compression\r
+  //\r
+  DstSize = 0;\r
+  Status  = Compress (SrcBuffer, SrcSize, DstBuffer, &DstSize);\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    if ((DstBuffer = malloc (DstSize)) == NULL) {\r
+      printf ("Can't allocate memory\n");\r
+      goto Done;\r
+    }\r
+\r
+    Status = Compress (SrcBuffer, SrcSize, DstBuffer, &DstSize);\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    printf ("Compress Error\n");\r
+    goto Done;\r
+  }\r
+\r
+  printf ("\nOrig Size = %ld\n", SrcSize);\r
+  printf ("Comp Size = %ld\n", DstSize);\r
+\r
+  if (DstBuffer == NULL) {\r
+    printf ("No destination to write to.\n");\r
+    goto Done;\r
+  }\r
+  //\r
+  // Write out the result\r
+  //\r
+  if (fwrite (DstBuffer, 1, DstSize, outfile) != DstSize) {\r
+    printf ("Can't write to destination file\n");\r
+  }\r
+\r
+Done:\r
+  if (SrcBuffer) {\r
+    free (SrcBuffer);\r
+  }\r
+\r
+  if (DstBuffer) {\r
+    free (DstBuffer);\r
+  }\r
+\r
+  if (infile) {\r
+    fclose (infile);\r
+  }\r
+\r
+  if (outfile) {\r
+    fclose (outfile);\r
+  }\r
+\r
+  return 0;\r
+}\r