]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/EfiCompress/EfiCompressMain.c
1. Removed the unnecessary #include statements and include files
[mirror_edk2.git] / Tools / Source / TianoTools / EfiCompress / EfiCompressMain.c
1 /*++
2
3 Copyright (c) 1999 - 2002 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
10 Intel Corporation.
11
12
13 Module Name:
14
15 EfiCompressMain.c
16
17 Abstract:
18
19 The main function for the compression utility.
20
21 --*/
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <ctype.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include <Common/UefiBaseTypes.h>
30
31 #include "EfiCompress.h"
32
33 int
34 main (
35 INT32 argc,
36 CHAR8 *argv[]
37 )
38 /*++
39
40 Routine Description:
41
42 Compresses the input files
43
44 Arguments:
45
46 argc - number of arguments passed into the command line.
47 argv[] - files to compress and files to output compressed data to.
48
49 Returns:
50
51 int: 0 for successful execution of the function.
52
53 --*/
54 {
55 EFI_STATUS Status;
56 FILE *infile;
57 FILE *outfile;
58 UINT32 SrcSize;
59 UINT32 DstSize;
60 UINT8 *SrcBuffer;
61 UINT8 *DstBuffer;
62 UINT8 Buffer[8];
63
64 //
65 // Added for makefile debug - KCE
66 //
67 INT32 arg_counter;
68 printf ("\n\n");
69 for (arg_counter = 0; arg_counter < argc; arg_counter++) {
70 printf ("%s ", argv[arg_counter]);
71 }
72
73 printf ("\n\n");
74
75 SrcBuffer = DstBuffer = NULL;
76
77 infile = outfile = NULL;
78
79 if (argc != 3) {
80 printf ("Usage: EFICOMPRESS <infile> <outfile>\n");
81 goto Done;
82 }
83
84 if ((outfile = fopen (argv[2], "wb")) == NULL) {
85 printf ("Can't open output file\n");
86 goto Done;
87 }
88
89 if ((infile = fopen (argv[1], "rb")) == NULL) {
90 printf ("Can't open input file\n");
91 goto Done;
92 }
93 //
94 // Get the size of source file
95 //
96 SrcSize = 0;
97 while (fread (Buffer, 1, 1, infile)) {
98 SrcSize++;
99
100 }
101 //
102 // Read in the source data
103 //
104 if ((SrcBuffer = malloc (SrcSize)) == NULL) {
105 printf ("Can't allocate memory\n");
106 goto Done;
107 }
108
109 rewind (infile);
110 if (fread (SrcBuffer, 1, SrcSize, infile) != SrcSize) {
111 printf ("Can't read from source\n");
112 goto Done;
113 }
114 //
115 // Get destination data size and do the compression
116 //
117 DstSize = 0;
118 Status = Compress (SrcBuffer, SrcSize, DstBuffer, &DstSize);
119 if (Status == EFI_BUFFER_TOO_SMALL) {
120 if ((DstBuffer = malloc (DstSize)) == NULL) {
121 printf ("Can't allocate memory\n");
122 goto Done;
123 }
124
125 Status = Compress (SrcBuffer, SrcSize, DstBuffer, &DstSize);
126 }
127
128 if (EFI_ERROR (Status)) {
129 printf ("Compress Error\n");
130 goto Done;
131 }
132
133 printf ("\nOrig Size = %ld\n", SrcSize);
134 printf ("Comp Size = %ld\n", DstSize);
135
136 if (DstBuffer == NULL) {
137 printf ("No destination to write to.\n");
138 goto Done;
139 }
140 //
141 // Write out the result
142 //
143 if (fwrite (DstBuffer, 1, DstSize, outfile) != DstSize) {
144 printf ("Can't write to destination file\n");
145 }
146
147 Done:
148 if (SrcBuffer) {
149 free (SrcBuffer);
150 }
151
152 if (DstBuffer) {
153 free (DstBuffer);
154 }
155
156 if (infile) {
157 fclose (infile);
158 }
159
160 if (outfile) {
161 fclose (outfile);
162 }
163
164 return 0;
165 }