2006-05-19 04:38:56 +02:00
|
|
|
/*++
|
|
|
|
|
2006-07-14 11:15:04 +02:00
|
|
|
Copyright (c) 1999-2006 Intel Corporation. All rights reserved
|
|
|
|
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.
|
2006-05-19 04:38:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
Module Name:
|
|
|
|
|
|
|
|
EfiCompressMain.c
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
|
|
|
|
The main function for the compression utility.
|
|
|
|
|
|
|
|
--*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2006-06-16 13:42:42 +02:00
|
|
|
|
|
|
|
#include <Common/UefiBaseTypes.h>
|
2006-12-07 06:29:07 +01:00
|
|
|
#include "Compress.h"
|
2006-05-19 04:38:56 +02:00
|
|
|
|
2006-11-14 23:01:45 +01:00
|
|
|
#define UTILITY_NAME "EfiCompress"
|
|
|
|
#define UTILITY_MAJOR_VERSION 1
|
|
|
|
#define UTILITY_MINOR_VERSION 1
|
|
|
|
|
|
|
|
void
|
2007-01-02 21:17:36 +01:00
|
|
|
Version(
|
2006-11-14 23:01:45 +01:00
|
|
|
void
|
|
|
|
)
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Routine Description:
|
|
|
|
|
|
|
|
Print out version information for EfiCompress.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
--*/
|
|
|
|
{
|
2007-01-18 23:07:47 +01:00
|
|
|
printf ("%s v%d.%d -Efi File Compress Utility\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);
|
2006-11-14 23:01:45 +01:00
|
|
|
printf ("Copyright (c) 2005-2006 Intel Corporation. All rights reserved.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-01-02 21:17:36 +01:00
|
|
|
Usage(
|
2006-11-14 23:01:45 +01:00
|
|
|
void
|
|
|
|
)
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Routine Description:
|
|
|
|
|
|
|
|
Print out usage information for EfiCompress.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
None
|
|
|
|
|
|
|
|
--*/
|
|
|
|
{
|
2007-01-02 21:17:36 +01:00
|
|
|
Version();
|
|
|
|
printf ("\nUsage: %s Inputfile Outputfile\n", UTILITY_NAME);
|
2006-11-14 23:01:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-19 04:38:56 +02:00
|
|
|
int
|
|
|
|
main (
|
|
|
|
INT32 argc,
|
|
|
|
CHAR8 *argv[]
|
|
|
|
)
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Routine Description:
|
|
|
|
|
|
|
|
Compresses the input files
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
|
|
|
|
argc - number of arguments passed into the command line.
|
|
|
|
argv[] - files to compress and files to output compressed data to.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
int: 0 for successful execution of the function.
|
|
|
|
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
FILE *infile;
|
|
|
|
FILE *outfile;
|
|
|
|
UINT32 SrcSize;
|
|
|
|
UINT32 DstSize;
|
|
|
|
UINT8 *SrcBuffer;
|
|
|
|
UINT8 *DstBuffer;
|
|
|
|
UINT8 Buffer[8];
|
|
|
|
|
|
|
|
//
|
|
|
|
// Added for makefile debug - KCE
|
|
|
|
//
|
|
|
|
INT32 arg_counter;
|
2006-11-14 23:01:45 +01:00
|
|
|
|
2006-05-19 04:38:56 +02:00
|
|
|
SrcBuffer = DstBuffer = NULL;
|
|
|
|
infile = outfile = NULL;
|
|
|
|
|
2007-01-08 23:27:20 +01:00
|
|
|
if (argc == 1) {
|
2007-01-02 21:17:36 +01:00
|
|
|
Usage();
|
2006-11-14 23:01:45 +01:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0) ||
|
|
|
|
(strcmp(argv[1], "-?") == 0) || (strcmp(argv[1], "/?") == 0)) {
|
2007-01-02 21:17:36 +01:00
|
|
|
Usage();
|
2006-11-14 23:01:45 +01:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0)) {
|
2007-01-02 21:17:36 +01:00
|
|
|
Version();
|
2006-11-14 23:01:45 +01:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2006-05-19 04:38:56 +02:00
|
|
|
if (argc != 3) {
|
2007-01-02 21:17:36 +01:00
|
|
|
Usage();
|
2006-05-19 04:38:56 +02:00
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((outfile = fopen (argv[2], "wb")) == NULL) {
|
|
|
|
printf ("Can't open output file\n");
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((infile = fopen (argv[1], "rb")) == NULL) {
|
|
|
|
printf ("Can't open input file\n");
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Get the size of source file
|
|
|
|
//
|
|
|
|
SrcSize = 0;
|
|
|
|
while (fread (Buffer, 1, 1, infile)) {
|
|
|
|
SrcSize++;
|
|
|
|
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Read in the source data
|
|
|
|
//
|
|
|
|
if ((SrcBuffer = malloc (SrcSize)) == NULL) {
|
|
|
|
printf ("Can't allocate memory\n");
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
rewind (infile);
|
|
|
|
if (fread (SrcBuffer, 1, SrcSize, infile) != SrcSize) {
|
|
|
|
printf ("Can't read from source\n");
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Get destination data size and do the compression
|
|
|
|
//
|
|
|
|
DstSize = 0;
|
2006-12-07 06:29:07 +01:00
|
|
|
Status = EfiCompress (SrcBuffer, SrcSize, DstBuffer, &DstSize);
|
2006-05-19 04:38:56 +02:00
|
|
|
if (Status == EFI_BUFFER_TOO_SMALL) {
|
|
|
|
if ((DstBuffer = malloc (DstSize)) == NULL) {
|
|
|
|
printf ("Can't allocate memory\n");
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
2006-12-07 06:29:07 +01:00
|
|
|
Status = EfiCompress (SrcBuffer, SrcSize, DstBuffer, &DstSize);
|
2006-05-19 04:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
printf ("Compress Error\n");
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf ("\nOrig Size = %ld\n", SrcSize);
|
|
|
|
printf ("Comp Size = %ld\n", DstSize);
|
|
|
|
|
|
|
|
if (DstBuffer == NULL) {
|
|
|
|
printf ("No destination to write to.\n");
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Write out the result
|
|
|
|
//
|
|
|
|
if (fwrite (DstBuffer, 1, DstSize, outfile) != DstSize) {
|
|
|
|
printf ("Can't write to destination file\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
if (SrcBuffer) {
|
|
|
|
free (SrcBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DstBuffer) {
|
|
|
|
free (DstBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (infile) {
|
|
|
|
fclose (infile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outfile) {
|
|
|
|
fclose (outfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|