+++ /dev/null
-/*++\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
-#include "Compress.h"\r
-\r
-#define UTILITY_NAME "EfiCompress"\r
-#define UTILITY_MAJOR_VERSION 1\r
-#define UTILITY_MINOR_VERSION 1\r
-\r
-void \r
-Version(\r
- void\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Print out version information for EfiCompress.\r
-\r
-Arguments:\r
-\r
- None\r
- \r
-Returns:\r
-\r
- None\r
- \r
---*/ \r
-{\r
- printf ("%s v%d.%d -Efi File Compress Utility\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r
- printf ("Copyright (c) 2005-2006 Intel Corporation. All rights reserved.\n");\r
-}\r
-\r
-void \r
-Usage(\r
- void\r
- )\r
-/*++\r
-\r
-Routine Description:\r
-\r
- Print out usage information for EfiCompress.\r
-\r
-Arguments:\r
-\r
- None\r
- \r
-Returns:\r
-\r
- None\r
- \r
---*/ \r
-{\r
- Version();\r
- printf ("\nUsage: %s Inputfile Outputfile\n", UTILITY_NAME);\r
-}\r
-\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
- \r
- SrcBuffer = DstBuffer = NULL;\r
- infile = outfile = NULL;\r
-\r
- if (argc == 1) {\r
- Usage();\r
- goto Done;\r
- }\r
- \r
- if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0) ||\r
- (strcmp(argv[1], "-?") == 0) || (strcmp(argv[1], "/?") == 0)) {\r
- Usage();\r
- goto Done;\r
- }\r
- \r
- if ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0)) {\r
- Version();\r
- goto Done;\r
- }\r
- \r
- if (argc != 3) {\r
- Usage();\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 = EfiCompress (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 = EfiCompress (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