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