]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/EfiCompress/EfiCompressMain.c
3 Copyright (c) 1999-2006 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 The main function for the compression utility.
29 #include <Common/UefiBaseTypes.h>
32 #define UTILITY_NAME "EfiCompress"
33 #define UTILITY_MAJOR_VERSION 1
34 #define UTILITY_MINOR_VERSION 1
44 Print out version information for EfiCompress.
56 printf ("%s v%d.%d -EDK Efi Compress Utility\n", UTILITY_NAME
, UTILITY_MAJOR_VERSION
, UTILITY_MINOR_VERSION
);
57 printf ("Copyright (c) 2005-2006 Intel Corporation. All rights reserved.\n");
68 Print out usage information for EfiCompress.
81 printf ("\nUsage: %s Inputfile Outputfile\n", UTILITY_NAME
);
94 Compresses the input files
98 argc - number of arguments passed into the command line.
99 argv[] - files to compress and files to output compressed data to.
103 int: 0 for successful execution of the function.
117 // Added for makefile debug - KCE
121 SrcBuffer
= DstBuffer
= NULL
;
122 infile
= outfile
= NULL
;
129 if ((strcmp(argv
[1], "-h") == 0) || (strcmp(argv
[1], "--help") == 0) ||
130 (strcmp(argv
[1], "-?") == 0) || (strcmp(argv
[1], "/?") == 0)) {
135 if ((strcmp(argv
[1], "-V") == 0) || (strcmp(argv
[1], "--version") == 0)) {
145 if ((outfile
= fopen (argv
[2], "wb")) == NULL
) {
146 printf ("Can't open output file\n");
150 if ((infile
= fopen (argv
[1], "rb")) == NULL
) {
151 printf ("Can't open input file\n");
155 // Get the size of source file
158 while (fread (Buffer
, 1, 1, infile
)) {
163 // Read in the source data
165 if ((SrcBuffer
= malloc (SrcSize
)) == NULL
) {
166 printf ("Can't allocate memory\n");
171 if (fread (SrcBuffer
, 1, SrcSize
, infile
) != SrcSize
) {
172 printf ("Can't read from source\n");
176 // Get destination data size and do the compression
179 Status
= EfiCompress (SrcBuffer
, SrcSize
, DstBuffer
, &DstSize
);
180 if (Status
== EFI_BUFFER_TOO_SMALL
) {
181 if ((DstBuffer
= malloc (DstSize
)) == NULL
) {
182 printf ("Can't allocate memory\n");
186 Status
= EfiCompress (SrcBuffer
, SrcSize
, DstBuffer
, &DstSize
);
189 if (EFI_ERROR (Status
)) {
190 printf ("Compress Error\n");
194 printf ("\nOrig Size = %ld\n", SrcSize
);
195 printf ("Comp Size = %ld\n", DstSize
);
197 if (DstBuffer
== NULL
) {
198 printf ("No destination to write to.\n");
202 // Write out the result
204 if (fwrite (DstBuffer
, 1, DstSize
, outfile
) != DstSize
) {
205 printf ("Can't write to destination file\n");